ed36c4c7a857becfa36cadec21ef1389058bdfdc
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / class.tx_rtehtmlarea_base.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004 Kasper Skaarhoj (kasper@typo3.com)
6 * (c) 2004 Philipp Borgmann <philipp.borgmann@gmx.de>
7 * (c) 2004-2008 Stanislas Rolland <stanislas.rolland(arobas)fructifor.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 <stanislas.rolland(arobas)fructifor.ca>
34 *
35 * $Id$ *
36 */
37
38 require_once(PATH_t3lib.'class.t3lib_rteapi.php');
39 require_once(PATH_t3lib.'class.t3lib_cs.php');
40
41 class tx_rtehtmlarea_base extends t3lib_rteapi {
42
43 // Configuration of supported browsers
44 var $conf_supported_browser = array (
45 'msie' => array (
46 1 => array (
47 'version' => 5.5,
48 'system' => 'win'
49 )
50 ),
51 'gecko' => array (
52 1 => array (
53 'version' => 1.3
54 )
55 ),
56 'safari' => array (
57 1 => array (
58 'version' => 523
59 )
60 ),
61 'opera' => array (
62 1 => array (
63 'version' => 9
64 )
65 )
66 );
67
68 // Always hide these toolbar buttons (TYPO3 button name)
69 var $conf_toolbar_hide = array (
70 'showhelp', // Has no content yet
71 );
72
73 // Hide toolbar buttons not implemented in client browsers
74 var $hideButtonsFromClient = array (
75 'safari' => array('paste'),
76 'opera' => array('copy', 'cut', 'paste'),
77 );
78
79 // Always show these toolbar buttons (TYPO3 button name)
80 var $conf_toolbar_show = array (
81 'undo',
82 'redo',
83 //'showhelp',
84 'about',
85 );
86
87 // The order of the toolbar: the name is the TYPO3-button name
88 var $defaultToolbarOrder;
89
90 // The default hotkeys: the name is the TYPO3-button name
91 var $defaultHotKeyList = 'selectall, cleanword, undo, redo';
92
93 // Conversion array: TYPO3 button names to htmlArea button names
94 var $convertToolbarForHtmlAreaArray = array (
95 'line' => 'InsertHorizontalRule',
96 'cut' => 'Cut',
97 'copy' => 'Copy',
98 'paste' => 'Paste',
99 'chMode' => 'HtmlMode',
100 'showhelp' => 'ShowHelp',
101 'textindicator' => 'TextIndicator',
102 'space' => 'space',
103 'bar' => 'separator',
104 'linebreak' => 'linebreak',
105 'undo' => 'Undo',
106 'redo' => 'Redo',
107 );
108
109 var $pluginList = 'ContextMenu';
110 var $pluginButton = array();
111 var $pluginLabel = array();
112
113 // External:
114 var $RTEdivStyle; // Alternative style for RTE <div> tag.
115 var $extHttpPath; // full Path to this extension for http (so no Server path). It ends with "/"
116 var $siteURL; // TYPO3 site url
117 var $hostURL; // TYPO3 host url
118 var $typoVersion; // Typo3 version
119
120 // Internal, static:
121 var $ID = 'rtehtmlarea'; // Identifies the RTE as being the one from the "rte" extension if any external code needs to know...
122 var $debugMode = FALSE; // If set, the content goes into a regular TEXT area field - for developing testing of transformations. (Also any browser will load the field!)
123
124 // For the editor
125 var $client;
126
127 /**
128 * Reference to parent object, which is an instance of the TCEforms
129 *
130 * @var t3lib_TCEforms
131 */
132 var $TCEform;
133 var $elementId;
134 var $elementParts;
135 var $tscPID;
136 var $typeVal;
137 var $thePid;
138 var $RTEsetup;
139 var $thisConfig;
140 var $confValues;
141 var $language;
142 public $contentTypo3Language;
143 public $contentISOLanguage;
144 public $contentCharset;
145 var $BECharset;
146 var $OutputCharset;
147 var $editorCSS;
148 var $specConf;
149 var $toolbar = array(); // Save the buttons for the toolbar
150 var $toolbar_level_size; // The size for each level in the toolbar:
151 var $toolbarOrderArray = array();
152 protected $pluginEnabledArray = array(); // Array of plugin id's enabled in the current RTE editing area
153 protected $pluginEnabledCumulativeArray = array(); // Cumulative array of plugin id's enabled so far in any of the RTE editing areas of the form
154 protected $registeredPlugins = array(); // Array of registered plugins indexd by their plugin Id's
155
156 /**
157 * Returns true if the RTE is available. Here you check if the browser requirements are met.
158 * If there are reasons why the RTE cannot be displayed you simply enter them as text in ->errorLog
159 *
160 * @return boolean TRUE if this RTE object offers an RTE in the current browser environment
161 */
162
163 function isAvailable() {
164 global $TYPO3_CONF_VARS;
165
166 $this->client = $this->clientInfo();
167 $this->errorLog = array();
168 if (!$this->debugMode) { // If debug-mode, let any browser through
169 $rteIsAvailable = 0;
170 $rteConfBrowser = $this->conf_supported_browser;
171 if (!$TYPO3_CONF_VARS['EXTCONF']['rtehtmlarea']['enableInOpera9']) unset($rteConfBrowser['opera']);
172 if (is_array($rteConfBrowser)) {
173 foreach ($rteConfBrowser as $browser => $browserConf) {
174 if ($browser == $this->client['BROWSER']) {
175 // Config for Browser found, check it:
176 if (is_array($browserConf)) {
177 foreach ($browserConf as $browserConfNr => $browserConfSub) {
178 if ($browserConfSub['version'] <= $this->client['VERSION'] || empty($browserConfSub['version'])) {
179 // Version is correct
180 if ($browserConfSub['system'] == $this->client['SYSTEM'] || empty($browserConfSub['system'])) {
181 // System is correctly
182 $rteIsAvailable = 1;
183 }// End of System
184 }// End of Version
185 }// End of foreach-BrowserSubpart
186 } else {
187 // no config for this browser found, so all versions or system with this browsers are allow
188 $rteIsAvailable = 1;
189 }
190 } // End of Browser Check
191 } // foreach: Browser Check
192 } else {
193 // no Browser config for this RTE-Editor, so all Clients are allow
194 }
195 if (!$rteIsAvailable) {
196 $this->errorLog[] = 'rte: Browser not supported. Only msie Version 5 or higher and Mozilla based client 1. and higher.';
197 }
198 if (t3lib_div::int_from_ver(TYPO3_version) < 4000000) {
199 $rteIsAvailable = 0;
200 $this->errorLog[] = 'rte: This version of htmlArea RTE cannot run under this version of TYPO3.';
201 }
202 }
203 if ($rteIsAvailable) return true;
204 }
205
206 /**
207 * Draws the RTE as an iframe
208 *
209 * @param object Reference to parent object, which is an instance of the TCEforms.
210 * @param string The table name
211 * @param string The field name
212 * @param array The current row from which field is being rendered
213 * @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.
214 * @param array "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
215 * @param array Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
216 * @param string Record "type" field value.
217 * @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!
218 * @param integer PID value of record (true parent page id)
219 * @return string HTML code for RTE!
220 */
221
222 function drawRTE($parentObject, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue) {
223 global $BE_USER, $LANG, $TYPO3_DB, $TYPO3_CONF_VARS;
224
225 $this->TCEform =& $parentObject;
226 $inline =& $this->TCEform->inline;
227 $LANG->includeLLFile('EXT:' . $this->ID . '/locallang.xml');
228 $this->client = $this->clientInfo();
229 $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version);
230 $this->userUid = 'BE_' . $BE_USER->user['uid'];
231
232 // Draw form element:
233 if ($this->debugMode) { // Draws regular text area (debug mode)
234 $item = parent::drawRTE($this->TCEform, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue);
235 } else { // Draw real RTE
236
237 /* =======================================
238 * INIT THE EDITOR-SETTINGS
239 * =======================================
240 */
241
242 // first get the http-path to typo3:
243 $this->httpTypo3Path = substr( substr( t3lib_div::getIndpEnv('TYPO3_SITE_URL'), strlen( t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') ) ), 0, -1 );
244 if (strlen($this->httpTypo3Path) == 1) {
245 $this->httpTypo3Path = '/';
246 } else {
247 $this->httpTypo3Path .= '/';
248 }
249 // Get the path to this extension:
250 $this->extHttpPath = $this->httpTypo3Path . t3lib_extMgm::siteRelPath($this->ID);
251 // Get the site URL
252 $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
253 // Get the host URL
254 $this->hostURL = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
255
256 // Element ID + pid
257 $this->elementId = $PA['itemFormElName']; // Form element name
258 $this->elementParts = explode('][',ereg_replace('\]$','',ereg_replace('^(TSFE_EDIT\[data\]\[|data\[)','',$this->elementId)));
259
260 // Find the page PIDs:
261 list($this->tscPID,$this->thePid) = t3lib_BEfunc::getTSCpid(trim($this->elementParts[0]),trim($this->elementParts[1]),$thePidValue);
262
263 // Record "types" field value:
264 $this->typeVal = $RTEtypeVal; // TCA "types" value for record
265
266 // Find "thisConfig" for record/editor:
267 unset($this->RTEsetup);
268 $this->RTEsetup = $BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($this->tscPID));
269 $this->thisConfig = $thisConfig;
270
271 // Special configuration and default extras:
272 $this->specConf = $specConf;
273
274 if ($this->thisConfig['forceHTTPS']) {
275 $this->httpTypo3Path = preg_replace('/^(http|https)/', 'https', $this->httpTypo3Path);
276 $this->extHttpPath = preg_replace('/^(http|https)/', 'https', $this->extHttpPath);
277 $this->siteURL = preg_replace('/^(http|https)/', 'https', $this->siteURL);
278 $this->hostURL = preg_replace('/^(http|https)/', 'https', $this->hostURL);
279 }
280
281 /* =======================================
282 * LANGUAGES & CHARACTER SETS
283 * =======================================
284 */
285
286 // Languages: interface and content
287 $this->language = $LANG->lang;
288 if ($this->language=='default' || !$this->language) {
289 $this->language='en';
290 }
291 $this->contentTypo3Language = $this->language;
292
293 $this->contentLanguageUid = ($row['sys_language_uid'] > 0) ? $row['sys_language_uid'] : 0;
294 if (t3lib_extMgm::isLoaded('static_info_tables')) {
295 if ($this->contentLanguageUid) {
296 $tableA = 'sys_language';
297 $tableB = 'static_languages';
298 $languagesUidsList = $this->contentLanguageUid;
299 $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2,' . $tableB . '.lg_typo3';
300 $tableAB = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
301 $whereClause = $tableA . '.uid IN (' . $languagesUidsList . ') ';
302 $whereClause .= t3lib_BEfunc::BEenableFields($tableA);
303 $whereClause .= t3lib_BEfunc::deleteClause($tableA);
304 $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause);
305 while($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) {
306 $this->contentISOLanguage = strtolower(trim($languageRow['lg_iso_2']).(trim($languageRow['lg_country_iso_2'])?'_'.trim($languageRow['lg_country_iso_2']):''));
307 $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
308 }
309 } else {
310 $this->contentISOLanguage = trim($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['defaultDictionary']) ? trim($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['defaultDictionary']) : 'en';
311 $selectFields = 'lg_iso_2, lg_typo3';
312 $tableAB = 'static_languages';
313 $whereClause = 'lg_iso_2 = ' . $TYPO3_DB->fullQuoteStr(strtoupper($this->contentISOLanguage), $tableAB);
314 $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause);
315 while($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) {
316 $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
317 }
318 }
319 }
320
321 // Character sets: interface and content
322 $this->charset = $LANG->csConvObj->charSetArray[$this->language];
323 $this->charset = $this->charset ? $this->charset : 'iso-8859-1';
324 $this->BECharset = trim($TYPO3_CONF_VARS['BE']['forceCharset']) ? trim($TYPO3_CONF_VARS['BE']['forceCharset']) : $this->charset;
325 $this->OutputCharset = $this->BECharset;
326
327 $this->contentCharset = $LANG->csConvObj->charSetArray[$this->contentTypo3Language];
328 $this->contentCharset = $this->contentCharset ? $this->contentCharset : 'iso-8859-1';
329 $this->origContentCharSet = $this->contentCharset;
330 $this->contentCharset = (trim($TYPO3_CONF_VARS['BE']['forceCharset']) ? trim($TYPO3_CONF_VARS['BE']['forceCharset']) : $this->contentCharset);
331
332 /* =======================================
333 * TOOLBAR CONFIGURATION
334 * =======================================
335 */
336
337 // htmlArea plugins list
338 $this->pluginEnabledArray = t3lib_div::trimExplode(',', $this->pluginList, 1);
339 $this->enableRegisteredPlugins();
340 $hidePlugins = array();
341 if ($this->client['BROWSER'] == 'msie') {
342 $this->thisConfig['keepButtonGroupTogether'] = 0;
343 }
344 if ($this->client['BROWSER'] == 'opera') {
345 $hidePlugins[] = 'ContextMenu';
346 $this->thisConfig['keepButtonGroupTogether'] = 0;
347 }
348 if ($this->client['BROWSER'] == 'gecko' && $this->client['VERSION'] == '1.3') {
349 $this->thisConfig['keepButtonGroupTogether'] = 0;
350 }
351 $this->pluginEnabledArray = array_diff($this->pluginEnabledArray, $hidePlugins);
352
353 // Toolbar
354 $this->setToolbar();
355
356 // Check if some plugins need to be disabled
357 $this->setPlugins();
358
359 // Merge the list of enabled plugins with the lists from the previous RTE editing areas on the same form
360 $this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] = $this->pluginEnabledArray;
361 if ($this->TCEform->RTEcounter > 1 && isset($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1]) && is_array($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1])) {
362 $this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] = array_unique(array_values(array_merge($this->pluginEnabledArray,$this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1])));
363 }
364
365 /* =======================================
366 * SET STYLES
367 * =======================================
368 */
369
370 $RTEWidth = isset($BE_USER->userTS['options.']['RTESmallWidth']) ? $BE_USER->userTS['options.']['RTESmallWidth'] : '530';
371 $RTEHeight = isset($BE_USER->userTS['options.']['RTESmallHeight']) ? $BE_USER->userTS['options.']['RTESmallHeight'] : '380';
372 $RTEWidth = $RTEWidth + ($this->TCEform->docLarge ? (isset($BE_USER->userTS['options.']['RTELargeWidthIncrement']) ? $BE_USER->userTS['options.']['RTELargeWidthIncrement'] : '150') : 0);
373 $RTEWidth -= ($inline->getStructureDepth() > 0 ? ($inline->getStructureDepth()+1)*$inline->getLevelMargin() : 0);
374 $RTEHeight = $RTEHeight + ($this->TCEform->docLarge ? (isset($BE_USER->userTS['options.']['RTELargeHeightIncrement']) ? $BE_USER->userTS['options.']['RTELargeHeightIncrement'] : 0) : 0);
375 $editorWrapWidth = $RTEWidth . 'px';
376 $editorWrapHeight = $RTEHeight . 'px';
377 $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:'.$RTEWidth.'px; border: 1px solid black; padding: 2px 0px 2px 2px;';
378 $this->toolbar_level_size = $RTEWidth;
379
380 /* =======================================
381 * LOAD CSS AND JAVASCRIPT
382 * =======================================
383 */
384
385 // Preloading the pageStyle
386 $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/res/contentcss/default.css';
387 $this->TCEform->additionalCode_pre['loadCSS'] = '
388 <link rel="alternate stylesheet" type="text/css" href="' . $this->getFullFileName($filename) . '" title="HTMLArea RTE Content CSS" />';
389
390 // Loading the editor skin
391 $skinFilename = trim($this->thisConfig['skin']) ? trim($this->thisConfig['skin']) : 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
392 if($this->client['BROWSER'] == 'gecko' && $this->client['VERSION'] == '1.3' && substr($skinFilename,0,4) == 'EXT:') {
393 $skinFilename = 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
394 }
395 if (substr($skinFilename,0,4) == 'EXT:') { // extension
396 list($extKey,$local) = explode('/',substr($skinFilename,4),2);
397 $skinFilename='';
398 if (strcmp($extKey,'') && t3lib_extMgm::isLoaded($extKey) && strcmp($local,'')) {
399 $skinFilename = $this->httpTypo3Path . t3lib_extMgm::siteRelPath($extKey) . $local;
400 $skinDir = $this->siteURL . t3lib_extMgm::siteRelPath($extKey) . dirname($local);
401 }
402 } elseif (substr($skinFilename,0,1) != '/') {
403 $skinDir = $this->siteURL.dirname($skinFilename);
404 $skinFilename = $this->siteURL . $skinFilename;
405 } else {
406 $skinDir = substr($this->siteURL,0,-1) . dirname($skinFilename);
407 }
408 $this->editorCSS = $skinFilename;
409 $this->editedContentCSS = $skinDir . '/htmlarea-edited-content.css';
410 $this->TCEform->additionalCode_pre['loadCSS'] .= '
411 <link rel="alternate stylesheet" type="text/css" href="' . $this->editedContentCSS . '" />';
412
413 // Main skin
414 $this->TCEform->additionalCode_pre['loadCSS'] .= '
415 <link rel="stylesheet" type="text/css" href="' . $this->editorCSS . '" />';
416
417 // Additional icons from registered plugins
418 foreach ($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] as $pluginId) {
419 if (is_object($this->registeredPlugins[$pluginId])) {
420 $pathToSkin = $this->registeredPlugins[$pluginId]->getPathToSkin();
421 if ($pathToSkin) {
422 $this->TCEform->additionalCode_pre['loadCSS'] .= '
423 <link rel="stylesheet" type="text/css" href="' . $this->httpTypo3Path . t3lib_extMgm::siteRelPath($this->registeredPlugins[$pluginId]->getExtensionKey()) . $pathToSkin . '" />';
424 }
425 }
426 }
427
428 // Loading JavaScript files and code
429 if ($this->TCEform->RTEcounter == 1) {
430 $this->TCEform->additionalCode_pre['loadJSfiles'] = $this->loadJSfiles($this->TCEform->RTEcounter);
431 $this->TCEform->additionalJS_pre['loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter);
432 }
433
434 /* =======================================
435 * DRAW THE EDITOR
436 * =======================================
437 */
438
439 // Transform value:
440 $value = $this->transformContent('rte',$PA['itemFormElValue'],$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$thePidValue);
441
442 // Further content transformation by registered plugins
443 foreach ($this->registeredPlugins as $pluginId => $plugin) {
444 if ($this->isPluginEnabled($pluginId) && method_exists($plugin, "transformContent")) {
445 $value = $plugin->transformContent($value);
446 }
447 }
448 // Register RTE windows
449 $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
450
451 // Check if wizard_rte called this for fullscreen edtition; if so, change the size of the RTE to fullscreen using JS
452 if (basename(PATH_thisScript) == 'wizard_rte.php') {
453 $height = 'window.innerHeight';
454 $width = 'window.innerWidth';
455 if ($this->client['BROWSER'] == 'msie') {
456 $height = 'document.body.offsetHeight';
457 $width = 'document.body.offsetWidth';
458 }
459 $editorWrapWidth = '100%';
460 $editorWrapHeight = '100%';
461 $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:100%; width:100%; border: 1px solid black; padding: 2px 0px 2px 2px;';
462 $this->TCEform->additionalJS_post[] = $this->setRTEsizeByJS('RTEarea'.$this->TCEform->RTEcounter, $height, $width);
463 }
464
465 // Register RTE in JS:
466 $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, $table, $row['uid'], $field);
467
468 // Set the save option for the RTE:
469 $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, htmlspecialchars($PA['itemFormElName']));
470
471 // Draw the textarea
472 $visibility = 'hidden';
473 $item = $this->triggerField($PA['itemFormElName']).'
474 <div id="pleasewait' . $this->TCEform->RTEcounter . '" class="pleasewait" style="display: none;" >' . $LANG->getLL('Please wait') . '</div>
475 <div id="editorWrap' . $this->TCEform->RTEcounter . '" class="editorWrap" style="width:' . $editorWrapWidth . '; height:' . $editorWrapHeight . ';">
476 <textarea id="RTEarea'.$this->TCEform->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.t3lib_div::deHSCentities(htmlspecialchars($this->RTEdivStyle)).'">'.t3lib_div::formatForTextarea($value).'</textarea>
477 </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
478 ';
479 }
480
481 // Return form item:
482 return $item;
483 }
484
485 /**
486 * Add registered plugins to the array of enabled plugins
487 *
488 */
489 function enableRegisteredPlugins() {
490 global $TYPO3_CONF_VARS;
491 // Traverse registered plugins
492 if (is_array($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['plugins'])) {
493 foreach($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['plugins'] as $pluginId => $pluginObjectConfiguration) {
494 $plugin = &t3lib_div::getUserObj($pluginObjectConfiguration['objectReference']);
495 if (is_object($plugin)) {
496 if ($plugin->main($this)) {
497 $this->registeredPlugins[$pluginId] = $plugin;
498 // Override buttons from previously registered plugins
499 $pluginButtons = t3lib_div::trimExplode(',', $plugin->getPluginButtons(), 1);
500 foreach ($this->pluginButton as $previousPluginId => $buttonList) {
501 $this->pluginButton[$previousPluginId] = implode(',',array_diff(t3lib_div::trimExplode(',', $this->pluginButton[$previousPluginId], 1), $pluginButtons));
502 }
503 $this->pluginButton[$pluginId] = $plugin->getPluginButtons();
504 $pluginLabels = t3lib_div::trimExplode(',', $plugin->getPluginLabels(), 1);
505 foreach ($this->pluginLabel as $previousPluginId => $labelList) {
506 $this->pluginLabel[$previousPluginId] = implode(',',array_diff(t3lib_div::trimExplode(',', $this->pluginLabel[$previousPluginId], 1), $pluginLabels));
507 }
508 $this->pluginLabel[$pluginId] = $plugin->getPluginLabels();
509 $this->pluginEnabledArray[] = $pluginId;
510 }
511 }
512 }
513 }
514 // Process overrides
515 $hidePlugins = array();
516 foreach ($this->registeredPlugins as $pluginId => $plugin) {
517 if (!$this->pluginButton[$pluginId]) {
518 $hidePlugins[] = $pluginId;
519 }
520 }
521 $this->pluginEnabledArray = array_diff($this->pluginEnabledArray, $hidePlugins);
522 }
523
524 /**
525 * Set the toolbar config (only in this PHP-Object, not in JS):
526 *
527 */
528
529 function setToolbar() {
530 global $BE_USER;
531
532 $this->defaultToolbarOrder = 'bar, blockstylelabel, blockstyle, space, textstylelabel, textstyle, linebreak,
533 bar, formattext, bold, strong, italic, emphasis, big, small, insertedtext, deletedtext, citation, code, definition, keyboard, monospaced, quotation, sample, variable, bidioverride, strikethrough, subscript, superscript, underline, span,
534 bar, fontstyle, space, fontsize, bar, formatblock, insertparagraphbefore, insertparagraphafter, blockquote,
535 bar, left, center, right, justifyfull,
536 bar, orderedlist, unorderedlist, outdent, indent, bar, lefttoright, righttoleft,
537 bar, textcolor, bgcolor, textindicator,
538 bar, emoticon, insertcharacter, line, 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,
539 bar, chMode, inserttag, removeformat, bar, copy, cut, paste, bar, undo, redo, bar, showhelp, about, linebreak,
540 ' . ($this->thisConfig['hideTableOperationsInToolbar'] ? '': 'bar, toggleborders,') . ' bar, tableproperties, bar, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit, bar,
541 columninsertbefore, columninsertafter, columndelete, columnsplit, bar,
542 cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge';
543
544 // Special toolbar for Mozilla Wamcom on Mac OS 9
545 if($this->client['BROWSER'] == 'gecko' && $this->client['VERSION'] == '1.3') {
546 $this->defaultToolbarOrder = $this->TCEform->docLarge ? 'bar, blockstylelabel, blockstyle, space, textstylelabel, textstyle, linebreak,
547 bar, fontstyle, space, fontsize, space, formatblock, insertparagraphbefore, insertparagraphafter, blockquote, bar, bold, italic, underline, strikethrough,
548 subscript, superscript, lefttoright, righttoleft, bar, left, center, right, justifyfull, linebreak,
549 bar, orderedlist, unorderedlist, outdent, indent, bar, textcolor, bgcolor, textindicator, bar, emoticon,
550 insertcharacter, line, link, unlink, image, table, user, acronym, bar, findreplace, spellcheck, bar, chMode, inserttag,
551 removeformat, bar, copy, cut, paste, bar, undo, redo, bar, showhelp, about, linebreak,
552 bar, toggleborders, bar, tableproperties, bar, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit, bar,
553 columninsertbefore, columninsertafter, columndelete, columnsplit, bar,
554 cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge'
555 : 'bar, blockstylelabel, blockstyle, space, textstylelabel, textstyle, linebreak,
556 bar, fontstyle, space, fontsize, space, formatblock, insertparagraphbefore, insertparagraphafter, blockquote, bar, bold, italic, underline, strikethrough,
557 subscript, superscript, linebreak, bar, lefttoright, righttoleft, bar, left, center, right, justifyfull,
558 orderedlist, unorderedlist, outdent, indent, bar, textcolor, bgcolor, textindicator, bar, emoticon,
559 insertcharacter, line, link, unlink, image, table, user, acronym, linebreak, bar, findreplace, spellcheck, bar, chMode, inserttag,
560 removeformat, bar, copy, cut, paste, bar, undo, redo, bar, showhelp, about, linebreak,
561 bar, toggleborders, bar, tableproperties, bar, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit, bar,
562 columninsertbefore, columninsertafter, columndelete, columnsplit, bar,
563 cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge';
564 }
565
566 // Additional buttons from registered plugins
567 foreach($this->registeredPlugins as $pluginId => $plugin) {
568 if ($this->isPluginEnabled($pluginId)) {
569 $this->defaultToolbarOrder = $plugin->addButtonsToToolbar();
570 }
571 }
572 $toolbarOrder = $this->thisConfig['toolbarOrder'] ? $this->thisConfig['toolbarOrder'] : $this->defaultToolbarOrder;
573
574 // Getting rid of undefined buttons
575 $this->toolbarOrderArray = array_intersect(t3lib_div::trimExplode(',', $toolbarOrder, 1), t3lib_div::trimExplode(',', $this->defaultToolbarOrder, 1));
576 $toolbarOrder = array_unique(array_values($this->toolbarOrderArray));
577
578 // Fetching specConf for field from backend
579 $pList = is_array($this->specConf['richtext']['parameters']) ? implode(',',$this->specConf['richtext']['parameters']) : '';
580 if ($pList != '*') { // If not all
581 $show = is_array($this->specConf['richtext']['parameters']) ? $this->specConf['richtext']['parameters'] : array();
582 if ($this->thisConfig['showButtons']) {
583 if (!t3lib_div::inList($this->thisConfig['showButtons'],'*')) {
584 $show = array_unique(array_merge($show,t3lib_div::trimExplode(',',$this->thisConfig['showButtons'],1)));
585 } else {
586 $show = array_unique(array_merge($show, $toolbarOrder));
587 }
588 }
589 if (is_array($this->thisConfig['showButtons.'])) {
590 foreach ($this->thisConfig['showButtons.'] as $buttonId => $value) {
591 if ($value) $show[] = $buttonId;
592 }
593 $show = array_unique($show);
594 }
595 } else {
596 $show = $toolbarOrder;
597 }
598
599 // Resticting to RTEkeyList for backend user
600 if(is_object($BE_USER)) {
601 $RTEkeyList = isset($BE_USER->userTS['options.']['RTEkeyList']) ? $BE_USER->userTS['options.']['RTEkeyList'] : '*';
602 if ($RTEkeyList != '*') { // If not all
603 $show = array_intersect($show, t3lib_div::trimExplode(',',$RTEkeyList,1));
604 }
605 }
606
607 // Hiding buttons of disabled plugins
608 $hideButtons = array('space', 'bar', 'linebreak');
609 foreach ($this->pluginButton as $pluginId => $buttonList) {
610 if (!$this->isPluginEnabled($pluginId)) {
611 $buttonArray = t3lib_div::trimExplode(',',$buttonList,1);
612 foreach ($buttonArray as $button) {
613 $hideButtons[] = $button;
614 }
615 }
616 }
617
618 // Hiding labels of disabled plugins
619 foreach ($this->pluginLabel as $pluginId => $label) {
620 if (!$this->isPluginEnabled($pluginId)) {
621 $hideButtons[] = $label;
622 }
623 }
624
625 // Hiding buttons not implemented in some clients
626 foreach ($this->hideButtonsFromClient as $client => $buttonArray) {
627 if ($this->client['BROWSER'] == $client) {
628 foreach($buttonArray as $buttonId) {
629 $hideButtons[] = $buttonId;
630 }
631 }
632 }
633
634 // Hiding the buttons
635 $show = array_diff($show, $this->conf_toolbar_hide, $hideButtons, t3lib_div::trimExplode(',',$this->thisConfig['hideButtons'],1));
636
637 // Adding the always show buttons
638 $show = array_unique(array_merge($show, $this->conf_toolbar_show));
639 $toolbarOrder = array_unique(array_merge($toolbarOrder, $this->conf_toolbar_show));
640 foreach ($this->conf_toolbar_show as $buttonId) {
641 if (!in_array($buttonId, $this->toolbarOrderArray)) $this->toolbarOrderArray[] = $buttonId;
642 }
643
644 // Getting rid of the buttons for which we have no position
645 $show = array_intersect($show, $toolbarOrder);
646 $this->toolbar = $show;
647 }
648
649 /**
650 * Disable some plugins
651 *
652 */
653
654 function setPlugins() {
655 global $TYPO3_CONF_VARS;
656
657 $hideButtons = array();
658
659 // Disabling the plugins if their buttons are not in the toolbar
660 $hidePlugins = array();
661 foreach ($this->pluginButton as $pluginId => $buttonList) {
662 $showPlugin = false;
663 $buttonArray = t3lib_div::trimExplode(',', $buttonList, 1);
664 foreach ($buttonArray as $button) {
665 if (in_array($button, $this->toolbar)) {
666 $showPlugin = true;
667 }
668 }
669 if (!$showPlugin) {
670 $hidePlugins[] = $pluginId;
671 }
672 }
673 if ($this->thisConfig['disableContextMenu'] || $this->thisConfig['disableRightClick']) $hidePlugins[] = 'ContextMenu';
674 $this->pluginEnabledArray = array_diff($this->pluginEnabledArray, $hidePlugins);
675
676 // Hiding labels of disabled plugins
677 foreach ($this->pluginLabel as $pluginId => $label) {
678 if (!$this->isPluginEnabled($pluginId)) {
679 $hideButtons[] = $label;
680 }
681 }
682 $this->toolbar = array_diff($this->toolbar, $hideButtons);
683
684 // Completing the toolbar converion array for htmlArea
685 foreach ($this->registeredPlugins as $pluginId => $plugin) {
686 if ($this->isPluginEnabled($pluginId)) {
687 $this->convertToolbarForHtmlAreaArray = array_unique(array_merge($this->convertToolbarForHtmlAreaArray, $plugin->getConvertToolbarForHtmlAreaArray()));
688 }
689 }
690 }
691
692 /**
693 * Convert the TYPO3 names of buttons into the names for htmlArea RTE
694 *
695 * @param string buttonname (typo3-name)
696 * @return string buttonname (htmlarea-name)
697 */
698
699 function convertToolbarForHTMLArea($button) {
700 return $this->convertToolbarForHtmlAreaArray[$button];
701 }
702
703 /**
704 * Return the JS-function for setting the RTE size.
705 *
706 * @param string DivID-Name
707 * @param int the height for the RTE
708 * @param int the width for the RTE
709 * @return string Loader function in JS
710 */
711 function setRTEsizeByJS($divId, $height, $width) {
712 return '
713 setRTEsizeByJS(\''.$divId.'\','.$height.', '.$width.');
714 ';
715 }
716
717 /**
718 * Return the HTML code for loading the Javascript files
719 *
720 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
721 *
722 * @return string the html code for loading the Javascript Files
723 */
724 function loadJSfiles($RTEcounter) {
725 global $TYPO3_CONF_VARS;
726
727 $loadJavascriptCode = '
728 <script type="text/javascript">
729 /*<![CDATA[*/
730 i=1;
731 while (document.getElementById("pleasewait" + i)) {
732 document.getElementById("pleasewait" + i).style.display = "block";
733 document.getElementById("editorWrap" + i).style.visibility = "hidden";
734 i++;
735 };
736 RTEarea = new Array();
737 RTEarea[0] = new Object();
738 RTEarea[0]["version"] = "' . $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . '";
739 RTEarea[0]["popupwin"] = "' . $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/popupwin.js', "popupwin") . '";'
740 . (($this->client['BROWSER'] == 'msie') ? ('
741 RTEarea[0]["htmlarea-ie"] = "' . $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea-ie.js', "htmlarea-ie") . '";')
742 : ('
743 RTEarea[0]["htmlarea-gecko"] = "' . $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea-gecko.js', "htmlarea-gecko") . '";')) . '
744 _editor_url = "' . $this->extHttpPath . 'htmlarea";
745 _editor_lang = "' . $this->language . '";
746 _editor_CSS = "' . $this->editorCSS . '";
747 _editor_skin = "' . dirname($this->editorCSS) . '";
748 _editor_edited_content_CSS = "' . $this->editedContentCSS . '";
749 _typo3_host_url = "' . $this->hostURL . '";
750 _editor_debug_mode = ' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? 'true' : 'false') . ';
751 _editor_compressed_scripts = ' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? 'true' : 'false') . ';'
752 . (($this->client['BROWSER'] == 'gecko') ? ('
753 _editor_mozAllowClipboard_url = "' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['mozAllowClipboardURL'] ? $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['mozAllowClipboardURL'] : '') . '";')
754 : '') . '
755 /*]]>*/
756 </script>';
757 $loadJavascriptCode .= '
758 <script type="text/javascript" src="' . $this->buildJSMainLangFile($RTEcounter) . '"></script>
759 <script type="text/javascript" src="' . $this->writeTemporaryFile('EXT:' . $this->ID . '/htmlarea/htmlarea.js', "htmlarea") . '"></script>
760 ';
761 return $loadJavascriptCode;
762 }
763
764 /**
765 * Return the inline Javascript code for initializing the RTE
766 *
767 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
768 *
769 * @return string the inline Javascript code for initializing the RTE
770 */
771
772 function loadJScode($RTEcounter) {
773 global $TYPO3_CONF_VARS;
774
775 $loadPluginCode = '';
776 foreach ($this->pluginEnabledCumulativeArray[$RTEcounter] as $pluginId) {
777 $extensionKey = is_object($this->registeredPlugins[$pluginId]) ? $this->registeredPlugins[$pluginId]->getExtensionKey() : $this->ID;
778 $loadPluginCode .= '
779 HTMLArea.loadPlugin("' . $pluginId . '", true, "' . $this->writeTemporaryFile('EXT:' . $extensionKey . '/htmlarea/plugins/' . $pluginId . '/' . strtolower(preg_replace('/([a-z])([A-Z])([a-z])/', "$1".'-'."$2"."$3", $pluginId)) . '.js', $pluginId) . '");';
780 }
781 return (!$this->is_FE() ? '' : '
782 ' . '/*<![CDATA[*/') . ($this->is_FE() ? '' : '
783 RTEarea[0]["RTEtsConfigParams"] = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams()) . '";')
784 . $loadPluginCode . '
785 HTMLArea.init();' . (!$this->is_FE() ? '' : '
786 /*]]>*/
787 ');
788 }
789
790 /**
791 * Return the Javascript code for configuring the RTE
792 *
793 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
794 * @param string $table: The table that includes this RTE (optional, necessary for IRRE).
795 * @param string $uid: The uid of that table that includes this RTE (optional, necessary for IRRE).
796 * @param string $field: The field of that record that includes this RTE (optional).
797 *
798 * @return string the Javascript code for configuring the RTE
799 */
800 function registerRTEinJS($RTEcounter, $table='', $uid='', $field='') {
801 global $TYPO3_CONF_VARS;
802
803 $configureRTEInJavascriptString = (!$this->is_FE() ? '' : '
804 ' . '/*<![CDATA[*/') . '
805 RTEarea['.$RTEcounter.'] = new Object();
806 RTEarea['.$RTEcounter.'].RTEtsConfigParams = "&RTEtsConfigParams=' . rawurlencode($this->RTEtsConfigParams()) . '";
807 RTEarea['.$RTEcounter.'].number = '.$RTEcounter.';
808 RTEarea['.$RTEcounter.'].id = "RTEarea'.$RTEcounter.'";
809 RTEarea['.$RTEcounter.'].enableWordClean = ' . (trim($this->thisConfig['enableWordClean'])?'true':'false') . ';
810 RTEarea['.$RTEcounter.']["htmlRemoveComments"] = ' . (trim($this->thisConfig['removeComments'])?'true':'false') . ';
811 RTEarea['.$RTEcounter.']["disableEnterParagraphs"] = ' . (trim($this->thisConfig['disableEnterParagraphs'])?'true':'false') . ';
812 RTEarea['.$RTEcounter.']["removeTrailingBR"] = ' . (trim($this->thisConfig['removeTrailingBR'])?'true':'false') . ';
813 RTEarea['.$RTEcounter.']["useCSS"] = ' . (trim($this->thisConfig['useCSS'])?'true':'false') . ';
814 RTEarea['.$RTEcounter.']["keepButtonGroupTogether"] = ' . (trim($this->thisConfig['keepButtonGroupTogether'])?'true':'false') . ';
815 RTEarea['.$RTEcounter.']["disablePCexamples"] = ' . (trim($this->thisConfig['disablePCexamples'])?'true':'false') . ';
816 RTEarea['.$RTEcounter.']["statusBar"] = ' . (trim($this->thisConfig['showStatusBar'])?'true':'false') . ';
817 RTEarea['.$RTEcounter.']["showTagFreeClasses"] = ' . (trim($this->thisConfig['showTagFreeClasses'])?'true':'false') . ';
818 RTEarea['.$RTEcounter.']["useHTTPS"] = ' . ((trim(stristr($this->siteURL, 'https')) || $this->thisConfig['forceHTTPS'])?'true':'false') . ';
819 RTEarea['.$RTEcounter.']["enableMozillaExtension"] = ' . (($this->client['BROWSER'] == 'gecko' && $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableMozillaExtension'])?'true':'false') . ';
820 RTEarea['.$RTEcounter.']["tceformsNested"] = ' . (is_object($this->TCEform) && method_exists($this->TCEform, 'getDynNestedStack') ? $this->TCEform->getDynNestedStack(true) : '[]') . ';';
821
822 // The following properties apply only to the backend
823 if (!$this->is_FE()) {
824 $configureRTEInJavascriptString .= '
825 RTEarea['.$RTEcounter.'].sys_language_content = "' . $this->contentLanguageUid . '";
826 RTEarea['.$RTEcounter.'].typo3ContentLanguage = "' . $this->contentTypo3Language . '";
827 RTEarea['.$RTEcounter.'].typo3ContentCharset = "' . $this->contentCharset . '";
828 RTEarea['.$RTEcounter.'].userUid = "' . $this->userUid . '";';
829 }
830
831 // Setting the plugin flags
832 $configureRTEInJavascriptString .= '
833 RTEarea['.$RTEcounter.'].plugin = new Object();';
834 foreach ($this->pluginEnabledArray as $pluginId) {
835 $configureRTEInJavascriptString .= '
836 RTEarea['.$RTEcounter.'].plugin.'.$pluginId.' = true;';
837 }
838
839 // Setting the buttons configuration
840 $configureRTEInJavascriptString .= '
841 RTEarea['.$RTEcounter.'].buttons = new Object();';
842 if (is_array($this->thisConfig['buttons.'])) {
843 foreach ($this->thisConfig['buttons.'] as $buttonIndex => $conf) {
844 $button = substr($buttonIndex, 0, -1);
845 if (in_array($button,$this->toolbar)) {
846 $indexButton = 0;
847 $configureRTEInJavascriptString .= '
848 RTEarea['.$RTEcounter.'].buttons.'.$button.' = {';
849 if (is_array($conf)) {
850 foreach ($conf as $propertyName => $conf1) {
851 $property = $propertyName;
852 if ($indexButton) {
853 $configureRTEInJavascriptString .= ', ';
854 }
855 if (is_array($conf1)) {
856 $property = substr($property, 0, -1);
857 $indexProperty = 0;
858 $configureRTEInJavascriptString .= '"'.$property.'" : {';
859 foreach ($conf1 as $property1Name => $conf2) {
860 $property1 = $property1Name;
861 if ($indexProperty) {
862 $configureRTEInJavascriptString .= ', ';
863 }
864 if (is_array($conf2)) {
865 $property1 = substr($property1, 0, -1);
866 $indexProperty1 = 0;
867 $configureRTEInJavascriptString .= '"'.$property1.'" : {';
868 foreach ($conf2 as $property2Name => $conf3) {
869 $property2 = $property2Name;
870 if ($indexProperty1) {
871 $configureRTEInJavascriptString .= ', ';
872 }
873 if (is_array($conf3)) {
874 $property2 = substr($property2, 0, -1);
875 $indexProperty2 = 0;
876 $configureRTEInJavascriptString .= '"'.$property2.'" : {';
877 foreach($conf3 as $property3Name => $conf4) {
878 $property3 = $property3Name;
879 if ($indexProperty2) {
880 $configureRTEInJavascriptString .= ', ';
881 }
882 if (!is_array($conf4)) {
883 $configureRTEInJavascriptString .= '"'.$property3.'" : '.($conf4?'"'.$conf4.'"':'false');
884 }
885 $indexProperty2++;
886 }
887 $configureRTEInJavascriptString .= '}';
888 } else {
889 $configureRTEInJavascriptString .= '"'.$property2.'" : '.($conf3?'"'.$conf3.'"':'false');
890 }
891 $indexProperty1++;
892 }
893 $configureRTEInJavascriptString .= '}';
894 } else {
895 $configureRTEInJavascriptString .= '"'.$property1.'" : '.($conf2?'"'.$conf2.'"':'false');
896 }
897 $indexProperty++;
898 }
899 $configureRTEInJavascriptString .= '}';
900 } else {
901 $configureRTEInJavascriptString .= '"'.$property.'" : '.($conf1?'"'.$conf1.'"':'false');
902 }
903 $indexButton++;
904 }
905 }
906 $configureRTEInJavascriptString .= '};';
907 }
908 }
909 }
910
911 // Setting the list of tags to be removed if specified in the RTE config
912 if (trim($this->thisConfig['removeTags'])) {
913 $configureRTEInJavascriptString .= '
914 RTEarea['.$RTEcounter.']["htmlRemoveTags"] = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTags'], 1)) . ')$/i;';
915 }
916
917 // Setting the list of tags to be removed with their contents if specified in the RTE config
918 if (trim($this->thisConfig['removeTagsAndContents'])) {
919 $configureRTEInJavascriptString .= '
920 RTEarea['.$RTEcounter.']["htmlRemoveTagsAndContents"] = /^(' . implode('|', t3lib_div::trimExplode(',', $this->thisConfig['removeTagsAndContents'], 1)) . ')$/i;';
921 }
922
923 // Process default style configuration
924 $configureRTEInJavascriptString .= '
925 RTEarea['.$RTEcounter.'].defaultPageStyle = "' . $this->hostURL . $this->writeTemporaryFile('', 'defaultPageStyle', 'css', $this->buildStyleSheet()) . '";';
926
927 // Setting the pageStyle
928 $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/res/contentcss/default.css';
929 $configureRTEInJavascriptString .= '
930 RTEarea['.$RTEcounter.'].pageStyle = "' . $this->getFullFileName($filename) .'";';
931
932 // Process classes configuration
933 $classesConfigurationRequired = false;
934 foreach ($this->registeredPlugins as $pluginId => $plugin) {
935 if ($this->isPluginEnabled($pluginId)) {
936 $classesConfigurationRequired = $classesConfigurationRequired || $plugin->requiresClassesConfiguration();
937 }
938 }
939 if ($classesConfigurationRequired) {
940 $configureRTEInJavascriptString .= $this->buildJSClassesConfig($RTEcounter);
941 }
942
943 // Add Javascript configuration for registered plugins
944 foreach ($this->registeredPlugins as $pluginId => $plugin) {
945 if ($this->isPluginEnabled($pluginId)) {
946 $configureRTEInJavascriptString .= $plugin->buildJavascriptConfiguration($RTEcounter);
947 }
948 }
949
950 $configureRTEInJavascriptString .= '
951 RTEarea['.$RTEcounter.'].toolbar = '.$this->getJSToolbarArray().';
952 HTMLArea.initEditor('.$RTEcounter.');' . (!$this->is_FE() ? '' : '
953 /*]]>*/');
954 return $configureRTEInJavascriptString;
955 }
956
957 /**
958 * Return true, if the plugin can be loaded
959 *
960 * @param string $pluginId: The identification string of the plugin
961 *
962 * @return boolean true if the plugin can be loaded
963 */
964
965 function isPluginEnabled($pluginId) {
966 return in_array($pluginId, $this->pluginEnabledArray);
967 }
968
969 /**
970 * Build the default content style sheet
971 *
972 * @return string Style sheet
973 */
974 function buildStyleSheet() {
975
976 if (!trim($this->thisConfig['ignoreMainStyleOverride'])) {
977 $mainStyle_font = $this->thisConfig['mainStyle_font'] ? $this->thisConfig['mainStyle_font']: 'Verdana,sans-serif';
978
979 $mainElements = array();
980 $mainElements['P'] = $this->thisConfig['mainStyleOverride_add.']['P'];
981 $elList = explode(',','H1,H2,H3,H4,H5,H6,PRE');
982 foreach ($elList as $elListName) {
983 if ($this->thisConfig['mainStyleOverride_add.'][$elListName]) {
984 $mainElements[$elListName] = $this->thisConfig['mainStyleOverride_add.'][$elListName];
985 }
986 }
987
988 $addElementCode = '';
989 foreach ($mainElements as $elListName => $elValue) {
990 $addElementCode .= strToLower($elListName) . ' {' . $elValue . '}' . chr(10);
991 }
992
993 $stylesheet = $this->thisConfig['mainStyleOverride'] ? $this->thisConfig['mainStyleOverride'] : chr(10) .
994 'body.htmlarea-content-body { font-family: ' . $mainStyle_font .
995 '; font-size: '.($this->thisConfig['mainStyle_size'] ? $this->thisConfig['mainStyle_size'] : '12px') .
996 '; color: '.($this->thisConfig['mainStyle_color']?$this->thisConfig['mainStyle_color'] : 'black') .
997 '; background-color: '.($this->thisConfig['mainStyle_bgcolor'] ? $this->thisConfig['mainStyle_bgcolor'] : 'white') .
998 ';'.$this->thisConfig['mainStyleOverride_add.']['BODY'].'}' . chr(10) .
999 'td { ' . $this->thisConfig['mainStyleOverride_add.']['TD'].'}' . chr(10) .
1000 'div { ' . $this->thisConfig['mainStyleOverride_add.']['DIV'].'}' . chr(10) .
1001 'pre { ' . $this->thisConfig['mainStyleOverride_add.']['PRE'].'}' . chr(10) .
1002 'ol { ' . $this->thisConfig['mainStyleOverride_add.']['OL'].'}' . chr(10) .
1003 'ul { ' . $this->thisConfig['mainStyleOverride_add.']['UL'].'}' . chr(10) .
1004 'blockquote { ' . $this->thisConfig['mainStyleOverride_add.']['BLOCKQUOTE'].'}' . chr(10) .
1005 $addElementCode;
1006
1007 if (is_array($this->thisConfig['inlineStyle.'])) {
1008 $stylesheet .= chr(10) . implode(chr(10), $this->thisConfig['inlineStyle.']) . chr(10);
1009 }
1010 } else {
1011 $stylesheet = '/* mainStyleOverride and inlineStyle properties ignored. */';
1012 }
1013 return $stylesheet;
1014 }
1015
1016 /**
1017 * Return Javascript configuration of classes
1018 *
1019 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
1020 *
1021 * @return string Javascript configuration of classes
1022 */
1023 function buildJSClassesConfig($RTEcounter) {
1024 // Build JS array of lists of classes
1025 $classesTagList = 'classesCharacter, classesParagraph, classesImage, classesTable, classesLinks, classesTD';
1026 $classesTagConvert = array( 'classesCharacter' => 'span', 'classesParagraph' => 'p', 'classesImage' => 'img', 'classesTable' => 'table', 'classesLinks' => 'a', 'classesTD' => 'td');
1027 $classesTagArray = t3lib_div::trimExplode(',' , $classesTagList);
1028 $configureRTEInJavascriptString = '
1029 RTEarea['.$RTEcounter.']["classesTag"] = new Object();';
1030 foreach ($classesTagArray as $classesTagName) {
1031 $HTMLAreaJSClasses = ($this->thisConfig[$classesTagName])?('"' . $this->cleanList($this->thisConfig[$classesTagName]) . '";'):'null;';
1032 $configureRTEInJavascriptString .= '
1033 RTEarea['.$RTEcounter.']["classesTag"]["'. $classesTagConvert[$classesTagName] .'"] = '. $HTMLAreaJSClasses;
1034 }
1035
1036 // Include JS arrays of configured classes
1037 $configureRTEInJavascriptString .= '
1038 RTEarea['.$RTEcounter.']["classesUrl"] = "' . $this->hostURL . $this->writeTemporaryFile('', 'classes_'.$LANG->lang, 'js', $this->buildJSClassesArray()) . '";';
1039
1040 return $configureRTEInJavascriptString;
1041 }
1042
1043 /**
1044 * Return JS arrays of classes labels and noShow flags
1045 *
1046 * @return string JS classes arrays
1047 */
1048 function buildJSClassesArray() {
1049 global $TSFE, $LANG, $TYPO3_CONF_VARS;
1050
1051 if ($this->is_FE()) {
1052 $RTEProperties = $this->RTEsetup;
1053 } else {
1054 $RTEProperties = $this->RTEsetup['properties'];
1055 }
1056
1057 $linebreak = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
1058 $index = 0;
1059 $JSClassesLabelsArray = 'HTMLArea.classesLabels = { ' . $linebreak;
1060 $JSClassesValuesArray = 'HTMLArea.classesValues = { ' . $linebreak;
1061 $JSClassesNoShowArray = 'HTMLArea.classesNoShow = { ' . $linebreak;
1062 $JSClassesXORArray = 'HTMLArea.classesXOR = { ' . $linebreak;
1063
1064 // Scanning the list of classes if specified in the RTE config
1065 if (is_array($RTEProperties['classes.'])) {
1066 $stylesheet = '';
1067 foreach ($RTEProperties['classes.'] as $className => $conf) {
1068 $className = substr($className,0,-1);
1069 $classLabel = $this->getPageConfigLabel($conf['name']);
1070 $JSClassesLabelsArray .= (($index)?',':'') . '"' . $className . '": ' . $classLabel . $linebreak;
1071 $JSClassesValuesArray .= (($index)?',':'') . '"' . $className . '":"' . str_replace('"', '\"', str_replace('\\\'', '\'', $conf['value'])) . '"' . $linebreak;
1072 $JSClassesNoShowArray .= (($index)?',':'') . '"' . $className . '":' . ($conf['noShow']?'true':'false') . $linebreak;
1073 if (is_array($RTEProperties['mutuallyExclusiveClasses.'])) {
1074 foreach ($RTEProperties['mutuallyExclusiveClasses.'] as $listName => $conf) {
1075 if (t3lib_div::inList($conf, $className)) {
1076 $JSClassesXORArray .= (($index)?',':'') . '"' . $className . '": /^(' . implode('|', t3lib_div::trimExplode(',', t3lib_div::rmFromList($className, $conf), 1)) . ')$/i' . $linebreak;
1077 break;
1078 }
1079 }
1080 }
1081 $index++;
1082 }
1083 }
1084 $JSClassesLabelsArray .= '};' . $linebreak;
1085 $JSClassesValuesArray .= '};' . $linebreak;
1086 $JSClassesNoShowArray .= '};' . $linebreak;
1087 $JSClassesXORArray .= '};' . $linebreak;
1088
1089 return $JSClassesLabelsArray . $JSClassesValuesArray . $JSClassesNoShowArray . $JSClassesXORArray;
1090 }
1091
1092 /**
1093 * Return a Javascript localization array for htmlArea RTE
1094 *
1095 * @return string Javascript localization array
1096 */
1097 function buildJSMainLangArray() {
1098 global $TSFE, $LANG, $TYPO3_CONF_VARS;
1099
1100 $linebreak = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
1101 $JSLanguageArray .= 'var HTMLArea_langArray = new Object();' . $linebreak;
1102 $JSLanguageArray .= 'HTMLArea_langArray = { ' . $linebreak;
1103 if($this->is_FE()) {
1104 $JSLanguageArray = $TSFE->csConvObj->conv($JSLanguageArray, 'iso-8859-1', $this->OutputCharset);
1105 } else {
1106 $JSLanguageArray = $LANG->csConvObj->conv($JSLanguageArray, 'iso-8859-1', $this->OutputCharset);
1107 }
1108
1109 $subArrays = array( 'tooltips', 'msg' , 'dialogs');
1110 $subArraysIndex = 0;
1111 foreach($subArrays as $labels) {
1112 $JSLanguageArray .= (($subArraysIndex++)?',':'') . $labels . ': {' . $linebreak;
1113 if($this->is_FE()) {
1114 $LOCAL_LANG = $TSFE->readLLfile(t3lib_extMgm::extPath($this->ID).'htmlarea/locallang_' . $labels . '.xml', $this->language);
1115 $TSFE->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
1116 if(!empty($LOCAL_LANG[$this->language])) $TSFE->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
1117 } else {
1118 $LOCAL_LANG = $LANG->readLLfile(t3lib_extMgm::extPath($this->ID).'htmlarea/locallang_' . $labels . '.xml');
1119 $LANG->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
1120 if(!empty($LOCAL_LANG[$this->language])) $LANG->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
1121 }
1122 if(!empty($LOCAL_LANG[$this->language])) {
1123 $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'], $LOCAL_LANG[$this->language]);
1124 } else {
1125 $LOCAL_LANG[$this->language] = $LOCAL_LANG['default'];
1126 }
1127 $index = 0;
1128 foreach ( $LOCAL_LANG[$this->language] as $labelKey => $labelValue ) {
1129 $JSLanguageArray .= (($index++)?',':'') . '"' . $labelKey . '":"' . str_replace('"', '\"', $labelValue) . '"' . $linebreak;
1130 }
1131 if($this->is_FE()) {
1132 $JSLanguageArray .= $TSFE->csConvObj->conv(' }' . chr(10), 'iso-8859-1', $this->OutputCharset);
1133 } else {
1134 $JSLanguageArray .= $LANG->csConvObj->conv(' }' . chr(10), 'iso-8859-1', $this->OutputCharset);
1135 }
1136 }
1137
1138 if($this->is_FE()) {
1139 $JSLanguageArray .= $TSFE->csConvObj->conv(' }' . chr(10), 'iso-8859-1', $this->OutputCharset);
1140 } else {
1141 $JSLanguageArray .= $LANG->csConvObj->conv(' }' . chr(10), 'iso-8859-1', $this->OutputCharset);
1142 }
1143 return $JSLanguageArray;
1144 }
1145
1146 /**
1147 * Writes contents in a file in typo3temp/rtehtmlarea directory and returns the file name
1148 *
1149 * @param string $sourceFileName: The name of the file from which the contents should be extracted
1150 * @param string $label: A label to insert at the beginning of the name of the file
1151 * @param string $fileExtension: The file extension of the file, defaulting to 'js'
1152 * @param string $contents: The contents to write into the file if no $sourceFileName is provided
1153 *
1154 * @return string The name of the file writtten to typo3temp/rtehtmlarea
1155 */
1156 public function writeTemporaryFile($sourceFileName='', $label, $fileExtension='js', $contents='') {
1157 global $TYPO3_CONF_VARS;
1158
1159 if ($sourceFileName) {
1160 $output = '';
1161 $source = t3lib_div::getFileAbsFileName($sourceFileName);
1162 $inputHandle = @fopen($source, "rb");
1163 while (!feof($inputHandle)) {
1164 $output .= @fread($inputHandle, 8192);
1165 }
1166 fclose($inputHandle);
1167 } else {
1168 $output = $contents;
1169 }
1170 $compress = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] && ($fileExtension == 'js') && ($output != '');
1171 $relativeFilename = 'typo3temp/' . $this->ID . '/' . str_replace('-','_',$label) . '_' . t3lib_div::shortMD5(($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['version'] . ($sourceFileName?$sourceFileName:$output)), 20) . ($compress ? '_compressed' : '') . '.' . $fileExtension;
1172 $destination = PATH_site . $relativeFilename;
1173 if(!file_exists($destination)) {
1174 $compressedJavaScript = '';
1175 if ($compress) {
1176 $compressedJavaScript = t3lib_div::minifyJavaScript($output);
1177 }
1178 $failure = t3lib_div::writeFileToTypo3tempDir($destination, $compressedJavaScript?$compressedJavaScript:$output);
1179 if ($failure) {
1180 die($failure);
1181 }
1182 }
1183 return ($this->thisConfig['forceHTTPS']?$this->siteURL:$this->httpTypo3Path) . $relativeFilename;
1184 }
1185
1186 /**
1187 * Return a file name containing the main JS language array for HTMLArea
1188 *
1189 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
1190 *
1191 * @return string filename
1192 */
1193
1194 function buildJSMainLangFile($RTEcounter) {
1195 $contents = $this->buildJSMainLangArray() . chr(10);
1196 foreach ($this->pluginEnabledCumulativeArray[$RTEcounter] as $pluginId) {
1197 $contents .= $this->buildJSLangArray($pluginId) . chr(10);
1198 }
1199 return $this->writeTemporaryFile('', $this->language.'_'.$this->OutputCharset, 'js', $contents);
1200 }
1201
1202 /**
1203 * Return a Javascript localization array for the plugin
1204 *
1205 * @param string $plugin: identification string of the plugin
1206 *
1207 * @return string Javascript localization array
1208 */
1209
1210 function buildJSLangArray($plugin) {
1211 global $TSFE, $LANG, $TYPO3_CONF_VARS;
1212
1213 $extensionKey = is_object($this->registeredPlugins[$plugin]) ? $this->registeredPlugins[$plugin]->getExtensionKey() : $this->ID;
1214
1215 $linebreak = $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableCompressedScripts'] ? '' : chr(10);
1216 if($this->is_FE()) {
1217 $LOCAL_LANG = $TSFE->readLLfile(t3lib_extMgm::extPath($extensionKey).'htmlarea/plugins/' . $plugin . '/locallang.xml', $this->language);
1218 if(!empty($LOCAL_LANG['default'])) $TSFE->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
1219 if(!empty($LOCAL_LANG[$this->language])) $TSFE->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
1220 } else {
1221 $LOCAL_LANG = $LANG->readLLfile(t3lib_extMgm::extPath($extensionKey).'htmlarea/plugins/' . $plugin . '/locallang.xml');
1222 if(!empty($LOCAL_LANG['default'])) $LANG->csConvObj->convArray($LOCAL_LANG['default'], 'iso-8859-1', $this->OutputCharset);
1223 if(!empty($LOCAL_LANG[$this->language])) $LANG->csConvObj->convArray($LOCAL_LANG[$this->language], $this->charset, $this->OutputCharset);
1224 }
1225
1226 if(!empty($LOCAL_LANG[$this->language])) {
1227 $LOCAL_LANG[$this->language] = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG['default'],$LOCAL_LANG[$this->language]);
1228 } else {
1229 $LOCAL_LANG[$this->language] = $LOCAL_LANG['default'];
1230 }
1231
1232 $JSLanguageArray .= 'var ' . $plugin . '_langArray = new Object();' . $linebreak;
1233 $JSLanguageArray .= $plugin . '_langArray = {' . $linebreak;
1234 if($this->is_FE()) {
1235 $JSLanguageArray = $TSFE->csConvObj->conv($JSLanguageArray, 'iso-8859-1', $this->OutputCharset);
1236 } else {
1237 $JSLanguageArray = $LANG->csConvObj->conv($JSLanguageArray, 'iso-8859-1', $this->OutputCharset);
1238 }
1239
1240 $index = 0;
1241 foreach ( $LOCAL_LANG[$this->language] as $labelKey => $labelValue ) {
1242 $JSLanguageArray .= (($index++)?',':'') . '"' . $labelKey . '":"' . str_replace('"', '\"', $labelValue) . '"' . $linebreak;
1243 }
1244
1245 if($this->is_FE()) {
1246 $JSLanguageArray .= $TSFE->csConvObj->conv(' }' . chr(10), 'iso-8859-1', $this->OutputCharset);
1247 } else {
1248 $JSLanguageArray .= $LANG->csConvObj->conv(' }' . chr(10), 'iso-8859-1', $this->OutputCharset);
1249 }
1250
1251 return $JSLanguageArray;
1252 }
1253
1254 /**
1255 * Return the JS-Code for the Toolbar-Config-Array for HTML-Area
1256 *
1257 * @return string the JS-Code as an JS-Array
1258 */
1259
1260 function getJSToolbarArray() {
1261 $toolbar = ''; // The JS-Code for the toolbar
1262 $group = ''; // The TS-Code for the group in the moment, each group are between "bar"s
1263 $group_has_button = false; // True if the group has any enabled buttons
1264 $group_needs_starting_bar = false;
1265 $previous_is_space = false;
1266
1267 // process each button in the order list
1268 foreach ($this->toolbarOrderArray as $button) {
1269 // check if a new group starts
1270 if (($button == 'bar' || $button == 'linebreak') && $group_has_button) {
1271 // New line
1272 if ($button == 'linebreak') {
1273 $convertButton = '"' . $this->convertToolbarForHTMLArea('linebreak') . '"';
1274 $group = ($group!='') ? ($group . ', ' . $convertButton) : $convertButton;
1275 }
1276 // New group
1277 $toolbar .= $toolbar ? (', ' . $group) : ('[[' . $group);
1278 $group = '';
1279 $previous_is_space = false;
1280 $group_has_button = false;
1281 $group_needs_starting_bar = true;
1282 } elseif ($toolbar && $button == 'linebreak' && !$group_has_button) {
1283 // Insert linebreak if no group is opened
1284 $group = '';
1285 $previous_is_space = false;
1286 $group_needs_starting_bar = false;
1287 $toolbar .= ', "' . $this->convertToolbarForHTMLArea($button) . '"';
1288 } elseif ($button == 'bar' && !$group_has_button) {
1289 $group_needs_starting_bar = true;
1290 } elseif ($button == 'space' && $group_has_button && !$previous_is_space) {
1291 $convertButton = $this->convertToolbarForHTMLArea($button);
1292 $convertButton = '"' . $convertButton . '"';
1293 $group .= $group ? (', ' . $convertButton) : ($group_needs_starting_bar ? ('"' . $this->convertToolbarForHTMLArea('bar') . '", ' . $convertButton) : $convertButton);
1294 $group_needs_starting_bar = false;
1295 $previous_is_space = true;
1296 } elseif (in_array($button, $this->toolbar)) {
1297 // Add the button to the group
1298 $convertButton = $this->convertToolbarForHTMLArea($button);
1299 if ($convertButton) {
1300 $convertButton = '"' . $convertButton . '"';
1301 $group .= $group ? (', ' . $convertButton) : ($group_needs_starting_bar ? ('"' . $this->convertToolbarForHTMLArea('bar') . '", ' . $convertButton) : $convertButton);
1302 $group_has_button = true;
1303 $group_needs_starting_bar = false;
1304 $previous_is_space = false;
1305 }
1306 }
1307 // else ignore
1308 }
1309 // add the last group
1310 if($group_has_button) $toolbar .= $toolbar ? (', ' . $group) : ('[[' . $group);
1311 $toolbar = $toolbar . ']]';
1312 return $toolbar;
1313 }
1314
1315 public function getLLContent($string) {
1316 global $LANG;
1317
1318 $BE_lang = $LANG->lang;
1319 $BE_origCharset = $LANG->origCharSet;
1320 $BE_charSet = $LANG->charSet;
1321 $LANG->lang = $this->contentTypo3Language;
1322 $LANG->origCharSet = $this->origContentCharSet;
1323 $LANG->charSet = $this->contentCharset;
1324 $LLString = $LANG->JScharCode($LANG->sL($string));
1325 $LANG->lang = $BE_lang;
1326 $LANG->origCharSet = $BE_origCharset;
1327 $LANG->charSet = $BE_charSet;
1328 return $LLString;
1329 }
1330
1331 public function getPageConfigLabel($string,$JScharCode=1) {
1332 global $LANG, $TSFE;
1333
1334 if ($this->is_FE()) {
1335 $label = $TSFE->csConvObj->conv($TSFE->sL(trim($string)), $TSFE->renderCharset, $TSFE->metaCharset);
1336 $label = str_replace('"', '\"', str_replace('\\\'', '\'', $label));
1337 $label = $JScharCode ? $this->feJScharCode($label) : $label;
1338 } else {
1339 if (strcmp(substr($string,0,4),'LLL:')) {
1340 $label = $string;
1341 } else {
1342 $label = $LANG->sL(trim($string));
1343 }
1344 $label = str_replace('"', '\"', str_replace('\\\'', '\'', $label));
1345 $label = $JScharCode ? $LANG->JScharCode($label): $label;
1346 }
1347 return $label;
1348 }
1349
1350 function feJScharCode($str) {
1351 global $TSFE;
1352 // Convert string to UTF-8:
1353 if ($this->OutputCharset != 'utf-8') $str = $TSFE->csConvObj->utf8_encode($str,$this->OutputCharset);
1354 // Convert the UTF-8 string into a array of char numbers:
1355 $nArr = $TSFE->csConvObj->utf8_to_numberarray($str);
1356 return 'String.fromCharCode('.implode(',',$nArr).')';
1357 }
1358
1359 public function getFullFileName($filename) {
1360 if (substr($filename,0,4)=='EXT:') { // extension
1361 list($extKey,$local) = explode('/',substr($filename,4),2);
1362 $newFilename = '';
1363 if (strcmp($extKey,'') && t3lib_extMgm::isLoaded($extKey) && strcmp($local,'')) {
1364 $newFilename = $this->siteURL . t3lib_extMgm::siteRelPath($extKey) . $local;
1365 }
1366 } elseif (substr($filename,0,1) != '/') {
1367 $newFilename = $this->siteURL . $filename;
1368 } else {
1369 $newFilename = $this->siteURL . substr($filename,1);
1370 }
1371 return $newFilename;
1372 }
1373
1374 /**
1375 * Return the Javascript code for copying the HTML code from the editor into the hidden input field.
1376 * This is for submit function of the form.
1377 *
1378 * @param integer $RTEcounter: The index number of the current RTE editing area within the form.
1379 * @param string $formName: the name of the form
1380 * @param string $textareaId: the id of the textarea
1381 *
1382 * @return string Javascript code
1383 */
1384 function setSaveRTE($RTEcounter, $formName, $textareaId) {
1385 return '
1386 editornumber = '.$RTEcounter.';
1387 if (RTEarea[editornumber]) {
1388 document.'.$formName.'["'.$textareaId.'"].value = RTEarea[editornumber]["editor"].getHTML();
1389 }
1390 else {
1391 OK=0;
1392 }
1393 ';
1394 }
1395
1396 /**
1397 * Return true if we are in the FE, but not in the FE editing feature of BE.
1398 *
1399 * @return boolean
1400 */
1401
1402 function is_FE() {
1403 global $TSFE;
1404 return is_object($TSFE) && !strstr($this->elementId,'TSFE_EDIT');
1405 }
1406
1407 /**
1408 * Client Browser Information
1409 *
1410 * Usage: 4
1411 *
1412 * @param string Alternative User Agent string (if empty, t3lib_div::getIndpEnv('HTTP_USER_AGENT') is used)
1413 * @return array Parsed information about the HTTP_USER_AGENT in categories BROWSER, VERSION, SYSTEM and FORMSTYLE
1414 */
1415
1416 function clientInfo($useragent='') {
1417 global $TYPO3_CONF_VARS;
1418
1419 if (!$useragent) $useragent=t3lib_div::getIndpEnv('HTTP_USER_AGENT');
1420
1421 $bInfo=array();
1422 // Which browser?
1423 if (strstr($useragent,'Konqueror')) {
1424 $bInfo['BROWSER']= 'konqu';
1425 } elseif (strstr($useragent,'Opera')) {
1426 $bInfo['BROWSER']= 'opera';
1427 } elseif (strstr($useragent,'MSIE')) {
1428 $bInfo['BROWSER']= 'msie';
1429 } elseif (strstr($useragent,'Gecko/')) {
1430 $bInfo['BROWSER']='gecko';
1431 } elseif (strstr($useragent,'Safari/')) {
1432 $bInfo['BROWSER']='safari';
1433 } elseif (strstr($useragent,'Mozilla/4')) {
1434 $bInfo['BROWSER']='net';
1435 }
1436
1437 if ($bInfo['BROWSER']) {
1438 // Browser version
1439 switch($bInfo['BROWSER']) {
1440 case 'net':
1441 $bInfo['VERSION']= doubleval(substr($useragent,8));
1442 if (strstr($useragent,'Netscape6/')) {$bInfo['VERSION']=doubleval(substr(strstr($useragent,'Netscape6/'),10));}
1443 if (strstr($useragent,'Netscape/7')) {$bInfo['VERSION']=doubleval(substr(strstr($useragent,'Netscape/7'),9));}
1444 break;
1445 case 'gecko':
1446 $tmp = strstr($useragent,'rv:');
1447 $bInfo['VERSION'] = doubleval(ereg_replace('^[^0-9]*','',substr($tmp,3)));
1448 break;
1449 case 'msie':
1450 $tmp = strstr($useragent,'MSIE');
1451 $bInfo['VERSION'] = doubleval(ereg_replace('^[^0-9]*','',substr($tmp,4)));
1452 break;
1453 case 'safari':
1454 $tmp = strstr($useragent,'Safari/');
1455 $bInfo['VERSION'] = doubleval(ereg_replace('^[^0-9]*','',substr($tmp,3)));
1456 break;
1457 case 'opera':
1458 $tmp = strstr($useragent,'Opera');
1459 $bInfo['VERSION'] = doubleval(ereg_replace('^[^0-9]*','',substr($tmp,5)));
1460 break;
1461 case 'konqu':
1462 $tmp = strstr($useragent,'Konqueror/');
1463 $bInfo['VERSION'] = doubleval(substr($tmp,10));
1464 break;
1465 }
1466
1467 // Client system
1468 if (strstr($useragent,'Win')) {
1469 $bInfo['SYSTEM'] = 'win';
1470 } elseif (strstr($useragent,'Mac')) {
1471 $bInfo['SYSTEM'] = 'mac';
1472 } elseif (strstr($useragent,'Linux') || strstr($useragent,'X11') || strstr($useragent,'SGI') || strstr($useragent,' SunOS ') || strstr($useragent,' HP-UX ')) {
1473 $bInfo['SYSTEM'] = 'unix';
1474 }
1475 }
1476
1477 // Is true if the browser supports css to format forms, especially the width
1478 $bInfo['FORMSTYLE']=($bInfo['BROWSER']=='msie' || ($bInfo['BROWSER']=='net'&&$bInfo['VERSION']>=5) || $bInfo['BROWSER']=='opera' || $bInfo['BROWSER']=='konqu');
1479 return $bInfo;
1480 }
1481
1482 /***************************
1483 *
1484 * OTHER FUNCTIONS: (from Classic RTE)
1485 *
1486 ***************************/
1487 /**
1488 * @return [type] ...
1489 * @desc
1490 */
1491
1492 function RTEtsConfigParams() {
1493 if($this->is_FE()) {
1494 return '';
1495 } else {
1496 $p = t3lib_BEfunc::getSpecConfParametersFromArray($this->specConf['rte_transform']['parameters']);
1497 return $this->elementParts[0].':'.$this->elementParts[1].':'.$this->elementParts[2].':'.$this->thePid.':'.$this->typeVal.':'.$this->tscPID.':'.$p['imgpath'];
1498 }
1499 }
1500
1501 public function cleanList($str) {
1502 if (strstr($str,'*')) {
1503 $str = '*';
1504 } else {
1505 $str = implode(',',array_unique(t3lib_div::trimExplode(',',$str,1)));
1506 }
1507 return $str;
1508 }
1509
1510 function filterStyleEl($elValue,$matchList) {
1511 $matchParts = t3lib_div::trimExplode(',',$matchList,1);
1512 $styleParts = explode(';',$elValue);
1513 $nStyle=array();
1514 foreach ($styleParts as $k => $p) {
1515 $pp = t3lib_div::trimExplode(':',$p);
1516 if ($pp[0]&&$pp[1]) {
1517 foreach ($matchParts as $el) {
1518 $star=substr($el,-1)=='*';
1519 if (!strcmp($pp[0],$el) || ($star && t3lib_div::isFirstPartOfStr($pp[0],substr($el,0,-1)) )) {
1520 $nStyle[]=$pp[0].':'.$pp[1];
1521 } else unset($styleParts[$k]);
1522 }
1523 } else {
1524 unset($styleParts[$k]);
1525 }
1526 }
1527 return implode('; ',$nStyle);
1528 }
1529
1530 // Hook on lorem_ipsum extension to insert text into the RTE in wysiwyg mode
1531 function loremIpsumInsert($params) {
1532 return "
1533 if (typeof(lorem_ipsum) == 'function' && " . $params['element'] . ".tagName.toLowerCase() == 'textarea' ) lorem_ipsum(" . $params['element'] . ", lipsum_temp_strings[lipsum_temp_pointer]);
1534 ";
1535 }
1536 }
1537
1538 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/class.tx_rtehtmlarea_base.php']) {
1539 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/class.tx_rtehtmlarea_base.php']);
1540 }
1541
1542 ?>