* Raising Extbase and Fluid version numbers to 0.9.12
[Packages/TYPO3.CMS.git] / typo3 / template.php
index 0fe9ea1..06b2605 100644 (file)
 
 if (!defined('TYPO3_MODE'))    die("Can't include this file directly.");
 
-require_once(PATH_t3lib.'class.t3lib_ajax.php');
-
-
-
-
-
-
-
-
-
 
 /**
  * Deprecated fontwrap function. Is just transparent now.
@@ -173,7 +163,7 @@ class template {
        var $form='';                                   // This can be set to the HTML-code for a formtag. Useful when you need a form to span the whole page; Inserted exactly after the body-tag.
        var $JScodeLibArray = array();          // Similar to $JScode (see below) but used as an associative array to prevent double inclusion of JS code. This is used to include certain external Javascript libraries before the inline JS code. <script>-Tags are not wrapped around automatically
        var $JScode='';                                 // Additional header code (eg. a JavaScript section) could be accommulated in this var. It will be directly outputted in the header.
-       var $extJsCode = '';                            // Additional header code for ExtJS. It will be included in document header and inserted in a Ext.onReady(function()
+       var $extJScode = '';                            // Additional header code for ExtJS. It will be included in document header and inserted in a Ext.onReady(function()
        var $JScodeArray = array();             // Similar to $JScode but for use as array with associative keys to prevent double inclusion of JS code. a <script> tag is automatically wrapped around.
        var $postCode='';                               // Additional 'page-end' code could be accommulated in this var. It will be outputted at the end of page before </body> and some other internal page-end code.
        var $docType = '';                              // Doc-type used in the header. Default is xhtml_trans. You can also set it to 'html_3', 'xhtml_strict' or 'xhtml_frames'.
@@ -214,18 +204,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 $addExtJSdebug = false;
+       var $pageHeaderBlock = '';
+       var $endOfPageJsBlock = '';
+
+       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
@@ -236,17 +231,20 @@ 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 = ereg_replace('^.*\/(sysext|ext)\/', 'ext/', $GLOBALS['TBE_MODULES']['_PATHS'][$temp_M] . 'index.php');
+                       $this->scriptID = preg_replace('/^.*\/(sysext|ext)\//', 'ext/', $GLOBALS['TBE_MODULES']['_PATHS'][$temp_M] . 'index.php');
                } else {
-                       $this->scriptID = ereg_replace('^.*\/(sysext|ext)\/', 'ext/', substr(PATH_thisScript, strlen(PATH_site)));
+                       $this->scriptID = preg_replace('/^.*\/(sysext|ext)\//', 'ext/', substr(PATH_thisScript, strlen(PATH_site)));
                }
                if (TYPO3_mainDir!='typo3/' && substr($this->scriptID,0,strlen(TYPO3_mainDir)) == TYPO3_mainDir)        {
                        $this->scriptID = 'typo3/'.substr($this->scriptID,strlen(TYPO3_mainDir));       // This fixes if TYPO3_mainDir has been changed so the script ids are STILL "typo3/..."
                }
 
-               $this->bodyTagId = ereg_replace('[^[:alnum:]-]','-',$this->scriptID);
+               $this->bodyTagId = preg_replace('/[^A-Za-z0-9-]/','-',$this->scriptID);
 
                        // Individual configuration per script? If so, make a recursive merge of the arrays:
                if (is_array($TBE_STYLES['scriptIDindex'][$this->scriptID]))    {
@@ -276,7 +274,20 @@ class template {
        }
 
 
-
+       /**
+        * 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;
+       }
 
 
 
@@ -453,7 +464,7 @@ class template {
                $pathInfo = parse_url(t3lib_div::getIndpEnv('REQUEST_URI'));
 
                        // Add the module identifier automatically if typo3/mod.php is used:
-               if (ereg('typo3/mod\.php$', $pathInfo['path']) && isset($GLOBALS['TBE_MODULES']['_PATHS'][$modName])) {
+               if (preg_match('/typo3\/mod\.php$/', $pathInfo['path']) && isset($GLOBALS['TBE_MODULES']['_PATHS'][$modName])) {
                        $storeUrl = '&M='.$modName.$storeUrl;
                }
 
@@ -635,49 +646,46 @@ 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':
-                               $headerStart = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-';
+                               $headerStart = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">';
                                $htmlTag = '<html>';
                                break;
                        case 'xhtml_strict':
                                $headerStart = '<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<?xml version="1.0" encoding="'.$this->charset.'"?>
-<?xml-stylesheet href="#internalStyle" type="text/css"?>
-';
+       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
                                break;
                        case 'xhtml_frames':
                                $headerStart = '<!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
-     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
-<?xml version="1.0" encoding="'.$this->charset.'"?>
-';
+     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
                                break;
                        // The fallthrough is intended as XHTML 1.0 transitional is the default for the BE.
                        case 'xhtml_trans':
                        default:
                                $headerStart = '<!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<?xml version="1.0" encoding="'.$this->charset.'"?>
-<?xml-stylesheet href="#internalStyle" type="text/css"?>
-';
+     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
                }
 
                // This loads the tabulator-in-textarea feature. It automatically modifies
@@ -686,26 +694,66 @@ class template {
                        $this->loadJavascriptLib('tab.js');
                }
 
+                       // Get the browser info
+               $browserInfo = t3lib_utility_Client::getBrowserInfo(t3lib_div::getIndpEnv('HTTP_USER_AGENT'));
+
+                       // Set the XML prologue
+               $xmlPrologue = '<?xml version="1.0" encoding="' . $this->charset . '"?>';
+
+                       // Set the XML stylesheet
+               $xmlStylesheet = '<?xml-stylesheet href="#internalStyle" type="text/css"?>';
+
+                       // Add the XML prologue for XHTML doctypes
+               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;
+                       } else {
+                               $headerStart = $xmlPrologue . chr(10) . $headerStart;
+                       }
+
+                               // Add the xml stylesheet according to doctype
+                       if ($this->docType !== 'xhtml_frames') {
+                               $headerStart = $headerStart . chr(10) . $xmlStylesheet;
+                       }
+               }
+
+               $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->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 . $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->JScode = $this->extJScode = '';
                $this->JScodeArray = array();
 
+               $this->endOfPageJsBlock = $this->pageRenderer->render(t3lib_PageRenderer::PART_FOOTER);
+
                if ($this->docType=='xhtml_frames')     {
                        return $str;
                } else
@@ -738,12 +786,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));
@@ -838,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;
        }
 
        /**
@@ -944,28 +993,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(chr(10), $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 . chr(10) . '/*###POSTCSSMARKER###*/');
+               if ($this->styleSheetFile_post) {
+                       $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile_post);
+       }
 
