2 /***************************************************************
5 * (c) 2005-2012 Stanislas Rolland <typo3(arobas)sjbr.ca>
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Front end RTE based on htmlArea
30 * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
32 class tx_rtehtmlarea_pi2
extends tx_rtehtmlarea_base
{
35 public $RTEWrapStyle = ''; // Alternative style for RTE wrapper <div> tag.
36 public $RTEdivStyle = ''; // Alternative style for RTE <div> tag.
44 var $RTEsetup = array();
45 var $thisConfig = array();
48 public $OutputCharset;
52 * @var t3lib_PageRenderer
54 protected $pageRenderer;
57 * Draws the RTE as an iframe
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!
71 function drawRTE($parentObject,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue) {
72 global $TSFE, $TYPO3_CONF_VARS, $TYPO3_DB;
74 $this->TCEform
= $parentObject;
75 $this->client
= $this->clientInfo();
76 $this->typoVersion
= t3lib_utility_VersionNumber
::convertVersionNumberToInteger(TYPO3_version
);
78 /* =======================================
79 * INIT THE EDITOR-SETTINGS
80 * =======================================
82 // Get the path to this extension:
83 $this->extHttpPath
= t3lib_extMgm
::siteRelPath($this->ID
);
85 $this->siteURL
= $GLOBALS['TSFE']->absRefPrefix ?
$GLOBALS['TSFE']->absRefPrefix
: '';
89 $this->elementId
= $PA['itemFormElName'];
90 $this->elementParts
[0] = $table;
91 $this->elementParts
[1] = $row['uid'];
92 $this->tscPID
= $thePidValue;
93 $this->thePid
= $thePidValue;
95 // Record "type" field value:
96 $this->typeVal
= $RTEtypeVal; // TCA "type" value for record
99 $pageTSConfig = $TSFE->getPagesTSconfig();
100 if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.'])) {
101 $this->RTEsetup
= $pageTSConfig['RTE.'];
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.'];
110 // Special configuration (line) and default extras:
111 $this->specConf
= $specConf;
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
);
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 * =======================================
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';
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']));
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']));
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';
167 $this->charset
= $TSFE->renderCharset
;
168 $this->OutputCharset
= $TSFE->metaCharset ?
$TSFE->metaCharset
: $TSFE->renderCharset
;
170 // Set the charset of the content
171 $this->contentCharset
= $TSFE->csConvObj
->charSetArray
[$this->contentTypo3Language
];
172 $this->contentCharset
= $this->contentCharset ?
$this->contentCharset
: 'iso-8859-1';
173 $this->contentCharset
= trim($TSFE->config
['config']['metaCharset']) ?
trim($TSFE->config
['config']['metaCharset']) : $this->contentCharset
;
175 /* =======================================
176 * TOOLBAR CONFIGURATION
177 * =======================================
179 $this->initializeToolbarConfiguration();
181 /* =======================================
183 * =======================================
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%';
193 $width = (intval($this->thisConfig
['RTEWidthOverride']) > 0) ?
intval($this->thisConfig
['RTEWidthOverride']) : $width;
196 $RTEWidth = strstr($width, '%') ?
$width : $width . 'px';
197 $editorWrapWidth = strstr($width, '%') ?
$width : ($width+
2) . 'px';
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;';
206 /* =======================================
207 * LOAD JS, CSS and more
208 * =======================================
210 $this->pageRenderer
= $this->getPageRenderer();
211 // Preloading the pageStyle and including RTE skin stylesheets
212 $this->addPageStyle();
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();
223 $this->pageRenderer
->addCssFile($this->siteURL
. 't3lib/js/extjs/ux/resize.css');
224 $this->pageRenderer
->addJsFile($this->siteURL
. $this->getFullFileName('t3lib/js/extjs/ux/ext.resizable.js'));
225 $this->pageRenderer
->addJsFile($this->siteURL
. $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();
233 /* =======================================
235 * =======================================
238 $value = $this->transformContent('rte',$PA['itemFormElValue'],$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$thePidValue);
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);
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>
255 * Add style sheet file to document header
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
263 protected function addStyleSheet($key, $href, $title='', $relation='stylesheet') {
264 $this->pageRenderer
->addCssFile($href, $relation, 'screen', $title);
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.
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
274 * @return string the JS-Code
276 function setSaveRTE($RTEcounter, $form, $textareaId) {
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();
288 * Gets instance of PageRenderer
290 * @return t3lib_PageRenderer
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');
300 $this->pageRenderer
= $GLOBALS['TSFE']->getPageRenderer();
302 $this->pageRenderer
->setBackPath(TYPO3_mainDir
);
304 return $this->pageRenderer
;
307 * Wrap input string in CDATA enclosure
309 * @param string $string: input to be wrapped
311 * @return string wrapped string
313 public function wrapCDATA ($string) {
324 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php'])) {
325 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php']);