| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: fckeditor.lib.inc,v 1.1.2.7 2010/03/10 07:43:32 jorrit Exp $ 3 /** 4 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 5 * Copyright (C) 2003-2008 Frederico Caldeira Knabben 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 * FCKeditor Module for Drupal 6.x 25 * 26 * This module allows Drupal to replace textarea fields with FCKeditor. 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 * Guess the absolute server path to the document root 35 * Usually it should return $_SERVER['DOCUMENT_ROOT'] 36 * 37 * @todo Improve me!! 38 * Returns absolute path or false on failure 39 * 40 * @return string|boolean 41 */ 42 function fckeditor_get_document_root_full_path() { 43 $found=0; 44 $index_dir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); // {/dir1/dir2/home/drupal}/index.php 45 if (getcwd() == $index_dir) { 46 $found++; 47 } 48 $drupal_dir = base_path(); 49 $index_dir = str_replace('\\', "/", $index_dir); 50 $drupal_dir = str_replace('\\', "/", $drupal_dir); 51 $document_root_dir = $index_dir .'/'. str_repeat('../', substr_count($drupal_dir, '/')-1); 52 $document_root_dir = realpath($document_root_dir); 53 $document_root_dir = rtrim($document_root_dir, '/\\'); 54 if ($document_root_dir == $_SERVER['DOCUMENT_ROOT']) { 55 $found++; 56 } 57 $document_root_dir = str_replace('\\', '/', $document_root_dir); 58 59 if ($document_root_dir != '') { 60 $found++; 61 } 62 if (file_exists($document_root_dir)) { 63 $found++; 64 } 65 if (file_exists($document_root_dir . base_path() .'includes/bootstrap.inc')) { 66 $found++; 67 } 68 69 if ($found >= 3) { 70 return $document_root_dir; 71 } 72 else{ 73 return FALSE; 74 } 75 } 76 77 /** 78 * Emulates the asp Server.mapPath function. 79 * Given an url path return the physical directory that it corresponds to. 80 * 81 * Returns absolute path or false on failure 82 * 83 * @param string $path 84 * @return @return string|boolean 85 */ 86 function fckeditor_resolve_url($path) { 87 if (function_exists('apache_lookup_uri')) { 88 $info = @apache_lookup_uri($path); 89 if (!$info) { 90 return FALSE; 91 } 92 return $info->filename . $info->path_info ; 93 } 94 95 $document_root = fckeditor_get_document_root_full_path(); 96 if ($document_root !== FALSE) { 97 return $document_root . $path; 98 } 99 100 return FALSE; 101 } 102 103 function fckeditor_load_toolbar_options() { 104 $arr = array(); 105 $module_drupal_path = drupal_get_path('module', 'fckeditor'); 106 $editor_local_path = fckeditor_path(TRUE); 107 $fckconfig_js = $editor_local_path .'/fckconfig.js'; 108 $fckeditor_config_js = $module_drupal_path .'/fckeditor.config.js'; 109 if (file_exists($fckconfig_js) && is_readable($fckconfig_js)) { 110 $fp = @fopen($fckconfig_js, "r"); 111 if ($fp) { 112 while (!feof($fp)) { 113 $line = fgets($fp, 1024); 114 $matches = array(); 115 if (preg_match('/FCKConfig\.ToolbarSets\[("|\')(.*?)\\1\]/i', $line, $matches)) { 116 $arr[$matches[2]] = drupal_ucfirst($matches[2]); 117 } 118 } 119 fclose($fp); 120 } 121 } 122 if (file_exists($fckeditor_config_js) && is_readable($fckeditor_config_js)) { 123 $fp = @fopen($fckeditor_config_js, "r"); 124 if ($fp) { 125 while (!feof($fp)) { 126 $line = fgets($fp, 1024); 127 $matches = array(); 128 if (preg_match('/FCKConfig\.ToolbarSets\[("|\')(.*?)\\1\]/i', $line, $matches)) { 129 $arr[$matches[2]] = drupal_ucfirst($matches[2]); 130 } 131 } 132 fclose($fp); 133 } 134 } 135 136 //oops, we have no information about toolbars, let's use hardcoded array 137 if (empty($arr)) { 138 $arr = array( 139 'Basic' => 'Basic', 140 'Default' => 'Default', 141 ); 142 } 143 asort($arr); 144 145 return $arr; 146 } 147 148 function fckeditor_load_skin_options() { 149 $arr = array(); 150 $editor_local_path = fckeditor_path(TRUE); 151 $skin_dir = $editor_local_path .'/editor/skins'; 152 if (is_dir($skin_dir)) { 153 $dh = @opendir($skin_dir); 154 if (FALSE !== $dh) { 155 while (($file = readdir($dh)) !== FALSE ) { 156 if (in_array($file, array(".", "..", "CVS", ".svn"))) { 157 continue; 158 } 159 if (is_dir($skin_dir . DIRECTORY_SEPARATOR . $file)) { 160 $arr[$file] = drupal_ucfirst($file); 161 } 162 } 163 closedir( $dh ); 164 } 165 } 166 167 //oops, we have no information about skins, let's use only default 168 if (empty($arr)) { 169 $arr = array( 170 'default' => 'Default', 171 ); 172 } 173 asort($arr); 174 175 return $arr; 176 } 177 178 function fckeditor_load_lang_options() { 179 $arr = array(); 180 $editor_local_path = fckeditor_path(TRUE); 181 $lang_dir = $editor_local_path .'/editor/lang'; 182 if (is_dir($lang_dir)) { 183 $dh = @opendir($lang_dir); 184 if (FALSE !== $dh ) { 185 while (($file = readdir($dh)) !== FALSE) { 186 if (in_array($file, array(".", "..", "CVS", ".svn"))) { 187 continue; 188 } 189 $matches = array(); 190 if (is_file($lang_dir . DIRECTORY_SEPARATOR . $file) && preg_match('/^(.*?)\.js$/', $file, $matches)) { 191 $lang = $matches[1]; 192 $arr[$lang] = drupal_strtoupper($lang); 193 } 194 } 195 closedir( $dh ); 196 } 197 } 198 199 //oops, we have no information about languages, let's use those available in FCKeditor 2.4.3 200 if (empty($arr)) { 201 $arr = array( 202 'af' => 'Afrikaans', 203 'ar' => 'Arabic', 204 'bg' => 'Bulgarian', 205 'bn' => 'Bengali/Bangla', 206 'bs' => 'Bosnian', 207 'ca' => 'Catalan', 208 'cs' => 'Czech', 209 'da' => 'Danish', 210 'de' => 'German', 211 'el' => 'Greek', 212 'en' => 'English', 213 'en-au' => 'English (Australia)', 214 'en-ca' => 'English (Canadian)', 215 'en-uk' => 'English (United Kingdom)', 216 'eo' => 'Esperanto', 217 'es' => 'Spanish', 218 'et' => 'Estonian', 219 'eu' => 'Basque', 220 'fa' => 'Persian', 221 'fi' => 'Finnish', 222 'fo' => 'Faroese', 223 'fr' => 'French', 224 'gl' => 'Galician', 225 'he' => 'Hebrew', 226 'hi' => 'Hindi', 227 'hr' => 'Croatian', 228 'hu' => 'Hungarian', 229 'it' => 'Italian', 230 'ja' => 'Japanese', 231 'km' => 'Khmer', 232 'ko' => 'Korean', 233 'lt' => 'Lithuanian', 234 'lv' => 'Latvian', 235 'mn' => 'Mongolian', 236 'ms' => 'Malay', 237 'nb' => 'Norwegian Bokmal', 238 'nl' => 'Dutch', 239 'no' => 'Norwegian', 240 'pl' => 'Polish', 241 'pt' => 'Portuguese (Portugal)', 242 'pt-br' => 'Portuguese (Brazil)', 243 'ro' => 'Romanian', 244 'ru' => 'Russian', 245 'sk' => 'Slovak', 246 'sl' => 'Slovenian', 247 'sr' => 'Serbian (Cyrillic)', 248 'sr-latn' => 'Serbian (Latin)', 249 'sv' => 'Swedish', 250 'th' => 'Thai', 251 'tr' => 'Turkish', 252 'uk' => 'Ukrainian', 253 'vi' => 'Vietnamese', 254 'zh' => 'Chinese Traditional', 255 'zh-cn' => 'Chinese Simplified', 256 ); 257 } 258 259 asort($arr); 260 261 return $arr; 262 } 263 264 /** 265 * Determines if the supplied text doesn't contain 266 * any HTML 267 * 268 * @param string $text 269 * @return bool 270 */ 271 function fckeditor_is_plaintext($text) { 272 if (strpos($text, '<p>') !== FALSE) { 273 return FALSE; 274 } 275 276 if (strpos($text, '<div>') !== FALSE) { 277 return FALSE; 278 } 279 280 if (strpos($text, '<br') !== FALSE) { 281 return FALSE; 282 } 283 284 return TRUE; 285 }
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 |