* Merging all changes from TYPO3_4-0 branch back into HEAD
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / pi2 / class.tx_rtehtmlarea_pi2.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2005-2006 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
37 class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
38
39 // External:
40 var $RTEWrapStyle = ''; // Alternative style for RTE wrapper <div> tag.
41 var $RTEdivStyle = ''; // Alternative style for RTE <div> tag.
42 var $extHttpPath; // full Path to this extension for http (so no Server path). It ends with "/"
43
44 // For the editor
45 var $elementId;
46 var $elementParts;
47 var $tscPID;
48 var $typeVal;
49 var $thePid;
50 var $RTEsetup;
51 var $thisConfig;
52 var $confValues;
53 var $language;
54 var $spellCheckerLanguage;
55 var $spellCheckerCharset;
56 var $spellCheckerMode;
57 var $specConf;
58 var $LOCAL_LANG;
59
60 /**
61 * Draws the RTE as an iframe
62 *
63 * @param object Reference to parent object, which is an instance of the TCEforms.
64 * @param string The table name
65 * @param string The field name
66 * @param array The current row from which field is being rendered
67 * @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.
68 * @param array "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
69 * @param array Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
70 * @param string Record "type" field value.
71 * @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!
72 * @param integer PID value of record (true parent page id)
73 * @return string HTML code for RTE!
74 */
75 function drawRTE(&$pObj,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue) {
76 global $TSFE, $TYPO3_CONF_VARS, $TYPO3_DB;
77
78 //call $this->transformContent
79 //call $this->triggerField
80 $this->TCEform = $pObj;
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
113 unset($this->RTEsetup);
114 $pageTSConfig = $TSFE->getPagesTSconfig();
115 $this->RTEsetup = $pageTSConfig['RTE.'];
116 $this->thisConfig = $this->RTEsetup['default.'];
117 $this->thisConfig = $this->thisConfig['FE.'];
118
119 // Special configuration (line) and default extras:
120 $this->specConf = $specConf;
121
122 // Language
123 $TSFE->initLLvars();
124 $this->language = $TSFE->lang;
125 $this->LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $this->ID . '/locallang.xml', $this->language);
126 if ($this->language=='default' || !$this->language) {
127 $this->language='en';
128 }
129 // Character set
130 $this->charset = $TSFE->labelsCharset;
131 $this->OutputCharset = $TSFE->metaCharset ? $TSFE->metaCharset : $TSFE->renderCharset;
132
133 /* =======================================
134 * TOOLBAR CONFIGURATION
135 * =======================================
136 */
137 // htmlArea plugins list
138 $this->pluginEnableArray = array_intersect(t3lib_div::trimExplode(',', $this->pluginList , 1), t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['HTMLAreaPluginList'], 1));
139 $hidePlugins = array('TYPO3Browsers', 'UserElements', 'Acronym', 'TYPO3HtmlParser');
140 if ($this->client['BROWSER'] == 'opera') {
141 $hidePlugins[] = 'ContextMenu';
142 $this->thisConfig['hideTableOperationsInToolbar'] = 0;
143 }
144 if(!t3lib_extMgm::isLoaded('sr_static_info') || in_array($this->language, t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
145 $this->pluginEnableArray = array_diff($this->pluginEnableArray, $hidePlugins);
146 $this->pluginEnableArrayMultiple = $this->pluginEnableArray;
147
148 // Toolbar
149 $this->setToolBar();
150
151 // Check if some plugins need to be disabled
152 $this->setPlugins();
153
154 /* =======================================
155 * PLUGIN-SPECIFIC CONFIGURATION
156 * =======================================
157 */
158
159 if( $this->isPluginEnable('SpellChecker') ) {
160 // Set the language of the content for the SpellChecker
161 $this->spellCheckerLanguage = $TYPO3_CONF_VARS['EXTCONF']['rtehtmlarea']['defaultDictionary'];
162 if($row['sys_language_uid']) {
163 $tableA = 'sys_language';
164 $tableB = 'static_languages';
165 $languagesUidsList = $row['sys_language_uid'];
166 $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2,' . $tableB . '.lg_typo3';
167 $table = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
168 $whereClause = $tableA . '.uid IN (' . $languagesUidsList . ') ';
169 $whereClause .= $TSFE->cObj->enableFields($tableA);
170 $res = $TYPO3_DB->exec_SELECTquery($selectFields, $table, $whereClause);
171 while ( $languageRow = $TYPO3_DB->sql_fetch_assoc($res) ) {
172 $this->spellCheckerLanguage = strtolower(trim($languageRow['lg_iso_2']).(trim($languageRow['lg_country_iso_2'])?'_'.trim($languageRow['lg_country_iso_2']):''));
173 $this->spellCheckerTypo3Language = strtolower(trim($languageRow['lg_typo3']));
174 }
175 }
176 $this->spellCheckerLanguage = $this->spellCheckerLanguage?$this->spellCheckerLanguage:$this->language;
177 $this->spellCheckerTypo3Language = $this->spellCheckerTypo3Language?$this->spellCheckerTypo3Language:$TSFE->lang;
178 if ($this->spellCheckerTypo3Language=='default') {
179 $this->spellCheckerTypo3Language='en';
180 }
181
182 // Set the charset of the content for the SpellChecker
183 $this->spellCheckerCharset = $TSFE->csConvObj->charSetArray[$this->spellCheckerTypo3Language];
184 $this->spellCheckerCharset = $this->spellCheckerCharset ? $this->spellCheckerCharset : 'iso-8859-1';
185 $this->spellCheckerCharset = trim($TSFE->config['config']['metaCharset']) ? trim($TSFE->config['config']['metaCharset']) : $this->spellCheckerCharset;
186
187 // Set the SpellChecker mode
188 $this->spellCheckerMode = isset($this->thisConfig['HTMLAreaPspellMode']) ? trim($this->thisConfig['HTMLAreaPspellMode']) : 'normal';
189 if( !in_array($this->spellCheckerMode, $this->spellCheckerModes)) {
190 $this->spellCheckerMode = 'normal';
191 }
192 }
193
194 if( $this->isPluginEnable('QuickTag') && trim($this->thisConfig['hideTags'])) {
195 $this->quickTagHideTags = implode(',', t3lib_div::trimExplode(',', $this->thisConfig['hideTags'], 1));
196 }
197
198 /* =======================================
199 * SET STYLES
200 * =======================================
201 */
202
203 $RTEWidth = 460+($pObj->docLarge ? 150 : 0);
204 $RTEHeight = 380;
205 $editorWrapWidth = $RTEWidth . 'px';
206 $editorWrapHeight = $RTEHeight . 'px';
207 $this->RTEWrapStyle = $this->RTEWrapStyle ? $this->RTEWrapStyle : ($this->RTEdivStyle ? $this->RTEdivStyle : ('height:' . ($RTEHeight+2) . 'px; width:'. ($RTEWidth+2) . 'px;'));
208 $this->RTEdivStyle = $this->RTEdivStyle ? $this->RTEdivStyle : 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:'.$RTEWidth.'px; border: 1px solid black;';
209 $this->toolbar_level_size = $RTEWidth;
210
211 /* =======================================
212 * LOAD JS, CSS and more
213 * =======================================
214 */
215 // Preloading the pageStyle
216 $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/htmlarea/plugins/DynamicCSS/dynamiccss.css';
217 $additionalCode_loadCSS = '
218 <link rel="alternate stylesheet" type="text/css" href="' . $this->getFullFileName($filename) . '" />';
219
220 // Loading the editor skin
221 $skinFilename = trim($this->thisConfig['skin']) ? trim($this->thisConfig['skin']) : 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
222 if($this->client['BROWSER'] == 'gecko' && $this->client['VERSION'] == '1.3' && substr($skinFilename,0,4) == 'EXT:') {
223 $skinFilename = 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
224 }
225 if (substr($skinFilename,0,4) == 'EXT:') { // extension
226 list($extKey,$local) = explode('/',substr($skinFilename,4),2);
227 $skinFilename='';
228 if (strcmp($extKey,'') && t3lib_extMgm::isLoaded($extKey) && strcmp($local,'')) {
229 $skinFilename = $this->httpTypo3Path . t3lib_extMgm::siteRelPath($extKey).$local;
230 $skinDir = $this->siteURL . t3lib_extMgm::siteRelPath($extKey) . dirname($local);
231 }
232 } elseif (substr($skinFilename,0,1) != '/') {
233 $skinDir = $this->siteURL.dirname($skinFilename);
234 $skinFilename = $this->siteURL.$skinFilename;
235 } else {
236 $skinDir = substr($this->siteURL,0,-1) . dirname($skinFilename);
237 }
238
239 $this->editorCSS = $skinFilename;
240 $this->editedContentCSS = $skinDir . '/htmlarea-edited-content.css';
241 $additionalCode_loadCSS .= '
242 <link rel="alternate stylesheet" type="text/css" href="' . $this->editedContentCSS . '" />';
243 $additionalCode_loadCSS .= '
244 <link rel="stylesheet" type="text/css" href="' . $this->editorCSS . '" />';
245
246 // Loading CSS, JavaScript files and code
247 $TSFE->additionalHeaderData['htmlArea'] = $additionalCode_loadCSS;
248 $pObj->additionalJS_initial = $this->loadJSfiles($pObj->RTEcounter);
249 $pObj->additionalJS_pre[] = $this->loadJScode($pObj->RTEcounter);
250
251 /* =======================================
252 * DRAW THE EDITOR
253 * =======================================
254 */
255 // Transform value:
256 $value = $this->transformContent('rte',$PA['itemFormElValue'],$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$thePidValue);
257 if ($this->client['BROWSER'] == 'gecko') {
258 // change <strong> to <b>
259 $value = preg_replace('/<(\/?)strong/i', "<$1b", $value);
260 // change <em> to <i>
261 $value = preg_replace('/<(\/?)em([^b>]*>)/i', "<$1i$2", $value);
262 }
263
264 // Register RTE windows:
265 $pObj->RTEwindows[] = $PA['itemFormElName'];
266
267 // Register RTE in JS:
268 $pObj->additionalJS_post[] = $this->registerRTEinJS($pObj->RTEcounter);
269
270 // Set the save option for the RTE:
271 $pObj->additionalJS_submit[] = $this->setSaveRTE($pObj->RTEcounter, $pObj->formName, htmlspecialchars($PA['itemFormElName']));
272
273 // draw the textarea
274 $visibility = 'hidden';
275 $item = $this->triggerField($PA['itemFormElName']).'
276 <div id="pleasewait' . $pObj->RTEcounter . '" class="pleasewait">' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
277 <div id="editorWrap' . $pObj->RTEcounter . '" class="editorWrap" style="visibility:' . $visibility . '; '. htmlspecialchars($this->RTEWrapStyle). '">
278 <textarea id="RTEarea'.$pObj->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.htmlspecialchars($this->RTEdivStyle).'">'.t3lib_div::formatForTextarea($value).'</textarea>
279 </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
280 ';
281 return $item;
282 }
283
284 /**
285 * Return the JS-Code for copy the HTML-Code from the editor in the hidden input field.
286 * This is for submit function from the form.
287 *
288 * @return string the JS-Code
289 */
290 function setSaveRTE($number, $form, $textarea) {
291 return '
292 editornumber = '.$number.';
293 if (RTEarea[editornumber]) {
294 fields = document.getElementsByName(\'' . $textarea . '\');
295 field = fields.item(0);
296 if(field && field.tagName.toLowerCase() == \'textarea\') field.value = RTEarea[editornumber][\'editor\'].getHTML();
297 }
298 else {
299 OK=0;
300 }
301 ';
302 }
303
304 }
305
306 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php']) {
307 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php']);
308 }
309
310 ?>