You are here

function ckeditor_load_plugins in CKEditor - WYSIWYG HTML editor 6

Same name and namespace in other branches
  1. 7 includes/ckeditor.lib.inc \ckeditor_load_plugins()

List of CKEditor plugins

Return value

array

4 calls to ckeditor_load_plugins()
ckeditor_admin_profile_form in includes/ckeditor.admin.inc
Form builder for a normal profile
ckeditor_admin_values_to_settings in includes/ckeditor.admin.inc
Converts an array of form values to a serialized array that does not contain Drupal Form API values
ckeditor_profile_overview in includes/ckeditor.admin.inc
Controller for CKEditor profiles.
ckeditor_toolbar_buttons_all in includes/ckeditor.admin.inc

File

includes/ckeditor.lib.inc, line 242
CKEditor - The text editor for the Internet - http://ckeditor.com Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.

Code

function ckeditor_load_plugins($render = FALSE) {
  $arr = array();
  $base_path = '%base_path%';
  $editor_path = '%editor_path%';
  $ckeditor_path = '%ckeditor_path%';
  $plugin_dir = '%plugin_dir%';
  $plugin_dir_additional = '%plugin_dir_extra%';
  $pattern = '#\\.addButton\\([\\s]*[\'"](.*?)[\'"][\\s]*\\,[\\s]*\\{[\\s]*(.*?)[\\s]*\\}#s';

  /*
   * External plugins
   */
  if (module_exists('ckeditor_swf') && file_exists(drupal_get_path('module', 'ckeditor_swf') . '/plugins/swf/plugin.js')) {
    $arr['ckeditor_swf'] = array(
      'name' => 'swf',
      'desc' => t('Support for the CKEditor SWF module'),
      'path' => $base_path . drupal_get_path('module', 'ckeditor_swf') . '/plugins/swf/',
      'buttons' => FALSE,
      'default' => 't',
    );
  }
  if (module_exists('ckeditor_link') && file_exists(drupal_get_path('module', 'ckeditor_link') . '/plugins/link/plugin.js')) {
    $arr['ckeditor_link'] = array(
      'name' => 'drupal_path',
      'desc' => t('Support for the CKEditor Link module'),
      'path' => $base_path . drupal_get_path('module', 'ckeditor_link') . '/plugins/link/',
      'buttons' => FALSE,
      'default' => 't',
    );
  }
  if (module_exists('linkit') && file_exists(drupal_get_path('module', 'linkit') . '/editors/ckeditor/plugin.js')) {
    $arr['linkit'] = array(
      'name' => 'Linkit',
      'desc' => t('Support for the Linkit module <em>(buttons: Linkit)</em>'),
      'path' => $base_path . drupal_get_path('module', 'linkit') . '/editors/ckeditor/',
      'buttons' => array(
        'Linkit' => array(
          'title' => 'Linkit',
          'icon' => $base_path . drupal_get_path('module', 'linkit') . '/editors/ckeditor/linkit.png',
        ),
      ),
      'default' => 't',
    );
  }

  /*
   * CKEditor build-in plugins
   */
  $_editor_path = ckeditor_path(TRUE) . '/';
  if (file_exists($_editor_path . 'plugins/tableresize/plugin.js')) {
    $arr['tableresize'] = array(
      'name' => 'tableresize',
      'desc' => t('Table Resize plugin'),
      'path' => $base_path . $editor_path . 'plugins/tableresize/',
      'buttons' => FALSE,
      'default' => 't',
    );
  }
  if (file_exists($_editor_path . 'plugins/autogrow/plugin.js')) {
    $arr['autogrow'] = array(
      'name' => 'autogrow',
      'desc' => t('Auto Grow plugin'),
      'path' => $base_path . $editor_path . 'plugins/autogrow/',
      'buttons' => FALSE,
      'default' => 'f',
    );
  }
  if (file_exists($_editor_path . 'plugins/stylesheetparser/plugin.js')) {
    $arr['stylesheetparser'] = array(
      'name' => 'stylesheetparser',
      'desc' => t('Stylesheet Parser plugin'),
      'path' => $base_path . $editor_path . 'plugins/stylesheetparser/',
      'buttons' => FALSE,
      'default' => 'f',
    );
  }

  /*
   * CKEditor module plugins
   */
  $_plugin_dir = drupal_get_path('module', 'ckeditor') . '/plugins/';
  if (is_dir($_plugin_dir) && ($handle = opendir($_plugin_dir))) {
    while (false !== ($file = readdir($handle))) {
      if (is_dir($_plugin_dir . $file) && file_exists($_plugin_dir . $file . '/plugin.js')) {
        $source = file_get_contents($_plugin_dir . $file . '/plugin.js');
        $buttons = array();
        if (preg_match_all($pattern, $source, $matches)) {
          foreach ($matches[1] as $i => $button_name) {
            if (preg_match('#(icon)[\\s]*\\:[\\s]*([^\\,\\n]*)#', $matches[2][$i], $matches2)) {
              $buttons[$button_name] = array();
              $buttons[$button_name]['label'] = $button_name;
              $matches2[2] = str_replace(array(
                'this.path',
                '+',
                '\'',
                '"',
              ), array(
                '',
                '',
                '',
                '',
              ), $matches2[2]);
              $buttons[$button_name]['icon'] = trim($matches2[2]);
            }
          }
        }
        if (preg_match('#@file ([^\\n\\r]*)#', $source, $matches)) {
          $arr[$file] = array(
            'name' => $file,
            'desc' => t($matches[1]),
            'path' => $base_path . $plugin_dir . $file . '/',
            'buttons' => count($buttons) > 0 ? $buttons : FALSE,
            'default' => 'f',
          );
        }
        else {
          $arr[$file] = array(
            'name' => $file,
            'desc' => t('Plugin file: ' . $file),
            'path' => $base_path . $plugin_dir . $file . '/',
            'buttons' => count($buttons) > 0 ? $buttons : FALSE,
            'default' => 'f',
          );
        }
      }
    }
    closedir($handle);
  }

  /*
   * CKEditor module plugins - additional directory
   */
  $_plugin_dir_additional = ckeditor_plugins_path(TRUE) . '/';
  if ($_plugin_dir != $_plugin_dir_additional && is_dir($_plugin_dir_additional) && ($handle = opendir($_plugin_dir_additional))) {
    while (false !== ($file = readdir($handle))) {
      if (is_dir($_plugin_dir_additional . $file) && file_exists($_plugin_dir_additional . $file . '/plugin.js')) {
        $source = file_get_contents($_plugin_dir_additional . $file . '/plugin.js');
        $buttons = array();
        if (preg_match_all($pattern, $source, $matches)) {
          foreach ($matches[1] as $i => $button_name) {
            if (preg_match('#(icon)[\\s]*\\:[\\s]*([^\\,\\n]*)#', $matches[2][$i], $matches2)) {
              $buttons[$button_name] = array();
              $buttons[$button_name]['label'] = $button_name;
              $matches2[2] = str_replace(array(
                'this.path',
                '+',
                '\'',
                '"',
              ), array(
                '',
                '',
                '',
                '',
              ), $matches2[2]);
              $buttons[$button_name]['icon'] = trim($matches2[2]);
            }
          }
        }
        if (preg_match('#@file ([^\\n\\r]*)#', $source, $matches)) {
          $arr[$file] = array(
            'name' => $file,
            'desc' => t($matches[1]),
            'path' => $base_path . $plugin_dir_additional . $file . '/',
            'buttons' => count($buttons) > 0 ? $buttons : FALSE,
            'default' => 'f',
          );
        }
        else {
          $arr[$file] = array(
            'name' => $file,
            'desc' => t('Plugin file: ' . $file),
            'path' => $base_path . $plugin_dir_additional . $file . '/',
            'buttons' => count($buttons) > 0 ? $buttons : FALSE,
            'default' => 'f',
          );
        }
      }
    }
    closedir($handle);
  }

  /*
   * CKEditor plugins registered by hook
   */
  $plugins = module_invoke_all('ckeditor_plugin');
  foreach ($plugins as $i => $plugin) {
    if (file_exists($plugin['path'] . 'plugin.js')) {
      $source = file_get_contents($plugin['path'] . 'plugin.js');
      $plugins[$i]['path'] = $base_path . $plugin['path'];
      if (!isset($plugin['buttons']) || count($plugin['buttons']) == 0) {
        $buttons = array();
        if (preg_match_all($pattern, $source, $matches)) {
          foreach ($matches[1] as $j => $button_name) {
            if (preg_match('#(icon)[\\s]*\\:[\\s]*([^\\,\\n]*)#', $matches[2][$j], $matches2)) {
              $buttons[$button_name] = array();
              $buttons[$button_name]['label'] = $button_name;
              $matches2[2] = str_replace(array(
                'this.path',
                '+',
                '\'',
                '"',
              ), array(
                '',
                '',
                '',
                '',
              ), $matches2[2]);
              $buttons[$button_name]['icon'] = trim($matches2[2]);
            }
          }
        }
        $plugins[$i]['buttons'] = count($buttons) > 0 ? $buttons : FALSE;
      }
    }
    else {
      unset($plugins[$i]);
    }
  }
  $arr = array_merge($arr, $plugins);
  if (isset($arr['linktomenu']) && module_exists('linktocontent') == FALSE) {
    unset($arr['linktomenu']);
  }
  if (isset($arr['linktonode']) && module_exists('linktocontent') == FALSE) {
    unset($arr['linktonode']);
  }
  if (isset($arr['imce']) && module_exists('imce') == FALSE) {
    unset($arr['imce']);
  }

  //remove page break button if there is no module to do this
  if (isset($arr['drupalbreaks']['buttons']['DrupalPageBreak']) && !module_exists('paging') && !module_exists('pagebreak')) {
    unset($arr['drupalbreaks']['buttons']['DrupalPageBreak']);
  }
  if (isset($arr['drupalbreaks'])) {
    $arr['drupalbreaks']['default'] = 't';
  }
  ksort($arr);
  if ($render === TRUE) {
    $arr = ckeditor_plugins_render($arr);
  }
  return $arr;
}