Added feature #14247: Add a concatenator for CSS and JS (thanks to Steffen Gebert)
[Packages/TYPO3.CMS.git] / typo3 / template.php
index af86a31..34ea945 100644 (file)
 
 if (!defined('TYPO3_MODE'))    die("Can't include this file directly.");
 
-require_once(PATH_t3lib.'class.t3lib_ajax.php');
-require_once(PATH_t3lib.'class.t3lib_matchcondition.php');
-
-
-
-
-
-
-
-
 
 /**
  * Deprecated fontwrap function. Is just transparent now.
@@ -142,7 +132,8 @@ require_once(PATH_t3lib.'class.t3lib_matchcondition.php');
  * @return     string          Output string (in the old days this was wrapped in <font> tags)
  * @deprecated since TYPO3 3.6
  */
-function fw($str)      {
+function fw($str) {
+       t3lib_div::logDeprecatedFunction();
        return $str;
 }
 
@@ -188,7 +179,6 @@ class template {
        var $form_rowsToStylewidth = 9.58;      // Multiplication factor for formWidth() input size (default is 48* this value).
        var $form_largeComp = 1.33;             // Compensation for large documents (used in class.t3lib_tceforms.php)
        var $endJS=1;                                   // If set, then a JavaScript section will be outputted in the bottom of page which will try and update the top.busy session expiry object.
-       protected $additionalStyleSheets=array();       // Links to additional style sheets
 
                // TYPO3 Colorscheme.
                // If you want to change this, please do so through a skin using the global var $TBE_STYLES
@@ -199,12 +189,25 @@ class template {
        var $bgColor5 = '#ABBBB4';              // light tablerow background, greenish
        var $bgColor6 = '#E7DBA8';              // light tablerow background, yellowish, for section headers. Light.
        var $hoverColor = '#254D7B';
-       var $styleSheetFile = 'stylesheet.css'; // Filename of stylesheet (relative to PATH_typo3)
+       var $styleSheetFile = '';       // Filename of stylesheet (relative to PATH_typo3)
        var $styleSheetFile2 = '';              // Filename of stylesheet #2 - linked to right after the $this->styleSheetFile script (relative to PATH_typo3)
        var $styleSheetFile_post = '';  // Filename of a post-stylesheet - included right after all inline styles.
        var $backGroundImage = '';              // Background image of page (relative to PATH_typo3)
        var $inDocStyles_TBEstyle = ''; // Inline css styling set from TBE_STYLES array
 
+               // Skinning
+               // stylesheets from core
+       protected $stylesheetsCore = array(
+               'structure' => 'stylesheets/structure/',
+               'visual' => 'stylesheets/visual/',
+       );
+
+               // include these CSS directories from skins by default
+       protected $stylesheetsSkins = array(
+               'structure' => 'stylesheets/structure/',
+               'visual' => 'stylesheets/visual/',
+       );
+
                // DEV:
        var $parseTimeFlag = 0;                 // Will output the parsetime of the scripts in milliseconds (for admin-users). Set this to false when releasing TYPO3. Only for dev.
 
@@ -214,24 +217,23 @@ class template {
        var $sectionFlag=0;                             // Internal: Indicates if a <div>-output section is open
        var $divClass = '';                             // (Default) Class for wrapping <DIV>-tag of page. Is set in class extensions.
 
-               // internal flags for JS-libraries
-       protected $addPrototype = false;
-       protected $addScriptaculousModules = array(
-               'builder'  => false,
-               'effects'  => false,
-               'dragdrop' => false,
-               'controls' => false,
-               'slider'   => false
-       );
-       protected $addExtJS = false;
-       protected $extJSadapter = 'ext/ext-base.js';
-       protected $enableExtJsDebug = false;
+       var $pageHeaderBlock = '';
+       var $endOfPageJsBlock = '';
 
-       // available adapters for extJs
-       const EXTJS_ADAPTER_JQUERY = 'jquery'; 
-       const EXTJS_ADAPTER_PROTOTYPE = 'prototype'; 
-       const EXTJS_ADAPTER_YUI = 'yui';
+       var $hasDocheader = true;
 
+       /**
+        * @var t3lib_PageRenderer
+        */
+       protected $pageRenderer;
+       protected $pageHeaderFooterTemplateFile = '';   // alternative template file
+
+       /**
+        * Whether flashmessages should be rendered or not
+        *
+        * @var $showFlashMessages
+        */
+       public $showFlashMessages = TRUE;
 
        /**
         * Constructor
@@ -242,6 +244,9 @@ class template {
        function template()     {
                global $TBE_STYLES;
 
+                       // Initializes the page rendering object:
+               $this->getPageRenderer();
+
                        // Setting default scriptID:
                if (($temp_M = (string) t3lib_div::_GET('M')) && $GLOBALS['TBE_MODULES']['_PATHS'][$temp_M]) {
                        $this->scriptID = preg_replace('/^.*\/(sysext|ext)\//', 'ext/', $GLOBALS['TBE_MODULES']['_PATHS'][$temp_M] . 'index.php');
@@ -277,12 +282,32 @@ class template {
                if ($TBE_STYLES['styleSheetFile_post']) $this->styleSheetFile_post = $TBE_STYLES['styleSheetFile_post'];
                if ($TBE_STYLES['inDocStyles_TBEstyle'])        $this->inDocStyles_TBEstyle = $TBE_STYLES['inDocStyles_TBEstyle'];
 
+                       // include all stylesheets
+               foreach ($this->getSkinStylesheetDirectories() as $stylesheetDirectory) {
+                       $this->addStylesheetDirectory($stylesheetDirectory);
+               }
+
                        // Background image
                if ($TBE_STYLES['background'])  $this->backGroundImage = $TBE_STYLES['background'];
        }
 
 
-
+       /**
+        * 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'
+                       );
+                       $this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
+                       $this->pageRenderer->enableConcatenateFiles();
+               }
+               return $this->pageRenderer;
+       }
 
 
 
@@ -641,18 +666,24 @@ class template {
                        }
                }
 
-                       // Get META tag containing the currently selected charset for backend output. The function sets $this->charSet.
-               $charSet = $this->initCharset();
-               $generator = $this->generator();
+               $this->pageRenderer->backPath = $this->backPath;
 
+                       // alternative template for Header and Footer
+               if ($this->pageHeaderFooterTemplateFile) {
+                       $file =  t3lib_div::getFileAbsFileName($this->pageHeaderFooterTemplateFile, TRUE);
+                       if ($file) {
+                               $this->pageRenderer->setTemplateFile($file);
+                       }
+               }
                        // For debugging: If this outputs "QuirksMode"/"BackCompat" (IE) the browser runs in quirks-mode. Otherwise the value is "CSS1Compat"
 #              $this->JScodeArray[]='alert(document.compatMode);';
 
                        // Send HTTP header for selected charset. Added by Robert Lemke 23.10.2003
+               $this->initCharset();
                header ('Content-Type:text/html;charset='.$this->charset);
 
                        // Standard HTML tag
-               $htmlTag = '<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':
@@ -684,8 +715,7 @@ class template {
                }
 
                        // Get the browser info
-               $matchObject = t3lib_div::makeInstance('t3lib_matchCondition');
-               $browserInfo = $matchObject->browserInfo(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
+               $browserInfo = t3lib_utility_Client::getBrowserInfo(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
 
                        // Set the XML prologue
                $xmlPrologue = '<?xml version="1.0" encoding="' . $this->charset . '"?>';
@@ -697,37 +727,54 @@ class template {
                if ($this->docType !== 'html_3') {
                                // Put the XML prologue before or after the doctype declaration according to browser
                        if ($browserInfo['browser'] === 'msie' && $browserInfo['version'] < 7) {
-                               $headerStart = $headerStart . chr(10) . $xmlPrologue;
+                               $headerStart = $headerStart . LF . $xmlPrologue;
                        } else {
-                               $headerStart = $xmlPrologue . chr(10) . $headerStart;
+                               $headerStart = $xmlPrologue . LF . $headerStart;
                        }
 
                                // Add the xml stylesheet according to doctype
                        if ($this->docType !== 'xhtml_frames') {
-                               $headerStart = $headerStart . chr(10) . $xmlStylesheet;
+                               $headerStart = $headerStart . LF . $xmlStylesheet;
                        }
                }
 
+               $this->pageRenderer->setXmlPrologAndDocType($headerStart);
+               $this->pageRenderer->setHeadTag('<head>' . LF. '<!-- TYPO3 Script ID: '.htmlspecialchars($this->scriptID).' -->');
+               $this->pageRenderer->setCharSet($this->charset);
+               $this->pageRenderer->addMetaTag($this->generator());
+               $this->pageRenderer->addMetaTag($this->xUaCompatible());
+               $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);
+               }
+
+               if (count($this->JScodeLibArray)) {
+                       foreach($this->JScodeLibArray as $library) {
+                               $this->pageRenderer->addHeaderData($library);
+                       }
+               }
+
+               if ($this->extJScode) {
+                       $this->pageRenderer->addExtOnReadyCode($this->extJScode);
+               }
+
                        // Construct page header.
-               $str = $headerStart . chr(10) . $htmlTag . '
-<head>
-       <!-- TYPO3 Script ID: '.htmlspecialchars($this->scriptID).' -->
-       '.$charSet.'
-       '.$generator.'
-       <title>'.htmlspecialchars($title).'</title>
-       '.$this->docStyle().'
-       ' . $this->renderJSlibraries() . '
-       '.$this->JScode.'
-       '.$this->wrapScriptTags(implode("\n", $this->JScodeArray)).
-       ($this->extJScode ? $this->wrapScriptTags('Ext.onReady(function() {' . chr(10) . $this->extJScode . chr(10) . '});') : '') .
-       '
-       <!--###POSTJSMARKER###-->
-</head>
-';
+               $str = $this->pageRenderer->render(t3lib_PageRenderer::PART_HEADER);
+
                $this->JScodeLibArray = array();
                $this->JScode = $this->extJScode = '';
                $this->JScodeArray = array();
 
+               $this->endOfPageJsBlock = $this->pageRenderer->render(t3lib_PageRenderer::PART_FOOTER);
+
                if ($this->docType=='xhtml_frames')     {
                        return $str;
                } else
@@ -760,12 +807,10 @@ $str.=$this->docBodyTagBegin().
                        $str .= ($this->divClass?'
 
 <!-- Wrapping DIV-section for whole page END -->
-</div>':'').'
-</body>        ';
+</div>':'') . $this->endOfPageJsBlock ;
 
                }
 
-               $str .= '</html>';
 
                        // Logging: Can't find better place to put it:
                if (TYPO3_DLOG) t3lib_div::devLog('END of BACKEND session', 'template', 0, array('_FLUSH' => true));
@@ -860,14 +905,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;
        }
 
        /**
@@ -966,28 +1014,20 @@ $str.=$this->docBodyTagBegin().
                $this->inDocStylesArray[] = $this->inDocStyles_TBEstyle;
 
                        // Implode it all:
-               $inDocStyles = implode('
-                                       ',$this->inDocStylesArray);
-
-                       // The default color scheme should also in full be represented in the stylesheet.
-               $style=trim('
-                       '.($this->styleSheetFile?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile.'" />':'').'
-                       '.($this->styleSheetFile2?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile2.'" />':'').'
-                       <style type="text/css" id="internalStyle">
-                               /*<![CDATA[*/
-                                       '.trim($inDocStyles).'
-                                       /*###POSTCSSMARKER###*/
-                               /*]]>*/
-                       </style>
-                       '.($this->styleSheetFile_post?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile_post.'" />':'').'
-                       '.implode("\n", $this->additionalStyleSheets)
-               )
-               ;
-               $this->inDocStyles='';
-               $this->inDocStylesArray=array();
+               $inDocStyles = implode(LF, $this->inDocStylesArray);
+
+               if ($this->styleSheetFile) {
+                       $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile);
+               }
+               if ($this->styleSheetFile2) {
+                       $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile2);
+               }
+
+               $this->pageRenderer->addCssInlineBlock('inDocStyles', $inDocStyles . LF . '/*###POSTCSSMARKER###*/');
+               if ($this->styleSheetFile_post) {
+                       $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile_post);
+               }
 
