Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ckeditor / includes / ckeditor.lib.inc @ 0695d136

1
<?php
2

    
3
/**
4
 * CKEditor - The text editor for the Internet - http://ckeditor.com
5
 * Copyright (c) 2003-2013, 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
 * Guess the absolute server path to the document root
39
 * Usually it should return $_SERVER['DOCUMENT_ROOT']
40
 *
41
 * @todo Improve me!!
42
 * Returns absolute path or false on failure
43
 *
44
 * @return string|boolean
45
 */
46
function ckeditor_get_document_root_full_path() {
47
  $found = 0;
48
  $index_dir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); // {/dir1/dir2/home/drupal}/index.php
49
  if (getcwd() == $index_dir) {
50
    $found++;
51
  }
52
  $drupal_dir = base_path();
53
  $index_dir = str_replace('\\', "/", $index_dir);
54
  $drupal_dir = str_replace('\\', "/", $drupal_dir);
55
  $document_root_dir = $index_dir . '/' . str_repeat('../', substr_count($drupal_dir, '/') - 1);
56
  $document_root_dir = realpath($document_root_dir);
57
  $document_root_dir = rtrim($document_root_dir, '/\\');
58
  if ($document_root_dir == $_SERVER['DOCUMENT_ROOT']) {
59
    $found++;
60
  }
61
  $document_root_dir = str_replace('\\', '/', $document_root_dir);
62

    
63
  if ($document_root_dir != '') {
64
    $found++;
65
  }
66
  if (file_exists($document_root_dir)) {
67
    $found++;
68
  }
69
  if (file_exists($document_root_dir . base_path() . 'includes/bootstrap.inc')) {
70
    $found++;
71
  }
72

    
73
  if ($found >= 3) {
74
    return $document_root_dir;
75
  }
76
  else {
77
    return FALSE;
78
  }
79
}
80

    
81
/**
82
 * Emulates the asp Server.mapPath function.
83
 * Given an url path return the physical directory that it corresponds to.
84
 *
85
 * Returns absolute path or false on failure
86
 *
87
 * @param string $path
88
 * @return string|boolean
89
 */
90
function ckeditor_resolve_url($path) {
91
  if (function_exists('apache_lookup_uri')) {
92
    $info = @apache_lookup_uri($path);
93
    if (!$info) {
94
      return FALSE;
95
    }
96
    return $info->filename . $info->path_info;
97
  }
98

    
99
  $document_root = ckeditor_get_document_root_full_path();
100
  if ($document_root !== FALSE) {
101
    return $document_root . $path;
102
  }
103

    
104
  return FALSE;
105
}
106

    
107
/**
108
 * List of configured CKEditor toolbars
109
 *
110
 * @return array
111
 */
112
function ckeditor_load_toolbar_options() {
113
  $arr = array('Basic' => 'Basic', 'Full' => 'Full');
114
  $module_drupal_path = drupal_get_path('module', 'ckeditor');
115
  $editor_local_path = ckeditor_path('local');
116
  $ckconfig_js = $editor_local_path . '/config.js';
117
  $ckeditor_config_js = $module_drupal_path . '/ckeditor.config.js';
118
  if ($editor_local_path != '<URL>' && file_exists($ckconfig_js) && is_readable($ckconfig_js)) {
119
    $fp = @fopen($ckconfig_js, "r");
120
    if ($fp) {
121
      while (!feof($fp)) {
122
        $line = fgets($fp, 1024);
123
        $matches = array();
124
        if (preg_match('/config.toolbar_([a-z0-9_]+)/i', $line, $matches)) {
125
          $arr[$matches[1]] = drupal_ucfirst($matches[1]);
126
        }
127
      }
128
      fclose($fp);
129
    }
130
  }
131
  if (file_exists($ckeditor_config_js) && is_readable($ckeditor_config_js)) {
132
    $fp = @fopen($ckeditor_config_js, "r");
133
    if ($fp) {
134
      while (!feof($fp)) {
135
        $line = fgets($fp, 1024);
136
        $matches = array();
137
        if (preg_match('/config.toolbar_([a-z0-9_]+)/i', $line, $matches)) {
138
          $arr[$matches[1]] = drupal_ucfirst($matches[1]);
139
        }
140
      }
141
      fclose($fp);
142
    }
143
  }
144

    
145
  //oops, we have no information about toolbars, let's use hardcoded array
146
  if (empty($arr)) {
147
    $arr = array(
148
      'Basic' => 'Basic',
149
      'Default' => 'Default',
150
    );
151
  }
152
  asort($arr);
153

    
154
  return $arr;
155
}
156

    
157
/**
158
 * List of installed CKEditor skins
159
 *
160
 * @return array
161
 */
162
function ckeditor_load_skin_options() {
163
  $arr = array();
164
  $editor_local_path = ckeditor_path('local');
165
  $skin_dir = $editor_local_path . '/skins';
166
  if ($editor_local_path != '<URL>' && is_dir($skin_dir)) {
167
    $dh = @opendir($skin_dir);
168
    if (FALSE !== $dh) {
169
      while (($file = readdir($dh)) !== FALSE) {
170
        if (in_array($file, array(".", "..", "CVS", ".svn"))) {
171
          continue;
172
        }
173
        if (is_dir($skin_dir . DIRECTORY_SEPARATOR . $file)) {
174
          $arr[$file] = drupal_ucfirst($file);
175
        }
176
      }
177
      closedir($dh);
178
    }
179
  }
180
  //oops, we have no information about skins, let's use only default
181
  if (empty($arr)) {
182
    $arr = array(
183
      'moono' => 'Moono',
184
      'kama' => 'Kama'
185
    );
186
  }
187
  asort($arr);
188

    
189
  return $arr;
190
}
191

    
192
/**
193
 * Return default skin for CKEditor
194
 *
195
 * @return string
196
 */
197
function ckeditor_default_skin() {
198
  $skin_options = ckeditor_load_skin_options();
199
  if (array_key_exists('moono', $skin_options)) {
200
    return 'moono';
201
  }
202
  if (array_key_exists('kama', $skin_options)) {
203
    return 'kama';
204
  }
205
  reset($skin_options);
206
  //if any default theme not exists select first from the list
207
  return key($skin_options);
208
}
209

    
210
/**
211
 * List of installed CKEditor languages
212
 *
213
 * @return array
214
 */
215
function ckeditor_load_lang_options() {
216
  $arr = array();
217
  $editor_local_path = ckeditor_path('local');
218
  $lang_file = $editor_local_path . '/lang/_languages.js';
219
  if ($editor_local_path != '<URL>' && file_exists($lang_file)) {
220
    $f = fopen($lang_file, 'r');
221
    $file = fread($f, filesize($lang_file));
222
    $tmp = explode('{', $file);
223
    if (isset($tmp[2])) {
224
      $tmp = explode('}', $tmp[2]);
225
    }
226
    $langs = explode(',', $tmp[0]);
227
    foreach ($langs AS $key => $lang) {
228
      preg_match("/'?(\w+-?\w+)'?:'([\w\s\(\)]+)'/i", $lang, $matches);
229
      if (isset($matches[1]) && isset($matches[2]))
230
        $arr[$matches[1]] = $matches[2];
231
    }
232
  }
233
  //oops, we have no information about languages, let's use those available in CKEditor 2.4.3
234
  if (empty($arr)) {
235
    $arr = array(
236
      'af' => 'Afrikaans',
237
      'ar' => 'Arabic',
238
      'bg' => 'Bulgarian',
239
      'bn' => 'Bengali/Bangla',
240
      'bs' => 'Bosnian',
241
      'ca' => 'Catalan',
242
      'cs' => 'Czech',
243
      'da' => 'Danish',
244
      'de' => 'German',
245
      'el' => 'Greek',
246
      'en' => 'English',
247
      'en-au' => 'English (Australia)',
248
      'en-ca' => 'English (Canadian)',
249
      'en-uk' => 'English (United Kingdom)',
250
      'eo' => 'Esperanto',
251
      'es' => 'Spanish',
252
      'et' => 'Estonian',
253
      'eu' => 'Basque',
254
      'fa' => 'Persian',
255
      'fi' => 'Finnish',
256
      'fo' => 'Faroese',
257
      'fr' => 'French',
258
      'gl' => 'Galician',
259
      'he' => 'Hebrew',
260
      'hi' => 'Hindi',
261
      'hr' => 'Croatian',
262
      'hu' => 'Hungarian',
263
      'it' => 'Italian',
264
      'ja' => 'Japanese',
265
      'km' => 'Khmer',
266
      'ko' => 'Korean',
267
      'lt' => 'Lithuanian',
268
      'lv' => 'Latvian',
269
      'mn' => 'Mongolian',
270
      'ms' => 'Malay',
271
      'nb' => 'Norwegian Bokmal',
272
      'nl' => 'Dutch',
273
      'no' => 'Norwegian',
274
      'pl' => 'Polish',
275
      'pt' => 'Portuguese (Portugal)',
276
      'pt-br' => 'Portuguese (Brazil)',
277
      'ro' => 'Romanian',
278
      'ru' => 'Russian',
279
      'sk' => 'Slovak',
280
      'sl' => 'Slovenian',
281
      'sr' => 'Serbian (Cyrillic)',
282
      'sr-latn' => 'Serbian (Latin)',
283
      'sv' => 'Swedish',
284
      'th' => 'Thai',
285
      'tr' => 'Turkish',
286
      'uk' => 'Ukrainian',
287
      'vi' => 'Vietnamese',
288
      'zh' => 'Chinese Traditional',
289
      'zh-cn' => 'Chinese Simplified',
290
    );
291
  }
292
  asort($arr);
293
  return $arr;
294
}
295

    
296
/**
297
 * Get the language locale code supported by Scayt for the specified language
298
 */
