Projet

Général

Profil

Paste
Télécharger (21,7 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ckeditor / ckeditor.install @ 2e0f6994

1
<?php
2

    
3
/*
4
 * CKEditor - The text editor for the Internet - http://ckeditor.com
5
 * Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
6
 *
7
 * == BEGIN LICENSE ==
8
 *
9
 * Licensed under the terms of any of the following licenses of 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 7.x
25
 *
26
 * This module allows Drupal to replace textarea fields with CKEditor.
27
 *
28
 * CKEditor is an online rich text editor that can be embedded inside web pages.
29
 * It is a WYSIWYG (What You See Is What You Get) editor which means that the
30
 * text edited in it looks as similar as possible to the results end users will
31
 * see after the document gets published. It brings to the Web popular editing
32
 * features found in desktop word processors such as Microsoft Word and
33
 * OpenOffice.org Writer. CKEditor is truly lightweight and does not require any
34
 * kind of installation on the client computer.
35
 */
36

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

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

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

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

    
62
  //security
63
  $arr['ss'] = "2";
64
  $arr['filters']['filter_html'] = 1;
65

    
66
  //appearance
67
  $arr['default'] = "t";
68
  $arr['show_toggle'] = "t";
69
  $arr['popup'] = variable_get('ckeditor_popup', 0) ? "t" : "f";
70
  // <!--break--> does not work in Filtered HTML, so DrupalBreak does not make sense here
71
  // https://drupal.org/node/881006
72
  $arr['toolbar'] = "
73
[
74
    ['Source'],
75
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
76
    ['Undo','Redo','Find','Replace','-','SelectAll'],
77
    ['Image','Media','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
78
    ['Maximize', 'ShowBlocks'],
79
    '/',
80
    ['Format'],
81
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript','-','RemoveFormat'],
82
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
83
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],
84
    ['Link','Unlink','Anchor','Linkit']
85
]
86
    ";
87
  $arr['expand'] = variable_get('ckeditor_toolbar_start_expanded', 1) ? "t" : "f";
88
  $arr['width'] = variable_get("ckeditor_width", "100%");
89
  $arr['lang'] = "en";
90
  $arr['auto_lang'] = "t";
91
  $arr['language_direction'] = "default";
92

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

    
102
  //css
103
  $arr['css_mode'] = "none";
104
  $arr['css_path'] = variable_get("ckeditor_stylesheet", "");
105

    
106
  //upload
107
  //get permissions here like in _update_role_permissions
108
  $arr['filebrowser'] = "none";
109
  $arr['user_choose'] = "f";
110
  $arr['ckeditor_load_method'] = "ckeditor.js";
111
  $arr['ckeditor_load_time_out'] = 0;
112
  $arr['scayt_autoStartup'] = "f";
113

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

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

    
119
  //insert settings for advanced role
120
  $arr['toolbar'] = "
121
[
122
    ['Source'],
123
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
124
    ['Undo','Redo','Find','Replace','-','SelectAll'],
125
    ['Image','Media','Flash','Table','HorizontalRule','Smiley','SpecialChar','Iframe'],
126
    '/',
127
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript','-','RemoveFormat'],
128
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
129
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl','-','Language'],
130
    ['Link','Unlink','Anchor','Linkit'],
131
    ['DrupalBreak'],
132
    '/',
133
    ['Format','Font','FontSize'],
134
    ['TextColor','BGColor'],
135
    ['Maximize', 'ShowBlocks']
136
]
137
    ";
138

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

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

    
143
  $arr = array();
144

    
145
  if (!empty($ckeditor_path)) {
146
    $arr['ckeditor_path'] = $ckeditor_path;
147
  }
148
  else {
149
    $arr['ckeditor_path'] = '//cdn.ckeditor.com/' . CKEDITOR_LATEST . '/full-all';
150
  }
151

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

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

    
157
/**
158
 * Implementation of hook_schema().
159
 */
160
function ckeditor_schema() {
161
  $schema['ckeditor_settings'] = array(
162
    'description' => 'Stores CKEditor profile settings',
163
    'fields' => array(
164
      'name' => array(
165
        'type' => 'varchar',
166
        'not null' => TRUE,
167
        'default' => '',
168
        'length' => 128,
169
        'description' => 'Name of the CKEditor profile',
170
      ),
171
      'settings' => array(
172
        'type' => 'text',
173
        'description' => 'Profile settings',
174
      ),
175
    ),
176
    'primary key' => array('name')
177
  );
178
  $schema['ckeditor_input_format'] = array(
179
    'description' => 'Stores CKEditor input format assignments',
180
    'fields' => array(
181
      'name' => array(
182
        'type' => 'varchar',
183
        'not null' => TRUE,
184
        'default' => '',
185
        'length' => 128,
186
        'description' => 'Name of the CKEditor role',
187
      ),
188
      'format' => array(
189
        'type' => 'varchar',
190
        'not null' => TRUE,
191
        'default' => '',
192
        'length' => 128,
193
        'description' => 'Drupal filter format ID',
194
      )
195
    ),
196
    'primary key' => array('name', 'format'),
197
  );
198

    
199
  return $schema;
200
}
201

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

    
213
  if ($phase == 'runtime') {
214
    module_load_include('module', 'ckeditor');
215
    module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
216
    $requirements['ckeditor'] = array(
217
      'title' => t('CKEditor'),
218
      'value' => t('Unknown'),
219
    );
220

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

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

    
226
      $requirements['ckeditor']['description'] = t('CKEditor was not found in <code>%sourcepath</code>.', array('%sourcepath' => $sourcepath));
227
      $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
228
    }
229
    elseif (($installed_version = _ckeditor_requirements_getinstalledversion()) === NULL) {
230
      $requirements['ckeditor']['description'] = t('CKEditor version could not be determined.');
231
      $requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
232
    }
233
    else {
234
      $profile_name = _ckeditor_requirements_ckfinder_filebrowser_enabled();
235
      if ($profile_name !== FALSE) {
236
        if (!_ckeditor_requirements_cookiedomainset()) {
237
          $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
238
          $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))));
