ckeditor.install 21.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
<?php

/*
 * CKEditor - The text editor for the Internet - http://ckeditor.com
 * Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses of your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * @file
 * CKEditor Module for Drupal 7.x
 *
 * This module allows Drupal to replace textarea fields with CKEditor.
 *
 * CKEditor is an online rich text editor that can be embedded inside web pages.
 * It is a WYSIWYG (What You See Is What You Get) editor which means that the
 * text edited in it looks as similar as possible to the results end users will
 * see after the document gets published. It brings to the Web popular editing
 * features found in desktop word processors such as Microsoft Word and
 * OpenOffice.org Writer. CKEditor is truly lightweight and does not require any
 * kind of installation on the client computer.
 */

/*
 * Implementation of hook_install().
 *
 * This will automatically install the database tables for the CKEditor module for both MySQL and PostgreSQL databases.
 *
 * If you are using another database, you will have to install the tables manually, using the queries below as a reference.
 *
 * Note that the curly braces around table names are a Drupal-specific feature to allow for automatic database table prefixing,
 * and will need to be removed.
 */

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

  //searching ckeditor.js
  $ckeditor_path = _ckeditor_script_path();
  //insert default input formats to profiles
  db_insert('ckeditor_input_format')->fields(array("name" => "Advanced", "format" => 'filtered_html'))->execute();
  db_insert('ckeditor_input_format')->fields(array("name" => "Full", "format" => 'full_html'))->execute();

  //insert settings for default role
  $arr = array();
  $arr['filebrowser'] = 'none';
  $arr['quickupload'] = 'f';

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

  //appearance
  $arr['default'] = "t";
  $arr['show_toggle'] = "t";
  $arr['popup'] = variable_get('ckeditor_popup', 0) ? "t" : "f";
  // <!--break--> does not work in Filtered HTML, so DrupalBreak does not make sense here
  // https://drupal.org/node/881006
  $arr['toolbar'] = "
[
    ['Source'],
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
    ['Undo','Redo','Find','Replace','-','SelectAll'],
    ['Image','Media','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
    ['Maximize', 'ShowBlocks'],
    '/',
    ['Format'],
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript','-','RemoveFormat'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],
    ['Link','Unlink','Anchor','Linkit']
]
    ";
  $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'] = "none";
  $arr['css_path'] = variable_get("ckeditor_stylesheet", "");

  //upload
  //get permissions here like in _update_role_permissions
  $arr['filebrowser'] = "none";
  $arr['user_choose'] = "f";
  $arr['ckeditor_load_method'] = "ckeditor.js";
  $arr['ckeditor_load_time_out'] = 0;
  $arr['scayt_autoStartup'] = "f";

  //advanced options
  $arr['html_entities'] = "f";

  db_insert('ckeditor_settings')->fields(array("name" => "Advanced", "settings" => serialize($arr)))->execute();

  //insert settings for advanced role
  $arr['toolbar'] = "
[
    ['Source'],
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
    ['Undo','Redo','Find','Replace','-','SelectAll'],
    ['Image','Media','Flash','Table','HorizontalRule','Smiley','SpecialChar','Iframe'],
    '/',
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript','-','RemoveFormat'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl','-','Language'],
    ['Link','Unlink','Anchor','Linkit'],
    ['DrupalBreak'],
    '/',
    ['Format','Font','FontSize'],
    ['TextColor','BGColor'],
    ['Maximize', 'ShowBlocks']
]
    ";

  $arr['filters'] = array();

  db_insert('ckeditor_settings')->fields(array("name" => "Full", "settings" => serialize($arr)))->execute();

  $arr = array();

  if (!empty($ckeditor_path)) {
    $arr['ckeditor_path'] = $ckeditor_path;
  }
  else {
    $arr['ckeditor_path'] = '//cdn.ckeditor.com/4.4.3/full-all';
  }

  db_insert('ckeditor_settings')->fields(array("name" => "CKEditor Global Profile", "settings" => serialize($arr)))->execute();

  module_load_include('inc', 'ckeditor', 'includes/ckeditor.admin');
}

/**
 * Implementation of hook_schema().
 */
function ckeditor_schema() {
  $schema['ckeditor_settings'] = array(
    'description' => 'Stores CKEditor profile settings',
    'fields' => array(
      'name' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '',
        'length' => 128,
        'description' => 'Name of the CKEditor profile',
      ),
      'settings' => array(
        'type' => 'text',
        'description' => 'Profile settings',
      ),
    ),
    'primary key' => array('name')
  );
  $schema['ckeditor_input_format'] = array(
    'description' => 'Stores CKEditor input format assignments',
    'fields' => array(
      'name' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '',
        'length' => 128,
        'description' => 'Name of the CKEditor role',
      ),
      'format' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '',
        'length' => 128,
        'description' => 'Drupal filter format ID',
      )
    ),
    'primary key' => array('name', 'format'),
  );

  return $schema;
}