299
function ckeditor_scayt_langcode($lang) {
300
  $scayt_langs = array(
301
    'en' => 'en_US',
302
    'es' => 'es_ES',
303
    'fr' => 'fr_FR',
304
    'de' => 'de_DE',
305
    'it' => 'it_IT',
306
    'el' => 'el_EL',
307
    'pt' => 'pt_PT',
308
    'da' => 'da_DA',
309
    'sv' => 'sv_SE',
310
    'nl' => 'nl_NL',
311
    'nb' => 'no_NO',
312
    'fi' => 'fi_FI',
313
  );
314
  if (array_key_exists($lang, $scayt_langs)) {
315
    return $scayt_langs[$lang];
316
  }
317

    
318
  $default = language_default();
319
  $default = $default->language;
320
  if (array_key_exists($default, $scayt_langs)) {
321
    return $scayt_langs[$default];
322
  }
323

    
324
  return 'en_US';
325
}
326

    
327
/**
328
 * List of CKEditor plugins;
329
 *
330
 * @return array
331
 */
332
function ckeditor_load_plugins($render = FALSE) {
333
  $arr = array();
334
  $base_path = '%base_path%';
335
  $editor_path = '%editor_path%';
336
  $plugin_dir = '%plugin_dir%';
337
  $plugin_dir_additional = '%plugin_dir_extra%';
338
  $pattern = '#\.addButton\([\s]*[\'"](.*?)[\'"][\s]*\,[\s]*\{[\s]*(.*?)[\s]*\}#s';
339

    
340
  /*
341
   * External plugins
342
   */
343
  if (module_exists('ckeditor_swf') && file_exists(drupal_get_path('module', 'ckeditor_swf') . '/plugins/swf/plugin.js')) {
344
    $arr['ckeditor_swf'] = array(
345
      'name' => 'swf',
346
      'desc' => t('Support for the CKEditor SWF module'),
347
      'path' => $base_path . drupal_get_path('module', 'ckeditor_swf') . '/plugins/swf/',
348
      'buttons' => FALSE,
349
      'default' => 't'
350
    );
351
  }
352

    
353
  if (module_exists('ckeditor_link') && file_exists(drupal_get_path('module', 'ckeditor_link') . '/plugins/link/plugin.js')) {
354
    $arr['ckeditor_link'] = array(
355
      'name' => 'drupal_path',
356
      'desc' => t('Support for the CKEditor Link module'),
357
      'path' => $base_path . drupal_get_path('module', 'ckeditor_link') . '/plugins/link/',
358
      'buttons' => FALSE,
359
      'default' => 't'
360
    );
361
  }
362

    
363
  if (module_exists('linkit') && file_exists(drupal_get_path('module', 'linkit') . '/editors/ckeditor/plugin.js')) {
364
    $arr['linkit'] = array(
365
      'name' => 'Linkit',
366
      'desc' => t('Support for the Linkit module <em>(buttons: Linkit)</em>'),
367
      'path' => $base_path . drupal_get_path('module', 'linkit') . '/editors/ckeditor/',
368
      'buttons' => array(
369
        'Linkit' => array(
370
          'title' => 'Linkit',
371
          'icon' => $base_path . drupal_get_path('module', 'linkit') . '/editors/ckeditor/linkit.png'
372
        )
373
      ),
374
      'default' => 't'
375
    );
376
  }
377

    
378
  /*
379
   * CKEditor build-in plugins
380
   */
381
  $_editor_path = ckeditor_path('local');
382
  //die($editor_path);
383
  if ($_editor_path != '<URL>') {
384
    if (file_exists($_editor_path . '/plugins/tableresize/plugin.js')) {
385
      $arr['tableresize'] = array(
386
        'name' => 'tableresize',
387
        'desc' => t('Table Resize plugin'),
388
        'path' => $editor_path . '/plugins/tableresize/',
389
        'buttons' => FALSE,
390
        'default' => 't'
391
      );
392
    }
393

    
394
    if (file_exists($_editor_path . '/plugins/autogrow/plugin.js')) {
395
      $arr['autogrow'] = array(
396
        'name' => 'autogrow',
397
        'desc' => t('Auto Grow plugin'),
398
        'path' => $editor_path . '/plugins/autogrow/',
399
        'buttons' => FALSE,
400
        'default' => 'f'
401
      );
402
    }
403

    
404
    if (file_exists($_editor_path . '/plugins/stylesheetparser/plugin.js')) {
405
      $arr['stylesheetparser'] = array(
406
        'name' => 'stylesheetparser',
407
        'desc' => t('Stylesheet Parser plugin'),
408
        'path' => $editor_path . '/plugins/stylesheetparser/',
409
        'buttons' => FALSE,
410
        'default' => 'f'
411
      );
412
    }
413
  }
414
  else {
415
    $_editor_url = ckeditor_path('url');
416
    if (preg_match("/\/(standard|full)-all/", $_editor_url)) {
417
      $arr['tableresize'] = array(
418
        'name' => 'tableresize',
419
        'desc' => t('Table Resize plugin. See !link for more details.', array(
420
          '!link' => l(t('addon page'), 'http://ckeditor.com/addon/tableresize')
421
        )),
422
        'path' => $_editor_url . '/plugins/tableresize/',
423
        'buttons' => FALSE,
424
        'default' => 't'
425
      );
426
      $arr['autogrow'] = array(
427
        'name' => 'autogrow',
428
        'desc' => t('Auto Grow plugin. See !link for more details.', array(
429
            '!link' => l(t('addon page'), 'http://ckeditor.com/addon/autogrow')
430
          )),
431
        'path' => $_editor_url . '/plugins/autogrow/',
432
        'buttons' => FALSE,
433
        'default' => 'f'
434
      );
435
      $arr['stylesheetparser'] = array(
436
        'name' => 'stylesheetparser',
437
        'desc' => t('Stylesheet Parser plugin. See !link for more details.', array(
438
          '!link' => l(t('addon page'), 'http://ckeditor.com/addon/stylesheetparser')
439
        )),
440
        'path' => $_editor_url . '/plugins/stylesheetparser/',
441
        'buttons' => FALSE,
442
        'default' => 'f'
443
      );
444
      $arr['codesnippet'] = array(
445
        'name' => 'codesnippet',
446
        'desc' => t('Plugin for inserting Code Snippets. See !link for more details. See !help for additional instructions.', array(
447
            '!link' => l(t('addon page'), 'http://ckeditor.com/addon/codesnippet'),
448
            '!help' => l(t('help'), 'admin/help/ckeditor', array('fragment' => 'codesnippet'))
449
          )),
450
        'path' => $_editor_url . '/plugins/codesnippet/',
451
        'buttons' => array(
452
          'CodeSnippet' => array(
453
            'icon' => 'icons/codesnippet.png',
454
            'label' => 'Insert Code Snippet',
455
          )
456
        ),
457
        'default' => 'f'
458
      );
459
      $arr['mathjax'] = array(
460
        'name' => 'mathjax',
461
        'desc' => t('Plugin for inserting Mathematical Formula (MathJax). See !link for more details. See !help for additional instructions.', array(
462
          '!link' => l(t('addon page'), 'http://ckeditor.com/addon/mathjax'),
463
          '!help' => l(t('help'), 'admin/help/ckeditor', array('fragment' => 'mathjax'))
464
        )),
465
        'path' => $_editor_url . '/plugins/mathjax/',
466
        'buttons' => array(
467
          'Mathjax' => array(
468
            'icon' => 'icons/mathjax.png',
469
            'label' => 'Insert Mathematical Formulas',
470
          )
471
        ),
472
        'default' => 'f'
473
      );
474
    }
475
  }
476

    
477
  /*
478
   * CKEditor module plugins
479
   */
480
  $_plugin_dir = ckeditor_module_path('local') . '/plugins/';
481
  if ($handle = opendir($_plugin_dir)) {
482
    while (false !== ($file = readdir($handle))) {
483
      if (is_dir($_plugin_dir . $file) && file_exists($_plugin_dir . $file . '/plugin.js')) {
484
        $source = file_get_contents($_plugin_dir . $file . '/plugin.js');
485
        $buttons = array();
486
        if (preg_match_all($pattern, $source, $matches)) {
487
          foreach ($matches[1] as $i => $button_name) {
488
            if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$i], $matches2)) {
489
              $buttons[$button_name] = array();
490
              $buttons[$button_name]['label'] = $button_name;
491
              $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]);
492
              $buttons[$button_name]['icon'] = trim($matches2[2]);
493
            }
494
          }