239
        }
240
        elseif ($error = _ckeditor_requirements_ckfinder_config_check($profile_name)) {
241
          $requirements['ckeditor']['severity'] = REQUIREMENT_ERROR;
242
          $requirements['ckeditor']['description'] = $error;
243
        }
244
      }
245
    }
246
    if ((($installed_version = _ckeditor_requirements_getinstalledversion()) !== NULL) && $installed_version != '%VERSION%' && $installed_version != '<URL>' && (-1 == version_compare($installed_version, '3.1 SVN'))) {
247
      $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).');
248
      $requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
249
    }
250
    if (!empty($installed_version)) {
251
      if ($installed_version == '%VERSION%') {
252
        $requirements['ckeditor']['value'] = 'GIT version';
253
      }
254
      else if ($installed_version == '<URL>') {
255
        $requirements['ckeditor']['value'] = 'Unknown version. CKEditor is loaded from a remote URL.';
256
        $requirements['ckeditor']['severity'] = REQUIREMENT_INFO;
257
      }
258
      else {
259
        $requirements['ckeditor']['value'] = $installed_version;
260
      }
261
    }
262
    else {
263
      $requirements['ckeditor']['value'] = t('Not found');
264
    }
265
  }
266

    
267
  return $requirements;
268
}
269

    
270
/**
271
 * Fetches the version of the installed CKEditor sources.
272
 *
273
 * It tries to locate the version of the CKEditor sources in
274
 * ckeditor.js.
275
 *
276
 * Releases have a version number such as "3.0.1".
277
 * SVN nightly releases have a minor version number with SVN appended: "3.0 SVN".
278
 * SVN checkouts have the string "[Development]".
279
 *
280
 * This function is used by ckeditor_requirements().
281
 *
282
 * @return string Version number (eg. 3.0) of CKEditor. Null if not found in ckeditor_basic.js.
283
 */
284
function _ckeditor_requirements_getinstalledversion() {
285
  module_load_include('module', 'ckeditor');
286
  $editor_path = ckeditor_path('local', TRUE);
287
  if ($editor_path == '<URL>') {
288
    $url = ckeditor_path('url', TRUE);
289
    $matches = array();
290
    if (preg_match("|cdn.ckeditor.com/(\d(\.\d+)+.*)/|i", $url, $matches)) {
291
      return $matches[1];
292
    }
293
    return '<URL>';
294
  }
295
  $jspath = $editor_path . '/ckeditor.js';
296

    
297
  $configcontents = @file_get_contents($jspath);
298
  if (!$configcontents) {
299
    return NULL;
300
  }
301
  $matches = array();
302
  if (preg_match('#,version:[\'\"]{1}(.*?)[\'\"]{1},#', $configcontents, $matches)) {
303
    return $matches[1];
304
  }
305
  return NULL;
306
}
307

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

    
319
  if (!file_exists($config_path)) {
320
    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(
321
          '!config' => $config_path,
322
          '!ckfinder' => '<a href="http://cksource.com/ckfinder">CKFinder</a>',
323
          '!global' => l(t('CKEditor Global Profile'), 'admin/config/content/ckeditor/editg')
324
        ));
