* Raising Extbase and Fluid version numbers to 0.9.12
[Packages/TYPO3.CMS.git] / typo3 / template.php
index 2a424b2..06b2605 100644 (file)
@@ -215,6 +215,12 @@ class template {
        protected $pageRenderer;
        protected $pageHeaderFooterTemplateFile = '';   // alternative template file
 
+       /**
+        * Whether flashmessages should be rendered or not
+        *
+        * @var $showFlashMessages
+        */
+       public $showFlashMessages = TRUE;
 
        /**
         * Constructor
@@ -270,7 +276,7 @@ class template {
 
        /**
         * Gets instance of PageRenderer
-        * 
+        *
         * @return      t3lib_PageRenderer
         */
        public function getPageRenderer() {
@@ -717,16 +723,16 @@ class template {
                $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->pageRenderer->addHeaderData($this->JScode);
-               
+
                foreach ($this->JScodeArray as $name => $code) {
-                       $this->pageRenderer->addJsInlineCode($name, $code);     
+                       $this->pageRenderer->addJsInlineCode($name, $code);
                }
 
                if (count($this->JScodeLibArray)) {
@@ -747,7 +753,7 @@ class template {
                $this->JScodeArray = array();
 
                $this->endOfPageJsBlock = $this->pageRenderer->render(t3lib_PageRenderer::PART_FOOTER);
-               
+
                if ($this->docType=='xhtml_frames')     {
                        return $str;
                } else
@@ -878,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;
        }
 
        /**
@@ -1821,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')
         *
@@ -1963,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
@@ -2149,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.
@@ -2158,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);
                }
        }
 }