function wysiwyg_tinymce_settings in Wysiwyg 5.2
Same name and namespace in other branches
- 5 editors/tinymce.inc \wysiwyg_tinymce_settings()
- 6.2 editors/tinymce.inc \wysiwyg_tinymce_settings()
- 6 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 143 - Editor integration functions for TinyMCE.
Code
function wysiwyg_tinymce_settings($editor, $config, $theme) {
$settings = 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'])) {
$settings['apply_source_formatting'] = $config['apply_source_formatting'];
}
if (isset($config['convert_fonts_to_spans'])) {
$settings['convert_fonts_to_spans'] = $config['convert_fonts_to_spans'];
}
if (isset($config['language'])) {
$settings['language'] = $config['language'];
}
if (isset($config['paste_auto_cleanup_on_paste'])) {
$settings['paste_auto_cleanup_on_paste'] = $config['paste_auto_cleanup_on_paste'];
}
if (isset($config['preformatted'])) {
$settings['preformatted'] = $config['preformatted'];
}
if (isset($config['remove_linebreaks'])) {
$settings['remove_linebreaks'] = $config['remove_linebreaks'];
}
if (isset($config['verify_html'])) {
$settings['verify_html'] = (bool) $config['verify_html'];
}
if (!empty($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') {
$settings['content_css'] = implode(',', wysiwyg_get_css());
}
else {
if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['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.
// $settings['buttons'] are stacked into $settings['theme_advanced_buttons1']
// later.
$settings['buttons'] = array();
if (!empty($config['buttons']) && is_array($config['buttons'])) {
// 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().
$settings['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') {
$settings['buttons'][] = $button;
}
// Add external Drupal plugins to the list of extensions.
if ($type == 'buttons' && !empty($plugins[$plugin]['proxy'])) {
$settings['extensions'][_wysiwyg_tinymce_plugin_name('add', $button)] = 1;
}
else {
if ($type == 'buttons' && empty($plugins[$plugin]['internal'])) {
$settings['extensions'][_wysiwyg_tinymce_plugin_name('add', $plugin)] = 1;
}
else {
if ($type == 'buttons' && !empty($plugins[$plugin]['load'])) {
$settings['extensions'][$plugin] = 1;
}
else {
if ($type == 'extensions' && !empty($plugins[$plugin]['load'])) {
$settings['extensions'][$plugin] = 1;
}
}
}
}
// Allow plugins to add valid HTML elements.
if (!empty($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'])) {
$settings = array_merge($settings, $plugins[$plugin]['options']);
}
}
}
}
// Clean-up.
$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':
$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_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'])) {
$settings['theme_advanced_blockformats'] = $config['block_formats'];
}
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.
$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($settings['buttons']); $i++) {
$settings['theme_advanced_buttons1'][] = $settings['buttons'][$i];
}
}
break;
}
unset($settings['buttons']);
// Convert the config values into the form expected by TinyMCE.
$csv_settings = array(
'plugins',
'extended_valid_elements',
'theme_advanced_buttons1',
'theme_advanced_buttons2',
'theme_advanced_buttons3',
);
foreach ($csv_settings as $key) {
if (isset($settings[$key]) && is_array($settings[$key])) {
$settings[$key] = implode(',', $settings[$key]);
}
}
return $settings;
}