5 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
6 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
10 * Licensed under the terms of any of the following licenses at your
13 * - GNU General Public License Version 2 or later (the "GPL")
14 * http://www.gnu.org/licenses/gpl.html
16 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
17 * http://www.gnu.org/licenses/lgpl.html
19 * - Mozilla Public License Version 1.1 or later (the "MPL")
20 * http://www.mozilla.org/MPL/MPL-1.1.html
25 * FCKeditor Module for Drupal 5.x
27 * This file is required by FCKeditor module if you want to enable built-in file management functionality
29 * This useful script does the following:
30 * - authenticate users that are allowed to use file browser
31 * - redefine the $Config['UserFilesPath'] and $Config['UserFilesAbsolutePath'] according to the values set in FCKeditor profile
34 $GLOBALS['devel_shutdown'] = FALSE
;
36 $fck_user_files_path = "";
37 $fck_user_files_absolute_path = "";
39 function CheckAuthentication()
41 static
$authenticated;
43 if (!isset($authenticated)) {
46 if (!empty($_SERVER['SCRIPT_FILENAME'])) {
47 $drupal_path = dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))));
48 if(!file_exists($drupal_path .
"/includes/bootstrap.inc")) {
49 $drupal_path = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
52 $drupal_path = dirname($drupal_path);
55 while(!($bootstrapFileFound = file_exists($drupal_path .
"/includes/bootstrap.inc")) && $depth<10);
58 if (!isset($bootstrapFileFound) || !$bootstrapFileFound) {
59 $drupal_path = "../../../";
60 if(!file_exists($drupal_path .
"/includes/bootstrap.inc")) {
61 $drupal_path = "../..";
63 $drupal_path .
= "/..";
64 $depth = substr_count($drupal_path, "..");
66 while(!($bootstrapFileFound = file_exists($drupal_path .
"/includes/bootstrap.inc")) && $depth<10);
69 if (!isset($bootstrapFileFound) || $bootstrapFileFound) {
72 require_once
"./includes/bootstrap.inc";
73 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL
);
74 $authenticated = user_access("allow fckeditor file uploads");
75 if (isset($_SESSION['FCKeditor']['UserFilesPath'], $_SESSION['FCKeditor']['UserFilesAbsolutePath'])) {
76 $GLOBALS['fck_user_files_path'] = $_SESSION['FCKeditor']['UserFilesPath'];
77 $GLOBALS['fck_user_files_absolute_path'] = $_SESSION['FCKeditor']['UserFilesAbsolutePath'];
83 return $authenticated;
88 * Although in FCKeditor 2.5 $Config['Enabled'] is not used anymore,
89 * CheckAuthentication() must be called once to initialize session
90 * before sending any content
91 * Static $authenticated variable is being assigned, so
92 * application performance is not affected
94 $Config['Enabled'] = CheckAuthentication();
96 if (!empty($fck_user_files_path)) {
97 $Config['UserFilesPath'] = $fck_user_files_path;
98 $Config['UserFilesAbsolutePath'] = $fck_user_files_absolute_path;
101 // Nothing in session? Shouldn't happen... anyway let's try to upload it in the (almost) right place
102 // Path to user files relative to the document root.
103 $Config['UserFilesPath'] = strtr(base_path(), array(
104 "/modules/fckeditor/fckeditor/editor/filemanager/connectors/php" => "",
105 "/modules/fckeditor/fckeditor/editor/filemanager/browser/default/connectors/php" => "",
106 "/modules/fckeditor/fckeditor/editor/filemanager/upload/php" => "",
107 )) .
file_directory_path() .
"/";