* Feature/Cleanup: Acronym plugin of htmlArea RTE using new plugin API and enabled...
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / pi2 / class.tx_rtehtmlarea_pi2.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2005-2007 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Front end RTE based on htmlArea
29 *
30 * @author Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
31 *
32 * $Id$ *
33 */
34
35 require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlarea_base.php');
36 require_once(PATH_t3lib.'class.t3lib_parsehtml_proc.php');
37 require_once(PATH_t3lib.'class.t3lib_befunc.php');
38
39 class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
40
41 // External:
42 var $RTEWrapStyle = ''; // Alternative style for RTE wrapper <div> tag.
43 var $RTEdivStyle = ''; // Alternative style for RTE <div> tag.
44 var $extHttpPath; // full Path to this extension for http (so no Server path). It ends with "/"
45
46 // For the editor
47 var $elementId;
48 var $elementParts;
49 var $tscPID;
50 var $typeVal;
51 var $thePid;
52 var $RTEsetup;
53 var $thisConfig;
54 var $confValues;
55 var $language;
56 var $spellCheckerLanguage;
57 var $spellCheckerCharset;
58 var $spellCheckerMode;
59 var $specConf;
60 var $LOCAL_LANG;
61
62 /**
63 * Draws the RTE as an iframe
64 *
65 * @param object Reference to parent object, which is an instance of the TCEforms.
66 * @param string The table name
67 * @param string The field name
68 * @param array The current row from which field is being rendered
69 * @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.
70 * @param array "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
71 * @param array Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
72 * @param string Record "type" field value.
73 * @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!
74 * @param integer PID value of record (true parent page id)
75 * @return string HTML code for RTE!
76 */
77 function drawRTE($parentObject,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue) {
78 global $TSFE, $TYPO3_CONF_VARS, $TYPO3_DB;
79
80 $this->TCEform =& $parentObject;
81 $this->client = $this->clientInfo();
82 $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version);
83
84 /* =======================================
85 * INIT THE EDITOR-SETTINGS
86 * =======================================
87 */
88
89 // first get the http-path to typo3:
90 $this->httpTypo3Path = substr( substr( t3lib_div::getIndpEnv('TYPO3_SITE_URL'), strlen( t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') ) ), 0, -1 );
91 if (strlen($this->httpTypo3Path) == 1) {
92 $this->httpTypo3Path = '/';
93 } else {
94 $this->httpTypo3Path .= '/';
95 }
96 // Get the path to this extension:
97 $this->extHttpPath = $this->httpTypo3Path.t3lib_extMgm::siteRelPath($this->ID);
98 // Get the site URL
99 $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
100 // Get the host URL
101 $this->hostURL = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
102
103 // Element ID + pid
104 $this->elementId = $PA['itemFormElName'];
105 $this->elementParts[0] = $table;
106 $this->elementParts[1] = $row['uid'];
107 $this->tscPID = $thePidValue;
108 $this->thePid = $thePidValue;
109
110 // Record "type" field value:
111 $this->typeVal = $RTEtypeVal; // TCA "type" value for record
112 unset($this->RTEsetup);
113 $pageTSConfig = $TSFE->getPagesTSconfig();
114 $this->RTEsetup = $pageTSConfig['RTE.'];
115 $this->thisConfig = $this->RTEsetup['default.'];
116 $this->thisConfig = $this->thisConfig['FE.'];
117
118 // Special configuration (line) and default extras:
119 $this->specConf = $specConf;
120
121 if ($this->thisConfig['forceHTTPS']) {
122 $this->httpTypo3Path = preg_replace('/^(http|https)/', 'https', $this->httpTypo3Path);
123 $this->extHttpPath = preg_replace('/^(http|https)/', 'https', $this->extHttpPath);
124 $this->siteURL = preg_replace('/^(http|https)/', 'https', $this->siteURL);
125 $this->hostURL = preg_replace('/^(http|https)/', 'https', $this->hostURL);
126 }
127
128 // Language
129 $TSFE->initLLvars();
130 $this->language = $TSFE->lang;
131 $this->LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $this->ID . '/locallang.xml', $this->language);
132 if ($this->language=='default' || !$this->language) {
133 $this->language='en';
134 }
135 // Character set
136 $this->charset = $TSFE->labelsCharset;
137 $this->OutputCharset = $TSFE->metaCharset ? $TSFE->metaCharset : $TSFE->renderCharset;
138
139 /* =======================================
140 * TOOLBAR CONFIGURATION
141 * =======================================
142 */
143
144 // htmlArea plugins list
145 $this->pluginEnabledArray = t3lib_div::trimExplode(',', $this->pluginList, 1);
146 $this->enableRegisteredPlugins();
147 $hidePlugins = array('TYPO3Browsers', 'UserElements', 'TYPO3HtmlParser');
148 if ($this->client['BROWSER'] == 'opera') {
149 $hidePlugins[] = 'ContextMenu';
150 $this->thisConfig['hideTableOperationsInToolbar'] = 0;
151 $this->thisConfig['disableEnterParagraphs'] = 1;
152 }
153 if(!t3lib_extMgm::isLoaded('static_info_tables') || in_array($this->language, t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
154 $this->pluginEnabledArray = array_diff($this->pluginEnabledArray, $hidePlugins);
155
156 // Toolbar
157 $this->settoolbar();
158
159 // Check if some plugins need to be disabled
160 $this->setPlugins();
161
162 // Merge the list of enabled plugins with the lists from the previous RTE editing areas on the same form
163 $this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] = $this->pluginEnabledArray;
164 if ($this->TCEform->RTEcounter > 1 && isset($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1]) && is_array($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1])) {
165 $this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] = array_unique(array_values(array_merge($this->pluginEnabledArray,$this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter-1])));
166 }
167
168 /* =======================================
169 * PLUGIN-SPECIFIC CONFIGURATION
170 * =======================================
171 */
172
173 if( $this->isPluginEnabled('SpellChecker') ) {
174 // Set the language of the content for the SpellChecker
175 $this->spellCheckerLanguage = $TYPO3_CONF_VARS['EXTCONF']['rtehtmlarea']['defaultDictionary'];
176 if($row['sys_language_uid']) {
177 $tableA = 'sys_language';
178 $tableB = 'static_languages';
179 $languagesUidsList = $row['sys_language_uid'];
180 $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2,' . $tableB . '.lg_typo3';
181 $table = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
182 $whereClause = $tableA . '.uid IN (' . $languagesUidsList . ') ';
183 $whereClause .= $TSFE->cObj->enableFields($tableA);
184 $res = $TYPO3_DB->exec_SELECTquery($selectFields, $table, $whereClause);
185 while ( $languageRow = $TYPO3_DB->sql_fetch_assoc($res) ) {
186 $this->spellCheckerLanguage = strtolower(trim($languageRow['lg_iso_2']).(trim($languageRow['lg_country_iso_2'])?'_'.trim($languageRow['lg_country_iso_2']):''));
187 $this->spellCheckerTypo3Language = strtolower(trim($languageRow['lg_typo3']));
188 }
189 }
190 $this->spellCheckerLanguage = $this->spellCheckerLanguage?$this->spellCheckerLanguage:$this->language;
191 $this->spellCheckerTypo3Language = $this->spellCheckerTypo3Language?$this->spellCheckerTypo3Language:$TSFE->lang;
192 if ($this->spellCheckerTypo3Language=='default') {
193 $this->spellCheckerTypo3Language='en';
194 }
195
196 // Set the charset of the content for the SpellChecker
197 $this->spellCheckerCharset = $TSFE->csConvObj->charSetArray[$this->spellCheckerTypo3Language];
198 $this->spellCheckerCharset = $this->spellCheckerCharset ? $this->spellCheckerCharset : 'iso-8859-1';
199 $this->spellCheckerCharset = trim($TSFE->config['config']['metaCharset']) ? trim($TSFE->config['config']['metaCharset']) : $this->spellCheckerCharset;
200
201 // Set the SpellChecker mode
202 $this->spellCheckerMode = isset($this->thisConfig['HTMLAreaPspellMode']) ? trim($this->thisConfig['HTMLAreaPspellMode']) : 'normal';
203 if( !in_array($this->spellCheckerMode, $this->spellCheckerModes)) {
204 $this->spellCheckerMode = 'normal';
205 }
206 }
207
208 if( $this->isPluginEnabled('QuickTag') && trim($this->thisConfig['hideTags'])) {
209 $this->quickTagHideTags = implode(',', t3lib_div::trimExplode(',', $this->thisConfig['hideTags'], 1));
210 }
211
212 /* =======================================
213 * SET STYLES
214 * =======================================
215 */
216
217 $RTEWidth = 460+($this->TCEform->docLarge ? 150 : 0);
218 $RTEHeight = 380;
219 $editorWrapWidth = $RTEWidth . 'px';
220 $editorWrapHeight = $RTEHeight . 'px';
221 $this->RTEWrapStyle = $this->RTEWrapStyle ? $this->RTEWrapStyle : ($this->RTEdivStyle ? $this->RTEdivStyle : ('height:' . ($RTEHeight+2) . 'px; width:'. ($RTEWidth+2) . 'px;'));
222 $this->RTEdivStyle = $this->RTEdivStyle ? $this->RTEdivStyle : 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:'.$RTEWidth.'px; border: 1px solid black;';
223 $this->toolbar_level_size = $RTEWidth;
224
225 /* =======================================
226 * LOAD JS, CSS and more
227 * =======================================
228 */
229 // Preloading the pageStyle
230 $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/res/contentcss/default.css';
231 $additionalCode_loadCSS = '
232 <link rel="alternate stylesheet" type="text/css" href="' . $this->getFullFileName($filename) . '" title="HTMLArea RTE Content CSS" />';
233
234 // Loading the editor skin
235 $skinFilename = trim($this->thisConfig['skin']) ? trim($this->thisConfig['skin']) : 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
236 if($this->client['BROWSER'] == 'gecko' && $this->client['VERSION'] == '1.3' && substr($skinFilename,0,4) == 'EXT:') {
237 $skinFilename = 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
238 }
239 if (substr($skinFilename,0,4) == 'EXT:') { // extension
240 list($extKey,$local) = explode('/',substr($skinFilename,4),2);
241 $skinFilename='';
242 if (strcmp($extKey,'') && t3lib_extMgm::isLoaded($extKey) && strcmp($local,'')) {
243 $skinFilename = $this->httpTypo3Path . t3lib_extMgm::siteRelPath($extKey).$local;
244 $skinDir = $this->siteURL . t3lib_extMgm::siteRelPath($extKey) . dirname($local);
245 }
246 } elseif (substr($skinFilename,0,1) != '/') {
247 $skinDir = $this->siteURL.dirname($skinFilename);
248 $skinFilename = $this->siteURL.$skinFilename;
249 } else {
250 $skinDir = substr($this->siteURL,0,-1) . dirname($skinFilename);
251 }
252
253 $this->editorCSS = $skinFilename;
254 $this->editedContentCSS = $skinDir . '/htmlarea-edited-content.css';
255 $additionalCode_loadCSS .= '
256 <link rel="alternate stylesheet" type="text/css" href="' . $this->editedContentCSS . '" />';
257
258 // Main stylesheet
259 $additionalCode_loadCSS .= '
260 <link rel="stylesheet" type="text/css" href="' . $this->editorCSS . '" />';
261
262 // Additional icons from registered plugins
263 foreach ($this->pluginEnabledCumulativeArray[$this->TCEform->RTEcounter] as $pluginId) {
264 if (is_object($this->registeredPlugins[$pluginId])) {
265 $pathToSkin = $this->registeredPlugins[$pluginId]->getPathToSkin();
266 if ($pathToSkin) {
267 $additionalCode_loadCSS .= '
268 <link rel="stylesheet" type="text/css" href="' . $this->httpTypo3Path . t3lib_extMgm::siteRelPath($this->registeredPlugins[$pluginId]->getExtensionKey()) . $pathToSkin . '" />';
269 }
270 }
271 }
272
273 // Loading CSS, JavaScript files and code
274 $TSFE->additionalHeaderData['htmlArea'] = $additionalCode_loadCSS;
275 $this->TCEform->additionalJS_initial = $this->loadJSfiles($this->TCEform->RTEcounter);
276 $this->TCEform->additionalJS_pre[] = $this->loadJScode($this->TCEform->RTEcounter);
277
278 /* =======================================
279 * DRAW THE EDITOR
280 * =======================================
281 */
282 // Transform value:
283 $value = $this->transformContent('rte',$PA['itemFormElValue'],$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$thePidValue);
284
285 // Further content transformation by registered plugins
286 foreach ($this->registeredPlugins as $pluginId => $plugin) {
287 if ($this->isPluginEnabled($pluginId) && method_exists($plugin, "transformContent")) {
288 $value = $plugin->transformContent($value);
289 }
290 }
291
292 // Register RTE windows:
293 $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
294
295 // Register RTE in JS:
296 $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter);
297
298 // Set the save option for the RTE:
299 $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, htmlspecialchars($PA['itemFormElName']));
300
301 // draw the textarea
302 $visibility = 'hidden';
303 $item = $this->triggerField($PA['itemFormElName']).'
304 <div id="pleasewait' . $this->TCEform->RTEcounter . '" class="pleasewait" style="display: none;" >' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
305 <div id="editorWrap' . $this->TCEform->RTEcounter . '" class="editorWrap" style="'. htmlspecialchars($this->RTEWrapStyle). '">
306 <textarea id="RTEarea'.$this->TCEform->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.htmlspecialchars($this->RTEdivStyle).'">'.t3lib_div::formatForTextarea($value).'</textarea>
307 </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
308 ';
309 return $item;
310 }
311
312 /**
313 * Return the JS-Code for copy the HTML-Code from the editor in the hidden input field.
314 * This is for submit function from the form.
315 *
316 * @param integer $RTEcounter: The index number of the RTE editing area.
317 * @param string $form: the name of the form
318 * @param string $textarea: the name of the textarea
319 *
320 * @return string the JS-Code
321 */
322 function setSaveRTE($RTEcounter, $form, $textarea) {
323 return '
324 editornumber = '.$RTEcounter.';
325 if (RTEarea[editornumber]) {
326 fields = document.getElementsByName(\'' . $textarea . '\');
327 field = fields.item(0);
328 if(field && field.tagName.toLowerCase() == \'textarea\') field.value = RTEarea[editornumber][\'editor\'].getHTML();
329 }
330 else {
331 OK=0;
332 }
333 ';
334 }
335
336 }
337
338 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php']) {
339 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php']);
340 }
341
342 ?>