-               return '
-                       '.$style;
        }
 
        /**
@@ -1000,10 +1040,32 @@ $str.=$this->docBodyTagBegin().
         * @return      void
         */
        function addStyleSheet($key, $href, $title='', $relation='stylesheet') {
-               if (!isset($this->additionalStyleSheets[$key])) {
-                       $this->additionalStyleSheets[$key] = '<link rel="' . $relation . '" type="text/css" href="' . $href . '"' . ($title ? (' title="' . $title . '"') : '') . ' />';
+               if (strpos($href, '://') !== FALSE || substr($href, 0, 1) === '/') {
+                       $file = $href;
+               } else {
+                       $file = $this->backPath . $href;
                }
-        }
+               $this->pageRenderer->addCssFile($file, $relation, 'screen', $title);
+       }
+
+       /**
+        * Add all *.css files of the directory $path to the stylesheets
+        *
+        * @param       string          directory to add
+        * @return      void
+        */
+       function addStyleSheetDirectory($path) {
+                       // calculation needed, when TYPO3 source is used via a symlink
+                       // absolute path to the stylesheets
+               $filePath = dirname(t3lib_div::getIndpEnv('SCRIPT_FILENAME')) . '/' . $GLOBALS['BACK_PATH'] . $path;
+                       // clean the path
+               $resolvedPath = t3lib_div::resolveBackPath($filePath);
+                       // read all files in directory and sort them alphabetically
+               $files = t3lib_div::getFilesInDir($resolvedPath, 'css', FALSE, 1);
+               foreach ($files as $file) {
+                       $this->pageRenderer->addCssFile($GLOBALS['BACK_PATH'] . $path . $file, 'stylesheet', 'all');
+               }
+       }
 
        /**
         * Insert post rendering document style into already rendered content
@@ -1015,17 +1077,61 @@ $str.=$this->docBodyTagBegin().
        function insertStylesAndJS($content)    {
                        // insert accumulated CSS
                $this->inDocStylesArray[] = $this->inDocStyles;
-               $styles = "\n".implode("\n", $this->inDocStylesArray);
+               $styles = LF.implode(LF, $this->inDocStylesArray);
                $content = str_replace('/*###POSTCSSMARKER###*/',$styles,$content);
 
                        // insert accumulated JS