/**
 * Implementation of hook_requirements().
 *
 * This hook will issue warnings if:
 * - The CKEditor source files are not found.
 * - The CKEditor source files are out of date.
 * - Quick upload and/or the built-in file browser are used and $cookie_domain is not set.
 */
function ckeditor_requirements($phase) {
  $requirements = array();

  if ($phase == 'runtime') {
    module_load_include('module', 'ckeditor');
    module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
    $requirements['ckeditor'] = array(
      'title' => t('CKEditor'),
      'value' => t('Unknown'),
    );

    $requirements['ckeditor']['severity'] = REQUIREMENT_OK;

    if (!_ckeditor_requirements_isinstalled()) {
      $sourcepath = ckeditor_path('local');

      $requirements['ckeditor']['description'] = t('CKEditor was not found in <code>%sourcepath</code>.', array('%sourcepath' => $sourcepath));
      $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
    }
    elseif (($installed_version = _ckeditor_requirements_getinstalledversion()) === NULL) {
      $requirements['ckeditor']['description'] = t('CKEditor version could not be determined.');
      $requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
    }
    else {
      $profile_name = _ckeditor_requirements_ckfinder_filebrowser_enabled();
      if ($profile_name !== FALSE) {
        if (!_ckeditor_requirements_cookiedomainset()) {
          $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
          $requirements['ckeditor']['description'] = t('You are using a feature that requires <code>$cookie_domain</code> to be set, but it is not set in your <code>settings.php</code> file (CKFinder is enabled in the !profile profile).', array('!profile' => l($profile_name, 'admin/config/content/ckeditor/edit/' . urlencode($profile_name))));
        }
        elseif ($error = _ckeditor_requirements_ckfinder_config_check($profile_name)) {
          $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
          $requirements['ckeditor']['description'] = $error;
        }
      }
    }
    if ((($installed_version = _ckeditor_requirements_getinstalledversion()) !== NULL) && $installed_version != '%VERSION%' && $installed_version != '<URL>' && (-1 == version_compare($installed_version, '3.1 SVN'))) {
      $requirements['ckeditor']['description'] = t('Some features are disabled because you are using an older version of CKEditor. Please upgrade to CKEditor 3.1 (or higher).');
      $requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
    }
    if (!empty($installed_version)) {
      if ($installed_version == '%VERSION%') {
        $requirements['ckeditor']['value'] = 'GIT version';
      }
      else if ($installed_version == '<URL>') {
        $requirements['ckeditor']['value'] = 'Unknown version. CKEditor is loaded from a remote URL.';
        $requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
      }
      else {
        $requirements['ckeditor']['value'] = $installed_version;
      }
    }
    else {
      $requirements['ckeditor']['value'] = t('Not found');
    }
  }

  return $requirements;
}

/**
 * Fetches the version of the installed CKEditor sources.
 *
 * It tries to locate the version of the CKEditor sources in
 * ckeditor.js.
 *
 * Releases have a version number such as "3.0.1".
 * SVN nightly releases have a minor version number with SVN appended: "3.0 SVN".
 * SVN checkouts have the string "[Development]".
 *
 * This function is used by ckeditor_requirements().
 *
 * @return string Version number (eg. 3.0) of CKEditor. Null if not found in ckeditor_basic.js.
 */
function _ckeditor_requirements_getinstalledversion() {
  module_load_include('module', 'ckeditor');
  $editor_path = ckeditor_path('local', TRUE);
  if ($editor_path == '<URL>') {
    $url = ckeditor_path('url', TRUE);
    $matches = array();
    if (preg_match("|cdn.ckeditor.com/(\d(\.\d+)+.*)/|i", $url, $matches)) {
      return $matches[1];
    }
    return '<URL>';
  }
  $jspath = $editor_path . '/ckeditor.js';

  $configcontents = @file_get_contents($jspath);
  if (!$configcontents) {
    return NULL;
  }
  $matches = array();
  if (preg_match('#,version:[\'\"]{1}(.*?)[\'\"]{1},#', $configcontents, $matches)) {
    return $matches[1];
  }
  return NULL;
}

/**
 * Executed when the built-in file browser is enabled.
 * Returns FALSE if no errors are found in the config.php file, otherwise it returns an error message.
 *
 * @return string|boolean
 */