495
        }
496
        if (preg_match('#@file ([^\n\r]*)#', $source, $matches)) {
497
          $arr[$file] = array(
498
            'name' => $file,
499
            'desc' => t($matches[1]),
500
            'path' => $plugin_dir . $file . '/',
501
            'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
502
            'default' => 'f'
503
          );
504
        }
505
        else {
506
          $arr[$file] = array(
507
            'name' => $file,
508
            'desc' => t('Plugin file: ' . $file),
509
            'path' => $plugin_dir . $file . '/',
510
            'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
511
            'default' => 'f'
512
          );
513
        }
514
      }
515
    }
516
    closedir($handle);
517
  }
518

    
519
  /*
520
   * CKEditor module plugins - additional directory
521
   */
522
  $_plugin_dir_additional = ckeditor_plugins_path('local') . '/';
523
  if ($_plugin_dir != $_plugin_dir_additional && is_dir($_plugin_dir_additional) && $handle = opendir($_plugin_dir_additional)) {
524
    while (false !== ($file = readdir($handle))) {
525
      if (is_dir($_plugin_dir_additional . $file) && file_exists($_plugin_dir_additional . $file . '/plugin.js')) {
526
        $source = file_get_contents($_plugin_dir_additional . $file . '/plugin.js');
527
        $buttons = array();
528
        if (preg_match_all($pattern, $source, $matches)) {
529
          foreach ($matches[1] as $i => $button_name) {
530
            if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$i], $matches2)) {
531
              $buttons[$button_name] = array();
532
              $buttons[$button_name]['label'] = $button_name;
533
              $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]);
534
              $buttons[$button_name]['icon'] = trim($matches2[2]);
535
            }
536
          }
537
        }
538
        if (preg_match('#@file ([^\n\r]*)#', $source, $matches)) {
539
          $arr[$file] = array(
540
            'name' => $file,
541
            'desc' => t($matches[1]),
542
            'path' => $plugin_dir_additional . $file . '/',
543
            'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
544
            'default' => 'f'
545
          );
546
        }
547
        else {
548
          $arr[$file] = array(
549
            'name' => $file,
550
            'desc' => t('Plugin file: ' . $file),
551
            'path' => $plugin_dir_additional . $file . '/',
552
            'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
553
            'default' => 'f'
554
          );
555
        }
556
      }
557
    }
558

    
559
    closedir($handle);
560
  }
561

    
562
  /*
563
   * CKEditor plugins registered by hook
564
   */
565
  $plugins = module_invoke_all('ckeditor_plugin');
566

    
567
  foreach ($plugins as $i => $plugin) {
568
    if (file_exists($plugin['path'] . 'plugin.js')) {
569
      $source = file_get_contents($plugin['path'] . 'plugin.js');
570
      $plugins[$i]['path'] = $base_path . $plugin['path'];
571
      if (!isset($plugin['buttons']) || count($plugin['buttons']) == 0) {
572
        $buttons = array();
573
        if (preg_match_all($pattern, $source, $matches)) {
574
          foreach ($matches[1] as $j => $button_name) {
575
            if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$j], $matches2)) {
576
              $buttons[$button_name] = array();
577
              $buttons[$button_name]['label'] = $button_name;
578
              $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]);
579
              $buttons[$button_name]['icon'] = trim($matches2[2]);
580
            }
581
          }
582
        }
583
        $plugins[$i]['buttons'] = (count($buttons) > 0) ? $buttons : FALSE;
584
      }
585
    }
586
    else {
587
      unset($plugins[$i]);
588
    }
589
  }
590
  $arr = array_merge($arr, $plugins);
591

    
592
  if (isset($arr['media']) && module_exists('media') == FALSE) {
593
    unset($arr['media']);
594
  }
595

    
596
  if (isset($arr['imce']) && module_exists('imce') == FALSE) {
597
    unset($arr['imce']);
598
  }
599
  //remove page break button if there is no module to do this
600
  if (isset($arr['drupalbreaks']['buttons']['DrupalPageBreak']) && !module_exists('paging') && !module_exists('pagebreak') && !module_exists('smart_paging')) {
601
    unset($arr['drupalbreaks']['buttons']['DrupalPageBreak']);
602
  }
603

    
604
  if (isset($arr['drupalbreaks'])) {
605
    $arr['drupalbreaks']['default'] = 't';
606
  }
607

    
608
  ksort($arr);
609
  if ($render === TRUE) {
610
    $arr = ckeditor_plugins_render($arr);
611
  }
612
  return $arr;
613
}
614

    
615
/**
616
 * Render CKEditor plugins path
617
 */
618
function ckeditor_plugins_render($plugins) {
619
  $render = array();
620
  $render["%base_path%"] = ckeditor_base_path('relative') . '/';
621
  $render["%editor_path%"] = ckeditor_path('relative') . '/';
622
  $render["%module_path%"] = ckeditor_module_path('relative') . '/';
623
  $render["%plugin_dir%"] = $render["%module_path%"] . 'plugins/';
624
  $render["%plugin_dir_extra%"] = ckeditor_plugins_path('relative') . '/';
625

    
626
  foreach ((array) $plugins as $i => $plugin) {
627
    $plugins[$i]['path'] = str_replace(array_keys($render), array_values($render), $plugin['path']);
628
  }
629

    
630
  return $plugins;
631
}
632

    
633
/**
634
 * Get default ckeditor settings
635
 *
636
 * @return array
637
 */
638
function ckeditor_user_get_setting_default() {
639
  $default = array(
640
    'default' => 't',
641
    'show_toggle' => 't',
642
    'width' => '100%',
643
    'lang' => 'en',
644
    'auto_lang' => 't',
645
  );
646

    
647
  // Allow other modules to alter the default settings.
648
  drupal_alter('ckeditor_default_settings', $default);
649

    
650
  return $default;
651
}
652

    
653
/**
654
 * Return CKEditor settings
655
 *
656
 * @param object $user
657
 * @param object $profile
658
 * @param string $setting
659
 * @return array
660
 */
661
function ckeditor_user_get_setting($user, $profile, $setting) {
662
  $default = ckeditor_user_get_setting_default();
663

    
664
  if (user_access('customize ckeditor')) {
665
    $status = isset($user->data['ckeditor_' . $setting]) ? $user->data['ckeditor_' . $setting] : (isset($profile->settings[$setting]) ? $profile->settings[$setting] : $default[$setting]);
666
  }
667
  else {
668
    $status = isset($profile->settings[$setting]) ? $profile->settings[$setting] : $default[$setting];
669
  }
670

    
671
  return $status;
672
}
673

    
674
/**
675
 * Return CKEditor profile by input format
676
 *
677
 * @param string $input_format
678
 * @return object|boolean
679
 */
680
function ckeditor_get_profile($input_format) {
681
  $select = db_select('ckeditor_settings', 's');
682
  $select->join('ckeditor_input_format', 'f', 'f.name = s.name');
683
  $result = $select->fields('s', array("name"))->condition('f.format', $input_format)->condition('f.name', 'CKEditor Global Profile', '<>')->range(0, 1)->execute()->fetchAssoc();
684

    
685
  if ($result && $profile = ckeditor_profile_load($result['name'])) {
686
    return $profile;
687
  }
688

    
689
  return FALSE;
690
}
691

    
692
/**
693
 * Return CKEditor profile list
694
 */
695
function ckeditor_profile_input_formats() {
696
  $select = db_select('ckeditor_settings', 's');
697
  $select->join('ckeditor_input_format', 'f', 'f.name = s.name');
698
  $result = $select->fields('s', array("name"))->fields('f', array("format"))->execute();
699

    
700
  $list = array();
701
  while ($row = $result->fetchAssoc()) {
702
    if (!isset($row['name'])) {
703
      $list[$row['name']] = array();
704
    }
705
    $list[$row['name']][] = $row['format'];
706
  }
707

    
708
  return $list;
709
}
710

    
711
/**
712
 * Search and return CKEditor plugin path
713
 *
714
 * @return string
715
 */
716
function _ckeditor_script_path() {
717
  $jspath = '';
718
  $module_path = drupal_get_path('module', 'ckeditor');
719

    
720
  if (file_exists($module_path . '/ckeditor/ckeditor.js')) {
721
    $jspath = '%m/ckeditor';
722
  }
723
  elseif (file_exists($module_path . '/ckeditor/ckeditor/ckeditor.js')) {
724
    $jspath = '%m/ckeditor/ckeditor';
725
  }
726
  elseif (file_exists(ckeditor_library_path('url') . '/ckeditor/ckeditor.js')) {
727
    $jspath = '%l/ckeditor';
728
  }
729
  return $jspath;
730
}
731

    
732
/**
733
 * Determines whether the CKEditor sources are present
734
 *
735
 * It checks if ckeditor.js is present.
736
 *
737
 * This function is used by ckeditor_requirements()
738
 *
739
 * @return boolean True if CKEditor is installed
740
 */
741
function _ckeditor_requirements_isinstalled() {
742
  $editor_path = ckeditor_path('local');
743
  if ($editor_path == '<URL>')
744
    return TRUE;
745
  $jspath = $editor_path . '/ckeditor.js';
746

    
747
  $jsp = file_exists($jspath);
748
  if (!$jsp && ($editor_path = _ckeditor_script_path())) {
749
    $result = db_select('ckeditor_settings', 's')->fields('s')->condition('name', 'CKEditor Global Profile')->execute()->fetchAssoc();
750
    if ($result) {
751
      $result['settings'] = unserialize($result['settings']);
752
      $result['settings']['ckeditor_path'] = $editor_path;
753
      $result['settings'] = serialize($result['settings']);
754
      db_update('ckeditor_settings')->fields(array("settings" => $result['settings']))->condition('name', 'CKEditor Global Profile')->execute();
755

    
756
      $jsp = TRUE;
757
      ckeditor_path('local', TRUE);
758
    }
759
  }
760
  return $jsp;
761
}
762

    
763
/**
764
 * Compile settings of all profiles at returns is as array
765
 *
766
 * @param string $input_format
767
 * @param boolean $clear
768
 * @return array
769
 */
770
function ckeditor_profiles_compile($input_format = FALSE, $clear = FALSE) {
771
  static $compiled = FALSE;
772
  static $_ckeditor_compiled = array();
773

    
774
  if ($clear !== FALSE && $compiled !== FALSE) {
775
    $compiled = FALSE;
776
  }
777

    
778
  if ($compiled === TRUE) {
779
    return ( $input_format === FALSE ) ? $_ckeditor_compiled : ( isset($_ckeditor_compiled[$input_format]) ? $_ckeditor_compiled[$input_format] : array() );
780
  }
781

    
782
  $global_profile = ckeditor_profile_load('CKEditor Global Profile');
783

    
784
  $profiles_list = ckeditor_profile_input_formats();
785

    
786
  foreach ($profiles_list AS $_profile => $_inputs) {
787
    $profile = ckeditor_profile_load($_profile);
788
    $setting = ckeditor_profile_settings_compile($global_profile, $profile);
789

    
790
    foreach ($_inputs AS $_input) {
791
      $_ckeditor_compiled[$_input] = $setting;
792
    }
793
  }
794

    
795
  $compiled = TRUE;
796

    
797
  return ( $input_format === FALSE ) ? $_ckeditor_compiled : $_ckeditor_compiled[$input_format];
798
}
799

    
800
/**
801
 * Compile settings of profile
802
 *
803
 * @param object $global_profile
804
 * @param object $profile
805
 * @return array
806
 */
