TYPO3 CMS  TYPO3_6-2
FrontendRteController.php
Go to the documentation of this file.
1 <?php
3 
22 
23  // External:
24  public $RTEWrapStyle = '';
25 
26  // Alternative style for RTE wrapper <div> tag.
27  public $RTEdivStyle = '';
28 
29  // Alternative style for RTE <div> tag.
30  // For the editor
34  public $elementId;
35 
39  public $elementParts;
40 
44  public $tscPID;
45 
49  public $typeVal;
50 
54  public $thePid;
55 
59  public $RTEsetup = array();
60 
64  public $thisConfig = array();
65 
69  public $confValues;
70 
71  public $language;
72 
74 
78  public $specConf;
79 
83  public $LOCAL_LANG;
84 
88  protected $pageRenderer;
89 
106  public function drawRTE(&$parentObject, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue) {
107  global $TSFE, $TYPO3_CONF_VARS, $TYPO3_DB;
108  $this->TCEform = $parentObject;
109  $this->client = $this->clientInfo();
111  /* =======================================
112  * INIT THE EDITOR-SETTINGS
113  * =======================================
114  */
115  // Get the path to this extension:
117  // Get the site URL
118  $this->siteURL = $GLOBALS['TSFE']->absRefPrefix ?: '';
119  // Get the host URL
120  $this->hostURL = '';
121  // Element ID + pid
122  $this->elementId = $PA['itemFormElName'];
123  $this->elementParts[0] = $table;
124  $this->elementParts[1] = $row['uid'];
125  $this->tscPID = $thePidValue;
126  $this->thePid = $thePidValue;
127  // Record "type" field value:
128  $this->typeVal = $RTEtypeVal;
129  // TCA "type" value for record
130  // RTE configuration
131  $pageTSConfig = $TSFE->getPagesTSconfig();
132  if (is_array($pageTSConfig) && is_array($pageTSConfig['RTE.'])) {
133  $this->RTEsetup = $pageTSConfig['RTE.'];
134  }
135  if (is_array($thisConfig) && !empty($thisConfig)) {
136  $this->thisConfig = $thisConfig;
137  } elseif (is_array($this->RTEsetup['default.']) && is_array($this->RTEsetup['default.']['FE.'])) {
138  $this->thisConfig = $this->RTEsetup['default.']['FE.'];
139  }
140  // Special configuration (line) and default extras:
141  $this->specConf = $specConf;
142  if ($this->thisConfig['forceHTTPS']) {
143  $this->extHttpPath = preg_replace('/^(http|https)/', 'https', $this->extHttpPath);
144  $this->siteURL = preg_replace('/^(http|https)/', 'https', $this->siteURL);
145  $this->hostURL = preg_replace('/^(http|https)/', 'https', $this->hostURL);
146  }
147  // Register RTE windows:
148  $this->TCEform->RTEwindows[] = $PA['itemFormElName'];
149  $textAreaId = preg_replace('/[^a-zA-Z0-9_:.-]/', '_', $PA['itemFormElName']);
150  $textAreaId = htmlspecialchars(preg_replace('/^[^a-zA-Z]/', 'x', $textAreaId)) . '_' . strval($this->TCEform->RTEcounter);
151  /* =======================================
152  * LANGUAGES & CHARACTER SETS
153  * =======================================
154  */
155  // Language
156  $GLOBALS['TSFE']->initLLvars();
157  $this->language = $GLOBALS['TSFE']->lang;
158  $this->LOCAL_LANG = \TYPO3\CMS\Core\Utility\GeneralUtility::readLLfile('EXT:' . $this->ID . '/locallang.xml', $this->language);
159  if ($this->language === 'default' || !$this->language) {
160  $this->language = 'en';
161  }
162  $this->contentISOLanguage = $GLOBALS['TSFE']->sys_language_isocode ?: 'en';
163  $this->contentLanguageUid = max($row['sys_language_uid'], 0);
164  if ($this->contentLanguageUid && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) {
165  $tableA = 'sys_language';
166  $tableB = 'static_languages';
167  $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2';
168  $tableAB = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
169  $whereClause = $tableA . '.uid = ' . intval($this->contentLanguageUid);
172  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selectFields, $tableAB, $whereClause);
173  while ($languageRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
174  $this->contentISOLanguage = strtolower(trim($languageRow['lg_iso_2']) . (trim($languageRow['lg_country_iso_2']) ? '_' . trim($languageRow['lg_country_iso_2']) : ''));
175  }
176  }
177  $this->contentTypo3Language = $this->contentISOLanguage;
178  // Character set
179  $this->charset = $TSFE->renderCharset;
180  $this->OutputCharset = $TSFE->metaCharset ?: $TSFE->renderCharset;
181  // Set the charset of the content
182  $this->contentCharset = $TSFE->csConvObj->charSetArray[$this->contentTypo3Language];
183  $this->contentCharset = $this->contentCharset ?: 'utf-8';
184  $this->contentCharset = trim($TSFE->config['config']['metaCharset']) ?: $this->contentCharset;
185  /* =======================================
186  * TOOLBAR CONFIGURATION
187  * =======================================
188  */
190  /* =======================================
191  * SET STYLES
192  * =======================================
193  */
194  $width = 610;
195  if (isset($this->thisConfig['RTEWidthOverride'])) {
196  if (strstr($this->thisConfig['RTEWidthOverride'], '%')) {
197  if ($this->client['browser'] != 'msie') {
198  $width = (int)$this->thisConfig['RTEWidthOverride'] > 0 ? $this->thisConfig['RTEWidthOverride'] : '100%';
199  }
200  } else {
201  $width = (int)$this->thisConfig['RTEWidthOverride'] > 0 ? (int)$this->thisConfig['RTEWidthOverride'] : $width;
202  }
203  }
204  $RTEWidth = strstr($width, '%') ? $width : $width . 'px';
205  $editorWrapWidth = strstr($width, '%') ? $width : ($width + 2) . 'px';
206  $height = 380;
207  $RTEHeightOverride = (int)$this->thisConfig['RTEHeightOverride'];
208  $height = $RTEHeightOverride > 0 ? $RTEHeightOverride : $height;
209  $RTEHeight = $height . 'px';
210  $editorWrapHeight = ($height + 2) . 'px';
211  $this->RTEWrapStyle = $this->RTEWrapStyle ?: ($this->RTEdivStyle ?: 'height:' . $editorWrapHeight . '; width:' . $editorWrapWidth . ';');
212  $this->RTEdivStyle = $this->RTEdivStyle ?: 'position:relative; left:0px; top:0px; height:' . $RTEHeight . '; width:' . $RTEWidth . '; border: 1px solid black;';
213  /* =======================================
214  * LOAD JS, CSS and more
215  * =======================================
216  */
217  $this->getPageRenderer();
218  // Register RTE in JS
219  $this->TCEform->additionalJS_post[] = $this->wrapCDATA($this->registerRTEinJS($this->TCEform->RTEcounter, '', '', '', $textAreaId));
220  // Set the save option for the RTE:
221  $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId);
222  // Loading ExtJs JavaScript files and inline code, if not configured in TS setup
223  if (!is_array($GLOBALS['TSFE']->pSetup['javascriptLibs.']['ExtJs.'])) {
224  $this->pageRenderer->loadExtJs();
225  $this->pageRenderer->enableExtJSQuickTips();
226  }
227  $this->pageRenderer->addJsFile($this->getFullFileName('typo3/js/extjs/ux/ext.resizable.js'));
228  $this->pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/notifications.js');
229  // Preloading the pageStyle and including RTE skin stylesheets
230  $this->addPageStyle();
231  $this->pageRenderer->addCssFile($this->siteURL . 'typo3/contrib/extjs/resources/css/ext-all-notheme.css');
232  $this->pageRenderer->addCssFile($this->siteURL . 'typo3/sysext/t3skin/extjs/xtheme-t3skin.css');
233  $this->addSkin();
234  $this->pageRenderer->addCssFile($this->siteURL . 'typo3/js/extjs/ux/resize.css');
235  // Add RTE JavaScript
236  $this->addRteJsFiles($this->TCEform->RTEcounter);
237  $this->pageRenderer->addJsFile($this->buildJSMainLangFile($this->TCEform->RTEcounter));
238  $this->pageRenderer->addJsInlineCode('HTMLArea-init', $this->getRteInitJsCode(), TRUE);
239  /* =======================================
240  * DRAW THE EDITOR
241  * =======================================
242  */
243  // Transform value:
244  $value = $this->transformContent('rte', $PA['itemFormElValue'], $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $thePidValue);
245  // Further content transformation by registered plugins
246  foreach ($this->registeredPlugins as $pluginId => $plugin) {
247  if ($this->isPluginEnabled($pluginId) && method_exists($plugin, 'transformContent')) {
248  $value = $plugin->transformContent($value);
249  }
250  }
251  // draw the textarea
252  $item = $this->triggerField($PA['itemFormElName']) . '
253  <div id="pleasewait' . $textAreaId . '" class="pleasewait" style="display: block;" >' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait', $this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
254  <div id="editorWrap' . $textAreaId . '" class="editorWrap" style="visibility: hidden; ' . htmlspecialchars($this->RTEWrapStyle) . '">
255  <textarea id="RTEarea' . $textAreaId . '" name="' . htmlspecialchars($PA['itemFormElName']) . '" rows="0" cols="0" style="' . htmlspecialchars($this->RTEdivStyle) . '">' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatForTextarea($value) . '</textarea>
256  </div>' . LF;
257  return $item;
258  }
259 
269  protected function addStyleSheet($key, $href, $title = '', $relation = 'stylesheet') {
270  $this->pageRenderer->addCssFile($href, $relation, 'screen', $title);
271  }
272 
283  public function setSaveRTE($RTEcounter, $form, $textareaId) {
284  return '
285  if (RTEarea[\'' . $textareaId . '\'] && !RTEarea[\'' . $textareaId . '\'].deleted) {
286  var field = document.getElementById(\'RTEarea' . $textareaId . '\');
287  if (field && field.nodeName.toLowerCase() == \'textarea\') {
288  field.value = RTEarea[\'' . $textareaId . '\'][\'editor\'].getHTML();
289  }
290  } else {
291  OK = 0;
292  }';
293  }
294 
300  public function getPageRenderer() {
301  if (!isset($this->pageRenderer)) {
302  $this->pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
303  $this->pageRenderer->setBackPath(TYPO3_mainDir);
304  }
305  return $this->pageRenderer;
306  }
307 
314  public function wrapCDATA($string) {
315  return implode(LF, array(
316  '',
317  '/*<![CDATA[*/',
318  $string,
319  '/*]]>*/'
320  ));
321  }
322 }
$TYPO3_CONF_VARS['SYS']['contentTable']
$TSFE
Definition: index_ts.php:72
transformContent($dirRTE, $value, $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $pid)
registerRTEinJS($RTEcounter, $table='', $uid='', $field='', $textAreaId='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static deleteClause($table, $tableAlias='')
addStyleSheet($key, $href, $title='', $relation='stylesheet')
drawRTE(&$parentObject, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue)