You are here

function wysiwyg_ckeditor_settings in Wysiwyg 5.2

Same name and namespace in other branches
  1. 6.2 editors/ckeditor.inc \wysiwyg_ckeditor_settings()
  2. 7.2 editors/ckeditor.inc \wysiwyg_ckeditor_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_ckeditor_settings'
wysiwyg_ckeditor_editor in editors/ckeditor.inc
Plugin implementation of hook_editor().

File

editors/ckeditor.inc, line 136
Editor integration functions for CKEditor.

Code

function wysiwyg_ckeditor_settings($editor, $config, $theme) {
  $settings = array(
    // Needed to make relative paths work in the editor.
    'baseHref' => $GLOBALS['base_url'] . '/',
    'width' => 'auto',
    // For better compatibility with smaller textareas.
    'resize_minWidth' => 450,
    'height' => 420,
    // @todo Do not use skins as themes and add separate skin handling.
    'theme' => 'default',
    'skin' => !empty($theme) ? $theme : 'kama',
    // By default, CKEditor converts most characters into HTML entities. Since
    // it does not support a custom definition, but Drupal supports Unicode, we
    // disable at least the additional character sets. CKEditor always converts
    // XML default characters '&', '<', '>'.
    // @todo Check whether completely disabling ProcessHTMLEntities is an option.
    'entities_latin' => FALSE,
    'entities_greek' => FALSE,
  );

  // Add HTML block format settings; common block formats are already predefined
  // by CKEditor.
  if (isset($config['block_formats'])) {
    $block_formats = explode(',', drupal_strtolower($config['block_formats']));
    $predefined_formats = array(
      'h1',
      'h2',
      'h3',
      'h4',
      'h5',
      'h6',
      'p',
      'pre',
      'address',
      'div',
    );
    foreach (array_diff($block_formats, $predefined_formats) as $tag) {
      $tag = trim($tag);
      $settings["format_{$tag}"] = array(
        'element' => $tag,
        'name' => strtoupper(substr($tag, 0, 1)) . substr($tag, 1),
      );
    }
    $settings['format_tags'] = implode(';', $block_formats);
  }
  if (isset($config['apply_source_formatting'])) {
    $settings['apply_source_formatting'] = $config['apply_source_formatting'];
  }
  if (isset($config['css_setting'])) {

    // Versions below 3.0.1 could only handle one stylesheet.
    if (version_compare($editor['installed version'], '3.0.1.4391', '<')) {
      if ($config['css_setting'] == 'theme') {
        $css = wysiwyg_get_css();
        $settings['contentsCss'] = reset($css);
      }
      elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
        $settings['contentsCss'] = strtr($config['css_path'], array(
          '%b' => base_path(),
          '%t' => path_to_theme(),
        ));
      }
    }
    else {
      if ($config['css_setting'] == 'theme') {
        $settings['contentsCss'] = wysiwyg_get_css();
      }
      elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
        $settings['contentsCss'] = explode(',', strtr($config['css_path'], array(
          '%b' => base_path(),
          '%t' => path_to_theme(),
        )));
      }
    }
  }
  if (isset($config['language'])) {
    $settings['language'] = $config['language'];
  }
  if (isset($config['resizing'])) {
    $settings['resize_enabled'] = $config['resizing'];
  }
  if (isset($config['toolbar_loc'])) {
    $settings['toolbarLocation'] = $config['toolbar_loc'];
  }
  $settings['toolbar'] = array();
  if (!empty($config['buttons'])) {
    $extra_plugins = 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['toolbar'][] = $button;
          }

          // Add external Drupal plugins to the list of extensions.
          if ($type == 'buttons' && !empty($plugins[$plugin]['proxy'])) {
            $extra_plugins[] = $button;
          }
          elseif ($type == 'buttons' && empty($plugins[$plugin]['internal'])) {
            $extra_plugins[] = $plugin;
          }
          elseif ($type == 'buttons' && !empty($plugins[$plugin]['load'])) {
            $extra_plugins[] = $plugin;
          }
          elseif ($type == 'extensions' && !empty($plugins[$plugin]['load'])) {
            $extra_plugins[] = $plugin;
          }

          // Allow plugins to add or override global configuration settings.
          if (!empty($plugins[$plugin]['options'])) {
            $settings = array_merge($settings, $plugins[$plugin]['options']);
          }
        }
      }
    }
    if (!empty($extra_plugins)) {
      $settings['extraPlugins'] = implode(',', $extra_plugins);
    }
  }

  // For now, all buttons are placed into one row.
  $settings['toolbar'] = array(
    $settings['toolbar'],
  );
  return $settings;
}