Reducing Tinymce editor features for user

So...

I know I can set the editor to 'simple' to limit the format ribbon(s).  What if I don't want people to display pictures or weird fonts and colors anyway by pasting in something they copied from Word or whatever html based source?

I don't mind Bold, Italics, Underline or even justifications.  Is it an all or nothing scenario?

Is there some funky complex strip_tags process I would have to go through to keep photos and huge fonts, colors, tables and stuff out?

Appreciate any thoughts on this.  Don't get me wrong, I love full text editor but there are times when you need to reduce or takeaway the user's options.

Related, I know I can take out the attributes variable in the <textarea> element and just make it a regular textarea field but when I tried to submit the content, the form is likely not seeing the keyed data because the "not enough characters" message appears.  Any thoughts on what to tweak to make that part work in case there's no real way to use the tinymce editor and limit what the user can do?

Quote · 13 Apr 2013

The easiest way it to limit the allowed tags in the TinyMCE configuration.  You can block the image tag <img> and TinyMCE will strip out any image tag that someone tries to insert.  You can remove the insert image button, and the html edit button and the font button.  Bold and italics are done with span tags.  You can alter the configuration so that the editor provides some features and remove the others.  The file is /templates/base/scripts/BxBaseEditorTinyMCE.php.  Go to http://www.tinymce.com to learn how to configure the file.  Note how the editor is configured in Dolphin, for example, you may see double quotes used in an example; follow the syntax you see in the BxBaseEditorTinyMCE.php file.

You can even create a new configuration; there is another file to edit for this along with BxBaseEditorTinyMCE.php, but it is more involved; I thought about writing a tutorial on adding custom tinymce editor instances but never did.  For example, I needed to add one to the files edit but it needed to be a custom one so I created a new instance of the tinymce editor just for the files edit.

Geeks, making the world a better place
Quote · 13 Apr 2013

So Tinymce will handle stripping out all unwanted tags posted in by virtue of removing the unwanted toolbar plugins, ie images?  If so, that's so simple I feel stupid spending an hour for a way to cleanse the data.

 

I was going down the path of $sValue = strip_tags($sValue, '<p><em><span><ul><li><ol>');

But on first try, something is amiss. Thankfully I just saw your post so I'll try what you suggested. Thx!  As you can likely tell, I'm not that familiar with the text editor like I probably should be.

Quote · 13 Apr 2013

Well I can't figure it out - yet but I have to move on after spending like 4hrs on it now. Sheesh. 

I tried  various elements using the following format(s) in BxBaseEditorTinyMCE.php as the last line of the variable $CONF_COMMON. I'm pretty sure that's where it should go.

  valid_elements :"a[href|target=_blank],strong/b,div[align],br"


As far as formatting the toolbar, I removed all the buttons I don't want and it displays like I want. But if I go to like espn or msn or whatever and copy some random content with links and images, etc then paste it into my textarea box, it retains all the tag elements when saving to the db_table.

 

Is strip_tags the absolute wrong area to focus my time?  Should I focus on valid_elements I suppose?  If the latter, am I missing another file than bxbaseeditor.php to make adjustments?

 

Appreciate the help. 

Quote · 13 Apr 2013

First of all, please note that if you use valid_elements, you have to list all the elements you want as valid and you have to be specific in what you want to allow in that element.  There is also extended_valid_elements that can be use to add a valid element; and if there is no valid_element then TinyMCE uses the default; you can still use extended_valid_element to add to the default list.

In your case, I think you want to use invalid_elements to exclude some items from the list.  For example, to exclude the image tag, use:

invalid_elements: 'img'

To also exclude the use of anchor tags:

invalid_elements: 'img,a'

Note that attributes can not be used with invalid elements.

You can use extended_valid_elements to specify attributes.  Let's say you want to be able to include spans if they have a class attribute, otherwise you wish for them to be removed.

extended_valid_element: 'span[!class]'

In this case, if a span tag exists without the class it is removed.  If the span tag has a class, then it is left when TinyMCE does code clean up.  The ! means that class is required, if the span tag does not have a class attribute it will be removed.

Geeks, making the world a better place
Quote · 13 Apr 2013

Post your configuration for TinyMCE here and we can see if there is an error preventing it from working correctly

Geeks, making the world a better place
Quote · 13 Apr 2013

I bet that's it - exclude instead of include.  Here's a snapshot of how I have it now.  I'll play with it some more based on your rather insightful suggestion - thank you my lady. errr... geek_girl.

 

  jQuery('{bx_var_selector}').tinymce({
                        {bx_var_custom_init}
                        document_base_url: '{bx_url_root}',
                        remove_script_host: false,
                        relative_urls: false,
                        script_url: '{bx_var_plugins_path}tiny_mce/tiny_mce_gzip.php',
                        skin: '{bx_var_skin}',
                        language: '{bx_var_lang}',
                        content_css: '{bx_var_css_path}',
                        gecko_spellcheck: true,
                        entity_encoding: 'raw',
                        verify_html: false,

   valid_elements : 'strong/b,br'

                    });
    ";

    /**
     * Standard view initialization params
     */
    protected static $WIDTH_STANDARD = '630px';
    protected static $CONF_STANDARD = "
                        plugins: 'autolink,autosave,lists,inlinepopups,media,paste,fullscreen',
                        width: '100%',
                        height: '270',
                        theme: 'advanced',
                        theme_advanced_buttons1: 'bold,italic,underline,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,|,undo,redo,|',
                        theme_advanced_buttons2: 'hr,link,unlink,|,pastetext',
                        theme_advanced_buttons3: '',
                        theme_advanced_toolbar_location: 'top',
                        theme_advanced_toolbar_align: 'left',
                        theme_advanced_statusbar_location: 'bottom',
                        theme_advanced_resizing: true,
                        theme_advanced_resize_horizontal: false,
                        theme_advanced_resizing_use_cookie: true,
                        theme_advanced_path: false,
    ";

Quote · 14 Apr 2013

Is there a way to reduce the number of available features only for members, not affecting the Admin panel?

This is my signature, there are many like it but this one is mine...
Quote · 1 Jul 2013

There are several TinyMCE toolbar sets and you can create new ones.  So you could create a new TinyMCE set with reduced functions and assign that set for the members to use.  You have to edit two files; one file; and I can not remember the name of the file as I type this, holds the numbers assigned to TinyMCE for use in such as HTML => 2 and of course the other one is the one that holds the different sets.  Once you create your new set, then you have to assign that one to the areas that uses the toolbar, such as the blog editor.  The comment one is already reduced; reduced so much that I had to add to it.  The profile editor uses the first set.  If this is something you think you can do, then I can add to this later when my mind is more awake.

Geeks, making the world a better place
Quote · 1 Jul 2013
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.