-               $jscode = $this->JScode."\n".$this->wrapScriptTags(implode("\n", $this->JScodeArray));
+               $jscode = $this->JScode.LF.$this->wrapScriptTags(implode(LF, $this->JScodeArray));
                $content = str_replace('<!--###POSTJSMARKER###-->',$jscode,$content);
 
                return $content;
        }
 
        /**
+        * Returns an array of all stylesheet directories belonging to core and skins
+        *
+        * @return      array   Stylesheet directories
+        */
+       public function getSkinStylesheetDirectories() {
+               $stylesheetDirectories = array();
+
+                       // add default core stylesheets
+               foreach ($this->stylesheetsCore as $stylesheetDir) {
+                       $stylesheetDirectories[] = $stylesheetDir;
+               }
+
+                       // Stylesheets from skins
+                       // merge default css directories ($this->stylesheetsSkin) with additional ones and include them
+               if (is_array($GLOBALS['TBE_STYLES']['skins'])) {
+                               // loop over all registered skins
+                       foreach ($GLOBALS['TBE_STYLES']['skins'] as $skinExtKey => $skin) {
+                               $skinStylesheetDirs = $this->stylesheetsSkins;
+
+                                       // skins can add custom stylesheetDirectories using
+                                       // $TBE_STYLES['skins'][$_EXTKEY]['stylesheetDirectories']
+                               if (is_array($skin['stylesheetDirectories'])) {
+                                       $skinStylesheetDirs = array_merge($skinStylesheetDirs, $skin['stylesheetDirectories']);
+                               }
+
+                                       // add all registered directories
+                               foreach ($skinStylesheetDirs as $stylesheetDir) {
+                                               // for EXT:myskin/stylesheets/ syntax
+                                       if (substr($stylesheetDir, 0, 4) === 'EXT:') {
+                                               list($extKey, $path) = explode('/', substr($stylesheetDir, 4), 2);
+                                               if (strcmp($extKey, '') && t3lib_extMgm::isLoaded($extKey) && strcmp($path, '')) {
+                                                       $stylesheetDirectories[] = t3lib_extMgm::extRelPath($extKey) . $path;
+                                               }
+                                       } else {
+                                               // for relative paths
+                                               $stylesheetDirectories[] = t3lib_extMgm::extRelPath($skinExtKey) . $stylesheetDir;
+                                       }
+                               }
+                       }
+               }
+               return $stylesheetDirectories;
+       }
+
+       /**
         * Initialize the charset.
         * Sets the internal $this->charset variable to the charset defined in $GLOBALS["LANG"] (or the default as set in this class)
         * Returns the meta-tag for the document header
@@ -1049,6 +1155,16 @@ $str.=$this->docBodyTagBegin().
                return '<meta name="generator" content="'.$str .'" />';
        }
 
+       /**
+        * Returns X-UA-Compatible meta tag
+        *
+        * @return      string          <meta http-equiv="X-UA-Compatible" content="???" />
+        */
+       function xUaCompatible() {
+                       // the most recent version if Internet Explorer, in which the Backend works
+               $str = "IE=8";
+               return '<meta http-equiv="X-UA-Compatible" content="' . $str . '" />';
+       }
 
 
 