function _ckeditor_requirements_ckfinder_config_check($profile_name) {
  global $base_url;
  module_load_include('module', 'ckeditor');
  $config_path = ckfinder_path('local') . '/config.php';

  if (!file_exists($config_path)) {
    return t('!ckfinder is not installed correctly: <code>!config</code> not found. Make sure that you uploaded all files and did not accidentally remove the configuration file. If you installed CKFinder in other location (e.g. in the libraries folder), make sure to update the path to CKFinder in !global.', array(
          '!config' => $config_path,
          '!ckfinder' => '<a href="http://cksource.com/ckfinder">CKFinder</a>',
          '!global' => l(t('CKEditor Global Profile'), 'admin/config/content/ckeditor/editg')
        ));
  }

  if (!is_readable($config_path)) {
    return t('CKEditor needs read permission to the <code>!config</code> file.', array('!config' => $config_path));
  }

  $config_contents = file($config_path);

  //not a 100% valid check, but well... let's have at least some error checking
  $require_once_found = FALSE;
  $require_once_line = 0;
  $userfiles_absolute_path_line = 0;
  $force_single_extension_line = 0;

  if ($config_contents) {
    foreach ($config_contents as $line_num => $line) {
      //make sure it doesn't start with a comment, unfortunately we're not protected if code is commented with /* */
      if (!$require_once_found && strpos($line, "filemanager.config.php") !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
        $require_once_found = TRUE;
        $require_once_line = $line_num;
      }
      /**
       * @todo Finish this
       */
      if (!$userfiles_absolute_path_line && strpos($line, '$Config[\'UserFilesAbsolutePath\']') !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
        $userfiles_absolute_path_line = $line_num;
      }
      if (!$force_single_extension_line && strpos($line, '$Config[\'ForceSingleExtension\']') !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
        $force_single_extension_line = $line_num;
      }
    }
  }

  if (!$require_once_found) {
    return t('You are using a feature that requires manual integration in the <code>config.php</code> file. Please read the "Installing CKFinder" section in the <code>!readme</code> file carefully and add a <code>require_once ...</code> statement to the <code>%ckfconfig</code> file.', array('%ckfconfig' => $config_path, '!readme' => l(t('README.txt'), $base_url . '/' . drupal_get_path('module', 'ckeditor') . '/README.txt', array('absolute' => TRUE))));
  }

  if ($userfiles_absolute_path_line && $force_single_extension_line && (
      $require_once_line < $userfiles_absolute_path_line || $require_once_line > $force_single_extension_line)) {
    return t('You are using a feature that requires manual integration in the <code>config.php</code> file. You have added a <code>require_once ...</code> statement to the <code>%ckfconfig</code> file, but in the wrong line.', array('%ckfconfig' => $config_path));
  }

  return FALSE;
}

/**
 * Checks if any profile requires an explicit setting of $cookie_domain
 * in settings.php.
 *
 * %cookie_domain is required when the internal file browser or quick upload is used.
 *
 * This function is used by ckeditor_requirements().
 *
 * @return boolean True if any profile requires $cookie_domain.
 */
function _ckeditor_requirements_ckfinder_filebrowser_enabled() {
  module_load_include('module', 'ckeditor');
  $profiles = ckeditor_profile_load();

  foreach ($profiles as $profile) {
    if ((isset($profile->settings['filebrowser']) && $profile->settings['filebrowser'] == 'ckfinder')) {
      return $profile->name;
    }
  }

  return FALSE;
}

/**
 * Checks if $cookie_domain was set.
 *
 * It has to include settings.php again because conf_init() sets
 * $cookie_domain regardless of its presence in settings.php, so
 * simply checking $GLOBALS['cookie_domain'] is not possible.
 *
 * This function is used by ckeditor_requirements().
 *
 * @return boolean True if $cookie_domain was set in settings.php.
 */
function _ckeditor_requirements_cookiedomainset() {
  if (file_exists('./' . conf_path() . '/settings.php')) {
    $settings = file_get_contents('./' . conf_path() . '/settings.php');

    if (preg_match('#^\s*\$cookie_domain#m', $settings)) {
      return TRUE;
    }
  }

  return FALSE;
}

/**
 * Updates broken settings for the 'Full' profile. (Resets toolbar to default)
 */
function ckeditor_update_7000() {
  _ckeditor_d6_to_d7_migration();
  $result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(':name' => 'Full'))->fetchField();
  $settings = unserialize($result);
  $settings['toolbar'] = "
[
    ['Source'],
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
    ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
    '/',
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],
    ['Link','Unlink','Anchor'],
    ['DrupalBreak'],
    '/',
    ['Format','Font','FontSize'],
    ['TextColor','BGColor'],
    ['Maximize', 'ShowBlocks']
]
    ";

  $settings = serialize($settings);

  $update = db_update('ckeditor_settings')
      ->fields(array(
        'settings' => $settings,
      ))
      ->condition('name', 'Full', '=')
      ->execute();
}

/**
 * Removes the 'DrupalBreak' button from the 'Advanced' profile. (Resets toolbar to default)
 */
