? ? Success

User tests: Successful: Unsuccessful:

avatar artur-stepien
artur-stepien
16 Jul 2014

This pull request makes TinyMCE load all available templates into editor. So user is only required to put html template file into /media/editors/tinymce/templates and refresh his browser window without creating any additional files or interfere into plug-in code.

Proper feature request has been created here: http://forge.joomla.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_id=8549&tracker_item_id=33954

avatar artur-stepien artur-stepien - open - 16 Jul 2014
avatar artur-stepien artur-stepien - change - 16 Jul 2014
Title
Automatic loading of all templates
[#33954] Automatic loading of all templates
avatar Bakual
Bakual - comment - 16 Jul 2014

Can you make sure that you follow our coding standard (http://joomla.github.io/coding-standards/)?

Also you may consider to use JFolder::files(). You could probably reduce the code using it.

avatar artur-stepien
artur-stepien - comment - 16 Jul 2014

I was checking if everything is coded as it should be on that page and didn't saw any mistakes. If you see anything I will ofc change it.

Using JFolder::Files() will not only make code longer but also slower.

avatar Bakual
Bakual - comment - 16 Jul 2014

I will comment inline on the standard issues I see.

Using JFolder::Files() will not only make code longer but also slower.

Hmm, I thought you could use exclude to not get the index.html for example and you should also be able to directly get the full path. Something like this:

$files = JFolder::files('JPATH_ROOT.'/media/editors/tinymce/templates', '.html', false, true, array('index.html'));
foreach ($files as $file)
{
...
}

Haven't tested it and it's a bit since I used it myself, so it may be wrong :)

avatar infograf768
infograf768 - comment - 18 Jul 2014

One more small code correction please

if ( $filename != 'index' )

should be

if ($filename != 'index')
avatar artur-stepien
artur-stepien - comment - 18 Jul 2014

I don't think his travis build error is related to my code

avatar infograf768
infograf768 - comment - 19 Jul 2014

I had relaunched Travis and it is now Ok.
After much thought, and although we lose the description of the template with this code, I think it is generally much easier than creating lists (lists indeed shall not be created from js anymore but from a templates.php file see http://www.tinymce.com/wiki.php/Configuration:templates )

The problem I see when losing the description is for people not using English as language as the description allows to use non-ascii languages to explain the template.
For these cases, the only solution I see is the list with updated code to use templates.php

avatar artur-stepien
artur-stepien - comment - 19 Jul 2014

Using templates.php is the same as using list like in my code. But lunching another php script just to get translations is pointless. It would be better to check for each and every file if there is translation in system. If there is translation, use translation, if not, drop it and just use file name.That would fix the problem with descriptions. What you think about this

avatar infograf768
infograf768 - comment - 19 Jul 2014

I do not see how we could get a translation for a description that does not exist (and should not) in the html template file... If we were using the name of the file to provide a translation, this would mean adding the string if not in ALL Tiny lang.js , but at least into the lang concerned. Not multilang aware
Joomla JText::_ is not used here.
Impossible imho.

I think we will just have to merge your PR and make sure we follow the new Tiny API for list in the future.

avatar artur-stepien
artur-stepien - comment - 19 Jul 2014

You're right, there is no translation in HTML file. But plug-in initialisation is made in php within Joomla framework so we can add checking there. And proper descriptions into plug-in translation file.

avatar artur-stepien
artur-stepien - comment - 19 Jul 2014

That way would also give a possibility of overriding or adding descriptions in Language Overriding.

avatar infograf768
infograf768 - comment - 20 Jul 2014

Joomla language strings are not usable into TinyMCE. Tiny uses exclusively these:
https://github.com/joomla/joomla-cms/tree/staging/media/editors/tinymce/langs

avatar artur-stepien
artur-stepien - comment - 20 Jul 2014

You still don't understand. Template name and description was hard-coded like this (So there was no translations and I didn't saw any in Polish):

$templates = "templates: [
{title: 'Layout', description: 'HTMLLayout', url:'" . JUri::root() . "media/editors/tinymce/templates/layout1.html'},
{title: 'Simple snippet', description: 'Simple HTML snippet', url:'" . JUri::root() . "media/editors/tinymce/templates/snippet1.html'}
],";

so we can make translations like this:

$templates = "templates: [
{title: '" . JText::_('PLG_EDITOR_TINYMCE_TEMPLATE_NAME_HTML_LAYOUT') . "', description: '" . JText::_('PLG_EDITOR_TINYMCE_TEMPLATE_DESCRIPTION_HTML_LAYOUT') . "', url:'" . JUri::root() . "media/editors/tinymce/templates/layout1.html'},
{title: '" . JText::_('PLG_EDITOR_TINYMCE_TEMPLATE_NAME_SIMPLE_SNIPET') . "', description: '" . JText::_('PLG_EDITOR_TINYMCE_TEMPLATE_DESCRIPTION_SIMPLE_SNIPET') . "', url:'" . JUri::root() . "media/editors/tinymce/templates/snippet1.html'}
],";