@@ -1157,14 +1273,14 @@ $str.=$this->docBodyTagBegin().
        function wrapScriptTags($string, $linebreak=TRUE)       {
                if(trim($string)) {
                                // <script wrapped in nl?
-                       $cr = $linebreak? "\n" : '';
+                       $cr = $linebreak? LF : '';
 
                                // remove nl from the beginning
                        $string = preg_replace ('/^\n+/', '', $string);
                                // re-ident to one tab using the first line as reference
                        $match = array();
                        if(preg_match('/^(\t+)/',$string,$match)) {
-                               $string = str_replace($match[1],"\t", $string);
+                               $string = str_replace($match[1],TAB, $string);
                        }
                        $string = $cr.'<script type="text/javascript">
 /*<![CDATA[*/
@@ -1329,26 +1445,10 @@ $str.=$this->docBodyTagBegin().
         * @return      void
         */
        function loadJavascriptLib($lib)        {
-               if (!isset($this->JScodeLibArray[$lib]))        {
-                       $this->JScodeLibArray[$lib] = '<script type="text/javascript" src="' . $this->backPath . $lib . '"></script>';
-               }
+               $this->pageRenderer->addJsFile($this->backPath . $lib);
        }
 
 
-       /**
-        *
-        * @param string $lib   it will remove lib from general JScodeLibArray because lib is loaded already.
-        */
-       protected function removeJavascriptLib($lib) {
-               if (count($this->JScodeLibArray)) {
-                       $scripts = array_keys($this->JScodeLibArray);
-                       foreach ($scripts as $script) {
-                               if (strpos($script, '/' . $lib . '/') !== false) {
-                                       unset ($this->JScodeLibArray[$script]);
-                               }
-                       }
-               }
-       }
 
        /**
         * Includes the necessary Javascript function for the clickmenu (context sensitive menus) in the document
@@ -1357,7 +1457,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'] = '
@@ -1376,7 +1476,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');
 
@@ -1550,7 +1650,7 @@ $str.=$this->docBodyTagBegin().
                                }
 
                                $mouseOverOut = ' onmouseover="DTM_mouseOver(this);" onmouseout="DTM_mouseOut(this);"';
-                               $requiredIcon = '<img name="' . $id . '-' . $index . '-REQ" src="' . $GLOBALS['BACK_PATH'] . 'gfx/clear.gif" width="10" height="10" hspace="4" alt="" />';
+                               $requiredIcon = '<img name="' . $id . '-' . $index . '-REQ" src="' . $GLOBALS['BACK_PATH'] . 'gfx/clear.gif" class="t3-TCEforms-reqTabImg" alt="" />';
 
                                if (!$foldout)  {
                                                // Create TAB cell:
@@ -1823,9 +1923,9 @@ $str.=$this->docBodyTagBegin().
                }
        }
 
-
        /**
         * Function to load a HTML template file with markers.
+        * When calling from own extension, use  syntax getHtmlTemplate('EXT:extkey/template.html')
         *
         * @param       string          tmpl name, usually in the typo3/template/ directory
         * @return      string          HTML of template
@@ -1834,7 +1934,12 @@ $str.=$this->docBodyTagBegin().
                if ($GLOBALS['TBE_STYLES']['htmlTemplates'][$filename]) {
                        $filename = $GLOBALS['TBE_STYLES']['htmlTemplates'][$filename];
                }
-               return ($filename ? t3lib_div::getURL(t3lib_div::resolveBackPath($this->backPath . $filename)) : '');
+               if (substr($filename,0,4) != 'EXT:') {
+                       $filename = t3lib_div::resolveBackPath($this->backPath . $filename);
+               } else {
+                       $filename = t3lib_div::getFileAbsFileName($filename, true, true);
+               }
+               return t3lib_div::getURL($filename);
        }
 
        /**
@@ -1844,7 +1949,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);
        }
@@ -1889,6 +1994,31 @@ $str.=$this->docBodyTagBegin().
                foreach ($subpartArray as $marker => $content) {
                        $moduleBody = t3lib_parsehtml::substituteSubpart($moduleBody, $marker, $content);
                }
+
+               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
+                               );
+                       }
+               }
+
                        // replacing all markers with the finished markers and return the HTML content
                return t3lib_parsehtml::substituteMarkerArray($moduleBody, $markerArray, '###|###');
 
@@ -1923,9 +2053,9 @@ $str.=$this->docBodyTagBegin().
                                }
                        }
                                // replace the marker with the template and remove all line breaks (for IE compat)
-                       $markers['BUTTONLIST_' . strtoupper($key)] = str_replace("\n", '', $buttonTemplate);
+                       $markers['BUTTONLIST_' . strtoupper($key)] = str_replace(LF, '', $buttonTemplate);
                }
-               
+
                        // Hook for manipulating docHeaderButtons
                if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'])) {
                        $params = array(
@@ -1983,6 +2113,7 @@ $str.=$this->docBodyTagBegin().
                        $iconImg = t3lib_iconWorks::getIconImage('pages', $pageRecord, $this->backPath, 'class="absmiddle" title="'. htmlspecialchars($alttext) . '"');
                                // Make Icon:
                        $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
+                       $pid = $pageRecord['uid'];
                } else {        // On root-level of page tree
                                // Make Icon
                        $iconImg = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/i/_icon_website.gif') . ' alt="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '" />';
@@ -1991,169 +2122,19 @@ $str.=$this->docBodyTagBegin().
                        } else {
                                $theIcon = $iconImg;
                        }
+                       $pid = '0 (root)';
                }
 
                        // Setting icon with clickmenu + uid
-               $pageInfo = $theIcon . '<em>[pid: ' . $pageRecord['uid'] . ']</em>';
+               $pageInfo = $theIcon . '<em>[pid: ' . $pid . ']</em>';
                return $pageInfo;
        }
 
 
-       /**
-        *  Following functions are help function for JS library include.
-        *  They enable loading the libraries prototype, scriptaculous and extJS from contrib-directory
-        */
 
 
-       /**
-        * Function for render the JS-libraries in header
-        * Load order is prototype / scriptaculous / extJS
-        */
-       protected function renderJSlibraries() {
-               $libs = array();
-
-                       // include prototype
-               if ($this->addPrototype) {
-                       $libs[] = 'contrib/prototype/prototype.js';
-                               // remove prototype from JScodeLibArray
-                       $this->removeJavascriptLib('prototype');
-               }
-
-                       // include scriptaculous
-               if ($this->addScriptaculous) {
-                       $mods = array();
-                       foreach ($this->addScriptaculousModules as $key => $value) {
-                               if ($this->addScriptaculousModules[$key]) {
-                                       $mods[] = $key;
-                               }
-                       }
-                               // resolve dependencies
-                       if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
-                               $mods = array_merge(array('effects'), $mods);
-                       }
-
-                       if (count($mods)) {
-                               $moduleLoadString = '?load=' . implode(',', $mods);
-                       }
-                       $libs[] = 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString;
-                               // remove scriptaculous from JScodeLibArray
-                       $this->removeJavascriptLib('scriptaculous');
-               }
-
-                       // include extJS
-               if ($this->addExtJS) {
-                               // use the base adapter all the time
-                       $libs[] = 'contrib/extjs/adapter/' . $this->extJSadapter;
-                       $libs[] = 'contrib/extjs/ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js';
-
-                               // add extJS localization
-                       $localeMap = $GLOBAL['LANG']->csConvObj->isoArray;      // load standard ISO mapping and modify for use with ExtJS
-                       $localeMap[''] = 'en';
-                       $localeMap['default'] = 'en';
-                       $localeMap['gr'] = 'el_GR';     // Greek
-                       $localeMap['no'] = 'no_BO';     // Norwegian Bokmaal
-                       $localeMap['se'] = 'se_SV';     // Swedish
-                       $extJsLang = isset($localeMap[$GLOBALS['BE_USER']->uc['lang']]) ? $localeMap[$GLOBALS['BE_USER']->uc['lang']] : $GLOBALS['BE_USER']->uc['lang'];
-                       // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
-                       $extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $extJsLang . '.js';
-                       if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
-                               $libs[] = $extJsLocaleFile;
-                       }
-                               // set clear.gif
-                       $this->extJScode .= 'Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl('gfx/clear.gif')) . '";';
-                               // remove extjs from JScodeLibArray
-                       $this->removeJavascriptLib('extjs');
-               }
-
-               foreach ($libs as &$lib) {
-                       $lib = '<script type="text/javascript" src="' . $this->backPath . $lib . '"></script>';
-               }
-
-                       // add other JavascriptLibs and return it
-               $libs = array_merge($libs, $this->JScodeLibArray);
-               return count($libs) ? chr(10) . chr(10) . implode(chr(10), $libs) . chr(10) . chr(10) : '';
-       }
-
-       /**
-        *  call function if you need the prototype library
-        */
-       public function loadPrototype() {
-               $this->addPrototype = true;
-       }
-
-       /**
-        *  call function if you need the Scriptaculous library
-        * @param string $modules   add modules you need. use "all" if you need complete modules
-        */
-       public function loadScriptaculous($modules='') {
-                       // Scriptaculous require prototype, so load prototype too.
-               $this->addPrototype = true;
-               $this->addScriptaculous = true;
-               if ($modules) {
-                       if ($modules == 'all') {
-                               foreach ($this->addScriptaculousModules as $key => $value) {
-                                       $this->addScriptaculousModules[$key] = true;
-                               }
-                       } else {
-                               $mods = t3lib_div::trimExplode(',', $modules);
-                               foreach ($mods as $mod) {
-                                       if (isset($this->addScriptaculousModules[strtolower($mod)])) {
-                                               $this->addScriptaculousModules[strtolower($mod)] = true;
-                                       }
-                               }
-                       }
-               }
-       }
 
