function wysiwyg_tinymce_settings in Wysiwyg 6
Same name and namespace in other branches
- 5.2 editors/tinymce.inc \wysiwyg_tinymce_settings()
- 5 editors/tinymce.inc \wysiwyg_tinymce_settings()
- 6.2 editors/tinymce.inc \wysiwyg_tinymce_settings()
- 7.2 editors/tinymce.inc \wysiwyg_tinymce_settings()
Return runtime editor settings for a given wysiwyg profile.
Parameters
$editor: A processed hook_editor() array of editor properties.
$config: An array containing wysiwyg editor profile settings.
$theme: The name of a theme/GUI/skin to use.
Return value
A settings array to be populated in Drupal.settings.wysiwyg.configs.{editor}
1 string reference to 'wysiwyg_tinymce_settings'
- wysiwyg_tinymce_editor in editors/
tinymce.inc - Plugin implementation of hook_editor().
File
- editors/
tinymce.inc, line 105
Code
function wysiwyg_tinymce_settings($editor, $config, $theme) {
$init = array(
'button_tile_map' => TRUE,
// @todo Add a setting for this.
'document_base_url' => base_path(),
'mode' => 'none',
'plugins' => array(),
'theme' => $theme,
'width' => '100%',
// Strict loading mode must be enabled; otherwise TinyMCE would use
// document.write() in IE and Chrome.
'strict_loading_mode' => TRUE,
// TinyMCE's URL conversion magic breaks Drupal modules that use a special
// syntax for paths. This makes 'relative_urls' obsolete.
'convert_urls' => FALSE,
// The default entity_encoding ('named') converts too many characters in
// languages (like Greek). Since Drupal supports Unicode, we only convert
// HTML control characters and invisible characters. TinyMCE always converts
// XML default characters '&', '<', '>'.
'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'];
}
if (isset($config['convert_fonts_to_spans'])) {
$init['convert_fonts_to_spans'] = $config['convert_fonts_to_spans'];
}
if (isset($config['language'])) {
$init['language'] = $config['language'];
}
if (isset($config['paste_auto_cleanup_on_paste'])) {
$init['paste_auto_cleanup_on_paste'] = $config['paste_auto_cleanup_on_paste'];
}
if (isset($config['preformatted'])) {
$init['preformatted'] = $config['preformatted'];
}
if (isset($config['remove_linebreaks'])) {
$init['remove_linebreaks'] = $config['remove_linebreaks'];
}
if (isset($config['verify_html'])) {
$init['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']))));
}
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
$init['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(),
));
}
}
}
// Find the enabled buttons and the button row they belong on.
// 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.
// @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().
// @todo Needs a complete plugin API redesign using arrays for
// tag => attributes definitions and array_merge_recursive().
$init['extended_valid_elements'] = array();
$plugins = wysiwyg_get_plugins($editor['name']);
foreach ($config['buttons'] as $plugin => $buttons) {
foreach ($buttons as $button => $enabled) {
// Iterate separately over buttons and extensions properties.
foreach (array(
'buttons',
'extensions',
) as $type) {
// Skip unavailable plugins.
if (!isset($plugins[$plugin][$type][$button])) {
continue;
}
// Add buttons.
if ($type == 'buttons') {
$init['buttons'][] = $button;
}
// Add external plugins to the list of extensions.
if ($type == 'buttons' && empty($plugins[$plugin]['internal'])) {
$init['extensions'][_wysiwyg_tinymce_plugin_name('add', $plugin)] = 1;
}
else {
if ($type == 'buttons' && !empty($plugins[$plugin]['load'])) {
$init['extensions'][$plugin] = 1;
}
else {
if ($type == 'extensions' && !empty($plugins[$plugin]['load'])) {
$init['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']);
}
// Allow plugins to add or override global configuration settings.
if (!empty($plugins[$plugin]['options'])) {
$init = array_merge($init, $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']);
}
}
// Add theme-specific settings.
switch ($theme) {
case 'advanced':
$init += 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_resizing' => isset($config['resizing']) ? $config['resizing'] : 1,
'theme_advanced_toolbar_location' => isset($config['toolbar_loc']) ? $config['toolbar_loc'] : 'top',
'theme_advanced_toolbar_align' => isset($config['toolbar_align']) ? $config['toolbar_align'] : 'left',
);
if (isset($config['block_formats'])) {
$init['theme_advanced_blockformats'] = $config['block_formats'];
}
if (isset($init['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(
'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];
}
}
break;
}
unset($init['buttons']);
// Convert the config values into the form expected by TinyMCE.
foreach ($init as $key => $value) {
if (is_bool($value)) {
continue;
}
if (is_array($value)) {
$init[$key] = implode(',', $init[$key]);
}
}
return $init;
}