function ckeditor_update_7001() {
  $result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(':name' => 'Advanced'))->fetchField();
  $settings = unserialize($result);
  $settings['toolbar'] = "
[
    ['Source'],
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
    ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
    ['Maximize', 'ShowBlocks'],
    '/',
    ['Format'],
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],
    ['Link','Unlink','Anchor']
]
    ";

  $settings = serialize($settings);

  $update = db_update('ckeditor_settings')
      ->fields(array(
        'settings' => $settings,
      ))
      ->condition('name', 'Advanced', '=')
      ->execute();
}

/**
 * Rewrites 'Path to CKEditor' to new flags.
 */
function ckeditor_update_7002() {
  $result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(':name' => 'CKEditor Global Profile'))->fetchField();
  $settings = unserialize($result);
  if ($settings['ckeditor_path'] == '%b/sites/all/libraries/ckeditor') {
    $settings['ckeditor_path'] = '%l/ckeditor';
  }
  else {
    $settings['ckeditor_path'] = str_replace('%b/', '', $settings['ckeditor_path']);
    $settings['ckeditor_path'] = str_replace('%b', '', $settings['ckeditor_path']);
  }

  $settings = serialize($settings);

  $update = db_update('ckeditor_settings')
      ->fields(array(
        'settings' => $settings,
      ))
      ->condition('name', 'CKEditor Global Profile', '=')
      ->execute();
}

/**
 * Fixes static paths to plugin files.
 */
function ckeditor_update_7003() {
  module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
  module_load_include('module', 'ckeditor');

  _ckeditor_d6_to_d7_migration();

  $render = array();
  $render["%base_path%"] = base_path();
  $render["%editor_path%"] = ckeditor_path('relative') . '/';
  $render["%ckeditor_path%"] = ckeditor_module_path('relative');
  $render["%plugin_dir%"] = $render["%module_path%"] . '/plugins/';

  $result = db_query("SELECT * FROM {ckeditor_settings} WHERE name <> :name", array(':name' => 'CKEditor Global Profile'))->fetchAllAssoc('name');

  foreach ((array) $result as $profile) {
    $name = $profile->name;
    $settings = unserialize($profile->settings);

    foreach ((array) $settings['loadPlugins'] as $i => $plugin) {
      $settings['loadPlugins'][$i]['path'] = str_replace(array_values($render), array_keys($render), $plugin['path']);
    }

    $settings = serialize($settings);

    $update = db_update('ckeditor_settings')
        ->fields(array(
          'settings' => $settings,
        ))
        ->condition('name', $name, '=')
        ->execute();
  }
}

/**
 * Minor update for those who have run update.php with problems.
 * @see http://drupal.org/node/1347682 for a better explanation.
 */
function ckeditor_update_7004() {
  return _ckeditor_d6_to_d7_migration();
}

/**
 * Fixes plugin paths stored in database.
 * @see http://drupal.org/node/1864760 for more information
 */
function ckeditor_update_7005() {
  $result = db_query("SELECT * FROM {ckeditor_settings} WHERE name <> :name", array(':name' => 'CKEditor Global Profile'))->fetchAllAssoc('name');

  foreach ((array) $result as $profile) {
    $name = $profile->name;
    $settings = unserialize($profile->settings);

    $replace = array(
      "%base_path%%editor_path%" => "%editor_path%",
      "%base_path%%module_path%" => "%module_path%",
      "%base_path%%plugin_dir%" => "%plugin_dir%",
      "%base_path%%plugin_dir_extra%" => "%plugin_dir_extra%"
    );

    foreach ((array) $settings['loadPlugins'] as $i => $plugin) {
      $settings['loadPlugins'][$i]['path'] = str_replace(array_keys($replace), array_values($replace), $plugin['path']);
    }

    $settings = serialize($settings);

    db_update('ckeditor_settings')
        ->fields(array(
          'settings' => $settings,
        ))
        ->condition('name', $name, '=')
        ->execute();
  }
}

/**
 * Adapts D6 table structure to D7 schema.
 */
function _ckeditor_d6_to_d7_migration() {
  if (db_table_exists('ckeditor_role')) {
    db_drop_table('ckeditor_role');
  }
  if (!db_table_exists('ckeditor_input_format')) {
    $ckeditor_input_format = array(
      'description' => 'Stores CKEditor input format assignments',
      'fields' => array(
        'name' => array(
          'type' => 'varchar',
          'not null' => TRUE,
          'default' => '',
          'length' => 128,
          'description' => 'Name of the CKEditor role',
        ),
        'format' => array(
          'type' => 'varchar',
          'not null' => TRUE,
          'default' => '',
          'length' => 128,
          'description' => 'Drupal filter format ID',
        )
      ),
      'primary key' => array('name', 'format'),
    );
    db_create_table('ckeditor_input_format', $ckeditor_input_format);
  }
}