You are here

function ckeditor_install in CKEditor - WYSIWYG HTML editor 6

Same name and namespace in other branches
  1. 7 ckeditor.install \ckeditor_install()

File

./ckeditor.install, line 46

Code

function ckeditor_install() {
  module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
  drupal_install_schema('ckeditor');

  //migration

  //checking fck editor schema version
  $rs = db_query("SELECT schema_version FROM {system} WHERE name='fckeditor'");
  $f_sv = FALSE;
  if ($row = db_fetch_array($rs)) {
    $f_sv = (int) $row['schema_version'];
  }

  //searching ckeditor.js
  $editor_path = _ckeditor_script_path();
  switch ($f_sv) {
    case 6201:
    case 6202:
      db_query("INSERT INTO {ckeditor_role}(name, rid) SELECT name, rid FROM {fckeditor_role}");
      $rs = db_query("SELECT * FROM {fckeditor_settings}");
      while ($row = db_fetch_array($rs)) {
        $nname = str_replace(array(
          'FCKeditor',
          'fckeditor',
        ), array(
          'CKEditor',
          'ckeditor',
        ), $row['name']);
        $settings = unserialize($row['settings']);
        if (array_key_exists('js_conf', $settings)) {
          unset($settings['js_conf']);
        }
        foreach ($settings as $k => $v) {
          if (FALSE !== strpos($k, 'fckeditor')) {
            unset($settings[$k]);
            $k = str_replace('fckeditor', 'ckeditor', $k);
          }
          if (!is_array($v) && FALSE !== strpos($v, 'fckeditor')) {
            $v = str_replace('fckeditor', 'ckeditor', $v);
          }
          if ($k == 'skin' && $v != 'office2003') {
            $v = 'kama';
          }
          if ($k == 'css_style' && $v != 'default') {
            $v = 'default';
          }
          if ($k == 'styles_path' && strlen($v) > 0) {
            $v = '';
          }
          if ($editor_path && $k == 'ckeditor_path') {
            $v = $editor_path;
          }
          $settings[$k] = $v;
        }
        if (!array_key_exists('excl', $settings)) {
          $settings['excl'] = '';
        }
        if (!array_key_exists('simple_incl', $settings)) {
          $settings['simple_incl'] = '';
        }
        $settings = serialize($settings);
        db_query("INSERT INTO {ckeditor_settings}(name, settings) VALUES('%s', '%s')", $nname, $settings);
      }
      break;
    default:

      //create two default roles based on previous settings
      db_query("INSERT INTO {ckeditor_role} (name, rid) VALUES ('%s', %d)", "Default", defined('DRUPAL_ANONYMOUS_RID') ? DRUPAL_ANONYMOUS_RID : 1);
      db_query("INSERT INTO {ckeditor_role} (name, rid) VALUES ('%s', %d)", "Advanced", defined('DRUPAL_AUTHENTICATED_RID') ? DRUPAL_AUTHENTICATED_RID : 2);

      //insert settings for default role
      $arr = array();
      $arr['allow_user_conf'] = "f";
      $arr['min_rows'] = variable_get('ckeditor_minimum_rows', 1);
      $arr['excl_mode'] = variable_get('ckeditor_exclude_toggle', 0);
      $arr['filebrowser'] = 'none';
      $arr['quickupload'] = 'f';
      $arr['excl'] = '';
      $arr['simple_incl'] = '';

      //security
      $arr['ss'] = "2";
      $arr['filters']['filter/0'] = 1;

      //appearance
      $arr['default'] = "t";
      $arr['show_toggle'] = "t";
      $arr['popup'] = variable_get('ckeditor_popup', 0) ? "t" : "f";
      $arr['skin'] = "moono";
      $arr['toolbar'] = "\n[\n    [ 'Format', 'Bold', 'Italic', '-', 'NumberedList','BulletedList', '-', 'Link', 'Unlink', 'Image' ]\n]\n      ";
      $arr['expand'] = variable_get('ckeditor_toolbar_start_expanded', 1) ? "t" : "f";
      $arr['width'] = variable_get("ckeditor_width", "100%");
      $arr['lang'] = "en";
      $arr['auto_lang'] = "t";
      $arr['language_direction'] = "default";

      //output
      $arr['enter_mode'] = "p";
      $arr['shift_enter_mode'] = "br";
      $arr['font_format'] = 'p;div;pre;address;h1;h2;h3;h4;h5;h6';
      $arr['format_source'] = "t";
      $arr['format_output'] = "t";
      $arr['custom_formatting'] = "f";
      $arr['formatting']['custom_formatting_options'] = array(
        'indent' => 'indent',
        'breakBeforeOpen' => 'breakBeforeOpen',
        'breakAfterOpen' => 'breakAfterOpen',
        'breakAfterClose' => 'breakAfterClose',
      );

      //css
      $arr['css_mode'] = "theme";
      $arr['css_path'] = variable_get("ckeditor_stylesheet", "");

      //upload

      //get permissions here like in _update_role_permissions
      $arr['filebrowser'] = "none";
      $arr['user_choose'] = "f";
      $arr['show_fieldnamehint'] = "t";
      $arr['ckeditor_load_method'] = "ckeditor.js";
      $arr['ckeditor_load_time_out'] = 0;
      $arr['scayt_autoStartup'] = "f";
      db_query("INSERT INTO {ckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Default", serialize($arr));

      //insert settings for advanced role
      $arr['toolbar'] = "\n[\n    ['Source'],\n    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],\n    ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],\n    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','Iframe'],\n    ['Maximize', 'ShowBlocks'],\n    '/',\n    ['Format'],\n    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],\n    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],\n    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiRtl','BidiLtr'],\n    ['Link','Unlink','Anchor','Linkit','LinkToNode','LinkToMenu'],\n    ['DrupalBreak']\n]\n      ";
      db_query("INSERT INTO {ckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Advanced", serialize($arr));
      $arr = array();

      //exclude by default some known textareas where HTML is not expected

      //edit-recipients //contact module

      //edit-reply //contact module

      //edit-description //taxonomy module

      //edit-synonyms //taxonomy module

      //edit-img-assist-textareas //img assist module
      $arr['excl_mode'] = 0;
      $arr['excl'] = variable_get("ckeditor_exclude", "admin/user/settings.edit-user-mail-*\n" . "*.edit-pages\n" . "*.edit-pathauto-ignore-words\n" . "*.edit-recipients\n" . "*.edit-reply\n" . "*.edit-description\n" . "*.edit-synonyms\n" . "*.edit-img-assist-textareas\n" . "*.edit-img-assist-paths\n" . "*.edit-nodewords-description\n" . "*.edit-nodewords-description-value\n" . "admin/content/nodewords/global*\n" . "*.edit-relatedlinks-fieldset-relatedlinks\n" . "*.edit-allowed-values-php\n" . "*.edit-allowed-values\n" . "*.edit-update-notify-emails\n" . "*.edit-googleanalytics-*\n" . "*.edit-piwik-*\n" . "*.edit-feedburner-useragents\n" . "*@*.edit-webform-*\n" . "webform@*.edit-extra-items\n" . "admin/*/logintoboggan\n" . "admin/settings/actions/configure/*\n" . "*.edit-target\n" . "*.edit-wysiwyg-filter-*\n" . "admin/build/views*\n");

      //force by default simple toolbar on selected textareas
      $arr['simple_incl_mode'] = 1;
      $arr['simple_incl'] = "*.edit-signature\n" . "admin/settings/site-information.*\n" . "admin/settings/site-maintenance.*\n" . "*.edit-page-help\n" . "*.edit-user-registration-help\n" . "*.edit-user-picture-guidelines\n";
      if ($editor_path) {
        $arr['ckeditor_path'] = $editor_path;
      }
      db_query("INSERT INTO {ckeditor_settings} (name, settings) VALUES ('%s', '%s')", "CKEditor Global Profile", serialize($arr));
  }
  module_load_include('inc', 'ckeditor', 'includes/ckeditor.admin');
  ckeditor_rebuild_selectors();
}