325
  }
326

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

    
331
  $config_contents = file($config_path);
332

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

    
339
  if ($config_contents) {
340
    foreach ($config_contents as $line_num => $line) {
341
      //make sure it doesn't start with a comment, unfortunately we're not protected if code is commented with /* */
342
      if (!$require_once_found && strpos($line, "filemanager.config.php") !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
343
        $require_once_found = TRUE;
344
        $require_once_line = $line_num;
345
      }
346
      /**
347
       * @todo Finish this
348
       */
349
      if (!$userfiles_absolute_path_line && strpos($line, '$Config[\'UserFilesAbsolutePath\']') !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
350
        $userfiles_absolute_path_line = $line_num;
351
      }
352
      if (!$force_single_extension_line && strpos($line, '$Config[\'ForceSingleExtension\']') !== FALSE && !preg_match(",^(?://|\#|\*|/\*),", trim($line))) {
353
        $force_single_extension_line = $line_num;
354
      }
355
    }
356
  }
357

    
358
  if (!$require_once_found) {
359
    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))));
360
  }
361

    
362
  if ($userfiles_absolute_path_line && $force_single_extension_line && (
363
      $require_once_line < $userfiles_absolute_path_line || $require_once_line > $force_single_extension_line)) {
364
    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));
365
  }
366

    
367
  return FALSE;
368
}
369

    
370
/**
371
 * Checks if any profile requires an explicit setting of $cookie_domain
372
 * in settings.php.
373
 *
374
 * %cookie_domain is required when the internal file browser or quick upload is used.
375
 *
376
 * This function is used by ckeditor_requirements().
377
 *
378
 * @return boolean True if any profile requires $cookie_domain.
379
 */
380
function _ckeditor_requirements_ckfinder_filebrowser_enabled() {
381
  module_load_include('module', 'ckeditor');
382
  $profiles = ckeditor_profile_load();
383

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

    
390
  return FALSE;
391
}
392

    
393
/**
394
 * Checks if $cookie_domain was set.
395
 *
396
 * It has to include settings.php again because conf_init() sets
397
 * $cookie_domain regardless of its presence in settings.php, so
398
 * simply checking $GLOBALS['cookie_domain'] is not possible.
399
 *
400
 * This function is used by ckeditor_requirements().
401
 *
402
 * @return boolean True if $cookie_domain was set in settings.php.
403
 */
404
function _ckeditor_requirements_cookiedomainset() {
405
  if (file_exists('./' . conf_path() . '/settings.php')) {
406
    $settings = file_get_contents('./' . conf_path() . '/settings.php');
407

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

    
413
  return FALSE;
414
}
415

    
416
/**
417
 * Updates broken settings for the 'Full' profile. (Resets toolbar to default)
418
 */
419
function ckeditor_update_7000() {
420
  _ckeditor_d6_to_d7_migration();
421
  $result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(':name' => 'Full'))->fetchField();
422
  $settings = unserialize($result);
423
  $settings['toolbar'] = "
424
[
425
    ['Source'],
426
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
427
    ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
428
    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
429
    '/',
430
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
431
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
432
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],
433
    ['Link','Unlink','Anchor'],
434
    ['DrupalBreak'],
435
    '/',
436
    ['Format','Font','FontSize'],
437
    ['TextColor','BGColor'],
438
    ['Maximize', 'ShowBlocks']
439
]
440
    ";
441

    
442
  $settings = serialize($settings);
443

    
444
  $update = db_update('ckeditor_settings')
445
      ->fields(array(
446
        'settings' => $settings,
447
      ))
448
      ->condition('name', 'Full', '=')
449
      ->execute();
450
}
451

    
452
/**
453
 * Removes the 'DrupalBreak' button from the 'Advanced' profile. (Resets toolbar to default)
454
 */
