User tests: Successful: Unsuccessful:
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
Title |
|
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.
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 :)
One more small code correction please
if ( $filename != 'index' )
should be
if ($filename != 'index')
I don't think his travis build error is related to my code
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
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
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.
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.
That way would also give a possibility of overriding or adding descriptions in Language Overriding.
Joomla language strings are not usable into TinyMCE. Tiny uses exclusively these:
https://github.com/joomla/joomla-cms/tree/staging/media/editors/tinymce/langs
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.
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).
let me know if you will update your PR, if not I will create one.
I will create update. Was busy last days.
Labels |
Added:
?
|
Labels |
Added:
?
|
@artur-stepien Works as described, thank you!
Merged into 3.4-dev
. Thanks!
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2014-08-10 19:51:46 |
Milestone |
Added: |
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.