Just a little function humor.

5 posts by 2 authors in: Forums > CMS Builder
Last Post: August 14, 2015   (RSS)

By rconring - August 7, 2015

I hope I am not breaking forum decorum but I just had to share this nugget with the CMSB community.

The other day, I found myself in need of a function to replace an array of placeholders with an array of variables.  I knew I had written that very function for use on another site some time ago but could not remember which site.  I did remember that I had named the function something like "replace_token" or "swap_token" ... I knew it had "token" in the name so I did a search of my web projects directory for *token*.  

Holy Smoke! (pun intended)  Ironically, there is was in a little quickie site I did for a client last year .... cannabiscrusades.com! 

If you don't get it, it's probably a good thing!  LOL

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

By Dave - August 12, 2015

Hey Ron, 

We use a lot of metaphors to describe data and ideas and we often deal with hierarchical/tree structured data.   So we use a very common child/parent metaphor in the code to describe how uploads work, and when creating a new record in the CMS, you can upload files before the record is created.  So on save "child" upload records are "adopted" by the "parent" record.  Except sometime a user might upload some files and then not click save.  In which case we need to clean up the uploads and remove them after a period of time.

Anyways, I remember having a conversation about some  unintentionally morbid code that killed off or abandoning children that weren't adopted.   I think we ended up changing some of the wording, but just know that if you ever see some code that reads like that, we didn't mean it that way! :-)

Dave Edis - Senior Developer
interactivetools.com

By rconring - August 12, 2015

Yep ... the killing of the orphans!

On a serious note while on the topic, I need to take this opportunity to see if there is a solution to a parent/child problem that I am currently having.  

The WYSIWYG editor being a designer's nemesis, I am trying to create a tightly controlled structured situation for a client that cannot seem to grasp even the most basic design rules and creates the most hideous HTML that totally breaks a responsive design.  So, I am taking away his WYSIWYG field so he has to create a post which consists of post elements ... Banner Image, Slider, H1, H2, Paragraph, Photo Array, Document, Form, Video ... etc.  So, the data structure is basically a header record "posts" with related children "post_elements".  This all works very well and produces very clean responsive posts since I control every aspect of the rendered code on the front end.

The problem I am having is with the back end.  I cannot drag-sort the post elements from within the "posts" record where the preview button is.  I have to back out of the "posts" record and go to a filtered "post_elements" list in order to rearrange the elements' sort order.  Also, if I edit one of the related elements from within the "posts" record, it returns me to the "posts" listing rather than to the related "post_elements" list within the open post record.  I can manage it myself this way, but I am sure my client will never be able to.  There are probably some tweaks to the back end code to resolve this, but I haven't spent a lot of time playing with the editing environment so am at the "Ask Dave" point in this endeavor.  Is there something obvious that I am missing or would this require major surgery? 

I attached a couple of screenshots.

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

By Dave - August 14, 2015

Hi Ron, 

Here's a couple things that might be of interest:

Customize WYSIWYG - You can edit/limit the buttons shown on the wysiwyg by editting /lib/wysiwyg.php.  You can save it as wysiwyg_custom.php.  The button list looks like this: formatselect,fontsizeselect,bold,italic,underline,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,|,outdent,indent,|,sub,sup,charmap,|,removeformat,fullscreen

htmlPurify() - For plugin authors there's also a function in /lib/common.php called htmlPurify() that filters out unwanted HTML.  It's a bit more work to implement but works well.  We use it for this forum.  It uses an underlying library from: http://htmlpurifier.org/

Related Records Drag Sorting - Try setting this to '1' in your /data/settings file(s):  'allowRelatedRecordsDragSorting' => '0',  Note that sorting a subset of the records might produce unexpected results, so make sure you test it before relying on it.

Hope one of those help!

Dave Edis - Senior Developer
interactivetools.com