Fixed bug #14896: ExtJS is not included when RTE is invoked by USER_INT frontend...
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / pi2 / class.tx_rtehtmlarea_pi2.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2005-2010 Stanislas Rolland <typo3(arobas)sjbr.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 <typo3(arobas)sjbr.ca>
31 *
32 * $Id$ *
33 */
34 require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlarea_base.php');
35 class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
36
37 // External:
38 public $RTEWrapStyle = ''; // Alternative style for RTE wrapper <div> tag.
39 public $RTEdivStyle = ''; // Alternative style for RTE <div> tag.
40
41 // For the editor
42 var $elementId;
43 var $elementParts;
44 var $tscPID;
45 var $typeVal;
46 var $thePid;
47 var $RTEsetup = array();
48 var $thisConfig = array();
49 var $confValues;
50 public $language;
51 public $OutputCharset;
52 var $specConf;
53 var $LOCAL_LANG;
54 /**
55 * @var t3lib_PageRenderer
56 */
57 protected $pageRenderer;
58
59 /**
60 * Draws the RTE as an iframe
61 *
62 * @param object Reference to parent object, which is an instance of the TCEforms.
63 * @param string The table name
64 * @param string The field name
65 * @param array The current row from which field is being rendered
66 * @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.
67 * @param array "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
68 * @param array Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
69 * @param string Record "type" field value.
70 * @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!
71 * @param integer PID value of record (true parent page id)
72 * @return string HTML code for RTE!
73 */
74 function drawRTE($parentObject,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue) {
75 global $TSFE, $TYPO3_CONF_VARS, $TYPO3_DB;
76
77 $this->TCEform = $parentObject;
78 $this->client = $this->clientInfo();
79 $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version);
80
81 /* =======================================
82 * INIT THE EDITOR-SETTINGS
83 * =======================================
84 */
85 // Get the path to this extension:
86 $this->extHttpPath = t3lib_extMgm::siteRelPath($this->ID);
87 // Get the site URL
88 $this->siteURL = $GLOBALS['TSFE']->absRefPrefix ? $GLOBALS['TSFE']->absRefPrefix : '';
89 // Get the host URL
90 $this->hostURL = '';
91 // Element ID + pid
92 $this->elementId = $PA['itemFormElName'];
93 $this->elementParts[0] = $table;
94 $this->elementParts[1] = $row['uid'];
95 $this->tscPID = $thePidValue;
96 $this->thePid = $thePidValue;
97
98 // Record "type" field value:
99 $this->typeVal = $RTEtypeVal; // TCA "type" value for record
100
101 // RTE configuration
102 $pageTSConfig = $TSFE->getPagesTSconfig();
103 if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.'])) {
104 $this->RTEsetup = $pageTSConfig['RTE.'];
105 }
106
107 if (is_array($thisConfig) && !empty($thisConfig)) {
108 $this->thisConfig = $thisConfig;
109 } else if (is_array($this->RTEsetup['default.']) && is_array($this->RTEsetup['default.']['FE.'])) {
110 $this->thisConfig = $this->RTEsetup['default.']['FE.'];
111 }
112
113 // Special configuration (line) and default extras:
114 $this->specConf = $specConf;
115
116 if ($this->thisConfig['forceHTTPS']) {
117 $this->extHttpPath = preg_replace('/^(http|https)/', 'https', $this->extHttpPath);
118 $this->siteURL = preg_replace('/^(http|https)/', 'https', $this->siteURL);
119 $this->hostURL = preg_replace('/^(http|https)/', 'https', $this->hostURL);
120 }
121 /* =======================================
122 * LANGUAGES & CHARACTER SETS
123 * =======================================
124 */
125 // Language
126 $TSFE->initLLvars();
127 $this->language = $TSFE->lang;
128 $this->LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $this->ID . '/locallang.xml', $this->language);
129 if ($this->language == 'default' || !$this->language) {
130 $this->language = 'en';
131 }
132 $this->contentLanguageUid = ($row['sys_language_uid'] > 0) ? $row['sys_language_uid'] : 0;
133 if (t3lib_extMgm::isLoaded('static_info_tables')) {
134 if ($this->contentLanguageUid) {
135 $tableA = 'sys_language';
136 $tableB = 'static_languages';
137 $languagesUidsList = $this->contentLanguageUid;
138 $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2,' . $tableB . '.lg_typo3';
139 $tableAB = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
140 $whereClause = $tableA . '.uid IN (' . $languagesUidsList . ') ';
141 $whereClause .= t3lib_BEfunc::BEenableFields($tableA);
142 $whereClause .= t3lib_BEfunc::deleteClause($tableA);
143 $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause);
144 while($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) {
145 $this->contentISOLanguage = strtolower(trim($languageRow['lg_iso_2']).(trim($languageRow['lg_country_iso_2'])?'_'.trim($languageRow['lg_country_iso_2']):''));
146 $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
147 }
148 } else {
149 $this->contentISOLanguage = $GLOBALS['TSFE']->sys_language_isocode ? $GLOBALS['TSFE']->sys_language_isocode : 'en';
150 $selectFields = 'lg_iso_2, lg_typo3';
151 $tableAB = 'static_languages';
152 $whereClause = 'lg_iso_2 = ' . $TYPO3_DB->fullQuoteStr(strtoupper($this->contentISOLanguage), $tableAB);
153 $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause);
154 while($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) {
155 $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3']));
156 }
157 }
158 }
159 $this->contentISOLanguage = $this->contentISOLanguage ? $this->contentISOLanguage : ($GLOBALS['TSFE']->sys_language_isocode ? $GLOBALS['TSFE']->sys_language_isocode : 'en');
160 $this->contentTypo3Language = $this->contentTypo3Language ? $this->contentTypo3Language : $GLOBALS['TSFE']->lang;
161 if ($this->contentTypo3Language == 'default') {
162 $this->contentTypo3Language = 'en';
163 }
164
165 // Character set
166 $this->charset = $TSFE->renderCharset;
167 $this->OutputCharset = $TSFE->metaCharset ? $TSFE->metaCharset : $TSFE->renderCharset;
168
169 // Set the charset of the content
170 $this->contentCharset = $TSFE->csConvObj->charSetArray[$this->contentTypo3Language];
171 $this->contentCharset = $this->contentCharset ? $this->contentCharset : 'iso-8859-1';
172 $this->contentCharset = trim($TSFE->config['config']['metaCharset']) ? trim($TSFE->config['config']['metaCharset']) : $this->contentCharset;
173
174 /* =======================================
175 * TOOLBAR CONFIGURATION
176 * =======================================
177 */
178 $this->initializeToolbarConfiguration();
179
180 /* =======================================
181 * SET STYLES
182 * =======================================
183 */
184
185 $width = 460+($this->TCEform->docLarge ? 150 : 0);
186 if (isset($this->thisConfig['RTEWidthOverride'])) {
187 if (strstr($this->thisConfig['RTEWidthOverride'], '%')) {
188 if ($this->client['browser'] != 'msie') {
189 $width = (intval($this->thisConfig['RTEWidthOverride']) > 0) ? $this->thisConfig['RTEWidthOverride'] : '100%';
190 }
191 } else {
192 $width = (intval($this->thisConfig['RTEWidthOverride']) > 0) ? intval($this->thisConfig['RTEWidthOverride']) : $width;
193 }
194 }
195 $RTEWidth = strstr($width, '%') ? $width : $width . 'px';
196 $editorWrapWidth = strstr($width, '%') ? $width : ($width+2) . 'px';
197 $height = 380;
198 $RTEHeightOverride = intval($this->thisConfig['RTEHeightOverride']);
199 $height = ($RTEHeightOverride > 0) ? $RTEHeightOverride : $height;
200 $RTEHeight = $height . 'px';
201 $editorWrapHeight = ($height+2) . 'px';
202 $this->RTEWrapStyle = $this->RTEWrapStyle ? $this->RTEWrapStyle : ($this->RTEdivStyle ? $this->RTEdivStyle : ('height:' . $editorWrapHeight . '; width:'. $editorWrapWidth . ';'));
203 $this->RTEdivStyle = $this->RTEdivStyle ? $this->RTEdivStyle : 'position:relative; left:0px; top:0px; height:' . $RTEHeight . '; width:'.$RTEWidth.'; border: 1px solid black;';
204
205 /* =======================================
206 * LOAD JS, CSS and more
207 * =======================================
208 */
209 $pageRenderer = $this->getPageRenderer();
210 // Preloading the pageStyle and including RTE skin stylesheets
211 $this->addPageStyle();
212 $this->addSkin();
213 // Loading ExtJs JavaScript files and inline code, if not configured in TS setup
214 if (!$GLOBALS['TSFE']->isINTincScript() || !is_array($GLOBALS['TSFE']->pSetup['javascriptLibs.']['ExtJs.'])) {
215 $pageRenderer->loadExtJs();
216 $pageRenderer->enableExtJSQuickTips();
217 if (!$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts']) {
218 $pageRenderer->enableExtJsDebug();
219 }
220 }
221 $pageRenderer->addCssFile($this->siteURL . 't3lib/js/extjs/ux/resize.css');
222 $pageRenderer->addJsFile($this->siteURL . 't3lib/js/extjs/ux/ext.resizable.js');
223 if ($this->TCEform->RTEcounter == 1) {
224 $this->TCEform->additionalJS_pre['rtehtmlarea-loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter);
225 }
226 $this->TCEform->additionalJS_initial = $this->loadJSfiles($this->TCEform->RTEcounter);
227 $resizableSettings = array(
228 'textareaResize' => true,
229 'textareaMaxHeight' => '600'
230 );
231 $pageRenderer->addInlineSettingArray('', $resizableSettings);
232 if ($GLOBALS['TSFE']->isINTincScript()) {
233 $GLOBALS['TSFE']->additionalHeaderData['rtehtmlarea'] = $pageRenderer->render();
234 }
235 /* =======================================
236 * DRAW THE EDITOR
237 * =======================================
238 */
239 // Transform value:
240 $value = $this->transformContent('rte',$PA['itemFormElValue'],$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$thePidValue);
241
242 // Further content transformation by registered plugins
243 foreach ($this->registeredPlugins as $pluginId => $plugin) {
244 if ($this->isPluginEnabled($pluginId) && method_exists($plugin, "transformContent")) {
245 $value = $plugin->transformContent($value);
246 }
247 }
248
249 // Register RTE windows:
250 $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
251 $textAreaId = htmlspecialchars($PA['itemFormElName']);
252
253 // Register RTE in JS:
254 $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, '', '', '',$textAreaId);
255
256 // Set the save option for the RTE:
257 $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
258
259 // draw the textarea
260 $item = $this->triggerField($PA['itemFormElName']).'
261 <div id="pleasewait' . $textAreaId . '" class="pleasewait" style="display: block;" >' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
262 <div id="editorWrap' . $textAreaId . '" class="editorWrap" style="visibility: hidden; '. htmlspecialchars($this->RTEWrapStyle). '">
263 <textarea id="RTEarea' . $textAreaId . '" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.htmlspecialchars($this->RTEdivStyle).'">'.t3lib_div::formatForTextarea($value).'</textarea>
264 </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
265 ';
266 return $item;
267 }
268 /**
269 * Add style sheet file to document header
270 *
271 * @param string $key: some key identifying the style sheet
272 * @param string $href: uri to the style sheet file
273 * @param string $title: value for the title attribute of the link element
274 * @return string $relation: value for the rel attribute of the link element
275 * @return void
276 */
277 protected function addStyleSheet($key, $href, $title='', $relation='stylesheet') {
278 $this->pageRenderer->addCssFile($href, $relation, 'screen', $title);
279 }
280 /**
281 * Return the JS-Code for copy the HTML-Code from the editor in the hidden input field.
282 * This is for submit function from the form.
283 *
284 * @param integer $RTEcounter: The index number of the RTE editing area.
285 * @param string $form: the name of the form
286 * @param string $textareaId: the id of the textarea
287 *
288 * @return string the JS-Code
289 */
290 function setSaveRTE($RTEcounter, $form, $textareaId) {
291 return '
292 if (RTEarea[\'' . $textareaId . '\'] && !RTEarea[\'' . $textareaId . '\'].deleted) {
293 fields = document.getElementsByName(\'' . $textareaId . '\');
294 field = fields.item(0);
295 if (field && field.nodeName.toLowerCase() == \'textarea\') {
296 field.value = RTEarea[\'' . $textareaId . '\'][\'editor\'].getHTML();
297 }
298 } else {
299 OK = 0;
300 }';
301 }
302 /**
303 * Gets instance of PageRenderer
304 *
305 * @return t3lib_PageRenderer
306 */
307 public function getPageRenderer() {
308 if (!isset($this->pageRenderer)) {
309 if ($GLOBALS['TSFE']->isINTincScript()) {
310 // We use an instance of t3lib_PageRenderer to render additional header data
311 // because this script is invoked after header has been rendered by $GLOBALS['TSFE']->getPageRenderer()
312 $this->pageRenderer = t3lib_div::makeInstance('t3lib_PageRenderer');
313 $this->pageRenderer->setTemplateFile($this->extHttpPath . 'templates/rtehtmlarea_pageheader_frontend.html');
314 } else {
315 $this->pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
316 }
317 $this->pageRenderer->setBackPath(TYPO3_mainDir);
318 }
319 return $this->pageRenderer;
320 }
321 }
322 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php']) {
323 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php']);
324 }
325 ?>