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