PageRenderTime 201ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_jce/models/editor.php

https://github.com/cavila/Astica
PHP | 867 lines | 577 code | 140 blank | 150 comment | 94 complexity | eeaae7764d70055be3c5301dca4d30e6 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * @version $Id: editor.php 256 2011-06-30 09:36:47Z happy_noodle_boy $
  4. * @package JCE
  5. * @copyright Copyright Š 2009-2011 Ryan Demmer. All rights reserved.
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL 2 or later
  8. * This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. */
  13. // Check to ensure this file is included in Joomla!
  14. defined('_JEXEC') or die();
  15. wfimport('admin.classes.text');
  16. wfimport('admin.helpers.xml');
  17. wfimport('admin.helpers.extension');
  18. wfimport('editor.libraries.classes.token');
  19. wfimport('editor.libraries.classes.editor');
  20. class WFModelEditor extends JModel
  21. {
  22. public function buildEditor()
  23. {
  24. // get document
  25. $document = JFactory::getDocument();
  26. $wf = WFEditor::getInstance();
  27. // get current component
  28. $option = JRequest::getCmd('option');
  29. $component = WFExtensionHelper::getComponent(null, $option);
  30. // get default settings
  31. $settings = $this->getEditorSettings();
  32. // set default component id
  33. $component_id = 0;
  34. $component_id = isset($component->extension_id) ? $component->extension_id : ($component->id ? $component->id : 0);
  35. $version = $this->getVersion();
  36. // settings array for jce, tinymce etc
  37. $init = array();
  38. $profile = $wf->getProfile();
  39. if ($profile) {
  40. // get jqueryui theme
  41. $dialog_theme = $wf->getParam('editor.dialog_theme', 'jce');
  42. $dialog_theme_css = JFolder::files(WF_EDITOR_LIBRARIES . DS . 'css' . DS . 'jquery' . DS . $dialog_theme, '\.css$');
  43. $settings = array_merge($settings, array(
  44. 'theme' => 'advanced',
  45. 'component_id' => $component_id,
  46. 'plugins' => $this->getPlugins()
  47. ), $this->getToolbar($profile->rows));
  48. // Theme and skins
  49. $theme = array(
  50. 'toolbar_location' => array(
  51. 'top',
  52. 'bottom'
  53. ),
  54. 'toolbar_align' => array(
  55. 'left',
  56. 'center'
  57. ),
  58. 'statusbar_location' => array(
  59. 'bottom',
  60. 'top'
  61. ),
  62. 'path' => array(
  63. 1,
  64. 1
  65. ),
  66. 'resizing' => array(
  67. 1,
  68. 0
  69. ),
  70. 'resize_horizontal' => array(
  71. 1,
  72. 1
  73. ),
  74. 'resizing_use_cookie' => array(1, 1)
  75. );
  76. foreach ($theme as $k => $v) {
  77. $settings['theme_advanced_' . $k] = $wf->getParam('editor.' . $k, $v[0], $v[1]);
  78. }
  79. if (!$wf->getParam('editor.use_cookies', 1)) {
  80. $settings['theme_advanced_resizing_use_cookie'] = 0;
  81. }
  82. $settings['width'] = $wf->getParam('editor.width');
  83. $settings['height'] = $wf->getParam('editor.height');
  84. // 'Look & Feel'
  85. $settings['jquery_ui'] = JURI::root(true) . '/components/com_jce/editor/libraries/css/jquery/' . $dialog_theme . '/' . basename($dialog_theme_css[0]);
  86. $skin = explode('.', $wf->getParam('editor.toolbar_theme', 'default', 'default'));
  87. $settings['skin'] = $skin[0];
  88. $settings['skin_variant'] = isset($skin[1]) ? $skin[1] : '';
  89. $settings['body_class'] = $wf->getParam('editor.content_style_reset', $wf->getParam('editor.highcontrast', 0)) == 1 ? 'mceContentReset' : '';
  90. $settings['body_id'] = $wf->getParam('editor.body_id', '');
  91. $settings['content_css'] = $this->getStyleSheets();
  92. // Editor Toggle
  93. $settings['toggle'] = $wf->getParam('editor.toggle', 1, 1);
  94. $settings['toggle_label'] = htmlspecialchars($wf->getParam('editor.toggle_label', '[show/hide]', '[show/hide]'));
  95. $settings['toggle_state'] = $wf->getParam('editor.toggle_state', 1, 1);
  96. // elements
  97. // Get Extended elements
  98. $settings['extended_valid_elements'] = $wf->getParam('editor.extended_elements', '', '');
  99. // Configuration list of invalid elements as array
  100. $settings['invalid_elements'] = explode(',', $wf->getParam('editor.invalid_elements', 'applet', ''));
  101. // Add elements to invalid list (removed by plugin)
  102. $this->addKeys($settings['invalid_elements'], array(
  103. 'iframe',
  104. 'object',
  105. 'param',
  106. 'embed',
  107. 'audio',
  108. 'video',
  109. 'source',
  110. 'script',
  111. 'style'
  112. ));
  113. }// end profile
  114. //Other - user specified
  115. $userParams = $wf->getParam('editor.custom_config', '');
  116. $baseParams = array (
  117. 'mode',
  118. 'cleanup_callback',
  119. 'save_callback',
  120. 'file_browser_callback',
  121. 'urlconverter_callback',
  122. 'onpageload',
  123. 'oninit',
  124. 'editor_selector'
  125. );
  126. if ($userParams) {
  127. $userParams = explode(';', $userParams);
  128. foreach ($userParams as $userParam) {
  129. $keys = explode(':', $userParam);
  130. if (!in_array(trim($keys[0]), $baseParams)) {
  131. $settings[trim($keys[0])] = count($keys) > 1 ? trim($keys[1]) : '';
  132. }
  133. }
  134. }
  135. // set compression states
  136. $compress = array(
  137. 'javascript' => intval($wf->getParam('editor.compress_javascript', 0)),
  138. 'css' => intval($wf->getParam('editor.compress_css', 0))
  139. );
  140. // create token
  141. $token = WFToken::getToken();
  142. // set compression
  143. if ($compress['javascript']) {
  144. $document->addScript(JURI::base(true) . '/index.php?option=com_jce&view=editor&layout=editor&task=pack&component_id=' . $component_id . '&' . $token . '=1&version=' . $version);
  145. } else {
  146. $document->addScript($this->getURL(true) . '/tiny_mce/tiny_mce.js?version=' . $version);
  147. // Editor
  148. $document->addScript($this->getURL(true) . '/libraries/js/editor.js?version=' . $version);
  149. }
  150. // set compression
  151. if ($compress['css']) {
  152. $document->addStyleSheet(JURI::base(true) . '/index.php?option=com_jce&view=editor&layout=editor&task=pack&type=css&component_id=' . $component_id . '&' . $token . '=1&version=' . $version);
  153. } else {
  154. // CSS
  155. $document->addStyleSheet($this->getURL(true) . '/libraries/css/editor.css?version=' . $version);
  156. // get plugin styles
  157. $this->getPluginStyles($settings);
  158. }
  159. // Get all optional plugin configuration options
  160. $this->getPluginConfig($settings);
  161. // pass compresison states to settings
  162. $settings['compress'] = json_encode($compress);
  163. $output = "";
  164. $i = 1;
  165. foreach ($settings as $k => $v) {
  166. // If the value is an array, implode!
  167. if (is_array($v)) {
  168. $v = implode(',', $v);
  169. if ($v[0] == ',') {
  170. $v = substr($v, 1);
  171. }
  172. }
  173. // Value must be set
  174. if ($v !== '') {
  175. // objects or arrays or functions or regular expression
  176. if (preg_match('/(\[[^\]*]\]|\{[^\}]*\}|function\([^\}]*\}|^#(.*)#$)/', $v)) {
  177. // replace hash delimiters with / for javascript regular expression
  178. $v = preg_replace('@^#(.*)#$@', '/$1/', $v);
  179. }
  180. // anything that is not solely an integer
  181. else if (!is_numeric($v)) {
  182. $v = '"' . trim($v, '"') . '"';
  183. }
  184. $output .= "\t\t\t" . $k . ": " . $v . "";
  185. if ($i < count($settings)) {
  186. $output .= ",\n";
  187. }
  188. }
  189. // Must have 3 rows, even if 2 are blank!
  190. if (preg_match('/theme_advanced_buttons([1-3])/', $k) && $v == '') {
  191. $output .= "\t\t\t" . $k . ": \"\"";
  192. if ($i < count($settings)) {
  193. $output .= ",\n";
  194. }
  195. }
  196. $i++;
  197. }
  198. $tinymce = "{\n";
  199. $tinymce .= preg_replace('/,?\n?$/', '', $output) . "
  200. }";
  201. $init[] = $tinymce;
  202. $document->addScriptDeclaration("\t\ttry{WFEditor.init(" . implode(',', $init) . ");}catch(e){alert(e);}");
  203. if ($profile) {
  204. if ($wf->getParam('editor.callback_file')) {
  205. $document->addScript(JURI::root(true) . '/' . $callbackFile);
  206. }
  207. }
  208. }
  209. /**
  210. * Get the current version
  211. * @return Version
  212. */
  213. function getVersion()
  214. {
  215. // Get Component xml
  216. $xml = JApplicationHelper::parseXMLInstallFile(WF_ADMINISTRATOR . DS . 'jce.xml');
  217. // return cleaned version number or date
  218. $version = preg_replace('/[^0-9a-z]/i', '', $xml['version']);
  219. if (!$version) {
  220. return date('Y-m-d', strtotime('today'));
  221. }
  222. return $version;
  223. }
  224. /**
  225. * Get default settings array
  226. * @return array
  227. */
  228. public function getEditorSettings()
  229. {
  230. wfimport('editor.libraries.classes.token');
  231. $wf = WFEditor::getInstance();
  232. $settings = array(
  233. 'token' => WFToken::getToken(),
  234. 'base_url' => JURI::root(),
  235. 'language' => $wf->getLanguage(),
  236. 'directionality' => $wf->getLanguageDir(),
  237. 'theme' => 'none',
  238. 'invalid_elements' => 'applet,iframe,object,embed,script,style',
  239. 'plugins' => ''
  240. );
  241. return $settings;
  242. }
  243. /**
  244. * Return a list of icons for each JCE editor row
  245. *
  246. * @access public
  247. * @param string The number of rows
  248. * @return The row array
  249. */
  250. private function getToolbar($toolbar)
  251. {
  252. $model = JModel::getInstance('plugins', 'WFModel');
  253. $db = JFactory::getDBO();
  254. $rows = array(
  255. 'theme_advanced_buttons1' => '',
  256. 'theme_advanced_buttons2' => '',
  257. 'theme_advanced_buttons3' => ''
  258. );
  259. $plugins = $model->getPlugins();
  260. $commands = $model->getCommands();
  261. $icons = array_merge($commands, $plugins);
  262. $lists = explode(';', $toolbar);
  263. $x = 0;
  264. for ($i = 1; $i <= count($lists); $i++) {
  265. $items = array();
  266. foreach (explode(',', $lists[$x]) as $item) {
  267. if ($item == 'spacer') {
  268. $items[] = '|';
  269. } else {
  270. if (isset($icons[$item])) {
  271. $items[] = $icons[$item]->icon;
  272. }
  273. }
  274. }
  275. if (!empty($items)) {
  276. $rows['theme_advanced_buttons' . $i] = implode(',', $items);
  277. }
  278. $x++;
  279. }
  280. return $rows;
  281. }
  282. /**
  283. * Return a list of published JCE plugins
  284. *
  285. * @access public
  286. * @return string list
  287. */
  288. private function getPlugins()
  289. {
  290. $db = JFactory::getDBO();
  291. $wf = WFEditor::getInstance();
  292. jimport('joomla.filesystem.file');
  293. $plugins = array();
  294. $profile = $wf->getProfile();
  295. if (is_object($profile)) {
  296. $plugins = explode(',', $profile->plugins);
  297. $plugins = array_unique(array_merge($plugins, array(
  298. 'advlist',
  299. 'autolink',
  300. 'code',
  301. 'cleanup',
  302. 'format',
  303. 'lists',
  304. 'tabfocus',
  305. 'wordcount'
  306. )));
  307. $compress = $wf->getParam('editor.compress_javascript', 0);
  308. foreach ($plugins as $plugin) {
  309. $path = WF_EDITOR_PLUGINS . DS . $plugin;
  310. $language = $wf->getLanguage();
  311. if (!JFolder::exists($path) || !JFile::exists($path . DS . 'editor_plugin.js')) {
  312. $this->removeKeys($plugins, $plugin);
  313. }
  314. if (!$compress) {
  315. if ($language != 'en') {
  316. // new language file
  317. $new = $path . DS . 'langs' . DS . $language . '.js';
  318. // existing english file
  319. $en = $path . DS . 'langs' . DS . 'en.js';
  320. if (JFile::exists($en) && !JFile::exists($new)) {
  321. // remove plugin and throw error
  322. $this->removeKeys($plugins, $plugin);
  323. JError::raiseNotice('SOME_ERROR_CODE', sprintf(WFText::_('PLUGIN NOT LOADED : LANGUAGE FILE MISSING'), 'components/com_jce/editor/tiny_mce/plugins/' . $plugin . '/langs/' . $language . '.js') . ' - ' . ucfirst($plugin));
  324. }
  325. }
  326. }
  327. }
  328. }
  329. return $plugins;
  330. }
  331. /**
  332. * Get all loaded plugins config options
  333. *
  334. * @access public
  335. * @param array $settings passed by reference
  336. */
  337. function getPluginConfig(&$settings)
  338. {
  339. $plugins = $settings['plugins'];
  340. if ($plugins && is_array($plugins)) {
  341. foreach ($plugins as $plugin) {
  342. $file = WF_EDITOR_PLUGINS . DS . $plugin . DS . 'classes' . DS . 'config.php';
  343. if (file_exists($file)) {
  344. require_once($file);
  345. // Create class name
  346. $classname = 'WF' . ucfirst($plugin) . 'PluginConfig';
  347. // Check class and method
  348. if (class_exists($classname) && method_exists(new $classname, 'getConfig')) {
  349. call_user_func_array(array($classname, 'getConfig'), array(&$settings));
  350. }
  351. }
  352. }
  353. }
  354. }
  355. /**
  356. * Get all loaded plugins styles
  357. *
  358. * @access public
  359. * @param array $settings passed by reference
  360. */
  361. function getPluginStyles($settings)
  362. {
  363. $plugins = $settings['plugins'];
  364. if ($plugins && is_array($plugins)) {
  365. foreach ($plugins as $plugin) {
  366. $file = WF_EDITOR_PLUGINS . DS . $plugin . DS . 'classes' . DS . 'config.php';
  367. if (file_exists($file)) {
  368. require_once($file);
  369. // Create class name
  370. $classname = 'WF' . ucfirst($plugin) . 'PluginConfig';
  371. // Check class and method
  372. if (class_exists($classname) && method_exists(new $classname, 'getStyles')) {
  373. call_user_func(array($classname, 'getStyles'));
  374. }
  375. }
  376. }
  377. }
  378. }
  379. /**
  380. * Remove keys from an array
  381. *
  382. * @return $array by reference
  383. * @param arrau $array Array to edit
  384. * @param array $keys Keys to remove
  385. */
  386. function removeKeys(&$array, $keys)
  387. {
  388. if (!is_array($keys)) {
  389. $keys = array(
  390. $keys
  391. );
  392. }
  393. $array = array_diff($array, $keys);
  394. }
  395. /**
  396. * Add keys to an array
  397. *
  398. * @return The string list with added key or the key
  399. * @param string The array
  400. * @param string The keys to add
  401. */
  402. function addKeys(&$array, $keys)
  403. {
  404. if (!is_array($keys)) {
  405. $keys = array(
  406. $keys
  407. );
  408. }
  409. $array = array_unique(array_merge($array, $keys));
  410. }
  411. /**
  412. * Get a list of editor font families
  413. *
  414. * @return string font family list
  415. * @param string $add Font family to add
  416. * @param string $remove Font family to remove
  417. */
  418. function getEditorFonts()
  419. {
  420. $wf = WFEditor::getInstance();
  421. $add = explode(';', $wf->getParam('editor.theme_advanced_fonts_add', ''));
  422. $remove = preg_split('/[;,]+/', $wf->getParam('editor.theme_advanced_fonts_remove', ''));
  423. // Default font list
  424. $fonts = array(
  425. 'Andale Mono=andale mono,times',
  426. 'Arial=arial,helvetica,sans-serif',
  427. 'Arial Black=arial black,avant garde',
  428. 'Book Antiqua=book antiqua,palatino',
  429. 'Comic Sans MS=comic sans ms,sans-serif',
  430. 'Courier New=courier new,courier',
  431. 'Georgia=georgia,palatino',
  432. 'Helvetica=helvetica',
  433. 'Impact=impact,chicago',
  434. 'Symbol=symbol',
  435. 'Tahoma=tahoma,arial,helvetica,sans-serif',
  436. 'Terminal=terminal,monaco',
  437. 'Times New Roman=times new roman,times',
  438. 'Trebuchet MS=trebuchet ms,geneva',
  439. 'Verdana=verdana,geneva',
  440. 'Webdings=webdings',
  441. 'Wingdings=wingdings,zapf dingbats'
  442. );
  443. if (count($remove)) {
  444. foreach ($fonts as $key => $value) {
  445. foreach ($remove as $gone) {
  446. if ($gone) {
  447. if (preg_match('/^' . $gone . '=/i', $value)) {
  448. // Remove family
  449. unset($fonts[$key]);
  450. }
  451. }
  452. }
  453. }
  454. }
  455. foreach ($add as $new) {
  456. // Add new font family
  457. if (preg_match('/([^\=]+)(\=)([^\=]+)/', trim($new)) && !in_array($new, $fonts)) {
  458. $fonts[] = $new;
  459. }
  460. }
  461. natcasesort($fonts);
  462. return implode(';', $fonts);
  463. }
  464. /**
  465. * Return the current site template name
  466. *
  467. * @access public
  468. */
  469. function getSiteTemplates()
  470. {
  471. $db = JFactory::getDBO();
  472. $app = JFactory::getApplication();
  473. $id = 0;
  474. if ($app->isSite()) {
  475. $menus = JSite::getMenu();
  476. $menu = $menus->getActive();
  477. if ($menu) {
  478. $id = isset($menu->template_style_id) ? $menu->template_style_id : $menu->id;
  479. }
  480. }
  481. // Joomla! 1.5
  482. if (WF_JOOMLA15) {
  483. $query = 'SELECT menuid as id, template'
  484. . ' FROM #__templates_menu'
  485. . ' WHERE client_id = 0'
  486. ;
  487. $db->setQuery($query);
  488. $templates = $db->loadObjectList();
  489. // Joomla! 1.6+
  490. } else {
  491. $query = 'SELECT id, template'
  492. . ' FROM #__template_styles'
  493. . ' WHERE client_id = 0'
  494. . ' AND home = 1'
  495. ;
  496. $db->setQuery($query);
  497. $templates = $db->loadObjectList();
  498. }
  499. $assigned = array();
  500. foreach ($templates as $template) {
  501. if ($id == $template->id) {
  502. array_unshift($assigned, $template->template);
  503. } else {
  504. $assigned[] = $template->template;
  505. }
  506. }
  507. // return templates
  508. return $assigned;
  509. }
  510. function getStyleSheets($absolute = false)
  511. {
  512. jimport('joomla.filesystem.folder');
  513. jimport('joomla.filesystem.file');
  514. $wf = WFEditor::getInstance();
  515. $path = '';
  516. $url = '';
  517. // get templates
  518. $templates = $this->getSiteTemplates();
  519. foreach($templates as $template) {
  520. // Template CSS
  521. $path = JPATH_SITE . DS . 'templates' . DS . $template . DS . 'css';
  522. // get the first path that exists
  523. if (is_dir($path)) {
  524. $url = "templates/" . $template . "/css";
  525. break;
  526. }
  527. $path = '';
  528. }
  529. $styles = '';
  530. $stylesheets = array();
  531. $files = array();
  532. if ($path) {
  533. // Joomla! 1.5 standard
  534. $file = 'template.css';
  535. $css = JFolder::files($path, '(base|core|template|template_css)\.css$', false, true);
  536. if (!empty($css)) {
  537. // use the first result
  538. $file = $css[0];
  539. }
  540. // check for php version
  541. if (JFile::exists($file . '.php')) {
  542. $file = $file . '.php';
  543. }
  544. $global = intval($wf->getParam('editor.content_css', 1));
  545. $profile = intval($wf->getParam('editor.profile_content_css', 2));
  546. // use getParam so result is cleaned
  547. $global_custom = $wf->getParam('editor.content_css_custom', '');
  548. // Replace $template variable with site template name
  549. $global_custom = str_replace('$template', $template, $global_custom);
  550. // explode to array
  551. $global_custom = explode(',', $global_custom);
  552. switch ($global) {
  553. // Custom template css files
  554. case 0:
  555. $files = $global_custom;
  556. break;
  557. // Template css (template.css or template_css.css)
  558. case 1:
  559. $files[] = $url . '/' . basename($file);
  560. break;
  561. // Nothing, use editors default stylesheet
  562. case 2:
  563. $files = array();
  564. break;
  565. }
  566. $profile_custom = $wf->getParam('editor.profile_content_css_custom', '');
  567. // Replace $template variable with site template name
  568. $profile_custom = str_replace('$template', $template, $profile_custom);
  569. // explode to array
  570. $profile_custom = explode(',', $profile_custom);
  571. switch ($profile) {
  572. // add to global config value
  573. case 0:
  574. $files = array_merge($files, $profile_custom);
  575. break;
  576. // overwrite global config value
  577. case 1:
  578. $files = $profile_custom;
  579. break;
  580. // inherit global config value
  581. case 2:
  582. break;
  583. }
  584. // get rid of duplicate css files
  585. $files = array_unique($files);
  586. $root = $absolute ? JPATH_SITE : JURI::root(true);
  587. // check each file and make array of stylesheets
  588. foreach ($files as $file) {
  589. if ($file && JFile::exists(JPATH_SITE . DS . $file)) {
  590. $stylesheets[] = $root . '/' . $file;
  591. }
  592. }
  593. // get rid of duplicate stylesheets
  594. $stylesheets = array_unique($stylesheets);
  595. // default editor stylesheet
  596. if ($global == 2 && !count($stylesheets)) {
  597. $styles = '';
  598. } else {
  599. if (count($stylesheets)) {
  600. $styles = implode(',', $stylesheets);
  601. }
  602. }
  603. }
  604. return $styles;
  605. }
  606. function getURL($relative = false)
  607. {
  608. if ($relative) {
  609. return JURI::root(true) . '/components/com_jce/editor';
  610. }
  611. return JURI::root() . 'components/com_jce/editor';
  612. }
  613. /**
  614. * Pack / compress editor files
  615. */
  616. public function pack()
  617. {
  618. // check token
  619. WFToken::checkToken('GET') or die('RESTRICTED');
  620. $wf = WFEditor::getInstance();
  621. require_once(JPATH_COMPONENT_ADMINISTRATOR . DS . 'classes' . DS . 'packer.php');
  622. $type = JRequest::getWord('type', 'javascript');
  623. // javascript
  624. $packer = new WFPacker(array(
  625. 'type' => $type
  626. ));
  627. $themes = 'none';
  628. $plugins = array();
  629. $languages = $wf->getLanguage();
  630. $suffix = JRequest::getWord('suffix', '');
  631. $component_id = JRequest::getInt('component_id', 0);
  632. if ($wf->checkUser()) {
  633. $themes = 'advanced';
  634. $plugins = $this->getPlugins();
  635. }
  636. $languages = explode(',', $languages);
  637. $themes = explode(',', $themes);
  638. // toolbar theme
  639. $toolbar = explode('.', $wf->getParam('editor.toolbar_theme', 'default'));
  640. if ($type == 'javascript') {
  641. $files = array();
  642. // add core file
  643. $files[] = WF_EDITOR . DS . "tiny_mce/tiny_mce" . $suffix . ".js";
  644. // Add core languages
  645. foreach ($languages as $language) {
  646. $file = WF_EDITOR . DS . "tiny_mce/langs/" . $language . ".js";
  647. if (!JFile::exists($file)) {
  648. $file = WF_EDITOR . DS . "tiny_mce/langs/en.js";
  649. }
  650. $files[] = $file;
  651. }
  652. // Add themes
  653. foreach ($themes as $theme) {
  654. $files[] = WF_EDITOR . DS . "tiny_mce/themes/" . $theme . "/editor_template" . $suffix . ".js";
  655. foreach ($languages as $language) {
  656. $file = WF_EDITOR . DS . "tiny_mce/themes/" . $theme . "/langs/" . $language . ".js";
  657. if (!JFile::exists($file)) {
  658. $file = WF_EDITOR . DS . "tiny_mce/themes/" . $theme . "/langs/en.js";
  659. }
  660. $files[] = $file;
  661. }
  662. }
  663. // Add plugins
  664. foreach ($plugins as $plugin) {
  665. $files[] = WF_EDITOR . DS . "tiny_mce/plugins/" . $plugin . "/editor_plugin" . $suffix . ".js";
  666. foreach ($languages as $language) {
  667. $file = WF_EDITOR . DS . "tiny_mce/plugins/" . $plugin . "/langs/" . $language . ".js";
  668. if (!JFile::exists($file)) {
  669. $file = WF_EDITOR . DS . "tiny_mce/plugins/" . $plugin . "/langs/en.js";
  670. }
  671. if (JFile::exists($file)) {
  672. $files[] = $file;
  673. }
  674. }
  675. }
  676. // add Editor file
  677. $files[] = WF_EDITOR . DS . 'libraries' . DS . 'js' . DS . 'editor.js';
  678. }
  679. if ($type == 'css') {
  680. $context = JRequest::getWord('context', 'editor');
  681. if ($context == 'content') {
  682. $files = array();
  683. $files[] = WF_EDITOR_THEMES . DS . $themes[0] . DS . 'skins' . DS . $toolbar[0] . DS . 'content.css';
  684. // get template stylesheets
  685. $styles = explode(',', $this->getStyleSheets(true));
  686. foreach ($styles as $style) {
  687. if (JFile::exists($style)) {
  688. $files[] = $style;
  689. }
  690. }
  691. // load content styles dor each plugin if they exist
  692. foreach ($plugins as $plugin) {
  693. $content = WF_EDITOR_PLUGINS . DS . $plugin . DS . 'css' . DS . 'content.css';
  694. if (JFile::exists($content)) {
  695. $files[] = $content;
  696. }
  697. }
  698. } else {
  699. $files = array();
  700. $files[] = WF_EDITOR_LIBRARIES . DS . 'css' . DS . 'editor.css';
  701. $dialog = $wf->getParam('editor.dialog_theme', 'jce');
  702. $files[] =WF_EDITOR_THEMES . DS . $themes[0] . DS . 'skins' . DS . $toolbar[0] . DS . 'ui.css';
  703. if (isset($toolbar[1])) {
  704. $files[] = WF_EDITOR_THEMES . DS . $themes[0] . DS . 'skins' . DS . $toolbar[0] . DS . 'ui_' . $toolbar[1] . '.css';
  705. }
  706. // get external styles from config class for each plugin
  707. foreach ($plugins as $plugin) {
  708. $class = WF_EDITOR_PLUGINS . DS . $plugin . DS . 'classes' . DS . 'config.php';
  709. if (JFile::exists($class)) {
  710. require_once($class);
  711. $classname = 'WF' . ucfirst($plugin) . 'PluginConfig';
  712. if (class_exists($classname) && method_exists(new $classname, 'getStyles')) {
  713. $files = array_merge($files, (array)call_user_func(array($classname, 'getStyles')));
  714. }
  715. }
  716. }
  717. }
  718. }
  719. $packer->setFiles($files);
  720. $packer->pack();
  721. }
  722. public function getToken($id)
  723. {
  724. return '<input type="hidden" id="wf_' . $id . '_token" name="' . WFToken::getToken() . '" value="1" />';
  725. }
  726. }
  727. ?>