455
function ckeditor_update_7001() {
456
  $result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(':name' => 'Advanced'))->fetchField();
457
  $settings = unserialize($result);
458
  $settings['toolbar'] = "
459
[
460
    ['Source'],
461
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
462
    ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
463
    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
464
    ['Maximize', 'ShowBlocks'],
465
    '/',
466
    ['Format'],
467
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
468
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
469
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl'],
470
    ['Link','Unlink','Anchor']
471
]
472
    ";
473

    
474
  $settings = serialize($settings);
475

    
476
  $update = db_update('ckeditor_settings')
477
      ->fields(array(
478
        'settings' => $settings,
479
      ))
480
      ->condition('name', 'Advanced', '=')
481
      ->execute();
482
}
483

    
484
/**
485
 * Rewrites 'Path to CKEditor' to new flags.
486
 */
487
function ckeditor_update_7002() {
488
  $result = db_query("SELECT settings FROM {ckeditor_settings} WHERE name = :name", array(':name' => 'CKEditor Global Profile'))->fetchField();
489
  $settings = unserialize($result);
490
  if ($settings['ckeditor_path'] == '%b/sites/all/libraries/ckeditor') {
491
    $settings['ckeditor_path'] = '%l/ckeditor';
492
  }
493
  else {
494
    $settings['ckeditor_path'] = str_replace('%b/', '', $settings['ckeditor_path']);
495
    $settings['ckeditor_path'] = str_replace('%b', '', $settings['ckeditor_path']);
496
  }
497

    
498
  $settings = serialize($settings);
499

    
500
  $update = db_update('ckeditor_settings')
501
      ->fields(array(
502
        'settings' => $settings,
503
      ))
504
      ->condition('name', 'CKEditor Global Profile', '=')
505
      ->execute();
506
}
507

    
508
/**
509
 * Fixes static paths to plugin files.
510
 */
511
function ckeditor_update_7003() {
512
  module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
513
  module_load_include('module', 'ckeditor');
514

    
515
  _ckeditor_d6_to_d7_migration();
516

    
517
  $render = array();
518
  $render["%base_path%"] = base_path();
519
  $render["%editor_path%"] = ckeditor_path('relative') . '/';
520
  $render["%ckeditor_path%"] = ckeditor_module_path('relative');
521
  $render["%plugin_dir%"] = $render["%module_path%"] . '/plugins/';
522

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

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

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

    
533
    $settings = serialize($settings);
534

    
535
    $update = db_update('ckeditor_settings')
536
        ->fields(array(
537
          'settings' => $settings,
538
        ))
539
        ->condition('name', $name, '=')
540
        ->execute();
541
  }
542
}
543

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

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

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

    
563
    $replace = array(
564
      "%base_path%%editor_path%" => "%editor_path%",
565
      "%base_path%%module_path%" => "%module_path%",
566
      "%base_path%%plugin_dir%" => "%plugin_dir%",
567
      "%base_path%%plugin_dir_extra%" => "%plugin_dir_extra%"
568
    );
569

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

    
574
    $settings = serialize($settings);
575

    
576
    db_update('ckeditor_settings')
577
        ->fields(array(
578
          'settings' => $settings,
579
        ))
580
        ->condition('name', $name, '=')
581
        ->execute();
582
  }
583
}
584

    
585
/**
586
 * Adapts D6 table structure to D7 schema.
587
 */
588
function _ckeditor_d6_to_d7_migration() {
589
  if (db_table_exists('ckeditor_role')) {
590
    db_drop_table('ckeditor_role');
591
  }
592
  if (!db_table_exists('ckeditor_input_format')) {
593
    $ckeditor_input_format = array(
594
      'description' => 'Stores CKEditor input format assignments',
595
      'fields' => array(
596
        'name' => array(
597
          'type' => 'varchar',
598
          'not null' => TRUE,
599
          'default' => '',
600
          'length' => 128,
601
          'description' => 'Name of the CKEditor role',
602
        ),
603
        'format' => array(
604
          'type' => 'varchar',
605
          'not null' => TRUE,
606
          'default' => '',
607
          'length' => 128,
608
          'description' => 'Drupal filter format ID',
609
        )
610
      ),
611
      'primary key' => array('name', 'format'),
612
    );
613
    db_create_table('ckeditor_input_format', $ckeditor_input_format);
614
  }
615
}