[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/ckeditor/ -> ckeditor.install (source)

   1  <?php
   2  // $Id: ckeditor.install,v 1.2.2.10 2010/09/15 15:23:36 wwalc Exp $
   3  /*
   4   * CKEditor - The text editor for Internet - http://ckeditor.com
   5   * Copyright (C) 2003-2008 Frederico Caldeira Knabben
   6   *
   7   * == BEGIN LICENSE ==
   8   *
   9   * Licensed under the terms of any of the following licenses at your
  10   * choice:
  11   *
  12   *  - GNU General Public License Version 2 or later (the "GPL")
  13   *    http://www.gnu.org/licenses/gpl.html
  14   *
  15   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  16   *    http://www.gnu.org/licenses/lgpl.html
  17   *
  18   *  - Mozilla Public License Version 1.1 or later (the "MPL")
  19   *    http://www.mozilla.org/MPL/MPL-1.1.html
  20   *
  21   * == END LICENSE ==
  22   *
  23   * @file
  24   * CKEditor Module for Drupal 6.x
  25   *
  26   * This module allows Drupal to replace textarea fields with CKEditor.
  27   *
  28   * This HTML text editor brings to the web many of the powerful functionalities
  29   * of known desktop editors like Word. It's really  lightweight and doesn't
  30   * require any kind of installation on the client computer.
  31   */
  32  
  33  /*
  34   * Implementation of hook_install().
  35   *
  36   * This will automatically install the database tables for the CKEditor module for both the MySQL and PostgreSQL databases.
  37   *
  38   * If you are using another database, you will have to install the tables by hand, using the queries below as a reference.
  39   *
  40   * Note that the curly braces around table names are a drupal-specific feature to allow for automatic database table prefixing,
  41   * and will need to be removed.
  42   */
  43  function ckeditor_install() {
  44    module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
  45    drupal_install_schema('ckeditor');
  46  
  47    //migration
  48    //checking fck editor schema version
  49    $rs=db_query("SELECT schema_version FROM {system} WHERE name='fckeditor'");
  50    $f_sv=FALSE;
  51    if ($row = db_fetch_array($rs)) {
  52      $f_sv=(int)$row['schema_version'];
  53    }
  54  
  55    //searching ckeditor.js
  56    $editor_path = _ckeditor_script_path();
  57  
  58    switch ($f_sv) {
  59      case 6201:
  60        db_query("INSERT INTO {ckeditor_role}(name, rid) SELECT name, rid FROM {fckeditor_role}");
  61        $rs=db_query("SELECT * FROM {fckeditor_settings}");
  62        while ($row=db_fetch_array($rs)) {
  63          $nname=str_replace(array('FCKeditor', 'fckeditor'), array('CKEditor', 'ckeditor'), $row['name']);
  64          $settings=unserialize($row['settings']);
  65          if (array_key_exists('js_conf', $settings)) {
  66            unset($settings['js_conf']);
  67          }
  68          foreach ($settings as $k => $v) {
  69            if (FALSE!==strpos($k, 'fckeditor')) {
  70              unset($settings[$k]);
  71              $k=str_replace('fckeditor', 'ckeditor', $k);
  72            }
  73            if ((!is_array($v))&&(FALSE!==strpos($v, 'fckeditor'))) {
  74              $v=str_replace('fckeditor', 'ckeditor', $v);
  75            }
  76            if ($k == 'skin' && $v != 'office2003') {
  77              $v = 'kama';
  78            }
  79            if ($k == 'css_style' && $v != 'default') {
  80              $v = 'default';
  81            }
  82            if ($k == 'styles_path' && strlen($v) > 0) {
  83              $v='';
  84            }
  85            if ($editor_path && $k == 'ckeditor_path') {
  86              $v=$editor_path;
  87            }
  88            $settings[$k]=$v;
  89          }
  90          if (!array_key_exists('excl', $settings)) {
  91            $settings['excl']='';
  92          }
  93          if (!array_key_exists('simple_incl', $settings)) {
  94            $settings['simple_incl']='';
  95          }
  96          $settings=serialize($settings);
  97          db_query("INSERT INTO {ckeditor_settings}(name, settings) VALUES('%s', '%s')", $nname, $settings);
  98        }
  99        break;
 100      default:
 101        //create two default roles based on previous settings
 102        db_query("INSERT INTO {ckeditor_role} (name, rid) VALUES ('%s', %d)",
 103        "Default", defined('DRUPAL_ANONYMOUS_RID') ? DRUPAL_ANONYMOUS_RID : 1);
 104        db_query("INSERT INTO {ckeditor_role} (name, rid) VALUES ('%s', %d)",
 105        "Advanced", defined('DRUPAL_AUTHENTICATED_RID') ? DRUPAL_AUTHENTICATED_RID : 2);
 106  
 107        //insert settings for default role
 108        $arr = array();
 109        $arr['allow_user_conf'] = "f";
 110        $arr['min_rows'] = variable_get('ckeditor_minimum_rows', 1);
 111        $arr['excl_mode'] = variable_get('ckeditor_exclude_toggle', 0);
 112        $arr['filebrowser'] = 'none';
 113        $arr['quickupload'] = 'f';
 114        $arr['excl']='';
 115        $arr['simple_incl']='';
 116  
 117        //security
 118        $arr['ss'] = "2";
 119        $arr['filters']['filter/0'] = 1;
 120  
 121        //appearance
 122        $arr['default'] = "t";
 123        $arr['show_toggle'] = "t";
 124        $arr['popup'] = variable_get('ckeditor_popup', 0) ? "t" : "f";
 125        $arr['skin'] = "kama";
 126        $arr['toolbar'] = variable_get('ckeditor_default_toolbar', 'DrupalBasic');
 127        $arr['expand'] = variable_get('ckeditor_toolbar_start_expanded', 1) ? "t" : "f";
 128        $arr['width'] = variable_get("ckeditor_width", "100%");
 129        $arr['lang'] = "en";
 130        $arr['auto_lang'] = "t";
 131        $arr['language_direction'] = "default";
 132        
 133        //output
 134        $arr['enter_mode'] = "p";
 135        $arr['shift_enter_mode'] = "br";
 136        $arr['font_format'] = 'p;div;pre;address;h1;h2;h3;h4;h5;h6';
 137        $arr['format_source'] = "t";
 138        $arr['format_output'] = "t";
 139        $arr['custom_formatting'] = "f";
 140        $arr['formatting']['custom_formatting_options'] = array('indent' => 'indent', 'breakBeforeOpen' => 'breakBeforeOpen', 'breakAfterOpen' => 'breakAfterOpen', 'breakAfterClose' => 'breakAfterClose');
 141  
 142        //css
 143        $arr['css_mode'] = "theme";
 144        $arr['css_path'] = variable_get("ckeditor_stylesheet", "");
 145  
 146        //upload
 147        //get permissions here like in _update_role_permissions
 148        $arr['filebrowser'] = "none";
 149        $arr['user_choose'] = "f";
 150        $arr['show_fieldnamehint'] = "t";
 151        $arr['ckeditor_load_method'] = "ckeditor.js";
 152        $arr['ckeditor_load_time_out'] = 0;
 153        $arr['scayt_autoStartup'] = "f";
 154  
 155        db_query("INSERT INTO {ckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Default", serialize($arr));
 156  
 157        //insert settings for advanced role
 158        $arr['toolbar'] = variable_get('ckeditor_advanced_toolbar', 'DrupalFiltered');
 159        db_query("INSERT INTO {ckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Advanced", serialize($arr));
 160  
 161        $arr = array();
 162  
 163        //exclude by default some known textareas where HTML is not expected
 164        //edit-recipients //contact module
 165        //edit-reply //contact module
 166        //edit-description //taxonomy module
 167        //edit-synonyms //taxonomy module
 168        //edit-img-assist-textareas //img assist module
 169        $arr['excl_mode'] = 0;
 170        $arr['excl'] = variable_get("ckeditor_exclude",
 171        "admin/user/settings.edit-user-mail-*\n".
 172        "*.edit-pages\n".
 173        "*.edit-pathauto-ignore-words\n".
 174        "*.edit-recipients\n".
 175        "*.edit-reply\n".
 176        "*.edit-description\n".
 177        "*.edit-synonyms\n".
 178        "*.edit-img-assist-textareas\n".
 179        "*.edit-img-assist-paths\n".
 180        "*.edit-nodewords-description\n".
 181        "*.edit-nodewords-description-value\n".
 182        "admin/content/nodewords/global*\n".
 183        "*.edit-relatedlinks-fieldset-relatedlinks\n".
 184        "*.edit-allowed-values-php\n".
 185        "*.edit-allowed-values\n".
 186        "*.edit-update-notify-emails\n".
 187        "*.edit-googleanalytics-*\n".
 188        "*.edit-piwik-*\n".
 189        "*.edit-feedburner-useragents\n".
 190        "*@*.edit-webform-*\n".
 191        "webform@*.edit-extra-items\n".
 192        "admin/*/logintoboggan\n".
 193        "admin/settings/actions/configure/*\n".
 194        "*.edit-target\n".
 195        "*.edit-wysiwyg-filter-*\n"
 196        );
 197  
 198        //force by default simple toolbar on selected textareas
 199        $arr['simple_incl_mode'] = 1;
 200        $arr['simple_incl'] =
 201        "*.edit-signature\n".
 202        "admin/settings/site-information.*\n".
 203        "admin/settings/site-maintenance.*\n".
 204        "*.edit-page-help\n".
 205        "*.edit-user-registration-help\n".
 206        "*.edit-user-picture-guidelines\n";
 207        if ($editor_path) {
 208          $arr['ckeditor_path']=$editor_path;
 209        }
 210  
 211        db_query("INSERT INTO {ckeditor_settings} (name, settings) VALUES ('%s', '%s')", "CKEditor Global Profile", serialize($arr));
 212    }
 213    module_load_include('inc', 'ckeditor', 'includes/ckeditor.admin');
 214    ckeditor_rebuild_selectors();
 215  }
 216  
 217  /**
 218   * Implementation of hook_schema().
 219   */
 220  function ckeditor_schema() {
 221    $schema['ckeditor_settings'] = array(
 222    'description' => 'Stores CKEditor profile settings',
 223    'fields' => array(
 224    'name'    => array(
 225    'type' => 'varchar',
 226    'not null' => TRUE,
 227    'default' => '',
 228    'length' => 128,
 229    'description' => 'Name of the CKEditor profile',
 230      ),
 231      'settings'    => array(
 232        'type' => 'text',
 233        'description' => 'Profile settings',
 234      ),
 235    ),
 236    'primary key' => array('name'),
 237    );
 238    $schema['ckeditor_role'] = array(
 239      'description' => 'Stores CKEditor profile assignments',
 240      'fields' => array(
 241        'name'    => array(
 242          'type' => 'varchar',
 243          'not null' => TRUE,
 244          'default' => '',
 245          'length' => 128,
 246          'description' => 'Name of the CKEditor role',
 247        ),
 248        'rid' => array(
 249          'type' => 'int',
 250          'not null' => TRUE,
 251          'default' => 0,
 252          'description' => 'Drupal role id',
 253        ),
 254      ),
 255      'primary key' => array('name', 'rid'),
 256    );
 257  
 258    return $schema;
 259  }
 260  
 261  /**
 262   * Implementation of hook_requirements().
 263   *
 264   * This hook will issue warnings if:
 265   * - The CKEditor source files are not found
 266   * - The CKEditor source files are out of date
 267   * - Quick upload and/or the built-in file browser are used and $cookie_domain is not set
 268   */
 269  function ckeditor_requirements($phase) {
 270    $requirements = array();
 271  
 272    if ($phase == 'runtime') {
 273      module_load_include('module', 'ckeditor');
 274      module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
 275      $requirements['ckeditor'] = array(
 276        'title' => t('CKEditor'),
 277        'value' => t('Unknown'),
 278      );
 279  
 280      $requirements['ckeditor']['severity'] = REQUIREMENT_OK;
 281  
 282      if (!_ckeditor_requirements_isinstalled()) {
 283        $sourcepath = ckeditor_path(TRUE);
 284  
 285        $requirements['ckeditor']['description'] = t('CKEditor was not found at %sourcepath', array('%sourcepath' => $sourcepath));
 286        $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
 287      }
 288      elseif (($installed_version = _ckeditor_requirements_getinstalledversion()) === NULL) {
 289        $requirements['ckeditor']['description'] = t('CKEditor version could not be determined');
 290        $requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
 291      }
 292      else {
 293        $profile_name = _ckeditor_requirements_ckfinder_filebrowser_enabled();
 294        if ($profile_name !== FALSE) {
 295          if (!_ckeditor_requirements_cookiedomainset()) {
 296            $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
 297            $requirements['ckeditor']['description'] = t('You are using a feature that requires $cookie_domain to be set, but it is not set in your settings.php (CKFinder is enabled in the !profile profile).', array('!profile' => l($profile_name, 'admin/settings/ckeditor/edit/'. urlencode($profile_name))));
 298          }
 299          elseif ($error = _ckeditor_requirements_ckfinder_config_check($profile_name)) {
 300            $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
 301            $requirements['ckeditor']['description'] = $error;
 302          }
 303        }
 304      }
 305      if ((($installed_version = _ckeditor_requirements_getinstalledversion()) !== NULL) && (-1==version_compare($installed_version, '3.1 SVN'))) {
 306        $requirements['ckeditor']['description'] = t('Some features are disabled because you\'re using an older version of CKEditor, please upgrade the editor to CKEditor 3.1 (or higher).');
 307        $requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
 308      }
 309      if (!empty($installed_version)) {
 310        $requirements['ckeditor']['value'] = $installed_version;
 311      }
 312    }
 313  
 314    return $requirements;
 315  }
 316  
 317  /**
 318   * Fetches the version of the installed CKEditor sources
 319   *
 320   * It tries to locate the version of the CKEditor sources in
 321   * ckeditor.js
 322   *
 323   * Releases have a version number such as "3.0.1"
 324   * SVN nightly releases have a minor version number with SVN appended: "3.0 SVN"
 325   * SVN check outs have the string "[Development]"
 326   *
 327   * This function is used by ckeditor_requirements()
 328   *
 329   * @return string Version number (eg. 3.0) of CKEditor. Null if not found in ckeditor_basic.js
 330   */
 331  function _ckeditor_requirements_getinstalledversion() {
 332    module_load_include('module', 'ckeditor');
 333    $editor_path = ckeditor_path(TRUE, TRUE);
 334    $jspath = $editor_path .'/ckeditor_basic.js';
 335  
 336    $configcontents = @file_get_contents($jspath);
 337    if (!$configcontents) {
 338      return NULL;
 339    }
 340    $matches = array();
 341    if (preg_match('#,version:\'(.*?)\',#', $configcontents, $matches)) {
 342      return $matches[1];
 343    }
 344    return NULL;
 345  }
 346  
 347  /**
 348   * Executed when built-in file browser is enabled
 349   * Returns FALSE if no errors are found in config.php file, otherwise it returns an error message.
 350   *
 351   * @return string|boolean
 352   */
 353  function _ckeditor_requirements_ckfinder_config_check($profile_name) {
 354    module_load_include('module', 'ckeditor');
 355    $module_drupal_path = drupal_get_path('module', 'ckeditor');
 356    $config_path = $module_drupal_path .'/ckfinder/config.php';
 357  
 358    if (!file_exists($config_path)) {
 359      return t('!ckfinder is not installed correctly: !config not found. Make sure that you have uploaded all files or didn\'t remove that file accidentally.', array(
 360        '!config' => $module_drupal_path .'/ckfinder/config.php',
 361        '!ckfinder' => '<a href="http://ckfinder.com">CKFinder</a>'
 362      ));
 363    }
 364  
 365    if (!is_readable($config_path)) {
 366      return t('CKEditor needs read permission to !config.', array('!config' => 'ckfinder/config.php'));
 367    }
 368  
 369    $config_contents = file($config_path);
 370  
 371    //not a 100% valid check, but well... let's have at least some error checking
 372    $require_once_found = FALSE;
 373    $require_once_line = 0;
 374    $userfiles_absolute_path_line = 0;
 375    $force_single_extension_line = 0;
 376  
 377    if ($config_contents)
 378    foreach ($config_contents as $line_num => $line) {
 379      //make sure it doesn't start with a comment, unfortunately we're not protected if code is commented with /* */
 380      if (!$require_once_found && strpos($line, "filemanager.config.php") !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
 381        $require_once_found = TRUE;
 382        $require_once_line = $line_num;
 383      }
 384      /**
 385       * @todo Finish this
 386       */
 387      if (!$userfiles_absolute_path_line && strpos($line, '$Config[\'UserFilesAbsolutePath\']') !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
 388        $userfiles_absolute_path_line = $line_num;
 389      }
 390      if (!$force_single_extension_line && strpos($line, '$Config[\'ForceSingleExtension\']') !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
 391        $force_single_extension_line = $line_num;
 392      }
 393    }
 394  
 395    if (!$require_once_found) {
 396      return t('You are using a feature that requires manual integration into config.php (either built-in filebrowser or quick uploads are enabled in the !profile profile). Read instructions about enabling built-in file browser and add "require_once ..." statement in editor/filemanager/connectors/php/config.php.', array('!profile' => l($profile_name, 'admin/settings/ckeditor/edit/'. urlencode($profile_name))));
 397    }
 398  
 399    if ($userfiles_absolute_path_line && $force_single_extension_line && (
 400    $require_once_line < $userfiles_absolute_path_line || $require_once_line > $force_single_extension_line)) {
 401      return t('You are using a feature that requires manual integration into config.php (either built-in filebrowser or quick uploads are enabled in the !profile profile). You have added "require_once ..." statement in editor/filemanager/connectors/php/config.php, but in the wrong line.', array('!profile' => l($profile_name, 'admin/settings/ckeditor/edit/'. urlencode($profile_name))));
 402    }
 403  
 404    return FALSE;
 405  }
 406  
 407  /**
 408   * Checks if any profile requires an explicit setting of $cookie_domain
 409   * in settings.php
 410   *
 411   * %cookie_domain is required when the internal filebrowser or quick upload is used
 412   *
 413   * This function is used by ckeditor_requirements()
 414   *
 415   * @return boolean True iff any profile requires $cookie_domain
 416   */
 417  function _ckeditor_requirements_ckfinder_filebrowser_enabled() {
 418    module_load_include('module', 'ckeditor');
 419    $profiles = ckeditor_profile_load();
 420  
 421    foreach ($profiles as $profile) {
 422      if ((isset($profile->settings['filebrowser']) && $profile->settings['filebrowser'] == 'ckfinder')) {
 423        return $profile->name;
 424      }
 425    }
 426  
 427    return FALSE;
 428  }
 429  
 430  /**
 431   * Checks if $cookie_domain has been set
 432   *
 433   * It has to include settings.php again because conf_init() sets
 434   * $cookie_domain regardless of its presence in settings.php, so
 435   * simply checking $GLOBALS['cookie_domain'] is not possible.
 436   *
 437   * This function is used by ckeditor_requirements()
 438   *
 439   * @return boolean True iff $cookie_domain was set in settings.php
 440   */
 441  function _ckeditor_requirements_cookiedomainset() {
 442    if (file_exists('./'. conf_path() .'/settings.php')) {
 443      $settings = file_get_contents('./'. conf_path() .'/settings.php');
 444  
 445      if (preg_match('#^\s*\$cookie_domain#m', $settings)) {
 446        return TRUE;
 447      }
 448    }
 449  
 450    return FALSE;
 451  }
 452  
 453  /**
 454   *    Implementation of hook_update_N().
 455   *
 456   *    Delete all plus signs from profiles name
 457   */
 458   
 459  function ckeditor_update_6100(){
 460      
 461      $ret = array();
 462      
 463      $ret[] = update_sql( "UPDATE {ckeditor_role} SET name = REPLACE(name,'+','')");
 464      $ret[] = update_sql( "UPDATE {ckeditor_role} SET name = REPLACE(name,'/','')");
 465      $ret[] = update_sql( "UPDATE {ckeditor_settings} SET name = REPLACE(name,'+','')");
 466      $ret[] = update_sql( "UPDATE {ckeditor_settings} SET name = REPLACE(name,'/','')");
 467      
 468      return $ret;
 469      
 470  }
 471  
 472  /**
 473   * Implementation of hook_uninstall().
 474   */
 475  function ckeditor_uninstall() {
 476    drupal_uninstall_schema('ckeditor');
 477  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7