What I propose is just a little more advanced.

avatar infograf768
infograf768 - comment - 21 Jul 2014

FYI: in the next Joomla release, fr.js Tiny lang file includes translations for the templates:
https://github.com/joomla/joomla-cms/blob/staging/media/editors/tinymce/langs/fr.js#L197
"Layout": "Mise en page",
"HTMLLayout": "Mise en page HTML",
"Simple snippet": "Simple fragment de code",
"Simple HTML snippet": "Simple fragment de code HTML",

But you have here a much better idea!

I suggest you modify your PR this way:

            else
            {
                $templates = 'templates: [';

                foreach (glob(JPATH_ROOT . '/media/editors/tinymce/templates/*.html') as $filename) 
                {
                    $filename = basename($filename, '.html');

                    if ($filename !== 'index')
                    {
                        $lang = JFactory::getLanguage();

                        if ($lang->hasKey('PLG_TINY_' . strtoupper($filename) . '_TITLE'))
                        {
                            $title = JText::_('PLG_TINY_' . strtoupper($filename) . '_TITLE');
                        }
                        else
                        {
                            $title = $filename;
                        }

                        if ($lang->hasKey('PLG_TINY_' . strtoupper($filename) . '_DESC'))
                        {
                            $description = JText::_('PLG_TINY_' . strtoupper($filename) . '_DESC');
                        }
                        else
                        {
                            $description = $filename;
                        }

                        $templates .= '{title: \'' . $title . '\', description: \'' . $description . '\', url:\'' . JUri::root() . 'media/editors/tinymce/templates/' . $filename . '.html\'},';
                    }
                }

                $templates .= '],';
            }

Then add in en-GB.plg_editors_tinymce.ini the 4 strings for our sample:

PLG_TINY_LAYOUT1_DESC="HTML Layout"
PLG_TINY_LAYOUT1_TITLE="Layout"

PLG_TINY_SNIPPET1_DESC="Simple HTML snippet"
PLG_TINY_SNIPPET1_TITLE="Simple Snippet"

When a user adds an html file, charge to him to add the new strings in the overrides (in frontend as well as back-end).

avatar infograf768
infograf768 - comment - 22 Jul 2014

@artur-stepien

let me know if you will update your PR, if not I will create one.

avatar artur-stepien
artur-stepien - comment - 22 Jul 2014

I will create update. Was busy last days.

avatar artur-stepien artur-stepien - reference | - 24 Jul 14
avatar artur-stepien artur-stepien - reference | - 24 Jul 14
avatar brianteeman brianteeman - change - 8 Aug 2014
Labels Added: ?
avatar infograf768 infograf768 - change - 10 Aug 2014
Labels Added: ?
avatar Kubik-Rubik
Kubik-Rubik - comment - 10 Aug 2014

@artur-stepien Works as described, thank you!

avatar Bakual Bakual - reference | - 10 Aug 14
avatar Bakual Bakual - close - 10 Aug 2014
avatar Bakual
Bakual - comment - 10 Aug 2014

Merged into 3.4-dev. Thanks!

avatar Bakual Bakual - change - 10 Aug 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-08-10 19:51:46
avatar Bakual Bakual - close - 10 Aug 2014
avatar wilsonge wilsonge - change - 8 Feb 2015
Milestone Added:

Add a Comment

Login with GitHub to post a comment