-       /**
-        *  call this function if you need the extJS library
-        * @param boolean $css flag, if set the ext-css will be loaded
-        * @param boolean $theme flag, if set the ext-theme "grey" will be loaded
-        * @param string $adapter choose alternative adapter, possible values: yui, prototype, jquery
-        */
-       public function loadExtJS($css = true, $theme = true, $adapter = '') {
-               if ($adapter) {
-                               // empty $adapter will always load the ext adapter
-                       switch (t3lib_div::strtolower(trim($adapter))) {
-                               case template::EXTJS_ADAPTER_YUI:
-                                       $this->extJSadapter = 'yui/ext-yui-adapter.js';
-                               break;
-                               case template::EXTJS_ADAPTER_PROTOTYPE:
-                                   $this->extJSadapter = 'prototype/ext-prototype-adapter.js';
-                               break;
-                               case template::EXTJS_ADAPTER_JQUERY:
-                                       $this->extJSadapter = 'jquery/ext-jquery-adapter.js';
-                               break;
-                       }
                }
-               if (!$this->addExtJS) {
-                       $this->addExtJS = true;
-                       if ($css) {
-                               if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
-                                       $this->addStyleSheet('ext-all', $GLOBALS['TBE_STYLES']['extJS']['all']);
-                               } else {
-                                       $this->addStyleSheet('ext-all', $this->backPath . 'contrib/extjs/resources/css/ext-all.css');
-                               }
-                       }
-                       if ($theme) {
-                               if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
-                                       $this->addStyleSheet('ext-theme', $GLOBALS['TBE_STYLES']['extJS']['theme']);
-                               } else {
-                                       $this->addStyleSheet('ext-theme', $this->backPath . 'contrib/extjs/resources/css/xtheme-gray.css');
-                               }
-                       }
-               }
-       }
-
-       /**
-        * call this function to load debug version of extJS. Use this for development only
-        */
-       public function enableExtJsDebug() {
-               $this->enableExtJsDebug = true;
-       }
-
-
-}
 
 
 // ******************************
@@ -2204,7 +2185,18 @@ class mediumDoc extends template {
  * Extension class for "template" - used in the context of frontend editing.
  */
 class frontendDoc extends template {
-       var $backPath = 'typo3/';
+
+       /**
+        * Gets instance of PageRenderer
+        *
+        * @return      t3lib_PageRenderer
+        */
+       public function getPageRenderer() {
+               if (!isset($this->pageRenderer)) {
+                       $this->pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
+               }
+               return $this->pageRenderer;
+       }
 
        /**
         * Used in the frontend context to insert header data via TSFE->additionalHeaderData.
@@ -2213,13 +2205,19 @@ 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) . '});');
+
+               $this->backPath = $GLOBALS['TSFE']->backPath = TYPO3_mainDir;
+               $this->pageRenderer->setBackPath($this->backPath);
+               $this->docStyle();
+
+                       // add applied JS/CSS to $GLOBALS['TSFE']
+               if ($this->JScode) {
+                       $this->pageRenderer->addHeaderData($this->JScode);
+               }
+               if (count($this->JScodeArray)) {
+                       foreach ($this->JScodeArray as $name => $code) {
+                               $this->pageRenderer->addJsInlineCode($name, $code);
+                       }
                }
        }
 }