[BUGFIX] Make PageRenderer work with USER_INT plugins
authorHelmut Hummel <helmut.hummel@typo3.org>
Wed, 21 Dec 2011 13:21:40 +0000 (14:21 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sat, 18 Aug 2012 14:58:24 +0000 (16:58 +0200)
Currently the PageRenderer renders all the page content before
USER_INT plugins are substituted in the cached output.
This leads to the situation, that adding header or footer data using
the PageRenderer does not work for USER_INT plugins.

If you for example try to use tt_content.media.20 in a
USER_INT plugin, the JS library and the inline JS, is not
included.

This change solves the problem, by adding the header and footer data
of the PageRenderer during USER_INT processing.

Resolves: #22273
Releases: 6.0
Change-Id: I97609684ccacdab1bd0853b9ccd6608716706f87
Reviewed-on: http://review.typo3.org/7465
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
t3lib/class.t3lib_pagerenderer.php
typo3/sysext/cms/tslib/class.tslib_fe.php
typo3/sysext/cms/tslib/class.tslib_pagegen.php

index c917587..db55299 100644 (file)
@@ -1799,6 +1799,68 @@ class t3lib_PageRenderer implements t3lib_Singleton {
        }
 
        /**
        }
 
        /**
+        * Render the page but not the JavaScript and CSS Files
+        *
+        * @param string $substituteHash The hash that is used for the placehoder markers
+        * @access private
+        * @return string Content of rendered section
+        */
+       public function renderPageWithUncachedObjects($substituteHash) {
+               $this->prepareRendering();
+
+               $markerArray = $this->getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash);
+               $template = $this->getTemplateForPart(self::PART_COMPLETE);
+
+               return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
+       }
+
+       /**
+        * Renders the JavaScript and CSS files that have been added during processing
+        * of uncached content objects (USER_INT, COA_INT)
+        *
+        * @param string $cachedPageContent
+        * @param string $substituteHash The hash that is used for the placehoder markers
+        * @access private
+        * @return string
+        */
+       public function renderJavaScriptAndCssForProcessingOfUncachedContentObjects($cachedPageContent, $substituteHash) {
+               $this->prepareRendering();
+
+               list(
+                               $jsLibs,
+                               $jsFiles,
+                               $jsFooterFiles,
+                               $cssFiles,
+                               $jsInline,
+                               $cssInline,
+                               $jsFooterInline,
+                               $jsFooterLibs
+                       ) = $this->renderJavaScriptAndCss();
+
+               $markerArray = array(
+                       '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->' => $cssFiles,
+                       '<!-- ###CSS_INLINE' . $substituteHash . '### -->' => $cssInline,
+                       '<!-- ###JS_INLINE' . $substituteHash . '### -->' => $jsInline,
+                       '<!-- ###JS_INCLUDE' . $substituteHash . '### -->' => $jsFiles,
+                       '<!-- ###JS_LIBS' . $substituteHash . '### -->' => $jsLibs,
+                       '<!-- ###HEADERDATA' . $substituteHash . '### -->' => implode(LF, $this->headerData),
+                       '<!-- ###FOOTERDATA' . $substituteHash . '### -->' => implode(LF, $this->footerData),
+                       '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->' => $jsFooterLibs,
+                       '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->' => $jsFooterFiles,
+                       '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->' => $jsFooterInline,
+               );
+
+               foreach ($markerArray as $placeHolder => $content) {
+                       $cachedPageContent = str_replace($placeHolder, $content, $cachedPageContent);
+               }
+
+
+               $this->reset();
+
+               return $cachedPageContent;
+       }
+
+       /**
         * Remove ending slashes from static header block
         * if the page is beeing rendered as html (not xhtml)
         * and define property $this->endingSlash for further use
         * Remove ending slashes from static header block
         * if the page is beeing rendered as html (not xhtml)
         * and define property $this->endingSlash for further use
@@ -1903,6 +1965,40 @@ class t3lib_PageRenderer implements t3lib_Singleton {
        }
 
        /**
        }
 
        /**
+        * Fills the marker array with the given strings and trims each value
+        *
+        * @param string $substituteHash The hash that is used for the placehoder markers
+        * @return array Marker array
+        */
+       protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteHash) {
+               $markerArray = array(
+                       'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
+                       'HTMLTAG' => $this->htmlTag,
+                       'HEADTAG' => $this->headTag,
+                       'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
+                       'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
+                       'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
+                       'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
+                       'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
+                       'META' => implode(LF, $this->metaTags),
+                       'BODY' => $this->bodyContent,
+                       'CSS_INCLUDE' => '<!-- ###CSS_INCLUDE' . $substituteHash . '### -->',
+                       'CSS_INLINE' => '<!-- ###CSS_INLINE' . $substituteHash . '### -->',
+                       'JS_INLINE' => '<!-- ###JS_INLINE' . $substituteHash . '### -->',
+                       'JS_INCLUDE' => '<!-- ###JS_INCLUDE' . $substituteHash . '### -->',
+                       'JS_LIBS' => '<!-- ###JS_LIBS' . $substituteHash . '### -->',
+                       'HEADERDATA' => '<!-- ###HEADERDATA' . $substituteHash . '### -->',
+                       'FOOTERDATA' => '<!-- ###FOOTERDATA' . $substituteHash . '### -->',
+                       'JS_LIBS_FOOTER' => '<!-- ###JS_LIBS_FOOTER' . $substituteHash . '### -->',
+                       'JS_INCLUDE_FOOTER' => '<!-- ###JS_INCLUDE_FOOTER' . $substituteHash . '### -->',
+                       'JS_INLINE_FOOTER' => '<!-- ###JS_INLINE_FOOTER' . $substituteHash . '### -->',
+               );
+               $markerArray = array_map('trim', $markerArray);
+
+               return $markerArray;
+       }
+
+       /**
         * Reads the template file and returns the requested part as string
         *
         * @param integer $part
         * Reads the template file and returns the requested part as string
         *
         * @param integer $part
index b7c5961..912a0cb 100644 (file)
@@ -495,6 +495,15 @@ class tslib_fe {
                return $this->pageRenderer;
        }
 
                return $this->pageRenderer;
        }
 
+       /**
+        * This is needed for USER_INT processing
+        *
+        * @param t3lib_PageRenderer $pageRenderer
+        */
+       protected function setPageRenderer(t3lib_PageRenderer $pageRenderer) {
+               $this->pageRenderer = $pageRenderer;
+       }
+
        /********************************************
         *
         * Initializing, resolving page id
        /********************************************
         *
         * Initializing, resolving page id
@@ -3109,6 +3118,12 @@ class tslib_fe {
                $this->JSImgCode = $this->additionalHeaderData['JSImgCode'];
                $this->divSection='';
 
                $this->JSImgCode = $this->additionalHeaderData['JSImgCode'];
                $this->divSection='';
 
+               if (!empty($this->config['INTincScript_ext']['pageRenderer'])) {
+                       /** @var $pageRenderer t3lib_PageRenderer */
+                       $pageRenderer = unserialize($this->config['INTincScript_ext']['pageRenderer']);
+                       $this->setPageRenderer($pageRenderer);
+               }
+
                do {
                        $INTiS_config = $this->config['INTincScript'];
                        $this->INTincScript_includeLibs($INTiS_config);
                do {
                        $INTiS_config = $this->config['INTincScript'];
                        $this->INTincScript_includeLibs($INTiS_config);
@@ -3123,6 +3138,11 @@ class tslib_fe {
                $this->content = str_replace('<!--HD_'.$this->config['INTincScript_ext']['divKey'].'-->', $this->convOutputCharset(implode(LF, $this->additionalHeaderData), 'HD'), $this->content);
                $this->content = str_replace('<!--FD_'.$this->config['INTincScript_ext']['divKey'].'-->', $this->convOutputCharset(implode(LF, $this->additionalFooterData), 'FD'), $this->content);
                $this->content = str_replace('<!--TDS_'.$this->config['INTincScript_ext']['divKey'].'-->', $this->convOutputCharset($this->divSection, 'TDS'), $this->content);
                $this->content = str_replace('<!--HD_'.$this->config['INTincScript_ext']['divKey'].'-->', $this->convOutputCharset(implode(LF, $this->additionalHeaderData), 'HD'), $this->content);
                $this->content = str_replace('<!--FD_'.$this->config['INTincScript_ext']['divKey'].'-->', $this->convOutputCharset(implode(LF, $this->additionalFooterData), 'FD'), $this->content);
                $this->content = str_replace('<!--TDS_'.$this->config['INTincScript_ext']['divKey'].'-->', $this->convOutputCharset($this->divSection, 'TDS'), $this->content);
+
+               if (isset($pageRenderer)) {
+                       $this->content = $pageRenderer->renderJavaScriptAndCssForProcessingOfUncachedContentObjects($this->content, $this->config['INTincScript_ext']['divKey']);
+               }
+
                $this->setAbsRefPrefix();
                $GLOBALS['TT']->pull();
        }
                $this->setAbsRefPrefix();
                $GLOBALS['TT']->pull();
        }
index a5b364c..7bb142e 100644 (file)
@@ -277,8 +277,6 @@ class TSpagegen {
                /** @var $pageRenderer t3lib_PageRenderer */
                $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
 
                /** @var $pageRenderer t3lib_PageRenderer */
                $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
 
-               $pageRenderer->backPath = TYPO3_mainDir;
-
                if ($GLOBALS['TSFE']->config['config']['moveJsFromHeaderToFooter']) {
                        $pageRenderer->enableMoveJsFromHeaderToFooter();
                }
                if ($GLOBALS['TSFE']->config['config']['moveJsFromHeaderToFooter']) {
                        $pageRenderer->enableMoveJsFromHeaderToFooter();
                }
@@ -1057,8 +1055,15 @@ class TSpagegen {
                        // Page content
                $pageRenderer->addBodyContent(LF . $pageContent);
 
                        // Page content
                $pageRenderer->addBodyContent(LF . $pageContent);
 
-                       // Render complete page
-               $GLOBALS['TSFE']->content = $pageRenderer->render();
+               if (!empty($GLOBALS['TSFE']->config['INTincScript']) && is_array($GLOBALS['TSFE']->config['INTincScript'])) {
+                               // Store the serialized pageRenderer in configuration
+                       $GLOBALS['TSFE']->config['INTincScript_ext']['pageRenderer'] = serialize($pageRenderer);
+                               // Render complete page, keep placeholders for JavaScript and CSS
+                       $GLOBALS['TSFE']->content = $pageRenderer->renderPageWithUncachedObjects($GLOBALS['TSFE']->config['INTincScript_ext']['divKey']);
+               } else {
+                               // Render complete page
+                       $GLOBALS['TSFE']->content = $pageRenderer->render();
+               }
 
                        // Ending page
                if ($GLOBALS['TSFE']->pSetup['frameSet.']) {
 
                        // Ending page
                if ($GLOBALS['TSFE']->pSetup['frameSet.']) {