as an example I use the code from init_tinymce(). Just three lines to change:
1. In top of the function, initialize $temp to false:
- Code: Select all
function init_tinymce($classes = array(), $config = false) {
global $sl, $cf, $plugin_cf, $pth, $hjs, $o, $h, $u, $l, $sn, $onload;
static $run = 0;
$temp = false; //Add this line
include_tinymce();
2. After the foreach - loop:
- Code: Select all
foreach ($inits as $init) {
$temp = explode('_', basename($init, '.js'));
if (isset($temp[1]) && $temp[1] === $config) {
$tiny_mode = $config;
$isFile = false;
$initFile = $pth['folder']['plugins'] . 'tinymce/' . 'inits/init_' . $tiny_mode . '.js';
break;
}
}
if(!$initFile){
//$initFile = $config;
$temp = $config; // this line is new
}
3. After inclusion of links.php
- Code: Select all
include_once $pth['folder']['plugins'] . 'tinymce/' . 'links.php';
//$temp = file_get_contents($initFile);
if ($temp === false) {
$temp = file_get_contents($initFile); //use $initFile only if $temp is still false
}
$temp = str_replace('%TINY_FOLDER%', $pth['folder']['plugins'] . 'tinymce/', $temp);
$temp = str_replace('%LANGUAGE%', $tiny_language, $temp);
Now a plugin author can copy a shipped init_xxx.js from the /editor/inits - folder to change it for his needs and to put it to his plugin-folder.
It's possible to use the placeholders too, so he must not mess around with dynamic settings like baseHref or the internal-links.
Adjusting such an existing init_xxx.js should be easy done.
@cmb:
I'll agree with you that it's the best choice to use existing editor-configurations like "full" "minimal" etc, this way:
- Code: Select all
init_editor(array('class1', 'class2'), 'minimal')
The integration of those "special editors" should be done with the changed code above, together with a check, if the plugin provides config-files for the configured editor.
A plugin can do that this way:
- Code: Select all
$config = false;
//look for the name of the configured editor
$myEditor = $cf['editor']['external'];
$config = @file_get_contents('myconfig_' . $myEditor . 'js'); //use '@' to avoid PHP - warnings
if ($config) {
include_editor($classes, $config);
}
else {
//throw a message: No compatible editor installed!
}
IMO that's a flexible and easy way to include editors to plugins. No need to mess around with filebrowsers, baseHref or other dynamic settings of unknown editors. No need to mess around with three single functions and coding of a complete editor-setups.
And adding a new editor to the plugin is done with only a new config-file
At the end I think it's better this way, instead calling the function with a path to a static file. It's somehow as I meant in a post at the beginning of this thread:
myself wrote:if a plugin just needs another skin or another toolbar, maybe it's a good idea when $config only overwrites the default editor-configuration.
So init_editor() will always create a working editor ...
KR
Holger

