<?php
// $Id$
+/**
+ * @file
+ * Editor integration functions for TinyMCE.
+ */
/**
* Plugin implementation of hook_editor().
*
- * - Function signature and returned editor name nust match include filename.
- * - Returns an array of supported editor versions along with support files.
- *
* @todo wysiwyg_<editor>_alter() to add/inject optional libraries like gzip.
*/
function wysiwyg_tinymce_editor() {
- $editor = array();
$editor['tinymce'] = array(
- // Required properties
'title' => 'TinyMCE',
'vendor url' => 'http://tinymce.moxiecode.com',
'download url' => 'http://tinymce.moxiecode.com/download.php',
'library path' => wysiwyg_get_path('tinymce') . '/jscripts/tiny_mce',
- 'libraries' => array( // We cannot assume that all editors need just one js library.
- '' => array( // Key may be used in wysiwyg_tinymce_settings() for exec mode.
+ 'libraries' => array(
+ '' => array(
'title' => 'Minified',
'files' => array('tiny_mce.js'),
),
),
),
'proxy plugin settings callback' => 'wysiwyg_tinymce_proxy_plugin_settings',
- 'versions' => array( // Each version can override global editor properties.
+ 'versions' => array(
'2.1' => array(
- // 'include files' => array('tinymce-2.inc'),
'js files' => array('tinymce-2.js'),
'css files' => array('tinymce-2.css'),
'download url' => 'http://sourceforge.net/project/showfiles.php?group_id=103281&package_id=111430&release_id=557383',
),
'3.1' => array(
- // 'include files' => array('tinymce-3.inc'),
'js files' => array('tinymce-3.js'),
'css files' => array('tinymce-3.css'),
- // 'plugin callback' => 'wysiwyg_tinymce_3_plugins',
'libraries' => array(
'' => array(
'title' => 'Minified',
* The installed editor version.
*/
function wysiwyg_tinymce_version($editor) {
- $script = $editor['library path'] .'/tiny_mce.js';
+ $script = $editor['library path'] . '/tiny_mce.js';
$script = fopen($script, 'r');
// Version is contained in the first 80 chars.
$line = fgets($script, 80);
// 3.x: majorVersion:'3',minorVersion:'2.0.1'
if (preg_match('@majorVersion[=:]["\'](\d).+?minorVersion[=:]["\']([\d\.]+)@', $line, $version)) {
fclose($script);
- return $version[1] .'.'. $version[2];
+ return $version[1] . '.' . $version[2];
+ }
+ fclose($script);
+}
+
+/**
+ * Determine available editor themes or check/reset a given one.
+ *
+ * @param $editor
+ * A processed hook_editor() array of editor properties.
+ * @param $profile
+ * A wysiwyg editor profile.
+ *
+ * @return
+ * An array of theme names. The first returned name should be the default
+ * theme name.
+ */
+function wysiwyg_tinymce_themes($editor, $profile) {
+ /*
+ $themes = array();
+ $dir = $editor['library path'] . '/themes/';
+ if (is_dir($dir) && $dh = opendir($dir)) {
+ while (($file = readdir($dh)) !== FALSE) {
+ if (!in_array($file, array('.', '..', 'CVS', '.svn')) && is_dir($dir . $file)) {
+ $themes[$file] = $file;
+ }
+ }
+ closedir($dh);
+ asort($themes);
}
+ return $themes;
+ */
+ return array('advanced', 'simple');
}
/**
* Drupal.settings.wysiwyg.configs.{editor}
*/
function wysiwyg_tinymce_settings($editor, $config, $theme) {
- $init = array(
+ $settings = array(
'button_tile_map' => TRUE, // @todo Add a setting for this.
'document_base_url' => base_path(),
'mode' => 'none',
'entities' => '160,nbsp,173,shy,8194,ensp,8195,emsp,8201,thinsp,8204,zwnj,8205,zwj,8206,lrm,8207,rlm',
);
if (isset($config['apply_source_formatting'])) {
- $init['apply_source_formatting'] = $config['apply_source_formatting'];
+ $settings['apply_source_formatting'] = $config['apply_source_formatting'];
}
if (isset($config['convert_fonts_to_spans'])) {
- $init['convert_fonts_to_spans'] = $config['convert_fonts_to_spans'];
+ $settings['convert_fonts_to_spans'] = $config['convert_fonts_to_spans'];
}
if (isset($config['language'])) {
- $init['language'] = $config['language'];
+ $settings['language'] = $config['language'];
}
if (isset($config['paste_auto_cleanup_on_paste'])) {
- $init['paste_auto_cleanup_on_paste'] = $config['paste_auto_cleanup_on_paste'];
+ $settings['paste_auto_cleanup_on_paste'] = $config['paste_auto_cleanup_on_paste'];
}
if (isset($config['preformatted'])) {
- $init['preformatted'] = $config['preformatted'];
+ $settings['preformatted'] = $config['preformatted'];
}
if (isset($config['remove_linebreaks'])) {
- $init['remove_linebreaks'] = $config['remove_linebreaks'];
+ $settings['remove_linebreaks'] = $config['remove_linebreaks'];
}
if (isset($config['verify_html'])) {
- $init['verify_html'] = $config['verify_html'];
+ $settings['verify_html'] = $config['verify_html'];
}
if (!empty($config['css_classes'])) {
- $init['theme_advanced_styles'] = implode(';', array_filter(explode("\n", str_replace("\r", '', $config['css_classes']))));
+ $settings['theme_advanced_styles'] = implode(';', array_filter(explode("\n", str_replace("\r", '', $config['css_classes']))));
}
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
- $init['content_css'] = implode(',', wysiwyg_get_css());
+ $settings['content_css'] = implode(',', wysiwyg_get_css());
}
else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
- $init['content_css'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
+ $settings['content_css'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
}
}
// Also map the plugin metadata for each button.
// @todo What follows is a pain; needs a rewrite.
if (!empty($config['buttons']) && is_array($config['buttons'])) {
- // $init['buttons'] are stacked into $init['theme_advanced_buttons1'] later.
+ // $settings['buttons'] are stacked into
+ // $settings['theme_advanced_buttons1'] later.
// @todo Add a toolbar designer based on jQuery UI.
- $init['buttons'] = array();
- // Only array keys in $init['extensions'] matter; added to $init['plugins']
- // later.
- $init['extensions'] = array();
- // $init['extended_valid_elements'] are just stacked, unique'd later, and
- // transformed into a comma-separated string in wysiwyg_add_editor_settings().
+ $settings['buttons'] = array();
+ // Only array keys in $settings['extensions'] matter; added to
+ // $settings['plugins'] later.
+ $settings['extensions'] = array();
+ // $settings['extended_valid_elements'] are just stacked, unique'd later,
+ // and transformed into a comma-separated string in
+ // wysiwyg_add_editor_settings().
// @todo Needs a complete plugin API redesign using arrays for
// tag => attributes definitions and array_merge_recursive().
- $init['extended_valid_elements'] = array();
+ $settings['extended_valid_elements'] = array();
$plugins = wysiwyg_get_plugins($editor['name']);
foreach ($config['buttons'] as $plugin => $buttons) {
}
// Add buttons.
if ($type == 'buttons') {
- $init['buttons'][] = $button;
+ $settings['buttons'][] = $button;
}
// Add external Drupal plugins to the list of extensions.
if ($type == 'buttons' && !empty($plugins[$plugin]['proxy'])) {
- $init['extensions'][_wysiwyg_tinymce_plugin_name('add', $button)] = 1;
+ $settings['extensions'][_wysiwyg_tinymce_plugin_name('add', $button)] = 1;
}
// Add external plugins to the list of extensions.
else if ($type == 'buttons' && empty($plugins[$plugin]['internal'])) {
- $init['extensions'][_wysiwyg_tinymce_plugin_name('add', $plugin)] = 1;
+ $settings['extensions'][_wysiwyg_tinymce_plugin_name('add', $plugin)] = 1;
}
// Add internal buttons that also need to be loaded as extension.
else if ($type == 'buttons' && !empty($plugins[$plugin]['load'])) {
- $init['extensions'][$plugin] = 1;
+ $settings['extensions'][$plugin] = 1;
}
// Add plain extensions.
else if ($type == 'extensions' && !empty($plugins[$plugin]['load'])) {
- $init['extensions'][$plugin] = 1;
+ $settings['extensions'][$plugin] = 1;
}
// Allow plugins to add valid HTML elements.
if (!empty($plugins[$plugin]['extended_valid_elements'])) {
- $init['extended_valid_elements'] = array_merge($init['extended_valid_elements'], $plugins[$plugin]['extended_valid_elements']);
+ $settings['extended_valid_elements'] = array_merge($settings['extended_valid_elements'], $plugins[$plugin]['extended_valid_elements']);
}
// Allow plugins to add or override global configuration settings.
if (!empty($plugins[$plugin]['options'])) {
- $init = array_merge($init, $plugins[$plugin]['options']);
+ $settings = array_merge($settings, $plugins[$plugin]['options']);
}
}
}
}
// Clean-up.
- $init['extended_valid_elements'] = array_unique($init['extended_valid_elements']);
- if ($init['extensions']) {
- $init['plugins'] = array_keys($init['extensions']);
- unset($init['extensions']);
- } else {
- unset($init['extensions']);
+ $settings['extended_valid_elements'] = array_unique($settings['extended_valid_elements']);
+ if ($settings['extensions']) {
+ $settings['plugins'] = array_keys($settings['extensions']);
}
+ unset($settings['extensions']);
}
// Add theme-specific settings.
switch ($theme) {
case 'advanced':
- $init += array(
+ $settings += array(
'theme_advanced_resize_horizontal' => FALSE,
'theme_advanced_resizing_use_cookie' => FALSE,
'theme_advanced_path_location' => isset($config['path_loc']) ? $config['path_loc'] : 'bottom',
'theme_advanced_toolbar_align' => isset($config['toolbar_align']) ? $config['toolbar_align'] : 'left',
);
if (isset($config['block_formats'])) {
- $init['theme_advanced_blockformats'] = $config['block_formats'];
+ $settings['theme_advanced_blockformats'] = $config['block_formats'];
}
- if (isset($init['buttons'])) {
+ if (isset($settings['buttons'])) {
// These rows explicitly need to be set to be empty, otherwise TinyMCE
// loads its default buttons of the advanced theme for each row.
- $init += array(
+ $settings += array(
'theme_advanced_buttons1' => array(),
'theme_advanced_buttons2' => array(),
'theme_advanced_buttons3' => array(),
);
// @todo Allow to sort/arrange editor buttons.
- for ($i = 0; $i < count($init['buttons']); $i++) {
- $init['theme_advanced_buttons1'][] = $init['buttons'][$i];
+ for ($i = 0; $i < count($settings['buttons']); $i++) {
+ $settings['theme_advanced_buttons1'][] = $settings['buttons'][$i];
}
}
break;
}
- unset($init['buttons']);
+ unset($settings['buttons']);
// Convert the config values into the form expected by TinyMCE.
- foreach ($init as $key => $value) {
+ foreach ($settings as $key => $value) {
if (is_bool($value)) {
continue;
}
if (is_array($value)) {
- $init[$key] = implode(',', $init[$key]);
+ $settings[$key] = implode(',', $settings[$key]);
}
}
- return $init;
-}
-
-/**
- * Determine available editor themes or check/reset a given one.
- *
- * @param $editor
- * A processed hook_editor() array of editor properties.
- * @param $profile
- * A wysiwyg editor profile.
- *
- * @return
- * An array of theme names. The first returned name should be the default
- * theme name.
- */
-function wysiwyg_tinymce_themes($editor, $profile) {
- /*
- $themes = array();
- $dir = $editor['library path'] . '/themes/';
- if (is_dir($dir) && $dh = opendir($dir)) {
- while (($file = readdir($dh)) !== FALSE) {
- if (!in_array($file, array('.', '..', 'CVS', '.svn')) && is_dir($dir . $file)) {
- $themes[$file] = $file;
- }
- }
- closedir($dh);
- asort($themes);
- }
- return $themes;
- */
- return array('advanced', 'simple');
+ return $settings;
}
/**
// Populate required plugin settings.
$settings[$name] = $plugin['dialog settings'] + array(
'title' => $plugin['title'],
- 'icon' => base_path() . $plugin['icon path'] .'/'. $plugin['icon file'],
+ 'icon' => base_path() . $plugin['icon path'] . '/' . $plugin['icon file'],
'iconTitle' => $plugin['icon title'],
// @todo These should only be set if the plugin defined them.
- 'css' => base_path() . $plugin['css path'] .'/'. $plugin['css file'],
+ 'css' => base_path() . $plugin['css path'] . '/' . $plugin['css file'],
);
}
return $settings;
*
* TinyMCE requires that external plugins, which should not be loaded from
* its own plugin repository are prefixed with a hiven in the name.
- *
+ *
* @param string $op
* Operation to perform, 'add' or 'remove' (hiven).
* @param string $name
function _wysiwyg_tinymce_plugin_name($op, $name) {
if ($op == 'add') {
if (strpos($name, '-') !== 0) {
- return '-'. $name;
+ return '-' . $name;
}
return $name;
}
function wysiwyg_tinymce_plugins($editor) {
$plugins = array(
'default' => array(
- 'path' => $editor['library path'] .'/themes/advanced',
+ 'path' => $editor['library path'] . '/themes/advanced',
'buttons' => array(
'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
'strikethrough' => t('Strike-through'),
'visualaid' => t('Visual aid'),
'removeformat' => t('Remove format'),
'charmap' => t('Character map'),
- 'help' => t('Help')),
+ 'help' => t('Help'),
+ ),
'internal' => TRUE,
),
'advhr' => array(
- 'path' => $editor['library path'] .'/plugins/advhr',
+ 'path' => $editor['library path'] . '/plugins/advhr',
'buttons' => array('advhr' => t('Advanced horizontal rule')),
'extended_valid_elements' => array('hr[class|width|size|noshade]'),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advhr',
'load' => TRUE,
),
'advimage' => array(
- 'path' => $editor['library path'] .'/plugins/advimage',
+ 'path' => $editor['library path'] . '/plugins/advimage',
'extensions' => array('advimage' => t('Advanced image')),
'extended_valid_elements' => array('img[src|alt|title|align|width|height|hspace|vspace|border|style|class|onmouseover|onmouseout|id|name]'),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advimage',
'load' => TRUE,
),
'advlink' => array(
- 'path' => $editor['library path'] .'/plugins/advlink',
+ 'path' => $editor['library path'] . '/plugins/advlink',
'extensions' => array('advlink' => t('Advanced link')),
'extended_valid_elements' => array('a[name|href|target|title|class|onfocus|onblur|onclick|ondlbclick|onmousedown|onmouseup|onmouseover|onmouseout|onkeypress|onkeydown|onkeyup|id|style|rel]'),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advlink',
'load' => TRUE,
),
'autosave' => array(
- 'path' => $editor['library path'] .'/plugins/autosave',
+ 'path' => $editor['library path'] . '/plugins/autosave',
'extensions' => array('autosave' => t('Auto save')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/autosave',
'internal' => TRUE,
'load' => TRUE,
),
'contextmenu' => array(
- 'path' => $editor['library path'] .'/plugins/contextmenu',
+ 'path' => $editor['library path'] . '/plugins/contextmenu',
'extensions' => array('contextmenu' => t('Context menu')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
'internal' => TRUE,
'load' => TRUE,
),
'directionality' => array(
- 'path' => $editor['library path'] .'/plugins/directionality',
+ 'path' => $editor['library path'] . '/plugins/directionality',
'buttons' => array('ltr' => t('Left-to-right'), 'rtl' => t('Right-to-left')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality',
'internal' => TRUE,
'load' => TRUE,
),
'emotions' => array(
- 'path' => $editor['library path'] .'/plugins/emotions',
+ 'path' => $editor['library path'] . '/plugins/emotions',
'buttons' => array('emotions' => t('Emotions')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/emotions',
'internal' => TRUE,
'load' => TRUE,
),
'font' => array(
- 'path' => $editor['library path'] .'/plugins/font',
+ 'path' => $editor['library path'] . '/plugins/font',
'buttons' => array('formatselect' => t('HTML block format'), 'fontselect' => t('Font'), 'fontsizeselect' => t('Font size'), 'styleselect' => t('Font style')),
'extended_valid_elements' => array('font[face|size|color|style],span[class|align|style]'),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/font',
'internal' => TRUE,
),
'fullscreen' => array(
- 'path' => $editor['library path'] .'/plugins/fullscreen',
+ 'path' => $editor['library path'] . '/plugins/fullscreen',
'buttons' => array('fullscreen' => t('Fullscreen')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullscreen',
'internal' => TRUE,
'load' => TRUE,
),
'inlinepopups' => array(
- 'path' => $editor['library path'] .'/plugins/inlinepopups',
+ 'path' => $editor['library path'] . '/plugins/inlinepopups',
'extensions' => array('inlinepopups' => t('Inline popups')),
'options' => array(
'dialog_type' => array('modal'),
'load' => TRUE,
),
'insertdatetime' => array(
- 'path' => $editor['library path'] .'/plugins/insertdatetime',
+ 'path' => $editor['library path'] . '/plugins/insertdatetime',
'buttons' => array('insertdate' => t('Insert date'), 'inserttime' => t('Insert time')),
'options' => array(
'plugin_insertdate_dateFormat' => array('%Y-%m-%d'),
'load' => TRUE,
),
'layer' => array(
- 'path' => $editor['library path'] .'/plugins/layer',
+ 'path' => $editor['library path'] . '/plugins/layer',
'buttons' => array('insertlayer' => t('Insert layer'), 'moveforward' => t('Move forward'), 'movebackward' => t('Move backward'), 'absolute' => t('Absolute')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/layer',
'internal' => TRUE,
'load' => TRUE,
),
'paste' => array(
- 'path' => $editor['library path'] .'/plugins/paste',
+ 'path' => $editor['library path'] . '/plugins/paste',
'buttons' => array('pastetext' => t('Paste text'), 'pasteword' => t('Paste from Word'), 'selectall' => t('Select all')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/paste',
'internal' => TRUE,
'load' => TRUE,
),
'preview' => array(
- 'path' => $editor['library path'] .'/plugins/preview',
+ 'path' => $editor['library path'] . '/plugins/preview',
'buttons' => array('preview' => t('Preview')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/preview',
'internal' => TRUE,
'load' => TRUE,
),
'print' => array(
- 'path' => $editor['library path'] .'/plugins/print',
+ 'path' => $editor['library path'] . '/plugins/print',
'buttons' => array('print' => t('Print')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/print',
'internal' => TRUE,
'load' => TRUE,
),
'searchreplace' => array(
- 'path' => $editor['library path'] .'/plugins/searchreplace',
+ 'path' => $editor['library path'] . '/plugins/searchreplace',
'buttons' => array('search' => t('Search'), 'replace' => t('Replace')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/searchreplace',
'internal' => TRUE,
'load' => TRUE,
),
'style' => array(
- 'path' => $editor['library path'] .'/plugins/style',
+ 'path' => $editor['library path'] . '/plugins/style',
'buttons' => array('styleprops' => t('Style properties')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/style',
'internal' => TRUE,
'load' => TRUE,
),
'table' => array(
- 'path' => $editor['library path'] .'/plugins/table',
+ 'path' => $editor['library path'] . '/plugins/table',
'buttons' => array('tablecontrols' => t('Table')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/table',
'internal' => TRUE,
);
if (version_compare($editor['installed version'], '3', '<')) {
$plugins['flash'] = array(
- 'path' => $editor['library path'] .'/plugins/flash',
+ 'path' => $editor['library path'] . '/plugins/flash',
'buttons' => array('flash' => t('Flash')),
'extended_valid_elements' => array('img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|obj|param|embed]'),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/flash',
}
if (version_compare($editor['installed version'], '2.0.6', '>')) {
$plugins['media'] = array(
- 'path' => $editor['library path'] .'/plugins/media',
+ 'path' => $editor['library path'] . '/plugins/media',
'buttons' => array('media' => t('Media')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/media',
- 'internal' => TRUE,
+ 'internal' => TRUE,
'load' => TRUE,
);
$plugins['xhtmlxtras'] = array(
- 'path' => $editor['library path'] .'/plugins/xhtmlxtras',
+ 'path' => $editor['library path'] . '/plugins/xhtmlxtras',
'buttons' => array('cite' => t('Citation'), 'del' => t('Deleted'), 'abbr' => t('Abbreviation'), 'acronym' => t('Acronym'), 'ins' => t('Inserted')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/xhtmlxtras',
'internal' => TRUE,
}
if (version_compare($editor['installed version'], '3', '>')) {
$plugins['bbcode'] = array(
- 'path' => $editor['library path'] .'/plugins/bbcode',
+ 'path' => $editor['library path'] . '/plugins/bbcode',
'extensions' => array('bbcode' => t('BBCode')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/bbcode',
'internal' => TRUE,
'load' => TRUE,
);
$plugins['safari'] = array(
- 'path' => $editor['library path'] .'/plugins/safari',
+ 'path' => $editor['library path'] . '/plugins/safari',
'extensions' => array('safari' => t('Safari compatibility')),
'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/safari',
'internal' => TRUE,