ckeditor.lib.inc 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661
  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. * @return array
  313. */
  314. function ckeditor_load_plugins($render = FALSE) {
  315. $arr = array();
  316. $base_path = '%base_path%';
  317. $editor_path = '%editor_path%';
  318. $plugin_dir = '%plugin_dir%';
  319. $plugin_dir_additional = '%plugin_dir_extra%';
  320. $pattern = '#\.addButton\([\s]*[\'"](.*?)[\'"][\s]*\,[\s]*\{[\s]*(.*?)[\s]*\}#s';
  321. /*
  322. * External plugins
  323. */
  324. if (module_exists('ckeditor_swf') && file_exists(drupal_get_path('module', 'ckeditor_swf') . '/plugins/swf/plugin.js')) {
  325. $arr['ckeditor_swf'] = array(
  326. 'name' => 'swf',
  327. 'desc' => t('Support for the CKEditor SWF module'),
  328. 'path' => $base_path . drupal_get_path('module', 'ckeditor_swf') . '/plugins/swf/',
  329. 'buttons' => FALSE,
  330. 'default' => 't'
  331. );
  332. }
  333. if (module_exists('ckeditor_link') && file_exists(drupal_get_path('module', 'ckeditor_link') . '/plugins/link/plugin.js')) {
  334. $arr['ckeditor_link'] = array(
  335. 'name' => 'drupal_path',
  336. 'desc' => t('Support for the CKEditor Link module'),
  337. 'path' => $base_path . drupal_get_path('module', 'ckeditor_link') . '/plugins/link/',
  338. 'buttons' => FALSE,
  339. 'default' => 't'
  340. );
  341. }
  342. if (module_exists('linkit') && file_exists(drupal_get_path('module', 'linkit') . '/editors/ckeditor/plugin.js')) {
  343. $arr['linkit'] = array(
  344. 'name' => 'Linkit',
  345. 'desc' => t('Support for the Linkit module <em>(buttons: Linkit)</em>'),
  346. 'path' => $base_path . drupal_get_path('module', 'linkit') . '/editors/ckeditor/',
  347. 'buttons' => array(
  348. 'Linkit' => array(
  349. 'title' => 'Linkit',
  350. 'icon' => $base_path . drupal_get_path('module', 'linkit') . '/editors/ckeditor/linkit.png'
  351. )
  352. ),
  353. 'default' => 't'
  354. );
  355. }
  356. /*
  357. * CKEditor build-in plugins
  358. */
  359. $_editor_path = ckeditor_path('local');
  360. //die($editor_path);
  361. if ($_editor_path != '<URL>') {
  362. if (file_exists($_editor_path . '/plugins/tableresize/plugin.js')) {
  363. $arr['tableresize'] = array(
  364. 'name' => 'tableresize',
  365. 'desc' => t('Table Resize plugin'),
  366. 'path' => $editor_path . '/plugins/tableresize/',
  367. 'buttons' => FALSE,
  368. 'default' => 't'
  369. );
  370. }
  371. if (file_exists($_editor_path . '/plugins/autogrow/plugin.js')) {
  372. $arr['autogrow'] = array(
  373. 'name' => 'autogrow',
  374. 'desc' => t('Auto Grow plugin'),
  375. 'path' => $editor_path . '/plugins/autogrow/',
  376. 'buttons' => FALSE,
  377. 'default' => 'f'
  378. );
  379. }
  380. if (file_exists($_editor_path . '/plugins/stylesheetparser/plugin.js')) {
  381. $arr['stylesheetparser'] = array(
  382. 'name' => 'stylesheetparser',
  383. 'desc' => t('Stylesheet Parser plugin'),
  384. 'path' => $editor_path . '/plugins/stylesheetparser/',
  385. 'buttons' => FALSE,
  386. 'default' => 'f'
  387. );
  388. }
  389. }
  390. else {
  391. $_editor_url = ckeditor_path('url');
  392. if (preg_match("/\/(standard|full)-all/", $_editor_url)) {
  393. $arr['tableresize'] = array(
  394. 'name' => 'tableresize',
  395. 'desc' => t('Table Resize plugin. See !link for more details.', array(
  396. '!link' => l(t('addon page'), 'http://ckeditor.com/addon/tableresize')
  397. )),
  398. 'path' => $_editor_url . '/plugins/tableresize/',
  399. 'buttons' => FALSE,
  400. 'default' => 't'
  401. );
  402. $arr['autogrow'] = array(
  403. 'name' => 'autogrow',
  404. 'desc' => t('Auto Grow plugin. See !link for more details.', array(
  405. '!link' => l(t('addon page'), 'http://ckeditor.com/addon/autogrow')
  406. )),
  407. 'path' => $_editor_url . '/plugins/autogrow/',
  408. 'buttons' => FALSE,
  409. 'default' => 'f'
  410. );
  411. $arr['stylesheetparser'] = array(
  412. 'name' => 'stylesheetparser',
  413. 'desc' => t('Stylesheet Parser plugin. See !link for more details.', array(
  414. '!link' => l(t('addon page'), 'http://ckeditor.com/addon/stylesheetparser')
  415. )),
  416. 'path' => $_editor_url . '/plugins/stylesheetparser/',
  417. 'buttons' => FALSE,
  418. 'default' => 'f'
  419. );
  420. $arr['codesnippet'] = array(
  421. 'name' => 'codesnippet',
  422. 'desc' => t('Plugin for inserting Code Snippets. See !link for more details. See !help for additional instructions.', array(
  423. '!link' => l(t('addon page'), 'http://ckeditor.com/addon/codesnippet'),
  424. '!help' => l(t('help'), 'admin/help/ckeditor', array('fragment' => 'codesnippet'))
  425. )),
  426. 'path' => $_editor_url . '/plugins/codesnippet/',
  427. 'buttons' => array(
  428. 'CodeSnippet' => array(
  429. 'icon' => 'icons/codesnippet.png',
  430. 'label' => 'Insert Code Snippet',
  431. )
  432. ),
  433. 'default' => 'f'
  434. );
  435. $arr['mathjax'] = array(
  436. 'name' => 'mathjax',
  437. 'desc' => t('Plugin for inserting Mathematical Formula (MathJax). See !link for more details. See !help for additional instructions.', array(
  438. '!link' => l(t('addon page'), 'http://ckeditor.com/addon/mathjax'),
  439. '!help' => l(t('help'), 'admin/help/ckeditor', array('fragment' => 'mathjax'))
  440. )),
  441. 'path' => $_editor_url . '/plugins/mathjax/',
  442. 'buttons' => array(
  443. 'Mathjax' => array(
  444. 'icon' => 'icons/mathjax.png',
  445. 'label' => 'Insert Mathematical Formulas',
  446. )
  447. ),
  448. 'default' => 'f'
  449. );
  450. }
  451. }
  452. /*
  453. * CKEditor module plugins
  454. */
  455. $_plugin_dir = ckeditor_module_path('local') . '/plugins/';
  456. if ($handle = opendir($_plugin_dir)) {
  457. while (false !== ($file = readdir($handle))) {
  458. if (is_dir($_plugin_dir . $file) && file_exists($_plugin_dir . $file . '/plugin.js')) {
  459. $source = file_get_contents($_plugin_dir . $file . '/plugin.js');
  460. $buttons = array();
  461. if (preg_match_all($pattern, $source, $matches)) {
  462. foreach ($matches[1] as $i => $button_name) {
  463. if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$i], $matches2)) {
  464. $buttons[$button_name] = array();
  465. $buttons[$button_name]['label'] = $button_name;
  466. $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]);
  467. $buttons[$button_name]['icon'] = trim($matches2[2]);
  468. }
  469. }
  470. }
  471. if (preg_match('#@file ([^\n\r]*)#', $source, $matches)) {
  472. $arr[$file] = array(
  473. 'name' => $file,
  474. 'desc' => t($matches[1]),
  475. 'path' => $plugin_dir . $file . '/',
  476. 'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
  477. 'default' => 'f'
  478. );
  479. }
  480. else {
  481. $arr[$file] = array(
  482. 'name' => $file,
  483. 'desc' => t('Plugin file: ' . $file),
  484. 'path' => $plugin_dir . $file . '/',
  485. 'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
  486. 'default' => 'f'
  487. );
  488. }
  489. }
  490. }
  491. closedir($handle);
  492. }
  493. /*
  494. * CKEditor module plugins - additional directory
  495. */
  496. $_plugin_dir_additional = ckeditor_plugins_path('local') . '/';
  497. if ($_plugin_dir != $_plugin_dir_additional && is_dir($_plugin_dir_additional) && $handle = opendir($_plugin_dir_additional)) {
  498. while (false !== ($file = readdir($handle))) {
  499. if (is_dir($_plugin_dir_additional . $file) && file_exists($_plugin_dir_additional . $file . '/plugin.js')) {
  500. $source = file_get_contents($_plugin_dir_additional . $file . '/plugin.js');
  501. $buttons = array();
  502. if (preg_match_all($pattern, $source, $matches)) {
  503. foreach ($matches[1] as $i => $button_name) {
  504. if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$i], $matches2)) {
  505. $buttons[$button_name] = array();
  506. $buttons[$button_name]['label'] = $button_name;
  507. $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]);
  508. $buttons[$button_name]['icon'] = trim($matches2[2]);
  509. }
  510. }
  511. }
  512. if (preg_match('#@file ([^\n\r]*)#', $source, $matches)) {
  513. $arr[$file] = array(
  514. 'name' => $file,
  515. 'desc' => t($matches[1]),
  516. 'path' => $plugin_dir_additional . $file . '/',
  517. 'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
  518. 'default' => 'f'
  519. );
  520. }
  521. else {
  522. $arr[$file] = array(
  523. 'name' => $file,
  524. 'desc' => t('Plugin file: ' . $file),
  525. 'path' => $plugin_dir_additional . $file . '/',
  526. 'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
  527. 'default' => 'f'
  528. );
  529. }
  530. }
  531. }
  532. closedir($handle);
  533. }
  534. /*
  535. * CKEditor plugins registered by hook
  536. */
  537. $plugins = module_invoke_all('ckeditor_plugin');
  538. foreach ($plugins as $i => $plugin) {
  539. if (file_exists($plugin['path'] . 'plugin.js')) {
  540. $source = file_get_contents($plugin['path'] . 'plugin.js');
  541. $plugins[$i]['path'] = $base_path . $plugin['path'];
  542. if (!isset($plugin['buttons']) || count($plugin['buttons']) == 0) {
  543. $buttons = array();
  544. if (preg_match_all($pattern, $source, $matches)) {
  545. foreach ($matches[1] as $j => $button_name) {
  546. if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$j], $matches2)) {
  547. $buttons[$button_name] = array();
  548. $buttons[$button_name]['label'] = $button_name;
  549. $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]);
  550. $buttons[$button_name]['icon'] = trim($matches2[2]);
  551. }
  552. }
  553. }
  554. $plugins[$i]['buttons'] = (count($buttons) > 0) ? $buttons : FALSE;
  555. }
  556. }
  557. else {
  558. unset($plugins[$i]);
  559. }
  560. }
  561. $arr = array_merge($arr, $plugins);
  562. if (isset($arr['media']) && module_exists('media') == FALSE) {
  563. unset($arr['media']);
  564. }
  565. if (isset($arr['imce']) && module_exists('imce') == FALSE) {
  566. unset($arr['imce']);
  567. }
  568. //remove page break button if there is no module to do this
  569. if (isset($arr['drupalbreaks']['buttons']['DrupalPageBreak']) && !module_exists('paging') && !module_exists('pagebreak') && !module_exists('smart_paging')) {
  570. unset($arr['drupalbreaks']['buttons']['DrupalPageBreak']);
  571. }
  572. if (isset($arr['drupalbreaks'])) {
  573. $arr['drupalbreaks']['default'] = 't';
  574. }
  575. ksort($arr);
  576. if ($render === TRUE) {
  577. $arr = ckeditor_plugins_render($arr);
  578. }
  579. return $arr;
  580. }
  581. /**
  582. * Render CKEditor plugins path
  583. */
  584. function ckeditor_plugins_render($plugins) {
  585. $render = array();
  586. $render["%base_path%"] = ckeditor_base_path('relative') . '/';
  587. $render["%editor_path%"] = ckeditor_path('relative') . '/';
  588. $render["%module_path%"] = ckeditor_module_path('relative') . '/';
  589. $render["%plugin_dir%"] = $render["%module_path%"] . 'plugins/';
  590. $render["%plugin_dir_extra%"] = ckeditor_plugins_path('relative') . '/';
  591. foreach ((array) $plugins as $i => $plugin) {
  592. $plugins[$i]['path'] = str_replace(array_keys($render), array_values($render), $plugin['path']);
  593. }
  594. return $plugins;
  595. }
  596. /**
  597. * Get default ckeditor settings
  598. *
  599. * @return array
  600. */
  601. function ckeditor_user_get_setting_default() {
  602. $default = array(
  603. 'default' => 't',
  604. 'show_toggle' => 't',
  605. 'width' => '100%',
  606. 'lang' => 'en',
  607. 'auto_lang' => 't',
  608. );
  609. // Allow other modules to alter the default settings.
  610. drupal_alter('ckeditor_default_settings', $default);
  611. return $default;
  612. }
  613. /**
  614. * Return CKEditor settings
  615. *
  616. * @param object $user
  617. * @param object $profile
  618. * @param string $setting
  619. * @return array
  620. */
  621. function ckeditor_user_get_setting($user, $profile, $setting) {
  622. $default = ckeditor_user_get_setting_default();
  623. if (user_access('customize ckeditor')) {
  624. $status = isset($user->data['ckeditor_' . $setting]) ? $user->data['ckeditor_' . $setting] : (isset($profile->settings[$setting]) ? $profile->settings[$setting] : $default[$setting]);
  625. }
  626. else {
  627. $status = isset($profile->settings[$setting]) ? $profile->settings[$setting] : $default[$setting];
  628. }
  629. return $status;
  630. }
  631. /**
  632. * Return CKEditor profile by input format
  633. *
  634. * @param string $input_format
  635. * @return object|boolean
  636. */
  637. function ckeditor_get_profile($input_format) {
  638. $select = db_select('ckeditor_settings', 's');
  639. $select->join('ckeditor_input_format', 'f', 'f.name = s.name');
  640. $result = $select->fields('s', array("name"))->condition('f.format', $input_format)->condition('f.name', 'CKEditor Global Profile', '<>')->range(0, 1)->execute()->fetchAssoc();
  641. if ($result && $profile = ckeditor_profile_load($result['name'])) {
  642. return $profile;
  643. }
  644. return FALSE;
  645. }
  646. /**
  647. * Return CKEditor profile list
  648. */
  649. function ckeditor_profile_input_formats() {
  650. $select = db_select('ckeditor_settings', 's');
  651. $select->join('ckeditor_input_format', 'f', 'f.name = s.name');
  652. $result = $select->fields('s', array("name"))->fields('f', array("format"))->execute();
  653. $list = array();
  654. while ($row = $result->fetchAssoc()) {
  655. if (!isset($row['name'])) {
  656. $list[$row['name']] = array();
  657. }
  658. $list[$row['name']][] = $row['format'];
  659. }
  660. return $list;
  661. }
  662. /**
  663. * Search and return CKEditor plugin path
  664. *
  665. * @return string
  666. */
  667. function _ckeditor_script_path() {
  668. $jspath = '';
  669. $module_path = drupal_get_path('module', 'ckeditor');
  670. if (file_exists($module_path . '/ckeditor/ckeditor.js')) {
  671. $jspath = '%m/ckeditor';
  672. }
  673. elseif (file_exists($module_path . '/ckeditor/ckeditor/ckeditor.js')) {
  674. $jspath = '%m/ckeditor/ckeditor';
  675. }
  676. elseif (file_exists(ckeditor_library_path('url') . '/ckeditor/ckeditor.js')) {
  677. $jspath = '%l/ckeditor';
  678. }
  679. return $jspath;
  680. }
  681. /**
  682. * Determines whether the CKEditor sources are present
  683. *
  684. * It checks if ckeditor.js is present.
  685. *
  686. * This function is used by ckeditor_requirements()
  687. *
  688. * @return boolean True if CKEditor is installed
  689. */
  690. function _ckeditor_requirements_isinstalled() {
  691. $editor_path = ckeditor_path('local');
  692. if ($editor_path == '<URL>')
  693. return TRUE;
  694. $jspath = $editor_path . '/ckeditor.js';
  695. $jsp = file_exists($jspath);
  696. if (!$jsp && ($editor_path = _ckeditor_script_path())) {
  697. $result = db_select('ckeditor_settings', 's')->fields('s')->condition('name', 'CKEditor Global Profile')->execute()->fetchAssoc();
  698. if ($result) {
  699. $result['settings'] = unserialize($result['settings']);
  700. $result['settings']['ckeditor_path'] = $editor_path;
  701. $result['settings'] = serialize($result['settings']);
  702. db_update('ckeditor_settings')->fields(array("settings" => $result['settings']))->condition('name', 'CKEditor Global Profile')->execute();
  703. $jsp = TRUE;
  704. ckeditor_path('local', TRUE);
  705. }
  706. }
  707. return $jsp;
  708. }
  709. /**
  710. * Compile settings of all profiles at returns is as array
  711. *
  712. * @param string $input_format
  713. * @param boolean $clear
  714. * @return array
  715. */
  716. function ckeditor_profiles_compile($input_format = FALSE, $clear = FALSE) {
  717. static $compiled = FALSE;
  718. static $_ckeditor_compiled = array();
  719. if ($clear !== FALSE && $compiled !== FALSE) {
  720. $compiled = FALSE;
  721. }
  722. if ($compiled === TRUE) {
  723. return ( $input_format === FALSE ) ? $_ckeditor_compiled : ( isset($_ckeditor_compiled[$input_format]) ? $_ckeditor_compiled[$input_format] : array() );
  724. }
  725. $global_profile = ckeditor_profile_load('CKEditor Global Profile');
  726. $profiles_list = ckeditor_profile_input_formats();
  727. foreach ($profiles_list AS $_profile => $_inputs) {
  728. $profile = ckeditor_profile_load($_profile);
  729. $setting = ckeditor_profile_settings_compile($global_profile, $profile);
  730. foreach ($_inputs AS $_input) {
  731. $_ckeditor_compiled[$_input] = $setting;
  732. }
  733. }
  734. $compiled = TRUE;
  735. return ( $input_format === FALSE ) ? $_ckeditor_compiled : $_ckeditor_compiled[$input_format];
  736. }
  737. /**
  738. * Compile settings of profile
  739. *
  740. * @param object $global_profile
  741. * @param object $profile
  742. * @return array
  743. */
  744. function ckeditor_profile_settings_compile($global_profile, $profile) {
  745. global $user, $language, $theme;
  746. $current_theme = variable_get('theme_default', $theme);
  747. $settings = array();
  748. $conf = array();
  749. $conf = $profile->settings;
  750. $profile_name = $profile->name;
  751. if (user_access('customize ckeditor')) {
  752. foreach (array('default', 'show_toggle', 'width', 'lang', 'auto_lang') as $setting) {
  753. $conf[$setting] = ckeditor_user_get_setting($user, $profile, $setting);
  754. }
  755. }
  756. if (!isset($conf['ss'])) {
  757. $conf['ss'] = 2;
  758. }
  759. $themepath = drupal_get_path('theme', $current_theme) . '/';
  760. $host = base_path();
  761. // setting some variables
  762. $module_drupal_path = ckeditor_module_path('relative');
  763. $module_drupal_local_path = ckeditor_module_path('local');
  764. $editor_path = ckeditor_path('relative');
  765. $editor_local_path = ckeditor_path('local');
  766. $toolbar = $conf['toolbar'];
  767. if (!empty($conf['theme_config_js']) && $conf['theme_config_js'] == 't' && file_exists($themepath . 'ckeditor.config.js')) {
  768. $ckeditor_config_path = $host . $themepath . 'ckeditor.config.js?' . @filemtime($themepath . 'ckeditor.config.js');
  769. }
  770. else {
  771. $ckeditor_config_path = $module_drupal_path . "/ckeditor.config.js?" . @filemtime($module_drupal_path . "/ckeditor.config.js");
  772. }
  773. $settings['customConfig'] = $ckeditor_config_path;
  774. $settings['defaultLanguage'] = $conf['lang'];
  775. $settings['toolbar'] = $toolbar;
  776. $settings['enterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['enter_mode']));
  777. $settings['shiftEnterMode'] = constant("CKEDITOR_ENTERMODE_" . strtoupper($conf['shift_enter_mode']));
  778. $settings['toolbarStartupExpanded'] = ( $conf['expand'] == 't' );
  779. if ($conf['expand'] == 'f') {
  780. $settings['toolbarCanCollapse'] = true;
  781. }
  782. $settings['width'] = $conf['width'];
  783. //check if skin exists, if not select default one
  784. if (isset($global_profile->settings['skin']) && file_exists($editor_local_path . '/skins/' . $global_profile->settings['skin'])) {
  785. $settings['skin'] = $global_profile->settings['skin'];
  786. }
  787. else {
  788. $settings['skin'] = ckeditor_default_skin();
  789. }
  790. $settings['format_tags'] = $conf['font_format'];
  791. $settings['show_toggle'] = $conf['show_toggle'];
  792. if (!empty($conf['allowed_content']) && $conf['allowed_content'] === 'f') {
  793. $settings['allowedContent'] = true;
  794. }
  795. elseif (!empty($conf['extraAllowedContent'])) {
  796. $settings['extraAllowedContent'] = $conf['extraAllowedContent'];
  797. }
  798. $settings['ss'] = $conf['ss'];
  799. if (isset($conf['language_direction'])) {
  800. switch ($conf['language_direction']) {
  801. case 'default':
  802. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
  803. $settings['contentsLangDirection'] = 'rtl';
  804. }
  805. break;
  806. case 'ltr':
  807. $settings['contentsLangDirection'] = 'ltr';
  808. break;
  809. case 'rtl':
  810. $settings['contentsLangDirection'] = 'rtl';
  811. break;
  812. }
  813. }
  814. if (isset($conf['loadPlugins'])) {
  815. $settings['loadPlugins'] = ckeditor_plugins_render($conf['loadPlugins']);
  816. if (array_key_exists('media', $settings['loadPlugins']) && module_exists('media')) {
  817. module_load_include('inc', 'media', 'includes/media.browser');
  818. $javascript = media_browser_js();
  819. foreach ($javascript as $key => $definitions) {
  820. foreach ($definitions as $definition) {
  821. $function = 'drupal_add_' . $key;
  822. call_user_func_array($function, $definition);
  823. }
  824. }
  825. drupal_add_js(drupal_get_path('module', 'ckeditor') . '/plugins/media/library.js', array('scope' => 'footer', 'weight' => -20));
  826. }
  827. }
  828. else {
  829. $settings['loadPlugins'] = array();
  830. }
  831. //add support for divarea plugin from CKE4
  832. if (isset($conf['use_divarea']) && $conf['use_divarea'] == 't' && $editor_local_path != '<URL>' && file_exists($editor_local_path . '/plugins/divarea/plugin.js')) {
  833. $settings['loadPlugins']['divarea'] = array('name' => 'divarea', 'path' => $editor_path . '/plugins/divarea/', 'buttons' => FALSE, 'default' => 'f');
  834. }
  835. if (isset($conf['html_entities']) && $conf['html_entities'] == 'f') {
  836. $settings['entities'] = FALSE;
  837. $settings['entities_greek'] = FALSE;
  838. $settings['entities_latin'] = FALSE;
  839. }
  840. if (isset($conf['scayt_autoStartup']) && $conf['scayt_autoStartup'] == 't') {
  841. $settings['scayt_autoStartup'] = TRUE;
  842. }
  843. else {
  844. $settings['scayt_autoStartup'] = FALSE;
  845. }
  846. if ($conf['auto_lang'] == "f") {
  847. $settings['language'] = $conf['lang'];
  848. //[#1473010]
  849. $settings['scayt_sLang'] = ckeditor_scayt_langcode($conf['lang']);
  850. }
  851. if (isset($conf['forcePasteAsPlainText']) && $conf['forcePasteAsPlainText'] == 't') {
  852. $settings['forcePasteAsPlainText'] = TRUE;
  853. }
  854. if (isset($conf['custom_formatting']) && $conf['custom_formatting'] == 't') {
  855. foreach ($conf['formatting']['custom_formatting_options'] as $k => $v) {
  856. if ($v === 0) {
  857. $conf['formatting']['custom_formatting_options'][$k] = FALSE;
  858. }
  859. else {
  860. $conf['formatting']['custom_formatting_options'][$k] = TRUE;
  861. }
  862. }
  863. $settings['output_pre_indent'] = $conf['formatting']['custom_formatting_options']['pre_indent'];
  864. unset($conf['formatting']['custom_formatting_options']['pre_indent']);
  865. $settings['custom_formatting'] = $conf['formatting']['custom_formatting_options'];
  866. }
  867. // add code for filebrowser for users that have access
  868. $filebrowser = !empty($conf['filebrowser']) ? $conf['filebrowser'] : 'none';
  869. $filebrowser_image = !empty($conf['filebrowser_image']) ? $conf['filebrowser_image'] : $filebrowser;
  870. $filebrowser_flash = !empty($conf['filebrowser_flash']) ? $conf['filebrowser_flash'] : $filebrowser;
  871. if ($filebrowser == 'imce' && !module_exists('imce')) {
  872. $filebrowser = 'none';
  873. }
  874. if ($filebrowser == 'elfinder' && !module_exists('elfinder')) {
  875. $filebrowser = 'none';
  876. }
  877. /* MODULES NOT PORTED TO D7
  878. if ($filebrowser == 'tinybrowser' && !module_exists('tinybrowser')) {
  879. $filebrowser = 'none';
  880. }
  881. if ($filebrowser == 'ib' && !module_exists('imagebrowser')) {
  882. $filebrowser = 'none';
  883. }
  884. if ($filebrowser == 'webfm' && !module_exists('webfm_popup')) {
  885. $filebrowser = 'none';
  886. }
  887. */
  888. if ($filebrowser_image != $filebrowser) {
  889. if ($filebrowser_image == 'imce' && !module_exists('imce')) {
  890. $filebrowser_image = $filebrowser;
  891. }
  892. if ($filebrowser_image == 'elfinder' && !module_exists('elfinder')) {
  893. $filebrowser_image = $filebrowser;
  894. }
  895. /* MODULES NOT PORTED TO D7
  896. if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) {
  897. $filebrowser_image = $filebrowser;
  898. }
  899. if ($filebrowser_image == 'ib' && !module_exists('imagebrowser')) {
  900. $filebrowser_image = $filebrowser;
  901. }
  902. if ($filebrowser_image == 'webfm' && !module_exists('webfm_popup')) {
  903. $filebrowser_image = $filebrowser;
  904. }
  905. */
  906. }
  907. if ($filebrowser_flash != $filebrowser) {
  908. if ($filebrowser_flash == 'imce' && !module_exists('imce')) {
  909. $filebrowser_flash = $filebrowser;
  910. }
  911. if ($filebrowser_image == 'elfinder' && !module_exists('elfinder')) {
  912. $filebrowser_flash = $filebrowser;
  913. }
  914. /* MODULES NOT PORTED TO D7
  915. if ($filebrowser_image == 'tinybrowser' && !module_exists('tinybrowser')) {
  916. $filebrowser_flash = $filebrowser;
  917. }
  918. if ($filebrowser_flash == 'ib' && !module_exists('imagebrowser')) {
  919. $filebrowser_flash = $filebrowser;
  920. }
  921. if ($filebrowser_flash == 'webfm' && !module_exists('webfm_popup')) {
  922. $filebrowser_flash = $filebrowser;
  923. }
  924. */
  925. }
  926. if ($filebrowser == 'ckfinder' || $filebrowser_image == 'ckfinder' || $filebrowser_flash == 'ckfinder') {
  927. if (user_access('allow CKFinder file uploads')) {
  928. if (!empty($profile->settings['UserFilesPath'])) {
  929. $_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));
  930. }
  931. else {
  932. $_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));
  933. }
  934. if (!empty($profile->settings['UserFilesAbsolutePath'])) {
  935. $_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));
  936. }
  937. else {
  938. $_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));
  939. }
  940. if (variable_get('file_default_scheme', '') == 'private') {
  941. $private_dir = isset($global_profile->settings['private_dir']) ? trim($global_profile->settings['private_dir'], '/') : '';
  942. if (!empty($private_dir)) {
  943. $private_dir = strtr($private_dir, array('%u' => $user->uid, '%n' => $user->name));
  944. $_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = url('system/files') . '/' . $private_dir . '/';
  945. $private_upload_path = file_uri_target('private://' . variable_get('file_private_path', '')) . '/' . $private_dir;
  946. }
  947. else {
  948. $_SESSION['ckeditor'][$profile_name]['UserFilesPath'] = url('system/files') . '/';
  949. $private_upload_path = file_uri_target('private://' . variable_get('file_private_path', ''));
  950. }
  951. //add '/' to beginning of path if necessary
  952. if (strpos(variable_get('file_private_path', ''), '/') === 0 && $private_upload_path[0] != '/') {
  953. $private_upload_path = '/' . $private_upload_path;
  954. }
  955. //check if CKEditor private dir exists and create it if not
  956. if ($private_dir && !is_dir($private_upload_path)) {
  957. mkdir($private_upload_path, 0755, TRUE);
  958. }
  959. $_SESSION['ckeditor'][$profile_name]['UserFilesAbsolutePath'] = drupal_realpath($private_upload_path) . '/';
  960. }
  961. }
  962. }
  963. /* MODULES NOT PORTED TO D7
  964. if (in_array('tinybrowser', array($filebrowser, $filebrowser_image, $filebrowser_flash))) {
  965. $popup_win_size = variable_get('tinybrowser_popup_window_size', '770x480');
  966. if (!preg_match('#\d+x\d+#is', $popup_win_size)) {
  967. $popup_win_size = '770x480';
  968. }
  969. $popup_win_size = trim($popup_win_size);
  970. $popup_win_size = strtolower($popup_win_size);
  971. $win_size = split('x', $popup_win_size);
  972. }
  973. */
  974. switch ($filebrowser) {
  975. case 'ckfinder':
  976. if (user_access('allow CKFinder file uploads')) {
  977. $ckfinder_full_path = ckfinder_path('relative');
  978. $settings['filebrowserBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?id=' . $profile_name;
  979. $settings['filebrowserImageBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
  980. $settings['filebrowserFlashBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Flash&id=' . $profile_name;
  981. $settings['filebrowserUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Files&id=' . $profile_name;
  982. $settings['filebrowserImageUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
  983. $settings['filebrowserFlashUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Flash&id=' . $profile_name;
  984. }
  985. break;
  986. case 'imce':
  987. $settings['filebrowserBrowseUrl'] = url('imce', array('query' => array('app' => 'ckeditor|sendto@ckeditor_imceSendTo|')));
  988. break;
  989. case 'elfinder':
  990. $settings['filebrowserBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
  991. break;
  992. /* MODULES NOT PORTED TO D7
  993. case 'webfm':
  994. if (user_access('access webfm')) {
  995. $settings['filebrowserBrowseUrl'] = $host . "index.php?q=webfm_popup";
  996. }
  997. break;
  998. case 'ib':
  999. if (user_access('browse own images')) {
  1000. $settings['filebrowserBrowseUrl'] = $host . "index.php?q=imagebrowser/view/browser&app=ckeditor";
  1001. $settings['filebrowserWindowWidth'] = 700;
  1002. $settings['filebrowserWindowHeight'] = 520;
  1003. }
  1004. break;
  1005. case 'tinybrowser':
  1006. $settings['filebrowserBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=file";
  1007. $settings['filebrowserWindowWidth'] = (int) $win_size[0] + 15;
  1008. $settings['filebrowserWindowHeight'] = (int) $win_size[1] + 15;
  1009. break;
  1010. */
  1011. }
  1012. if ($filebrowser_image != $filebrowser) {
  1013. switch ($filebrowser_image) {
  1014. case 'ckfinder':
  1015. if (user_access('allow CKFinder file uploads')) {
  1016. $ckfinder_full_path = ckfinder_path('relative');
  1017. $settings['filebrowserImageBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
  1018. $settings['filebrowserImageUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
  1019. }
  1020. break;
  1021. case 'imce':
  1022. $settings['filebrowserImageBrowseUrl'] = url('imce', array('query' => array('app' => 'ckeditor|sendto@ckeditor_imceSendTo|')));
  1023. break;
  1024. case 'elfinder':
  1025. $settings['filebrowserImageBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
  1026. break;
  1027. /* MODULES NOT PORTED TO D7
  1028. case 'webfm':
  1029. if (user_access('access webfm')) {
  1030. $settings['filebrowserImageBrowseUrl'] = $host . "index.php?q=webfm_popup";
  1031. }
  1032. break;
  1033. case 'ib':
  1034. if (user_access('browse own images')) {
  1035. $settings['filebrowserImageBrowseUrl'] = $host . "index.php?q=imagebrowser/view/browser&app=ckeditor";
  1036. $settings['filebrowserImageWindowWidth'] = 680;
  1037. $settings['filebrowserImageWindowHeight'] = 439;
  1038. }
  1039. break;
  1040. case 'tinybrowser':
  1041. $settings['filebrowserImageBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=image";
  1042. $settings['filebrowserImageWindowWidth'] = (int) $win_size[0] + 15;
  1043. $settings['filebrowserImageWindowHeight'] = (int) $win_size[1] + 15;
  1044. break;
  1045. */
  1046. }
  1047. }
  1048. if ($filebrowser_flash != $filebrowser) {
  1049. switch ($filebrowser_flash) {
  1050. case 'ckfinder':
  1051. if (user_access('allow CKFinder file uploads')) {
  1052. $ckfinder_full_path = ckfinder_path('relative');
  1053. $settings['filebrowserFlashBrowseUrl'] = $ckfinder_full_path . '/ckfinder.html?Type=Images&id=' . $profile_name;
  1054. $settings['filebrowserFlashUploadUrl'] = $ckfinder_full_path . '/core/connector/php/connector.php?command=QuickUpload&type=Images&id=' . $profile_name;
  1055. }
  1056. break;
  1057. case 'imce':
  1058. $settings['filebrowserFlashBrowseUrl'] = url('imce', array('query' => array('app' => 'ckeditor|sendto@ckeditor_imceSendTo|')));
  1059. break;
  1060. case 'elfinder':
  1061. $settings['filebrowserFlashBrowseUrl'] = $host . "index.php?q=elfinder&app=ckeditor";
  1062. break;
  1063. /* MODULES NOT PORTED TO D7
  1064. case 'webfm':
  1065. if (user_access('access webfm')) {
  1066. $settings['filebrowserFlashBrowseUrl'] = $host . "index.php?q=webfm_popup";
  1067. }
  1068. break;
  1069. case 'ib':
  1070. if (user_access('browse own images')) {
  1071. $settings['filebrowserFlashBrowseUrl'] = $host . "index.php?q=imagebrowser/view/browser&app=ckeditor";
  1072. $settings['filebrowserFlashWindowWidth'] = 680;
  1073. $settings['filebrowserFlashWindowHeight'] = 439;
  1074. }
  1075. break;
  1076. case 'tinybrowser':
  1077. $settings['filebrowserFlashBrowseUrl'] = $host . drupal_get_path('module', 'tinybrowser') . "/tinybrowser/tinybrowser.php?type=media";
  1078. $settings['filebrowserFlashWindowWidth'] = (int) $win_size[0] + 15;
  1079. $settings['filebrowserFlashWindowHeight'] = (int) $win_size[1] + 15;
  1080. break;
  1081. */
  1082. }
  1083. }
  1084. if (!empty($conf['js_conf'])) {
  1085. preg_match_all('#config\.(\w+)[\s]*=[\s]*(.+?);[\s]*(?=config\.|$)#is', preg_replace("/[\n\r]+/", "", $conf['js_conf']), $matches);
  1086. foreach ($matches[2] as $i => $match) {
  1087. if (!empty($match)) {
  1088. $value = trim($match, " ;\n\r\t\0\x0B");
  1089. if (strcasecmp($value, 'true') == 0) {
  1090. $value = TRUE;
  1091. }
  1092. if (strcasecmp($value, 'false') == 0) {
  1093. $value = FALSE;
  1094. }
  1095. $settings["js_conf"][$matches[1][$i]] = $value;
  1096. }
  1097. }
  1098. }
  1099. $settings['stylesCombo_stylesSet'] = "drupal:" . $module_drupal_path . '/ckeditor.styles.js';
  1100. if (!empty($conf['css_style'])) {
  1101. if ($conf['css_style'] == 'theme' && file_exists($themepath . 'ckeditor.styles.js')) {
  1102. $settings['stylesCombo_stylesSet'] = "drupal:" . $host . $themepath . 'ckeditor.styles.js';
  1103. }
  1104. elseif (!empty($conf['css_style']) && $conf['css_style'] == 'self') {
  1105. $conf['styles_path'] = str_replace("%h%t", "%t", $conf['styles_path']);
  1106. $settings['stylesCombo_stylesSet'] = "drupal:" . str_replace(array('%h', '%t', '%m'), array($host, $host . $themepath, $module_drupal_path), $conf['styles_path']);
  1107. }
  1108. }
  1109. // add custom stylesheet if configured
  1110. // lets hope it exists but we'll leave that to the site admin
  1111. $query_string = '?' . variable_get('css_js_query_string', '0');
  1112. $css_files = array();
  1113. switch ($conf['css_mode']) {
  1114. case 'theme':
  1115. global $language, $base_theme_info;
  1116. $themes = list_themes();
  1117. $theme_info = $themes[$current_theme];
  1118. if (!empty($theme_info->stylesheets)) {
  1119. $editorcss = "\"";
  1120. foreach ($base_theme_info as $base) { // Grab stylesheets from base theme
  1121. if (!empty($base->stylesheets)) { // may be empty when the base theme reference in the info file is invalid
  1122. foreach ($base->stylesheets as $type => $stylesheets) {
  1123. if ($type != "print") {
  1124. foreach ($stylesheets as $name => $path) {
  1125. if (file_exists($path)) {
  1126. $css_files[$name] = $host . $path . $query_string;
  1127. // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) )
  1128. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path, 0, -8) != "-rtl.css") {
  1129. $rtl_path = substr($path, 0, -4) . "-rtl.css";
  1130. if (file_exists($rtl_path)) {
  1131. $css_files[$name . "-rtl"] = $host . $rtl_path . $query_string;
  1132. }
  1133. }
  1134. }
  1135. }
  1136. }
  1137. }
  1138. }
  1139. }
  1140. if (!empty($theme_info->stylesheets)) { // Grab stylesheets from current theme
  1141. foreach ($theme_info->stylesheets as $type => $stylesheets) {
  1142. if ($type != "print") {
  1143. foreach ($stylesheets as $name => $path) {
  1144. // Checks if less module exists...
  1145. if (strstr($path, '.less') && module_exists('less')) {
  1146. $path = 'sites/default/files/less/' . $path; // append the less file path
  1147. $path = str_replace('.less', '', $path); // remove the .less
  1148. }
  1149. if (file_exists($path)) {
  1150. $css_files[$name] = $host . $path . $query_string;
  1151. // Grab rtl stylesheets ( will get rtl css files when thay are named with suffix "-rtl.css" (ex: fusion baased themes) )
  1152. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && substr($path, 0, -8) != "-rtl.css") {
  1153. $rtl_path = substr($path, 0, -4) . "-rtl.css";
  1154. if (file_exists($rtl_path)) {
  1155. $css_files[$name . "-rtl"] = $host . $rtl_path . $query_string;
  1156. }
  1157. }
  1158. }
  1159. elseif (!empty($css_files[$name])) {
  1160. unset($css_files[$name]);
  1161. }
  1162. }
  1163. }
  1164. }
  1165. }
  1166. // Grab stylesheets local.css and local-rtl.css if they exist (fusion based themes)
  1167. if (file_exists($themepath . 'css/local.css')) {
  1168. $css_files[] = $host . $themepath . 'css/local.css' . $query_string;
  1169. }
  1170. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL && file_exists($themepath . 'css/local-rtl.css')) {
  1171. $css_files[] = $host . $themepath . 'css/local-rtl.css' . $query_string;
  1172. }
  1173. // Grab stylesheets from color module
  1174. $color_paths = variable_get('color_' . $current_theme . '_stylesheets', array());
  1175. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
  1176. if (!empty($color_paths[1])) {
  1177. $css_files[] = $host . $color_paths[1] . $query_string;
  1178. }
  1179. }
  1180. elseif (!empty($color_paths[0])) {
  1181. $css_files[] = $host . $color_paths[0] . $query_string;
  1182. }
  1183. }
  1184. else {
  1185. if (!file_exists($themepath . 'ckeditor.css') && file_exists($themepath . 'style.css')) {
  1186. $css_files[] = $host . $themepath . 'style.css' . $query_string;
  1187. }
  1188. }
  1189. if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
  1190. $css_files[] = $module_drupal_path . '/css/ckeditor.css' . $query_string;
  1191. }
  1192. if (file_exists($themepath . 'ckeditor.css')) {
  1193. $css_files[] = $host . $themepath . 'ckeditor.css' . $query_string;
  1194. }
  1195. break;
  1196. case 'self':
  1197. if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
  1198. $css_files[] = $module_drupal_path . '/css/ckeditor.css' . $query_string;
  1199. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
  1200. if (file_exists($module_drupal_local_path . '/css/ckeditor-rtl.css')) {
  1201. $css_files[] = $module_drupal_path . '/css/ckeditor-rtl.css' . $query_string;
  1202. }
  1203. }
  1204. }
  1205. foreach (explode(',', $conf['css_path']) as $css_path) {
  1206. $css_path = trim(str_replace("%h%t", "%t", $css_path));
  1207. $css_files[] = str_replace(array('%h', '%t'), array($host, $host . $themepath), $css_path) . $query_string;
  1208. }
  1209. break;
  1210. case 'none':
  1211. if (file_exists($module_drupal_local_path . '/css/ckeditor.css')) {
  1212. $css_files[] = $module_drupal_path . '/css/ckeditor.css' . $query_string;
  1213. if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) {
  1214. if (file_exists($module_drupal_local_path . '/css/ckeditor-rtl.css')) {
  1215. $css_files[] = $module_drupal_path . '/css/ckeditor-rtl.css' . $query_string;
  1216. }
  1217. }
  1218. }
  1219. if ($editor_local_path != '<URL>') {
  1220. if (file_exists($editor_local_path . '/contents.css')) {
  1221. $css_files[] = $editor_path . '/contents.css' . $query_string;
  1222. }
  1223. }
  1224. else {
  1225. $editor_url_path = ckeditor_path('url');
  1226. $css_files[] = $editor_url_path . '/contents.css' . $query_string;
  1227. }
  1228. break;
  1229. }
  1230. if (isset($conf['ckeditor_load_method']) && $conf['ckeditor_load_method'] == 'ckeditor_source.js') {
  1231. foreach ($css_files as $k => $v) {
  1232. $css_files[$k] = $v . '&t=' . time();
  1233. }
  1234. }
  1235. $settings['contentsCss'] = array_values($css_files);
  1236. if (!empty($conf['uicolor']) && $conf['uicolor'] == "custom" && !empty($conf['uicolor_user'])) {
  1237. $settings['uiColor'] = $conf['uicolor_user'];
  1238. }
  1239. if (!empty($conf['uicolor']) && strpos($conf['uicolor'], "color_") === 0) {
  1240. if (function_exists('color_get_palette')) {
  1241. $palette = @color_get_palette($current_theme, FALSE); //[#652274]
  1242. $color = str_replace("color_", "", $conf['uicolor']);
  1243. if (!empty($palette[$color])) {
  1244. $settings['uiColor'] = $palette[$color];
  1245. }
  1246. }
  1247. }
  1248. // Allow modules to modify the settings.
  1249. drupal_alter('ckeditor_settings', $settings, $conf);
  1250. return $settings;
  1251. }
  1252. /**
  1253. * Load CKEditor for field ID
  1254. *
  1255. * @param object $field
  1256. * @param string $format
  1257. *
  1258. * @return object
  1259. *
  1260. */
  1261. function ckeditor_load_by_field($field, $format, $show_toggle = TRUE, $add_fields_to_toggle = FALSE) {
  1262. global $user, $theme;
  1263. static $processed_ids = array();
  1264. static $is_running = FALSE;
  1265. $use_ckeditor = FALSE;
  1266. $format_arr = FALSE;
  1267. $suffix = '';
  1268. if (is_array($format)) {
  1269. $format_arr = $format;
  1270. $format = isset($format_arr['#value']) ? $format_arr['#value'] : $format_arr['#default_value'];
  1271. }
  1272. if (!isset($field['#id'])) {
  1273. return $field;
  1274. }
  1275. if (isset($processed_ids[$field['#id']])) {
  1276. return $field;
  1277. }
  1278. if (key_exists('#wysiwyg', $field) && !$field['#wysiwyg']) {
  1279. return $field;
  1280. }
  1281. if (isset($field['#access']) && !$field['#access']) {
  1282. return $field;
  1283. }
  1284. if ($field['#id'] == "edit-log") {
  1285. return $field;
  1286. }
  1287. if (isset($field['#attributes']['disabled']) && $field['#attributes']['disabled'] == 'disabled') {
  1288. return $field;
  1289. }
  1290. drupal_add_js(array('ckeditor' => array('textarea_default_format' => array($field['#id'] => $format))), 'setting');
  1291. if (!isset($processed_ids[$field['#id']])) {
  1292. $processed_ids[$field['#id']] = array();
  1293. }
  1294. $global_profile = ckeditor_profile_load('CKEditor Global Profile');
  1295. $profile = ckeditor_get_profile($format);
  1296. $host = base_path();
  1297. if ($profile === FALSE) {
  1298. $ckeditor_in_default_format = FALSE;
  1299. foreach ((array) $format_arr['#options'] as $key => $val) {
  1300. if ($key == $format)
  1301. continue;
  1302. if ($profile = ckeditor_get_profile($key)) {
  1303. $use_ckeditor = $key;
  1304. break;
  1305. }
  1306. }
  1307. if ($use_ckeditor === FALSE) {
  1308. return $field;
  1309. }
  1310. }
  1311. else {
  1312. $ckeditor_in_default_format = TRUE;
  1313. }
  1314. $settings = FALSE;
  1315. if ($settings = ckeditor_profiles_compile($format)) {
  1316. $ckeditor_on = ($profile->settings['default'] == 't') ? TRUE : FALSE;
  1317. }
  1318. elseif ($settings = ckeditor_profiles_compile($use_ckeditor)) {
  1319. $ckeditor_on = FALSE;
  1320. }
  1321. else {
  1322. return $field;
  1323. }
  1324. // Attach the editor css.
  1325. $field['#attached']['css'][] = drupal_get_path('module', 'ckeditor') . '/css/ckeditor.editor.css';
  1326. if ($settings) {
  1327. $textarea_id = $field['#id'];
  1328. $class[] = 'ckeditor-mod';
  1329. $_ckeditor_ids[] = $textarea_id;
  1330. //settings are saved as strings, not booleans
  1331. if ($settings['show_toggle'] == 't' && $show_toggle) {
  1332. if ($add_fields_to_toggle !== FALSE) {
  1333. if (is_array($add_fields_to_toggle)) {
  1334. $toggle_fields = "['" . $textarea_id . "','" . implode("','", $add_fields_to_toggle) . "']";
  1335. }
  1336. else {
  1337. $toggle_fields = "['" . $textarea_id . "','" . $add_fields_to_toggle . "']";
  1338. }
  1339. }
  1340. else {
  1341. $toggle_fields = "['{$textarea_id}']";
  1342. }
  1343. $wysiwyg_link = '';
  1344. $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}\">";
  1345. $wysiwyg_link .= $ckeditor_on ? t('Switch to plain text editor') : t('Switch to rich text editor');
  1346. $wysiwyg_link .= '</a>';
  1347. // Make sure to append to #suffix so it isn't completely overwritten
  1348. $suffix .= $wysiwyg_link;
  1349. }
  1350. $editor_local_path = ckeditor_path('local');
  1351. $editor_url_path = ckeditor_path('url');
  1352. if (!$is_running) {
  1353. // By default sessions are not started automatically for anonymous users.
  1354. // Start one for editing content so that we had a consistent token that is used in XSS filter.
  1355. if (isset($field['#entity']) && !empty($field['#entity']->created) && empty($user->uid)) {
  1356. drupal_session_start();
  1357. $_SESSION['ckeditor_anonymous_user'] = true;
  1358. drupal_page_is_cacheable(FALSE);
  1359. }
  1360. if (!$ckeditor_in_default_format) {
  1361. $load_method = 'ckeditor_basic.js';
  1362. $load_time_out = 0;
  1363. }
  1364. elseif (isset($profile->settings['ckeditor_load_method'])) {
  1365. $load_method = $profile->settings['ckeditor_load_method'];
  1366. $load_time_out = $profile->settings['ckeditor_load_time_out'];
  1367. }
  1368. if ($editor_local_path != '<URL>') {
  1369. drupal_add_js('window.CKEDITOR_BASEPATH = "' . ckeditor_path('relative') . '/"', array('type' => 'inline', 'weight' => -100));
  1370. }
  1371. drupal_add_js(ckeditor_module_path('url') . '/includes/ckeditor.utils.js', array('type' => 'file', 'scope' => 'footer'));
  1372. $preprocess = FALSE;
  1373. if (isset($global_profile->settings['ckeditor_aggregate']) && $global_profile->settings['ckeditor_aggregate'] == 't') {
  1374. $preprocess = TRUE;
  1375. }
  1376. if ($editor_local_path == '<URL>') {
  1377. drupal_add_js($editor_url_path . '/ckeditor.js', array('type' => 'external', 'scope' => 'footer'));
  1378. }
  1379. else if (isset($load_method) && file_exists($editor_local_path . '/' . $load_method)) {
  1380. drupal_add_js($editor_url_path . '/' . $load_method, array('type' => 'file', 'scope' => 'footer', 'preprocess' => $preprocess));
  1381. if ($load_method == 'ckeditor_basic.js') {
  1382. drupal_add_js('CKEDITOR.loadFullCoreTimeout = ' . $load_time_out . ';', array('type' => 'inline', 'scope' => 'footer'));
  1383. drupal_add_js(array('ckeditor' => array('load_timeout' => TRUE)), 'setting');
  1384. }
  1385. }
  1386. else {
  1387. drupal_add_js($editor_url_path . '/ckeditor.js', array('type' => 'file', 'scope' => 'footer', 'preprocess' => $preprocess));
  1388. }
  1389. $ckeditor_url = ckeditor_path('relative');
  1390. if ($ckeditor_url == '<URL>') {
  1391. $ckeditor_url = ckeditor_path('url');
  1392. }
  1393. $ckeditor_url .= '/';
  1394. drupal_add_js(array('ckeditor' => array('module_path' => ckeditor_module_path('relative'), 'editor_path' => $ckeditor_url)), 'setting');
  1395. if (module_exists('paging')) {
  1396. drupal_add_js(array('ckeditor' => array('pagebreak' => TRUE)), 'setting');
  1397. }
  1398. if (module_exists('linktocontent_node')) {
  1399. drupal_add_js(array('ckeditor' => array('linktocontent_node' => TRUE)), 'setting');
  1400. }
  1401. if (module_exists('linktocontent_menu')) {
  1402. drupal_add_js(array('ckeditor' => array('linktocontent_menu' => TRUE)), 'setting');
  1403. }
  1404. if (module_exists('pagebreak')) {
  1405. drupal_add_js(array('ckeditor' => array('pagebreak' => TRUE)), 'setting');
  1406. }
  1407. if (module_exists('smart_paging')) {
  1408. drupal_add_js(array('ckeditor' => array('pagebreak' => TRUE)), 'setting');
  1409. }
  1410. drupal_add_js(array('ckeditor' => array('ajaxToken' => drupal_get_token('ckeditorAjaxCall'), 'xss_url' => url('ckeditor/xss'))), 'setting');
  1411. $is_running = TRUE;
  1412. }
  1413. drupal_add_js(array('ckeditor' => array('theme' => $theme)), 'setting');
  1414. if (!empty($settings)) {
  1415. drupal_add_js(array('ckeditor' => array('elements' => array($textarea_id => $format))), 'setting');
  1416. }
  1417. if (!empty($ckeditor_on)) {
  1418. drupal_add_js(array('ckeditor' => array('autostart' => array($textarea_id => $ckeditor_on))), 'setting');
  1419. }
  1420. //[#1473010]
  1421. if (isset($settings['scayt_sLang'])) {
  1422. drupal_add_js(array('ckeditor' => array('scayt_language' => $settings['scayt_sLang'])), 'setting');
  1423. }
  1424. elseif (!empty($field["#language"]) && $field["#language"] != LANGUAGE_NONE) {
  1425. drupal_add_js(array('ckeditor' => array('scayt_language' => ckeditor_scayt_langcode($field["#language"]))), 'setting');
  1426. }
  1427. // Remember extra information and reuse it during "Preview"
  1428. $processed_ids[$field['#id']]['suffix'] = $suffix;
  1429. $processed_ids[$field['#id']]['class'] = $class;
  1430. if (empty($field['#suffix'])) {
  1431. $field['#suffix'] = $suffix;
  1432. }
  1433. else {
  1434. $field['#suffix'] .= $suffix;
  1435. }
  1436. if (empty($field['#attributes']['class'])) {
  1437. $field['#attributes']['class'] = $class;
  1438. }
  1439. else {
  1440. $field['#attributes']['class'] = array_merge($field['#attributes']['class'], $class);
  1441. }
  1442. }
  1443. return $field;
  1444. }
  1445. /**
  1446. * Return all modules that provide security filters.
  1447. */
  1448. function ckeditor_security_filters() {
  1449. $security_filters = array();
  1450. $security_filters['modules'] = array(
  1451. 'htmLawed' => array(
  1452. 'title' => 'htmLawed',
  1453. 'project_page' => 'http://drupal.org/project/htmLawed',
  1454. 'weight' => 0,
  1455. 'installed' => FALSE,
  1456. 'filters' => array()
  1457. ),
  1458. 'htmltidy' => array(
  1459. 'title' => 'Htmltidy',
  1460. 'project_page' => 'http://drupal.org/project/htmltidy',
  1461. 'weight' => 0,
  1462. 'installed' => FALSE,
  1463. 'filters' => array()
  1464. ),
  1465. 'htmlpurifier' => array(
  1466. 'title' => 'HTML Purifier',
  1467. 'project_page' => 'http://drupal.org/project/htmlpurifier',
  1468. 'weight' => 0,
  1469. 'installed' => FALSE,
  1470. 'filters' => array()
  1471. ),
  1472. 'wysiwyg_filter' => array(
  1473. 'title' => 'WYSIWYG Filter',
  1474. 'project_page' => 'http://drupal.org/project/wysiwyg_filter',
  1475. 'weight' => 0,
  1476. 'installed' => FALSE,
  1477. 'filters' => array()
  1478. )
  1479. );
  1480. $security_filters['filters'] = array();
  1481. foreach ($security_filters['modules'] as $module_name => $module_conf) {
  1482. if (module_exists($module_name)) {
  1483. $security_filters['modules'][$module_name]['installed'] = TRUE;
  1484. $module_filters = module_invoke($module_name, 'filter_info');
  1485. foreach ($module_filters as $module_filter_name => $module_filter_conf) {
  1486. $security_filters['modules'][$module_name]['filters'][$module_filter_name] = $module_filter_conf;
  1487. $security_filters['filters'][$module_filter_name] = TRUE;
  1488. }
  1489. }
  1490. }
  1491. //add filters from Drupal core
  1492. $security_filters['modules']['__drupal'] = array(
  1493. 'title' => 'Drupal core',
  1494. 'project_page' => FALSE,
  1495. 'weight' => -1,
  1496. 'installed' => TRUE,
  1497. 'filters' => array(
  1498. 'filter_html' => array(
  1499. 'title' => 'Limit allowed HTML tags',
  1500. 'description' => 'Removes the attributes that the built-in "Limit allowed HTML tags"-filter does not allow inside HTML elements/tags'
  1501. )
  1502. )
  1503. );
  1504. $security_filters['filters']['filter_html'] = TRUE;
  1505. //load security filters added by API
  1506. $external_module_filters = module_invoke_all('ckeditor_security_filter');
  1507. if (count($external_module_filters) > 0) {
  1508. $security_filters['modules']['__external'] = array(
  1509. 'title' => 'External filters',
  1510. 'project_page' => FALSE,
  1511. 'weight' => 1,
  1512. 'installed' => TRUE,
  1513. 'filters' => array()
  1514. );
  1515. foreach ($external_module_filters as $module_filter_name => $module_filter_conf) {
  1516. $security_filters['modules']['__external']['filters'][$module_filter_name] = $module_filter_conf;
  1517. $security_filters['filters'][$module_filter_name] = TRUE;
  1518. }
  1519. }
  1520. drupal_alter('ckeditor_security_filter', $security_filters);
  1521. return $security_filters;
  1522. }