-               return '
-                       '.$style;
        }
 
        /**
@@ -978,10 +1019,13 @@ $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, $title);
+       }
 
        /**
         * Insert post rendering document style into already rendered content
@@ -1023,7 +1067,7 @@ $str.=$this->docBodyTagBegin().
         * @return      string          <meta> tag with name "generator"
         */
        function generator()    {
-               $str = 'TYPO3 '.TYPO3_branch.', http://typo3.com, &#169; Kasper Sk&#229;rh&#248;j 1998-2008, extensions are copyright of their respective owners.';
+               $str = 'TYPO3 '.TYPO3_branch.', http://typo3.com, &#169; Kasper Sk&#229;rh&#248;j 1998-2009, extensions are copyright of their respective owners.';
                return '<meta name="generator" content="'.$str .'" />';
        }
 
@@ -1307,26 +1351,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
@@ -1335,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'] = '
@@ -1354,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');
 
@@ -1400,7 +1428,7 @@ $str.=$this->docBodyTagBegin().
                        foreach($menuItems as $value => $label) {
                                $menuDef[$value]['isActive'] = !strcmp($currentValue,$value);
                                $menuDef[$value]['label'] = t3lib_div::deHSCentities(htmlspecialchars($label));
-                               $menuDef[$value]['url'] = htmlspecialchars($script.'?'.$mainParams.$addparams.'&'.$elementName.'='.$value);
+                               $menuDef[$value]['url'] = $script . '?' . $mainParams . $addparams . '&' . $elementName . '=' . $value;
                        }
                        $content = $this->getTabMenuRaw($menuDef);
 
@@ -1801,9 +1829,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
@@ -1812,7 +1840,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);
        }
 
        /**
@@ -1822,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);
        }
@@ -1867,6 +1900,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, '###|###');
 
@@ -1903,6 +1961,19 @@ $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);
                }
+
+                       // Hook for manipulating docHeaderButtons
+               if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'])) {
+                       $params = array(
+                               'buttons'       => $buttons,
+                               'markers'       => &$markers,
+                               'pObj'          => &$this
+                       );
+                       foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'] as $funcRef)    {
+                               t3lib_div::callUserFunction($funcRef, $params, $this);
+                       }
+               }
+
                return $markers;
        }
 
@@ -1913,15 +1984,24 @@ $str.=$this->docBodyTagBegin().
         * @return      string  Page path
         */
        protected function getPagePath($pageRecord) {
-               global $LANG;
                        // Is this a real page
                if ($pageRecord['uid']) {
-                       $title = $pageRecord['_thePath'];
+                       $title = $pageRecord['_thePathFull'];
                } else {
                        $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
                }
                        // Setting the path of the page
-               $pagePath = $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.path', 1) . ': <span class="typo3-docheader-pagePath">' . htmlspecialchars(t3lib_div::fixed_lgd_cs($title, -50)) . '</span>';
+               $pagePath = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.path', 1) . ': <span class="typo3-docheader-pagePath">';
+
+                       // crop the title to title limit (or 50, if not defined)
+               $cropLength = (empty($GLOBALS['BE_USER']->uc['titleLen'])) ? 50 : $GLOBALS['BE_USER']->uc['titleLen'];
+               $croppedTitle = t3lib_div::fixed_lgd_cs($title, -$cropLength);
+               if ($croppedTitle !== $title) {
+                       $pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
+               } else {
+                       $pagePath .= htmlspecialchars($title);
+               }
+               $pagePath .= '</span>';
                return $pagePath;
        }
 
@@ -1955,142 +2035,11 @@ $str.=$this->docBodyTagBegin().
        }
 
 
-       /**
-        *  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) {
-                               // if prototype is loaded, then use the prototype adapter, otherwise the default one
-                       if ($this->addPrototype) {
-                               $libs[] = 'contrib/extjs/adapter/prototype/ext-prototype-adapter.js';
-                       } else {
-                               $libs[] = 'contrib/extjs/adapter/ext/ext-base.js';
-                       }
-                       $libs[] = 'contrib/extjs/ext-all' . ($this->addExtJSdebug ? '-debug' : '') . '.js';
 
-                               // add extJS localization
-                       $extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $GLOBALS['BE_USER']->uc['lang'] . '.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 string $css
-        */
-       public function loadExtJS($css = true, $theme = true) {
-               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 setExtJSdebug() {
-               $this->addExtJSdebug = true;
-       }
-
-       
-}
-
 
 // ******************************
 // Extension classes of the template class.
@@ -2136,6 +2085,55 @@ class mediumDoc extends template {
 }
 
 
+/**
+ * Extension class for "template" - used in the context of frontend editing.
+ */
+class frontendDoc extends template {
+
+       /**
+        * Used in the frontend context to insert header data via TSFE->additionalHeaderData.
+        * Mimics header inclusion from template->startPage().
+        *
+        * @return      void
+        */
+       public function insertHeaderData() {
+
+               /** @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);
+               }
+       }
+}
+
+
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/template.php'])     {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/template.php']);
 }