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