PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/typo3/sysext/rtehtmlarea/class.tx_rtehtmlarea_base.php

https://bitbucket.org/linxpinx/mercurial
PHP | 1450 lines | 981 code | 102 blank | 367 comment | 191 complexity | 961eae06702e80e74fd5312fd868f609 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2004-2010 Kasper Skaarhoj (kasper@typo3.com)
  6. * (c) 2004-2010 Philipp Borgmann <philipp.borgmann@gmx.de>
  7. * (c) 2004-2010 Stanislas Rolland <typo3(arobas)sjbr.ca>
  8. * All rights reserved
  9. *
  10. * This script is part of the TYPO3 project. The TYPO3 project is
  11. * free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * The GNU General Public License can be found at
  17. * http://www.gnu.org/copyleft/gpl.html.
  18. * A copy is found in the textfile GPL.txt and important notices to the license
  19. * from the author is found in LICENSE.txt distributed with these scripts.
  20. *
  21. *
  22. * This script is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * This copyright notice MUST APPEAR in all copies of the script!
  28. ***************************************************************/
  29. /**
  30. * A RTE using the htmlArea editor
  31. *
  32. * @author Philipp Borgmann <philipp.borgmann@gmx.de>
  33. * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
  34. *
  35. * $Id: class.tx_rtehtmlarea_base.php 8504 2010-08-06 00:38:25Z stan $ *
  36. */
  37. class tx_rtehtmlarea_base extends t3lib_rteapi {
  38. // Configuration of supported browsers
  39. var $conf_supported_browser = array (
  40. 'msie' => array (
  41. 1 => array (
  42. 'version' => 6.0,
  43. 'system' => 'winNT'
  44. ),
  45. 2 => array (
  46. 'version' => 6.0,
  47. 'system' => 'win98'
  48. ),
  49. 3 => array (
  50. 'version' => 6.0,
  51. 'system' => 'win95'
  52. )
  53. ),
  54. 'gecko' => array (
  55. 1 => array (
  56. 'version' => 1.8
  57. )
  58. ),
  59. 'webkit' => array (
  60. 1 => array (
  61. 'version' => 523
  62. )
  63. ),
  64. 'opera' => array (
  65. 1 => array (
  66. 'version' => 9.62
  67. )
  68. )
  69. );
  70. // Always hide these toolbar buttons (TYPO3 button name)
  71. var $conf_toolbar_hide = array (
  72. 'showhelp', // Has no content yet
  73. );
  74. // The order of the toolbar: the name is the TYPO3-button name
  75. var $defaultToolbarOrder;
  76. // Conversion array: TYPO3 button names to htmlArea button names
  77. var $convertToolbarForHtmlAreaArray = array (
  78. 'showhelp' => 'ShowHelp',
  79. 'space' => 'space',
  80. 'bar' => 'separator',
  81. 'linebreak' => 'linebreak',
  82. );
  83. var $pluginButton = array();
  84. var $pluginLabel = array();
  85. // Alternative style for RTE <div> tag.
  86. public $RTEdivStyle;
  87. // Relative path to this extension. It ends with "/"
  88. public $extHttpPath;
  89. public $backPath = '';
  90. // TYPO3 site url
  91. public $siteURL;
  92. // TYPO3 host url
  93. public $hostURL;
  94. // Typo3 version
  95. public $typoVersion;
  96. // Identifies the RTE as being the one from the "rtehtmlarea" extension if any external code needs to know
  97. var $ID = 'rtehtmlarea';
  98. // If set, the content goes into a regular TEXT area field - for developing testing of transformations.
  99. var $debugMode = FALSE;
  100. // For the editor
  101. var $client;
  102. /**
  103. * Reference to parent object, which is an instance of the TCEforms
  104. *
  105. * @var t3lib_TCEforms
  106. */
  107. var $TCEform;
  108. var $elementId;
  109. var $elementParts;
  110. var $tscPID;
  111. var $typeVal;
  112. var $thePid;
  113. var $RTEsetup;
  114. var $thisConfig;
  115. var $confValues;
  116. public $language;
  117. public $contentTypo3Language;
  118. public $contentISOLanguage;
  119. public $contentCharset;
  120. public $OutputCharset;
  121. var $editorCSS;
  122. var $specConf;
  123. var $toolbar = array(); // Save the buttons for the toolbar
  124. var $toolbarOrderArray = array();
  125. protected $pluginEnabledArray = array(); // Array of plugin id's enabled in the current RTE editing area
  126. protected $pluginEnabledCumulativeArray = array(); // Cumulative array of plugin id's enabled so far in any of the RTE editing areas of the form
  127. protected $cumulativeScripts = array();
  128. public $registeredPlugins = array(); // Array of registered plugins indexed by their plugin Id's
  129. protected $fullScreen = false;
  130. /**
  131. * Returns true if the RTE is available. Here you check if the browser requirements are met.
  132. * If there are reasons why the RTE cannot be displayed you simply enter them as text in ->errorLog
  133. *
  134. * @return boolean TRUE if this RTE object offers an RTE in the current browser environment
  135. */
  136. function isAvailable() {
  137. global $TYPO3_CONF_VARS;
  138. $this->client = $this->clientInfo();
  139. $this->errorLog = array();
  140. if (!$this->debugMode) { // If debug-mode, let any browser through
  141. $rteIsAvailable = 0;
  142. $rteConfBrowser = $this->conf_supported_browser;
  143. if (is_array($rteConfBrowser)) {
  144. foreach ($rteConfBrowser as $browser => $browserConf) {
  145. if ($browser == $this->client['browser']) {
  146. // Config for Browser found, check it:
  147. if (is_array($browserConf)) {
  148. foreach ($browserConf as $browserConfNr => $browserConfSub) {
  149. if ($browserConfSub['version'] <= $this->client['version'] || empty($browserConfSub['version'])) {
  150. // Version is correct
  151. if ($browserConfSub['system'] == $this->client['system'] || empty($browserConfSub['system'])) {
  152. // System is correctly
  153. $rteIsAvailable = 1;
  154. }// End of System
  155. }// End of Version
  156. }// End of foreach-BrowserSubpart
  157. } else {
  158. // no config for this browser found, so all versions or system with this browsers are allow
  159. $rteIsAvailable = 1;
  160. }
  161. } // End of Browser Check
  162. } // foreach: Browser Check
  163. } else {
  164. // no Browser config for this RTE-Editor, so all Clients are allow
  165. }
  166. if (!$rteIsAvailable) {
  167. $this->errorLog[] = 'rte: Browser not supported. Only msie Version 5 or higher and Mozilla based client 1. and higher.';
  168. }
  169. if (t3lib_div::int_from_ver(TYPO3_version) < 4000000) {
  170. $rteIsAvailable = 0;
  171. $this->errorLog[] = 'rte: This version of htmlArea RTE cannot run under this version of TYPO3.';
  172. }
  173. }
  174. if ($rteIsAvailable) return true;
  175. }
  176. /**
  177. * Draws the RTE as an iframe
  178. *
  179. * @param object Reference to parent object, which is an instance of the TCEforms.
  180. * @param string The table name
  181. * @param string The field name
  182. * @param array The current row from which field is being rendered
  183. * @param array Array of standard content for rendering form fields from TCEforms. See TCEforms for details on this. Includes for instance the value and the form field name, java script actions and more.
  184. * @param array "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
  185. * @param array Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
  186. * @param string Record "type" field value.
  187. * @param string Relative path for images/links in RTE; this is used when the RTE edits content from static files where the path of such media has to be transformed forth and back!
  188. * @param integer PID value of record (true parent page id)
  189. * @return string HTML code for RTE!
  190. */
  191. function drawRTE($parentObject, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue) {
  192. global $BE_USER, $LANG, $TYPO3_DB, $TYPO3_CONF_VARS;
  193. $this->TCEform = $parentObject;
  194. $inline = $this->TCEform->inline;
  195. $LANG->includeLLFile('EXT:' . $this->ID . '/locallang.xml');
  196. $this->client = $this->clientInfo();
  197. $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version);
  198. $this->userUid = 'BE_' . $BE_USER->user['uid'];
  199. // Draw form element:
  200. if ($this->debugMode) { // Draws regular text area (debug mode)
  201. $item = parent::drawRTE($this->TCEform, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue);
  202. } else { // Draw real RTE
  203. /* =======================================
  204. * INIT THE EDITOR-SETTINGS
  205. * =======================================
  206. */
  207. // Set backPath
  208. $this->backPath = $this->TCEform->backPath;
  209. // Get the path to this extension:
  210. $this->extHttpPath = $this->backPath . t3lib_extMgm::extRelPath($this->ID);
  211. // Get the site URL
  212. $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
  213. // Get the host URL
  214. $this->hostURL = $this->siteURL . TYPO3_mainDir;
  215. // Element ID + pid
  216. $this->elementId = $PA['itemFormElName']; // Form element name
  217. $this->elementParts = explode('][',preg_replace('/\]$/','',preg_replace('/^(TSFE_EDIT\[data\]\[|data\[)/','',$this->elementId)));
  218. // Find the page PIDs:
  219. list($this->tscPID,$this->thePid) = t3lib_BEfunc::getTSCpid(trim($this->elementParts[0]),trim($this->elementParts[1]),$thePidValue);
  220. // Record "types" field value:
  221. $this->typeVal = $RTEtypeVal; // TCA "types" value for record
  222. // Find "thisConfig" for record/editor:
  223. unset($this->RTEsetup);
  224. $this->RTEsetup = $BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($this->tscPID));
  225. $this->thisConfig = $thisConfig;
  226. // Special configuration and default extras:
  227. $this->specConf = $specConf;
  228. if ($this->thisConfig['forceHTTPS']) {
  229. $this->extHttpPath = preg_replace('/^(http|https)/', 'https', $this->extHttpPath);
  230. $this->siteURL = preg_replace('/^(http|https)/', 'https', $this->siteURL);
  231. $this->hostURL = preg_replace('/^(http|https)/', 'https', $this->hostURL);
  232. }
  233. /* =======================================
  234. * LANGUAGES & CHARACTER SETS
  235. * =======================================
  236. */
  237. // Languages: interface and content
  238. $this->language = $LANG->lang;
  239. if ($this->language=='default' || !$this->language) {
  240. $this->language='en';
  241. }
  242. $this->contentTypo3Language = $this->language;
  243. $this->contentISOLanguage = 'en';
  244. $this->contentLanguageUid = ($row['sys_language_uid'] > 0) ? $row['sys_language_uid'] : 0;
  245. if (t3lib_extMgm::isLoaded('static_info_tables')) {
  246. if ($this->contentLanguageUid) {
  247. $tableA = 'sys_language';
  248. $tableB = 'static_languages';
  249. $languagesUidsList = $this->contentLanguageUid;
  250. $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2,' . $tableB . '.lg_typo3';
  251. $tableAB = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
  252. $whereClause = $tableA . '.uid IN (' . $languagesUidsList . ') ';
  253. $whereClause .= t3lib_BEfunc::BEenableFields($tableA);
  254. $whereClause .= t3lib_BEfunc::deleteClause($tableA);
  255. $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause);
  256. while($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) {
  257. $this->contentISOLanguage = strtolower(trim($languageRow['lg_iso_2']).(trim($languageRow['lg_country_iso_2'])?'_'.trim($languageRow['lg_country_iso_2']):''));
  258. $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
  259. }
  260. } else {
  261. $this->contentISOLanguage = trim($this->thisConfig['defaultContentLanguage']) ? trim($this->thisConfig['defaultContentLanguage']) : 'en';
  262. $selectFields = 'lg_iso_2, lg_typo3';
  263. $tableAB = 'static_languages';
  264. $whereClause = 'lg_iso_2 = ' . $TYPO3_DB->fullQuoteStr(strtoupper($this->contentISOLanguage), $tableAB);
  265. $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause);
  266. while($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) {
  267. $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
  268. }
  269. }
  270. }
  271. // Character sets: interface and content
  272. $this->charset = $LANG->charSet;
  273. $this->OutputCharset = $this->charset;
  274. $this->contentCharset = $LANG->csConvObj->charSetArray[$this->contentTypo3Language];
  275. $this->contentCharset = $this->contentCharset ? $this->contentCharset : 'iso-8859-1';
  276. $this->origContentCharSet = $this->contentCharset;
  277. $this->contentCharset = (trim($TYPO3_CONF_VARS['BE']['forceCharset']) ? trim($TYPO3_CONF_VARS['BE']['forceCharset']) : $this->contentCharset);
  278. /* =======================================
  279. * TOOLBAR CONFIGURATION
  280. * =======================================
  281. */
  282. $this->initializeToolbarConfiguration();
  283. /* =======================================
  284. * SET STYLES
  285. * =======================================
  286. */
  287. $RTEWidth = isset($BE_USER->userTS['options.']['RTESmallWidth']) ? $BE_USER->userTS['options.']['RTESmallWidth'] : '530';
  288. $RTEHeight = isset($BE_USER->userTS['options.']['RTESmallHeight']) ? $BE_USER->userTS['options.']['RTESmallHeight'] : '380';
  289. $RTEWidth = $RTEWidth + ($this->TCEform->docLarge ? (isset($BE_USER->userTS['options.']['RTELargeWidthIncrement']) ? $BE_USER->userTS['options.']['RTELargeWidthIncrement'] : '150') : 0);
  290. $RTEWidth -= ($inline->getStructureDepth() > 0 ? ($inline->getStructureDepth()+1)*$inline->getLevelMargin() : 0);
  291. if (isset($this->thisConfig['RTEWidthOverride'])) {
  292. if (strstr($this->thisConfig['RTEWidthOverride'], '%')) {
  293. if ($this->client['browser'] != 'msie') {
  294. $RTEWidth = (intval($this->thisConfig['RTEWidthOverride']) > 0) ? $this->thisConfig['RTEWidthOverride'] : '100%';
  295. }
  296. } else {
  297. $RTEWidth = (intval($this->thisConfig['RTEWidthOverride']) > 0) ? intval($this->thisConfig['RTEWidthOverride']) : $RTEWidth;
  298. }
  299. }
  300. $RTEWidth = strstr($RTEWidth, '%') ? $RTEWidth : $RTEWidth . 'px';
  301. $RTEHeight = $RTEHeight + ($this->TCEform->docLarge ? (isset($BE_USER->userTS['options.']['RTELargeHeightIncrement']) ? $BE_USER->userTS['options.']['RTELargeHeightIncrement'] : 0) : 0);
  302. $RTEHeightOverride = intval($this->thisConfig['RTEHeightOverride']);
  303. $RTEHeight = ($RTEHeightOverride > 0) ? $RTEHeightOverride : $RTEHeight;
  304. $editorWrapWidth = '99%';
  305. $editorWrapHeight = '100%';
  306. $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:'.$RTEWidth.'; border: 1px solid black; padding: 2px 2px 2px 2px;';
  307. /* =======================================
  308. * LOAD CSS AND JAVASCRIPT
  309. * =======================================
  310. */
  311. // Preloading the pageStyle and including RTE skin stylesheets
  312. $this->addPageStyle();
  313. $this->addSkin();
  314. // Loading JavaScript files and code
  315. if ($this->TCEform->RTEcounter == 1) {
  316. $this->TCEform->additionalJS_pre['rtehtmlarea-loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter);
  317. }
  318. $this->TCEform->additionalCode_pre['rtehtmlarea-loadJSfiles'] = $this->loadJSfiles($this->TCEform->RTEcounter);
  319. $pageRenderer = $GLOBALS['SOBE']->doc->getPageRenderer();
  320. $pageRenderer->enableExtJSQuickTips();
  321. if (!$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts']) {
  322. $pageRenderer->enableExtJsDebug();
  323. }
  324. /* =======================================
  325. * DRAW THE EDITOR
  326. * =======================================
  327. */
  328. // Transform value:
  329. $value = $this->transformContent('rte',$PA['itemFormElValue'],$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$thePidValue);
  330. // Further content transformation by registered plugins
  331. foreach ($this->registeredPlugins as $pluginId => $plugin) {
  332. if ($this->isPluginEnabled($pluginId) && method_exists($plugin, "transformContent")) {
  333. $value = $plugin->transformContent($value);
  334. }
  335. }
  336. // Register RTE windows
  337. $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
  338. $textAreaId = htmlspecialchars($PA['itemFormElName']);
  339. // Check if wizard_rte called this for fullscreen edtition; if so, change the size of the RTE to fullscreen using JS
  340. if (basename(PATH_thisScript) == 'wizard_rte.php') {
  341. $this->fullScreen = true;
  342. $editorWrapWidth = '100%';
  343. $editorWrapHeight = '100%';
  344. $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:100%; width:100%; border: 1px solid black; padding: 2px 0px 2px 2px;';
  345. }
  346. // Register RTE in JS:
  347. $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, $table, $row['uid'], $field, $textAreaId);
  348. // Set the save option for the RTE:
  349. $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
  350. $this->TCEform->additionalJS_delete[] = $this->setDeleteRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
  351. // Draw the textarea
  352. $visibility = 'hidden';
  353. $item = $this->triggerField($PA['itemFormElName']).'
  354. <div id="pleasewait' . $textAreaId . '" class="pleasewait" style="display: block;" >' . $LANG->getLL('Please wait') . '</div>
  355. <div id="editorWrap' . $textAreaId . '" class="editorWrap" style="visibility: hidden; width:' . $editorWrapWidth . '; height:' . $editorWrapHeight . ';">
  356. <textarea id="RTEarea' . $textAreaId . '" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.t3lib_div::deHSCentities(htmlspecialchars($this->RTEdivStyle)).'">'.t3lib_div::formatForTextarea($value).'</textarea>
  357. </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
  358. ';
  359. }
  360. // Return form item:
  361. return $item;
  362. }
  363. /**
  364. * Add link to content style sheet to document header
  365. *
  366. * @return void
  367. */
  368. protected function addPageStyle() {
  369. // Get stylesheet file name from Page TSConfig if any
  370. $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/res/contentcss/default.css';
  371. $this->addStyleSheet(
  372. 'rtehtmlarea-page-style',
  373. $this->getFullFileName($filename),
  374. 'htmlArea RTE Content CSS',
  375. 'alternate stylesheet'
  376. );
  377. }
  378. /**
  379. * Add links to skin style sheet(s) to document header
  380. *
  381. * @return void
  382. */
  383. protected function addSkin() {
  384. // Get skin file name from Page TSConfig if any
  385. $skinFilename = trim($this->thisConfig['skin']) ? trim($this->thisConfig['skin']) : 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
  386. $this->editorCSS = $this->getFullFileName($skinFilename);
  387. $skinDir = dirname($this->editorCSS);
  388. // Editing area style sheet
  389. $this->editedContentCSS = $skinDir . '/htmlarea-edited-content.css';
  390. $this->addStyleSheet(
  391. 'rtehtmlarea-editing-area-skin',
  392. $this->editedContentCSS
  393. );
  394. // Main skin
  395. $this->addStyleSheet(
  396. 'rtehtmlarea-skin',
  397. $this->editorCSS
  398. );
  399. // Additional icons from registered plugins
  400. foreach ($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] as $pluginId) {
  401. if (is_object($this->registeredPlugins[$pluginId])) {
  402. $pathToSkin = $this->registeredPlugins[$pluginId]->getPathToSkin();
  403. if ($pathToSkin) {
  404. $key = $this->registeredPlugins[$pluginId]->getExtensionKey();
  405. $this->addStyleSheet(
  406. 'rtehtmlarea-plugin-' . $pluginId . '-skin',
  407. ($this->is_FE() ? t3lib_extMgm::siteRelPath($key) : $this->backPath . t3lib_extMgm::extRelPath($key)) . $pathToSkin
  408. );
  409. }
  410. }
  411. }
  412. }
  413. /**
  414. * Add style sheet file to document header
  415. *
  416. * @param string $key: some key identifying the style sheet
  417. * @param string $href: uri to the style sheet file
  418. * @param string $title: value for the title attribute of the link element
  419. * @return string $relation: value for the rel attribute of the link element
  420. * @return void
  421. */
  422. protected function addStyleSheet($key, $href, $title='', $relation='stylesheet') {
  423. // If it was not known that an RTE-enabled would be created when the page was first created, the css would not be added to head
  424. if (is_object($this->TCEform->inline) && $this->TCEform->inline->isAjaxCall) {
  425. $this->TCEform->additionalCode_pre[$key] = '<link rel="' . $relation . '" type="text/css" href="' . $href . '" title="' . $title. '" />';
  426. } else {
  427. $pageRenderer = $GLOBALS['SOBE']->doc->getPageRenderer();
  428. $pageRenderer->addCssFile($href, $relation, 'screen', $title);
  429. }
  430. }
  431. /**
  432. * Initialize toolbar configuration and enable registered plugins
  433. *
  434. * @return void
  435. */
  436. protected function initializeToolbarConfiguration() {
  437. // Enable registred plugins
  438. $this->enableRegisteredPlugins();
  439. // Configure toolbar
  440. $this->setToolbar();
  441. // Check if some plugins need to be disabled
  442. $this->setPlugins();
  443. // Merge the list of enabled plugins with the lists from the previous RTE editing areas on the same form
  444. $this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] = $this->pluginEnabledArray;
  445. if ($this->TCEform->RTEcounter > 1 && isset($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1]) && is_array($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1])) {
  446. $this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] = array_unique(array_values(array_merge($this->pluginEnabledArray,$this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1])));
  447. }
  448. }
  449. /**
  450. * Add registered plugins to the array of enabled plugins
  451. *
  452. */
  453. function enableRegisteredPlugins() {
  454. global $TYPO3_CONF_VARS;
  455. // Traverse registered plugins
  456. if (is_array($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['plugins'])) {
  457. foreach($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['plugins'] as $pluginId => $pluginObjectConfiguration) {
  458. $plugin = false;
  459. if (is_array($pluginObjectConfiguration) && count($pluginObjectConfiguration)) {
  460. $plugin = t3lib_div::getUserObj($pluginObjectConfiguration['objectReference']);
  461. }
  462. if (is_object($plugin)) {
  463. if ($plugin->main($this)) {
  464. $this->registeredPlugins[$pluginId] = $plugin;
  465. // Override buttons from previously registered plugins
  466. $pluginButtons = t3lib_div::trimExplode(',', $plugin->getPluginButtons(), 1);
  467. foreach ($this->pluginButton as $previousPluginId => $buttonList) {
  468. $this->pluginButton[$previousPluginId] = implode(',',array_diff(t3lib_div::trimExplode(',', $this->pluginButton[$previousPluginId], 1), $pluginButtons));
  469. }
  470. $this->pluginButton[$pluginId] = $plugin->getPluginButtons();
  471. $pluginLabels = t3lib_div::trimExplode(',', $plugin->getPluginLabels(), 1);
  472. foreach ($this->pluginLabel as $previousPluginId => $labelList) {
  473. $this->pluginLabel[$previousPluginId] = implode(',',array_diff(t3lib_div::trimExplode(',', $this->pluginLabel[$previousPluginId], 1), $pluginLabels));
  474. }
  475. $this->pluginLabel[$pluginId] = $plugin->getPluginLabels();
  476. $this->pluginEnabledArray[] = $pluginId;
  477. }
  478. }
  479. }
  480. }
  481. // Process overrides
  482. $hidePlugins = array();
  483. foreach ($this->registeredPlugins as $pluginId => $plugin) {
  484. if ($plugin->addsButtons() && !$this->pluginButton[$pluginId]) {
  485. $hidePlugins[] = $pluginId;
  486. }
  487. }
  488. $this->pluginEnabledArray = array_unique(array_diff($this->pluginEnabledArray, $hidePlugins));
  489. }
  490. /**
  491. * Set the toolbar config (only in this PHP-Object, not in JS):
  492. *
  493. */
  494. function setToolbar() {
  495. global $BE_USER;
  496. if ($this->client['browser'] == 'msie' || $this->client['browser'] == 'opera') {
  497. $this->thisConfig['keepButtonGroupTogether'] = 0;
  498. }
  499. $this->defaultToolbarOrder = 'bar, blockstylelabel, blockstyle, space, textstylelabel, textstyle, linebreak,
  500. bar, formattext, bold, strong, italic, emphasis, big, small, insertedtext, deletedtext, citation, code, definition, keyboard, monospaced, quotation, sample, variable, bidioverride, strikethrough, subscript, superscript, underline, span,
  501. bar, fontstyle, space, fontsize, bar, formatblock, insertparagraphbefore, insertparagraphafter, blockquote, line,
  502. bar, left, center, right, justifyfull,
  503. bar, orderedlist, unorderedlist, definitionlist, definitionitem, outdent, indent, bar, lefttoright, righttoleft, language, showlanguagemarks,
  504. bar, textcolor, bgcolor, textindicator,
  505. bar, emoticon, insertcharacter, link, unlink, image, table,' . (($this->thisConfig['hideTableOperationsInToolbar'] && is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['toggleborders.']) && $this->thisConfig['buttons.']['toggleborders.']['keepInToolbar']) ? ' toggleborders,': '') . ' user, acronym, bar, findreplace, spellcheck,
  506. bar, chMode, inserttag, removeformat, bar, copy, cut, paste, bar, undo, redo, bar, showhelp, about, linebreak,
  507. ' . ($this->thisConfig['hideTableOperationsInToolbar'] ? '': 'bar, toggleborders,') . ' bar, tableproperties, tablerestyle, bar, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit, bar,
  508. columnproperties, columninsertbefore, columninsertafter, columndelete, columnsplit, bar,
  509. cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge';
  510. // Additional buttons from registered plugins
  511. foreach($this->registeredPlugins as $pluginId => $plugin) {
  512. if ($this->isPluginEnabled($pluginId)) {
  513. $this->defaultToolbarOrder = $plugin->addButtonsToToolbar();
  514. }
  515. }
  516. $toolbarOrder = $this->thisConfig['toolbarOrder'] ? $this->thisConfig['toolbarOrder'] : $this->defaultToolbarOrder;
  517. // Getting rid of undefined buttons
  518. $this->toolbarOrderArray = array_intersect(t3lib_div::trimExplode(',', $toolbarOrder, 1), t3lib_div::trimExplode(',', $this->defaultToolbarOrder, 1));
  519. $toolbarOrder = array_unique(array_values($this->toolbarOrderArray));
  520. // Fetching specConf for field from backend
  521. $pList = is_array($this->specConf['richtext']['parameters']) ? implode(',',$this->specConf['richtext']['parameters']) : '';
  522. if ($pList != '*') { // If not all
  523. $show = is_array($this->specConf['richtext']['parameters']) ? $this->specConf['richtext']['parameters'] : array();
  524. if ($this->thisConfig['showButtons']) {
  525. if (!t3lib_div::inList($this->thisConfig['showButtons'],'*')) {
  526. $show = array_unique(array_merge($show,t3lib_div::trimExplode(',',$this->thisConfig['showButtons'],1)));
  527. } else {
  528. $show = array_unique(array_merge($show, $toolbarOrder));
  529. }
  530. }
  531. if (is_array($this->thisConfig['showButtons.'])) {
  532. foreach ($this->thisConfig['showButtons.'] as $buttonId => $value) {
  533. if ($value) $show[] = $buttonId;
  534. }
  535. $show = array_unique($show);
  536. }
  537. } else {
  538. $show = $toolbarOrder;
  539. }
  540. // Resticting to RTEkeyList for backend user
  541. if(is_object($BE_USER)) {
  542. $RTEkeyList = isset($BE_USER->userTS['options.']['RTEkeyList']) ? $BE_USER->userTS['options.']['RTEkeyList'] : '*';
  543. if ($RTEkeyList != '*') { // If not all
  544. $show = array_intersect($show, t3lib_div::trimExplode(',',$RTEkeyList,1));
  545. }
  546. }
  547. // Hiding buttons of disabled plugins
  548. $hideButtons = array('space', 'bar', 'linebreak');
  549. foreach ($this->pluginButton as $pluginId => $buttonList) {
  550. if (!$this->isPluginEnabled($pluginId)) {
  551. $buttonArray = t3lib_div::trimExplode(',',$buttonList,1);
  552. foreach ($buttonArray as $button) {
  553. $hideButtons[] = $button;
  554. }
  555. }
  556. }
  557. // Hiding labels of disabled plugins
  558. foreach ($this->pluginLabel as $pluginId => $label) {
  559. if (!$this->isPluginEnabled($pluginId)) {
  560. $hideButtons[] = $label;
  561. }
  562. }
  563. // Hiding buttons
  564. $show = array_diff($show, $this->conf_toolbar_hide, t3lib_div::trimExplode(',',$this->thisConfig['hideButtons'],1));
  565. // Apply toolbar constraints from registered plugins
  566. foreach ($this->registeredPlugins as $pluginId => $plugin) {
  567. if ($this->isPluginEnabled($pluginId) && method_exists($plugin, "applyToolbarConstraints")) {
  568. $show = $plugin->applyToolbarConstraints($show);
  569. }
  570. }
  571. // Getting rid of the buttons for which we have no position
  572. $show = array_intersect($show, $toolbarOrder);
  573. $this->toolbar = $show;
  574. }
  575. /**
  576. * Disable some plugins
  577. *
  578. */
  579. function setPlugins() {
  580. // Disabling a plugin that adds buttons if none of its buttons is in the toolbar
  581. $hidePlugins = array();
  582. foreach ($this->pluginButton as $pluginId => $buttonList) {
  583. if ($this->registeredPlugins[$pluginId]->addsButtons()) {
  584. $showPlugin = false;
  585. $buttonArray = t3lib_div::trimExplode(',', $buttonList, 1);
  586. foreach ($buttonArray as $button) {
  587. if (in_array($button, $this->toolbar)) {
  588. $showPlugin = true;
  589. }
  590. }
  591. if (!$showPlugin) {
  592. $hidePlugins[] = $pluginId;
  593. }
  594. }
  595. }
  596. $this->pluginEnabledArray = array_diff($this->pluginEnabledArray, $hidePlugins);
  597. // Hiding labels of disabled plugins
  598. $hideLabels = array();
  599. foreach ($this->pluginLabel as $pluginId => $label) {
  600. if (!$this->isPluginEnabled($pluginId)) {
  601. $hideLabels[] = $label;
  602. }
  603. }
  604. $this->toolbar = array_diff($this->toolbar, $hideLabels);
  605. // Adding plugins declared as prerequisites by enabled plugins
  606. $requiredPlugins = array();
  607. foreach ($this->registeredPlugins as $pluginId => $plugin) {
  608. if ($this->isPluginEnabled($pluginId)) {
  609. $requiredPlugins = array_merge($requiredPlugins, t3lib_div::trimExplode(',', $plugin->getRequiredPlugins(), 1));
  610. }
  611. }
  612. $requiredPlugins = array_unique($requiredPlugins);
  613. foreach ($requiredPlugins as $pluginId) {
  614. if (is_object($this->registeredPlugins[$pluginId]) && !$this->isPluginEnabled($pluginId)) {
  615. $this->pluginEnabledArray[] = $pluginId;
  616. }
  617. }
  618. $this->pluginEnabledArray = array_unique($this->pluginEnabledArray);
  619. // Completing the toolbar conversion array for htmlArea
  620. foreach ($this->registeredPlugins as $pluginId => $plugin) {
  621. if ($this->isPluginEnabled($pluginId)) {
  622. $this->convertToolbarForHtmlAreaArray = array_unique(array_merge($this->convertToolbarForHtmlAreaArray, $plugin->getConvertToolbarForHtmlAreaArray()));
  623. }
  624. }
  625. }
  626. /**
  627. * Convert the TYPO3 names of buttons into the names for htmlArea RTE
  628. *
  629. * @param string buttonname (typo3-name)
  630. * @return string buttonname (htmlarea-name)
  631. */
  632. function convertToolbarForHTMLArea($button) {
  633. return $this->convertToolbarForHtmlAreaArray[$button];
  634. }
  635. /**
  636. * Return the HTML code for loading the Javascript files
  637. *
  638. * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
  639. *
  640. * @return string the html code for loading the Javascript Files
  641. */
  642. function loadJSfiles($RTEcounter) {
  643. // Re-initialize the scripts array so that only the cumulative set of plugins of the last RTE on the page is used
  644. $this->cumulativeScripts[$RTEcounter] = array();
  645. $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea.js', 'htmlarea', 'js', '', TRUE);
  646. if ($this->client['browser'] == 'msie') {
  647. $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea-ie.js', 'htmlarea-ie', 'js', '', TRUE);
  648. } else {
  649. $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea-gecko.js', 'htmlarea-gecko', 'js', '', TRUE);
  650. }
  651. foreach ($this->pluginEnabledCumulativeArray[$RTEcounter] as $pluginId) {
  652. $extensionKey = is_object($this->registeredPlugins[$pluginId]) ? $this->registeredPlugins[$pluginId]->getExtensionKey() : $this->ID;
  653. $this->writeTemporaryFile('EXT:' . $extensionKey . '/htmlarea/plugins/' . $pluginId . '/' . strtolower(preg_replace('/([a-z])([A-Z])([a-z])/', "$1".'-'."$2"."$3", $pluginId)) . '.js', $pluginId, 'js', '', TRUE);
  654. }
  655. $this->buildJSMainLangFile($RTEcounter);
  656. // Avoid re-initialization on AJax call when RTEarea object was already initialized
  657. $loadJavascriptCode = '
  658. <script type="text/javascript" src="' . $this->doConcatenate($RTEcounter) . '"></script>
  659. <script type="text/javascript">
  660. /*<![CDATA[*/
  661. if (typeof(RTEarea) == "undefined") {
  662. RTEarea = new Object();
  663. RTEarea[0] = new Object();
  664. RTEarea[0].version = "' . $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['version'] . '";
  665. RTEarea[0].editorUrl = "' . $this->extHttpPath . 'htmlarea/";
  666. RTEarea[0].editorCSS = "' . t3lib_div::createVersionNumberedFilename($this->editorCSS) . '";
  667. RTEarea[0].editorSkin = "' . dirname($this->editorCSS) . '/";
  668. RTEarea[0].editedContentCSS = "' . t3lib_div::createVersionNumberedFilename($this->editedContentCSS) . '";
  669. RTEarea[0].hostUrl = "' . $this->hostURL . '";
  670. RTEarea[0].enableDebugMode = ' . ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableDebugMode'] ? 'true' : 'false') . ';
  671. RTEarea.init = function() {
  672. if (typeof(HTMLArea) == "undefined" || !Ext.isReady) {
  673. window.setTimeout("RTEarea.init();", 40);
  674. } else {
  675. Ext.QuickTips.init();
  676. HTMLArea.init();
  677. }
  678. };
  679. RTEarea.initEditor = function(editorNumber) {
  680. if (typeof(HTMLArea) == "undefined") {
  681. RTEarea.initEditor.defer(40, null, [editorNumber]);
  682. } else {
  683. HTMLArea.initEditor(editorNumber);
  684. }
  685. };
  686. }
  687. /*]]>*/
  688. </script>';
  689. return $loadJavascriptCode;
  690. }
  691. /**
  692. * Return the Javascript code for initializing the RTE
  693. *
  694. * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
  695. *
  696. * @return string the Javascript code for initializing the RTE
  697. */
  698. function loadJScode($RTEcounter) {
  699. return (!$this->is_FE() ? '' : '
  700. ' . '/*<![CDATA[*/') . '
  701. RTEarea.init();' . (!$this->is_FE() ? '' : '
  702. /*]]>*/
  703. ');
  704. }
  705. /**
  706. * Return the Javascript code for configuring the RTE
  707. *
  708. * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
  709. * @param string $table: The table that includes this RTE (optional, necessary for IRRE).
  710. * @param string $uid: The uid of that table that includes this RTE (optional, necessary for IRRE).
  711. * @param string $field: The field of that record that includes this RTE (optional).
  712. *
  713. * @return string the Javascript code for configuring the RTE
  714. */
  715. function registerRTEinJS($RTEcounter, $table='', $uid='', $field='', $textAreaId = '') {
  716. $configureRTEInJavascriptString = (!$this->is_FE() ? '' : '
  717. ' . '/*<![CDATA[*/') . '
  718. if (typeof(configureEditorInstance) == "undefined") {
  719. configureEditorInstance = new Object();
  720. }
  721. configureEditorInstance["' . $textAreaId . '"] = function() {
  722. if (typeof(RTEarea) == "undefined" || typeof(HTMLArea) == "undefined") {
  723. window.setTimeout("configureEditorInstance[\'' . $textAreaId . '\']();", 40);
  724. } else {
  725. editornumber = "' . $textAreaId . '";
  726. RTEarea[editornumber] = new Object();
  727. RTEarea[editornumber].RTEtsConfigParams = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams()) . '";
  728. RTEarea[editornumber].number = editornumber;
  729. RTEarea[editornumber].deleted = false;
  730. RTEarea[editornumber].textAreaId = "' . $textAreaId . '";
  731. RTEarea[editornumber].id = "RTEarea" + editornumber;
  732. RTEarea[editornumber].RTEWidthOverride = "' . trim($this->thisConfig['RTEWidthOverride']) . '";
  733. RTEarea[editornumber].RTEHeightOverride = "' . trim($this->thisConfig['RTEHeightOverride']) . '";
  734. RTEarea[editornumber].fullScreen = ' . ($this->fullScreen ? 'true' : 'false') . ';
  735. RTEarea[editornumber].showStatusBar = ' . (trim($this->thisConfig['showStatusBar'])?'true':'false') . ';
  736. RTEarea[editornumber].enableWordClean = ' . (trim($this->thisConfig['enableWordClean'])?'true':'false') . ';
  737. RTEarea[editornumber].htmlRemoveComments = ' . (trim($this->thisConfig['removeComments'])?'true':'false') . ';
  738. RTEarea[editornumber].disableEnterParagraphs = ' . (trim($this->thisConfig['disableEnterParagraphs'])?'true':'false') . ';
  739. RTEarea[editornumber].disableObjectResizing = ' . (trim($this->thisConfig['disableObjectResizing'])?'true':'false') . ';
  740. RTEarea[editornumber].removeTrailingBR = ' . (trim($this->thisConfig['removeTrailingBR'])?'true':'false') . ';
  741. RTEarea[editornumber].useCSS = ' . (trim($this->thisConfig['useCSS'])?'true':'false') . ';
  742. RTEarea[editornumber].keepButtonGroupTogether = ' . (trim($this->thisConfig['keepButtonGroupTogether'])?'true':'false') . ';
  743. RTEarea[editornumber].disablePCexamples = ' . (trim($this->thisConfig['disablePCexamples'])?'true':'false') . ';
  744. RTEarea[editornumber].showTagFreeClasses = ' . (trim($this->thisConfig['showTagFreeClasses'])?'true':'false') . ';
  745. RTEarea[editornumber].useHTTPS = ' . ((trim(stristr($this->siteURL, 'https')) || $this->thisConfig['forceHTTPS'])?'true':'false') . ';
  746. RTEarea[editornumber].tceformsNested = ' . (is_object($this->TCEform) && method_exists($this->TCEform, 'getDynNestedStack') ? $this->TCEform->getDynNestedStack(true) : '[]') . ';
  747. RTEarea[editornumber].dialogueWindows = new Object();
  748. RTEarea[editornumber].dialogueWindows.defaultPositionFromTop = ' . (isset($this->thisConfig['dialogueWindows.']['defaultPositionFromTop'])? intval($this->thisConfig['dialogueWindows.']['defaultPositionFromTop']) : '100') . ';
  749. RTEarea[editornumber].dialogueWindows.defaultPositionFromLeft = ' . (isset($this->thisConfig['dialogueWindows.']['defaultPositionFromLeft'])? intval($this->thisConfig['dialogueWindows.']['defaultPositionFromLeft']) : '100') . ';
  750. RTEarea[editornumber].dialogueWindows.doNotResize = ' . (trim($this->thisConfig['dialogueWindows.']['doNotResize'])?'true':'false') . ';
  751. RTEarea[editornumber].dialogueWindows.doNotCenter = ' . (trim($this->thisConfig['dialogueWindows.']['doNotCenter'])?'true':'false') . ';';
  752. // The following properties apply only to the backend
  753. if (!$this->is_FE()) {
  754. $configureRTEInJavascriptString .= '
  755. RTEarea[editornumber].sys_language_content = "' . $this->contentLanguageUid . '";
  756. RTEarea[editornumber].typo3ContentLanguage = "' . $this->contentTypo3Language . '";
  757. RTEarea[editornumber].typo3ContentCharset = "' . $this->contentCharset . '";
  758. RTEarea[editornumber].userUid = "' . $this->userUid . '";';
  759. }
  760. // Setting the plugin flags
  761. $configureRTEInJavascriptString .= '
  762. RTEarea[editornumber].plugin = new Object();
  763. RTEarea[editornumber].pathToPluginDirectory = new Object();';
  764. foreach ($this->pluginEnabledArray as $pluginId) {
  765. $configureRTEInJavascriptString .= '
  766. RTEarea[editornumber].plugin.'.$pluginId.' = true;';
  767. if (is_object($this->registeredPlugins[$pluginId])) {
  768. $pathToPluginDirectory = $this->registeredPlugins[$pluginId]->getPathToPluginDirectory();
  769. if ($pathToPluginDirectory) {
  770. $configureRTEInJavascriptString .= '
  771. RTEarea[editornumber].pathToPluginDirectory.'.$pluginId.' = "' . $pathToPluginDirectory . '";';
  772. }
  773. }
  774. }
  775. // Setting the buttons configuration
  776. $configureRTEInJavascriptString .= '
  777. RTEarea[editornumber].buttons = new Object();';
  778. if (is_array($this->thisConfig['buttons.'])) {
  779. foreach ($this->thisConfig['buttons.'] as $buttonIndex => $conf) {
  780. $button = substr($buttonIndex, 0, -1);
  781. if (in_array($button,$this->toolbar)) {
  782. $configureRTEInJavascriptString .= '
  783. RTEarea[editornumber].buttons.'.$button.' = ' . $this->buildNestedJSArray($conf) . ';';
  784. }
  785. }
  786. }
  787. // Setting the list of tags to be removed if specified in the RTE config
  788. if (trim($this->thisConfig['removeTags'])) {
  789. $configureRTEInJavascriptString .= '
  790. RTEarea[editornumber].htmlRemoveTags = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTags'], 1)) . ')$/i;';
  791. }
  792. // Setting the list of tags to be removed with their contents if specified in the RTE config
  793. if (trim($this->thisConfig['removeTagsAndContents'])) {
  794. $configureRTEInJavascriptString .= '
  795. RTEarea[editornumber].htmlRemoveTagsAndContents = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTagsAndContents'], 1)) . ')$/i;';
  796. }
  797. // Process default style configuration
  798. $configureRTEInJavascriptString .= '
  799. RTEarea[editornumber].defaultPageStyle = "' . $this->writeTemporaryFile('', 'defaultPageStyle', 'css', $this->buildStyleSheet()) . '";';
  800. // Setting the pageStyle
  801. $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/res/contentcss/default.css';
  802. $configureRTEInJavascriptString .= '
  803. RTEarea[editornumber].pageStyle = "' . t3lib_div::createVersionNumberedFilename($this->getFullFileName($filename)) .'";';
  804. // Process classes configuration
  805. $classesConfigurationRequired = false;
  806. foreach ($this->registeredPlugins as $pluginId => $plugin) {
  807. if ($this->isPluginEnabled($pluginId)) {
  808. $classesConfigurationRequired = $classesConfigurationRequired || $plugin->requiresClassesConfiguration();
  809. }
  810. }
  811. if ($classesConfigurationRequired) {
  812. $configureRTEInJavascriptString .= $this->buildJSClassesConfig($RTEcounter);
  813. }
  814. // Add Javascript configuration for registered plugins
  815. foreach ($this->registeredPlugins as $pluginId => $plugin) {
  816. if ($this->isPluginEnabled($pluginId)) {
  817. $configureRTEInJavascriptString .= $plugin->buildJavascriptConfiguration('editornumber');
  818. }
  819. }
  820. // Avoid premature reference to HTMLArea when being initially loaded by IRRE Ajax call
  821. $configureRTEInJavascriptString .= '
  822. RTEarea[editornumber].toolbar = ' . $this->getJSToolbarArray() . ';
  823. RTEarea[editornumber].convertButtonId = ' . json_encode(array_flip($this->convertToolbarForHtmlAreaArray)) . ';
  824. RTEarea.initEditor(editornumber);
  825. }
  826. };
  827. configureEditorInstance["' . $textAreaId . '"]();'. (!$this->is_FE() ? '' : '
  828. /*]]>*/');
  829. return $configureRTEInJavascriptString;
  830. }
  831. /**
  832. * Return true, if the plugin can be loaded
  833. *
  834. * @param string $pluginId: The identification string of the plugin
  835. *
  836. * @return boolean true if the plugin can be loaded
  837. */
  838. function isPluginEnabled($pluginId) {
  839. return in_array($pluginId, $this->pluginEnabledArray);
  840. }
  841. /**
  842. * Build the default content style sheet
  843. *
  844. * @return string Style sheet
  845. */
  846. function buildStyleSheet() {
  847. if (!trim($this->thisConfig['ignoreMainStyleOverride'])) {
  848. $mainStyle_font = $this->thisConfig['mainStyle_font'] ? $this->thisConfig['mainStyle_font']: 'Verdana,sans-serif';
  849. $mainElements = array();
  850. $mainElements['P'] = $this->thisConfig['mainStyleOverride_add.']['P'];
  851. $elList = explode(',','H1,H2,H3,H4,H5,H6,PRE');
  852. foreach ($elList as $elListName) {
  853. if ($this->thisConfig['mainStyleOverride_add.'][$elListName]) {
  854. $mainElements[$elListName] = $this->thisConfig['mainStyleOverride_add.'][$elListName];
  855. }
  856. }
  857. $addElementCode = '';
  858. foreach ($mainElements as $elListName => $elValue) {
  859. $addElementCode .= strToLower($elListName) . ' {' . $elValue . '}' . LF;
  860. }
  861. $stylesheet = $this->thisConfig['mainStyleOverride'] ? $this->thisConfig['mainStyleOverride'] : LF .
  862. 'body.htmlarea-content-body { font-family: ' . $mainStyle_font .
  863. '; font-size: '.($this->thisConfig['mainStyle_size'] ? $this->thisConfig['mainStyle_size'] : '12px') .
  864. '; color: '.($this->thisConfig['mainStyle_color']?$this->thisConfig['mainStyle_color'] : 'black') .
  865. '; background-color: '.($this->thisConfig['mainStyle_bgcolor'] ? $this->thisConfig['mainStyle_bgcolor'] : 'white') .
  866. ';'.$this->thisConfig['mainStyleOverride_add.']['BODY'].'}' . LF .
  867. 'td { ' . $this->thisConfig['mainStyleOverride_add.']['TD'].'}' . LF .
  868. 'div { ' . $this->thisConfig['mainStyleOverride_add.']['DIV'].'}' . LF .
  869. 'pre { ' . $this->thisConfig['mainStyleOverride_add.']['PRE'].'}' . LF .
  870. 'ol { ' . $this->thisConfig['mainStyleOverride_add.']['OL'].'}' . LF .
  871. 'ul { ' . $this->thisConfig['mainStyleOverride_add.']['UL'].'}' . LF .
  872. 'blockquote { ' . $this->thisConfig['mainStyleOverride_add.']['BLOCKQUOTE'].'}' . LF .
  873. $addElementCode;
  874. if (is_array($this->thisConfig['inlineStyle.'])) {
  875. $stylesheet .= LF . implode(LF, $this->thisConfig['inlineStyle.']) . LF;
  876. }
  877. } else {
  878. $stylesheet = '/* mainStyleOverride and inlineStyle properties ignored. */';
  879. }
  880. return $stylesheet;
  881. }
  882. /**
  883. * Return Javascript configuration of classes
  884. *
  885. * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
  886. *
  887. * @return string Javascript configuration of classes
  888. */
  889. function buildJSClassesConfig($RTEcounter) {
  890. // Build JS array of lists of classes
  891. $classesTagList = 'classesCharacter, classesParagraph, classesImage, classesTable, classesLinks, classesTD';
  892. $classesTagConvert = array( 'classesCharacter' => 'span', 'classesParagraph' => 'div', 'classesImage' => 'img', 'classesTable' => 'table', 'classesLinks' => 'a', 'classesTD' => 'td');
  893. $classesTagArray = t3lib_div::trimExplode(',' , $classesTagList);
  894. $configureRTEInJavascriptString = '
  895. RTEarea[editornumber].classesTag = new Object();';
  896. foreach ($classesTagArray as $classesTagName) {
  897. $HTMLAreaJSClasses = ($this->thisConfig[$classesTagName])?('"' . $this->cleanList($this->thisConfig[$classesTagName]) . '";'):'null;';
  898. $configureRTEInJavascriptString .= '
  899. RTEarea[editornumber].classesTag.'. $classesTagConvert[$classesTagName] .' = '. $HTMLAreaJSClasses;
  900. }
  901. // Include JS arrays of configured classes
  902. $configureRTEInJavascriptString .= '
  903. RTEarea[editornumber].classesUrl = "' . $this->writeTemporaryFile('', 'classes_'.$LANG->lang, 'js', $this->buildJSClassesArray()) . '";';
  904. return $configureRTEInJavascriptString;
  905. }
  906. /**
  907. * Return JS arrays of classes configuration
  908. *
  909. * @return string JS classes arrays
  910. */
  911. function buildJSClassesArray() {
  912. if ($this->is_FE()) {
  913. $RTEProperties = $this->RTEsetup;
  914. } else {
  915. $RTEProperties = $this->RTEsetup['properties'];
  916. }
  917. $classesArray = array('labels' => array(), 'values' => array(), 'noShow' => array(), 'alternating' => array(), 'counting' => array(), 'XOR' => array());
  918. $JSClassesArray = '';
  919. // Scanning the list of classes if specified in the RTE config
  920. if (is_array($RTEProperties['classes.'])) {
  921. foreach ($RTEProperties['classes.'] as $className => $conf) {
  922. $className = rtrim($className, '.');
  923. $classesArray['labels'][$className] = $this->getPageConfigLabel($conf['name'], FALSE);
  924. $classesArray['values'][$className] = str_replace('\\\'', '\'', $conf['value']);
  925. if (isset($conf['noShow'])) {
  926. $classesArray['noShow'][$className] = $conf['noShow'];
  927. }
  928. if (is_array($conf['alternating.'])) {
  929. $classesArray['alternating'][$className] = $conf['alternating.'];
  930. }
  931. if (is_array($conf['counting.'])) {
  932. $classesArray['counting'][$className] = $conf['counting.'];
  933. }
  934. }
  935. }
  936. // Scanning the list of sets of mutually exclusives classes if specified in the RTE config
  937. if (is_array($RTEProperties['mutuallyExclusiveClasses.'])) {
  938. foreach ($RTEProperties['mutuallyExclusiveClasses.'] as $listName => $conf) {
  939. $classSet = t3lib_div::trimExplode(',', $conf, 1);
  940. $classList = implode(',', $classSet);
  941. foreach ($classSet as $className) {
  942. $classesArray['XOR'][$className] = '/^(' . implode('|', t3lib_div::trimExplode(',', t3lib_div::rmFromList($className, $classList), 1)) . ')$/';
  943. }
  944. }
  945. }
  946. foreach ($classesArray as $key => $subArray) {
  947. $JSClassesArray .= 'HTMLArea.classes' . ucfirst($key) . ' = ' . $this->buildNestedJSArray($subArray) . ';' . LF;
  948. }
  949. return $JSClassesArray;
  950. }
  951. /**
  952. * Translate Page TS Config array in JS nested array definition
  953. * Replace 0 values with false
  954. * Unquote regular expression values
  955. * Replace empty arrays with empty objects
  956. *
  957. * @param array $conf: Page TSConfig configuration array
  958. *
  959. * @return string nested JS array definition
  960. */
  961. function buildNestedJSArray($conf) {
  962. $convertedConf = t3lib_div::removeDotsFromTS($conf);
  963. if ($this->is_FE()) {
  964. $GLOBALS['TSFE']->csConvObj->convArray($convertedConf, ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : 'iso-8859-1'), 'utf-8');
  965. } else {
  966. $GLOBALS['LANG']->csConvObj->convArray($convertedConf, $GLOBALS['LANG']->charSet, 'utf-8');
  967. }
  968. return str_replace(array(':"0"', ':"\/^(', ')$\/i"', ':"\/^(', ')$\/"', '[]'), array(':false', ':/^(', ')$/i', ':/^(', ')$/', '{}'), json_encode($convertedConf));
  969. }
  970. /**
  971. * Return a Javascript localization array for htmlArea RTE
  972. *
  973. * @return string Javascript localization array
  974. */
  975. function buildJSMainLangArray() {
  976. $JSLanguageArray = 'HTMLArea.I18N = new Object();' . LF;
  977. $labelsArray = array('tooltips' => array(), 'msg' => array(), 'dialogs' => array());
  978. foreach ($labelsArray as $labels => $subArray) {
  979. $LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $this->ID . '/htmlarea/locallang_' . $labels . '.xml', $this->language, 'utf-8');
  980. if (!empty($LOCAL_LANG[$this->language])) {
  981. $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'], $LOCAL_LANG[$this->language]);
  982. } else {
  983. $LOCAL_LANG[$this->language] = $LOCAL_LANG['default'];
  984. }
  985. $labelsArray[$labels] = $LOCAL_LANG[$this->language];
  986. }
  987. $JSLanguageArray .= 'HTMLArea.I18N = ' . json_encode($labelsArray) . ';' . LF;
  988. return $JSLanguageArray;
  989. }
  990. /**
  991. * Writes contents in a file in typo3temp/rtehtmlarea directory and returns the file name
  992. *
  993. * @param string $sourceFileName: The name of the file from which the contents should be extracted
  994. * @param string $label: A label to insert at the beginning of the name of the file
  995. * @param string $fileExtension: The file extension of the file, defaulting to 'js'
  996. * @param string $contents: The contents to write into the file if no $sourceFileName is provided
  997. *
  998. * @return string The name of the file writtten to typo3temp/rtehtmlarea
  999. */
  1000. public function writeTemporaryFile($sourceFileName='', $label, $fileExtension='js', $contents='', $concatenate = FALSE) {
  1001. global $TYPO3_CONF_VARS;
  1002. if ($sourceFileName) {
  1003. $output = '';
  1004. $source = t3lib_div::getFileAbsFileName($sourceFileName);
  1005. $output = file_get_contents($source);
  1006. } else {
  1007. $output = $contents;
  1008. }
  1009. $compress = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] && ($fileExtension == 'js') && ($output != '');
  1010. $relativeFilename = 'typo3temp/' . $this->ID . '/' . str_replace('-','_',$label) . '_' . t3lib_div::shortMD5(($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . ($sourceFileName ? $sourceFileName : $output)), 20) . ($compress ? '_compressed' : '') . '.' . $fileExtension;
  1011. $destination = PATH_site . $relativeFilename;
  1012. if(!file_exists($destination)) {
  1013. $compressedJavaScript = '';
  1014. if ($compress && $fileExtension == 'js') {
  1015. $compressedJavaScript = t3lib_div::minifyJavaScript($output);
  1016. }
  1017. $failure = t3lib_div::writeFileToTypo3

Large files files are truncated, but you can click here to view the full file