[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

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

   1  <?php
   2  // $Id: ckeditor.module,v 1.4.2.31 2010/09/27 12:49:01 dczepierga Exp $
   3  /**
   4   * CKEditor - The text editor for Internet - http://ckeditor.com
   5   * Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
   6   *
   7   * == BEGIN LICENSE ==
   8   *
   9   * Licensed under the terms of any of the following licenses at your
  10   * choice:
  11   *
  12   *  - GNU General Public License Version 2 or later (the "GPL")
  13   *    http://www.gnu.org/licenses/gpl.html
  14   *
  15   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  16   *    http://www.gnu.org/licenses/lgpl.html
  17   *
  18   *  - Mozilla Public License Version 1.1 or later (the "MPL")
  19   *    http://www.mozilla.org/MPL/MPL-1.1.html
  20   *
  21   * == END LICENSE ==
  22   *
  23   * @file
  24   * CKEditor Module for Drupal 6.x
  25   *
  26   * This module allows Drupal to replace textarea fields with CKEditor.
  27   *
  28   * This HTML text editor brings to the web many of the powerful functionalities
  29   * of known desktop editors like Word. It's really  lightweight and doesn't
  30   * require any kind of installation on the client computer.
  31   */
  32  
  33  /**
  34   * The name of simplified toolbar which should be forced
  35   * Be sure that this toolbar is defined in ckeditor.config.js or fckconfig.js
  36   */
  37  define('CKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME', 'DrupalBasic') ;
  38  define('CKEDITOR_ENTERMODE_P', 1);
  39  define('CKEDITOR_ENTERMODE_BR', 2);
  40  define('CKEDITOR_ENTERMODE_DIV', 3);
  41  
  42  global $_ckeditor_configuration;
  43  global $_ckeditor_ids;
  44  
  45  $_ckeditor_configuration = array();
  46  $_ckeditor_ids = array();
  47  
  48  /**
  49  * Implementation of hook_form_alter()
  50  */
  51  function ckeditor_form_alter(&$form, $form_state, $form_id) {
  52    // [#659278], [#666560], [#666616]
  53    if (substr($form_id, -10) == '_node_form') {
  54      $nodetype = $form['type']['#value'];
  55      if (!empty($form['body_field']['teaser_js']['#teaser'])) {
  56        $setting['ckeditor']['teaser'] = $form['body_field']['teaser_js']['#teaser'];
  57        drupal_add_js($setting, 'setting');
  58      }
  59    }
  60  }
  61  
  62  /**
  63   * Implementation of hook_help().
  64   *
  65   * This function delegates execution to ckeditor_help_delegate() in includes/ckeditor.page.inc to
  66   * lower the amount of code in ckeditor.module
  67   */
  68  function ckeditor_help($path, $arg) {
  69    module_load_include('inc', 'ckeditor', 'includes/ckeditor.page');
  70    return module_invoke('ckeditor', 'help_delegate', $path, $arg);
  71  }
  72  
  73  /**
  74   * Implementation of hook_user().
  75   *
  76   * This function delegates execution to ckeditor_user_delegate() in includes/ckeditor.user.inc to
  77   * lower the amount of code in ckeditor.module
  78   */
  79  function ckeditor_user($type, $edit, &$user, $category = NULL) {
  80    if (($type == 'form' && $category == 'account' && user_access('access ckeditor')) || $type == 'validate') {
  81      module_load_include('inc', 'ckeditor', 'includes/ckeditor.user');
  82      return ckeditor_user_delegate($type, $edit, $user, $category);
  83    }
  84    return NULL;
  85  }
  86  
  87  /**
  88   * Implementation of hook_perm().
  89   * Administer -> User management -> Permissions
  90   */
  91  function ckeditor_perm() {
  92    $arr = array('administer ckeditor', 'access ckeditor');
  93    if (file_exists(drupal_get_path('module', 'ckeditor') . "/ckfinder")) {
  94      $arr[] = 'allow CKFinder file uploads';
  95    }
  96    return $arr;
  97  }
  98  
  99  /**
 100   * Implementation of hook_elements().
 101   * Replace textarea with CKEditor using callback function (ckeditor_process_textarea)
 102   */
 103  function ckeditor_elements() {
 104    $type = array();
 105    $type['textfield'] = array(
 106      '#process' => array(
 107        'ckeditor_process_input'
 108      ),
 109    );
 110    // only roles with permission get the ckeditor
 111    if (user_access('access ckeditor')) {
 112      $type['textarea'] = array('#process' => array('ckeditor_process_textarea'));
 113      $type['form'] = array('#after_build' => array('ckeditor_process_form'));
 114      $type['hidden'] = array('#process' => array('ckeditor_process_hidden'));
 115    }
 116    return $type;
 117  }
 118  
 119  function ckeditor_process_hidden($element, $edit, $form_state, $complete_form) {
 120    if (!empty($element['#value']) && in_array($element['#value'], array('panels_edit_display_form', 'panels_panel_context_edit_content'))) {
 121      $fake_element = array('#id' => 'edit-body');
 122      ckeditor_process_textarea($fake_element);
 123    }
 124    return $element;
 125  }
 126  
 127  function ckeditor_process_form(&$form) {
 128    global $_ckeditor_configuration, $_ckeditor_ids;
 129    static $processed_textareas = array();
 130    static $found_textareas = array();
 131  
 132    //Skip if:
 133    // - we're not editing an element
 134    // - ckeditor is not enabled (configuration is empty)
 135    if (arg(1) == "add" || arg(1) == "reply" || !count($_ckeditor_configuration)) {
 136      return $form;
 137    }
 138  
 139    $ckeditor_filters = array();
 140  
 141    // Iterate over element children; resetting array keys to access last index.
 142    if ($children = array_values(element_children($form))) {
 143      foreach ($children as $index => $item) {
 144        $element = &$form[$item];
 145  
 146        if (isset($element['#id']) && in_array($element['#id'], $_ckeditor_ids)) {
 147          $found_textareas[$element['#id']] = &$element;
 148        }
 149  
 150        // filter_form() always uses the key 'format'. We need a type-agnostic
 151        // match to prevent FALSE positives. Also, there must have been at least
 152        // one element on this level.
 153        if ($item === 'format' && $index > 0) {
 154  
 155          // Make sure we either match a input format selector or input format
 156          // guidelines (displayed if user has access to one input format only).
 157          if ((isset($element['#type']) && $element['#type'] == 'fieldset') || isset($element['format']['guidelines'])) {
 158            // The element before this element is the target form field.
 159            $field = &$form[$children[$index - 1]];
 160            $textarea_id = $field['#id'];
 161  
 162            array_push($processed_textareas, $textarea_id);
 163  
 164            //search for checkxss1/2 class
 165            if (empty($field['#attributes']['class']) || strpos($field['#attributes']['class'], "checkxss") === FALSE) {
 166              continue;
 167            }
 168  
 169            // Determine the available input formats. The last child element is a
 170            // link to "More information about formatting options". When only one
 171            // input format is displayed, we also have to remove formatting
 172            // guidelines, stored in the child 'format'.
 173            $formats = element_children($element);
 174  
 175            foreach ($formats as $format_id) {
 176              $format = !empty($element[$format_id]['#default_value']) ? $element[$format_id]['#default_value'] : $element[$format_id]['#value'];
 177              break;
 178            }
 179  
 180            $enabled = filter_list_format($format);
 181            $ckeditor_filters = array();
 182  
 183            //loop through all enabled filters
 184            foreach ($enabled as $id => $filter) {
 185              //but use only that one selected in CKEditor profile
 186              if (in_array($id, array_keys($_ckeditor_configuration[$textarea_id]['filters'])) && $_ckeditor_configuration[$textarea_id]['filters'][$id]) {
 187                if (!isset($ckeditor_filters[$textarea_id])) {
 188                  $ckeditor_filters[$textarea_id] = array();
 189                }
 190                $ckeditor_filters[$textarea_id][] = $id ."/". $format;
 191              }
 192            }
 193  
 194            //No filters assigned, remove xss class
 195            if (empty($ckeditor_filters[$textarea_id])) {
 196              $field['#attributes']['class'] = preg_replace("/checkxss(1|2)/", "", $field['#attributes']['class']);
 197            }
 198            else {
 199              $field['#attributes']['class'] = strtr($field['#attributes']['class'], array("checkxss1" => "filterxss1", "checkxss2" => "filterxss2"));
 200            }
 201  
 202            array_pop($formats);
 203            unset($formats['format']);
 204          }
 205          // If this element is 'format', do not recurse further.
 206          continue;
 207        }
 208        // Recurse into children.
 209        ckeditor_process_form($element);
 210      }
 211    }
 212  
 213    //We're in a form
 214    if (isset($form['#action'])) {
 215      //some textareas associated with CKEditor has not been processed
 216      if (count($processed_textareas) < count($_ckeditor_ids)) {
 217        //loop through all found textfields
 218        foreach (array_keys($found_textareas) as $id) {
 219          $element = &$found_textareas[$id];
 220          //if not processed yet (checkxss class is before final processing)
 221          if (strpos($element['#attributes']['class'], "checkxss") !== FALSE && !in_array($element['#id'], $processed_textareas) && !empty($_ckeditor_configuration[$id]['filters']) && array_sum($_ckeditor_configuration[$id]['filters'])) {
 222            //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
 223            $ckeditor_filters[$element['#id']][] = "filter/0/1";
 224            $element['#attributes']['class'] = strtr($element['#attributes']['class'], array("checkxss1" => "filterxss1", "checkxss2" => "filterxss2"));
 225          }
 226        }
 227      }
 228    }
 229  
 230    if (!empty($ckeditor_filters)) {
 231      foreach ($ckeditor_filters as $id => $filters) {
 232        $arr['settings'][$id]['filters'] = $filters;
 233      }
 234      drupal_add_js(array('ckeditor' => $arr), 'setting');
 235    }
 236  
 237    return $form;
 238  }
 239  
 240  /**
 241   * Allow more than 255 chars in Allowed HTML tags textfield
 242   */
 243  function ckeditor_process_input($element) {
 244    if ($element['#id']=='edit-allowed-html-1') {
 245      $element['#maxlength'] = max($element['#maxlength'], 1024);
 246    }
 247    return $element;
 248  }
 249  
 250  /**
 251   * Implementation of hook_menu().
 252   */
 253  function ckeditor_menu() {
 254    $items = array();
 255  
 256    $items['ckeditor/xss'] = array(
 257      'title' => 'XSS Filter',
 258      'description' => 'XSS Filter.',
 259      'page callback' => 'ckeditor_filter_xss',
 260      'file' => 'includes/ckeditor.page.inc',
 261      'access arguments' => array('access ckeditor'),
 262      'type' => MENU_CALLBACK,
 263    );
 264  
 265    $items['admin/settings/ckeditor'] = array(
 266      'title' => 'CKEditor',
 267      'description' => 'Configure the rich text editor.',
 268      'page callback' => 'ckeditor_admin_main',
 269      'file' => 'includes/ckeditor.admin.inc',
 270      'access arguments' => array('administer ckeditor'),
 271      'type' => MENU_NORMAL_ITEM,
 272    );
 273  
 274    $items['admin/settings/ckeditor/add'] = array(
 275      'title' => 'Add new CKEditor profile',
 276      'description' => 'Configure the rich text editor.',
 277      'page callback' => 'drupal_get_form',
 278      'page arguments' => array('ckeditor_admin_profile_form'),
 279      'file' => 'includes/ckeditor.admin.inc',
 280      'access arguments' => array('administer ckeditor'),
 281      'type' => MENU_CALLBACK,
 282    );
 283  
 284    $items['admin/settings/ckeditor/clone/%ckeditor_profile'] = array(
 285      'title' => 'Clone CKEditor profile',
 286      'description' => 'Configure the rich text editor.',
 287      'page callback' => 'drupal_get_form',
 288      'page arguments' => array('ckeditor_admin_profile_clone_form', 4),
 289      'file' => 'includes/ckeditor.admin.inc',
 290      'access arguments' => array('administer ckeditor'),
 291      'type' => MENU_CALLBACK,
 292    );
 293  
 294    $items['admin/settings/ckeditor/edit/%ckeditor_profile'] = array(
 295      'title' => 'Edit CKEditor profile',
 296      'description' => 'Configure the rich text editor.',
 297      'page callback' => 'drupal_get_form',
 298      'page arguments' => array('ckeditor_admin_profile_form', 4),
 299      'file' => 'includes/ckeditor.admin.inc',
 300      'access arguments' => array('administer ckeditor'),
 301      'type' => MENU_CALLBACK,
 302    );
 303  
 304    $items['admin/settings/ckeditor/delete/%ckeditor_profile'] = array(
 305      'title' => 'Delete CKEditor profile',
 306      'description' => 'Configure the rich text editor.',
 307      'page callback' => 'drupal_get_form',
 308      'page arguments' => array('ckeditor_admin_profile_delete_form', 4),
 309      'file' => 'includes/ckeditor.admin.inc',
 310      'access arguments' => array('administer ckeditor'),
 311      'type' => MENU_CALLBACK,
 312    );
 313  
 314    $items['admin/settings/ckeditor/addg'] = array(
 315      'title' => 'Add CKEditor Global profile',
 316      'description' => 'Configure the rich text editor.',
 317      'page callback' => 'drupal_get_form',
 318      'page arguments' => array('ckeditor_admin_global_profile_form', 'add'),
 319      'file' => 'includes/ckeditor.admin.inc',
 320      'access arguments' => array('administer ckeditor'),
 321      'type' => MENU_CALLBACK,
 322    );
 323  
 324    $items['admin/settings/ckeditor/editg'] = array(
 325      'title' => 'Edit CKEditor Global profile',
 326      'description' => 'Configure the rich text editor.',
 327      'page callback' => 'drupal_get_form',
 328      'page arguments' => array('ckeditor_admin_global_profile_form', 'edit'),
 329      'file' => 'includes/ckeditor.admin.inc',
 330      'access arguments' => array('administer ckeditor'),
 331      'type' => MENU_CALLBACK,
 332    );
 333  
 334    return $items;
 335  }
 336  
 337  /**
 338   * Implementation of hook_init().
 339   */
 340  function ckeditor_init() {
 341    drupal_add_css(drupal_get_path('module', 'ckeditor') .'/ckeditor.css');
 342  }
 343  
 344  /**
 345   * Implementation of hook_file_download().
 346   * Support for private downloads.
 347   * CKEditor does not implement any kind of potection on private files.
 348   */
 349  function ckeditor_file_download($file) {
 350    if ($path = file_create_path($file)) {
 351      $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $path);
 352      if (db_fetch_object($result)) {
 353          return NULL;
 354      }
 355  
 356      //No info in DB? Probably a file uploaded with FCKeditor / CKFinder
 357      $global_profile = ckeditor_profile_load("CKEditor Global Profile");
 358  
 359      //Assume that files inside of ckeditor directory belong to the CKEditor. If private directory is set, let the decision about protection to the user.
 360      $private_dir = isset($global_profile->settings['private_dir']) ? trim($global_profile->settings['private_dir'], '\/') : '';
 361      $private_dir = preg_quote($private_dir, '#');
 362      $private_dir = strtr($private_dir, array('%u' => '(\d+)', '%n' => '([\x80-\xF7 \w@.-]+)')); // regex for %n taken from user_validate_name() in user.module
 363      $private_dir = trim($private_dir, '\/');
 364  
 365      $regex = '#^'. preg_quote(file_directory_path() .'/', '#') . $private_dir .'#';
 366  
 367      //If path to the file points to the CKEditor private directory, allow downloading
 368      if (preg_match($regex, $path)) {
 369        $ctype = ($info = @getimagesize($path)) ? $info['mime'] : (function_exists('mime_content_type') ? mime_content_type($path) : 'application/x-download');
 370        return array('Content-Type: '. $ctype);
 371      }
 372    }
 373  }
 374  
 375  /**
 376   * Load all profiles. Just load one profile if $name is passed in.
 377   */
 378  function ckeditor_profile_load($name = '', $clear = FALSE) {
 379    static $profiles = array();
 380  
 381    if (empty($profiles) || $clear === TRUE) {
 382      $result = db_query("SELECT * FROM {ckeditor_settings}");
 383      while (($data = db_fetch_object($result))) {
 384        $data->settings = unserialize($data->settings);
 385        $data->rids = array();
 386  
 387        $profiles[$data->name] = $data;
 388      }
 389  
 390      $roles = user_roles();
 391      $result = db_query("SELECT name, rid FROM {ckeditor_role}");
 392      while (($data = db_fetch_object($result))) {
 393        $profiles[$data->name]->rids[$data->rid] = $roles[$data->rid];
 394      }
 395    }
 396  
 397    return ($name ? (isset($profiles[urldecode($name)]) ? $profiles[urldecode($name)] : FALSE) : $profiles);
 398  }
 399  
 400  /**
 401   * This function create the HTML objects required for the CKEditor
 402   *
 403   * @param $element
 404   *   A fully populated form elment to add the editor to
 405   * @return
 406   *   The same $element with extra CKEditor markup and initialization
 407   */
 408  function ckeditor_process_textarea($element) {
 409    static $is_running = FALSE;
 410    static $num = 1;
 411    static $processed_ids=array();
 412    global $user, $theme, $language, $_ckeditor_configuration, $_ckeditor_ids;
 413    $settings = array();
 414    $enabled = TRUE;
 415    $suffix = "";
 416    $class = "";
 417    //hack for module developers that want to disable ckeditor on their textareas
 418    if (key_exists('#wysiwyg', $element) && !$element['#wysiwyg']) {
 419      return $element;
 420    }
 421  
 422    if (isset($element['#access']) && !$element['#access']) {
 423      return $element;
 424    }
 425  
 426    //skip this one, surely nobody wants WYSIWYG here
 427    switch ($element['#id']) {
 428      case 'edit-log':
 429        return $element;
 430        break;
 431    }
 432  
 433    if (isset($element['#attributes']['disabled']) && $element['#attributes']['disabled'] == 'disabled') {
 434      return $element;
 435    }
 436  
 437    if (isset($processed_ids[$element['#id']])) {
 438      //statement for node preview purpose, when second textarea element with the same id is processing to add class which ckeditor behavior must process
 439      if (empty($element['#attributes']['class'])) {
 440        $element['#attributes']['class'] = $processed_ids[$element['#id']]['class'];
 441      }
 442      else {
 443        $element['#attributes']['class'] .= " ". $processed_ids[$element['#id']]['class'];
 444      }
 445      if (empty($element['#suffix'])) {
 446        $element['#suffix'] = $processed_ids[$element['#id']]['suffix'];
 447      }
 448      else {
 449        $element['#suffix'] .= $processed_ids[$element['#id']]['suffix'];
 450      }
 451      return $element;
 452    }
 453    else {
 454      $processed_ids[$element['#id']] = array();
 455    }
 456  
 457    module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
 458  
 459    $global_profile = ckeditor_profile_load('CKEditor Global Profile');
 460    if ($global_profile) {
 461      $global_conf = $global_profile->settings;
 462      if ($global_conf) {
 463        $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']);
 464      }
 465    }
 466  
 467    if ($enabled) {
 468      $profile = ckeditor_user_get_profile($user, $element['#id']);
 469      if ($profile) {
 470        $conf = array();
 471        $conf = $profile->settings;
 472  
 473        if ($conf['allow_user_conf']=='t') {
 474          foreach (array('default', 'show_toggle', 'popup', 'skin', 'toolbar', 'expand', 'width', 'lang', 'auto_lang') as $setting) {
 475            $conf[$setting] = ckeditor_user_get_setting($user, $profile, $setting);
 476          }
 477        }
 478        if ($conf['popup'] == 't' && $conf['show_toggle'] == 't') {
 479          $conf['show_toggle'] = 'f';
 480        }
 481      }
 482      else {
 483        $enabled = FALSE;
 484      }
 485    }
 486  
 487    //old profile info, assume Filtered HTML is enabled
 488    if (!isset($conf['ss'])) {
 489      $conf['ss'] = 2;
 490      $conf['filters']['filter/0'] = 1;
 491    }
 492    if (!isset($conf['filters'])) {
 493      $conf['filters'] = array();
 494    }
 495  
 496    $themepath = path_to_theme() .'/';
 497    $host = base_path();
 498    if (!isset($element['#rows'])){
 499      $element['#rows'] = 5;
 500    }
 501    // only replace textarea when it has enough rows and it is enabled
 502    if ($enabled && (($element['#rows'] > $conf['min_rows']) || ($conf['min_rows'] <= 1 && empty($element['#rows'])))) {
 503      $textarea_id = $element['#id'];
 504      $class = 'ckeditor-mod';
 505      $_ckeditor_ids[] = $textarea_id;
 506      $ckeditor_on = ($conf['default']=='t') ? 1 : 0 ;
 507  
 508      $xss_check = 0;
 509      //it's not a problem when adding new content/comment
 510      if (arg(1) != "add" && arg(1) != "reply") {
 511        $_ckeditor_configuration[$element['#id']] = $conf;
 512  
 513        //let ckeditor know when perform XSS checks auto/manual
 514        if ($conf['ss'] == 1) {
 515          $xss_class = 'checkxss1';
 516        }
 517        else {
 518          $xss_class = 'checkxss2';
 519        }
 520  
 521        $class .= ' '. $xss_class;
 522        $xss_check = 1;
 523      }
 524  
 525      //settings are saved as strings, not booleans
 526      if ($conf['show_toggle'] == 't') {
 527        $content = '';
 528        if (isset($element['#post']['teaser_js'])) {
 529          $content .= $element['#post']['teaser_js'] .'<!--break-->';
 530        }
 531        if (isset($element['#value'])) {
 532          $content .= $element['#value'];
 533        }
 534        $wysiwyg_link = '';
 535        $wysiwyg_link .= "<a class=\"ckeditor_links\" style=\"display:none\" href=\"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}\">";
 536        $wysiwyg_link .= $ckeditor_on ? t('Switch to plain text editor') : t('Switch to rich text editor');
 537        $wysiwyg_link .= '</a>';
 538  
 539        // Make sure to append to #suffix so it isn't completely overwritten
 540        $suffix .= $wysiwyg_link;
 541      }
 542      // setting some variables
 543      $module_drupal_path = drupal_get_path('module', 'ckeditor');
 544      $module_full_path   = $host . $module_drupal_path;
 545      $editor_path        = ckeditor_path(FALSE);
 546      $editor_local_path  = ckeditor_path(TRUE);
 547      // get the default drupal files path
 548      $files_path         = $host . file_directory_path();
 549  
 550      // sensible default for small toolbars
 551      if (isset($element['#rows'])) {
 552        $height = intval($element['#rows']) * 14 + 140;
 553      } else {
 554        $height = 400;
 555      }
 556      if (!$is_running) {
 557        drupal_add_js($module_drupal_path .'/includes/ckeditor.utils.js', 'module', variable_get('preprocess_js', FALSE) ? 'header' : 'footer');
 558        /* In D6 drupal_add_js() can't add external JS, in D7 use drupal_add_js(...,'external') */
 559        if ( $conf['popup'] != 't' ) {
 560          if (isset($conf['ckeditor_load_method'])) {
 561            drupal_set_html_head('<script type="text/javascript" src="'. $editor_path . '/' . $conf['ckeditor_load_method'] . '?I"></script>');
 562            if ($conf['ckeditor_load_method'] == 'ckeditor_basic.js') {
 563              drupal_set_html_head('<script type="text/javascript">CKEDITOR.loadFullCoreTimeout = ' . $conf['ckeditor_load_time_out'] . ';</script>');
 564              drupal_add_js(array('ckeditor' => array('load_timeout' => TRUE)), 'setting');
 565            }
 566          }
 567          else {
 568            drupal_set_html_head('<script type="text/javascript" src="'. $editor_path .'/ckeditor.js?I"></script>');
 569          }
 570        }
 571        else {
 572          drupal_set_html_head('<script type="text/javascript" src="'. $editor_path .'/ckeditor_basic.js?I"></script>');
 573        }
 574        drupal_add_js(array('ckeditor' => array('module_path' => $module_full_path)), 'setting');
 575        if ($conf['popup'] == 't') {
 576          drupal_add_js(array('ckeditor' => array('editor_path' => $editor_path)), 'setting');
 577        }
 578        if (module_exists('paging')) {
 579          drupal_add_js(array('ckeditor' => array('pagebreak' => TRUE)), 'setting');
 580        }
 581        if (module_exists('linktocontent_node')) {
 582          drupal_add_js(array('ckeditor' => array('linktocontent_node' => TRUE)), 'setting');
 583        }
 584        if (module_exists('linktocontent_menu')) {
 585          drupal_add_js(array('ckeditor' => array('linktocontent_menu' => TRUE)), 'setting');
 586        }
 587        if (module_exists('pagebreak')) {
 588          drupal_add_js(array('ckeditor' => array('pagebreak' => TRUE)), 'setting');
 589        }
 590        if (function_exists('linktocontent_node_menu')) {
 591          if (!empty($global_conf['linktoc']) && $global_conf['linktoc']!='p') {
 592            drupal_add_js(array('ckeditor' => array('linktocontent_node_path_filter' => TRUE)), 'setting');
 593            if ($global_conf['linktoc'] == 'pn') {
 594              drupal_add_js(array('ckeditor' => array('linktocontent_node_select_type' => TRUE)), 'setting');
 595            }
 596          }
 597        }
 598        $is_running = TRUE;
 599      }
 600  
 601      $toolbar = $conf['toolbar'];
 602      //$height += 100; // for larger toolbars
 603  
 604      $force_simple_toolbar = ckeditor_is_enabled('1', empty($conf['simple_incl_regex']) ? '' : $conf['simple_incl_regex'], $element['#id'], $_GET['q']);
 605      if (!$force_simple_toolbar) {
 606        $force_simple_toolbar = ckeditor_is_enabled('1', empty($global_conf['simple_incl_regex']) ? '' : $global_conf['simple_incl_regex'], $element['#id'], $_GET['q']);
 607      }
 608      if ($force_simple_toolbar) {
 609        $toolbar = CKEDITOR_FORCE_SIMPLE_TOOLBAR_NAME;
 610      }
 611  
 612      if (!empty($conf['theme_config_js']) && $conf['theme_config_js'] == 't' && file_exists($themepath .'ckeditor.config.js')) {
 613        $ckeditor_config_path = $host . $themepath .'ckeditor.config.js?'. @filemtime($themepath .'ckeditor.config.js');
 614      }
 615      else {
 616        $ckeditor_config_path = $module_full_path ."/ckeditor.config.js?". @filemtime($module_drupal_path ."/ckeditor.config.js");
 617      }
 618  
 619      $settings[$textarea_id]['customConfig'] = $ckeditor_config_path;
 620      $settings[$textarea_id]['defaultLanguage'] = $conf['lang'];
 621      $settings[$textarea_id]['toolbar'] = $toolbar;
 622      $settings[$textarea_id]['enterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['enter_mode']));
 623      $settings[$textarea_id]['shiftEnterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['shift_enter_mode']));
 624      $settings[$textarea_id]['toolbarStartupExpanded'] = ( $conf['expand']=='t' );
 625      $settings[$textarea_id]['customConfig'] = $ckeditor_config_path;
 626      $settings[$textarea_id]['width'] = $conf['width'];
 627      $settings[$textarea_id]['height'] = $height;
 628      $settings[$textarea_id]['skin'] = $conf['skin'];
 629      $settings[$textarea_id]['format_tags'] = $conf['font_format'];
 630      if (isset($conf['language_direction'])) {
 631        switch ($conf['language_direction']) {
 632          case 'default':
 633            if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
 634              $settings[$textarea_id]['contentsLangDirection'] = 'rtl';
 635            }
 636            break;
 637          case 'ltr':
 638            $settings[$textarea_id]['contentsLangDirection'] = 'ltr';
 639            break;
 640          case 'rtl':
 641            $settings[$textarea_id]['contentsLangDirection'] = 'rtl';
 642            break;
 643        }
 644      }
 645      if (isset($conf['scayt_autoStartup']) && $conf['scayt_autoStartup'] == 't') {
 646        $settings[$textarea_id]['scayt_autoStartup'] = TRUE;
 647      } else {
 648        $settings[$textarea_id]['scayt_autoStartup'] = FALSE;
 649      }
 650      if ($conf['auto_lang']=="f") {
 651        $settings[$textarea_id]['language'] = $conf['lang'];
 652      }
 653      if (isset($conf['forcePasteAsPlainText']) && $conf['forcePasteAsPlainText'] == 't') {
 654        $settings[$textarea_id]['forcePasteAsPlainText'] = TRUE;
 655      }
 656      if (isset($conf['custom_formatting']) && $conf['custom_formatting'] == 't') {
 657        foreach ($conf['formatting']['custom_formatting_options'] as $k => $v) {
 658          if ($v === 0) {
 659            $conf['formatting']['custom_formatting_options'][$k] = FALSE;
 660          } else {
 661            $conf['formatting']['custom_formatting_options'][$k] = TRUE;
 662          }
 663        }
 664        $settings[$textarea_id]['output_pre_indent'] = $conf['formatting']['custom_formatting_options']['pre_indent'];
 665        unset($conf['formatting']['custom_formatting_options']['pre_indent']);
 666        $settings[$textarea_id]['custom_formatting'] = $conf['formatting']['custom_formatting_options'];
 667      }
 668      // add code for filebrowser for users that have access
 669      $filebrowser = !empty($conf['filebrowser']) ? $conf['filebrowser'] : 'none';
 670      $filebrowser_image = !empty($conf['filebrowser_image']) ? $conf['filebrowser_image'] : $filebrowser;
 671      $filebrowser_flash = !empty($conf['filebrowser_flash']) ? $conf['filebrowser_flash'] : $filebrowser;
 672  
 673      if ($filebrowser == 'imce' && !module_exists('imce')) {
 674        $filebrowser = 'none';
 675      }
 676  
 677      if ($filebrowser == 'tinybrowser' && !module_exists('tinybrowser')) {
 678        $filebrowser = 'none';
 679      }
 680  
 681      if ($filebrowser == 'ib' && !module_exists('imagebrowser')) {
 682        $filebrowser = 'none';
 683      }
 684      if ($filebrowser == 'webfm' && !module_exists('webfm_popup')) {
 685        $filebrowser = 'none';
 686      }
 687  
 688      if ($filebrowser_image != $filebrowser) {
 689        if ($filebrowser_image == 'imce' && !module_exists('imce')) {
 690          $filebrowser_image = $filebrowser;
 691        }
 692        if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) {
 693          $filebrowser_image = $filebrowser;
 694        }
 695        if ($filebrowser_image == 'ib' && !module_exists('imagebrowser')) {
 696          $filebrowser_image = $filebrowser;
 697        }
 698        if ($filebrowser_image == 'webfm' && !module_exists('webfm_popup')) {
 699          $filebrowser_image = $filebrowser;
 700        }
 701      }
 702  
 703      if ($filebrowser_flash != $filebrowser) {
 704        if ($filebrowser_flash == 'imce' && !module_exists('imce')) {
 705          $filebrowser_flash = $filebrowser;
 706        }
 707        if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) {
 708          $filebrowser_flash = $filebrowser;
 709        }
 710        if ($filebrowser_flash == 'ib' && !module_exists('imagebrowser')) {
 711          $filebrowser_flash = $filebrowser;
 712        }
 713        if ($filebrowser_flash == 'webfm' && !module_exists('webfm_popup')) {
 714          $filebrowser_flash = $filebrowser;
 715        }
 716      }
 717  
 718      if ($filebrowser == 'ckfinder' || $filebrowser_image == 'ckfinder' || $filebrowser_flash == 'ckfinder') {
 719        if (user_access('allow CKFinder file uploads')) {
 720          if (!empty($profile->settings['UserFilesPath'])) {
 721            $_SESSION['ckeditor']['UserFilesPath'] = strtr($profile->settings['UserFilesPath'], array("%f" => file_directory_path(), "%u" => $user->uid, "%b" => $host, "%n" => $user->name));
 722          }
 723          if (!empty($profile->settings['UserFilesAbsolutePath'])) {
 724            $_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));
 725          }
 726          if (variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE) {
 727            $private_dir = isset($global_profile->settings['private_dir']) ? trim($global_profile->settings['private_dir'], '\/') : '';
 728            if (!empty($private_dir)) {
 729              $private_dir = strtr($private_dir, array('%u' => $user->uid, '%n' => $user->name));
 730              $_SESSION['ckeditor']['UserFilesPath'] = url('system/files') .'/'. $private_dir .'/';
 731              $_SESSION['ckeditor']['UserFilesAbsolutePath'] = realpath(file_directory_path()) . DIRECTORY_SEPARATOR . $private_dir . DIRECTORY_SEPARATOR;
 732            }
 733            else {
 734              $_SESSION['ckeditor']['UserFilesPath'] = url('system/files') .'/';
 735              $_SESSION['ckeditor']['UserFilesAbsolutePath'] = realpath(file_directory_path()) . DIRECTORY_SEPARATOR;
 736            }
 737          }
 738        }
 739      }
 740  
 741      if (in_array('tinybrowser', array($filebrowser, $filebrowser_image, $filebrowser_flash))) {
 742        $popup_win_size = variable_get('tinybrowser_popup_window_size', '770x480');
 743        if (!preg_match('#\d+x\d+#is', $popup_win_size)) {
 744          $popup_win_size = '770x480';
 745        }
 746        $popup_win_size = trim($popup_win_size);
 747        $popup_win_size = strtolower($popup_win_size);
 748        $win_size = split('x', $popup_win_size);
 749      }
 750  
 751      switch ($filebrowser) {
 752        case 'ckfinder':
 753          if (user_access('allow CKFinder file uploads')) {
 754            $settings[$textarea_id]['filebrowserBrowseUrl'] = $module_full_path .'/ckfinder/ckfinder.html';
 755            $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $module_full_path .'/ckfinder/ckfinder.html?Type=Images';
 756            $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $module_full_path .'/ckfinder/ckfinder.html?Type=Flash';
 757            $settings[$textarea_id]['filebrowserUploadUrl'] = $module_full_path .'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files';
 758            $settings[$textarea_id]['filebrowserImageUploadUrl'] = $module_full_path .'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
 759            $settings[$textarea_id]['filebrowserFlashUploadUrl'] = $module_full_path .'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash';
 760          }
 761          break;
 762        case 'imce':
 763          $settings[$textarea_id]['filebrowserBrowseUrl'] = $host ."index.php?q=imce&app=ckeditor|sendto@ckeditor_fileUrl|";
 764          break;
 765        case 'webfm':
 766          if (user_access('access webfm')) {
 767            $settings[$textarea_id]['filebrowserBrowseUrl'] = $host ."index.php?q=webfm_popup";
 768          }
 769          break;
 770        case 'ib':
 771          if (user_access('browse own images')) {
 772            $settings[$textarea_id]['filebrowserBrowseUrl'] = $host ."index.php?q=imagebrowser/view/browser&app=ckeditor";
 773            $settings[$textarea_id]['filebrowserWindowWidth'] = 700;
 774            $settings[$textarea_id]['filebrowserWindowHeight'] = 520;
 775          }
 776          break;
 777        case 'tinybrowser':
 778          $settings[$textarea_id]['filebrowserBrowseUrl'] = $host . drupal_get_path('module','tinybrowser') . "/tinybrowser/tinybrowser.php?type=file";
 779          $settings[$textarea_id]['filebrowserWindowWidth'] = (int)$win_size[0] + 15;
 780          $settings[$textarea_id]['filebrowserWindowHeight'] = (int)$win_size[1] + 15;
 781          break;
 782      }
 783  
 784      if ($filebrowser_image != $filebrowser) {
 785        switch ($filebrowser_image) {
 786          case 'ckfinder':
 787            if (user_access('allow CKFinder file uploads')) {
 788              $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $module_full_path .'/ckfinder/ckfinder.html?Type=Images';
 789              $settings[$textarea_id]['filebrowserImageUploadUrl'] = $module_full_path .'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
 790            }
 791            break;
 792          case 'imce':
 793            $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $host ."index.php?q=imce&app=ckeditor|sendto@ckeditor_fileUrl|";
 794            break;
 795          case 'webfm':
 796            if (user_access('access webfm')) {
 797              $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $host ."index.php?q=webfm_popup";
 798            }
 799            break;
 800          case 'ib':
 801            if (user_access('browse own images')) {
 802              $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $host ."index.php?q=imagebrowser/view/browser&app=ckeditor";
 803              $settings[$textarea_id]['filebrowserImageWindowWidth'] = 680;
 804              $settings[$textarea_id]['filebrowserImageWindowHeight'] = 439;
 805            }
 806            break;
 807          case 'tinybrowser':
 808            $settings[$textarea_id]['filebrowserImageBrowseUrl'] = $host . drupal_get_path('module','tinybrowser') . "/tinybrowser/tinybrowser.php?type=image";
 809            $settings[$textarea_id]['filebrowserImageWindowWidth'] = (int)$win_size[0] + 15;
 810            $settings[$textarea_id]['filebrowserImageWindowHeight'] = (int)$win_size[1] + 15;
 811            break;
 812        }
 813      }
 814  
 815      if ($filebrowser_flash != $filebrowser) {
 816        switch ($filebrowser_flash) {
 817          case 'ckfinder':
 818            if (user_access('allow CKFinder file uploads')) {
 819              $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $module_full_path .'/ckfinder/ckfinder.html?Type=Images';
 820              $settings[$textarea_id]['filebrowserFlashUploadUrl'] = $module_full_path .'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images';
 821            }
 822            break;
 823          case 'imce':
 824            $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $host ."index.php?q=imce&app=ckeditor|sendto@ckeditor_fileUrl|";
 825            break;
 826          case 'webfm':
 827            if (user_access('access webfm')) {
 828              $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $host ."index.php?q=webfm_popup";
 829            }
 830            break;
 831          case 'ib':
 832            if (user_access('browse own images')) {
 833              $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $host ."index.php?q=imagebrowser/view/browser&app=ckeditor";
 834              $settings[$textarea_id]['filebrowserFlashWindowWidth'] = 680;
 835              $settings[$textarea_id]['filebrowserFlashWindowHeight'] = 439;
 836            }
 837            break;
 838          case 'tinybrowser':
 839            $settings[$textarea_id]['filebrowserFlashBrowseUrl'] = $host . drupal_get_path('module','tinybrowser') . "/tinybrowser/tinybrowser.php?type=media";
 840            $settings[$textarea_id]['filebrowserFlashWindowWidth'] = (int)$win_size[0] + 15;
 841            $settings[$textarea_id]['filebrowserFlashWindowHeight'] = (int)$win_size[1] + 15;
 842            break;
 843        }
 844      }
 845  
 846      if (!empty($conf['js_conf'])) {
 847        $lines = preg_split("/[\n\r]+/", $conf['js_conf']);
 848        foreach ($lines as $l) {
 849          //parsing lines with custom configuration
 850          preg_match_all('#(config\.)?(\w+)[ ]*=(.+)[;]?#is', $l, $matches);
 851          if (!empty($matches[0])) {
 852            $value=trim($matches[3][0], " ;'\"\n\r\t\0\x0B");
 853            if ( strcasecmp($value, 'true') == 0 ) {
 854              $value=TRUE;
 855            }
 856            if ( strcasecmp($value, 'false') == 0 ) {
 857              $value=FALSE;
 858            }
 859            $settings[$textarea_id][$matches[2][0]]=$value;
 860          }
 861        }
 862      }
 863  
 864      $settings[$textarea_id]['stylesCombo_stylesSet'] = "drupal:" . $module_full_path . '/ckeditor.styles.js';
 865      if (!empty($conf['css_style'])) {
 866        if ($conf['css_style'] == 'theme' && file_exists($themepath . 'ckeditor.styles.js')) {
 867          $settings[$textarea_id]['stylesCombo_stylesSet'] = "drupal:" . $host . $themepath . 'ckeditor.styles.js';
 868        }
 869        elseif (!empty($conf['css_style']) && $conf['css_style'] == 'self') {
 870          $conf['styles_path'] = str_replace("%h%t", "%t", $conf['styles_path']);
 871          $settings[$textarea_id]['stylesCombo_stylesSet'] = "drupal:" . str_replace(array('%h', '%t', '%m'), array($host, $host . $themepath, $module_drupal_path), $conf['styles_path']);
 872        }
 873      }
 874      // add custom stylesheet if configured
 875      // lets hope it exists but we'll leave that to the site admin
 876      $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);
 877      $css_files = array();
 878      switch ($conf['css_mode']) {
 879        case 'theme':
 880          global $language, $theme_info, $base_theme_info;
 881  
 882          if (!empty($theme_info->stylesheets)) {
 883            $editorcss = "\"";
 884            foreach ($base_theme_info as $base) { // Grab stylesheets from base theme
 885              if (!empty($base->stylesheets)) { // may be empty when the base theme reference in the info file is invalid
 886                foreach ($base->stylesheets as $type => $stylesheets) {
 887                  if ($type != "print") {
 888                    foreach ($stylesheets as $name => $path) {
 889                      if (file_exists($path)) {
 890                        $css_files[$name] = $host . $path . $query_string;
 891                        // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) )
 892                        if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path,0,-8) != "-rtl.css") {
 893                          $rtl_path = substr($path,0,-4)."-rtl.css";
 894                          if (file_exists($rtl_path)) {
 895                            $css_files[$name."-rtl"] = $host . $rtl_path . $query_string;
 896                          }
 897                        }
 898                      }
 899                    }
 900                  }
 901                }
 902              }
 903            }
 904            if (!empty($theme_info->stylesheets)) { // Grab stylesheets from current theme
 905              foreach ($theme_info->stylesheets as $type => $stylesheets) {
 906                if ($type != "print") {
 907                  foreach ($stylesheets as $name => $path) {
 908                    if (file_exists($path)) {
 909                      $css_files[$name] = $host . $path . $query_string;
 910                      // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) )
 911                      if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path,0,-8) != "-rtl.css") {
 912                        $rtl_path = substr($path,0,-4)."-rtl.css";
 913                        if (file_exists($rtl_path)) {
 914                          $css_files[$name."-rtl"] = $host . $rtl_path . $query_string;
 915                        }
 916                      }
 917                    }
 918                    elseif (!empty($css_files[$name])) {
 919                      unset($css_files[$name]);
 920                    }
 921                  }
 922                }
 923              }
 924            }
 925            // Grab stylesheets local.css and local-rtl.css if they exist (fusion based themes)
 926            if (file_exists($themepath . 'css/local.css')) {
 927              $css_files[] = $host . $themepath . 'css/local.css' . $query_string;
 928            }
 929            if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && file_exists($themepath . 'css/local-rtl.css')) {
 930              $css_files[] = $host . $themepath . 'css/local-rtl.css' . $query_string;
 931            }
 932  
 933            // Grab stylesheets from color module
 934            $color_paths = variable_get('color_'. $theme .'_stylesheets', array());
 935            if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
 936              if (!empty($color_paths[1])) {
 937                $css_files[] = $host . $color_paths[1] . $query_string;
 938              }
 939            }
 940            elseif (!empty($color_paths[0])) {
 941              $css_files[] = $host . $color_paths[0] . $query_string;
 942            }
 943          }
 944          else {
 945            if (file_exists($themepath .'style.css')) {
 946              $css_files[] = $host . $themepath .'style.css' . $query_string;
 947            }
 948          }
 949          $css_files[] = $module_full_path ."/ckeditor.css" . $query_string;
 950          break;
 951  
 952        case 'self':
 953          if (file_exists($module_drupal_path .'/ckeditor.css')) {
 954            $css_files[] = $module_full_path .'/ckeditor.css' . $query_string;
 955          }
 956          foreach (explode(',', $conf['css_path']) as $css_path) {
 957            $css_path = trim(str_replace("%h%t", "%t", $css_path));
 958            $css_files[] = str_replace(array('%h', '%t'), array($host, $host . $themepath), $css_path) . $query_string;
 959          }
 960          break;
 961  
 962        case 'none':
 963          if (file_exists($module_drupal_path .'/ckeditor.css')) {
 964            $css_files[] = $module_full_path .'/ckeditor.css' . $query_string;
 965          }
 966          $css_files[] = $editor_path .'/contents.css' . $query_string;
 967          break;
 968      }
 969      if ($conf['ckeditor_load_method'] == 'ckeditor_source.js') {
 970        foreach ($css_files as $k => $v) {
 971          $css_files[$k] = $v . '&t=' . time();
 972        }
 973      }
 974      $settings[$textarea_id]['contentsCss'] = array_values($css_files);
 975  
 976      if ($ckeditor_on) {
 977        $autostart[$textarea_id] = TRUE;
 978      }
 979  
 980      if (!empty($conf['uicolor']) && $conf['uicolor']=="custom" && !empty($conf['uicolor_user'])) {
 981        $settings[$textarea_id]['uiColor'] = $conf['uicolor_user'];
 982      }
 983      if (!empty($conf['uicolor']) && strpos($conf['uicolor'], "color_") === 0) {
 984        if (function_exists('color_get_palette')) {
 985          $palette = @color_get_palette($theme, FALSE); //[#652274]
 986          $color = str_replace("color_", "", $conf['uicolor']);
 987          if (!empty($palette[$color])) {
 988            $settings[$textarea_id]['uiColor'] = $palette[$color];
 989          }
 990        }
 991      }
 992  
 993      drupal_add_js(array('ckeditor' => array( 'theme' => $theme )), 'setting');
 994      if (!empty($settings)) {
 995        drupal_add_js(array('ckeditor' => array('settings' => $settings)), 'setting');
 996      }
 997      if (!empty($autostart)) {
 998        drupal_add_js(array('ckeditor' => array('autostart' => $autostart)), 'setting');
 999      }
1000  
1001      if ($conf['popup'] == 't') {
1002        $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>";
1003      }
1004    }
1005  
1006    // display the field id for administrators
1007    if (user_access('administer ckeditor') && (!isset($global_conf['show_fieldnamehint']) || $global_conf['show_fieldnamehint'] == 't')) {
1008      module_load_include('inc', 'ckeditor', 'includes/ckeditor.admin');
1009      $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>';
1010    }
1011  
1012    // Remember extra information and reuse it during "Preview"
1013    $processed_ids[$element['#id']]['suffix'] = $suffix;
1014    $processed_ids[$element['#id']]['class'] = $class;
1015  
1016    if (empty($element['#suffix'])) {
1017      $element['#suffix'] = $suffix;
1018    }
1019    else {
1020      $element['#suffix'] .= $suffix;
1021    }
1022  
1023    if (empty($element['#attributes']['class'])) {
1024      $element['#attributes']['class'] = $class;
1025    }
1026    else {
1027      $element['#attributes']['class'] .= ' '. $class;
1028    }
1029    //hack with patch jquery-ui dialog
1030  
1031    return $element;
1032  }
1033  
1034  /**
1035   * Read CKEditor path from Global profile
1036   *
1037   * @return
1038   *   path to CKEditor folder
1039   */
1040  function ckeditor_path($local = FALSE, $refresh = FALSE) {
1041    static $cke_path;
1042    static $cke_local_path;
1043  
1044    if ($refresh || (!$cke_path)) {
1045      $mod_path = drupal_get_path('module', 'ckeditor');
1046      $global_profile = ckeditor_profile_load('CKEditor Global Profile', $refresh);
1047  
1048      //default: path to ckeditor subdirectory in the ckeditor module directory (starting from the document root)
1049      //e.g. for http://example.com/drupal it will be /drupal/sites/all/modules/ckeditor/ckeditor
1050      $cke_path = base_path() . $mod_path .'/ckeditor';
1051  
1052      //default: path to ckeditor subdirectory in the ckeditor module directory (relative to index.php)
1053      //e.g.: sites/all/modules/ckeditor/ckeditor
1054      $cke_local_path = $mod_path .'/ckeditor';
1055  
1056      if ($global_profile) {
1057        $gs = $global_profile->settings;
1058  
1059        if (isset($gs['ckeditor_path'])) {
1060          $tmp_path = $gs['ckeditor_path'];
1061          $tmp_path = strtr($tmp_path, array("%b" => base_path(), "%m" => base_path() . $mod_path));
1062          $tmp_path   = str_replace('\\', '/', $tmp_path);
1063          $tmp_path   = str_replace('//', '/', $tmp_path);
1064          $tmp_path = rtrim($tmp_path, ' \/');
1065          if (substr($tmp_path, 0, 1) != '/') {
1066            $tmp_path = '/'. $tmp_path; //starts with '/'
1067          }
1068          $cke_path = $tmp_path;
1069  
1070          if (empty($gs['ckeditor_local_path'])) {
1071            //fortunately wildcards are used, we can easily get the right server path
1072            if (FALSE !== strpos($gs['ckeditor_path'], "%m")) {
1073              $gs['ckeditor_local_path'] = strtr($gs['ckeditor_path'], array("%m" => $mod_path));
1074            }
1075            if (FALSE !== strpos($gs['ckeditor_path'], "%b")) {
1076              $gs['ckeditor_local_path'] = strtr($gs['ckeditor_path'], array("%b" => "."));
1077            }
1078          }
1079        }
1080  
1081        //ckeditor_path is defined, but wildcards are not used, we need to try to find out where is
1082        //the document root located and append ckeditor_path to it.
1083        if (!empty($gs['ckeditor_local_path'])) {
1084          $cke_local_path = $gs['ckeditor_local_path'];
1085        }
1086        elseif (!empty($gs['ckeditor_path'])) {
1087          module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
1088          $local_path = ckeditor_resolve_url( $gs['ckeditor_path'] ."/" );
1089          if (FALSE !== $local_path) {
1090            $cke_local_path = $local_path;
1091          }
1092        }
1093      }
1094    }
1095    if ($local) {
1096      return $cke_local_path;
1097    }
1098    else {
1099      return $cke_path;
1100    }
1101  }
1102  
1103  function ckeditor_get_nodetype($get_q) {
1104    static $nodetype;
1105  
1106    if (!isset($nodetype)) {
1107      $menuitem = menu_get_item();
1108      $nodetype = '*';
1109      if (!empty($menuitem['page_arguments']) && is_array($menuitem['page_arguments'])) {
1110        foreach ($menuitem['page_arguments'] as $item) {
1111          if (!empty($item->nid) && !empty($item->type)) {
1112            // not 100% valid check if $item is a node
1113            $nodetype = $item->type;
1114            break;
1115          }
1116        }
1117      }
1118  
1119      if ($nodetype == '*') {
1120        $get_q = explode("/", $get_q, 3);
1121        if ($get_q[0] == "node" && !empty($get_q[1]) && $get_q[1] == "add" && !empty($get_q[2])) {
1122          $nodetype = $get_q[2];
1123        }
1124      }
1125    }
1126  
1127    return $nodetype;
1128  }


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