| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * CKEditor - The text editor for the Internet - http://ckeditor.com 4 * Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved. 5 * 6 * == BEGIN LICENSE == 7 * 8 * Licensed under the terms of any of the following licenses of your 9 * choice: 10 * 11 * - GNU General Public License Version 2 or later (the "GPL") 12 * http://www.gnu.org/licenses/gpl.html 13 * 14 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 15 * http://www.gnu.org/licenses/lgpl.html 16 * 17 * - Mozilla Public License Version 1.1 or later (the "MPL") 18 * http://www.mozilla.org/MPL/MPL-1.1.html 19 * 20 * == END LICENSE == 21 * 22 * @file 23 * CKEditor Module for Drupal 6.x 24 * 25 * This module allows Drupal to replace textarea fields with CKEditor. 26 * 27 * CKEditor is an online rich text editor that can be embedded inside web pages. 28 * It is a WYSIWYG (What You See Is What You Get) editor which means that the 29 * text edited in it looks as similar as possible to the results end users will 30 * see after the document gets published. It brings to the Web popular editing 31 * features found in desktop word processors such as Microsoft Word and 32 * OpenOffice.org Writer. CKEditor is truly lightweight and does not require any 33 * kind of installation on the client computer. 34 */ 35 36 /** 37 * The name of the simplified toolbar that should be forced. 38 * Make sure that this toolbar is defined in ckeditor.config.js or fckconfig.js. 39 */ 40 define('CKEDITOR_ENTERMODE_P', 1); 41 define('CKEDITOR_ENTERMODE_BR', 2); 42 define('CKEDITOR_ENTERMODE_DIV', 3); 43 44 global $_ckeditor_configuration; 45 global $_ckeditor_ids; 46 47 $_ckeditor_configuration = array(); 48 $_ckeditor_ids = array(); 49 /** 50 * Implementation of hook_form_alter() 51 */ 52 function ckeditor_form_alter(&$form, $form_state, $form_id) { 53 // [#659278], [#666560], [#666616] 54 if (substr($form_id, -10) == '_node_form') { 55 if (!empty($form['#node']->language)) { 56 $form['body_field']['body']['#scayt_language'] = _ckeditor_scayt_langcode($form['#node']->language); 57 } 58 if (!empty($form['body_field']['teaser_js']['#teaser'])) { 59 $setting['ckeditor']['teaser'] = $form['body_field']['teaser_js']['#teaser']; 60 drupal_add_js($setting, 'setting'); 61 } 62 } 63 } 64 65 /** 66 * Implementation of hook_help(). 67 * 68 * This function delegates the execution to ckeditor_help_delegate() in includes/ckeditor.page.inc to 69 * lower the amount of code in ckeditor.module. 70 */ 71 function ckeditor_help($path, $arg) { 72 module_load_include('inc', 'ckeditor', 'includes/ckeditor.page'); 73 return module_invoke('ckeditor', 'help_delegate', $path, $arg); 74 } 75 76 /** 77 * Implementation of hook_user(). 78 * 79 * This function delegates the execution to ckeditor_user_delegate() in includes/ckeditor.user.inc to 80 * lower the amount of code in ckeditor.module. 81 */ 82 function ckeditor_user($type, $edit, &$user, $category = NULL) { 83 if (($type == 'form' && $category == 'account' && user_access('access ckeditor')) || $type == 'validate') { 84 module_load_include('inc', 'ckeditor', 'includes/ckeditor.user'); 85 return ckeditor_user_delegate($type, $edit, $user, $category); 86 } 87 return NULL; 88 } 89 90 /** 91 * Implementation of hook_perm(). 92 * Administer -> User management -> Permissions 93 */ 94 function ckeditor_perm() { 95 $arr = array('administer ckeditor', 'access ckeditor'); 96 $ckfinder_full_path = ckfinder_path(); 97 $config_path = $ckfinder_full_path . '/config.php'; 98 if (file_exists($config_path)) { 99 $arr[] = 'allow CKFinder file uploads'; 100 } 101 return $arr; 102 } 103 104 /** 105 * Implementation of hook_elements(). 106 * Replace the textarea with CKEditor using a callback function (ckeditor_process_textarea) 107 */ 108 function ckeditor_elements() { 109 $type = array(); 110 $type['textfield'] = array( 111 '#process' => array( 112 'ckeditor_process_input' 113 ), 114 ); 115 // only roles with permission get CKEditor 116 if (user_access('access ckeditor')) { 117 $type['textarea'] = array('#process' => array('ckeditor_process_textarea')); 118 $type['form'] = array('#after_build' => array('ckeditor_process_form')); 119 $type['hidden'] = array('#process' => array('ckeditor_process_hidden')); 120 } 121 return $type; 122 } 123 124 function ckeditor_process_hidden($element, $edit, $form_state, $complete_form) { 125 if (!empty($element['#value']) && in_array($element['#value'], array('panels_edit_display_form', 'panels_panel_context_edit_content'))) { 126 $fake_element = array('#id' => 'edit-body'); 127 ckeditor_process_textarea($fake_element); 128 } 129 return $element; 130 } 131 132 function ckeditor_process_form(&$form) { 133 global $_ckeditor_configuration, $_ckeditor_ids; 134 static $processed_textareas = array(); 135 static $found_textareas = array(); 136 137 //Skip if: 138 // - we're not editing an element 139 // - ckeditor is not enabled (configuration is empty) 140 if (arg(1) == "add" || arg(1) == "reply" || !count($_ckeditor_configuration)) { 141 return $form; 142 } 143 144 $ckeditor_filters = array(); 145 146 // Iterate over element children; resetting array keys to access last index. 147 if ($children = array_values(element_children($form))) { 148 foreach ($children as $index => $item) { 149 $element = &$form[$item]; 150 151 if (isset($element['#id']) && in_array($element['#id'], $_ckeditor_ids)) { 152 $found_textareas[$element['#id']] = &$element; 153 } 154 155 // filter_form() always uses the key 'format'. We need a type-agnostic 156 // match to prevent FALSE positives. Also, there must have been at least 157 // one element on this level. 158 if ($item === 'format' && $index > 0) { 159 160 // Make sure we either match a input format selector or input format 161 // guidelines (displayed if user has access to one input format only). 162 if ((isset($element['#type']) && $element['#type'] == 'fieldset') || isset($element['format']['guidelines'])) { 163 // The element before this element is the target form field. 164 $field = &$form[$children[$index - 1]]; 165 $textarea_id = $field['#id']; 166 167 array_push($processed_textareas, $textarea_id); 168 169 //search for checkxss1/2 class 170 if (empty($field['#attributes']['class']) || strpos($field['#attributes']['class'], "checkxss") === FALSE) { 171 continue; 172 } 173 174 // Determine the available input formats. The last child element is a 175 // link to "More information about formatting options". When only one 176 // input format is displayed, we also have to remove formatting 177 // guidelines, stored in the child 'format'. 178 $formats = element_children($element); 179 180 foreach ($formats as $format_id) { 181 $format = !empty($element[$format_id]['#default_value']) ? $element[$format_id]['#default_value'] : $element[$format_id]['#value']; 182 break; 183 } 184 185 $enabled = filter_list_format($format); 186 $ckeditor_filters = array(); 187 188 //loop through all enabled filters 189 foreach ($enabled as $id => $filter) { 190 //but use only that one selected in CKEditor profile 191 if (in_array($id, array_keys($_ckeditor_configuration[$textarea_id]['filters'])) && $_ckeditor_configuration[$textarea_id]['filters'][$id]) { 192 if (!isset($ckeditor_filters[$textarea_id])) { 193 $ckeditor_filters[$textarea_id] = array(); 194 } 195 $ckeditor_filters[$textarea_id][] = $id ."/". $format; 196 } 197 } 198 199 drupal_add_js(array('ckeditor' => array('settings' => array($textarea_id => array('input_format' => $format)))), 'setting'); 200 201 //No filters assigned, remove xss class 202 if (empty($ckeditor_filters[$textarea_id])) { 203 $field['#attributes']['class'] = preg_replace("/checkxss(1|2)/", "", $field['#attributes']['class']); 204 } 205 else { 206 $field['#attributes']['class'] = strtr($field['#attributes']['class'], array("checkxss1" => "filterxss1", "checkxss2" => "filterxss2")); 207 } 208 209 array_pop($formats); 210 unset($formats['format']); 211 } 212 // If this element is 'format', do not recurse further. 213 continue; 214 } 215 // Recurse into children. 216 ckeditor_process_form($element); 217 } 218 } 219 220 //We're in a form 221 if (isset($form['#action'])) { 222 //some textareas associated with CKEditor has not been processed 223 if (count($processed_textareas) < count($_ckeditor_ids)) { 224 //loop through all found textfields 225 foreach (array_keys($found_textareas) as $id) { 226 $element = &$found_textareas[$id]; 227 //if not processed yet (checkxss class is before final processing) 228 if (strpos($element['#attributes']['class'], "checkxss") !== FALSE && !in_array($element['#id'], $processed_textareas) && !empty($_ckeditor_configuration[$id]['filters']) && array_sum($_ckeditor_configuration[$id]['filters'])) { 229 //assign default Filtered HTML to be safe on fields that do not have input format assigned, but only if at least one security filter is enabled in Security settings 230 $ckeditor_filters[$element['#id']][] = "filter/0/1"; 231 $element['#attributes']['class'] = strtr($element['#attributes']['class'], array("checkxss1" => "filterxss1", "checkxss2" => "filterxss2")); 232 } 233 } 234 } 235 } 236 237 if (!empty($ckeditor_filters)) { 238 foreach ($ckeditor_filters as $id => $filters) { 239 $arr['settings'][$id]['filters'] = $filters; 240 } 241 drupal_add_js(array('ckeditor' => $arr), 'setting'); 242 } 243 return $form; 244 } 245 246 /** 247 * Allow more than 255 chars in Allowed HTML tags textfield 248 */ 249 function ckeditor_process_input($element) { 250 if ($element['#id']=='edit-allowed-html-1') { 251 $element['#maxlength'] = max($element['#maxlength'], 1024); 252 } 253 return $element; 254 } 255 256 /** 257 * Implementation of hook_menu(). 258 */ 259 function ckeditor_menu() { 260 $items = array(); 261 262 $items['ckeditor/xss'] = array( 263 'title' => 'XSS Filter', 264 'description' => 'XSS Filter.', 265 'page callback' => 'ckeditor_filter_xss', 266 'file' => 'includes/ckeditor.page.inc', 267 'access arguments' => array('access ckeditor'), 268 'type' => MENU_CALLBACK, 269 ); 270 271 $items['ckeditor/disable/wysiwyg/%'] = array( 272 'title' => 'Disable WYSIWYG module', 273 'description' => 'Disable the WYSIWYG module.', 274 'page callback' => 'ckeditor_disable_wysiwyg', 275 'page arguments' => array(3), 276 'file' => 'includes/ckeditor.admin.inc', 277 'access arguments' => array('administer ckeditor'), 278 'type' => MENU_CALLBACK, 279 ); 280 281 $items['admin/settings/ckeditor'] = array( 282 'title' => 'CKEditor', 283 'description' => 'Configure the rich text editor.', 284 'page callback' => 'ckeditor_admin_main', 285 'file' => 'includes/ckeditor.admin.inc', 286 'access arguments' => array('administer ckeditor'), 287 'type' => MENU_NORMAL_ITEM, 288 ); 289 290 $items['admin/settings/ckeditor/add'] = array( 291 'title' => 'Add a new CKEditor profile', 292 'description' => 'Configure the rich text editor.', 293 'page callback' => 'drupal_get_form', 294 'page arguments' => array('ckeditor_admin_profile_form'), 295 'file' => 'includes/ckeditor.admin.inc', 296 'access arguments' => array('administer ckeditor'), 297 'type' => MENU_CALLBACK, 298 ); 299 300 $items['admin/settings/ckeditor/clone/%ckeditor_profile'] = array( 301 'title' => 'Clone the CKEditor profile', 302 'description' => 'Configure the rich text editor.', 303 'page callback' => 'drupal_get_form', 304 'page arguments' => array('ckeditor_admin_profile_clone_form', 4), 305 'file' => 'includes/ckeditor.admin.inc', 306 'access arguments' => array('administer ckeditor'), 307 'type' => MENU_CALLBACK, 308 ); 309 310 $items['admin/settings/ckeditor/edit/%ckeditor_profile'] = array( 311 'title' => 'Edit the CKEditor profile', 312 'description' => 'Configure the rich text editor.', 313 'page callback' => 'drupal_get_form', 314 'page arguments' => array('ckeditor_admin_profile_form', 4), 315 'file' => 'includes/ckeditor.admin.inc', 316 'access arguments' => array('administer ckeditor'), 317 'type' => MENU_CALLBACK, 318 ); 319 320 $items['admin/settings/ckeditor/delete/%ckeditor_profile'] = array( 321 'title' => 'Delete the CKEditor profile', 322 'description' => 'Configure the rich text editor.', 323 'page callback' => 'drupal_get_form', 324 'page arguments' => array('ckeditor_admin_profile_delete_form', 4), 325 'file' => 'includes/ckeditor.admin.inc', 326 'access arguments' => array('administer ckeditor'), 327 'type' => MENU_CALLBACK, 328 ); 329 330 $items['admin/settings/ckeditor/addg'] = array( 331 'title' => 'Add the CKEditor Global profile', 332 'description' => 'Configure the rich text editor.', 333 'page callback' => 'drupal_get_form', 334 'page arguments' => array('ckeditor_admin_global_profile_form', 'add'), 335 'file' => 'includes/ckeditor.admin.inc', 336 'access arguments' => array('administer ckeditor'), 337 'type' => MENU_CALLBACK, 338 ); 339 340 $items['admin/settings/ckeditor/editg'] = array( 341 'title' => 'Edit the CKEditor Global profile', 342 'description' => 'Configure the rich text editor.', 343 'page callback' => 'drupal_get_form', 344 'page arguments' => array('ckeditor_admin_global_profile_form', 'edit'), 345 'file' => 'includes/ckeditor.admin.inc', 346 'access arguments' => array('administer ckeditor'), 347 'type' => MENU_CALLBACK, 348 ); 349 350 $items['admin/ckeditor/get_settings'] = array( 351 'title' => 'Get settings for the CKEditor instance', 352 'description' => 'Get settings for the CKEditor instance', 353 'page callback' => 'ckeditor_get_settings', 354 'access arguments' => array('access ckeditor'), 355 'type' => MENU_CALLBACK, 356 ); 357 358 return $items; 359 } 360 361 /** 362 * Implementation of hook_init(). 363 */ 364 function ckeditor_init() { 365 drupal_add_css(drupal_get_path('module', 'ckeditor') .'/ckeditor.css'); 366 367 // Added for support [#1288664] Views 368 if (module_exists('views') && preg_match('/admin\/build\/views/', $_GET['q'])) { 369 $module_drupal_path = drupal_get_path('module', 'ckeditor'); 370 $editor_local_path = ckeditor_path(TRUE); 371 drupal_add_js($editor_local_path . '/ckeditor.js', 'module', 'footer', FALSE, TRUE, FALSE); 372 drupal_add_js($module_drupal_path .'/includes/ckeditor.utils.js', 'module', 'footer' ); 373 drupal_add_js(array('ckeditor' => array('ajaxToken' => drupal_get_token('ckeditorAjaxCall'), 'default_input_format' => variable_get('filter_default_format', 1), 'settings' => array('edit-footer', 'edit-header'))), 'setting'); 374 } 375 } 376 377 /** 378 * Implementation of hook_file_download(). 379 * Support for private downloads. 380 * CKEditor does not implement any kind of potection on private files. 381 */ 382 function ckeditor_file_download($file) { 383 if ($path = file_create_path($file)) { 384 $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $path); 385 if (db_fetch_object($result)) { 386 return NULL; 387 } 388 389 //No info in DB? Probably a file uploaded with FCKeditor / CKFinder 390 $global_profile = ckeditor_profile_load("CKEditor Global Profile"); 391 392 //Assume that files inside of ckeditor directory belong to the CKEditor. If private directory is set, let the decision about protection to the user. 393 $private_dir = isset($global_profile->settings['private_dir']) ? trim($global_profile->settings['private_dir'], '\/') : ''; 394 $private_dir = preg_quote($private_dir, '#'); 395 $private_dir = strtr($private_dir, array('%u' => '(\d+)', '%n' => '([\x80-\xF7 \w@.-]+)')); // regex for %n taken from user_validate_name() in user.module 396 $private_dir = trim($private_dir, '\/'); 397 $regex = '#^'. preg_quote(file_directory_path() .'/', '#') . $private_dir .'#'; 398 //check if CKEditor's "Enable access to files located in the private folder" option is disabled or enabled 399 $allow_download_private_files = FALSE; 400 if (isset($global_profile->settings['ckeditor_allow_download_private_files']) && $global_profile->settings['ckeditor_allow_download_private_files'] === 't') { 401 $allow_download_private_files = TRUE; 402 } 403 //denied access to file if private upload is set and CKEditor's "Enable access to files located in the private folder" option is disabled 404 if ($allow_download_private_files == FALSE ) return NULL; 405 //check if file can be served by comparing regex and path to file 406 if (preg_match($regex, $path)) { 407 $ctype = ($info = @getimagesize($path)) ? $info['mime'] : (function_exists('mime_content_type') ? mime_content_type($path) : 'application/x-download'); 408 return array('Content-Type: '. $ctype); 409 } 410 } 411 } 412 413 /** 414 * Load all profiles. Just load one profile if $name is passed in. 415 */ 416 function ckeditor_profile_load($name = '', $clear = FALSE) { 417 static $profiles = array(); 418 419 if (empty($profiles) || $clear === TRUE) { 420 $result = db_query("SELECT * FROM {ckeditor_settings} ORDER BY name"); 421 while (($data = db_fetch_object($result))) { 422 $data->settings = unserialize($data->settings); 423 $data->rids = array(); 424 425 $profiles[$data->name] = $data; 426 } 427 428 $roles = user_roles(); 429 $result = db_query("SELECT name, rid FROM {ckeditor_role}"); 430 while (($data = db_fetch_object($result))) { 431 $profiles[$data->name]->rids[$data->rid] = $roles[$data->rid]; 432 } 433 } 434 435 return ($name ? (isset($profiles[urldecode($name)]) ? $profiles[urldecode($name)] : FALSE) : $profiles); 436 } 437 438 /** 439 * This function creates the HTML objects required for CKEditor. 440 * 441 * @param $element 442 * A fully populated form elment to add the editor to. 443 * @return 444 * The same $element with extra CKEditor markup and initialization. 445 */ 446 function ckeditor_process_textarea($element) { 447 static $is_running = FALSE; 448 static $num = 1; 449 static $processed_ids=array(); 450 global $user, $theme, $language, $_ckeditor_configuration, $_ckeditor_ids; 451 $settings = array(); 452 $enabled = TRUE; 453 $suffix = ""; 454 $class = ""; 455 //hack for module developers that want to disable ckeditor on their textareas 456 if (key_exists('#wysiwyg', $element) && !$element['#wysiwyg']) { 457 return $element; 458 } 459 460 if (isset($element['#access']) && !$element['#access']) { 461 return $element; 462 } 463 //skip this one, surely nobody wants WYSIWYG here 464 switch ($element['#id']) { 465 case 'edit-log': 466 return $element; 467 break; 468 } 469 470 if (isset($element['#attributes']['disabled']) && $element['#attributes']['disabled'] == 'disabled') { 471 return $element; 472 } 473 474 if (isset($processed_ids[$element['#id']])) { 475 //statement for node preview purpose, when second textarea element with the same id is processing to add class which ckeditor behavior must process 476 if (empty($element['#attributes']['class'])) { 477 $element['#attributes']['class'] = $processed_ids[$element['#id']]['class']; 478 } 479 else { 480 $element['#attributes']['class'] .= " ". $processed_ids[$element['#id']]['class']; 481 } 482 if (empty($element['#suffix'])) { 483 $element['#suffix'] = $processed_ids[$element['#id']]['suffix']; 484 } 485 else { 486 $element['#suffix'] .= $processed_ids[$element['#id']]['suffix']; 487 } 488 return $element; 489 } 490 else { 491 $processed_ids[$element['#id']] = array(); 492 } 493 494 module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib'); 495 496 $global_profile = ckeditor_profile_load('CKEditor Global Profile'); 497 if ($global_profile) { 498 $global_conf = $global_profile->settings; 499 if ($global_conf) { 500 $enabled = ckeditor_is_enabled(empty($global_conf['excl_mode']) ? '0' : $global_conf['excl_mode'], empty($global_conf['excl_regex']) ? '' : $global_conf['excl_regex'], $element['#id'], $_GET['q']); 501 } 502 } 503 if ($enabled) { 504 $profile = ckeditor_user_get_profile($user, $element['#id']); 505 if ($profile) { 506 $conf = array(); 507 $conf = $profile->settings; 508 509 if ($conf['allow_user_conf']=='t') { 510 foreach (array('default', 'show_toggle', 'popup', 'skin', 'expand', 'width', 'lang', 'auto_lang') as $setting) { 511 $conf[$setting] = ckeditor_user_get_setting($user, $profile, $setting); 512 } 513 } 514 if ($conf['popup'] == 't' && $conf['show_toggle'] == 't') { 515 $conf['show_toggle'] = 'f'; 516 } 517 } 518 else { 519 $enabled = FALSE; 520 } 521 } 522 523 //old profile info, assume Filtered HTML is enabled 524 if (!isset($conf['ss'])) { 525 $conf['ss'] = 2; 526 $conf['filters']['filter/0'] = 1; 527 } 528 if (!isset($conf['filters'])) { 529 $conf['filters'] = array(); 530 } 531 532 $themepath = path_to_theme() .'/'; 533 $host = base_path(); 534 if (!isset($element['#rows'])) { 535 $element['#rows'] = 5; 536 } 537 // only replace textarea when it has enough rows and it is enabled 538 if ($enabled && (($element['#rows'] > $conf['min_rows']) || ($conf['min_rows'] <= 1 && empty($element['#rows'])))) { 539 $textarea_id = $element['#id']; 540 $class = 'ckeditor-mod'; 541 $_ckeditor_ids[] = $textarea_id; 542 $ckeditor_on = ($conf['default']=='t') ? 1 : 0 ; 543 $xss_check = 0; 544 //it's not a problem when adding new content/comment 545 if (arg(1) != "add" && arg(1) != "reply") { 546 $_ckeditor_configuration[$element['#id']] = $conf; 547 548 //let ckeditor know when perform XSS checks auto/manual 549 if ($conf['ss'] == 1) { 550 $xss_class = 'checkxss1'; 551 } 552 else { 553 $xss_class = 'checkxss2'; 554 } 555 556 $class .= ' '. $xss_class; 557 $xss_check = 1; 558 } 559 560 //settings are saved as strings, not booleans 561 if ($conf['show_toggle'] == 't') { 562 $content = ''; 563 if (isset($element['#post']['teaser_js'])) { 564 $content .= $element['#post']['teaser_js'] .'<!--break-->'; 565 } 566 if (isset($element['#value'])) { 567 $content .= $element['#value']; 568 } 569 $wysiwyg_link = ''; 570 $wysiwyg_link .= "<a class=\"ckeditor_links\" style=\"display:none\" href=\"javascript:void(0);\" onclick=\"javascript:Drupal.ckeditorToggle('{$textarea_id}','". str_replace("'", "\\'", t('Switch to plain text editor')) ."','". str_replace("'", "\\'", t('Switch to rich text editor')) ."',". $xss_check .");\" id=\"switch_{$textarea_id}\">"; 571 $wysiwyg_link .= $ckeditor_on ? t('Switch to plain text editor') : t('Switch to rich text editor'); 572 $wysiwyg_link .= '</a>'; 573 574 // Make sure to append to #suffix so it isn't completely overwritten 575 $suffix .= $wysiwyg_link; 576 } 577 // setting some variables 578 $module_drupal_path = drupal_get_path('module', 'ckeditor'); 579 $module_full_path = $host . $module_drupal_path; 580 $editor_path = ckeditor_path(FALSE); 581 $lib_path = dirname($editor_path); 582 $editor_local_path = ckeditor_path(TRUE); 583 $lib_local_path = dirname($editor_local_path); 584 // get the default drupal files path 585 $files_path = $host . file_directory_path(); 586 587 drupal_set_html_head('<script type="text/javascript">window.CKEDITOR_BASEPATH = "' . $editor_path . '/";</script>'); 588 589 // sensible default for small toolbars 590 if (isset($element['#rows'])) { 591 $height = intval($element['#rows']) * 14 + 140; 592 } 593 else { 594 $height = 400; 595 } 596 if (!$is_running) { 597 drupal_add_js($module_drupal_path .'/includes/ckeditor.utils.js', 'module', variable_get('preprocess_js', FALSE) ? 'header' : 'footer'); 598 /* In D6 drupal_add_js() can't add external JS, in D7 use drupal_add_js(...,'external') */ 599 if ( $conf['popup'] != 't' ) { 600 if (isset($conf['ckeditor_load_method'])) { 601 drupal_add_js($editor_local_path . '/' . $conf['ckeditor_load_method'], 'module', 'header', FALSE, TRUE, FALSE); 602 if ($conf['ckeditor_load_method'] == 'ckeditor_basic.js') { 603 drupal_add_js('CKEDITOR.loadFullCoreTimeout = ' . $conf['ckeditor_load_time_out'] . ';', 'inline'); 604 drupal_add_js(array('ckeditor' => array('load_timeout' => TRUE)), 'setting'); 605 } 606 } 607 else { 608 drupal_add_js($editor_local_path . '/ckeditor.js?I', 'module', 'header', FALSE, TRUE, FALSE); 609 } 610 } 611 else { 612 drupal_add_js($editor_local_path . '/ckeditor_basic.js?I', 'module', 'header', FALSE, TRUE, FALSE); 613 } 614 drupal_add_js(array('ckeditor' => array('module_path' => $module_full_path, 'editor_path' => $editor_path)), 'setting'); 615 drupal_add_js(array('ckeditor' => array('ajaxToken' => drupal_get_token('ckeditorAjaxCall'))), 'setting'); 616 drupal_add_js(array('ckeditor' => array('query' => $_GET['q'])), 'setting'); 617 drupal_add_js(array('ckeditor' => array('default_input_format' => variable_get('filter_default_format', 1))), 'setting'); 618 $is_running = TRUE; 619 } 620 621 $toolbar = $conf['toolbar']; 622 //$height += 100; // for larger toolbars 623 624 $force_simple_toolbar = ckeditor_is_enabled('1', empty($conf['simple_incl_regex']) ? '' : $conf['simple_incl_regex'], $element['#id'], $_GET['q']); 625 if (!$force_simple_toolbar) { 626 $force_simple_toolbar = ckeditor_is_enabled('1', empty($global_conf['simple_incl_regex']) ? '' : $global_conf['simple_incl_regex'], $element['#id'], $_GET['q']); 627 } 628 if ($force_simple_toolbar) { 629 if (!isset($global_conf['simple_toolbar'])) { 630 $toolbar = "[ [ 'Format', 'Bold', 'Italic', '-', 'NumberedList','BulletedList', '-', 'Link', 'Unlink', 'Image' ] ]"; 631 } 632 else { 633 $toolbar = $global_conf['simple_toolbar']; 634 } 635 } 636 637 if (!empty($conf['theme_config_js']) && $conf['theme_config_js'] == 't' && file_exists($themepath .'ckeditor.config.js')) { 638 $ckeditor_config_path = $host . $themepath .'ckeditor.config.js?'. @filemtime($themepath .'ckeditor.config.js'); 639 } 640 else { 641 $ckeditor_config_path = $module_full_path ."/ckeditor.config.js?". @filemtime($module_drupal_path ."/ckeditor.config.js"); 642 } 643 644 $settings[$textarea_id]['customConfig'] = $ckeditor_config_path; 645 $settings[$textarea_id]['defaultLanguage'] = $conf['lang']; 646 $settings[$textarea_id]['toolbar'] = $toolbar; 647 $settings[$textarea_id]['enterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['enter_mode'])); 648 $settings[$textarea_id]['shiftEnterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['shift_enter_mode'])); 649 $settings[$textarea_id]['toolbarStartupExpanded'] = ( $conf['expand']=='t' ); 650 $settings[$textarea_id]['customConfig'] = $ckeditor_config_path; 651 $settings[$textarea_id]['width'] = $conf['width']; 652 $settings[$textarea_id]['height'] = $height; 653 $settings[$textarea_id]['skin'] = $conf['skin']; 654 $settings[$textarea_id]['format_tags'] = $conf['font_format']; 655 if (isset($conf['language_direction'])) { 656 switch ($conf['language_direction']) { 657 case 'default': 658 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) { 659 $settings[$textarea_id]['contentsLangDirection'] = 'rtl'; 660 } 661 break; 662 case 'ltr': 663 $settings[$textarea_id]['contentsLangDirection'] = 'ltr'; 664 break; 665 case 'rtl': 666 $settings[$textarea_id]['contentsLangDirection'] = 'rtl'; 667 break; 668 } 669 } 670 if (isset($conf['loadPlugins'])) { 671 $settings[$textarea_id]['loadPlugins'] = ckeditor_plugins_render($conf['loadPlugins']); 672 } 673 if (isset($conf['html_entities']) && $conf['html_entities'] == 'f') { 674 $settings[$textarea_id]['entities'] = FALSE; 675 $settings[$textarea_id]['entities_greek'] = FALSE; 676 $settings[$textarea_id]['entities_latin'] = FALSE; 677 } 678 if (isset($conf['scayt_autoStartup']) && $conf['scayt_autoStartup'] == 't') { 679 $settings[$textarea_id]['scayt_autoStartup'] = TRUE; 680 } 681 else { 682 $settings[$textarea_id]['scayt_autoStartup'] = FALSE; 683 } 684 if ($conf['auto_lang']=="f") { 685 $settings[$textarea_id]['language'] = $conf['lang']; 686 } 687 if (isset($element['#scayt_language'])) { 688 $settings[$textarea_id]['scayt_sLang'] = $element['#scayt_language']; 689 } 690 if (isset($conf['forcePasteAsPlainText']) && $conf['forcePasteAsPlainText'] == 't') { 691 $settings[$textarea_id]['forcePasteAsPlainText'] = TRUE; 692 } 693 if (isset($conf['custom_formatting']) && $conf['custom_formatting'] == 't') { 694 foreach ($conf['formatting']['custom_formatting_options'] as $k => $v) { 695 if ($v === 0) { 696 $conf['formatting']['custom_formatting_options'][$k] = FALSE; 697 } 698 else { 699 $conf['formatting']['custom_formatting_options'][$k] = TRUE; 700 } 701 } 702 $settings[$textarea_id]['output_pre_indent'] = $conf['formatting']['custom_formatting_options']['pre_indent']; 703 unset($conf['formatting']['custom_formatting_options']['pre_indent']); 704 $settings[$textarea_id]['custom_formatting'] = $conf['formatting']['custom_formatting_options']; 705 } 706 // add code for filebrowser for users that have access 707 $filebrowser = !empty($conf['filebrowser']) ? $conf['filebrowser'] : 'none'; 708 $filebrowser_image = !empty($conf['filebrowser_image']) ? $conf['filebrowser_image'] : $filebrowser; 709 $filebrowser_flash = !empty($conf['filebrowser_flash']) ? $conf['filebrowser_flash'] : $filebrowser; 710 711 if ($filebrowser == 'imce' && !module_exists('imce')) { 712 $filebrowser = 'none'; 713 } 714 715 if ($filebrowser == 'tinybrowser' && !module_exists('tinybrowser')) { 716 $filebrowser = 'none'; 717 } 718 719 if ($filebrowser == 'ib' && !module_exists('imagebrowser')) { 720 $filebrowser = 'none'; 721 } 722 if ($filebrowser == 'webfm' && !module_exists('webfm_popup')) { 723 $filebrowser = 'none'; 724 } 725 726 if ($filebrowser == 'elfinder' && !module_exists('elfinder')) { 727 $filebrowser = 'none'; 728 } 729 730 if ($filebrowser_image != $filebrowser) { 731 if ($filebrowser_image == 'imce' && !module_exists('imce')) { 732 $filebrowser_image = $filebrowser; 733 } 734 if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) { 735 $filebrowser_image = $filebrowser; 736 } 737 if ($filebrowser_image == 'ib' && !module_exists('imagebrowser')) { 738 $filebrowser_image = $filebrowser; 739 } 740 if ($filebrowser_image == 'webfm' && !module_exists('webfm_popup')) { 741 $filebrowser_image = $filebrowser; 742 } 743 if ($filebrowser_image == 'elfinder' && !module_exists('elfinder')) { 744 $filebrowser_image = $filebrowser; 745 } 746 } 747 748 if ($filebrowser_flash != $filebrowser) { 749 if ($filebrowser_flash == 'imce' && !module_exists('imce')) { 750 $filebrowser_flash = $filebrowser; 751 } 752 if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) { 753 $filebrowser_flash = $filebrowser; 754 } 755 if ($filebrowser_flash == 'ib' && !module_exists('imagebrowser')) { 756 $filebrowser_flash = $filebrowser; 757 } 758 if ($filebrowser_flash == 'webfm' && !module_exists('webfm_popup')) { 759 $filebrowser_flash = $filebrowser; 760 } 761 if ($filebrowser_flash == 'elfinder' && !module_exists('elfinder')) { 762 $filebrowser_flash = $filebrowser; 763 } 764 } 765 766 if ($filebrowser == 'ckfinder' || $filebrowser_image == 'ckfinder' || $filebrowser_flash == 'ckfinder') { 767 if (user_access('allow CKFinder file uploads')) { 768 if (!empty($profile->settings['UserFilesPath'])) { 769 $_SESSION['ckeditor']['UserFilesPath'] = strtr($profile->settings['UserFilesPath'], array("%f" => file_directory_path(), "%u" => $user->uid, "%b" => $host, "%n" => $user->name)); 770 } 771 else{ 772 $_SESSION['ckeditor']['UserFilesPath'] = strtr('%b%f/', array("%f" => file_directory_path(), "%u" => $user->uid, "%b" => $host, "%n" => $user->name)); 773 } 774 if (!empty($profile->settings['UserFilesAbsolutePath'])) { 775 $_SESSION['ckeditor']['UserFilesAbsolutePath'] = strtr($profile->settings['UserFilesAbsolutePath'], array("%f" => file_directory_path(), "%u" => $user->uid, "%b" => base_path(), "%d" => $_SERVER['DOCUMENT_ROOT'], "%n" => $user->name)); 776 } 777 else{ 778 $_SESSION['ckeditor']['UserFilesAbsolutePath'] = strtr('%d%b%f/', array("%f" => file_directory_path(), "%u" => $user->uid, "%b" => base_path(), "%d" => $_SERVER['DOCUMENT_ROOT'], "%n" => $user->name)); 779 } 780 if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE) { 781 $private_dir = isset($global_profile->settings['private_dir']) ? trim($global_profile->settings['private_dir'], '\/') : ''; 782 if (!empty($private_dir)) { 783 $private_dir = strtr($private_dir, array('%u' => $user->uid, '%n' => $user->name)); 784 $_SESSION['ckeditor']['UserFilesPath'] = url('system/files') .'/'. $private_dir .'/'; 785 $_SESSION['ckeditor']['UserFilesAbsolutePath'] = realpath(file_directory_path()) . DIRECTORY_SEPARATOR . $private_dir . DIRECTORY_SEPARATOR; 786 } 787 else { 788 $_SESSION['ckeditor']['UserFilesPath'] = url('system/files') .'/'; 789 $_SESSION['ckeditor']['UserFilesAbsolutePath'] = realpath(file_directory_path()) . DIRECTORY_SEPARATOR; 790 } 791 } 792 } 793 } 794 795 if (in_array('tinybrowser', array($filebrowser, $filebrowser_image, $filebrowser_flash))) { 796 $popup_win_size = variable_get('tinybrowser_popup_window_size', '770x480'); 797 if (!preg_match('#\d+x\d+#is', $popup_win_size)) { 798 $popup_win_size = '770x480'; 799 } 800 $popup_win_size = trim($popup_win_size); 801 $popup_win_size = strtolower($popup_win_size); 802 $win_size = split('x', $popup_win_size); 803 } 804 805 switch ($filebrowser) { 806 case 'ckfinder': 807 if (user_access('allow CKFinder file uploads')) { 808 $ckfinder_full_path = base_path() . ckfinder_path(); 809 $settings[$textarea_id]['filebrowserBrowseUrl'] = $ckfinder_full_path .'/ckfinder.html'; 810 $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $ckfinder_full_path .'/ckfinder.html?Type=Images'; 811 $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $ckfinder_full_path .'/ckfinder.html?Type=Flash'; 812 $settings[$textarea_id]['filebrowserUploadUrl'] = $ckfinder_full_path .'/core/connector/php/connector.php?command=QuickUpload&type=Files'; 813 $settings[$textarea_id]['filebrowserImageUploadUrl'] = $ckfinder_full_path .'/core/connector/php/connector.php?command=QuickUpload&type=Images'; 814 $settings[$textarea_id]['filebrowserFlashUploadUrl'] = $ckfinder_full_path .'/core/connector/php/connector.php?command=QuickUpload&type=Flash'; 815 } 816 break; 817 case 'imce': 818 $settings[$textarea_id]['filebrowserBrowseUrl'] = $host ."index.php?q=imce&app=ckeditor|sendto@ckeditor_fileUrl|"; 819 break; 820 case 'webfm': 821 if (user_access('access webfm')) { 822 $settings[$textarea_id]['filebrowserBrowseUrl'] = $host ."index.php?q=webfm_popup&caller=ckeditor"; 823 } 824 break; 825 case 'ib': 826 if (user_access('browse own images')) { 827 $settings[$textarea_id]['filebrowserBrowseUrl'] = $host ."index.php?q=imagebrowser/view/browser&app=ckeditor"; 828 $settings[$textarea_id]['filebrowserWindowWidth'] = 700; 829 $settings[$textarea_id]['filebrowserWindowHeight'] = 520; 830 } 831 break; 832 case 'tinybrowser': 833 $settings[$textarea_id]['filebrowserBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=file"; 834 $settings[$textarea_id]['filebrowserWindowWidth'] = (int)$win_size[0] + 15; 835 $settings[$textarea_id]['filebrowserWindowHeight'] = (int)$win_size[1] + 15; 836 break; 837 case 'elfinder': 838 $settings[$textarea_id]['filebrowserBrowseUrl'] = $host ."index.php?q=elfinder&app=ckeditor"; 839 break; 840 } 841 842 if ($filebrowser_image != $filebrowser) { 843 switch ($filebrowser_image) { 844 case 'ckfinder': 845 if (user_access('allow CKFinder file uploads')) { 846 $ckfinder_full_path = base_path() . ckfinder_path(); 847 $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $ckfinder_full_path .'/ckfinder.html?Type=Images'; 848 $settings[$textarea_id]['filebrowserImageUploadUrl'] = $ckfinder_full_path .'/core/connector/php/connector.php?command=QuickUpload&type=Images'; 849 } 850 break; 851 case 'imce': 852 $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $host ."index.php?q=imce&app=ckeditor|sendto@ckeditor_fileUrl|"; 853 break; 854 case 'webfm': 855 if (user_access('access webfm')) { 856 $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $host ."index.php?q=webfm_popup&caller=ckeditor"; 857 } 858 break; 859 case 'ib': 860 if (user_access('browse own images')) { 861 $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $host ."index.php?q=imagebrowser/view/browser&app=ckeditor"; 862 $settings[$textarea_id]['filebrowserImageWindowWidth'] = 680; 863 $settings[$textarea_id]['filebrowserImageWindowHeight'] = 439; 864 } 865 break; 866 case 'tinybrowser': 867 $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=image"; 868 $settings[$textarea_id]['filebrowserImageWindowWidth'] = (int)$win_size[0] + 15; 869 $settings[$textarea_id]['filebrowserImageWindowHeight'] = (int)$win_size[1] + 15; 870 break; 871 case 'elfinder': 872 $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $host ."index.php?q=elfinder&app=ckeditor"; 873 break; 874 } 875 } 876 877 if ($filebrowser_flash != $filebrowser) { 878 switch ($filebrowser_flash) { 879 case 'ckfinder': 880 if (user_access('allow CKFinder file uploads')) { 881 $ckfinder_full_path = base_path() . ckfinder_path(); 882 $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $ckfinder_full_path .'/ckfinder.html?Type=Images'; 883 $settings[$textarea_id]['filebrowserFlashUploadUrl'] = $ckfinder_full_path .'/core/connector/php/connector.php?command=QuickUpload&type=Images'; 884 } 885 break; 886 case 'imce': 887 $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $host ."index.php?q=imce&app=ckeditor|sendto@ckeditor_fileUrl|"; 888 break; 889 case 'webfm': 890 if (user_access('access webfm')) { 891 $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $host ."index.php?q=webfm_popup&caller=ckeditor"; 892 } 893 break; 894 case 'ib': 895 if (user_access('browse own images')) { 896 $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $host ."index.php?q=imagebrowser/view/browser&app=ckeditor"; 897 $settings[$textarea_id]['filebrowserFlashWindowWidth'] = 680; 898 $settings[$textarea_id]['filebrowserFlashWindowHeight'] = 439; 899 } 900 break; 901 case 'tinybrowser': 902 $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=media"; 903 $settings[$textarea_id]['filebrowserFlashWindowWidth'] = (int)$win_size[0] + 15; 904 $settings[$textarea_id]['filebrowserFlashWindowHeight'] = (int)$win_size[1] + 15; 905 break; 906 case 'elfinder': 907 $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $host ."index.php?q=elfinder&app=ckeditor"; 908 break; 909 } 910 } 911 912 if (!empty($conf['js_conf'])) { 913 //parsing lines with custom configuration 914 preg_match_all('#config\.(\w+)[\s]*=[\s]*(.+?);[\s]*(?=config\.|$)#is', preg_replace("/[\n\r]+/", "", $conf['js_conf']), $matches); 915 foreach ($matches[2] as $i => $match) { 916 if (!empty($match)) { 917 $value=trim($match, " ;\n\r\t\0\x0B"); 918 if ( strcasecmp($value, 'true') == 0 ) { 919 $value=TRUE; 920 } 921 if ( strcasecmp($value, 'false') == 0 ) { 922 $value=FALSE; 923 } 924 $settings[$textarea_id]["js_conf"][$matches[1][$i]]=$value; 925 } 926 } 927 } 928 929 $settings[$textarea_id]['stylesCombo_stylesSet'] = "drupal:" . $module_full_path . '/ckeditor.styles.js'; 930 if (!empty($conf['css_style'])) { 931 if ($conf['css_style'] == 'theme' && file_exists($themepath . 'ckeditor.styles.js')) { 932 $settings[$textarea_id]['stylesCombo_stylesSet'] = "drupal:" . $host . $themepath . 'ckeditor.styles.js'; 933 } 934 elseif (!empty($conf['css_style']) && $conf['css_style'] == 'self') { 935 $conf['styles_path'] = str_replace("%h%t", "%t", $conf['styles_path']); 936 $settings[$textarea_id]['stylesCombo_stylesSet'] = "drupal:" . str_replace(array('%h', '%t', '%m'), array($host, $host . $themepath, $module_drupal_path), $conf['styles_path']); 937 } 938 } 939 // add custom stylesheet if configured 940 // lets hope it exists but we'll leave that to the site admin 941 $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1); 942 $css_files = array(); 943 switch ($conf['css_mode']) { 944 case 'theme': 945 global $language, $theme_info, $base_theme_info; 946 947 if (!empty($theme_info->stylesheets)) { 948 $editorcss = "\""; 949 foreach ($base_theme_info as $base) { // Grab stylesheets from base theme 950 if (!empty($base->stylesheets)) { // may be empty when the base theme reference in the info file is invalid 951 foreach ($base->stylesheets as $type => $stylesheets) { 952 if ($type != "print") { 953 foreach ($stylesheets as $name => $path) { 954 if (file_exists($path)) { 955 $css_files[$name] = $host . $path . $query_string; 956 // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) ) 957 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path, 0, -8) != "-rtl.css") { 958 $rtl_path = substr($path, 0, -4) . "-rtl.css"; 959 if (file_exists($rtl_path)) { 960 $css_files[$name . "-rtl"] = $host . $rtl_path . $query_string; 961 } 962 } 963 } 964 } 965 } 966 } 967 } 968 } 969 if (!empty($theme_info->stylesheets)) { // Grab stylesheets from current theme 970 foreach ($theme_info->stylesheets as $type => $stylesheets) { 971 if ($type != "print") { 972 foreach ($stylesheets as $name => $path) { 973 // Checks if less module exists... 974 if (strstr($path, '.less') && module_exists('less')) { 975 $path = 'sites/default/files/less/' . $path; // append the less file path 976 $path = str_replace('.less', '', $path); // remove the .less 977 } 978 if (file_exists($path)) { 979 $css_files[$name] = $host . $path . $query_string; 980 // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) ) 981 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path, 0, -8) != "-rtl.css") { 982 $rtl_path = substr($path, 0, -4) . "-rtl.css"; 983 if (file_exists($rtl_path)) { 984 $css_files[$name . "-rtl"] = $host . $rtl_path . $query_string; 985 } 986 } 987 } 988 elseif (!empty($css_files[$name])) { 989 unset($css_files[$name]); 990 } 991 } 992 } 993 } 994 } 995 // Grab stylesheets local.css and local-rtl.css if they exist (fusion based themes) 996 if (file_exists($themepath . 'css/local.css')) { 997 $css_files[] = $host . $themepath . 'css/local.css' . $query_string; 998 } 999 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && file_exists($themepath . 'css/local-rtl.css')) { 1000 $css_files[] = $host . $themepath . 'css/local-rtl.css' . $query_string; 1001 } 1002 1003 // Grab stylesheets from color module 1004 $color_paths = variable_get('color_'. $theme .'_stylesheets', array()); 1005 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) { 1006 if (!empty($color_paths[1])) { 1007 $css_files[] = $host . $color_paths[1] . $query_string; 1008 } 1009 } 1010 elseif (!empty($color_paths[0])) { 1011 $css_files[] = $host . $color_paths[0] . $query_string; 1012 } 1013 } 1014 else { 1015 if (file_exists($themepath .'style.css')) { 1016 $css_files[] = $host . $themepath .'style.css' . $query_string; 1017 } 1018 } 1019 if (file_exists($module_drupal_path .'/ckeditor.css')) { 1020 $css_files[] = $module_full_path .'/ckeditor.css' . $query_string; 1021 } 1022 if (file_exists($themepath . 'ckeditor.css')) { 1023 $css_files[] = $host . $themepath .'ckeditor.css' . $query_string; 1024 } 1025 break; 1026 1027 case 'self': 1028 if (file_exists($module_drupal_path .'/ckeditor.css')) { 1029 $css_files[] = $module_full_path .'/ckeditor.css' . $query_string; 1030 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) { 1031 if (file_exists($module_drupal_path . '/ckeditor-rtl.css')) { 1032 $css_files[] = $module_full_path . '/ckeditor-rtl.css' . $query_string; 1033 } 1034 } 1035 } 1036 foreach (explode(',', $conf['css_path']) as $css_path) { 1037 $css_path = trim(str_replace("%h%t", "%t", $css_path)); 1038 $css_files[] = str_replace(array('%h', '%t'), array($host, $host . $themepath), $css_path) . $query_string; 1039 } 1040 break; 1041 1042 case 'none': 1043 if (file_exists($module_drupal_path .'/ckeditor.css')) { 1044 $css_files[] = $module_full_path .'/ckeditor.css' . $query_string; 1045 if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) { 1046 if (file_exists($module_drupal_path . '/ckeditor-rtl.css')) { 1047 $css_files[] = $module_full_path . '/ckeditor-rtl.css' . $query_string; 1048 } 1049 } 1050 } 1051 $css_files[] = $editor_path .'/contents.css' . $query_string; 1052 break; 1053 } 1054 if (isset($conf['ckeditor_load_method']) && $conf['ckeditor_load_method'] == 'ckeditor_source.js') { 1055 foreach ($css_files as $k => $v) { 1056 $css_files[$k] = $v . '&t=' . time(); 1057 } 1058 } 1059 $settings[$textarea_id]['contentsCss'] = array_values($css_files); 1060 1061 if ($ckeditor_on) { 1062 $autostart[$textarea_id] = TRUE; 1063 } 1064 1065 if (!empty($conf['uicolor']) && $conf['uicolor']=="custom" && !empty($conf['uicolor_user'])) { 1066 $settings[$textarea_id]['uiColor'] = $conf['uicolor_user']; 1067 } 1068 if (!empty($conf['uicolor']) && strpos($conf['uicolor'], "color_") === 0) { 1069 if (function_exists('color_get_palette')) { 1070 $palette = @color_get_palette($theme, FALSE); //[#652274] 1071 $color = str_replace("color_", "", $conf['uicolor']); 1072 if (!empty($palette[$color])) { 1073 $settings[$textarea_id]['uiColor'] = $palette[$color]; 1074 } 1075 } 1076 } 1077 1078 drupal_add_js(array('ckeditor' => array( 'theme' => $theme )), 'setting'); 1079 if (!empty($settings)) { 1080 $_SESSION['cke_get_settings'] = $settings; 1081 drupal_add_js(array('ckeditor' => array('settings' => $settings)), 'setting'); 1082 } 1083 if (!empty($autostart)) { 1084 drupal_add_js(array('ckeditor' => array('autostart' => $autostart)), 'setting'); 1085 } 1086 1087 if ($conf['popup'] == 't') { 1088 $suffix .= ' <span style="display:none" class="ckeditor_popuplink ckeditor_links">(<a href="#" onclick="return ckeditorOpenPopup(\''. $textarea_id .'\', \''. $element['#id'] .'\', \''. $conf['width'] .'\');">'. t('Open rich text editor') ."</a>)</span>"; 1089 } 1090 } 1091 1092 // display the field id for administrators 1093 if (user_access('administer ckeditor') && (!isset($global_conf['show_fieldnamehint']) || $global_conf['show_fieldnamehint'] == 't')) { 1094 module_load_include('inc', 'ckeditor', 'includes/ckeditor.admin'); 1095 $suffix .= '<div class="textarea-identifier description">'. t('CKEditor: the ID for <a href="!excluding">excluding or including</a> this element is %fieldname.', array('!excluding' => url('admin/settings/ckeditor'), '%fieldname' => ckeditor_rule_to_string(ckeditor_rule_create(ckeditor_get_nodetype($_GET['q']), $_GET['q'], $element['#id'])))) .'</div>'; 1096 } 1097 1098 // Remember extra information and reuse it during "Preview" 1099 $processed_ids[$element['#id']]['suffix'] = $suffix; 1100 $processed_ids[$element['#id']]['class'] = $class; 1101 1102 if (empty($element['#suffix'])) { 1103 $element['#suffix'] = $suffix; 1104 } 1105 else { 1106 $element['#suffix'] .= $suffix; 1107 } 1108 1109 if (empty($element['#attributes']['class'])) { 1110 $element['#attributes']['class'] = $class; 1111 } 1112 else { 1113 $element['#attributes']['class'] .= ' '. $class; 1114 } 1115 //hack with patch jquery-ui dialog 1116 return $element; 1117 } 1118 1119 /** 1120 * Read the CKEditor path from the Global profile. 1121 * 1122 * @return 1123 * Path to CKEditor folder. 1124 */ 1125 function ckeditor_path($local = FALSE, $refresh = FALSE) { 1126 static $cke_path; 1127 static $cke_local_path; 1128 1129 if ($refresh || (!$cke_path)) { 1130 $mod_path = drupal_get_path('module', 'ckeditor'); 1131 $lib_path = 'sites/all/libraries'; 1132 $global_profile = ckeditor_profile_load('CKEditor Global Profile', $refresh); 1133 1134 //default: path to ckeditor subdirectory in the ckeditor module directory (starting from the document root) 1135 //e.g. for http://example.com/drupal it will be /drupal/sites/all/modules/ckeditor/ckeditor 1136 $cke_path = base_path() . $mod_path .'/ckeditor'; 1137 1138 //default: path to ckeditor subdirectory in the ckeditor module directory (relative to index.php) 1139 //e.g.: sites/all/modules/ckeditor/ckeditor 1140 $cke_local_path = $mod_path .'/ckeditor'; 1141 if ($global_profile) { 1142 $gs = $global_profile->settings; 1143 1144 if (isset($gs['ckeditor_path'])) { 1145 $tmp_path = $gs['ckeditor_path']; 1146 $tmp_path = strtr($tmp_path, array("%b" => base_path(), "%m" => base_path() . $mod_path, "%l" => base_path() . $lib_path)); 1147 $tmp_path = str_replace('\\', '/', $tmp_path); 1148 $tmp_path = str_replace('//', '/', $tmp_path); 1149 $tmp_path = rtrim($tmp_path, ' \/'); 1150 if (substr($tmp_path, 0, 1) != '/') { 1151 $tmp_path = '/'. $tmp_path; //starts with '/' 1152 } 1153 $cke_path = $tmp_path; 1154 1155 if (empty($gs['ckeditor_local_path'])) { 1156 //fortunately wildcards are used, we can easily get the right server path 1157 if (FALSE !== strpos($gs['ckeditor_path'], "%m")) { 1158 $gs['ckeditor_local_path'] = strtr($gs['ckeditor_path'], array("%m" => $mod_path)); 1159 } 1160 if (FALSE !== strpos($gs['ckeditor_path'], "%b")) { 1161 $gs['ckeditor_local_path'] = strtr($gs['ckeditor_path'], array("%b" => ".")); 1162 } 1163 if (FALSE !== strpos($gs['ckeditor_path'], "%l")) { 1164 $gs['ckeditor_local_path'] = strtr($gs['ckeditor_path'], array("%l" => "sites/all/libraries")); 1165 } 1166 } 1167 } 1168 1169 //ckeditor_path is defined, but wildcards are not used, we need to try to find out where is 1170 //the document root located and append ckeditor_path to it. 1171 if (!empty($gs['ckeditor_local_path'])) { 1172 $cke_local_path = $gs['ckeditor_local_path']; 1173 } 1174 elseif (!empty($gs['ckeditor_path'])) { 1175 module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib'); 1176 $local_path = ckeditor_resolve_url( $gs['ckeditor_path'] ."/" ); 1177 if (FALSE !== $local_path) { 1178 $cke_local_path = $local_path; 1179 } 1180 } 1181 } 1182 } 1183 if ($local) { 1184 return $cke_local_path; 1185 } 1186 else { 1187 return $cke_path; 1188 } 1189 } 1190 1191 /** 1192 * Read the CKEditor plugins path from the Global profile. 1193 * 1194 * @return 1195 * Path to CKEditor plugins folder. 1196 */ 1197 function ckeditor_plugins_path($local = FALSE, $refresh = FALSE) { 1198 static $cke_plugins_path; 1199 static $cke_plugins_local_path; 1200 1201 if ($refresh || (!$cke_plugins_path)) { 1202 $mod_path = drupal_get_path('module', 'ckeditor'); 1203 $lib_path = 'sites/all/libraries'; 1204 $global_profile = ckeditor_profile_load('CKEditor Global Profile', $refresh); 1205 1206 //default: path to plugins subdirectory in the ckeditor module directory (starting from the document root) 1207 //e.g. for http://example.com/drupal it will be /drupal/sites/all/modules/ckeditor/plugins 1208 $cke_plugins_path = base_path() . $mod_path .'/plugins'; 1209 1210 //default: path to plugins subdirectory in the ckeditor module directory (relative to index.php) 1211 //e.g.: sites/all/modules/ckeditor/plugins 1212 $cke_plugins_local_path = $mod_path .'/plugins'; 1213 1214 if ($global_profile) { 1215 $gs = $global_profile->settings; 1216 1217 if (isset($gs['ckeditor_plugins_path'])) { 1218 $tmp_path = $gs['ckeditor_plugins_path']; 1219 $tmp_path = strtr($tmp_path, array("%b" => base_path(), "%m" => base_path() . $mod_path, "%l" => base_path() . $lib_path)); 1220 $tmp_path = str_replace('\\', '/', $tmp_path); 1221 $tmp_path = str_replace('//', '/', $tmp_path); 1222 $tmp_path = rtrim($tmp_path, ' \/'); 1223 if (substr($tmp_path, 0, 1) != '/') { 1224 $tmp_path = '/'. $tmp_path; //starts with '/' 1225 } 1226 $cke_plugins_path = $tmp_path; 1227 1228 if (empty($gs['ckeditor_plugins_local_path'])) { 1229 //fortunately wildcards are used, we can easily get the right server path 1230 if (FALSE !== strpos($gs['ckeditor_plugins_path'], "%m")) { 1231 $gs['ckeditor_plugins_local_path'] = strtr($gs['ckeditor_plugins_path'], array("%m" => $mod_path)); 1232 } 1233 if (FALSE !== strpos($gs['ckeditor_plugins_path'], "%b")) { 1234 $gs['ckeditor_plugins_local_path'] = strtr($gs['ckeditor_plugins_path'], array("%b" => ".")); 1235 } 1236 if (FALSE !== strpos($gs['ckeditor_plugins_path'], "%l")) { 1237 $gs['ckeditor_plugins_local_path'] = strtr($gs['ckeditor_plugins_path'], array("%l" => "sites/all/libraries")); 1238 } 1239 } 1240 } 1241 1242 //ckeditor_plugins_path is defined, but wildcards are not used, we need to try to find out where is 1243 //the document root located and append ckeditor_plugins_path to it. 1244 if (!empty($gs['ckeditor_plugins_local_path']) && !is_null($gs['ckeditor_plugins_local_path'])) { 1245 $cke_plugins_local_path = $gs['ckeditor_plugins_local_path']; 1246 } 1247 elseif (!empty($gs['ckeditor_plugins_path'])) { 1248 module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib'); 1249 $local_path = ckeditor_resolve_url( $gs['ckeditor_plugins_path'] ."/" ); 1250 if (FALSE !== $local_path) { 1251 $cke_plugins_local_path = $local_path; 1252 } 1253 } 1254 } 1255 } 1256 1257 if ($local) { 1258 return $cke_plugins_local_path; 1259 } 1260 else { 1261 return $cke_plugins_path; 1262 } 1263 } 1264 1265 /** 1266 * Read the CKFinder path from the Global profile. 1267 * 1268 * @return 1269 * Path to CKFinder folder. 1270 */ 1271 function ckfinder_path($refresh = FALSE) { 1272 static $ckf_path; 1273 1274 if ($refresh || (!$ckf_path)) { 1275 $mod_path = drupal_get_path('module', 'ckeditor'); 1276 $lib_path = 'sites/all/libraries'; 1277 $global_profile = ckeditor_profile_load('CKEditor Global Profile', $refresh); 1278 1279 //default: path to ckeditor subdirectory in the ckeditor module directory (starting from the document root) 1280 //e.g. for http://example.com/drupal it will be /drupal/sites/all/modules/ckeditor/ckeditor 1281 $ckf_path = $mod_path . '/ckfinder'; 1282 if ($global_profile) { 1283 $gs = $global_profile->settings; 1284 1285 if (isset($gs['ckfinder_path'])) { 1286 $tmp_path = $gs['ckfinder_path']; 1287 $tmp_path = strtr($tmp_path, array("%b" => base_path(), "%m" => $mod_path, "%l" => $lib_path)); 1288 $tmp_path = str_replace('\\', '/', $tmp_path); 1289 $tmp_path = str_replace('//', '/', $tmp_path); 1290 $ckf_path = $tmp_path; 1291 } 1292 } 1293 } 1294 1295 return $ckf_path; 1296 } 1297 1298 function ckeditor_get_nodetype($get_q) { 1299 static $nodetype; 1300 1301 if (!isset($nodetype)) { 1302 $menuitem = menu_get_item($get_q); 1303 $nodetype = '*'; 1304 if (!empty($menuitem['page_arguments']) && is_array($menuitem['page_arguments'])) { 1305 foreach ($menuitem['page_arguments'] as $item) { 1306 if (!empty($item->nid) && !empty($item->type)) { 1307 // not 100% valid check if $item is a node 1308 $nodetype = $item->type; 1309 break; 1310 } 1311 } 1312 } 1313 1314 if ($nodetype == '*') { 1315 $get_q = explode("/", $get_q, 3); 1316 if ($get_q[0] == "node" && !empty($get_q[1]) && $get_q[1] == "add" && !empty($get_q[2])) { 1317 $nodetype = $get_q[2]; 1318 } 1319 } 1320 } 1321 $nodetype = str_replace('-', '_', $nodetype); 1322 return $nodetype; 1323 } 1324 1325 /** 1326 * Implementation of hook_features_api(). 1327 * 1328 * Allow exporting of CKEditor profiles by the Features module. 1329 */ 1330 function ckeditor_features_api() { 1331 return array( 1332 'ckeditor_profile' => array( 1333 'name' => t('CKEditor profiles'), 1334 'default_hook' => 'ckeditor_profile_defaults', 1335 'default_file' => FEATURES_DEFAULTS_INCLUDED, 1336 'file' => drupal_get_path('module', 'ckeditor') .'/includes/ckeditor.features.inc', 1337 ) 1338 ); 1339 } 1340 1341 /** 1342 * Get the language locale code supported by Scayt for the specified language 1343 */ 1344 function _ckeditor_scayt_langcode($lang) { 1345 $scayt_langs = array( 1346 'en' => 'en_US', 1347 'es' => 'es_ES', 1348 'fr' => 'fr_FR', 1349 'de' => 'de_DE', 1350 'it' => 'it_IT', 1351 'el' => 'el_EL', 1352 'pt' => 'pt_PT', 1353 'da' => 'da_DA', 1354 'sv' => 'sv_SE', 1355 'nl' => 'nl_NL', 1356 'nb' => 'no_NO', 1357 'fi' => 'fi_FI', 1358 ); 1359 if (array_key_exists($lang, $scayt_langs)) { 1360 return $scayt_langs[$lang]; 1361 } 1362 1363 $default = language_default('language'); 1364 if (array_key_exists($default, $scayt_langs)) { 1365 return $scayt_langs[$default]; 1366 } 1367 1368 return 'en_US'; 1369 } 1370 /* 1371 * Get settings for ckeditor 1372 * Added for support [#1288664] Views 1373 */ 1374 function ckeditor_get_settings() { 1375 global $user; 1376 module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib'); 1377 if (empty($_POST['id']) || !isset($_POST['token']) || !drupal_valid_token($_POST['token'], 'ckeditorAjaxCall')) { 1378 echo json_encode(array()); 1379 die(); 1380 } 1381 unset($_SESSION['cke_get_settings']); 1382 $enabled = FALSE; 1383 1384 $global_profile = ckeditor_profile_load('CKEditor Global Profile'); 1385 if ($global_profile) { 1386 $global_conf = $global_profile->settings; 1387 if ($global_conf) { 1388 $enabled = ckeditor_is_enabled(empty($global_conf['excl_mode']) ? '0' : $global_conf['excl_mode'], empty($global_conf['excl_regex']) ? '' : $global_conf['excl_regex'], $_POST['id'], $_POST['url']); 1389 } 1390 } 1391 if ($enabled) { 1392 $profile = ckeditor_user_get_profile($user, $_POST['#id']); 1393 if ($profile) { 1394 $conf = array(); 1395 $conf = $profile->settings; 1396 $enabled = ckeditor_is_enabled(empty($conf['excl_mode']) ? '0' : $conf['excl_mode'], empty($conf['excl_regex']) ? '' : $conf['excl_regex'], $_POST['id'], $_POST['url']); 1397 } 1398 else { 1399 $enabled = FALSE; 1400 } 1401 } 1402 1403 if (!$enabled) { 1404 echo json_encode(array()); die(); 1405 } 1406 $element = ckeditor_process_textarea(array('#id' => $_POST['id'])); 1407 if (empty($_SESSION['cke_get_settings'][$_POST['id']])) echo json_encode(array()); 1408 echo json_encode($_SESSION['cke_get_settings'][$_POST['id']]); 1409 die(); 1410 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |