TYPO3 CMS  TYPO3_7-6
PageGenerator.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
27 
35 {
40  const NO_PAGE_TITLE = 2;
41 
47  public static function pagegenInit()
48  {
50  $tsfe = $GLOBALS['TSFE'];
51  if ($tsfe->page['content_from_pid'] > 0) {
52  // make REAL copy of TSFE object - not reference!
53  $temp_copy_TSFE = clone $tsfe;
54  // Set ->id to the content_from_pid value - we are going to evaluate this pid as was it a given id for a page-display!
55  $temp_copy_TSFE->id = $tsfe->page['content_from_pid'];
56  $temp_copy_TSFE->MP = '';
57  $temp_copy_TSFE->getPageAndRootlineWithDomain($tsfe->config['config']['content_from_pid_allowOutsideDomain'] ? 0 : $tsfe->domainStartPage);
58  $tsfe->contentPid = (int)$temp_copy_TSFE->id;
59  unset($temp_copy_TSFE);
60  }
61  if ($tsfe->config['config']['MP_defaults']) {
62  $temp_parts = GeneralUtility::trimExplode('|', $tsfe->config['config']['MP_defaults'], true);
63  foreach ($temp_parts as $temp_p) {
64  list($temp_idP, $temp_MPp) = explode(':', $temp_p, 2);
65  $temp_ids = GeneralUtility::intExplode(',', $temp_idP);
66  foreach ($temp_ids as $temp_id) {
67  $tsfe->MP_defaults[$temp_id] = $temp_MPp;
68  }
69  }
70  }
71  // Global vars...
72  $tsfe->indexedDocTitle = $tsfe->page['title'];
73  $tsfe->debug = '' . $tsfe->config['config']['debug'];
74  // Base url:
75  if (isset($tsfe->config['config']['baseURL'])) {
76  $tsfe->baseUrl = $tsfe->config['config']['baseURL'];
77  // Deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8
78  $tsfe->anchorPrefix = substr(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), strlen(GeneralUtility::getIndpEnv('TYPO3_SITE_URL')));
79  }
80  // Internal and External target defaults
81  $tsfe->intTarget = '' . $tsfe->config['config']['intTarget'];
82  $tsfe->extTarget = '' . $tsfe->config['config']['extTarget'];
83  $tsfe->fileTarget = '' . $tsfe->config['config']['fileTarget'];
84  if ($tsfe->config['config']['spamProtectEmailAddresses'] === 'ascii') {
85  $tsfe->spamProtectEmailAddresses = 'ascii';
86  } else {
87  $tsfe->spamProtectEmailAddresses = MathUtility::forceIntegerInRange($tsfe->config['config']['spamProtectEmailAddresses'], -10, 10, 0);
88  }
89  // calculate the absolute path prefix
90  if (!empty($tsfe->config['config']['absRefPrefix'])) {
91  $absRefPrefix = trim($tsfe->config['config']['absRefPrefix']);
92  if ($absRefPrefix === 'auto') {
93  $tsfe->absRefPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
94  } else {
95  $tsfe->absRefPrefix = $absRefPrefix;
96  }
97  } else {
98  $tsfe->absRefPrefix = '';
99  }
100  if ($tsfe->type && $tsfe->config['config']['frameReloadIfNotInFrameset']) {
101  $tdlLD = $tsfe->tmpl->linkData($tsfe->page, '_top', $tsfe->no_cache, '');
102  $tsfe->additionalJavaScript['JSCode'] .= 'if(!parent.' . trim($tsfe->sPre) . ' && !parent.view_frame) top.location.href="' . $tsfe->baseUrlWrap($tdlLD['totalURL']) . '"';
103  }
104  $tsfe->compensateFieldWidth = '' . $tsfe->config['config']['compensateFieldWidth'];
105  $tsfe->lockFilePath = '' . $tsfe->config['config']['lockFilePath'];
106  $tsfe->lockFilePath = $tsfe->lockFilePath ?: $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'];
107  $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_noScaleUp'] = isset($tsfe->config['config']['noScaleUp']) ? '' . $tsfe->config['config']['noScaleUp'] : $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_noScaleUp'];
108  $tsfe->TYPO3_CONF_VARS['GFX']['im_noScaleUp'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_noScaleUp'];
109  $tsfe->ATagParams = trim($tsfe->config['config']['ATagParams']) ? ' ' . trim($tsfe->config['config']['ATagParams']) : '';
110  if ($tsfe->config['config']['setJS_mouseOver']) {
111  $tsfe->setJS('mouseOver');
112  }
113  if ($tsfe->config['config']['setJS_openPic']) {
114  $tsfe->setJS('openPic');
115  }
116  static::initializeSearchWordDataInTsfe();
117  // linkVars
118  $tsfe->calculateLinkVars();
119  // dtdAllowsFrames indicates whether to use the target attribute in links
120  $tsfe->dtdAllowsFrames = false;
121  if ($tsfe->config['config']['doctype']) {
122  if (in_array(
123  (string)$tsfe->config['config']['doctype'],
124  ['xhtml_trans', 'xhtml_frames', 'xhtml_basic', 'xhtml_2', 'html5'],
125  true)
126  ) {
127  $tsfe->dtdAllowsFrames = true;
128  }
129  } else {
130  $tsfe->dtdAllowsFrames = true;
131  }
132  // Setting XHTML-doctype from doctype
133  if (!$tsfe->config['config']['xhtmlDoctype']) {
134  $tsfe->config['config']['xhtmlDoctype'] = $tsfe->config['config']['doctype'];
135  }
136  if ($tsfe->config['config']['xhtmlDoctype']) {
137  $tsfe->xhtmlDoctype = $tsfe->config['config']['xhtmlDoctype'];
138  // Checking XHTML-docytpe
139  switch ((string)$tsfe->config['config']['xhtmlDoctype']) {
140  case 'xhtml_trans':
141 
142  case 'xhtml_strict':
143 
144  case 'xhtml_frames':
145  $tsfe->xhtmlVersion = 100;
146  break;
147  case 'xhtml_basic':
148  $tsfe->xhtmlVersion = 105;
149  break;
150  case 'xhtml_11':
151 
152  case 'xhtml+rdfa_10':
153  $tsfe->xhtmlVersion = 110;
154  break;
155  case 'xhtml_2':
156  GeneralUtility::deprecationLog('The option "config.xhtmlDoctype=xhtml_2" is deprecated since TYPO3 CMS 7, and will be removed with CMS 8');
157  $tsfe->xhtmlVersion = 200;
158  break;
159  default:
160  static::getPageRenderer()->setRenderXhtml(false);
161  $tsfe->xhtmlDoctype = '';
162  $tsfe->xhtmlVersion = 0;
163  }
164  } else {
165  static::getPageRenderer()->setRenderXhtml(false);
166  }
167  }
168 
175  public static function JSeventFunctions()
176  {
177  $functions = [];
178  $setEvents = [];
179  $setBody = [];
180  foreach ($GLOBALS['TSFE']->JSeventFuncCalls as $event => $handlers) {
181  if (!empty($handlers)) {
182  GeneralUtility::deprecationLog('The usage of $GLOBALS[\'TSFE\']->JSeventFuncCalls is deprecated as of TYPO3 CMS 7. Use Javascript directly.');
183  $functions[] = ' function T3_' . $event . 'Wrapper(e) { ' . implode(' ', $handlers) . ' }';
184  $setEvents[] = ' document.' . $event . '=T3_' . $event . 'Wrapper;';
185  if ($event == 'onload') {
186  // Dubiuos double setting breaks on some browser - do we need it?
187  $setBody[] = 'onload="T3_onloadWrapper();"';
188  }
189  }
190  }
191  return [!empty($functions) ? implode(LF, $functions) . LF . implode(LF, $setEvents) : '', $setBody];
192  }
193 
199  public static function renderContent()
200  {
202  $tsfe = $GLOBALS['TSFE'];
203 
205  $timeTracker = $GLOBALS['TT'];
206 
207  // PAGE CONTENT
208  $timeTracker->incStackPointer();
209  $timeTracker->push($tsfe->sPre, 'PAGE');
210  $pageContent = $tsfe->cObj->cObjGet($tsfe->pSetup);
211  if ($tsfe->pSetup['wrap']) {
212  $pageContent = $tsfe->cObj->wrap($pageContent, $tsfe->pSetup['wrap']);
213  }
214  if ($tsfe->pSetup['stdWrap.']) {
215  $pageContent = $tsfe->cObj->stdWrap($pageContent, $tsfe->pSetup['stdWrap.']);
216  }
217  // PAGE HEADER (after content - maybe JS is inserted!
218  // if 'disableAllHeaderCode' is set, all the header-code is discarded!
219  if ($tsfe->config['config']['disableAllHeaderCode']) {
220  $tsfe->content = $pageContent;
221  } else {
222  self::renderContentWithHeader($pageContent);
223  }
224  $timeTracker->pull($timeTracker->LR ? $tsfe->content : '');
225  $timeTracker->decStackPointer();
226  }
227 
234  public static function renderContentWithHeader($pageContent)
235  {
237  $tsfe = $GLOBALS['TSFE'];
238 
240  $timeTracker = $GLOBALS['TT'];
241 
242  $pageRenderer = static::getPageRenderer();
243  if ($tsfe->config['config']['moveJsFromHeaderToFooter']) {
244  $pageRenderer->enableMoveJsFromHeaderToFooter();
245  }
246  if ($tsfe->config['config']['pageRendererTemplateFile']) {
247  $file = $tsfe->tmpl->getFileName($tsfe->config['config']['pageRendererTemplateFile']);
248  if ($file) {
249  $pageRenderer->setTemplateFile($file);
250  }
251  }
252  $headerComment = $tsfe->config['config']['headerComment'];
253  if (trim($headerComment)) {
254  $pageRenderer->addInlineComment(TAB . str_replace(LF, (LF . TAB), trim($headerComment)) . LF);
255  }
256  // Setting charset:
257  $theCharset = $tsfe->metaCharset;
258  // Reset the content variables:
259  $tsfe->content = '';
260  $htmlTagAttributes = [];
261  $htmlLang = $tsfe->config['config']['htmlTag_langKey'] ?: ($tsfe->sys_language_isocode ?: 'en');
262  // Set content direction: (More info: http://www.tau.ac.il/~danon/Hebrew/HTML_and_Hebrew.html)
263  if ($tsfe->config['config']['htmlTag_dir']) {
264  $htmlTagAttributes['dir'] = htmlspecialchars($tsfe->config['config']['htmlTag_dir']);
265  }
266  // Setting document type:
267  $docTypeParts = [];
268  $xmlDocument = true;
269  // Part 1: XML prologue
270  switch ((string)$tsfe->config['config']['xmlprologue']) {
271  case 'none':
272  $xmlDocument = false;
273  break;
274  case 'xml_10':
275  $docTypeParts[] = '<?xml version="1.0" encoding="' . $theCharset . '"?>';
276  break;
277  case 'xml_11':
278  $docTypeParts[] = '<?xml version="1.1" encoding="' . $theCharset . '"?>';
279  break;
280  case '':
281  if ($tsfe->xhtmlVersion) {
282  $docTypeParts[] = '<?xml version="1.0" encoding="' . $theCharset . '"?>';
283  } else {
284  $xmlDocument = false;
285  }
286  break;
287  default:
288  $docTypeParts[] = $tsfe->config['config']['xmlprologue'];
289  }
290  // Part 2: DTD
291  $doctype = $tsfe->config['config']['doctype'];
292  if ($doctype) {
293  switch ($doctype) {
294  case 'xhtml_trans':
295  $docTypeParts[] = '<!DOCTYPE html
296  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
297  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
298  break;
299  case 'xhtml_strict':
300  $docTypeParts[] = '<!DOCTYPE html
301  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
302  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
303  break;
304  case 'xhtml_frames':
305  $docTypeParts[] = '<!DOCTYPE html
306  PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
307  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
308  break;
309  case 'xhtml_basic':
310  $docTypeParts[] = '<!DOCTYPE html
311  PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
312  "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">';
313  break;
314  case 'xhtml_11':
315  $docTypeParts[] = '<!DOCTYPE html
316  PUBLIC "-//W3C//DTD XHTML 1.1//EN"
317  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
318  break;
319  case 'xhtml_2':
320  $docTypeParts[] = '<!DOCTYPE html
321  PUBLIC "-//W3C//DTD XHTML 2.0//EN"
322  "http://www.w3.org/TR/xhtml2/DTD/xhtml2.dtd">';
323  break;
324  case 'xhtml+rdfa_10':
325  $docTypeParts[] = '<!DOCTYPE html
326  PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
327  "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">';
328  break;
329  case 'html5':
330  $docTypeParts[] = '<!DOCTYPE html>';
331  if ($xmlDocument) {
332  $pageRenderer->setMetaCharsetTag('<meta charset="|" />');
333  } else {
334  $pageRenderer->setMetaCharsetTag('<meta charset="|">');
335  }
336  break;
337  case 'none':
338  break;
339  default:
340  $docTypeParts[] = $doctype;
341  }
342  } else {
343  $docTypeParts[] = '<!DOCTYPE html>';
344  if ($xmlDocument) {
345  $pageRenderer->setMetaCharsetTag('<meta charset="|" />');
346  } else {
347  $pageRenderer->setMetaCharsetTag('<meta charset="|">');
348  }
349  }
350  if ($tsfe->xhtmlVersion) {
351  $htmlTagAttributes['xml:lang'] = $htmlLang;
352  }
353  if ($tsfe->xhtmlVersion < 110 || $doctype === 'html5') {
354  $htmlTagAttributes['lang'] = $htmlLang;
355  }
356  if ($tsfe->xhtmlVersion || $doctype === 'html5' && $xmlDocument) {
357  // We add this to HTML5 to achieve a slightly better backwards compatibility
358  $htmlTagAttributes['xmlns'] = 'http://www.w3.org/1999/xhtml';
359  if (is_array($tsfe->config['config']['namespaces.'])) {
360  foreach ($tsfe->config['config']['namespaces.'] as $prefix => $uri) {
361  // $uri gets htmlspecialchared later
362  $htmlTagAttributes['xmlns:' . htmlspecialchars($prefix)] = $uri;
363  }
364  }
365  }
366  // Swap XML and doctype order around (for MSIE / Opera standards compliance)
367  if ($tsfe->config['config']['doctypeSwitch']) {
368  $docTypeParts = array_reverse($docTypeParts);
369  }
370  // Adding doctype parts:
371  if (!empty($docTypeParts)) {
372  $pageRenderer->setXmlPrologAndDocType(implode(LF, $docTypeParts));
373  }
374  // Begin header section:
375  if ($tsfe->config['config']['htmlTag_setParams'] !== 'none') {
376  $_attr = $tsfe->config['config']['htmlTag_setParams'] ? $tsfe->config['config']['htmlTag_setParams'] : GeneralUtility::implodeAttributes($htmlTagAttributes);
377  } else {
378  $_attr = '';
379  }
380  $htmlTag = '<html' . ($_attr ? ' ' . $_attr : '') . '>';
381  if (isset($tsfe->config['config']['htmlTag_stdWrap.'])) {
382  $htmlTag = $tsfe->cObj->stdWrap($htmlTag, $tsfe->config['config']['htmlTag_stdWrap.']);
383  }
384  $pageRenderer->setHtmlTag($htmlTag);
385  // Head tag:
386  $headTag = $tsfe->pSetup['headTag'] ?: '<head>';
387  if (isset($tsfe->pSetup['headTag.'])) {
388  $headTag = $tsfe->cObj->stdWrap($headTag, $tsfe->pSetup['headTag.']);
389  }
390  $pageRenderer->setHeadTag($headTag);
391  // Setting charset meta tag:
392  $pageRenderer->setCharSet($theCharset);
393  $pageRenderer->addInlineComment(' This website is powered by TYPO3 - inspiring people to share!
394  TYPO3 is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.
395  TYPO3 is copyright ' . TYPO3_copyright_year . ' of Kasper Skaarhoj. Extensions are copyright of their respective owners.
396  Information and contribution at ' . TYPO3_URL_GENERAL . '
397 ');
398  if ($tsfe->baseUrl) {
399  $pageRenderer->setBaseUrl($tsfe->baseUrl);
400  }
401  if ($tsfe->pSetup['shortcutIcon']) {
402  $favIcon = ltrim($tsfe->tmpl->getFileName($tsfe->pSetup['shortcutIcon']), '/');
403  $iconFileInfo = GeneralUtility::makeInstance(ImageInfo::class, PATH_site . $favIcon);
404  if ($iconFileInfo->isFile()) {
405  $iconMimeType = $iconFileInfo->getMimeType();
406  if ($iconMimeType) {
407  $iconMimeType = ' type="' . $iconMimeType . '"';
408  $pageRenderer->setIconMimeType($iconMimeType);
409  }
410  $pageRenderer->setFavIcon(PathUtility::getAbsoluteWebPath($tsfe->absRefPrefix . $favIcon));
411  }
412  }
413  // Including CSS files
414  if (is_array($tsfe->tmpl->setup['plugin.'])) {
415  $stylesFromPlugins = '';
416  foreach ($tsfe->tmpl->setup['plugin.'] as $key => $iCSScode) {
417  if (is_array($iCSScode)) {
418  if ($iCSScode['_CSS_DEFAULT_STYLE'] && empty($tsfe->config['config']['removeDefaultCss'])) {
419  if (isset($iCSScode['_CSS_DEFAULT_STYLE.'])) {
420  $cssDefaultStyle = $tsfe->cObj->stdWrap($iCSScode['_CSS_DEFAULT_STYLE'], $iCSScode['_CSS_DEFAULT_STYLE.']);
421  } else {
422  $cssDefaultStyle = $iCSScode['_CSS_DEFAULT_STYLE'];
423  }
424  $stylesFromPlugins .= '/* default styles for extension "' . substr($key, 0, -1) . '" */' . LF . $cssDefaultStyle . LF;
425  }
426  if ($iCSScode['_CSS_PAGE_STYLE'] && empty($tsfe->config['config']['removePageCss'])) {
427  $cssPageStyle = implode(LF, $iCSScode['_CSS_PAGE_STYLE']);
428  if (isset($iCSScode['_CSS_PAGE_STYLE.'])) {
429  $cssPageStyle = $tsfe->cObj->stdWrap($cssPageStyle, $iCSScode['_CSS_PAGE_STYLE.']);
430  }
431  $cssPageStyle = '/* specific page styles for extension "' . substr($key, 0, -1) . '" */' . LF . $cssPageStyle;
432  self::addCssToPageRenderer($cssPageStyle, true, 'InlinePageCss');
433  }
434  }
435  }
436  if (!empty($stylesFromPlugins)) {
437  self::addCssToPageRenderer($stylesFromPlugins, false, 'InlineDefaultCss');
438  }
439  }
440  if ($tsfe->pSetup['stylesheet']) {
441  $ss = $tsfe->tmpl->getFileName($tsfe->pSetup['stylesheet']);
442  if ($ss) {
443  $pageRenderer->addCssFile($ss);
444  }
445  }
446  /**********************************************************************/
447  /* config.includeCSS / config.includeCSSLibs
448  /**********************************************************************/
449  if (is_array($tsfe->pSetup['includeCSS.'])) {
450  foreach ($tsfe->pSetup['includeCSS.'] as $key => $CSSfile) {
451  if (!is_array($CSSfile)) {
452  $cssFileConfig = &$tsfe->pSetup['includeCSS.'][$key . '.'];
453  if (isset($cssFileConfig['if.']) && !$tsfe->cObj->checkIf($cssFileConfig['if.'])) {
454  continue;
455  }
456  $ss = $cssFileConfig['external'] ? $CSSfile : $tsfe->tmpl->getFileName($CSSfile);
457  if ($ss) {
458  if ($cssFileConfig['import']) {
459  if (!$cssFileConfig['external'] && $ss[0] !== '/') {
460  // To fix MSIE 6 that cannot handle these as relative paths (according to Ben v Ende)
461  $ss = GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/' . $ss;
462  }
463  $pageRenderer->addCssInlineBlock('import_' . $key, '@import url("' . htmlspecialchars($ss) . '") ' . htmlspecialchars($cssFileConfig['media']) . ';', empty($cssFileConfig['disableCompression']), (bool)$cssFileConfig['forceOnTop'], '');
464  } else {
465  $pageRenderer->addCssFile(
466  $ss,
467  $cssFileConfig['alternate'] ? 'alternate stylesheet' : 'stylesheet',
468  $cssFileConfig['media'] ?: 'all',
469  $cssFileConfig['title'] ?: '',
470  empty($cssFileConfig['disableCompression']),
471  (bool)$cssFileConfig['forceOnTop'],
472  $cssFileConfig['allWrap'],
473  (bool)$cssFileConfig['excludeFromConcatenation'],
474  $cssFileConfig['allWrap.']['splitChar']
475  );
476  unset($cssFileConfig);
477  }
478  }
479  }
480  }
481  }
482  if (is_array($tsfe->pSetup['includeCSSLibs.'])) {
483  foreach ($tsfe->pSetup['includeCSSLibs.'] as $key => $CSSfile) {
484  if (!is_array($CSSfile)) {
485  $cssFileConfig = &$tsfe->pSetup['includeCSSLibs.'][$key . '.'];
486  if (isset($cssFileConfig['if.']) && !$tsfe->cObj->checkIf($cssFileConfig['if.'])) {
487  continue;
488  }
489  $ss = $cssFileConfig['external'] ? $CSSfile : $tsfe->tmpl->getFileName($CSSfile);
490  if ($ss) {
491  if ($cssFileConfig['import']) {
492  if (!$cssFileConfig['external'] && $ss[0] !== '/') {
493  // To fix MSIE 6 that cannot handle these as relative paths (according to Ben v Ende)
494  $ss = GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/' . $ss;
495  }
496  $pageRenderer->addCssInlineBlock('import_' . $key, '@import url("' . htmlspecialchars($ss) . '") ' . htmlspecialchars($cssFileConfig['media']) . ';', empty($cssFileConfig['disableCompression']), (bool)$cssFileConfig['forceOnTop'], '');
497  } else {
498  $pageRenderer->addCssLibrary(
499  $ss,
500  $cssFileConfig['alternate'] ? 'alternate stylesheet' : 'stylesheet',
501  $cssFileConfig['media'] ?: 'all',
502  $cssFileConfig['title'] ?: '',
503  empty($cssFileConfig['disableCompression']),
504  (bool)$cssFileConfig['forceOnTop'],
505  $cssFileConfig['allWrap'],
506  (bool)$cssFileConfig['excludeFromConcatenation'],
507  $cssFileConfig['allWrap.']['splitChar']
508  );
509  unset($cssFileConfig);
510  }
511  }
512  }
513  }
514  }
515 
516  // Stylesheets
517  $style = '';
518  if ($tsfe->pSetup['insertClassesFromRTE']) {
519  $pageTSConfig = $tsfe->getPagesTSconfig();
520  $RTEclasses = $pageTSConfig['RTE.']['classes.'];
521  if (is_array($RTEclasses)) {
522  foreach ($RTEclasses as $RTEclassName => $RTEvalueArray) {
523  if ($RTEvalueArray['value']) {
524  $style .= '
525 .' . substr($RTEclassName, 0, -1) . ' {' . $RTEvalueArray['value'] . '}';
526  }
527  }
528  }
529  if ($tsfe->pSetup['insertClassesFromRTE.']['add_mainStyleOverrideDefs'] && is_array($pageTSConfig['RTE.']['default.']['mainStyleOverride_add.'])) {
530  $mSOa_tList = GeneralUtility::trimExplode(',', strtoupper($tsfe->pSetup['insertClassesFromRTE.']['add_mainStyleOverrideDefs']), true);
531  foreach ($pageTSConfig['RTE.']['default.']['mainStyleOverride_add.'] as $mSOa_key => $mSOa_value) {
532  if (!is_array($mSOa_value) && (in_array('*', $mSOa_tList) || in_array($mSOa_key, $mSOa_tList))) {
533  $style .= '
534 ' . $mSOa_key . ' {' . $mSOa_value . '}';
535  }
536  }
537  }
538  }
539  // Setting body tag margins in CSS:
540  if (isset($tsfe->pSetup['bodyTagMargins']) && $tsfe->pSetup['bodyTagMargins.']['useCSS']) {
541  $margins = (int)$tsfe->pSetup['bodyTagMargins'];
542  $style .= '
543  BODY {margin: ' . $margins . 'px ' . $margins . 'px ' . $margins . 'px ' . $margins . 'px;}';
544  }
545  // CSS_inlineStyle from TS
546  $style .= trim($tsfe->pSetup['CSS_inlineStyle']);
547  $style .= $tsfe->cObj->cObjGet($tsfe->pSetup['cssInline.'], 'cssInline.');
548  if (trim($style)) {
549  self::addCssToPageRenderer($style, true, 'additionalTSFEInlineStyle');
550  }
551  // Javascript Libraries
552  if (is_array($tsfe->pSetup['javascriptLibs.'])) {
553  // Include jQuery into the page renderer
554  if (!empty($tsfe->pSetup['javascriptLibs.']['jQuery'])) {
555  $jQueryTS = $tsfe->pSetup['javascriptLibs.']['jQuery.'];
556  // Check if version / source is set, if not set variable to "NULL" to use the default of the page renderer
557  $version = isset($jQueryTS['version']) ? $jQueryTS['version'] : null;
558  $source = isset($jQueryTS['source']) ? $jQueryTS['source'] : null;
559  // When "noConflict" is not set or "1" enable the default jQuery noConflict mode, otherwise disable the namespace
560  if (!isset($jQueryTS['noConflict']) || !empty($jQueryTS['noConflict'])) {
561  // Set namespace to the "noConflict.namespace" value if "noConflict.namespace" has a value
562  if (!empty($jQueryTS['noConflict.']['namespace'])) {
563  $namespace = $jQueryTS['noConflict.']['namespace'];
564  } else {
566  }
567  } else {
569  }
570  $pageRenderer->loadJQuery($version, $source, $namespace);
571  }
572  if ($tsfe->pSetup['javascriptLibs.']['ExtJs']) {
573  $css = (bool)$tsfe->pSetup['javascriptLibs.']['ExtJs.']['css'];
574  $theme = (bool)$tsfe->pSetup['javascriptLibs.']['ExtJs.']['theme'];
575  $pageRenderer->loadExtJs($css, $theme);
576  if ($tsfe->pSetup['javascriptLibs.']['ExtJs.']['debug']) {
577  $pageRenderer->enableExtJsDebug();
578  }
579  }
580  }
581  // JavaScript library files
582  if (is_array($tsfe->pSetup['includeJSlibs.']) || is_array($tsfe->pSetup['includeJSLibs.'])) {
583  if (!is_array($tsfe->pSetup['includeJSlibs.'])) {
584  $tsfe->pSetup['includeJSlibs.'] = [];
585  } else {
586  GeneralUtility::deprecationLog('The property page.includeJSlibs is marked for deprecation and will be removed in TYPO3 CMS 8. Please use page.includeJSLibs (with an uppercase L) instead.');
587  }
588  if (!is_array($tsfe->pSetup['includeJSLibs.'])) {
589  $tsfe->pSetup['includeJSLibs.'] = [];
590  }
592  $tsfe->pSetup['includeJSLibs.'],
593  $tsfe->pSetup['includeJSlibs.']
594  );
595  unset($tsfe->pSetup['includeJSlibs.']);
596  foreach ($tsfe->pSetup['includeJSLibs.'] as $key => $JSfile) {
597  if (!is_array($JSfile)) {
598  if (isset($tsfe->pSetup['includeJSLibs.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJSLibs.'][$key . '.']['if.'])) {
599  continue;
600  }
601  $ss = $tsfe->pSetup['includeJSLibs.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
602  if ($ss) {
603  $jsFileConfig = &$tsfe->pSetup['includeJSLibs.'][$key . '.'];
604  $type = $jsFileConfig['type'];
605  if (!$type) {
606  $type = 'text/javascript';
607  }
608 
609  $pageRenderer->addJsLibrary(
610  $key,
611  $ss,
612  $type,
613  empty($jsFileConfig['disableCompression']),
614  (bool)$jsFileConfig['forceOnTop'],
615  $jsFileConfig['allWrap'],
616  (bool)$jsFileConfig['excludeFromConcatenation'],
617  $jsFileConfig['allWrap.']['splitChar'],
618  (bool)$jsFileConfig['async'],
619  $jsFileConfig['integrity']
620  );
621  unset($jsFileConfig);
622  }
623  }
624  }
625  }
626  if (is_array($tsfe->pSetup['includeJSFooterlibs.'])) {
627  foreach ($tsfe->pSetup['includeJSFooterlibs.'] as $key => $JSfile) {
628  if (!is_array($JSfile)) {
629  if (isset($tsfe->pSetup['includeJSFooterlibs.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJSFooterlibs.'][$key . '.']['if.'])) {
630  continue;
631  }
632  $ss = $tsfe->pSetup['includeJSFooterlibs.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
633  if ($ss) {
634  $jsFileConfig = &$tsfe->pSetup['includeJSFooterlibs.'][$key . '.'];
635  $type = $jsFileConfig['type'];
636  if (!$type) {
637  $type = 'text/javascript';
638  }
639  $pageRenderer->addJsFooterLibrary(
640  $key,
641  $ss,
642  $type,
643  empty($jsFileConfig['disableCompression']),
644  (bool)$jsFileConfig['forceOnTop'],
645  $jsFileConfig['allWrap'],
646  (bool)$jsFileConfig['excludeFromConcatenation'],
647  $jsFileConfig['allWrap.']['splitChar'],
648  (bool)$jsFileConfig['async'],
649  $jsFileConfig['integrity']
650  );
651  unset($jsFileConfig);
652  }
653  }
654  }
655  }
656  // JavaScript files
657  if (is_array($tsfe->pSetup['includeJS.'])) {
658  foreach ($tsfe->pSetup['includeJS.'] as $key => $JSfile) {
659  if (!is_array($JSfile)) {
660  if (isset($tsfe->pSetup['includeJS.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJS.'][$key . '.']['if.'])) {
661  continue;
662  }
663  $ss = $tsfe->pSetup['includeJS.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
664  if ($ss) {
665  $jsConfig = &$tsfe->pSetup['includeJS.'][$key . '.'];
666  $type = $jsConfig['type'];
667  if (!$type) {
668  $type = 'text/javascript';
669  }
670  $pageRenderer->addJsFile(
671  $ss,
672  $type,
673  empty($jsConfig['disableCompression']),
674  (bool)$jsConfig['forceOnTop'],
675  $jsConfig['allWrap'],
676  (bool)$jsConfig['excludeFromConcatenation'],
677  $jsConfig['allWrap.']['splitChar'],
678  (bool)$jsConfig['async'],
679  $jsConfig['integrity']
680  );
681  unset($jsConfig);
682  }
683  }
684  }
685  }
686  if (is_array($tsfe->pSetup['includeJSFooter.'])) {
687  foreach ($tsfe->pSetup['includeJSFooter.'] as $key => $JSfile) {
688  if (!is_array($JSfile)) {
689  if (isset($tsfe->pSetup['includeJSFooter.'][$key . '.']['if.']) && !$tsfe->cObj->checkIf($tsfe->pSetup['includeJSFooter.'][$key . '.']['if.'])) {
690  continue;
691  }
692  $ss = $tsfe->pSetup['includeJSFooter.'][$key . '.']['external'] ? $JSfile : $tsfe->tmpl->getFileName($JSfile);
693  if ($ss) {
694  $jsConfig = &$tsfe->pSetup['includeJSFooter.'][$key . '.'];
695  $type = $jsConfig['type'];
696  if (!$type) {
697  $type = 'text/javascript';
698  }
699  $pageRenderer->addJsFooterFile(
700  $ss,
701  $type,
702  empty($jsConfig['disableCompression']),
703  (bool)$jsConfig['forceOnTop'],
704  $jsConfig['allWrap'],
705  (bool)$jsConfig['excludeFromConcatenation'],
706  $jsConfig['allWrap.']['splitChar'],
707  (bool)$jsConfig['async'],
708  $jsConfig['integrity']
709  );
710  unset($jsConfig);
711  }
712  }
713  }
714  }
715  // Headerdata
716  if (is_array($tsfe->pSetup['headerData.'])) {
717  $pageRenderer->addHeaderData($tsfe->cObj->cObjGet($tsfe->pSetup['headerData.'], 'headerData.'));
718  }
719  // Footerdata
720  if (is_array($tsfe->pSetup['footerData.'])) {
721  $pageRenderer->addFooterData($tsfe->cObj->cObjGet($tsfe->pSetup['footerData.'], 'footerData.'));
722  }
723  static::generatePageTitle();
724 
725  $metaTagsHtml = static::generateMetaTagHtml(
726  isset($tsfe->pSetup['meta.']) ? $tsfe->pSetup['meta.'] : [],
727  $tsfe->xhtmlVersion,
728  $tsfe->cObj
729  );
730  foreach ($metaTagsHtml as $metaTag) {
731  $pageRenderer->addMetaTag($metaTag);
732  }
733 
734  unset($tsfe->additionalHeaderData['JSCode']);
735  if (is_array($tsfe->config['INTincScript'])) {
736  $tsfe->additionalHeaderData['JSCode'] = $tsfe->JSCode;
737  // Storing the JSCode vars...
738  $tsfe->config['INTincScript_ext']['divKey'] = $tsfe->uniqueHash();
739  $tsfe->config['INTincScript_ext']['additionalHeaderData'] = $tsfe->additionalHeaderData;
740  // Storing the header-data array
741  $tsfe->config['INTincScript_ext']['additionalFooterData'] = $tsfe->additionalFooterData;
742  // Storing the footer-data array
743  $tsfe->config['INTincScript_ext']['additionalJavaScript'] = $tsfe->additionalJavaScript;
744  // Storing the JS-data array
745  $tsfe->config['INTincScript_ext']['additionalCSS'] = $tsfe->additionalCSS;
746  // Storing the Style-data array
747  $tsfe->additionalHeaderData = ['<!--HD_' . $tsfe->config['INTincScript_ext']['divKey'] . '-->'];
748  // Clearing the array
749  $tsfe->additionalFooterData = ['<!--FD_' . $tsfe->config['INTincScript_ext']['divKey'] . '-->'];
750  // Clearing the array
751  $tsfe->divSection .= '<!--TDS_' . $tsfe->config['INTincScript_ext']['divKey'] . '-->';
752  } else {
753  $tsfe->INTincScript_loadJSCode();
754  }
755  $JSef = self::JSeventFunctions();
756  $scriptJsCode = $JSef[0];
757 
758  if ($tsfe->spamProtectEmailAddresses && $tsfe->spamProtectEmailAddresses !== 'ascii') {
759  $scriptJsCode = '
760  // decrypt helper function
761  function decryptCharcode(n,start,end,offset) {
762  n = n + offset;
763  if (offset > 0 && n > end) {
764  n = start + (n - end - 1);
765  } else if (offset < 0 && n < start) {
766  n = end - (start - n - 1);
767  }
768  return String.fromCharCode(n);
769  }
770  // decrypt string
771  function decryptString(enc,offset) {
772  var dec = "";
773  var len = enc.length;
774  for(var i=0; i < len; i++) {
775  var n = enc.charCodeAt(i);
776  if (n >= 0x2B && n <= 0x3A) {
777  dec += decryptCharcode(n,0x2B,0x3A,offset); // 0-9 . , - + / :
778  } else if (n >= 0x40 && n <= 0x5A) {
779  dec += decryptCharcode(n,0x40,0x5A,offset); // A-Z @
780  } else if (n >= 0x61 && n <= 0x7A) {
781  dec += decryptCharcode(n,0x61,0x7A,offset); // a-z
782  } else {
783  dec += enc.charAt(i);
784  }
785  }
786  return dec;
787  }
788  // decrypt spam-protected emails
789  function linkTo_UnCryptMailto(s) {
790  location.href = decryptString(s,' . $tsfe->spamProtectEmailAddresses * -1 . ');
791  }
792  ';
793  }
794  // Add inline JS
795  $inlineJS = '';
796  // defined in php
797  if (is_array($tsfe->inlineJS)) {
798  foreach ($tsfe->inlineJS as $key => $val) {
799  if (!is_array($val)) {
800  $inlineJS .= LF . $val . LF;
801  }
802  }
803  }
804  // defined in TS with page.inlineJS
805  // Javascript inline code
806  $inline = $tsfe->cObj->cObjGet($tsfe->pSetup['jsInline.'], 'jsInline.');
807  if ($inline) {
808  $inlineJS .= LF . $inline . LF;
809  }
810  // Javascript inline code for Footer
811  $inlineFooterJs = $tsfe->cObj->cObjGet($tsfe->pSetup['jsFooterInline.'], 'jsFooterInline.');
812  // Should minify?
813  if ($tsfe->config['config']['compressJs']) {
814  $pageRenderer->enableCompressJavascript();
815  $minifyErrorScript = ($minifyErrorInline = '');
816  $scriptJsCode = GeneralUtility::minifyJavaScript($scriptJsCode, $minifyErrorScript);
817  if ($minifyErrorScript) {
818  $timeTracker->setTSlogMessage($minifyErrorScript, 3);
819  }
820  if ($inlineJS) {
821  $inlineJS = GeneralUtility::minifyJavaScript($inlineJS, $minifyErrorInline);
822  if ($minifyErrorInline) {
823  $timeTracker->setTSlogMessage($minifyErrorInline, 3);
824  }
825  }
826  if ($inlineFooterJs) {
827  $inlineFooterJs = GeneralUtility::minifyJavaScript($inlineFooterJs, $minifyErrorInline);
828  if ($minifyErrorInline) {
829  $timeTracker->setTSlogMessage($minifyErrorInline, 3);
830  }
831  }
832  }
833  if (!$tsfe->config['config']['removeDefaultJS']) {
834  // inlude default and inlineJS
835  if ($scriptJsCode) {
836  $pageRenderer->addJsInlineCode('_scriptCode', $scriptJsCode, $tsfe->config['config']['compressJs']);
837  }
838  if ($inlineJS) {
839  $pageRenderer->addJsInlineCode('TS_inlineJS', $inlineJS, $tsfe->config['config']['compressJs']);
840  }
841  if ($inlineFooterJs) {
842  $pageRenderer->addJsFooterInlineCode('TS_inlineFooter', $inlineFooterJs, $tsfe->config['config']['compressJs']);
843  }
844  } elseif ($tsfe->config['config']['removeDefaultJS'] === 'external') {
845  /*
846  * This keeps inlineJS from *_INT Objects from being moved to external files.
847  * At this point in frontend rendering *_INT Objects only have placeholders instead
848  * of actual content so moving these placeholders to external files would
849  * a) break the JS file (syntax errors due to the placeholders)
850  * b) the needed JS would never get included to the page
851  * Therefore inlineJS from *_INT Objects must not be moved to external files but
852  * kept internal.
853  */
854  $inlineJSint = '';
855  self::stripIntObjectPlaceholder($inlineJS, $inlineJSint);
856  if ($inlineJSint) {
857  $pageRenderer->addJsInlineCode('TS_inlineJSint', $inlineJSint, $tsfe->config['config']['compressJs']);
858  }
859  if (trim($scriptJsCode . $inlineJS)) {
860  $pageRenderer->addJsFile(self::inline2TempFile($scriptJsCode . $inlineJS, 'js'), 'text/javascript', $tsfe->config['config']['compressJs']);
861  }
862  if ($inlineFooterJs) {
863  $inlineFooterJSint = '';
864  self::stripIntObjectPlaceholder($inlineFooterJs, $inlineFooterJSint);
865  if ($inlineFooterJSint) {
866  $pageRenderer->addJsFooterInlineCode('TS_inlineFooterJSint', $inlineFooterJSint, $tsfe->config['config']['compressJs']);
867  }
868  $pageRenderer->addJsFooterFile(self::inline2TempFile($inlineFooterJs, 'js'), 'text/javascript', $tsfe->config['config']['compressJs']);
869  }
870  } else {
871  // Include only inlineJS
872  if ($inlineJS) {
873  $pageRenderer->addJsInlineCode('TS_inlineJS', $inlineJS, $tsfe->config['config']['compressJs']);
874  }
875  if ($inlineFooterJs) {
876  $pageRenderer->addJsFooterInlineCode('TS_inlineFooter', $inlineFooterJs, $tsfe->config['config']['compressJs']);
877  }
878  }
879  if (is_array($tsfe->pSetup['inlineLanguageLabelFiles.'])) {
880  foreach ($tsfe->pSetup['inlineLanguageLabelFiles.'] as $key => $languageFile) {
881  if (is_array($languageFile)) {
882  continue;
883  }
884  $languageFileConfig = &$tsfe->pSetup['inlineLanguageLabelFiles.'][$key . '.'];
885  if (isset($languageFileConfig['if.']) && !$tsfe->cObj->checkIf($languageFileConfig['if.'])) {
886  continue;
887  }
888  $pageRenderer->addInlineLanguageLabelFile(
889  $languageFile,
890  $languageFileConfig['selectionPrefix'] ?: '',
891  $languageFileConfig['stripFromSelectionName'] ?: '',
892  $languageFileConfig['errorMode'] ? (int)$languageFileConfig['errorMode'] : 0
893  );
894  }
895  }
896  // ExtJS specific code
897  if (is_array($tsfe->pSetup['inlineLanguageLabel.'])) {
898  $pageRenderer->addInlineLanguageLabelArray($tsfe->pSetup['inlineLanguageLabel.'], true);
899  }
900  if (is_array($tsfe->pSetup['inlineSettings.'])) {
901  $pageRenderer->addInlineSettingArray('TS', $tsfe->pSetup['inlineSettings.']);
902  }
903  if (is_array($tsfe->pSetup['extOnReady.'])) {
904  $pageRenderer->addExtOnReadyCode($tsfe->cObj->cObjGet($tsfe->pSetup['extOnReady.'], 'extOnReady.'));
905  }
906  // Compression and concatenate settings
907  if ($tsfe->config['config']['compressCss']) {
908  $pageRenderer->enableCompressCss();
909  }
910  if ($tsfe->config['config']['compressJs']) {
911  $pageRenderer->enableCompressJavascript();
912  }
913  if ($tsfe->config['config']['concatenateCss']) {
914  $pageRenderer->enableConcatenateCss();
915  }
916  if ($tsfe->config['config']['concatenateJs']) {
917  $pageRenderer->enableConcatenateJavascript();
918  }
919  // Backward compatibility for old configuration
920  if ($tsfe->config['config']['concatenateJsAndCss']) {
921  $pageRenderer->enableConcatenateFiles();
922  }
923  // Add header data block
924  if ($tsfe->additionalHeaderData) {
925  $pageRenderer->addHeaderData(implode(LF, $tsfe->additionalHeaderData));
926  }
927  // Add footer data block
928  if ($tsfe->additionalFooterData) {
929  $pageRenderer->addFooterData(implode(LF, $tsfe->additionalFooterData));
930  }
931  // Header complete, now add content
932  if ($tsfe->pSetup['frameSet.']) {
933  $fs = GeneralUtility::makeInstance(FramesetRenderer::class);
934  $pageRenderer->addBodyContent($fs->make($tsfe->pSetup['frameSet.']));
935  $pageRenderer->addBodyContent(LF . '<noframes>' . LF);
936  }
937  // Bodytag:
938  if ($tsfe->config['config']['disableBodyTag']) {
939  $bodyTag = '';
940  } else {
941  $defBT = $tsfe->pSetup['bodyTagCObject'] ? $tsfe->cObj->cObjGetSingle($tsfe->pSetup['bodyTagCObject'], $tsfe->pSetup['bodyTagCObject.'], 'bodyTagCObject') : '';
942  if (!$defBT) {
943  $defBT = $tsfe->defaultBodyTag;
944  }
945  $bodyTag = $tsfe->pSetup['bodyTag'] ? $tsfe->pSetup['bodyTag'] : $defBT;
946  if ($bgImg = $tsfe->cObj->getImgResource($tsfe->pSetup['bgImg'], $tsfe->pSetup['bgImg.'])) {
947  GeneralUtility::deprecationLog('The option "page.bgImg" is deprecated since TYPO3 CMS 7, and will be removed with CMS 8');
948  $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' background="' . $tsfe->absRefPrefix . $bgImg[3] . '">';
949  }
950  if (isset($tsfe->pSetup['bodyTagMargins'])) {
951  $margins = (int)$tsfe->pSetup['bodyTagMargins'];
952  if ($tsfe->pSetup['bodyTagMargins.']['useCSS']) {
953  } else {
954  $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' leftmargin="' . $margins . '" topmargin="' . $margins . '" marginwidth="' . $margins . '" marginheight="' . $margins . '">';
955  }
956  }
957  if (trim($tsfe->pSetup['bodyTagAdd'])) {
958  $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' ' . trim($tsfe->pSetup['bodyTagAdd']) . '>';
959  }
960  // Event functions
961  if (!empty($JSef[1])) {
962  $bodyTag = preg_replace('/>$/', '', trim($bodyTag)) . ' ' . trim(implode(' ', $JSef[1])) . '>';
963  }
964  }
965  $pageRenderer->addBodyContent(LF . $bodyTag);
966  // Div-sections
967  if ($tsfe->divSection) {
968  $pageRenderer->addBodyContent(LF . $tsfe->divSection);
969  }
970  // Page content
971  $pageRenderer->addBodyContent(LF . $pageContent);
972  if (!empty($tsfe->config['INTincScript']) && is_array($tsfe->config['INTincScript'])) {
973  // Store the serialized pageRenderer in configuration
974  $tsfe->config['INTincScript_ext']['pageRenderer'] = serialize($pageRenderer);
975  // Render complete page, keep placeholders for JavaScript and CSS
976  $tsfe->content = $pageRenderer->renderPageWithUncachedObjects($tsfe->config['INTincScript_ext']['divKey']);
977  } else {
978  // Render complete page
979  $tsfe->content = $pageRenderer->render();
980  }
981  // Ending page
982  if ($tsfe->pSetup['frameSet.']) {
983  $tsfe->content .= LF . '</noframes>';
984  }
985  }
986 
987  /*************************
988  *
989  * Helper functions
990  * Remember: Calls internally must still be done on the non-instantiated class: PageGenerator::inline2TempFile()
991  *
992  *************************/
1000  protected static function stripIntObjectPlaceholder(&$searchString, &$intObjects)
1001  {
1002  $tempArray = [];
1003  preg_match_all('/\\<\\!--INT_SCRIPT.[a-z0-9]*--\\>/', $searchString, $tempArray);
1004  $searchString = preg_replace('/\\<\\!--INT_SCRIPT.[a-z0-9]*--\\>/', '', $searchString);
1005  $intObjects = implode('', $tempArray[0]);
1006  }
1007 
1015  public static function inline2TempFile($str, $ext)
1016  {
1017  // Create filename / tags:
1018  $script = '';
1019  switch ($ext) {
1020  case 'js':
1021  $script = 'typo3temp/Assets/' . substr(md5($str), 0, 10) . '.js';
1022  break;
1023  case 'css':
1024  $script = 'typo3temp/Assets/' . substr(md5($str), 0, 10) . '.css';
1025  break;
1026  }
1027  // Write file:
1028  if ($script) {
1029  if (!@is_file(PATH_site . $script)) {
1030  GeneralUtility::writeFileToTypo3tempDir(PATH_site . $script, $str);
1031  }
1032  }
1033  return $script;
1034  }
1035 
1043  public static function isAllowedLinkVarValue($haystack, $needle)
1044  {
1045  $OK = false;
1046  // Integer
1047  if ($needle == 'int' || $needle == 'integer') {
1048  if (MathUtility::canBeInterpretedAsInteger($haystack)) {
1049  $OK = true;
1050  }
1051  } elseif (preg_match('/^\\/.+\\/[imsxeADSUXu]*$/', $needle)) {
1052  // Regular expression, only "//" is allowed as delimiter
1053  if (@preg_match($needle, $haystack)) {
1054  $OK = true;
1055  }
1056  } elseif (strstr($needle, '-')) {
1057  // Range
1058  if (MathUtility::canBeInterpretedAsInteger($haystack)) {
1059  $range = explode('-', $needle);
1060  if ($range[0] <= $haystack && $range[1] >= $haystack) {
1061  $OK = true;
1062  }
1063  }
1064  } elseif (strstr($needle, '|')) {
1065  // List
1066  // Trim the input
1067  $haystack = str_replace(' ', '', $haystack);
1068  if (strstr('|' . $needle . '|', '|' . $haystack . '|')) {
1069  $OK = true;
1070  }
1071  } elseif ((string)$needle === (string)$haystack) {
1072  // String comparison
1073  $OK = true;
1074  }
1075  return $OK;
1076  }
1077 
1086  public static function generatePageTitle()
1087  {
1089  $tsfe = $GLOBALS['TSFE'];
1090 
1091  $pageTitleSeparator = '';
1092 
1093  // check for a custom pageTitleSeparator, and perform stdWrap on it
1094  if (isset($tsfe->config['config']['pageTitleSeparator']) && $tsfe->config['config']['pageTitleSeparator'] !== '') {
1095  $pageTitleSeparator = $tsfe->config['config']['pageTitleSeparator'];
1096 
1097  if (isset($tsfe->config['config']['pageTitleSeparator.']) && is_array($tsfe->config['config']['pageTitleSeparator.'])) {
1098  $pageTitleSeparator = $tsfe->cObj->stdWrap($pageTitleSeparator, $tsfe->config['config']['pageTitleSeparator.']);
1099  } else {
1100  $pageTitleSeparator .= ' ';
1101  }
1102  }
1103 
1104  $titleTagContent = $tsfe->tmpl->printTitle(
1105  $tsfe->altPageTitle ?: $tsfe->page['title'],
1106  $tsfe->config['config']['noPageTitle'],
1107  $tsfe->config['config']['pageTitleFirst'],
1108  $pageTitleSeparator
1109  );
1110  if ($tsfe->config['config']['titleTagFunction']) {
1111  $titleTagContent = $tsfe->cObj->callUserFunction(
1112  $tsfe->config['config']['titleTagFunction'],
1113  [],
1114  $titleTagContent
1115  );
1116  }
1117  // stdWrap around the title tag
1118  if (isset($tsfe->config['config']['pageTitle.']) && is_array($tsfe->config['config']['pageTitle.'])) {
1119  $titleTagContent = $tsfe->cObj->stdWrap($titleTagContent, $tsfe->config['config']['pageTitle.']);
1120  }
1121  if ($titleTagContent !== '' && (int)$tsfe->config['config']['noPageTitle'] !== self::NO_PAGE_TITLE) {
1122  static::getPageRenderer()->setTitle($titleTagContent);
1123  }
1124  }
1125 
1134  protected static function generateMetaTagHtml(array $metaTagTypoScript, $xhtml, ContentObjectRenderer $cObj)
1135  {
1136  // Add ending slash only to documents rendered as xhtml
1137  $endingSlash = $xhtml ? ' /' : '';
1138 
1139  $metaTags = [
1140  '<meta name="generator" content="TYPO3 CMS"' . $endingSlash . '>'
1141  ];
1142 
1144  $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
1145  $conf = $typoScriptService->convertTypoScriptArrayToPlainArray($metaTagTypoScript);
1146  foreach ($conf as $key => $properties) {
1147  if (is_array($properties)) {
1148  $nodeValue = isset($properties['_typoScriptNodeValue']) ? $properties['_typoScriptNodeValue'] : '';
1149  $value = trim($cObj->stdWrap($nodeValue, $metaTagTypoScript[$key . '.']));
1150  if ($value === '' && !empty($properties['value'])) {
1151  $value = $properties['value'];
1152  }
1153  } else {
1154  $value = $properties;
1155  }
1156 
1157  $attribute = 'name';
1158  if ((is_array($properties) && !empty($properties['httpEquivalent'])) || strtolower($key) === 'refresh') {
1159  $attribute = 'http-equiv';
1160  }
1161  if (is_array($properties) && !empty($properties['attribute'])) {
1162  $attribute = $properties['attribute'];
1163  }
1164 
1165  if (!is_array($value)) {
1166  $value = (array)$value;
1167  }
1168  foreach ($value as $subValue) {
1169  if (trim($subValue) !== '') {
1170  $metaTags[] = '<meta ' . $attribute . '="' . $key . '" content="' . htmlspecialchars($subValue) . '"' . $endingSlash . '>';
1171  }
1172  }
1173  }
1174  return $metaTags;
1175  }
1176 
1184  protected static function initializeSearchWordDataInTsfe()
1185  {
1187  $tsfe = $GLOBALS['TSFE'];
1188 
1189  $tsfe->sWordRegEx = '';
1190  $tsfe->sWordList = GeneralUtility::_GP('sword_list');
1191  if (is_array($tsfe->sWordList)) {
1192  $space = !empty($tsfe->config['config']['sword_standAlone']) ? '[[:space:]]' : '';
1193  foreach ($tsfe->sWordList as $val) {
1194  if (trim($val) !== '') {
1195  $tsfe->sWordRegEx .= $space . preg_quote($val, '/') . $space . '|';
1196  }
1197  }
1198  $tsfe->sWordRegEx = rtrim($tsfe->sWordRegEx, '|');
1199  }
1200  }
1201 
1205  protected static function getPageRenderer()
1206  {
1207  return GeneralUtility::makeInstance(PageRenderer::class);
1208  }
1209 
1217  protected static function addCssToPageRenderer($cssStyles, $excludeFromConcatenation = false, $inlineBlockName = 'TSFEinlineStyle')
1218  {
1219  if (empty($GLOBALS['TSFE']->config['config']['inlineStyle2TempFile'])) {
1220  self::getPageRenderer()->addCssInlineBlock($inlineBlockName, $cssStyles, !empty($GLOBALS['TSFE']->config['config']['compressCss']));
1221  } else {
1222  self::getPageRenderer()->addCssFile(
1223  self::inline2TempFile($cssStyles, 'css'),
1224  'stylesheet',
1225  'all',
1226  '',
1227  (bool)$GLOBALS['TSFE']->config['config']['compressCss'],
1228  false,
1229  '',
1230  $excludeFromConcatenation
1231  );
1232  }
1233  }
1234 }
static minifyJavaScript($script, &$error='')
static intExplode($delimiter, $string, $removeEmptyValues=false, $limit=0)
if(!defined("DB_ERROR")) define("DB_ERROR"
static implodeAttributes(array $arr, $xhtmlSafe=false, $dontOmitBlankAttribs=false)
static isAllowedLinkVarValue($haystack, $needle)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
static writeFileToTypo3tempDir($filepath, $content)
static getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:40
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static stripIntObjectPlaceholder(&$searchString, &$intObjects)
static addCssToPageRenderer($cssStyles, $excludeFromConcatenation=false, $inlineBlockName='TSFEinlineStyle')
static mergeRecursiveWithOverrule(array &$original, array $overrule, $addKeys=true, $includeEmptyValues=true, $enableUnsetFeature=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']