You are here

function ckeditor_path in CKEditor - WYSIWYG HTML editor 6

Same name and namespace in other branches
  1. 7 ckeditor.module \ckeditor_path()

Read the CKEditor path from the Global profile.

Return value

Path to CKEditor folder.

16 calls to ckeditor_path()
ckeditor_admin_global_profile_form in includes/ckeditor.admin.inc
ckeditor_admin_main in includes/ckeditor.admin.inc
Main administrative page
ckeditor_admin_profile_form in includes/ckeditor.admin.inc
Form builder for a normal profile
ckeditor_get_version in ./ckeditor.module
Check CKEditor version
ckeditor_init in ./ckeditor.module
Implementation of hook_init().

... See full list

1 string reference to 'ckeditor_path'
ckeditor_install in ./ckeditor.install

File

./ckeditor.module, line 1205
CKEditor - The text editor for the Internet - http://ckeditor.com Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.

Code

function ckeditor_path($local = FALSE, $refresh = FALSE) {
  static $cke_path;
  static $cke_local_path;
  if ($refresh || !$cke_path) {
    $mod_path = drupal_get_path('module', 'ckeditor');
    $lib_path = 'sites/all/libraries';
    $global_profile = ckeditor_profile_load('CKEditor Global Profile', $refresh);

    //default: path to ckeditor subdirectory in the ckeditor module directory (starting from the document root)

    //e.g. for http://example.com/drupal it will be /drupal/sites/all/modules/ckeditor/ckeditor
    $cke_path = base_path() . $mod_path . '/ckeditor';

    //default: path to ckeditor subdirectory in the ckeditor module directory (relative to index.php)

    //e.g.: sites/all/modules/ckeditor/ckeditor
    $cke_local_path = $mod_path . '/ckeditor';
    if ($global_profile) {
      $gs = $global_profile->settings;
      if (isset($gs['ckeditor_path'])) {
        $tmp_path = $gs['ckeditor_path'];
        $tmp_path = strtr($tmp_path, array(
          "%b" => base_path(),
          "%m" => base_path() . $mod_path,
          "%l" => base_path() . $lib_path,
        ));
        $tmp_path = str_replace('\\', '/', $tmp_path);
        $tmp_path = str_replace('//', '/', $tmp_path);
        $tmp_path = rtrim($tmp_path, ' \\/');
        if (substr($tmp_path, 0, 1) != '/') {
          $tmp_path = '/' . $tmp_path;

          //starts with '/'
        }
        $cke_path = $tmp_path;
        if (empty($gs['ckeditor_local_path'])) {

          //fortunately wildcards are used, we can easily get the right server path
          if (FALSE !== strpos($gs['ckeditor_path'], "%m")) {
            $gs['ckeditor_local_path'] = strtr($gs['ckeditor_path'], array(
              "%m" => $mod_path,
            ));
          }
          if (FALSE !== strpos($gs['ckeditor_path'], "%b")) {
            $gs['ckeditor_local_path'] = strtr($gs['ckeditor_path'], array(
              "%b" => ".",
            ));
          }
          if (FALSE !== strpos($gs['ckeditor_path'], "%l")) {
            $gs['ckeditor_local_path'] = strtr($gs['ckeditor_path'], array(
              "%l" => "sites/all/libraries",
            ));
          }
        }
      }

      //ckeditor_path is defined, but wildcards are not used, we need to try to find out where is

      //the document root located and append ckeditor_path to it.
      if (!empty($gs['ckeditor_local_path'])) {
        $cke_local_path = $gs['ckeditor_local_path'];
      }
      elseif (!empty($gs['ckeditor_path'])) {
        module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
        $local_path = ckeditor_resolve_url($gs['ckeditor_path'] . "/");
        if (FALSE !== $local_path) {
          $cke_local_path = $local_path;
        }
      }
    }
  }
  if ($local) {
    return $cke_local_path;
  }
  else {
    return $cke_path;
  }
}