ckeditor.lib.inc 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. <?php
  2. /**
  3. * CKEditor - The text editor for the Internet - http://ckeditor.com
  4. * Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
  5. *
  6. * == BEGIN LICENSE ==
  7. *
  8. * Licensed under the terms of any of the following licenses of your
  9. * choice:
  10. *
  11. * - GNU General Public License Version 2 or later (the "GPL")
  12. * http://www.gnu.org/licenses/gpl.html
  13. *
  14. * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  15. * http://www.gnu.org/licenses/lgpl.html
  16. *
  17. * - Mozilla Public License Version 1.1 or later (the "MPL")
  18. * http://www.mozilla.org/MPL/MPL-1.1.html
  19. *
  20. * == END LICENSE ==
  21. *
  22. * @file
  23. * CKEditor Module for Drupal 7.x
  24. *
  25. * This module allows Drupal to replace textarea fields with CKEditor.
  26. *
  27. * CKEditor is an online rich text editor that can be embedded inside web pages.
  28. * It is a WYSIWYG (What You See Is What You Get) editor which means that the
  29. * text edited in it looks as similar as possible to the results end users will
  30. * see after the document gets published. It brings to the Web popular editing
  31. * features found in desktop word processors such as Microsoft Word and
  32. * OpenOffice.org Writer. CKEditor is truly lightweight and does not require any
  33. * kind of installation on the client computer.
  34. */
  35. /**
  36. * Guess the absolute server path to the document root
  37. * Usually it should return $_SERVER['DOCUMENT_ROOT']
  38. *
  39. * @todo Improve me!!
  40. * Returns absolute path or false on failure
  41. *
  42. * @return string|boolean
  43. */
  44. function ckeditor_get_document_root_full_path() {
  45. $found = 0;
  46. $index_dir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); // {/dir1/dir2/home/drupal}/index.php
  47. if (getcwd() == $index_dir) {
  48. $found++;
  49. }
  50. $drupal_dir = base_path();
  51. $index_dir = str_replace('\\', "/", $index_dir);
  52. $drupal_dir = str_replace('\\', "/", $drupal_dir);
  53. $document_root_dir = $index_dir . '/' . str_repeat('../', substr_count($drupal_dir, '/') - 1);
  54. $document_root_dir = realpath($document_root_dir);
  55. $document_root_dir = rtrim($document_root_dir, '/\\');
  56. if ($document_root_dir == $_SERVER['DOCUMENT_ROOT']) {
  57. $found++;
  58. }
  59. $document_root_dir = str_replace('\\', '/', $document_root_dir);
  60. if ($document_root_dir != '') {
  61. $found++;
  62. }
  63. if (file_exists($document_root_dir)) {
  64. $found++;
  65. }
  66. if (file_exists($document_root_dir . base_path() . 'includes/bootstrap.inc')) {
  67. $found++;
  68. }
  69. if ($found >= 3) {
  70. return $document_root_dir;
  71. }
  72. else {
  73. return FALSE;
  74. }
  75. }
  76. /**
  77. * Emulates the asp Server.mapPath function.
  78. * Given an url path return the physical directory that it corresponds to.
  79. *
  80. * Returns absolute path or false on failure
  81. *
  82. * @param string $path
  83. * @return string|boolean
  84. */
  85. function ckeditor_resolve_url($path) {
  86. if (function_exists('apache_lookup_uri')) {
  87. $info = @apache_lookup_uri($path);
  88. if (!$info) {
  89. return FALSE;
  90. }
  91. return $info->filename . $info->path_info;
  92. }
  93. $document_root = ckeditor_get_document_root_full_path();
  94. if ($document_root !== FALSE) {
  95. return $document_root . $path;
  96. }
  97. return FALSE;
  98. }
  99. /**
  100. * List of configured CKEditor toolbars
  101. *
  102. * @return array
  103. */
  104. function ckeditor_load_toolbar_options() {
  105. $arr = array('Basic' => 'Basic', 'Full' => 'Full');
  106. $module_drupal_path = drupal_get_path('module', 'ckeditor');
  107. $editor_local_path = ckeditor_path('local');
  108. $ckconfig_js = $editor_local_path . '/config.js';
  109. $ckeditor_config_js = $module_drupal_path . '/ckeditor.config.js';
  110. if ($editor_local_path != '<URL>' && file_exists($ckconfig_js) && is_readable($ckconfig_js)) {
  111. $fp = @fopen($ckconfig_js, "r");
  112. if ($fp) {
  113. while (!feof($fp)) {
  114. $line = fgets($fp, 1024);
  115. $matches = array();
  116. if (preg_match('/config.toolbar_([a-z0-9_]+)/i', $line, $matches)) {
  117. $arr[$matches[1]] = drupal_ucfirst($matches[1]);
  118. }
  119. }
  120. fclose($fp);
  121. }
  122. }
  123. if (file_exists($ckeditor_config_js) && is_readable($ckeditor_config_js)) {
  124. $fp = @fopen($ckeditor_config_js, "r");
  125. if ($fp) {
  126. while (!feof($fp)) {
  127. $line = fgets($fp, 1024);
  128. $matches = array();
  129. if (preg_match('/config.toolbar_([a-z0-9_]+)/i', $line, $matches)) {
  130. $arr[$matches[1]] = drupal_ucfirst($matches[1]);
  131. }
  132. }
  133. fclose($fp);
  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. return $arr;
  145. }
  146. /**
  147. * List of installed CKEditor skins
  148. *
  149. * @return array
  150. */
  151. function ckeditor_load_skin_options() {
  152. $arr = array();
  153. $editor_local_path = ckeditor_path('local');
  154. $skin_dir = $editor_local_path . '/skins';
  155. if ($editor_local_path != '<URL>' && is_dir($skin_dir)) {
  156. $dh = @opendir($skin_dir);
  157. if (FALSE !== $dh) {
  158. while (($file = readdir($dh)) !== FALSE) {
  159. if (in_array($file, array(".", "..", "CVS", ".svn"))) {
  160. continue;
  161. }
  162. if (is_dir($skin_dir . DIRECTORY_SEPARATOR . $file)) {
  163. $arr[$file] = drupal_ucfirst($file);
  164. }
  165. }
  166. closedir($dh);
  167. }
  168. }
  169. //oops, we have no information about skins, let's use only default
  170. if (empty($arr)) {
  171. $arr = array(
  172. 'moono' => 'Moono',
  173. 'kama' => 'Kama'
  174. );
  175. }
  176. asort($arr);
  177. return $arr;
  178. }
  179. /**
  180. * Return default skin for CKEditor
  181. *
  182. * @return string
  183. */
  184. function ckeditor_default_skin() {
  185. $skin_options = ckeditor_load_skin_options();
  186. if (array_key_exists('moono', $skin_options)) {
  187. return 'moono';
  188. }
  189. if (array_key_exists('kama', $skin_options)) {
  190. return 'kama';
  191. }
  192. reset($skin_options);
  193. //if any default theme not exists select first from the list
  194. return key($skin_options);
  195. }
  196. /**
  197. * List of installed CKEditor languages
  198. *
  199. * @return array
  200. */
  201. function ckeditor_load_lang_options() {
  202. $arr = array();
  203. $editor_local_path = ckeditor_path('local');
  204. $lang_file = $editor_local_path . '/lang/_languages.js';
  205. if ($editor_local_path != '<URL>' && file_exists($lang_file)) {
  206. $f = fopen($lang_file, 'r');
  207. $file = fread($f, filesize($lang_file));
  208. $tmp = explode('{', $file);
  209. if (isset($tmp[2])) {
  210. $tmp = explode('}', $tmp[2]);
  211. }
  212. $langs = explode(',', $tmp[0]);
  213. foreach ($langs AS $key => $lang) {
  214. preg_match("/'?(\w+-?\w+)'?:'([\w\s\(\)]+)'/i", $lang, $matches);
  215. if (isset($matches[1]) && isset($matches[2]))
  216. $arr[$matches[1]] = $matches[2];
  217. }
  218. }
  219. //oops, we have no information about languages, let's use those available in CKEditor 2.4.3
  220. if (empty($arr)) {
  221. $arr = array(
  222. 'af' => 'Afrikaans',
  223. 'ar' => 'Arabic',
  224. 'bg' => 'Bulgarian',
  225. 'bn' => 'Bengali/Bangla',
  226. 'bs' => 'Bosnian',
  227. 'ca' => 'Catalan',
  228. 'cs' => 'Czech',
  229. 'da' => 'Danish',
  230. 'de' => 'German',
  231. 'el' => 'Greek',
  232. 'en' => 'English',
  233. 'en-au' => 'English (Australia)',
  234. 'en-ca' => 'English (Canadian)',
  235. 'en-uk' => 'English (United Kingdom)',
  236. 'eo' => 'Esperanto',
  237. 'es' => 'Spanish',
  238. 'et' => 'Estonian',
  239. 'eu' => 'Basque',
  240. 'fa' => 'Persian',
  241. 'fi' => 'Finnish',
  242. 'fo' => 'Faroese',
  243. 'fr' => 'French',
  244. 'gl' => 'Galician',
  245. 'he' => 'Hebrew',
  246. 'hi' => 'Hindi',
  247. 'hr' => 'Croatian',
  248. 'hu' => 'Hungarian',
  249. 'it' => 'Italian',
  250. 'ja' => 'Japanese',
  251. 'km' => 'Khmer',
  252. 'ko' => 'Korean',
  253. 'lt' => 'Lithuanian',
  254. 'lv' => 'Latvian',
  255. 'mn' => 'Mongolian',
  256. 'ms' => 'Malay',
  257. 'nb' => 'Norwegian Bokmal',
  258. 'nl' => 'Dutch',
  259. 'no' => 'Norwegian',
  260. 'pl' => 'Polish',
  261. 'pt' => 'Portuguese (Portugal)',
  262. 'pt-br' => 'Portuguese (Brazil)',
  263. 'ro' => 'Romanian',
  264. 'ru' => 'Russian',
  265. 'sk' => 'Slovak',
  266. 'sl' => 'Slovenian',
  267. 'sr' => 'Serbian (Cyrillic)',
  268. 'sr-latn' => 'Serbian (Latin)',
  269. 'sv' => 'Swedish',
  270. 'th' => 'Thai',
  271. 'tr' => 'Turkish',
  272. 'uk' => 'Ukrainian',
  273. 'vi' => 'Vietnamese',
  274. 'zh' => 'Chinese Traditional',
  275. 'zh-cn' => 'Chinese Simplified',
  276. );
  277. }
  278. asort($arr);
  279. return $arr;
  280. }
  281. /**
  282. * Get the language locale code supported by Scayt for the specified language
  283. */
  284. function ckeditor_scayt_langcode($lang) {
  285. $scayt_langs = array(
  286. 'en' => 'en_US',
  287. 'es' => 'es_ES',
  288. 'fr' => 'fr_FR',
  289. 'de' => 'de_DE',
  290. 'it' => 'it_IT',
  291. 'el' => 'el_EL',
  292. 'pt' => 'pt_PT',
  293. 'da' => 'da_DA',
  294. 'sv' => 'sv_SE',
  295. 'nl' => 'nl_NL',
  296. 'nb' => 'no_NO',
  297. 'fi' => 'fi_FI',
  298. );
  299. if (array_key_exists($lang, $scayt_langs)) {
  300. return $scayt_langs[$lang];
  301. }
  302. $default = language_default();
  303. $default = $default->language;
  304. if (array_key_exists($default, $scayt_langs)) {
  305. return $scayt_langs[$default];
  306. }
  307. return 'en_US';
  308. }
  309. /**
  310. * List of CKEditor plugins.
  311. *
  312. * @param boolean $render
  313. * Whether to generate plugin paths. Default to FALSE.
  314. * @return array
  315. */
  316. function ckeditor_load_plugins($render = FALSE) {
  317. $plugins = module_invoke_all('ckeditor_plugin');
  318. // [#2159403] introduced a slight change in CKEditor API, expecting the path
  319. // to a plugin returned by hook_ckeditor_plugin() to be a full URL. This
  320. // breaks backward compatibility for external plugins, so we're fixing it
  321. // below.
  322. foreach ($plugins as $i => $plugin) {
  323. if (strpos($plugin['path'], '%') !== 0 && !preg_match('|^(http(s)?:)?\/?\/|i', $plugin['path'])) {
  324. $plugins[$i]['path'] = '%base_path%' . $plugin['path'];
  325. }
  326. }
  327. drupal_alter('ckeditor_plugin', $plugins);
  328. ksort($plugins);
  329. if ($render) {
  330. $plugins = ckeditor_plugins_render($plugins);
  331. }
  332. return $plugins;
  333. }
  334. /**
  335. * Render CKEditor plugins path
  336. */
  337. function ckeditor_plugins_render($plugins) {
  338. $render = array();
  339. $render["%base_path%"] = ckeditor_base_path('relative') . '/';
  340. $render["%editor_path%"] = ckeditor_path('relative') . '/';
  341. $render["%module_path%"] = ckeditor_module_path('relative') . '/';
  342. $render["%plugin_dir%"] = $render["%module_path%"] . 'plugins/';
  343. $render["%plugin_dir_extra%"] = ckeditor_plugins_path('relative') . '/';
  344. foreach ((array) $plugins as $i => $plugin) {
  345. $plugins[$i]['path'] = str_replace(array_keys($render), array_values($render), $plugin['path']);
  346. }
  347. return $plugins;
  348. }
  349. /**
  350. * Get default ckeditor settings
  351. *
  352. * @return array
  353. */
  354. function ckeditor_user_get_setting_default() {
  355. $default = array(
  356. 'default' => 't',
  357. 'show_toggle' => 't',
  358. 'width' => '100%',
  359. 'lang' => 'en',
  360. 'auto_lang' => 't',
  361. );
  362. // Allow other modules to alter the default settings.
  363. drupal_alter('ckeditor_default_settings', $default);
  364. return $default;
  365. }
  366. /**
  367. * Return CKEditor settings
  368. *
  369. * @param object $user
  370. * @param object $profile
  371. * @param string $setting
  372. * @return array
  373. */
  374. function ckeditor_user_get_setting($user, $profile, $setting) {
  375. $default = ckeditor_user_get_setting_default();
  376. if (user_access('customize ckeditor')) {
  377. $status = isset($user->data['ckeditor_' . $setting]) ? $user->data['ckeditor_' . $setting] : (isset($profile->settings[$setting]) ? $profile->settings[$setting] : $default[$setting]);
  378. }
  379. else {
  380. $status = isset($profile->settings[$setting]) ? $profile->settings[$setting] : $default[$setting];
  381. }
  382. return $status;
  383. }
  384. /**
  385. * Return CKEditor profile by input format
  386. *
  387. * @param string $input_format
  388. * @return object|boolean
  389. */
  390. function ckeditor_get_profile($input_format) {
  391. $select = db_select('ckeditor_settings', 's');
  392. $select->join('ckeditor_input_format', 'f', 'f.name = s.name');
  393. $result = $select->fields('s', array("name"))->condition('f.format', $input_format)->condition('f.name', 'CKEditor Global Profile', '<>')->range(0, 1)->execute()->fetchAssoc();
  394. if ($result && $profile = ckeditor_profile_load($result['name'])) {
  395. return $profile;
  396. }
  397. return FALSE;
  398. }
  399. /**
  400. * Return CKEditor profile list
  401. */
  402. function ckeditor_profile_input_formats() {
  403. $select = db_select('ckeditor_settings', 's');
  404. $select->join('ckeditor_input_format', 'f', 'f.name = s.name');
  405. $result = $select->fields('s', array("name"))->fields('f', array("format"))->execute();
  406. $list = array();
  407. while ($row = $result->fetchAssoc()) {
  408. if (!isset($row['name'])) {
  409. $list[$row['name']] = array();
  410. }
  411. $list[$row['name']][] = $row['format'];
  412. }
  413. return $list;
  414. }
  415. /**
  416. * Search and return CKEditor plugin path
  417. *
  418. * @return string
  419. */
  420. function _ckeditor_script_path() {
  421. $jspath = '';
  422. $module_path = drupal_get_path('module', 'ckeditor');
  423. if (file_exists($module_path . '/ckeditor/ckeditor.js')) {
  424. $jspath = '%m/ckeditor';
  425. }
  426. elseif (file_exists($module_path . '/ckeditor/ckeditor/ckeditor.js')) {
  427. $jspath = '%m/ckeditor/ckeditor';
  428. }
  429. elseif (file_exists(ckeditor_library_path('url') . '/ckeditor/ckeditor.js')) {
  430. $jspath = '%l/ckeditor';
  431. }
  432. return $jspath;
  433. }
  434. /**
  435. * Determines whether the CKEditor sources are present
  436. *
  437. * It checks if ckeditor.js is present.
  438. *
  439. * This function is used by ckeditor_requirements()
  440. *
  441. * @return boolean True if CKEditor is installed
  442. */
  443. function _ckeditor_requirements_isinstalled() {
  444. $editor_path = ckeditor_path('local');
  445. if ($editor_path == '<URL>')
  446. return TRUE;
  447. $jspath = $editor_path . '/ckeditor.js';
  448. $jsp = file_exists($jspath);
  449. if (!$jsp && ($editor_path = _ckeditor_script_path())) {
  450. $result = db_select('ckeditor_settings', 's')->fields('s')->condition('name', 'CKEditor Global Profile')->execute()->fetchAssoc();
  451. if ($result) {
  452. $result['settings'] = unserialize($result['settings']);
  453. $result['settings']['ckeditor_path'] = $editor_path;
  454. $result['settings'] = serialize($result['settings']);
  455. db_update('ckeditor_settings')->fields(array("settings" => $result['settings']))->condition('name', 'CKEditor Global Profile')->execute();
  456. $jsp = TRUE;
  457. ckeditor_path('local', TRUE);
  458. }
  459. }
  460. return $jsp;
  461. }
  462. /**
  463. * Compile settings of all profiles at returns is as array
  464. *
  465. * @param string $input_format
  466. * @param boolean $clear
  467. * @return array
  468. */
  469. function ckeditor_profiles_compile($input_format = FALSE, $clear = FALSE) {
  470. static $compiled = FALSE;
  471. static $_ckeditor_compiled = array();
  472. if ($clear !== FALSE && $compiled !== FALSE) {
  473. $compiled = FALSE;
  474. }
  475. if ($compiled === TRUE) {
  476. return ( $input_format === FALSE ) ? $_ckeditor_compiled : ( isset($_ckeditor_compiled[$input_format]) ? $_ckeditor_compiled[$input_format] : array() );
  477. }
  478. $global_profile = ckeditor_profile_load('CKEditor Global Profile');
  479. $profiles_list = ckeditor_profile_input_formats();
  480. foreach ($profiles_list AS $_profile => $_inputs) {
  481. $profile = ckeditor_profile_load($_profile);
  482. $setting = ckeditor_profile_settings_compile($global_profile, $profile);
  483. foreach ($_inputs AS $_input) {
  484. $_ckeditor_compiled[$_input] = $setting;
  485. }
  486. }
  487. $compiled = TRUE;
  488. return ( $input_format === FALSE ) ? $_ckeditor_compiled : $_ckeditor_compiled[$input_format];
  489. }
  490. /**
  491. * Compile settings of profile
  492. *
  493. * @param object $global_profile
  494. * @param object $profile
  495. * @return array
  496. */
  497. function ckeditor_profile_settings_compile($global_profile, $profile) {
  498. global $user, $language, $theme;
  499. $current_theme = variable_get('theme_default', $theme);
  500. $settings = array();
  501. $conf = $profile->settings;
  502. $profile_name = $profile->name;
  503. if (user_access('customize ckeditor')) {
  504. foreach (array('default', 'show_toggle', 'width', 'lang', 'auto_lang') as $setting) {
  505. $conf[$setting] = ckeditor_user_get_setting($user, $profile, $setting);
  506. }
  507. }
  508. if (!isset($conf['ss'])) {
  509. $conf['ss'] = 2;
  510. }
  511. $themepath = drupal_get_path('theme', $current_theme) . '/';
  512. $host = base_path();
  513. // setting some variables
  514. $module_drupal_path = ckeditor_module_path('relative');
  515. $module_drupal_local_path = ckeditor_module_path('local');
  516. $editor_path = ckeditor_path('relative');
  517. $editor_local_path = ckeditor_path('local');
  518. $toolbar = $conf['toolbar'];
  519. if (!empty($conf['theme_config_js']) && $conf['theme_config_js'] == 't' && file_exists($themepath . 'ckeditor.config.js')) {
  520. $ckeditor_config_path = $host . $themepath . 'ckeditor.config.js?' . @filemtime($themepath . 'ckeditor.config.js');
  521. }
  522. else {
  523. $ckeditor_config_path = $module_drupal_path . "/ckeditor.config.js?" . @filemtime($module_drupal_path . "/ckeditor.config.js");
  524. }
  525. $settings['customConfig'] = $ckeditor_config_path;
  526. $settings['defaultLanguage'] = $conf['lang'];
  527. $settings['toolbar'] = $toolbar;
  528. $settings['enterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['enter_mode']));
  529. $settings['shiftEnterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['shift_enter_mode']));
  530. $settings['toolbarStartupExpanded'] = ( $conf['expand'] == 't' );
  531. if ($conf['expand'] == 'f') {
  532. $settings['toolbarCanCollapse'] = true;
  533. }
  534. $settings['width'] = $conf['width'];
  535. //check if skin exists, if not select default one
  536. if (isset($global_profile->settings['skin']) && file_exists($editor_local_path . '/skins/' . $global_profile->settings['skin'])) {
  537. $settings['skin'] = $global_profile->settings['skin'];
  538. }
  539. else {
  540. $settings['skin'] = ckeditor_default_skin();
  541. }
  542. $settings['format_tags'] = $conf['font_format'];
  543. $settings['show_toggle'] = $conf['show_toggle'];
  544. $settings['default'] = $conf['default'];
  545. if (!empty($conf['allowed_content']) && $conf['allowed_content'] === 'f') {
  546. $settings['allowedContent'] = true;
  547. }
  548. elseif (!empty($conf['extraAllowedContent'])) {
  549. $settings['extraAllowedContent'] = $conf['extraAllowedContent'];
  550. }
  551. $settings['ss'] = $conf['ss'];
  552. if (isset($conf['language_direction'])) {
  553. switch ($conf['language_direction']) {
  554. case 'default':
  555. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
  556. $settings['contentsLangDirection'] = 'rtl';
  557. }
  558. break;
  559. case 'ltr':
  560. $settings['contentsLangDirection'] = 'ltr';
  561. break;
  562. case 'rtl':
  563. $settings['contentsLangDirection'] = 'rtl';
  564. break;
  565. }
  566. }
  567. if (isset($conf['loadPlugins'])) {
  568. $settings['loadPlugins'] = ckeditor_plugins_render($conf['loadPlugins']);
  569. }
  570. else {
  571. $settings['loadPlugins'] = array();
  572. }
  573. //add support for divarea plugin from CKE4
  574. if (isset($conf['use_divarea']) && $conf['use_divarea'] == 't' && $editor_local_path != '<URL>' && file_exists($editor_local_path . '/plugins/divarea/plugin.js')) {
  575. $settings['loadPlugins']['divarea'] = array('name' => 'divarea', 'path' => $editor_path . '/plugins/divarea/', 'buttons' => FALSE, 'default' => 'f');
  576. }
  577. if (isset($conf['html_entities']) && $conf['html_entities'] == 'f') {
  578. $settings['entities'] = FALSE;
  579. $settings['entities_greek'] = FALSE;
  580. $settings['entities_latin'] = FALSE;
  581. }
  582. if (isset($conf['scayt_autoStartup']) && $conf['scayt_autoStartup'] == 't') {
  583. $settings['scayt_autoStartup'] = TRUE;
  584. }
  585. else {
  586. $settings['scayt_autoStartup'] = FALSE;
  587. }
  588. if ($conf['auto_lang'] == "f") {
  589. $settings['language'] = $conf['lang'];
  590. //[#1473010]
  591. $settings['scayt_sLang'] = ckeditor_scayt_langcode($conf['lang']);
  592. }
  593. if (isset($conf['forcePasteAsPlainText']) && $conf['forcePasteAsPlainText'] == 't') {
  594. $settings['forcePasteAsPlainText'] = TRUE;
  595. }
  596. if (isset($conf['custom_formatting']) && $conf['custom_formatting'] == 't') {
  597. foreach ($conf['formatting']['custom_formatting_options'] as $k => $v) {
  598. if ($v === 0) {
  599. $conf['formatting']['custom_formatting_options'][$k] = FALSE;
  600. }
  601. else {
  602. $conf['formatting']['custom_formatting_options'][$k] = TRUE;
  603. }
  604. }
  605. $settings['output_pre_indent'] = $conf['formatting']['custom_formatting_options']['pre_indent'];
  606. unset($conf['formatting']['custom_formatting_options']['pre_indent']);
  607. $settings['custom_formatting'] = $conf['formatting']['custom_formatting_options'];
  608. }
  609. // add code for filebrowser for users that have access
  610. $filebrowser = !empty($conf['filebrowser']) ? $conf['filebrowser'] : 'none';
  611. $filebrowser_image = !empty($conf['filebrowser_image']) ? $conf['filebrowser_image'] : $filebrowser;
  612. $filebrowser_flash = !empty($conf['filebrowser_flash']) ? $conf['filebrowser_flash'] : $filebrowser;
  613. if ($filebrowser == 'imce' && !module_exists('imce')) {
  614. $filebrowser = 'none';
  615. }
  616. if ($filebrowser == 'elfinder' && !module_exists('elfinder')) {
  617. $filebrowser = 'none';
  618. }
  619. /* MODULES NOT PORTED TO D7
  620. if ($filebrowser == 'tinybrowser' && !module_exists('tinybrowser')) {
  621. $filebrowser = 'none';
  622. }
  623. if ($filebrowser == 'ib' && !module_exists('imagebrowser')) {
  624. $filebrowser = 'none';
  625. }
  626. if ($filebrowser == 'webfm' && !module_exists('webfm_popup')) {
  627. $filebrowser = 'none';
  628. }
  629. */
  630. if ($filebrowser_image != $filebrowser) {
  631. if ($filebrowser_image == 'imce' && !module_exists('imce')) {
  632. $filebrowser_image = $filebrowser;
  633. }
  634. if ($filebrowser_image == 'elfinder' && !module_exists('elfinder')) {
  635. $filebrowser_image = $filebrowser;
  636. }
  637. /* MODULES NOT PORTED TO D7
  638. if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) {
  639. $filebrowser_image = $filebrowser;
  640. }
  641. if ($filebrowser_image == 'ib' && !module_exists('imagebrowser')) {
  642. $filebrowser_image = $filebrowser;
  643. }
  644. if ($filebrowser_image == 'webfm' && !module_exists('webfm_popup')) {
  645. $filebrowser_image = $filebrowser;
  646. }
  647. */
  648. }
  649. if ($filebrowser_flash != $filebrowser) {
  650. if ($filebrowser_flash == 'imce' && !module_exists('imce')) {
  651. $filebrowser_flash = $filebrowser;
  652. }
  653. if ($filebrowser_image == 'elfinder' && !module_exists('elfinder')) {
  654. $filebrowser_flash = $filebrowser;
  655. }
  656. /* MODULES NOT PORTED TO D7
  657. if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) {
  658. $filebrowser_flash = $filebrowser;
  659. }
  660. if ($filebrowser_flash == 'ib' && !module_exists('imagebrowser')) {
  661. $filebrowser_flash = $filebrowser;
  662. }
  663. if ($filebrowser_flash == 'webfm' && !module_exists('webfm_popup')) {
  664. $filebrowser_flash = $filebrowser;
  665. }
  666. */
  667. }
  668. if ($filebrowser == 'ckfinder' || $filebrowser_image == 'ckfinder' || $filebrowser_flash == 'ckfinder') {
  669. if (user_access('allow CKFinder file uploads')) {
  670. if (!empty($profile->settings['UserFilesPath'])) {
  671. $_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = strtr($profile->settings['UserFilesPath'], array("%f" => variable_get('file_public_path', conf_path() . '/files'), "%u" => $user->uid, "%b" => $host, "%n" => $user->name));
  672. }
  673. else {
  674. $_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = strtr('%b%f/', array("%f" => variable_get('file_public_path', conf_path() . '/files'), "%u" => $user->uid, "%b" => $host, "%n" => $user->name));
  675. }
  676. if (!empty($profile->settings['UserFilesAbsolutePath'])) {
  677. $_SESSION['ckeditor'][$profile_name]['UserFilesAbsolutePath'] = strtr($profile->settings['UserFilesAbsolutePath'], array("%f" => variable_get('file_public_path', conf_path() . '/files'), "%u" => $user->uid, "%b" => base_path(), "%d" => ckeditor_get_document_root_full_path(), "%n" => $user->name));
  678. }
  679. else {
  680. $_SESSION['ckeditor'][$profile_name]['UserFilesAbsolutePath'] = strtr('%d%b%f/', array("%f" => variable_get('file_public_path', conf_path() . '/files'), "%u" => $user->uid, "%b" => base_path(), "%d" => ckeditor_get_document_root_full_path(), "%n" => $user->name));
  681. }
  682. if (variable_get('file_default_scheme', '') == 'private') {
  683. $private_dir = isset($global_profile->settings['private_dir']) ? trim($global_profile->settings['private_dir'], '/') : '';
  684. if (!empty($private_dir)) {
  685. $private_dir = strtr($private_dir, array('%u' => $user->uid, '%n' => $user->name));
  686. $_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = url('system/files') . '/' . $private_dir . '/';
  687. $private_upload_path = file_uri_target('private://' . variable_get('file_private_path', '')) . '/' . $private_dir;
  688. }
  689. else {
  690. $_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = url('system/files') . '/';
  691. $private_upload_path = file_uri_target('private://' . variable_get('file_private_path', ''));
  692. }
  693. //add '/' to beginning of path if necessary
  694. if (strpos(variable_get('file_private_path', ''), '/') === 0 && $private_upload_path[0] != '/') {
  695. $private_upload_path = '/' . $private_upload_path;
  696. }
  697. //check if CKEditor private dir exists and create it if not
  698. if ($private_dir && !is_dir($private_upload_path)) {
  699. mkdir($private_upload_path, 0755, TRUE);
  700. }
  701. $_SESSION['ckeditor'][$profile_name]['UserFilesAbsolutePath'] = drupal_realpath($private_upload_path) . '/';
  702. }
  703. }
  704. }
  705. /* MODULES NOT PORTED TO D7
  706. if (in_array('tinybrowser', array($filebrowser, $filebrowser_image, $filebrowser_flash))) {
  707. $popup_win_size = variable_get('tinybrowser_popup_window_size', '770x480');
  708. if (!preg_match('#\d+x\d+#is', $popup_win_size)) {
  709. $popup_win_size = '770x480';
  710. }
  711. $popup_win_size = trim($popup_win_size);
  712. $popup_win_size = strtolower($popup_win_size);
  713. $win_size = split('x', $popup_win_size);
  714. }
  715. */
  716. switch ($filebrowser) {
  717. case 'ckfinder':
  718. if (user_access('allow CKFinder file uploads')) {
  719. $ckfinder_full_path = ckfinder_path('relative');
  720. $settings['filebrowserBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?id=' . $profile_name;
  721. $settings['filebrowserImageBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
  722. $settings['filebrowserFlashBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Flash&id=' . $profile_name;
  723. $settings['filebrowserUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Files&id=' . $profile_name;
  724. $settings['filebrowserImageUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
  725. $settings['filebrowserFlashUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Flash&id=' . $profile_name;
  726. }
  727. break;
  728. case 'imce':
  729. $settings['filebrowserBrowseUrl'] = url('imce', array('query' => array('app' => 'ckeditor|sendto@ckeditor_imceSendTo|')));
  730. break;
  731. case 'elfinder':
  732. $settings['filebrowserBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
  733. break;
  734. /* MODULES NOT PORTED TO D7
  735. case 'webfm':
  736. if (user_access('access webfm')) {
  737. $settings['filebrowserBrowseUrl'] = $host . "index.php?q=webfm_popup";
  738. }
  739. break;
  740. case 'ib':
  741. if (user_access('browse own images')) {
  742. $settings['filebrowserBrowseUrl'] = $host . "index.php?q=imagebrowser/view/browser&app=ckeditor";
  743. $settings['filebrowserWindowWidth'] = 700;
  744. $settings['filebrowserWindowHeight'] = 520;
  745. }
  746. break;
  747. case 'tinybrowser':
  748. $settings['filebrowserBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=file";
  749. $settings['filebrowserWindowWidth'] = (int) $win_size[0] + 15;
  750. $settings['filebrowserWindowHeight'] = (int) $win_size[1] + 15;
  751. break;
  752. */
  753. }
  754. if ($filebrowser_image != $filebrowser) {
  755. switch ($filebrowser_image) {
  756. case 'ckfinder':
  757. if (user_access('allow CKFinder file uploads')) {
  758. $ckfinder_full_path = ckfinder_path('relative');
  759. $settings['filebrowserImageBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
  760. $settings['filebrowserImageUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
  761. }
  762. break;
  763. case 'imce':
  764. $settings['filebrowserImageBrowseUrl'] = url('imce', array('query' => array('app' => 'ckeditor|sendto@ckeditor_imceSendTo|')));
  765. break;
  766. case 'elfinder':
  767. $settings['filebrowserImageBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
  768. break;
  769. /* MODULES NOT PORTED TO D7
  770. case 'webfm':
  771. if (user_access('access webfm')) {
  772. $settings['filebrowserImageBrowseUrl'] = $host . "index.php?q=webfm_popup";
  773. }
  774. break;
  775. case 'ib':
  776. if (user_access('browse own images')) {
  777. $settings['filebrowserImageBrowseUrl'] = $host . "index.php?q=imagebrowser/view/browser&app=ckeditor";
  778. $settings['filebrowserImageWindowWidth'] = 680;
  779. $settings['filebrowserImageWindowHeight'] = 439;
  780. }
  781. break;
  782. case 'tinybrowser':
  783. $settings['filebrowserImageBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=image";
  784. $settings['filebrowserImageWindowWidth'] = (int) $win_size[0] + 15;
  785. $settings['filebrowserImageWindowHeight'] = (int) $win_size[1] + 15;
  786. break;
  787. */
  788. }
  789. }
  790. if ($filebrowser_flash != $filebrowser) {
  791. switch ($filebrowser_flash) {
  792. case 'ckfinder':
  793. if (user_access('allow CKFinder file uploads')) {
  794. $ckfinder_full_path = ckfinder_path('relative');
  795. $settings['filebrowserFlashBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
  796. $settings['filebrowserFlashUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
  797. }
  798. break;
  799. case 'imce':
  800. $settings['filebrowserFlashBrowseUrl'] = url('imce', array('query' => array('app' => 'ckeditor|sendto@ckeditor_imceSendTo|')));
  801. break;
  802. case 'elfinder':
  803. $settings['filebrowserFlashBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
  804. break;
  805. /* MODULES NOT PORTED TO D7
  806. case 'webfm':
  807. if (user_access('access webfm')) {
  808. $settings['filebrowserFlashBrowseUrl'] = $host . "index.php?q=webfm_popup";
  809. }
  810. break;
  811. case 'ib':
  812. if (user_access('browse own images')) {
  813. $settings['filebrowserFlashBrowseUrl'] = $host . "index.php?q=imagebrowser/view/browser&app=ckeditor";
  814. $settings['filebrowserFlashWindowWidth'] = 680;
  815. $settings['filebrowserFlashWindowHeight'] = 439;
  816. }
  817. break;
  818. case 'tinybrowser':
  819. $settings['filebrowserFlashBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=media";
  820. $settings['filebrowserFlashWindowWidth'] = (int) $win_size[0] + 15;
  821. $settings['filebrowserFlashWindowHeight'] = (int) $win_size[1] + 15;
  822. break;
  823. */
  824. }
  825. }
  826. if (!empty($conf['js_conf'])) {
  827. preg_match_all('#config\.(\w+)[\s]*=[\s]*(.+?);[\s]*(?=config\.|$)#is', preg_replace("/[\n\r]+/", "", $conf['js_conf']), $matches);
  828. foreach ($matches[2] as $i => $match) {
  829. if (!empty($match)) {
  830. $value = trim($match, " ;\n\r\t\0\x0B");
  831. if (strcasecmp($value, 'true') == 0) {
  832. $value = TRUE;
  833. }
  834. if (strcasecmp($value, 'false') == 0) {
  835. $value = FALSE;
  836. }
  837. $settings["js_conf"][$matches[1][$i]] = $value;
  838. }
  839. }
  840. }
  841. $settings['stylesCombo_stylesSet'] = "drupal:" . $module_drupal_path . '/ckeditor.styles.js';
  842. if (!empty($conf['css_style'])) {
  843. if ($conf['css_style'] == 'theme' && file_exists($themepath . 'ckeditor.styles.js')) {
  844. $settings['stylesCombo_stylesSet'] = "drupal:" . $host . $themepath . 'ckeditor.styles.js';
  845. }
  846. elseif (!empty($conf['css_style']) && $conf['css_style'] == 'self') {
  847. $conf['styles_path'] = str_replace("%h%t", "%t", $conf['styles_path']);
  848. $settings['stylesCombo_stylesSet'] = "drupal:" . str_replace(array('%h', '%t', '%m'), array($host, $host . $themepath, $module_drupal_path), $conf['styles_path']);
  849. }
  850. }
  851. // add custom stylesheet if configured
  852. // lets hope it exists but we'll leave that to the site admin
  853. $query_string = '?' . variable_get('css_js_query_string', '0');
  854. $css_files = array();
  855. switch ($conf['css_mode']) {
  856. case 'theme':
  857. _ckeditor_add_css_from_theme($current_theme, $css_files);
  858. break;
  859. case 'self':
  860. if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
  861. $css_files[] = $module_drupal_path . '/css/ckeditor.css' . $query_string;
  862. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
  863. if (file_exists($module_drupal_local_path . '/css/ckeditor-rtl.css')) {
  864. $css_files[] = $module_drupal_path . '/css/ckeditor-rtl.css' . $query_string;
  865. }
  866. }
  867. }
  868. foreach (explode(',', $conf['css_path']) as $css_path) {
  869. $css_path = trim(str_replace("%h%t", "%t", $css_path));
  870. $css_files[] = str_replace(array('%h', '%t'), array($host, $host . $themepath), $css_path) . $query_string;
  871. }
  872. break;
  873. case 'none':
  874. if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
  875. $css_files[] = $module_drupal_path . '/css/ckeditor.css' . $query_string;
  876. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
  877. if (file_exists($module_drupal_local_path . '/css/ckeditor-rtl.css')) {
  878. $css_files[] = $module_drupal_path . '/css/ckeditor-rtl.css' . $query_string;
  879. }
  880. }
  881. }
  882. if ($editor_local_path != '<URL>') {
  883. if (file_exists($editor_local_path . '/contents.css')) {
  884. $css_files[] = $editor_path . '/contents.css' . $query_string;
  885. }
  886. }
  887. else {
  888. $editor_url_path = ckeditor_path('url');
  889. $css_files[] = $editor_url_path . '/contents.css' . $query_string;
  890. }
  891. break;
  892. }
  893. if (isset($conf['ckeditor_load_method']) && $conf['ckeditor_load_method'] == 'ckeditor_source.js') {
  894. foreach ($css_files as $k => $v) {
  895. $css_files[$k] = $v . '&t=' . time();
  896. }
  897. }
  898. $settings['contentsCss'] = array_values($css_files);
  899. if (!empty($conf['uicolor']) && $conf['uicolor'] == "custom" && !empty($conf['uicolor_user'])) {
  900. $settings['uiColor'] = $conf['uicolor_user'];
  901. }
  902. if (!empty($conf['uicolor']) && strpos($conf['uicolor'], "color_") === 0) {
  903. if (function_exists('color_get_palette')) {
  904. $palette = @color_get_palette($current_theme, FALSE); //[#652274]
  905. $color = str_replace("color_", "", $conf['uicolor']);
  906. if (!empty($palette[$color])) {
  907. $settings['uiColor'] = $palette[$color];
  908. }
  909. }
  910. }
  911. if (!empty($settings['loadPlugins'])) {
  912. // Remove orphaned plugins (coming from disabled modules).
  913. $available_plugins = array_keys(ckeditor_load_plugins());
  914. $settings['loadPlugins'] = array_intersect_key($settings['loadPlugins'], array_flip($available_plugins));
  915. }
  916. // Allow modules to modify the settings.
  917. drupal_alter('ckeditor_settings', $settings, $conf);
  918. return $settings;
  919. }
  920. function _ckeditor_add_css_from_theme($current_theme, &$css_files) {
  921. global $language, $base_theme_info;
  922. $themes = list_themes();
  923. $theme_info = $themes[$current_theme];
  924. if (!empty($theme_info->base_theme)) {
  925. _ckeditor_add_css_from_theme($theme_info->base_theme, $css_files);
  926. }
  927. $query_string = '?' . variable_get('css_js_query_string', '0');
  928. $host = base_path();
  929. $themepath = drupal_get_path('theme', $current_theme) . '/';
  930. $module_drupal_local_path = ckeditor_module_path('local');
  931. $module_drupal_path = drupal_get_path('module', 'ckeditor');
  932. if (!empty($theme_info->stylesheets)) {
  933. $editorcss = "\"";
  934. foreach ($base_theme_info as $base) { // Grab stylesheets from base theme
  935. if (!empty($base->stylesheets)) { // may be empty when the base theme reference in the info file is invalid
  936. foreach ($base->stylesheets as $type => $stylesheets) {
  937. if ($type != "print") {
  938. foreach ($stylesheets as $name => $path) {
  939. if (file_exists($path)) {
  940. $css_files[$name] = $host . $path . $query_string;
  941. // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) )
  942. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path, 0, -8) != "-rtl.css") {
  943. $rtl_path = substr($path, 0, -4) . "-rtl.css";
  944. if (file_exists($rtl_path)) {
  945. $css_files[$name . "-rtl"] = $host . $rtl_path . $query_string;
  946. }
  947. }
  948. }
  949. }
  950. }
  951. }
  952. }
  953. }
  954. if (!empty($theme_info->stylesheets)) { // Grab stylesheets from current theme
  955. foreach ($theme_info->stylesheets as $type => $stylesheets) {
  956. if ($type != "print") {
  957. foreach ($stylesheets as $name => $path) {
  958. // Checks if less module exists...
  959. if (strstr($path, '.less') && module_exists('less')) {
  960. $path = 'sites/default/files/less/' . $path; // append the less file path
  961. $path = str_replace('.less', '', $path); // remove the .less
  962. }
  963. if (file_exists($path)) {
  964. $css_files[$name] = $host . $path . $query_string;
  965. // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) )
  966. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path, 0, -8) != "-rtl.css") {
  967. $rtl_path = substr($path, 0, -4) . "-rtl.css";
  968. if (file_exists($rtl_path)) {
  969. $css_files[$name . "-rtl"] = $host . $rtl_path . $query_string;
  970. }
  971. }
  972. }
  973. elseif (!empty($css_files[$name])) {
  974. unset($css_files[$name]);
  975. }
  976. }
  977. }
  978. }
  979. }
  980. // Grab stylesheets local.css and local-rtl.css if they exist (fusion based themes)
  981. if (file_exists($themepath . 'css/local.css')) {
  982. $css_files[] = $host . $themepath . 'css/local.css' . $query_string;
  983. }
  984. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && file_exists($themepath . 'css/local-rtl.css')) {
  985. $css_files[] = $host . $themepath . 'css/local-rtl.css' . $query_string;
  986. }
  987. // Grab stylesheets from color module
  988. $color_paths = variable_get('color_' . $current_theme . '_stylesheets', array());
  989. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
  990. if (!empty($color_paths[1])) {
  991. $css_files[] = $host . $color_paths[1] . $query_string;
  992. }
  993. }
  994. elseif (!empty($color_paths[0])) {
  995. $css_files[] = $host . $color_paths[0] . $query_string;
  996. }
  997. }
  998. else {
  999. if (!file_exists($themepath . 'ckeditor.css') && file_exists($themepath . 'style.css')) {
  1000. $css_files[] = $host . $themepath . 'style.css' . $query_string;
  1001. }
  1002. }
  1003. if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
  1004. $css_files[] = $host . $module_drupal_path . '/css/ckeditor.css' . $query_string;
  1005. }
  1006. if (file_exists($themepath . 'ckeditor.css')) {
  1007. $css_files[] = $host . $themepath . 'ckeditor.css' . $query_string;
  1008. }
  1009. }
  1010. /**
  1011. * Load CKEditor for field ID
  1012. *
  1013. * @param object $field
  1014. * @param string $format
  1015. *
  1016. * @return object
  1017. *
  1018. */
  1019. function ckeditor_load_by_field($field, $format, $show_toggle = TRUE, $add_fields_to_toggle = FALSE) {
  1020. global $user, $theme;
  1021. static $processed_ids = array();
  1022. static $is_running = FALSE;
  1023. $use_ckeditor = FALSE;
  1024. $format_arr = FALSE;
  1025. $suffix = '';
  1026. if (is_array($format)) {
  1027. $format_arr = $format;
  1028. $format = isset($format_arr['#value']) ? $format_arr['#value'] : $format_arr['#default_value'];
  1029. }
  1030. if (!isset($field['#id'])) {
  1031. return $field;
  1032. }
  1033. if (isset($processed_ids[$field['#id']])) {
  1034. return $field;
  1035. }
  1036. if (key_exists('#wysiwyg', $field) && !$field['#wysiwyg']) {
  1037. return $field;
  1038. }
  1039. if (isset($field['#access']) && !$field['#access']) {
  1040. return $field;
  1041. }
  1042. if ($field['#id'] == "edit-log") {
  1043. return $field;
  1044. }
  1045. if (isset($field['#attributes']['disabled']) && $field['#attributes']['disabled'] == 'disabled') {
  1046. return $field;
  1047. }
  1048. drupal_add_js(array('ckeditor' => array('textarea_default_format' => array($field['#id'] => $format))), 'setting');
  1049. if (!isset($processed_ids[$field['#id']])) {
  1050. $processed_ids[$field['#id']] = array();
  1051. }
  1052. $global_profile = ckeditor_profile_load('CKEditor Global Profile');
  1053. $profile = ckeditor_get_profile($format);
  1054. $host = base_path();
  1055. if ($profile === FALSE) {
  1056. $ckeditor_in_default_format = FALSE;
  1057. foreach ((array) $format_arr['#options'] as $key => $val) {
  1058. if ($key == $format)
  1059. continue;
  1060. if ($profile = ckeditor_get_profile($key)) {
  1061. $use_ckeditor = $key;
  1062. break;
  1063. }
  1064. }
  1065. if ($use_ckeditor === FALSE) {
  1066. return $field;
  1067. }
  1068. }
  1069. else {
  1070. $ckeditor_in_default_format = TRUE;
  1071. }
  1072. if ($settings = ckeditor_profiles_compile($format)) {
  1073. $ckeditor_on = ($settings['default'] == 't' && $profile->settings['default'] == 't') ? TRUE : FALSE;
  1074. }
  1075. elseif ($settings = ckeditor_profiles_compile($use_ckeditor)) {
  1076. $ckeditor_on = FALSE;
  1077. }
  1078. else {
  1079. return $field;
  1080. }
  1081. // Attach the editor css.
  1082. $field['#attached']['css'][] = drupal_get_path('module', 'ckeditor') . '/css/ckeditor.editor.css';
  1083. if ($settings) {
  1084. $textarea_id = $field['#id'];
  1085. $class[] = 'ckeditor-mod';
  1086. $_ckeditor_ids[] = $textarea_id;
  1087. //settings are saved as strings, not booleans
  1088. if ($settings['show_toggle'] == 't' && $show_toggle) {
  1089. if ($add_fields_to_toggle !== FALSE) {
  1090. if (is_array($add_fields_to_toggle)) {
  1091. $toggle_fields = "['" . $textarea_id . "','" . implode("','", $add_fields_to_toggle) . "']";
  1092. }
  1093. else {
  1094. $toggle_fields = "['" . $textarea_id . "','" . $add_fields_to_toggle . "']";
  1095. }
  1096. }
  1097. else {
  1098. $toggle_fields = "['{$textarea_id}']";
  1099. }
  1100. $wysiwyg_link = '';
  1101. $wysiwyg_link .= "<a class=\"ckeditor_links\" style=\"display:none\" href=\"javascript:void(0);\" onclick=\"javascript:Drupal.ckeditorToggle({$toggle_fields},'" . str_replace("'", "\\'", t('Switch to plain text editor')) . "','" . str_replace("'", "\\'", t('Switch to rich text editor')) . "');\" id=\"switch_{$textarea_id}\">";
  1102. $wysiwyg_link .= $ckeditor_on ? t('Switch to plain text editor') : t('Switch to rich text editor');
  1103. $wysiwyg_link .= '</a>';
  1104. // Make sure to append to #suffix so it isn't completely overwritten
  1105. $suffix .= $wysiwyg_link;
  1106. }
  1107. $editor_local_path = ckeditor_path('local');
  1108. $editor_url_path = ckeditor_path('url');
  1109. if (!$is_running) {
  1110. // By default sessions are not started automatically for anonymous users.
  1111. // Start one for editing content so that we had a consistent token that is used in XSS filter.
  1112. if (isset($field['#entity']) && !empty($field['#entity']->created) && empty($user->uid)) {
  1113. drupal_session_start();
  1114. $_SESSION['ckeditor_anonymous_user'] = true;
  1115. drupal_page_is_cacheable(FALSE);
  1116. }
  1117. if (!$ckeditor_in_default_format) {
  1118. $load_method = 'ckeditor_basic.js';
  1119. $load_time_out = 0;
  1120. }
  1121. elseif (isset($profile->settings['ckeditor_load_method'])) {
  1122. $load_method = $profile->settings['ckeditor_load_method'];
  1123. $load_time_out = $profile->settings['ckeditor_load_time_out'];
  1124. }
  1125. if ($editor_local_path != '<URL>') {
  1126. drupal_add_js('window.CKEDITOR_BASEPATH = "' . ckeditor_path('relative') . '/"', array('type' => 'inline', 'weight' => -100));
  1127. }
  1128. drupal_add_js(ckeditor_module_path('url') . '/includes/ckeditor.utils.js', array('type' => 'file', 'scope' => 'footer'));
  1129. $preprocess = FALSE;
  1130. if (isset($global_profile->settings['ckeditor_aggregate']) && $global_profile->settings['ckeditor_aggregate'] == 't') {
  1131. $preprocess = TRUE;
  1132. }
  1133. if ($editor_local_path == '<URL>') {
  1134. drupal_add_js($editor_url_path . '/ckeditor.js', array('type' => 'external', 'scope' => 'footer'));
  1135. }
  1136. else if (isset($load_method) && file_exists($editor_local_path . '/' . $load_method)) {
  1137. drupal_add_js($editor_url_path . '/' . $load_method, array('type' => 'file', 'scope' => 'footer', 'preprocess' => $preprocess));
  1138. if ($load_method == 'ckeditor_basic.js') {
  1139. drupal_add_js('CKEDITOR.loadFullCoreTimeout = ' . $load_time_out . ';', array('type' => 'inline', 'scope' => 'footer'));
  1140. drupal_add_js(array('ckeditor' => array('load_timeout' => TRUE)), 'setting');
  1141. }
  1142. }
  1143. else {
  1144. drupal_add_js($editor_url_path . '/ckeditor.js', array('type' => 'file', 'scope' => 'footer', 'preprocess' => $preprocess));
  1145. }
  1146. $ckeditor_url = ckeditor_path('relative');
  1147. if ($ckeditor_url == '<URL>') {
  1148. $ckeditor_url = ckeditor_path('url');
  1149. }
  1150. $ckeditor_url .= '/';
  1151. drupal_add_js(array('ckeditor' => array('module_path' => ckeditor_module_path('relative'), 'editor_path' => $ckeditor_url)), 'setting');
  1152. if (module_exists('paging')) {
  1153. drupal_add_js(array('ckeditor' => array('pagebreak' => TRUE)), 'setting');
  1154. }
  1155. if (module_exists('linktocontent_node')) {
  1156. drupal_add_js(array('ckeditor' => array('linktocontent_node' => TRUE)), 'setting');
  1157. }
  1158. if (module_exists('linktocontent_menu')) {
  1159. drupal_add_js(array('ckeditor' => array('linktocontent_menu' => TRUE)), 'setting');
  1160. }
  1161. if (module_exists('pagebreak')) {
  1162. drupal_add_js(array('ckeditor' => array('pagebreak' => TRUE)), 'setting');
  1163. }
  1164. if (module_exists('smart_paging')) {
  1165. drupal_add_js(array('ckeditor' => array('pagebreak' => TRUE)), 'setting');
  1166. }
  1167. drupal_add_js(array('ckeditor' => array('ajaxToken' => drupal_get_token('ckeditorAjaxCall'), 'xss_url' => url('ckeditor/xss'))), 'setting');
  1168. $is_running = TRUE;
  1169. }
  1170. drupal_add_js(array('ckeditor' => array('theme' => $theme)), 'setting');
  1171. if (!empty($settings)) {
  1172. drupal_add_js(array('ckeditor' => array('elements' => array($textarea_id => $format))), 'setting');
  1173. }
  1174. if (!empty($ckeditor_on)) {
  1175. drupal_add_js(array('ckeditor' => array('autostart' => array($textarea_id => $ckeditor_on))), 'setting');
  1176. }
  1177. //[#1473010]
  1178. if (isset($settings['scayt_sLang'])) {
  1179. drupal_add_js(array('ckeditor' => array('scayt_language' => $settings['scayt_sLang'])), 'setting');
  1180. }
  1181. elseif (!empty($field["#language"]) && $field["#language"] != LANGUAGE_NONE) {
  1182. drupal_add_js(array('ckeditor' => array('scayt_language' => ckeditor_scayt_langcode($field["#language"]))), 'setting');
  1183. }
  1184. // Remember extra information and reuse it during "Preview"
  1185. $processed_ids[$field['#id']]['suffix'] = $suffix;
  1186. $processed_ids[$field['#id']]['class'] = $class;
  1187. if (empty($field['#suffix'])) {
  1188. $field['#suffix'] = $suffix;
  1189. }
  1190. else {
  1191. $field['#suffix'] .= $suffix;
  1192. }
  1193. if (empty($field['#attributes']['class'])) {
  1194. $field['#attributes']['class'] = $class;
  1195. }
  1196. else {
  1197. $field['#attributes']['class'] = array_merge($field['#attributes']['class'], $class);
  1198. }
  1199. }
  1200. return $field;
  1201. }
  1202. /**
  1203. * Return all modules that provide security filters.
  1204. */
  1205. function ckeditor_security_filters() {
  1206. $security_filters = array();
  1207. $security_filters['modules'] = array(
  1208. 'htmLawed' => array(
  1209. 'title' => 'htmLawed',
  1210. 'project_page' => 'http://drupal.org/project/htmLawed',
  1211. 'weight' => 0,
  1212. 'installed' => FALSE,
  1213. 'filters' => array()
  1214. ),
  1215. 'htmltidy' => array(
  1216. 'title' => 'Htmltidy',
  1217. 'project_page' => 'http://drupal.org/project/htmltidy',
  1218. 'weight' => 0,
  1219. 'installed' => FALSE,
  1220. 'filters' => array()
  1221. ),
  1222. 'htmlpurifier' => array(
  1223. 'title' => 'HTML Purifier',
  1224. 'project_page' => 'http://drupal.org/project/htmlpurifier',
  1225. 'weight' => 0,
  1226. 'installed' => FALSE,
  1227. 'filters' => array()
  1228. ),
  1229. 'wysiwyg_filter' => array(
  1230. 'title' => 'WYSIWYG Filter',
  1231. 'project_page' => 'http://drupal.org/project/wysiwyg_filter',
  1232. 'weight' => 0,
  1233. 'installed' => FALSE,
  1234. 'filters' => array()
  1235. )
  1236. );
  1237. $security_filters['filters'] = array();
  1238. foreach ($security_filters['modules'] as $module_name => $module_conf) {
  1239. if (module_exists($module_name)) {
  1240. $security_filters['modules'][$module_name]['installed'] = TRUE;
  1241. $module_filters = module_invoke($module_name, 'filter_info');
  1242. foreach ($module_filters as $module_filter_name => $module_filter_conf) {
  1243. $security_filters['modules'][$module_name]['filters'][$module_filter_name] = $module_filter_conf;
  1244. $security_filters['filters'][$module_filter_name] = TRUE;
  1245. }
  1246. }
  1247. }
  1248. //add filters from Drupal core
  1249. $security_filters['modules']['__drupal'] = array(
  1250. 'title' => 'Drupal core',
  1251. 'project_page' => FALSE,
  1252. 'weight' => -1,
  1253. 'installed' => TRUE,
  1254. 'filters' => array(
  1255. 'filter_html' => array(
  1256. 'title' => 'Limit allowed HTML tags',
  1257. 'description' => 'Removes the attributes that the built-in "Limit allowed HTML tags"-filter does not allow inside HTML elements/tags'
  1258. )
  1259. )
  1260. );
  1261. $security_filters['filters']['filter_html'] = TRUE;
  1262. //load security filters added by API
  1263. $external_module_filters = module_invoke_all('ckeditor_security_filter');
  1264. if (count($external_module_filters) > 0) {
  1265. $security_filters['modules']['__external'] = array(
  1266. 'title' => 'External filters',
  1267. 'project_page' => FALSE,
  1268. 'weight' => 1,
  1269. 'installed' => TRUE,
  1270. 'filters' => array()
  1271. );
  1272. foreach ($external_module_filters as $module_filter_name => $module_filter_conf) {
  1273. $security_filters['modules']['__external']['filters'][$module_filter_name] = $module_filter_conf;
  1274. $security_filters['filters'][$module_filter_name] = TRUE;
  1275. }
  1276. }
  1277. drupal_alter('ckeditor_security_filter', $security_filters);
  1278. return $security_filters;
  1279. }