6 * Plugin implementation of hook_editor().
8 * - Function signature and returned editor name nust match include filename.
9 * - Returns an array of supported editor versions along with support files.
11 * @todo wysiwyg_<editor>_alter() to add/inject optional libraries like gzip.
13 function wysiwyg_tinymce_editor() {
15 $editor['tinymce'] = array(
16 // Required properties
18 'vendor url' => 'http://tinymce.moxiecode.com',
19 'download url' => 'http://tinymce.moxiecode.com/download.php',
20 'editor path' => wysiwyg_get_path('tinymce'),
21 'library path' => wysiwyg_get_path('tinymce') .
'/jscripts/tiny_mce',
22 'libraries' => array( // We cannot assume that all editors need just one js library.
23 '' => array( // Key may be used in wysiwyg_tinymce_settings() for exec mode.
24 'title' => 'Minified',
25 'files' => array('tiny_mce.js'),
29 'files' => array('tiny_mce_src.js'),
32 'js path' => wysiwyg_get_path('js'),
33 'version callback' => 'wysiwyg_tinymce_version',
34 'themes callback' => 'wysiwyg_tinymce_themes',
35 'settings callback' => 'wysiwyg_tinymce_settings',
36 'plugin callback' => 'wysiwyg_tinymce_plugins',
37 'plugin settings callback' => 'wysiwyg_tinymce_plugin_settings',
38 'versions' => array( // Each version can override global editor properties.
40 // 'include files' => array('tinymce-2.inc'),
41 'js files' => array('tinymce-2.js'),
44 // 'include files' => array('tinymce-3.inc'),
45 'js files' => array('tinymce-3.js'),
46 // 'plugin callback' => 'wysiwyg_tinymce_3_plugins',
49 'title' => 'Minified',
50 'files' => array('tiny_mce.js'),
54 'files' => array('tiny_mce_jquery.js'),
58 'files' => array('tiny_mce_src.js'),
63 // Optional properties
64 'css path' => wysiwyg_get_path('css'),
65 'css files' => array('tinymce.css'),
71 * Detect editor version.
74 * An array containing editor properties as returned from hook_editor().
77 * The installed editor version.
79 function wysiwyg_tinymce_version($editor) {
80 $changelog = wysiwyg_get_path('tinymce') .
'/changelog.txt';
81 if (!file_exists($changelog)) {
82 $changelog = wysiwyg_get_path('tinymce') .
'/changelog';
84 $changelog = fopen($changelog, 'r');
85 $line = fgets($changelog, 50);
86 if (preg_match('@^Version ([\d\.]+)@', $line, $version)) {
93 * Return runtime editor settings for a given wysiwyg profile.
96 * A processed hook_editor() array of editor properties.
98 * An array containing wysiwyg editor profile settings.
100 * The name of a theme/GUI/skin to use.
103 * A settings array to be populated in
104 * Drupal.settings.wysiwygEditor.configs.{editor}
106 function wysiwyg_tinymce_settings($editor, $config, $theme) {
108 'apply_source_formatting' => $config['apply_source_formatting'],
109 'button_tile_map' => TRUE
, // @todo Add a setting for this.
110 'convert_fonts_to_spans' => $config['convert_fonts_to_spans'],
111 'document_base_url' => base_path(),
112 'entity_encoding' => 'raw',
113 'language' => $config['language'],
115 'paste_auto_cleanup_on_paste' => $config['paste_auto_cleanup_on_paste'],
116 'plugins' => array(),
117 'preformatted' => $config['preformatted'],
118 'relative_urls' => FALSE
,
119 'remove_linebreaks' => $config['remove_linebreaks'],
121 'verify_html' => $config['verify_html'],
124 if ($config['css_classes']) {
125 $init['theme_advanced_styles'] = implode(';', array_filter(explode("\n", str_replace("\r", '', $config['css_classes']))));
128 if ($config['css_setting'] == 'theme') {
129 $css = path_to_theme() .
'/style.css';
130 if (file_exists($css)) {
131 $init['content_css'] = base_path() .
$css;
134 else if ($config['css_setting'] == 'self') {
135 $init['content_css'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
138 // Find the enabled buttons and the button row they belong on.
139 // Also map the plugin metadata for each button.
140 // @todo What follows is a pain; needs a rewrite.
141 if (!empty($config['buttons']) && is_array($config['buttons'])) {
142 // $init['buttons'] are stacked into $init['theme_advanced_buttons1'] later.
143 // @todo Add a toolbar designer based on jQuery UI.
144 $init['buttons'] = array();
145 // Only array keys in $init['extensions'] matter; added to $init['plugins']
147 $init['extensions'] = array();
148 // $init['extended_valid_elements'] are just stacked, unique'd later, and
149 // transformed into a comma-separated string in wysiwyg_editor_add_settings().
150 // @todo Needs a complete plugin API redesign using arrays for
151 // tag => attributes definitions and array_merge_recursive().
152 $init['extended_valid_elements'] = array();
154 $plugins = wysiwyg_editor_get_plugins($editor['name']);
155 foreach ($config['buttons'] as
$plugin => $buttons) {
156 foreach ($buttons as
$button => $enabled) {
157 // Iterate separately over buttons and extensions properties.
158 foreach (array('buttons', 'extensions') as
$type) {
159 // Skip unavailable plugins.
160 if (!isset($plugins[$plugin][$type][$button])) {
164 if ($type == 'buttons') {
165 $init['buttons'][] = $button;
167 // Add external plugins to the list of extensions.
168 if ($type == 'buttons' && !isset($plugins[$plugin]['internal'])) {
169 $init['extensions'][_wysiwyg_tinymce_plugin_name('add', $plugin)] = 1;
171 // Add internal buttons that also need to be loaded as extension.
172 else if ($type == 'buttons' && isset($plugins[$plugin]['load'])) {
173 $init['extensions'][$plugin] = 1;
175 // Add plain extensions.
176 else if ($type == 'extensions') {
177 $init['extensions'][$plugin] = 1;
179 // Allow plugins to add valid HTML elements.
180 if (!empty($plugins[$plugin]['extended_valid_elements'])) {
181 $init['extended_valid_elements'] = array_merge($init['extended_valid_elements'], $plugins[$plugin]['extended_valid_elements']);
183 // Allow plugins to add or override global configuration settings.
184 if (!empty($plugins[$plugin]['options'])) {
185 $init = array_merge($init, $plugins[$plugin]['options']);
191 $init['extended_valid_elements'] = array_unique($init['extended_valid_elements']);
192 if ($init['extensions']) {
193 $init['plugins'] = array_keys($init['extensions']);
194 unset($init['extensions']);
196 unset($init['extensions']);
200 // Add theme-specific settings.
204 'theme_advanced_blockformats' => $config['block_formats'] ?
$config['block_formats'] : 'p,h2,h3,h4,h5,h6',
205 'theme_advanced_path_location' => $config['path_loc'],
206 'theme_advanced_resizing' => $config['resizing'],
207 'theme_advanced_resize_horizontal' => FALSE
,
208 'theme_advanced_resizing_use_cookie' => FALSE
,
209 'theme_advanced_toolbar_location' => $config['toolbar_loc'],
210 'theme_advanced_toolbar_align' => $config['toolbar_align'],
211 // Note: These rows need to be set to NULL otherwise TinyMCE loads its
212 // own buttons as defined in advanced theme.
213 'theme_advanced_buttons1' => array(),
214 'theme_advanced_buttons2' => array(),
215 'theme_advanced_buttons3' => array(),
218 for ($i = 0; $i < count($init['buttons']); $i++) {
219 $init['theme_advanced_buttons1'][] = $init['buttons'][$i];
223 unset($init['buttons']);
229 * Determine available editor themes or check/reset a given one.
232 * A processed hook_editor() array of editor properties.
234 * A wysiwyg editor profile.
237 * An array of theme names. The first returned name should be the default
240 function wysiwyg_tinymce_themes($editor, $profile) {
243 $dir = $editor['library path'] . '/themes/';
244 if (is_dir($dir) && $dh = opendir($dir)) {
245 while (($file = readdir($dh)) !== FALSE) {
246 if (!in_array($file, array('.', '..', 'CVS', '.svn')) && is_dir($dir . $file)) {
247 $themes[$file] = $file;
255 return array('advanced', 'simple');
259 * Build a JS settings array of external plugins that need to be loaded separately.
261 * TinyMCE requires that external plugins (i.e. not residing in the editor's
262 * directory) are loaded (once) after the editor has been initialized.
264 function wysiwyg_tinymce_plugin_settings($editor, $profile, $info) {
266 foreach ($info as
$name => $plugin) {
267 if (!isset($plugin['internal'])) {
268 $plugins[$name] = base_path() .
$plugin['path'];
275 * Add or remove leading hiven to/of external plugin names.
277 * TinyMCE requires that external plugins, which should not be loaded from
278 * its own plugin repository are prefixed with a hiven in the name.
281 * Operation to perform, 'add' or 'remove' (hiven).
282 * @param string $name
285 function _wysiwyg_tinymce_plugin_name($op, $name) {
287 if (strpos($name, '-') !== 0) {
292 else if ($op == 'remove') {
293 if (strpos($name, '-') === 0) {
294 return substr($name, 1);
301 * Return internal plugins for TinyMCE; semi-implementation of hook_wysiwyg_plugin().
303 function wysiwyg_tinymce_plugins($editor) {
306 'path' => $editor['library path'] .
'/themes/advanced',
308 'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
309 'strikethrough' => t('Strike-through'),
310 'justifyleft' => t('Align left'), 'justifycenter' => t('Align center'), 'justifyright' => t('Align right'), 'justifyfull' => t('Justify'),
311 'bullist' => t('Bullet list'), 'numlist' => t('Numbered list'),
312 'outdent' => t('Outdent'), 'indent' => t('Indent'),
313 'undo' => t('Undo'), 'redo' => t('Redo'),
314 'link' => t('Link'), 'unlink' => t('Unlink'), 'anchor' => t('Anchor'),
315 'image' => t('Image'),
316 'cleanup' => t('Clean-up'),
317 'forecolor' => t('Forecolor'), 'backcolor' => t('Backcolor'),
318 'sup' => t('Sup'), 'sub' => t('Sub'),
319 'code' => t('Source code'),
320 'hr' => t('Horizontal rule'),
321 'cut' => t('Cut'), 'copy' => t('Copy'), 'paste' => t('Paste'),
322 'visualaid' => t('Visual aid'),
323 'removeformat' => t('Remove format'),
324 'charmap' => t('Character map'),
325 'help' => t('Help')),
329 'path' => $editor['library path'] .
'/plugins/advhr',
330 'buttons' => array('advhr' => t('Advanced horizontal rule')),
331 'extended_valid_elements' => array('hr[class|width|size|noshade]'),
332 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advhr',
337 'path' => $editor['library path'] .
'/plugins/advimage',
338 'extensions' => array('advimage' => t('Advanced image')),
339 'extended_valid_elements' => array('img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name]'),
340 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advimage',
345 'path' => $editor['library path'] .
'/plugins/advlink',
346 'extensions' => array('advlink' => t('Advanced link')),
347 'extended_valid_elements' => array('a[name|href|target|title|onclick]'),
348 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advlink',
353 'path' => $editor['library path'] .
'/plugins/autosave',
354 'extensions' => array('autosave' => t('Auto save')),
355 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/autosave',
359 'contextmenu' => array(
360 'path' => $editor['library path'] .
'/plugins/contextmenu',
361 'extensions' => array('contextmenu' => t('Context menu')),
362 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
365 'directionality' => array(
366 'path' => $editor['library path'] .
'/plugins/directionality',
367 'buttons' => array('ltr' => t('Left-to-right'), 'rtl' => t('Right-to-left')),
368 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality',
373 'path' => $editor['library path'] .
'/plugins/emotions',
374 'buttons' => array('emotions' => t('Emotions')),
375 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/emotions',
380 'path' => $editor['library path'] .
'/plugins/flash',
381 'buttons' => array('flash' => t('Flash')),
382 'extended_valid_elements' => array('img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|obj|param|embed]'),
383 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/flash',
388 'path' => $editor['library path'] .
'/plugins/font',
389 'buttons' => array('formatselect' => t('HTML block format'), 'fontselect' => t('Font'), 'fontsizeselect' => t('Font size'), 'styleselect' => t('Font style')),
390 'extended_valid_elements' => array('font[face|size|color|style],span[class|align|style]'),
391 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/font',
394 'fullscreen' => array(
395 'path' => $editor['library path'] .
'/plugins/fullscreen',
396 'buttons' => array('fullscreen' => t('Fullscreen')),
397 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullscreen',
401 'inlinepopups' => array(
402 'path' => $editor['library path'] .
'/plugins/inlinepopups',
403 'extensions' => array('inlinepopups' => t('Inline popups')),
405 'dialog_type' => array('modal'),
407 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/inlinepopups',
411 'insertdatetime' => array(
412 'path' => $editor['library path'] .
'/plugins/insertdatetime',
413 'buttons' => array('insertdate' => t('Insert date'), 'inserttime' => t('Insert time')),
415 'plugin_insertdate_dateFormat' => array('%Y-%m-%d'),
416 'plugin_insertdate_timeFormat' => array('%H:%M:%S'),
418 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/insertdatetime',
423 'path' => $editor['library path'] .
'/plugins/layer',
424 'buttons' => array('insertlayer' => t('Insert layer'), 'moveforward' => t('Move forward'), 'movebackward' => t('Move backward'), 'absolute' => t('Absolute')),
425 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/layer',
430 'path' => $editor['library path'] .
'/plugins/paste',
431 'buttons' => array('pastetext' => t('Paste text'), 'pasteword' => t('Paste from Word'), 'selectall' => t('Select all')),
432 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/paste',
437 'path' => $editor['library path'] .
'/plugins/preview',
438 'buttons' => array('preview' => t('Preview')),
439 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/preview',
444 'path' => $editor['library path'] .
'/plugins/print',
445 'buttons' => array('print' => t('Print')),
446 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/print',
450 'searchreplace' => array(
451 'path' => $editor['library path'] .
'/plugins/searchreplace',
452 'buttons' => array('search' => t('Search'), 'replace' => t('Replace')),
453 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/searchreplace',
458 'path' => $editor['library path'] .
'/plugins/style',
459 'buttons' => array('styleprops' => t('Style properties')),
460 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/style',
465 'path' => $editor['library path'] .
'/plugins/table',
466 'buttons' => array('tablecontrols' => t('Table')),
467 'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/table',