You are here

function ckeditor_get_document_root_full_path in CKEditor - WYSIWYG HTML editor 7

Same name and namespace in other branches
  1. 6 includes/ckeditor.lib.inc \ckeditor_get_document_root_full_path()

Guess the absolute server path to the document root Usually it should return $_SERVER['DOCUMENT_ROOT']

@todo Improve me!! Returns absolute path or false on failure

Return value

string|boolean

3 calls to ckeditor_get_document_root_full_path()
ckeditor_admin_profile_form in includes/ckeditor.admin.inc
Form builder for a profile
ckeditor_profile_settings_compile in includes/ckeditor.lib.inc
Compile settings of profile
ckeditor_resolve_url in includes/ckeditor.lib.inc
Emulates the asp Server.mapPath function. Given an url path return the physical directory that it corresponds to.

File

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

Code

function ckeditor_get_document_root_full_path() {
  $found = 0;
  $index_dir = realpath(dirname($_SERVER['SCRIPT_FILENAME']));

  // {/dir1/dir2/home/drupal}/index.php
  if (getcwd() == $index_dir) {
    $found++;
  }
  $drupal_dir = base_path();
  $index_dir = str_replace('\\', "/", $index_dir);
  $drupal_dir = str_replace('\\', "/", $drupal_dir);
  $document_root_dir = $index_dir . '/' . str_repeat('../', substr_count($drupal_dir, '/') - 1);
  $document_root_dir = realpath($document_root_dir);
  $document_root_dir = rtrim($document_root_dir, '/\\');
  if ($document_root_dir == $_SERVER['DOCUMENT_ROOT']) {
    $found++;
  }
  $document_root_dir = str_replace('\\', '/', $document_root_dir);
  if ($document_root_dir != '') {
    $found++;
  }
  if (file_exists($document_root_dir)) {
    $found++;
  }
  if (file_exists($document_root_dir . base_path() . 'includes/bootstrap.inc')) {
    $found++;
  }
  if ($found >= 3) {
    return $document_root_dir;
  }
  else {
    return FALSE;
  }
}