* Raising Extbase and Fluid version numbers to 0.9.12
[Packages/TYPO3.CMS.git] / typo3 / template.php
index 3d028e1..06b2605 100644 (file)
@@ -156,7 +156,7 @@ function fw($str)   {
  * @package TYPO3
  * @subpackage core
  */
-class template extends t3lib_pageRender {
+class template {
 
                // Vars you typically might want to/should set from outside after making instance of this class:
        var $backPath = '';                             // 'backPath' pointing back to the PATH_typo3
@@ -209,10 +209,18 @@ class template extends t3lib_pageRender {
 
        var $hasDocheader = true;
 
-       // class for render the header / footer
-
-    var $pageHeaderFooterTemplateFile = '';    // alternative template file
+       /**
+        * @var t3lib_PageRenderer
+        */
+       protected $pageRenderer;
+       protected $pageHeaderFooterTemplateFile = '';   // alternative template file
 
+       /**
+        * Whether flashmessages should be rendered or not
+        *
+        * @var $showFlashMessages
+        */
+       public $showFlashMessages = TRUE;
 
        /**
         * Constructor
@@ -222,7 +230,9 @@ class template extends t3lib_pageRender {
         */
        function template()     {
                global $TBE_STYLES;
-               parent::__construct(TYPO3_mainDir . 'templates/pagerender_be.html');
+
+                       // Initializes the page rendering object:
+               $this->getPageRenderer();
 
                        // Setting default scriptID:
                if (($temp_M = (string) t3lib_div::_GET('M')) && $GLOBALS['TBE_MODULES']['_PATHS'][$temp_M]) {
@@ -264,7 +274,20 @@ class template extends t3lib_pageRender {
        }
 
 
-
+       /**
+        * Gets instance of PageRenderer
+        *
+        * @return      t3lib_PageRenderer
+        */
+       public function getPageRenderer() {
+               if (!isset($this->pageRenderer)) {
+                       $this->pageRenderer = t3lib_div::makeInstance('t3lib_PageRenderer');
+                       $this->pageRenderer->setTemplateFile(
+                               TYPO3_mainDir . 'templates/template_page_backend.html'
+                       );
+               }
+               return $this->pageRenderer;
+       }
 
 
 
@@ -623,11 +646,13 @@ class template extends t3lib_pageRender {
                        }
                }
 
+               $this->pageRenderer->backPath = $this->backPath;
+
                        // alternative template for Header and Footer
                if ($this->pageHeaderFooterTemplateFile) {
                        $file =  t3lib_div::getFileAbsFileName($this->pageHeaderFooterTemplateFile, TRUE);
                        if ($file) {
-                               $this->setAlternativeTemplateFile($file);
+                               $this->pageRenderer->setTemplateFile($file);
                        }
                }
                        // For debugging: If this outputs "QuirksMode"/"BackCompat" (IE) the browser runs in quirks-mode. Otherwise the value is "CSS1Compat"
@@ -638,7 +663,7 @@ class template extends t3lib_pageRender {
                header ('Content-Type:text/html;charset='.$this->charset);
 
                        // Standard HTML tag
-               $this->setHtmlTag('<html xmlns="http://www.w3.org/1999/xhtml">');
+               $this->pageRenderer->setHtmlTag('<html xmlns="http://www.w3.org/1999/xhtml">');
 
                switch($this->docType)  {
                        case 'html_3':
@@ -693,42 +718,42 @@ class template extends t3lib_pageRender {
                        }
                }
 
-               $this->setXmlPrologAndDocType($headerStart);
-               $this->setHeadTag('<head>' . chr(10). '<!-- TYPO3 Script ID: '.htmlspecialchars($this->scriptID).' -->');
-               $this->setCharSet($this->charset);      
-               $this->addMetaTag($this->generator());  
-               $this->setTitle($title);
-               
+               $this->pageRenderer->setXmlPrologAndDocType($headerStart);
+               $this->pageRenderer->setHeadTag('<head>' . chr(10). '<!-- TYPO3 Script ID: '.htmlspecialchars($this->scriptID).' -->');
+               $this->pageRenderer->setCharSet($this->charset);
+               $this->pageRenderer->addMetaTag($this->generator());
+               $this->pageRenderer->setTitle($title);
+
                // add docstyles
                $this->docStyle();
 
 
                // add jsCode - has to go to headerData as it may contain the script tags already
-               $this->addHeaderData($this->JScode);
-               
+               $this->pageRenderer->addHeaderData($this->JScode);
+
                foreach ($this->JScodeArray as $name => $code) {
-                       $this->addJsInlineCode($name, $code);   
+                       $this->pageRenderer->addJsInlineCode($name, $code);
                }
 
                if (count($this->JScodeLibArray)) {
                        foreach($this->JScodeLibArray as $library) {
-                               $this->addHeaderData($library);
+                               $this->pageRenderer->addHeaderData($library);
                        }
                }
 
                if ($this->extJScode) {
-                       $this->addJsHandlerCode($this->extJScode, t3lib_pageIncludes::JSHANDLER_EXTONREADY);
+                       $this->pageRenderer->addExtOnReadyCode($this->extJScode);
                }
 
                        // Construct page header.
-               $str = $this->render(1);
+               $str = $this->pageRenderer->render(t3lib_PageRenderer::PART_HEADER);
 
                $this->JScodeLibArray = array();
                $this->JScode = $this->extJScode = '';
                $this->JScodeArray = array();
 
-               $this->endOfPageJsBlock = $this->render(2);
-               
+               $this->endOfPageJsBlock = $this->pageRenderer->render(t3lib_PageRenderer::PART_FOOTER);
+
                if ($this->docType=='xhtml_frames')     {
                        return $str;
                } else
@@ -859,14 +884,17 @@ $str.=$this->docBodyTagBegin().
         * @param       string          Additional attributes to h-tag, eg. ' class=""'
         * @return      string          HTML content
         */
-       function sectionHeader($label,$sH=FALSE,$addAttrib='')  {
-               $tag = ($sH?'h3':'h4');
+       function sectionHeader($label, $sH=FALSE, $addAttrib='') {
+               $tag = ($sH ? 'h3' : 'h4');
+               if ($addAttrib && substr($addAttrib, 0, 1) !== ' ') {
+                       $addAttrib = ' ' . $addAttrib;
+               }
                $str='
 
        <!-- Section header -->
-       <'.$tag.$addAttrib.'>'.$label.'</'.$tag.'>
+       <' . $tag . $addAttrib . '>' . $label . '</' . $tag . '>
 ';
-               return $this->sectionBegin().$str;
+               return $this->sectionBegin() . $str;
        }
 
        /**
@@ -968,15 +996,15 @@ $str.=$this->docBodyTagBegin().
                $inDocStyles = implode(chr(10), $this->inDocStylesArray);
 
                if ($this->styleSheetFile) {
-                  $this->addCssFile($this->backPath . $this->styleSheetFile);                                  
+                       $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile);
                }
                if ($this->styleSheetFile2) {
-                       $this->addCssFile($this->backPath . $this->styleSheetFile2);                                    
+                       $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile2);
                }
 
-               $this->addCssInlineBlock('inDocStyles', $inDocStyles . chr(10) . '/*###POSTCSSMARKER###*/');
+               $this->pageRenderer->addCssInlineBlock('inDocStyles', $inDocStyles . chr(10) . '/*###POSTCSSMARKER###*/');
                if ($this->styleSheetFile_post) {
-                       $this->addCssFile($this->backPath . $this->styleSheetFile_post);
+                       $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile_post);
        }
 
        }
@@ -991,8 +1019,13 @@ $str.=$this->docBodyTagBegin().
         * @return      void
         */
        function addStyleSheet($key, $href, $title='', $relation='stylesheet') {
-               $this->addCssFile($this->backPath . $href, $relation, $title);
+               if (strpos($href, '://') !== FALSE || substr($href, 0, 1) === '/') {
+                       $file = $href;
+               } else {
+                       $file = $this->backPath . $href;
                }
+               $this->pageRenderer->addCssFile($file, $relation, $title);
+       }
 
        /**
         * Insert post rendering document style into already rendered content
@@ -1318,8 +1351,8 @@ $str.=$this->docBodyTagBegin().
         * @return      void
         */
        function loadJavascriptLib($lib)        {
-               $this->addJsFile($this->backPath . $lib);
-               }
+               $this->pageRenderer->addJsFile($this->backPath . $lib);
+       }
 
 
 
@@ -1330,7 +1363,7 @@ $str.=$this->docBodyTagBegin().
         *                      Please just call this function without expecting a return value for future calls
         */
        function getContextMenuCode()   {
-              $this->loadPrototype();
+              $this->pageRenderer->loadPrototype();
               $this->loadJavascriptLib('js/clickmenu.js');
 
               $this->JScodeArray['clickmenu'] = '
@@ -1349,7 +1382,7 @@ $str.=$this->docBodyTagBegin().
         * @return      array           If values are present: [0] = A <script> section for the HTML page header, [1] = onmousemove/onload handler for HTML tag or alike, [2] = One empty <div> layer for the follow-mouse drag element
         */
        function getDragDropCode($table)        {
-               $this->loadPrototype();
+               $this->pageRenderer->loadPrototype();
                $this->loadJavascriptLib('js/common.js');
                $this->loadJavascriptLib('js/tree.js');
 
@@ -1797,77 +1830,6 @@ $str.=$this->docBodyTagBegin().
        }
 
        /**
-        * Adds a flash message to the queue. It will live until the next call to
-        * popFlashMessages() in the current session.
-        *
-        * @param       t3lib_FlashMessage      A flash message object.
-        * @return      void
-        * @author      Karsten Dambekalns <karsten@typo3.org>
-        * @author      Ingo Renner <ingo@typo3.org>
-        */
-       public function pushFlashMessage(t3lib_FlashMessage $message) {
-               $queuedFlashMessages = $this->getFlashMessagesFromSession();
-               $queuedFlashMessages[] = $message;
-
-               $GLOBALS['BE_USER']->setAndSaveSessionData(
-                       'core.template.flashMessages',
-                       $queuedFlashMessages
-               );
-       }
-
-       /**
-        * Returns queued flash messages and clears the queue.
-        *
-        * @return      array   An array with t3lib_FlashMessage flash messages.
-        * @author      Karsten Dambekalns <karsten@typo3.org>
-        * @author      Ingo Renner <ingo@typo3.org>
-        */
-       public function popFlashMessages() {
-               $queuedFlashMessages = $this->getFlashMessagesFromSession();
-
-               if (!empty($queuedFlashMessages)) {
-                       $GLOBALS['BE_USER']->setAndSaveSessionData(
-                               'core.template.flashMessages',
-                               null
-                       );
-               }
-
-               return $queuedFlashMessages;
-       }
-
-       /**
-        * Returns current flash messages from the session, making sure to always
-        * return an array.
-        *
-        * @return      array   An array of t3lib_FlashMessage flash messages.
-        * @author      Karsten Dambekalns <karsten@typo3.org>
-        * @author      Ingo Renner <ingo@typo3.org>
-        */
-       protected function getFlashMessagesFromSession() {
-               $flashMessages = $GLOBALS['BE_USER']->getSessionData('core.template.flashMessages');
-
-               return is_array($flashMessages) ? $flashMessages : array();
-       }
-
-       /**
-        * Renders all available flash messages in the queue.
-        *
-        * @return      string  All flash messages in the queue rendered as HTML.
-        * @author      Ingo Renner <ingo@typo3.org>
-        */
-       public function renderFlashMessages() {
-               $content       = '';
-               $flashMessages = $this->popFlashMessages();
-
-               foreach ($flashMessages as $flashMessage) {
-                       $content .= $flashMessage->render();
-               }
-
-               return $content;
-       }
-
-
-       /**
         * Function to load a HTML template file with markers.
         * When calling from own extension, use  syntax getHtmlTemplate('EXT:extkey/template.html')
         *
@@ -1893,7 +1855,7 @@ $str.=$this->docBodyTagBegin().
         */
        function setModuleTemplate($filename) {
                        // Load Prototype lib for IE event
-               $this->loadPrototype();
+               $this->pageRenderer->loadPrototype();
                $this->loadJavascriptLib('js/iecompatibility.js');
                $this->moduleTemplate = $this->getHtmlTemplate($filename);
        }
@@ -1939,26 +1901,28 @@ $str.=$this->docBodyTagBegin().
                        $moduleBody = t3lib_parsehtml::substituteSubpart($moduleBody, $marker, $content);
                }
 
-                       // adding flash messages
-               $flashMessages = $this->renderFlashMessages();
-               if (!empty($flashMessages)) {
-                       $flashMessages = '<div id="typo3-messages">' . $flashMessages . '</div>';
-               }
+               if ($this->showFlashMessages) {
+                               // adding flash messages
+                       $flashMessages = t3lib_FlashMessageQueue::renderFlashMessages();
+                       if (!empty($flashMessages)) {
+                               $flashMessages = '<div id="typo3-messages">' . $flashMessages . '</div>';
+                       }
 
-               if (strstr($moduleBody, '###FLASHMESSAGES###')) {
-                               // either replace a dedicated marker for the messages if present
-                       $moduleBody = str_replace(
-                               '###FLASHMESSAGES###',
-                               $flashMessages,
-                               $moduleBody
-                       );
-               } else {
-                               // or force them to appear before the content
-                       $moduleBody = str_replace(
-                               '###CONTENT###',
-                               $flashMessages . '###CONTENT###',
-                               $moduleBody
-                       );
+                       if (strstr($moduleBody, '###FLASHMESSAGES###')) {
+                                       // either replace a dedicated marker for the messages if present
+                               $moduleBody = str_replace(
+                                       '###FLASHMESSAGES###',
+                                       $flashMessages,
+                                       $moduleBody
+                               );
+                       } else {
+                                       // or force them to appear before the content
+                               $moduleBody = str_replace(
+                                       '###CONTENT###',
+                                       $flashMessages . '###CONTENT###',
+                                       $moduleBody
+                               );
+                       }
                }
 
                        // replacing all markers with the finished markers and return the HTML content
@@ -2125,7 +2089,6 @@ class mediumDoc extends template {
  * Extension class for "template" - used in the context of frontend editing.
  */
 class frontendDoc extends template {
-       var $backPath = 'typo3/';
 
        /**
         * Used in the frontend context to insert header data via TSFE->additionalHeaderData.
@@ -2134,13 +2097,38 @@ class frontendDoc extends template {
         * @return      void
         */
        public function insertHeaderData() {
-               $GLOBALS['TSFE']->additionalHeaderData['docStyle'] = $this->docStyle();
-               $GLOBALS['TSFE']->additionalHeaderData['JSLibraries'] = $this->renderJSlibraries();
-               $GLOBALS['TSFE']->additionalHeaderData['JScode'] = $this->JScode;
-               $GLOBALS['TSFE']->additionalHeaderData['JScodeArray'] = $this->wrapScriptTags(implode("\n", $this->JScodeArray));
 
-               if ($this->extJScode) {
-                       $GLOBALS['TSFE']->additionalHeaderData['extJScode'] = $this->wrapScriptTags('Ext.onReady(function() {' . chr(10) . $this->extJScode . chr(10) . '});');
+               /** @var $pageRenderer t3lib_PageRenderer */
+               $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
+
+               $this->backPath = $GLOBALS['TSFE']->backPath = TYPO3_mainDir;
+               $this->pageRenderer->setBackPath($this->backPath);
+               $this->docStyle();
+
+                       // add applied JS/CSS to $GLOBALS['TSFE']
+               if ($this->JScode) {
+                       $pageRenderer->addHeaderData($this->JScode);
+               }
+               if (count($this->JScodeArray)) {
+                       foreach ($this->JScodeArray as $name => $code) {
+                               $pageRenderer->addJsInlineCode($name, $code);
+       }
+}
+
+               if ($this->addPrototype) {
+                       $pageRenderer->loadPrototype();
+               }
+               if ($this->addScriptaculous) {
+                       $pageRenderer->loadScriptaculous();
+               }
+               if ($this->addExtJS) {
+                       $pageRenderer->loadExtJs();
+               }
+               if ($this->inlineLanguageLabels) {
+                       $pageRenderer->addInlineLanguageLabelArray($this->inlineLanguageLabels);
+               }
+               if ($this->inlineSettings) {
+                       $pageRenderer->addInlineSettingArray($this->inlineSettings);
                }
        }
 }