807
function ckeditor_profile_settings_compile($global_profile, $profile) {
808
  global $user, $language, $theme;
809

    
810
  $current_theme = variable_get('theme_default', $theme);
811

    
812
  $settings = array();
813
  $conf = array();
814
  $conf = $profile->settings;
815
  $profile_name = $profile->name;
816

    
817
  if (user_access('customize ckeditor')) {
818
    foreach (array('default', 'show_toggle', 'width', 'lang', 'auto_lang') as $setting) {
819
      $conf[$setting] = ckeditor_user_get_setting($user, $profile, $setting);
820
    }
821
  }
822

    
823
  if (!isset($conf['ss'])) {
824
    $conf['ss'] = 2;
825
  }
826

    
827
  $themepath = drupal_get_path('theme', $current_theme) . '/';
828
  $host = base_path();
829

    
830
  // setting some variables
831
  $module_drupal_path = ckeditor_module_path('relative');
832
  $module_drupal_local_path = ckeditor_module_path('local');
833
  $editor_path = ckeditor_path('relative');
834
  $editor_local_path = ckeditor_path('local');
835

    
836
  $toolbar = $conf['toolbar'];
837

    
838
  if (!empty($conf['theme_config_js']) && $conf['theme_config_js'] == 't' && file_exists($themepath . 'ckeditor.config.js')) {
839
    $ckeditor_config_path = $host . $themepath . 'ckeditor.config.js?' . @filemtime($themepath . 'ckeditor.config.js');
840
  }
841
  else {
842
    $ckeditor_config_path = $module_drupal_path . "/ckeditor.config.js?" . @filemtime($module_drupal_path . "/ckeditor.config.js");
843
  }
844

    
845
  $settings['customConfig'] = $ckeditor_config_path;
846
  $settings['defaultLanguage'] = $conf['lang'];
847
  $settings['toolbar'] = $toolbar;
848
  $settings['enterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['enter_mode']));
849
  $settings['shiftEnterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['shift_enter_mode']));
850
  $settings['toolbarStartupExpanded'] = ( $conf['expand'] == 't' );
851
  if ($conf['expand'] == 'f') {
852
    $settings['toolbarCanCollapse'] = true;
853
  }
854
  $settings['width'] = $conf['width'];
855
  //check if skin exists, if not select default one
856
  if (isset($global_profile->settings['skin']) && file_exists($editor_local_path . '/skins/' . $global_profile->settings['skin'])) {
857
    $settings['skin'] = $global_profile->settings['skin'];
858
  }
859
  else {
860
    $settings['skin'] = ckeditor_default_skin();
861
  }
862
  $settings['format_tags'] = $conf['font_format'];
863
  $settings['show_toggle'] = $conf['show_toggle'];
864
  if (!empty($conf['allowed_content']) && $conf['allowed_content'] === 'f') {
865
    $settings['allowedContent'] = true;
866
  }
867
  elseif (!empty($conf['extraAllowedContent'])) {
868
    $settings['extraAllowedContent'] = $conf['extraAllowedContent'];
869
  }
870
  $settings['ss'] = $conf['ss'];
871

    
872
  if (isset($conf['language_direction'])) {
873
    switch ($conf['language_direction']) {
874
      case 'default':
875
        if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
876
          $settings['contentsLangDirection'] = 'rtl';
877
        }
878
        break;
879
      case 'ltr':
880
        $settings['contentsLangDirection'] = 'ltr';
881
        break;
882
      case 'rtl':
883
        $settings['contentsLangDirection'] = 'rtl';
884
        break;
885
    }
886
  }
887

    
888
  if (isset($conf['loadPlugins'])) {
889
    $settings['loadPlugins'] = ckeditor_plugins_render($conf['loadPlugins']);
890

    
891
    if (array_key_exists('media', $settings['loadPlugins']) && module_exists('media')) {
892
      module_load_include('inc', 'media', 'includes/media.browser');
893
      $javascript = media_browser_js();
894
      foreach ($javascript as $key => $definitions) {
895
        foreach ($definitions as $definition) {
896
          $function = 'drupal_add_' . $key;
897
          call_user_func_array($function, $definition);
898
        }
899
      }
900
      drupal_add_js(drupal_get_path('module', 'ckeditor') . '/plugins/media/library.js', array('scope' => 'footer', 'weight' => -20));
901
    }
902
  }
903
  else {
904
    $settings['loadPlugins'] = array();
905
  }
906

    
907
  //add support for divarea plugin from CKE4
908
  if (isset($conf['use_divarea']) && $conf['use_divarea'] == 't' && $editor_local_path != '<URL>' && file_exists($editor_local_path . '/plugins/divarea/plugin.js')) {
909
    $settings['loadPlugins']['divarea'] = array('name' => 'divarea', 'path' => $editor_path . '/plugins/divarea/', 'buttons' => FALSE, 'default' => 'f');
910
  }
911

    
912
  if (isset($conf['html_entities']) && $conf['html_entities'] == 'f') {
913
    $settings['entities'] = FALSE;
914
    $settings['entities_greek'] = FALSE;
915
    $settings['entities_latin'] = FALSE;
916
  }
917
  if (isset($conf['scayt_autoStartup']) && $conf['scayt_autoStartup'] == 't') {
918
    $settings['scayt_autoStartup'] = TRUE;
919
  }
920
  else {
921
    $settings['scayt_autoStartup'] = FALSE;
922
  }
923

    
924
  if ($conf['auto_lang'] == "f") {
925
    $settings['language'] = $conf['lang'];
926
    //[#1473010]
927
    $settings['scayt_sLang'] = ckeditor_scayt_langcode($conf['lang']);
928
  }
929

    
930
  if (isset($conf['forcePasteAsPlainText']) && $conf['forcePasteAsPlainText'] == 't') {
931
    $settings['forcePasteAsPlainText'] = TRUE;
932
  }
933

    
934
  if (isset($conf['custom_formatting']) && $conf['custom_formatting'] == 't') {
935
    foreach ($conf['formatting']['custom_formatting_options'] as $k => $v) {
936
      if ($v === 0) {
937
        $conf['formatting']['custom_formatting_options'][$k] = FALSE;
938
      }
939
      else {
940
        $conf['formatting']['custom_formatting_options'][$k] = TRUE;
941
      }
942
    }
943
    $settings['output_pre_indent'] = $conf['formatting']['custom_formatting_options']['pre_indent'];
944
    unset($conf['formatting']['custom_formatting_options']['pre_indent']);
945
    $settings['custom_formatting'] = $conf['formatting']['custom_formatting_options'];
946
  }
947

    
948
  // add code for filebrowser for users that have access
949
  $filebrowser = !empty($conf['filebrowser']) ? $conf['filebrowser'] : 'none';
950
  $filebrowser_image = !empty($conf['filebrowser_image']) ? $conf['filebrowser_image'] : $filebrowser;
951
  $filebrowser_flash = !empty($conf['filebrowser_flash']) ? $conf['filebrowser_flash'] : $filebrowser;
952

    
953
  if ($filebrowser == 'imce' && !module_exists('imce')) {
954
    $filebrowser = 'none';
955
  }
956

    
957
  if ($filebrowser == 'elfinder' && !module_exists('elfinder')) {
958
    $filebrowser = 'none';
959
  }
960

    
961
  /* MODULES NOT PORTED TO D7
962
    if ($filebrowser == 'tinybrowser' && !module_exists('tinybrowser')) {
963
    $filebrowser = 'none';
964
    }
965

    
966
    if ($filebrowser == 'ib' && !module_exists('imagebrowser')) {
967
    $filebrowser = 'none';
968
    }
969
    if ($filebrowser == 'webfm' && !module_exists('webfm_popup')) {
970
    $filebrowser = 'none';
971
    }
972
   */
973
  if ($filebrowser_image != $filebrowser) {
974
    if ($filebrowser_image == 'imce' && !module_exists('imce')) {
975
      $filebrowser_image = $filebrowser;
976
    }
977

    
978
    if ($filebrowser_image == 'elfinder' && !module_exists('elfinder')) {
979
      $filebrowser_image = $filebrowser;
980
    }
981
    /* MODULES NOT PORTED TO D7
982
      if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) {
983
      $filebrowser_image = $filebrowser;
984
      }
985
      if ($filebrowser_image == 'ib' && !module_exists('imagebrowser')) {
986
      $filebrowser_image = $filebrowser;
987
      }
988
      if ($filebrowser_image == 'webfm' && !module_exists('webfm_popup')) {
989
      $filebrowser_image = $filebrowser;
990
      }
991
     */
992
  }
993

    
994
  if ($filebrowser_flash != $filebrowser) {
995
    if ($filebrowser_flash == 'imce' && !module_exists('imce')) {
996
      $filebrowser_flash = $filebrowser;
997
    }
998

    
999
    if ($filebrowser_image == 'elfinder' && !module_exists('elfinder')) {
1000
      $filebrowser_flash = $filebrowser;
1001
    }
1002
    /* MODULES NOT PORTED TO D7
1003
      if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) {
1004
      $filebrowser_flash = $filebrowser;
1005
      }
1006
      if ($filebrowser_flash == 'ib' && !module_exists('imagebrowser')) {
1007
      $filebrowser_flash = $filebrowser;
1008
      }
1009
      if ($filebrowser_flash == 'webfm' && !module_exists('webfm_popup')) {
1010
      $filebrowser_flash = $filebrowser;
1011
      }
1012
     */
1013
  }
1014

    
1015
  if ($filebrowser == 'ckfinder' || $filebrowser_image == 'ckfinder' || $filebrowser_flash == 'ckfinder') {
1016
    if (user_access('allow CKFinder file uploads')) {
1017
      if (!empty($profile->settings['UserFilesPath'])) {
1018
        $_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = strtr($profile->settings['UserFilesPath'], array("%f" => variable_get('file_public_path', conf_path() . '/files'), "%u" => $user->uid, "%b" => $host, "%n" => $user->name));
1019
      }
1020
      else {
1021
        $_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = strtr('%b%f/', array("%f" => variable_get('file_public_path', conf_path() . '/files'), "%u" => $user->uid, "%b" => $host, "%n" => $user->name));
1022
      }
1023
      if (!empty($profile->settings['UserFilesAbsolutePath'])) {
1024
        $_SESSION['ckeditor'][$profile_name]['UserFilesAbsolutePath'] = strtr($profile->settings['UserFilesAbsolutePath'], array("%f" => variable_get('file_public_path', conf_path() . '/files'), "%u" => $user->uid, "%b" => base_path(), "%d" => ckeditor_get_document_root_full_path(), "%n" => $user->name));
1025
      }
1026
      else {
1027
        $_SESSION['ckeditor'][$profile_name]['UserFilesAbsolutePath'] = strtr('%d%b%f/', array("%f" => variable_get('file_public_path', conf_path() . '/files'), "%u" => $user->uid, "%b" => base_path(), "%d" => ckeditor_get_document_root_full_path(), "%n" => $user->name));
1028
      }
1029
      if (variable_get('file_default_scheme', '') == 'private') {
1030
        $private_dir = isset($global_profile->settings['private_dir']) ? trim($global_profile->settings['private_dir'], '/') : '';
1031
        if (!empty($private_dir)) {
1032
          $private_dir = strtr($private_dir, array('%u' => $user->uid, '%n' => $user->name));
1033
          $_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = url('system/files') . '/' . $private_dir . '/';
1034
          $private_upload_path = file_uri_target('private://' . variable_get('file_private_path', '')) . '/' . $private_dir;
1035
        }
1036
        else {
1037
          $_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = url('system/files') . '/';
1038
          $private_upload_path =  file_uri_target('private://' . variable_get('file_private_path', ''));
1039
        }
1040
        //add '/' to beginning of path if necessary
1041
        if (strpos(variable_get('file_private_path', ''), '/') === 0 && $private_upload_path[0] != '/') {
1042
          $private_upload_path = '/' . $private_upload_path;
1043
        }
1044
        //check if CKEditor private dir exists and create it if not
1045
        if ($private_dir && !is_dir($private_upload_path)) {
1046
          mkdir($private_upload_path, 0755, TRUE);
1047
        }
1048
        $_SESSION['ckeditor'][$profile_name]['UserFilesAbsolutePath'] = drupal_realpath($private_upload_path) . '/';
1049
      }
1050
    }
1051
  }
1052
  /* MODULES NOT PORTED TO D7
1053
    if (in_array('tinybrowser', array($filebrowser, $filebrowser_image, $filebrowser_flash))) {
1054
    $popup_win_size = variable_get('tinybrowser_popup_window_size', '770x480');
1055
    if (!preg_match('#\d+x\d+#is', $popup_win_size)) {
1056
    $popup_win_size = '770x480';
1057
    }
1058
    $popup_win_size = trim($popup_win_size);
1059
    $popup_win_size = strtolower($popup_win_size);
1060
    $win_size = split('x', $popup_win_size);
1061
    }
1062
   */
1063
  switch ($filebrowser) {
1064
    case 'ckfinder':
1065
      if (user_access('allow CKFinder file uploads')) {
1066
        $ckfinder_full_path = ckfinder_path('relative');
1067
        $settings['filebrowserBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?id=' . $profile_name;
1068
        $settings['filebrowserImageBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
1069
        $settings['filebrowserFlashBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Flash&id=' . $profile_name;
1070
        $settings['filebrowserUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Files&id=' . $profile_name;
1071
        $settings['filebrowserImageUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
1072
        $settings['filebrowserFlashUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Flash&id=' . $profile_name;
1073
      }
1074
      break;
1075
    case 'imce':
1076
      $settings['filebrowserBrowseUrl'] = url('imce', array('query' => array('app' => 'ckeditor|sendto@ckeditor_imceSendTo|')));
1077
      break;
1078
    case 'elfinder':
1079
      $settings['filebrowserBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
1080
      break;
1081
    /* MODULES NOT PORTED TO D7
1082
      case 'webfm':
1083
      if (user_access('access webfm')) {
1084
      $settings['filebrowserBrowseUrl'] = $host . "index.php?q=webfm_popup";
1085
      }
1086
      break;
1087
      case 'ib':
1088
      if (user_access('browse own images')) {
1089
      $settings['filebrowserBrowseUrl'] = $host . "index.php?q=imagebrowser/view/browser&app=ckeditor";
1090
      $settings['filebrowserWindowWidth'] = 700;
1091
      $settings['filebrowserWindowHeight'] = 520;
1092
      }
1093
      break;
1094
      case 'tinybrowser':
1095
      $settings['filebrowserBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=file";
1096
      $settings['filebrowserWindowWidth'] = (int) $win_size[0] + 15;
1097
      $settings['filebrowserWindowHeight'] = (int) $win_size[1] + 15;
1098
      break;
1099
     */
1100
  }
1101

    
1102
  if ($filebrowser_image != $filebrowser) {
1103
    switch ($filebrowser_image) {
1104
      case 'ckfinder':
1105
        if (user_access('allow CKFinder file uploads')) {
1106
          $ckfinder_full_path = ckfinder_path('relative');
1107
          $settings['filebrowserImageBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
1108
          $settings['filebrowserImageUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
1109
        }
1110
        break;
1111
      case 'imce':
1112
        $settings['filebrowserImageBrowseUrl'] = url('imce', array('query' => array('app' => 'ckeditor|sendto@ckeditor_imceSendTo|')));
1113
        break;
1114
      case 'elfinder':
1115
        $settings['filebrowserImageBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
1116
        break;
1117
      /* MODULES NOT PORTED TO D7
1118
        case 'webfm':
1119
        if (user_access('access webfm')) {
1120
        $settings['filebrowserImageBrowseUrl'] = $host . "index.php?q=webfm_popup";
1121
        }
1122
        break;
1123
        case 'ib':
1124
        if (user_access('browse own images')) {
1125
        $settings['filebrowserImageBrowseUrl'] = $host . "index.php?q=imagebrowser/view/browser&app=ckeditor";
1126
        $settings['filebrowserImageWindowWidth'] = 680;
1127
        $settings['filebrowserImageWindowHeight'] = 439;
1128
        }
1129
        break;
1130
        case 'tinybrowser':
1131
        $settings['filebrowserImageBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=image";
1132
        $settings['filebrowserImageWindowWidth'] = (int) $win_size[0] + 15;
1133
        $settings['filebrowserImageWindowHeight'] = (int) $win_size[1] + 15;
1134
        break;
1135
       */
1136
    }
1137
  }
1138

    
1139
  if ($filebrowser_flash != $filebrowser) {
1140
    switch ($filebrowser_flash) {
1141
      case 'ckfinder':
1142
        if (user_access('allow CKFinder file uploads')) {
1143
          $ckfinder_full_path = ckfinder_path('relative');
1144
          $settings['filebrowserFlashBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
1145
          $settings['filebrowserFlashUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
1146
        }
1147
        break;
1148
      case 'imce':
1149
        $settings['filebrowserFlashBrowseUrl'] = url('imce', array('query' => array('app' => 'ckeditor|sendto@ckeditor_imceSendTo|')));
1150
        break;
1151
      case 'elfinder':
1152
        $settings['filebrowserFlashBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
1153
        break;
1154
      /* MODULES NOT PORTED TO D7
1155
        case 'webfm':
1156
        if (user_access('access webfm')) {
1157
        $settings['filebrowserFlashBrowseUrl'] = $host . "index.php?q=webfm_popup";
1158
        }
1159
        break;
1160
        case 'ib':
1161
        if (user_access('browse own images')) {
1162
        $settings['filebrowserFlashBrowseUrl'] = $host . "index.php?q=imagebrowser/view/browser&app=ckeditor";
1163
        $settings['filebrowserFlashWindowWidth'] = 680;
1164
        $settings['filebrowserFlashWindowHeight'] = 439;
1165
        }
1166
        break;
1167
        case 'tinybrowser':
1168
        $settings['filebrowserFlashBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=media";
1169
        $settings['filebrowserFlashWindowWidth'] = (int) $win_size[0] + 15;
1170
        $settings['filebrowserFlashWindowHeight'] = (int) $win_size[1] + 15;
1171
        break;
1172
       */
1173
    }
1174
  }
1175

    
1176
  if (!empty($conf['js_conf'])) {
1177
    preg_match_all('#config\.(\w+)[\s]*=[\s]*(.+?);[\s]*(?=config\.|$)#is', preg_replace("/[\n\r]+/", "", $conf['js_conf']), $matches);
1178
    foreach ($matches[2] as $i => $match) {
1179
      if (!empty($match)) {
1180
        $value = trim($match, " ;\n\r\t\0\x0B");
1181
        if (strcasecmp($value, 'true') == 0) {
1182
          $value = TRUE;
1183
        }
1184
        if (strcasecmp($value, 'false') == 0) {
1185
          $value = FALSE;
1186
        }
1187
        $settings["js_conf"][$matches[1][$i]] = $value;
1188
      }
1189
    }
1190
  }
1191

    
1192
  $settings['stylesCombo_stylesSet'] = "drupal:" . $module_drupal_path . '/ckeditor.styles.js';
1193
  if (!empty($conf['css_style'])) {
1194
    if ($conf['css_style'] == 'theme' && file_exists($themepath . 'ckeditor.styles.js')) {
1195
      $settings['stylesCombo_stylesSet'] = "drupal:" . $host . $themepath . 'ckeditor.styles.js';
1196
    }
1197
    elseif (!empty($conf['css_style']) && $conf['css_style'] == 'self') {
1198
      $conf['styles_path'] = str_replace("%h%t", "%t", $conf['styles_path']);
1199
      $settings['stylesCombo_stylesSet'] = "drupal:" . str_replace(array('%h', '%t', '%m'), array($host, $host . $themepath, $module_drupal_path), $conf['styles_path']);
1200
    }
1201
  }
1202

    
1203
  // add custom stylesheet if configured
1204
  // lets hope it exists but we'll leave that to the site admin
1205
  $query_string = '?' . variable_get('css_js_query_string', '0');
1206
  $css_files = array();
1207
  switch ($conf['css_mode']) {
1208
    case 'theme':
1209
      global $language, $base_theme_info;
1210
      $themes = list_themes();
1211
      $theme_info = $themes[$current_theme];
1212
      if (!empty($theme_info->stylesheets)) {
1213
        $editorcss = "\"";
1214
        foreach ($base_theme_info as $base) { // Grab stylesheets from base theme
1215
          if (!empty($base->stylesheets)) { // may be empty when the base theme reference in the info file is invalid
1216
            foreach ($base->stylesheets as $type => $stylesheets) {
1217
              if ($type != "print") {
1218
                foreach ($stylesheets as $name => $path) {
1219
                  if (file_exists($path)) {
1220
                    $css_files[$name] = $host . $path . $query_string;
1221
                    // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) )
1222
                    if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path, 0, -8) != "-rtl.css") {
1223
                      $rtl_path = substr($path, 0, -4) . "-rtl.css";
1224
                      if (file_exists($rtl_path)) {
1225
                        $css_files[$name . "-rtl"] = $host . $rtl_path . $query_string;
1226
                      }
1227
                    }
1228
                  }
1229
                }
1230
              }
1231
            }
1232
          }
1233
        }
1234
        if (!empty($theme_info->stylesheets)) { // Grab stylesheets from current theme
1235
          foreach ($theme_info->stylesheets as $type => $stylesheets) {
1236
            if ($type != "print") {
1237
              foreach ($stylesheets as $name => $path) {
1238
                // Checks if less module exists...
1239
                if (strstr($path, '.less') && module_exists('less')) {
1240
                  $path = 'sites/default/files/less/' . $path; // append the less file path
1241
                  $path = str_replace('.less', '', $path); // remove the .less
1242
                }
1243
                if (file_exists($path)) {
1244
                  $css_files[$name] = $host . $path . $query_string;
1245
                  // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) )
1246
                  if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path, 0, -8) != "-rtl.css") {
1247
                    $rtl_path = substr($path, 0, -4) . "-rtl.css";
1248
                    if (file_exists($rtl_path)) {
1249
                      $css_files[$name . "-rtl"] = $host . $rtl_path . $query_string;
1250
                    }
1251
                  }
1252
                }
1253
                elseif (!empty($css_files[$name])) {
1254
                  unset($css_files[$name]);
1255
                }
1256
              }
1257
            }
1258
          }
1259
        }
1260
        // Grab stylesheets local.css and local-rtl.css if they exist (fusion based themes)
1261
        if (file_exists($themepath . 'css/local.css')) {
1262
          $css_files[] = $host . $themepath . 'css/local.css' . $query_string;
1263
        }
1264
        if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && file_exists($themepath . 'css/local-rtl.css')) {
1265
          $css_files[] = $host . $themepath . 'css/local-rtl.css' . $query_string;
1266
        }
1267

    
1268
        // Grab stylesheets from color module
1269
        $color_paths = variable_get('color_' . $current_theme . '_stylesheets', array());
1270
        if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
1271
          if (!empty($color_paths[1])) {
1272
            $css_files[] = $host . $color_paths[1] . $query_string;
1273
          }
1274
        }
1275
        elseif (!empty($color_paths[0])) {
1276
          $css_files[] = $host . $color_paths[0] . $query_string;
1277
        }
1278
      }
1279
      else {
1280
        if (!file_exists($themepath . 'ckeditor.css') && file_exists($themepath . 'style.css')) {
1281
          $css_files[] = $host . $themepath . 'style.css' . $query_string;
1282
        }
1283
      }
1284
      if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
1285
        $css_files[] = $module_drupal_path . '/css/ckeditor.css' . $query_string;
1286
      }
1287
      if (file_exists($themepath . 'ckeditor.css')) {
1288
        $css_files[] = $host . $themepath . 'ckeditor.css' . $query_string;
1289
      }
1290
      break;
1291

    
1292
    case 'self':
1293
      if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
1294
        $css_files[] = $module_drupal_path . '/css/ckeditor.css' . $query_string;
1295
        if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
1296
          if (file_exists($module_drupal_local_path . '/css/ckeditor-rtl.css')) {
1297
            $css_files[] = $module_drupal_path . '/css/ckeditor-rtl.css' . $query_string;
1298
          }
1299
        }
1300
      }
1301
      foreach (explode(',', $conf['css_path']) as $css_path) {
1302
        $css_path = trim(str_replace("%h%t", "%t", $css_path));
1303
        $css_files[] = str_replace(array('%h', '%t'), array($host, $host . $themepath), $css_path) . $query_string;
1304
      }
1305
      break;
1306

    
1307
    case 'none':
1308
      if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
1309
        $css_files[] = $module_drupal_path . '/css/ckeditor.css' . $query_string;
1310
        if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
1311
          if (file_exists($module_drupal_local_path . '/css/ckeditor-rtl.css')) {
1312
            $css_files[] = $module_drupal_path . '/css/ckeditor-rtl.css' . $query_string;
1313
          }
1314
        }
1315
      }
1316
      if ($editor_local_path != '<URL>') {
1317
        if (file_exists($editor_local_path . '/contents.css')) {
1318
          $css_files[] = $editor_path . '/contents.css' . $query_string;
1319
        }
1320
      }
1321
      else {
1322
        $editor_url_path = ckeditor_path('url');
1323
        $css_files[] = $editor_url_path . '/contents.css' . $query_string;
1324
      }
1325
      break;
1326
  }
1327

    
1328
  if (isset($conf['ckeditor_load_method']) && $conf['ckeditor_load_method'] == 'ckeditor_source.js') {
1329
    foreach ($css_files as $k => $v) {
1330
      $css_files[$k] = $v . '&t=' . time();
1331
    }
1332
  }
1333

    
1334
  $settings['contentsCss'] = array_values($css_files);
1335

    
1336
  if (!empty($conf['uicolor']) && $conf['uicolor'] == "custom" && !empty($conf['uicolor_user'])) {
1337
    $settings['uiColor'] = $conf['uicolor_user'];
1338
  }
1339

    
1340
  if (!empty($conf['uicolor']) && strpos($conf['uicolor'], "color_") === 0) {
1341
    if (function_exists('color_get_palette')) {
1342
      $palette = @color_get_palette($current_theme, FALSE); //[#652274]
1343
      $color = str_replace("color_", "", $conf['uicolor']);
1344
      if (!empty($palette[$color])) {
1345
        $settings['uiColor'] = $palette[$color];
1346
      }
1347
    }
1348
  }
1349

    
1350
  // Allow modules to modify the settings.
1351
  drupal_alter('ckeditor_settings', $settings, $conf);
1352

    
1353
  return $settings;
1354
}
1355

    
1356
/**
1357
 * Load CKEditor for field ID
1358
 *
1359
 * @param object $field
1360
 * @param string $format
1361
 *
1362
 * @return object
1363
 *
1364
 */
1365
function ckeditor_load_by_field($field, $format, $show_toggle = TRUE, $add_fields_to_toggle = FALSE) {
1366
  global $user, $theme;
1367
  static $processed_ids = array();
1368
  static $is_running = FALSE;
1369
  $use_ckeditor = FALSE;
1370
  $format_arr = FALSE;
1371
  $suffix = '';
1372

    
1373
  if (is_array($format)) {
1374
    $format_arr = $format;
1375
    $format = isset($format_arr['#value']) ? $format_arr['#value'] : $format_arr['#default_value'];
1376
  }
1377

    
1378
  if (!isset($field['#id'])) {
1379
    return $field;
1380
  }
1381

    
1382
  if (isset($processed_ids[$field['#id']])) {
1383
    return $field;
1384
  }
1385

    
1386
  if (key_exists('#wysiwyg', $field) && !$field['#wysiwyg']) {
1387
    return $field;
1388
  }
1389

    
1390
  if (isset($field['#access']) && !$field['#access']) {
1391
    return $field;
1392
  }
1393

    
1394
  if ($field['#id'] == "edit-log") {
1395
    return $field;
1396
  }
1397

    
1398
  if (isset($field['#attributes']['disabled']) && $field['#attributes']['disabled'] == 'disabled') {
1399
    return $field;
1400
  }
1401

    
1402
  drupal_add_js(array('ckeditor' => array('textarea_default_format' => array($field['#id'] => $format))), 'setting');
1403

    
1404
  if (!isset($processed_ids[$field['#id']])) {
1405
    $processed_ids[$field['#id']] = array();
1406
  }
1407

    
1408
  $global_profile = ckeditor_profile_load('CKEditor Global Profile');
1409
  $profile = ckeditor_get_profile($format);
1410
  $host = base_path();
1411

    
1412
  if ($profile === FALSE) {
1413
    $ckeditor_in_default_format = FALSE;
1414
    foreach ((array) $format_arr['#options'] as $key => $val) {
1415
      if ($key == $format)
1416
        continue;
1417
      if ($profile = ckeditor_get_profile($key)) {
1418
        $use_ckeditor = $key;
1419
        break;
1420
      }
1421
    }
1422
    if ($use_ckeditor === FALSE) {
1423
      return $field;
1424
    }
1425
  }
1426
  else {
1427
    $ckeditor_in_default_format = TRUE;
1428
  }
1429

    
1430
  $settings = FALSE;
1431
  if ($settings = ckeditor_profiles_compile($format)) {
1432
    $ckeditor_on = ($profile->settings['default'] == 't') ? TRUE : FALSE;
1433
  }
1434
  elseif ($settings = ckeditor_profiles_compile($use_ckeditor)) {
1435
    $ckeditor_on = FALSE;
1436
  }
1437
  else {
1438
    return $field;
1439
  }
1440

    
1441
  // Attach the editor css.
1442
  $field['#attached']['css'][] = drupal_get_path('module', 'ckeditor') . '/css/ckeditor.editor.css';
1443

    
1444
  if ($settings) {
1445
    $textarea_id = $field['#id'];
1446
    $class[] = 'ckeditor-mod';
1447
    $_ckeditor_ids[] = $textarea_id;
1448

    
1449
    //settings are saved as strings, not booleans
1450
    if ($settings['show_toggle'] == 't' && $show_toggle) {
1451

    
1452
      if ($add_fields_to_toggle !== FALSE) {
1453
        if (is_array($add_fields_to_toggle)) {
1454
          $toggle_fields = "['" . $textarea_id . "','" . implode("','", $add_fields_to_toggle) . "']";
1455
        }
1456
        else {
1457
          $toggle_fields = "['" . $textarea_id . "','" . $add_fields_to_toggle . "']";
1458
        }
1459
      }
1460
      else {
1461
        $toggle_fields = "['{$textarea_id}']";
1462
      }
1463

    
1464
      $wysiwyg_link = '';
1465
      $wysiwyg_link .= "<a class=\"ckeditor_links\" style=\"display:none\" href=\"javascript:void(0);\" onclick=\"javascript:Drupal.ckeditorToggle({$toggle_fields},'" . str_replace("'", "\\'", t('Switch to plain text editor')) . "','" . str_replace("'", "\\'", t('Switch to rich text editor')) . "');\" id=\"switch_{$textarea_id}\">";
1466
      $wysiwyg_link .= $ckeditor_on ? t('Switch to plain text editor') : t('Switch to rich text editor');
1467
      $wysiwyg_link .= '</a>';
1468

    
1469
      // Make sure to append to #suffix so it isn't completely overwritten
1470
      $suffix .= $wysiwyg_link;
1471
    }
1472

    
1473
    $editor_local_path = ckeditor_path('local');
1474
    $editor_url_path = ckeditor_path('url');
1475

    
1476
    if (!$is_running) {
1477
      // By default sessions are not started automatically for anonymous users.
1478
      // Start one for editing content so that we had a consistent token that is used in XSS filter.
1479
      if (isset($field['#entity']) && !empty($field['#entity']->created) && empty($user->uid)) {
1480
        drupal_session_start();
1481
        $_SESSION['ckeditor_anonymous_user'] = true;
1482
        drupal_page_is_cacheable(FALSE);
1483
      }
1484

    
1485
      if (!$ckeditor_in_default_format) {
1486
        $load_method = 'ckeditor_basic.js';
1487
        $load_time_out = 0;
1488
      }
1489
      elseif (isset($profile->settings['ckeditor_load_method'])) {
1490
        $load_method = $profile->settings['ckeditor_load_method'];
1491
        $load_time_out = $profile->settings['ckeditor_load_time_out'];
1492
      }
1493
      if ($editor_local_path != '<URL>') {
1494
        drupal_add_js('window.CKEDITOR_BASEPATH = "' . ckeditor_path('relative') . '/"', array('type' => 'inline', 'weight' => -100));
1495
      }
1496
      drupal_add_js(ckeditor_module_path('url') . '/includes/ckeditor.utils.js', array('type' => 'file', 'scope' => 'footer'));
1497

    
1498
      $preprocess = FALSE;
1499
      if (isset($global_profile->settings['ckeditor_aggregate']) && $global_profile->settings['ckeditor_aggregate'] == 't') {
1500
        $preprocess = TRUE;
1501
      }
1502

    
1503
      if ($editor_local_path == '<URL>') {
1504
        drupal_add_js($editor_url_path . '/ckeditor.js', array('type' => 'external', 'scope' => 'footer'));
1505
      }
1506
      else if (isset($load_method) && file_exists($editor_local_path . '/' . $load_method)) {
1507
        drupal_add_js($editor_url_path . '/' . $load_method, array('type' => 'file', 'scope' => 'footer', 'preprocess' => $preprocess));
1508
        if ($load_method == 'ckeditor_basic.js') {
1509
          drupal_add_js('CKEDITOR.loadFullCoreTimeout = ' . $load_time_out . ';', array('type' => 'inline', 'scope' => 'footer'));
1510
          drupal_add_js(array('ckeditor' => array('load_timeout' => TRUE)), 'setting');
1511
        }
1512
      }
1513
      else {
1514
        drupal_add_js($editor_url_path . '/ckeditor.js', array('type' => 'file', 'scope' => 'footer', 'preprocess' => $preprocess));
1515
      }
1516
      $ckeditor_url = ckeditor_path('relative');
1517
      if ($ckeditor_url == '<URL>') {
1518
        $ckeditor_url = ckeditor_path('url');
1519
      }
1520
      $ckeditor_url .= '/';
1521
      drupal_add_js(array('ckeditor' => array('module_path' => ckeditor_module_path('relative'), 'editor_path' => $ckeditor_url)), 'setting');
1522
      if (module_exists('paging')) {
1523
        drupal_add_js(array('ckeditor' => array('pagebreak' => TRUE)), 'setting');
1524
      }
1525
      if (module_exists('linktocontent_node')) {
1526
        drupal_add_js(array('ckeditor' => array('linktocontent_node' => TRUE)), 'setting');
1527
      }
1528
      if (module_exists('linktocontent_menu')) {
1529
        drupal_add_js(array('ckeditor' => array('linktocontent_menu' => TRUE)), 'setting');
1530
      }
1531
      if (module_exists('pagebreak')) {
1532
        drupal_add_js(array('ckeditor' => array('pagebreak' => TRUE)), 'setting');
1533
      }
1534
      if (module_exists('smart_paging')) {
1535
        drupal_add_js(array('ckeditor' => array('pagebreak' => TRUE)), 'setting');
1536
      }
1537
      drupal_add_js(array('ckeditor' => array('ajaxToken' => drupal_get_token('ckeditorAjaxCall'), 'xss_url' => url('ckeditor/xss'))), 'setting');
1538
      $is_running = TRUE;
1539
    }
1540

    
1541
    drupal_add_js(array('ckeditor' => array('theme' => $theme)), 'setting');
1542
    if (!empty($settings)) {
1543
      drupal_add_js(array('ckeditor' => array('elements' => array($textarea_id => $format))), 'setting');
1544
    }
1545
    if (!empty($ckeditor_on)) {
1546
      drupal_add_js(array('ckeditor' => array('autostart' => array($textarea_id => $ckeditor_on))), 'setting');
1547
    }
1548
    //[#1473010]
1549
    if (isset($settings['scayt_sLang'])) {
1550
      drupal_add_js(array('ckeditor' => array('scayt_language' => $settings['scayt_sLang'])), 'setting');
1551
    }
1552
    elseif (!empty($field["#language"]) && $field["#language"] != LANGUAGE_NONE) {
1553
      drupal_add_js(array('ckeditor' => array('scayt_language' => ckeditor_scayt_langcode($field["#language"]))), 'setting');
1554
    }
1555

    
1556
    // Remember extra information and reuse it during "Preview"
1557
    $processed_ids[$field['#id']]['suffix'] = $suffix;
1558
    $processed_ids[$field['#id']]['class'] = $class;
1559

    
1560
    if (empty($field['#suffix'])) {
1561
      $field['#suffix'] = $suffix;
1562
    }
1563
    else {
1564
      $field['#suffix'] .= $suffix;
1565
    }
1566

    
1567
    if (empty($field['#attributes']['class'])) {
1568
      $field['#attributes']['class'] = $class;
1569
    }
1570
    else {
1571
      $field['#attributes']['class'] = array_merge($field['#attributes']['class'], $class);
1572
    }
1573
  }
1574

    
1575
  return $field;
1576
}
1577

    
1578
/**
1579
 * Return all modules that provide security filters.
1580
 */
1581
function ckeditor_security_filters() {
1582
  $security_filters = array();
1583

    
1584
  $security_filters['modules'] = array(
1585
    'htmLawed' => array(
1586
      'title' => 'htmLawed',
1587
      'project_page' => 'http://drupal.org/project/htmLawed',
1588
      'weight' => 0,
1589
      'installed' => FALSE,
1590
      'filters' => array()
1591
    ),
1592
    'htmltidy' => array(
1593
      'title' => 'Htmltidy',
1594
      'project_page' => 'http://drupal.org/project/htmltidy',
1595
      'weight' => 0,
1596
      'installed' => FALSE,
1597
      'filters' => array()
1598
    ),
1599
    'htmlpurifier' => array(
1600
      'title' => 'HTML Purifier',
1601
      'project_page' => 'http://drupal.org/project/htmlpurifier',
1602
      'weight' => 0,
1603
      'installed' => FALSE,
1604
      'filters' => array()
1605
    ),
1606
    'wysiwyg_filter' => array(
1607
      'title' => 'WYSIWYG Filter',
1608
      'project_page' => 'http://drupal.org/project/wysiwyg_filter',
1609
      'weight' => 0,
1610
      'installed' => FALSE,
1611
      'filters' => array()
1612
    )
1613
  );
1614

    
1615
  $security_filters['filters'] = array();
1616

    
1617
  foreach ($security_filters['modules'] as $module_name => $module_conf) {
1618
    if (module_exists($module_name)) {
1619
      $security_filters['modules'][$module_name]['installed'] = TRUE;
1620
      $module_filters = module_invoke($module_name, 'filter_info');
1621
      foreach ($module_filters as $module_filter_name => $module_filter_conf) {
1622
        $security_filters['modules'][$module_name]['filters'][$module_filter_name] = $module_filter_conf;
1623
        $security_filters['filters'][$module_filter_name] = TRUE;
1624
      }
1625
    }
1626
  }
1627

    
1628
  //add filters from Drupal core
1629
  $security_filters['modules']['__drupal'] = array(
1630
    'title' => 'Drupal core',
1631
    'project_page' => FALSE,
1632
    'weight' => -1,
1633
    'installed' => TRUE,
1634
    'filters' => array(
1635
      'filter_html' => array(
1636
        'title' => 'Limit allowed HTML tags',
1637
        'description' => 'Removes the attributes that the built-in "Limit allowed HTML tags"-filter does not allow inside HTML elements/tags'
1638
      )
1639
    )
1640
  );
1641
  $security_filters['filters']['filter_html'] = TRUE;
1642

    
1643
  //load security filters added by API
1644
  $external_module_filters = module_invoke_all('ckeditor_security_filter');
1645
  if (count($external_module_filters) > 0) {
1646
    $security_filters['modules']['__external'] = array(
1647
      'title' => 'External filters',
1648
      'project_page' => FALSE,
1649
      'weight' => 1,
1650
      'installed' => TRUE,
1651
      'filters' => array()
1652
    );
1653
    foreach ($external_module_filters as $module_filter_name => $module_filter_conf) {
1654
      $security_filters['modules']['__external']['filters'][$module_filter_name] = $module_filter_conf;
1655
      $security_filters['filters'][$module_filter_name] = TRUE;
1656
    }
1657
  }
1658
  drupal_alter('ckeditor_security_filter', $security_filters);
1659

    
1660
  return $security_filters;
1661
}