class.t3lib_pagerenderer.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2009-2010 Steffen Kamper (info@sk-typo3.de)
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 
00028 /**
00029  * TYPO3 pageRender class (new in TYPO3 4.3.0)
00030  * This class render the HTML of a webpage, usable for BE and FE
00031  *
00032  * @author  Steffen Kamper <info@sk-typo3.de>
00033  * @package TYPO3
00034  * @subpackage t3lib
00035  * $Id: class.t3lib_pagerenderer.php 8182 2010-07-13 20:47:42Z steffenk $
00036  */
00037 class t3lib_PageRenderer implements t3lib_Singleton {
00038 
00039     protected $compressJavascript = FALSE;
00040     protected $compressCss = FALSE;
00041     protected $removeLineBreaksFromTemplate = FALSE;
00042 
00043     protected $concatenateFiles = FALSE;
00044 
00045     protected $moveJsFromHeaderToFooter = FALSE;
00046 
00047     protected $csConvObj;
00048     protected $lang;
00049 
00050     /* @var t3lib_Compressor Instance of t3lib_Compressor */
00051     protected $compressor;
00052 
00053     // static array containing associative array for the included files
00054     protected static $jsFiles = array ();
00055     protected static $jsFooterFiles = array ();
00056     protected static $jsLibs = array ();
00057     protected static $jsFooterLibs = array ();
00058     protected static $cssFiles = array ();
00059 
00060     protected $title;
00061     protected $charSet;
00062     protected $favIcon;
00063     protected $baseUrl;
00064 
00065     protected $renderXhtml = TRUE;
00066 
00067     // static header blocks
00068     protected $xmlPrologAndDocType = '';
00069     protected $metaTags = array ();
00070     protected $inlineComments = array ();
00071     protected $headerData = array ();
00072     protected $footerData = array ();
00073     protected $titleTag = '<title>|</title>';
00074     protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
00075     protected $htmlTag = '<html>';
00076     protected $headTag = '<head>';
00077     protected $baseUrlTag = '<base href="|" />';
00078     protected $iconMimeType = '';
00079     protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />
00080 <link rel="icon" href="%1$s"%2$s />';
00081 
00082     // static inline code blocks
00083     protected $jsInline = array ();
00084     protected $extOnReadyCode = array ();
00085     protected $cssInline = array ();
00086 
00087     protected $bodyContent;
00088 
00089     protected $templateFile;
00090 
00091     protected $jsLibraryNames = array ('prototype', 'scriptaculous', 'extjs');
00092 
00093     const PART_COMPLETE = 0;
00094     const PART_HEADER = 1;
00095     const PART_FOOTER = 2;
00096 
00097     // internal flags for JS-libraries
00098     protected $addPrototype = FALSE;
00099     protected $addScriptaculous = FALSE;
00100     protected $addScriptaculousModules = array ('builder' => FALSE, 'effects' => FALSE, 'dragdrop' => FALSE, 'controls' => FALSE, 'slider' => FALSE);
00101     protected $addExtJS = FALSE;
00102     protected $addExtCore = FALSE;
00103     protected $extJSadapter = 'ext/ext-base.js';
00104 
00105     protected $enableExtJsDebug = FALSE;
00106     protected $enableExtCoreDebug = FALSE;
00107 
00108     // available adapters for extJs
00109     const EXTJS_ADAPTER_JQUERY = 'jquery';
00110     const EXTJS_ADAPTER_PROTOTYPE = 'prototype';
00111     const EXTJS_ADAPTER_YUI = 'yui';
00112 
00113     protected $extJStheme = TRUE;
00114     protected $extJScss = TRUE;
00115 
00116     protected $enableExtJSQuickTips = false;
00117 
00118     protected $inlineLanguageLabels = array ();
00119     protected $inlineSettings = array ();
00120 
00121     protected $inlineJavascriptWrap = array ();
00122 
00123     // used by BE modules
00124     public $backPath;
00125 
00126     /**
00127      * Constructor
00128      *
00129      * @param string $templateFile  declare the used template file. Omit this parameter will use default template
00130      * @param string $backPath  relative path to typo3-folder. It varies for BE modules, in FE it will be typo3/
00131      * @return void
00132      */
00133     public function __construct($templateFile = '', $backPath = NULL) {
00134 
00135         $this->reset();
00136         $this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
00137 
00138         if (strlen($templateFile)) {
00139             $this->templateFile = $templateFile;
00140         }
00141         $this->backPath = isset($backPath) ? $backPath : $GLOBALS['BACK_PATH'];
00142 
00143         $this->inlineJavascriptWrap = array(
00144             '<script type="text/javascript">' . LF . '/*<![CDATA[*/' . LF . '<!-- ' . LF,
00145             '// -->' . LF . '/*]]>*/' . LF . '</script>' . LF
00146         );
00147         $this->inlineCssWrap = array(
00148             '<style type="text/css">' . LF . '/*<![CDATA[*/' . LF . '<!-- ' . LF,
00149             '-->' . LF . '/*]]>*/' . LF . '</style>' . LF
00150         );
00151 
00152     }
00153 
00154     /**
00155      * reset all vars to initial values
00156      *
00157      * @return void
00158      */
00159     protected function reset() {
00160         $this->templateFile = TYPO3_mainDir . 'templates/template_page_backend.html';
00161         $this->jsFiles = array ();
00162         $this->jsFooterFiles = array ();
00163         $this->jsInline = array ();
00164         $this->jsFooterInline = array ();
00165         $this->jsLibs = array ();
00166         $this->cssFiles = array ();
00167         $this->cssInline = array ();
00168         $this->metaTags = array ();
00169         $this->inlineComments = array ();
00170         $this->headerData = array ();
00171         $this->footerData = array ();
00172         $this->extOnReadyCode = array ();
00173     }
00174     /*****************************************************/
00175     /*                                                   */
00176     /*  Public Setters                                   */
00177     /*                                                   */
00178     /*                                                   */
00179     /*****************************************************/
00180 
00181     /**
00182      * Sets the title
00183      *
00184      * @param string $title title of webpage
00185      * @return void
00186      */
00187     public function setTitle($title) {
00188         $this->title = $title;
00189     }
00190 
00191 
00192     /**
00193      * Enables/disables rendering of XHTML code
00194      *
00195      * @param boolean $enable   Enable XHTML
00196      * @return void
00197      */
00198     public function setRenderXhtml($enable) {
00199         $this->renderXhtml = $enable;
00200     }
00201 
00202     /**
00203      * Sets xml prolog and docType
00204      *
00205      * @param string $xmlPrologAndDocType   complete tags for xml prolog and docType
00206      * @return void
00207      */
00208     public function setXmlPrologAndDocType($xmlPrologAndDocType) {
00209         $this->xmlPrologAndDocType = $xmlPrologAndDocType;
00210     }
00211 
00212     /**
00213      * Sets meta charset
00214      *
00215      * @param string $charSet   used charset
00216      * @return void
00217      */
00218     public function setCharSet($charSet) {
00219         $this->charSet = $charSet;
00220     }
00221 
00222     /**
00223      * Sets language
00224      *
00225      * @param string $lang  used language
00226      * @return void
00227      */
00228     public function setLanguage($lang) {
00229         $this->lang = $lang;
00230     }
00231 
00232     /**
00233      * Sets html tag
00234      *
00235      * @param string $htmlTag   html tag
00236      * @return void
00237      */
00238     public function setHtmlTag($htmlTag) {
00239         $this->htmlTag = $htmlTag;
00240     }
00241 
00242     /**
00243      * Sets head tag
00244      *
00245      * @param string $tag   head tag
00246      * @return void
00247      */
00248     public function setHeadTag($headTag) {
00249         $this->headTag = $headTag;
00250     }
00251 
00252     /**
00253      * Sets favicon
00254      *
00255      * @param string $favIcon
00256      * @return void
00257      */
00258     public function setFavIcon($favIcon) {
00259         $this->favIcon = $favIcon;
00260     }
00261 
00262     /**
00263      * Sets icon mime type
00264      *
00265      * @param string $iconMimeType
00266      * @return void
00267      */
00268     public function setIconMimeType($iconMimeType) {
00269         $this->iconMimeType = $iconMimeType;
00270     }
00271 
00272     /**
00273      * Sets base url
00274      *
00275      * @param string $url
00276      * @return void
00277      */
00278     public function setBaseUrl($baseUrl) {
00279         $this->baseUrl = $baseUrl;
00280     }
00281 
00282     /**
00283      * Sets template file
00284      *
00285      * @param string $file
00286      * @return void
00287      */
00288     public function setTemplateFile($file) {
00289         $this->templateFile = $file;
00290     }
00291 
00292     /**
00293      * Sets back path
00294      *
00295      * @param string $backPath
00296      * @return void
00297      */
00298     public function setBackPath($backPath) {
00299         $this->backPath = $backPath;
00300     }
00301 
00302     /**
00303      * Sets Content for Body
00304      *
00305      * @param string $content
00306      * @return void
00307      */
00308     public function setBodyContent($content) {
00309         $this->bodyContent = $content;
00310     }
00311 
00312     /*****************************************************/
00313     /*                                                   */
00314     /*  Public Enablers / Disablers                      */
00315     /*                                                   */
00316     /*                                                   */
00317     /*****************************************************/
00318 
00319     /**
00320      * Enables MoveJsFromHeaderToFooter
00321      *
00322      * @param void
00323      * @return void
00324      */
00325     public function enableMoveJsFromHeaderToFooter() {
00326         $this->moveJsFromHeaderToFooter = TRUE;
00327     }
00328 
00329     /**
00330      * Disables MoveJsFromHeaderToFooter
00331      *
00332      * @param void
00333      * @return void
00334      */
00335     public function disableMoveJsFromHeaderToFooter() {
00336         $this->moveJsFromHeaderToFooter = FALSE;
00337     }
00338 
00339     /**
00340      * Enables compression of javascript
00341      *
00342      * @param void
00343      * @return void
00344      */
00345     public function enableCompressJavascript() {
00346         $this->compressJavascript = TRUE;
00347     }
00348 
00349     /**
00350      * Disables compression of javascript
00351      *
00352      * @param void
00353      * @return void
00354      */
00355     public function disableCompressJavascript() {
00356         $this->compressJavascript = FALSE;
00357     }
00358 
00359     /**
00360      * Enables compression of css
00361      *
00362      * @param void
00363      * @return void
00364      */
00365     public function enableCompressCss() {
00366         $this->compressCss = TRUE;
00367     }
00368 
00369     /**
00370      * Disables compression of css
00371      *
00372      * @param void
00373      * @return void
00374      */
00375     public function disableCompressCss() {
00376         $this->compressCss = FALSE;
00377     }
00378 
00379     /**
00380      * Enables concatenation of js/css files
00381      *
00382      * @param void
00383      * @return void
00384      */
00385     public function enableConcatenateFiles() {
00386         $this->concatenateFiles = TRUE;
00387     }
00388 
00389     /**
00390      * Disables concatenation of js/css files
00391      *
00392      * @param void
00393      * @return void
00394      */
00395     public function disableConcatenateFiles() {
00396         $this->concatenateFiles = FALSE;
00397     }
00398 
00399     /**
00400      * Sets removal of all line breaks in template
00401      *
00402      * @param void
00403      * @return void
00404      */
00405     public function enableRemoveLineBreaksFromTemplate() {
00406         $this->removeLineBreaksFromTemplate = TRUE;
00407     }
00408 
00409     /**
00410      * Unsets removal of all line breaks in template
00411      *
00412      * @param void
00413      * @return void
00414      */
00415     public function disableRemoveLineBreaksFromTemplate() {
00416         $this->removeLineBreaksFromTemplate = FALSE;
00417     }
00418 
00419     /**
00420      * Enables Debug Mode
00421      * This is a shortcut to switch off all compress/concatenate features to enable easier debug
00422      *
00423      * @param void
00424      * @return void
00425      */
00426     public function enableDebugMode() {
00427         $this->compressJavascript = FALSE;
00428         $this->compressCss = FALSE;
00429         $this->concatenateFiles = FALSE;
00430         $this->removeLineBreaksFromTemplate = FALSE;
00431     }
00432 
00433     /*****************************************************/
00434     /*                                                   */
00435     /*  Public Getters                                   */
00436     /*                                                   */
00437     /*                                                   */
00438     /*****************************************************/
00439 
00440     /**
00441      * Gets the title
00442      *
00443      * @return string $title        title of webpage
00444      */
00445     public function getTitle() {
00446         return $this->title;
00447     }
00448 
00449     /**
00450      * Gets the charSet
00451      *
00452      * @return string $charSet
00453      */
00454     public function getCharSet() {
00455         return $this->charSet;
00456     }
00457 
00458     /**
00459      * Gets the language
00460      *
00461      * @return string $lang
00462      */
00463     public function getLanguage() {
00464         return $this->lang;
00465     }
00466 
00467     /**
00468      * Returns rendering mode XHTML or HTML
00469      *
00470      * @return boolean      TRUE if XHTML, FALSE if HTML
00471      */
00472     public function getRenderXhtml() {
00473         return $this->renderXhtml;
00474     }
00475 
00476     /**
00477      * Gets html tag
00478      *
00479      * @return string $htmlTag  html tag
00480      */
00481     public function getHtmlTag() {
00482         return $this->htmlTag;
00483     }
00484 
00485     /**
00486      * Gets head tag
00487      *
00488      * @return string $tag  head tag
00489      */
00490     public function getHeadTag() {
00491         return $this->headTag;
00492     }
00493 
00494     /**
00495      * Gets favicon
00496      *
00497      * @return string $favIcon
00498      */
00499     public function getFavIcon() {
00500         return $this->favIcon;
00501     }
00502 
00503     /**
00504      * Gets icon mime type
00505      *
00506      * @return string $iconMimeType
00507      */
00508     public function getIconMimeType() {
00509         return $this->iconMimeType;
00510     }
00511 
00512     /**
00513      * Gets base url
00514      *
00515      * @return string $url
00516      */
00517     public function getBaseUrl() {
00518         return $this->baseUrl;
00519     }
00520 
00521     /**
00522      * Gets template file
00523      *
00524      * @return string $file
00525      */
00526     public function getTemplateFile($file) {
00527         return $this->templateFile;
00528     }
00529 
00530     /**
00531      * Gets MoveJsFromHeaderToFooter
00532      *
00533      * @return boolean
00534      */
00535     public function getMoveJsFromHeaderToFooter() {
00536         return $this->moveJsFromHeaderToFooter;
00537     }
00538 
00539     /**
00540      * Gets compress of javascript
00541      *
00542      * @return boolean
00543      */
00544     public function getCompressJavascript() {
00545         return $this->compressJavascript;
00546     }
00547 
00548     /**
00549      * Gets compress of css
00550      *
00551      * @return boolean
00552      */
00553     public function getCompressCss() {
00554         return $this->compressCss;
00555     }
00556 
00557     /**
00558      * Gets concatenate of files
00559      *
00560      * @return boolean
00561      */
00562     public function getConcatenateFiles() {
00563         return $this->concatenateFiles;
00564     }
00565 
00566     /**
00567      * Gets remove of empty lines from template
00568      *
00569      * @return boolean
00570      */
00571     public function getRemoveLineBreaksFromTemplate() {
00572         return $this->removeLineBreaksFromTemplate;
00573     }
00574 
00575     /**
00576      * Gets content for body
00577      *
00578      * @return string
00579      */
00580     public function getBodyContent() {
00581         return $this->bodyContent;
00582     }
00583 
00584     /*****************************************************/
00585     /*                                                   */
00586     /*  Public Function to add Data                      */
00587     /*                                                   */
00588     /*                                                   */
00589     /*****************************************************/
00590 
00591     /**
00592      * Adds meta data
00593      *
00594      * @param string $meta  meta data (complete metatag)
00595      * @return void
00596      */
00597     public function addMetaTag($meta) {
00598         if (!in_array($meta, $this->metaTags)) {
00599             $this->metaTags[] = $meta;
00600         }
00601     }
00602 
00603     /**
00604      * Adds inline HTML comment
00605      *
00606      * @param string $comment
00607      * @return void
00608      */
00609     public function addInlineComment($comment) {
00610         if (!in_array($comment, $this->inlineComments)) {
00611             $this->inlineComments[] = $comment;
00612         }
00613     }
00614 
00615     /**
00616      * Adds header data
00617      *
00618      * @param string $data  free header data for HTML header
00619      * @return void
00620      */
00621     public function addHeaderData($data) {
00622         if (!in_array($data, $this->headerData)) {
00623             $this->headerData[] = $data;
00624         }
00625     }
00626 
00627     /**
00628      * Adds footer data
00629      *
00630      * @param string $data  free header data for HTML header
00631      * @return void
00632      */
00633     public function addFooterData($data) {
00634         if (!in_array($data, $this->footerData)) {
00635             $this->footerData[] = $data;
00636         }
00637     }
00638 
00639     /* Javascript Files */
00640 
00641     /**
00642      * Adds JS Library. JS Library block is rendered on top of the JS files.
00643      *
00644      * @param string $name
00645      * @param string $file
00646      * @param string $type
00647      * @param boolean $compress     flag if library should be compressed
00648      * @param boolean $forceOnTop   flag if added library should be inserted at begin of this block
00649      * @param string $allWrap
00650      * @return void
00651      */
00652     public function addJsLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '') {
00653         if (!in_array(strtolower($name), $this->jsLibs)) {
00654             $this->jsLibs[strtolower($name)] = array (
00655                 'file'        => $file,
00656                 'type'        => $type,
00657                 'section'     => self::PART_HEADER,
00658                 'compress'    => $compress,
00659                 'forceOnTop'  => $forceOnTop,
00660                 'allWrap'     => $allWrap
00661             );
00662         }
00663 
00664     }
00665 
00666     /**
00667      * Adds JS Library to Footer. JS Library block is rendered on top of the Footer JS files.
00668      *
00669      * @param string $name
00670      * @param string $file
00671      * @param string $type
00672      * @param boolean $compress flag if library should be compressed
00673      * @param boolean $forceOnTop   flag if added library should be inserted at begin of this block
00674      * @param string $allWrap
00675      * @return void
00676      */
00677     public function addJsFooterLibrary($name, $file, $type = 'text/javascript', $compress = FALSE, $forceOnTop = FALSE, $allWrap = '') {
00678         if (!in_array(strtolower($name), $this->jsLibs)) {
00679             $this->jsLibs[strtolower($name)] = array (
00680                 'file'        => $file,
00681                 'type'        => $type,
00682                 'section'     => self::PART_FOOTER,
00683                 'compress'    => $compress,
00684                 'forceOnTop'  => $forceOnTop,
00685                 'allWrap'     => $allWrap
00686             );
00687         }
00688 
00689     }
00690 
00691     /**
00692      * Adds JS file
00693      *
00694      * @param string $file
00695      * @param string $type
00696      * @param boolean $compress
00697      * @param boolean $forceOnTop
00698      * @param string $allWrap
00699      * @return void
00700      */
00701     public function addJsFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
00702         if (!isset($this->jsFiles[$file])) {
00703             $this->jsFiles[$file] = array (
00704                 'type'        => $type,
00705                 'section'     => self::PART_HEADER,
00706                 'compress'    => $compress,
00707                 'forceOnTop'  => $forceOnTop,
00708                 'allWrap'     => $allWrap
00709             );
00710         }
00711     }
00712 
00713     /**
00714      * Adds JS file to footer
00715      *
00716      * @param string $file
00717      * @param string $type
00718      * @param boolean $compress
00719      * @param boolean $forceOnTop
00720      * @return void
00721      */
00722     public function addJsFooterFile($file, $type = 'text/javascript', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
00723         if (!isset($this->jsFiles[$file])) {
00724             $this->jsFiles[$file] = array (
00725                 'type'        => $type,
00726                 'section'     => self::PART_FOOTER,
00727                 'compress'    => $compress,
00728                 'forceOnTop'  => $forceOnTop,
00729                 'allWrap'     => $allWrap
00730             );
00731         }
00732     }
00733 
00734     /*Javascript Inline Blocks */
00735 
00736     /**
00737      * Adds JS inline code
00738      *
00739      * @param string $name
00740      * @param string $block
00741      * @param boolean $compress
00742      * @param boolean $forceOnTop
00743      * @return void
00744      */
00745     public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
00746         if (!isset($this->jsInline[$name]) && !empty($block)) {
00747             $this->jsInline[$name] = array (
00748                 'code'        => $block . LF,
00749                 'section'     => self::PART_HEADER,
00750                 'compress'    => $compress,
00751                 'forceOnTop'  => $forceOnTop
00752             );
00753         }
00754     }
00755 
00756     /**
00757      * Adds JS inline code to footer
00758      *
00759      * @param string $name
00760      * @param string $block
00761      * @param boolean $compress
00762      * @param boolean $forceOnTop
00763      * @return void
00764      */
00765     public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
00766         if (!isset($this->jsInline[$name]) && !empty($block)) {
00767             $this->jsInline[$name] = array (
00768                 'code'        => $block . LF,
00769                 'section'     => self::PART_FOOTER,
00770                 'compress'    => $compress,
00771                 'forceOnTop'  => $forceOnTop
00772             );
00773         }
00774     }
00775 
00776     /**
00777      * Adds Ext.onready code, which will be wrapped in Ext.onReady(function() {...});
00778      *
00779      * @param string $block javascript code
00780      * @param boolean $forceOnTop position of the javascript code (TRUE for putting it on top, default is FALSE = bottom)
00781      * @return void
00782      */
00783     public function addExtOnReadyCode($block, $forceOnTop = FALSE) {
00784         if (!in_array($block, $this->extOnReadyCode)) {
00785             if ($forceOnTop) {
00786                 array_unshift($this->extOnReadyCode, $block);
00787             } else {
00788                 $this->extOnReadyCode[] = $block;
00789             }
00790         }
00791     }
00792 
00793     /* CSS Files */
00794 
00795     /**
00796      * Adds CSS file
00797      *
00798      * @param string $file
00799      * @param string $rel
00800      * @param string $media
00801      * @param string $title
00802      * @param boolean $compress
00803      * @param boolean $forceOnTop
00804      * @return void
00805      */
00806     public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
00807         if (!isset($this->cssFiles[$file])) {
00808             $this->cssFiles[$file] = array (
00809                 'rel'        => $rel,
00810                 'media'      => $media,
00811                 'title'      => $title,
00812                 'compress'   => $compress,
00813                 'forceOnTop' => $forceOnTop,
00814                 'allWrap'    => $allWrap
00815             );
00816         }
00817     }
00818 
00819     /*CSS Inline Blocks */
00820 
00821     /**
00822      * Adds CSS inline code
00823      *
00824      * @param string $name
00825      * @param string $block
00826      * @param boolean $compress
00827      * @param boolean $forceOnTop
00828      * @return void
00829      */
00830     public function addCssInlineBlock($name, $block, $compressed = FALSE, $forceOnTop = FALSE) {
00831         if (!isset($this->cssInline[$name]) && !empty($block)) {
00832             $this->cssInline[$name] = array (
00833                 'code'       => $block,
00834                 'compress'   => $compress,
00835                 'forceOnTop' => $forceOnTop
00836             );
00837         }
00838     }
00839 
00840     /* JS Libraries */
00841 
00842     /**
00843      *  call function if you need the prototype library
00844      *
00845      * @return void
00846      */
00847     public function loadPrototype() {
00848         $this->addPrototype = TRUE;
00849     }
00850 
00851     /**
00852      * call function if you need the Scriptaculous library
00853      *
00854      * @param string $modules   add modules you need. use "all" if you need complete modules
00855      * @return void
00856      */
00857     public function loadScriptaculous($modules = 'all') {
00858         // Scriptaculous require prototype, so load prototype too.
00859         $this->addPrototype = TRUE;
00860         $this->addScriptaculous = TRUE;
00861         if ($modules) {
00862             if ($modules == 'all') {
00863                 foreach ($this->addScriptaculousModules as $key => $value) {
00864                     $this->addScriptaculousModules[$key] = TRUE;
00865                 }
00866             } else {
00867                 $mods = t3lib_div::trimExplode(',', $modules);
00868                 foreach ($mods as $mod) {
00869                     if (isset($this->addScriptaculousModules[strtolower($mod)])) {
00870                         $this->addScriptaculousModules[strtolower($mod)] = TRUE;
00871                     }
00872                 }
00873             }
00874         }
00875     }
00876 
00877     /**
00878      * call this function if you need the extJS library
00879      *
00880      * @param boolean $css flag, if set the ext-css will be loaded
00881      * @param boolean $theme flag, if set the ext-theme "grey" will be loaded
00882      * @param string $adapter choose alternative adapter, possible values: yui, prototype, jquery
00883      * @return void
00884      */
00885     public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
00886         if ($adapter) {
00887             // empty $adapter will always load the ext adapter
00888             switch (t3lib_div::strtolower(trim($adapter))) {
00889                 case self::EXTJS_ADAPTER_YUI :
00890                     $this->extJSadapter = 'yui/ext-yui-adapter.js';
00891                     break;
00892                 case self::EXTJS_ADAPTER_PROTOTYPE :
00893                     $this->extJSadapter = 'prototype/ext-prototype-adapter.js';
00894                     break;
00895                 case self::EXTJS_ADAPTER_JQUERY :
00896                     $this->extJSadapter = 'jquery/ext-jquery-adapter.js';
00897                     break;
00898             }
00899         }
00900         $this->addExtJS = TRUE;
00901         $this->extJStheme = $theme;
00902         $this->extJScss = $css;
00903 
00904     }
00905 
00906     /**
00907      * Enables ExtJs QuickTips
00908      * Need extJs loaded
00909      *
00910      * @return void
00911      *
00912      */
00913     public function enableExtJSQuickTips() {
00914         $this->enableExtJSQuickTips = TRUE;
00915     }
00916 
00917 
00918     /**
00919      * call function if you need the ExtCore library
00920      *
00921      * @return void
00922      */
00923     public function loadExtCore() {
00924         $this->addExtCore = TRUE;
00925     }
00926 
00927     /**
00928      * call this function to load debug version of ExtJS. Use this for development only
00929      *
00930      */
00931     public function enableExtJsDebug() {
00932         $this->enableExtJsDebug = TRUE;
00933     }
00934 
00935     /**
00936      * call this function to load debug version of ExtCore. Use this for development only
00937      *
00938      * @return void
00939      */
00940     public function enableExtCoreDebug() {
00941         $this->enableExtCoreDebug = TRUE;
00942     }
00943 
00944     /**
00945      * Adds Javascript Inline Label. This will occur in TYPO3.lang - object
00946      * The label can be used in scripts with TYPO3.lang.<key>
00947      * Need extJs loaded
00948      *
00949      * @param string $key
00950      * @param string $value
00951      * @return void
00952      */
00953     public function addInlineLanguageLabel($key, $value) {
00954         $this->inlineLanguageLabels[$key] = $value;
00955     }
00956 
00957     /**
00958      * Adds Javascript Inline Label Array. This will occur in TYPO3.lang - object
00959      * The label can be used in scripts with TYPO3.lang.<key>
00960      * Array will be merged with existing array.
00961      * Need extJs loaded
00962      *
00963      * @param array $array
00964      * @return void
00965      */
00966     public function addInlineLanguageLabelArray(array $array) {
00967         $this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $array);
00968     }
00969 
00970     /**
00971      * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
00972      * The label can be used in scripts with TYPO3.setting.<key>
00973      * Need extJs loaded
00974      *
00975      * @param string $namespace
00976      * @param string $key
00977      * @param string $value
00978      * @return void
00979      */
00980     public function addInlineSetting($namespace, $key, $value) {
00981         if ($namespace) {
00982             if (strpos($namespace, '.')) {
00983                 $parts = explode('.', $namespace);
00984                 $a = &$this->inlineSettings;
00985                 foreach ($parts as $part) {
00986                     $a = &$a[$part];
00987                 }
00988                 $a[$key] = $value;
00989             } else {
00990                 $this->inlineSettings[$namespace][$key] = $value;
00991             }
00992         } else {
00993             $this->inlineSettings[$key] = $value;
00994         }
00995     }
00996 
00997     /**
00998      * Adds Javascript Inline Setting. This will occur in TYPO3.settings - object
00999      * The label can be used in scripts with TYPO3.setting.<key>
01000      * Array will be merged with existing array.
01001      * Need extJs loaded
01002      *
01003      * @param string $namespace
01004      * @param array $array
01005      * @return void
01006      */
01007     public function addInlineSettingArray($namespace, array $array) {
01008         if ($namespace) {
01009             if (strpos($namespace, '.')) {
01010                 $parts = explode('.', $namespace);
01011                 $a = &$this->inlineSettings;
01012                 foreach ($parts as $part) {
01013                     $a = &$a[$part];
01014                 }
01015                 $a = array_merge((array) $a, $array);
01016             } else {
01017                 $this->inlineSettings[$namespace] = array_merge((array) $this->inlineSettings[$namespace], $array);
01018             }
01019         } else {
01020             $this->inlineSettings = array_merge($this->inlineSettings, $array);
01021         }
01022     }
01023 
01024     /**
01025      * Adds content to body content
01026      *
01027      * @param string $content
01028      * @return void
01029      */
01030     public function addBodyContent($content) {
01031         $this->bodyContent .= $content;
01032     }
01033 
01034     /*****************************************************/
01035     /*                                                   */
01036     /*  Render Functions                                 */
01037     /*                                                   */
01038     /*                                                   */
01039     /*****************************************************/
01040 
01041     /**
01042      * render the section (Header or Footer)
01043      *
01044      * @param int $part section which should be rendered: self::PART_COMPLETE, self::PART_HEADER or self::PART_FOOTER
01045      * @return string   content of rendered section
01046      */
01047     public function render($part = self::PART_COMPLETE) {
01048 
01049         $jsFiles = '';
01050         $cssFiles = '';
01051         $cssInline = '';
01052         $jsInline = '';
01053         $jsFooterInline = '';
01054         $jsFooterLibs = '';
01055         $jsFooterFiles = '';
01056         $noJS = FALSE;
01057 
01058         // preRenderHook for possible manuipulation
01059         if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
01060             $params = array (
01061                 'jsLibs'         => &$this->jsLibs,
01062                 'jsFiles'        => &$this->jsFiles,
01063                 'jsFooterFiles'  => &$this->jsFooterFiles,
01064                 'cssFiles'       => &$this->cssFiles,
01065                 'headerData'     => &$this->headerData,
01066                 'footerData'     => &$this->footerData,
01067                 'jsInline'       => &$this->jsInline,
01068                 'cssInline'      => &$this->cssInline,
01069             );
01070             foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
01071                 t3lib_div::callUserFunction($hook, $params, $this);
01072             }
01073         }
01074 
01075         $jsLibs = $this->renderJsLibraries();
01076 
01077         if ($this->concatenateFiles) {
01078                 // do the file concatenation
01079             $this->doConcatenate();
01080         }
01081         if ($this->compressCss || $this->compressJavascript) {
01082                 // do the file compression
01083             $this->doCompress();
01084         }
01085 
01086         $metaTags = implode(LF, $this->metaTags);
01087 
01088             // remove ending slashes from static header block
01089             // if the page is beeing rendered as html (not xhtml)
01090             // and define variable $endingSlash for further use
01091         if ($this->getRenderXhtml()) {
01092             $endingSlash = ' /';
01093         } else {
01094             $this->metaCharsetTag = str_replace(' />', '>', $this->metaCharsetTag);
01095             $this->baseUrlTag = str_replace(' />', '>', $this->baseUrlTag);
01096             $this->shortcutTag = str_replace(' />', '>', $this->shortcutTag);
01097             $endingSlash = '';
01098         }
01099 
01100         if (count($this->cssFiles)) {
01101             foreach ($this->cssFiles as $file => $properties) {
01102                 $file = t3lib_div::resolveBackPath($file);
01103                 $file = t3lib_div::createVersionNumberedFilename($file);
01104                 $tag = '<link rel="' . $properties['rel'] . '" type="text/css" href="' .
01105                     htmlspecialchars($file) . '" media="' . $properties['media'] . '"' .
01106                     ($properties['title'] ? ' title="' . $properties['title'] . '"' : '') .
01107                     $endingSlash . '>';
01108                 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
01109                     $tag = str_replace('|', $tag, $properties['allWrap']);
01110                 }
01111                 if ($properties['forceOnTop']) {
01112                     $cssFiles = $tag . LF . $cssFiles;
01113                 } else {
01114                     $cssFiles .= LF . $tag;
01115                 }
01116             }
01117         }
01118 
01119         if (count($this->cssInline)) {
01120             foreach ($this->cssInline as $name => $properties) {
01121                 if ($properties['forceOnTop']) {
01122                     $cssInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $cssInline;
01123                 } else {
01124                     $cssInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
01125                 }
01126             }
01127             $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
01128         }
01129 
01130         if (count($this->jsLibs)) {
01131             foreach ($this->jsLibs as $name => $properties) {
01132                 $properties['file'] = t3lib_div::resolveBackPath($properties['file']);
01133                 $properties['file'] = t3lib_div::createVersionNumberedFilename($properties['file']);
01134                 $tag = '<script src="' . htmlspecialchars($properties['file']) . '" type="' . $properties['type'] . '"></script>';
01135                 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
01136                     $tag = str_replace('|', $tag, $properties['allWrap']);
01137                 }
01138                 if ($properties['forceOnTop']) {
01139                     if ($properties['section'] === self::PART_HEADER) {
01140                         $jsLibs = $tag . LF . $jsLibs;
01141                     } else {
01142                         $jsFooterLibs = $tag . LF . $jsFooterLibs;
01143                     }
01144                 } else {
01145                     if ($properties['section'] === self::PART_HEADER) {
01146                         $jsLibs .= LF . $tag;
01147                     } else {
01148                         $jsFooterLibs .= LF . $tag;
01149                     }
01150                 }
01151             }
01152         }
01153 
01154         if (count($this->jsFiles)) {
01155             foreach ($this->jsFiles as $file => $properties) {
01156                 $file = t3lib_div::resolveBackPath($file);
01157                 $file = t3lib_div::createVersionNumberedFilename($file);
01158                 $tag = '<script src="' . htmlspecialchars($file) . '" type="' . $properties['type'] . '"></script>';
01159                 if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
01160                     $tag = str_replace('|', $tag, $properties['allWrap']);
01161                 }
01162                 if ($properties['forceOnTop']) {
01163                     if ($properties['section'] === self::PART_HEADER) {
01164                         $jsFiles = $tag . LF . $jsFiles;
01165                     } else {
01166                         $jsFooterFiles = $tag . LF . $jsFooterFiles;
01167                     }
01168                 } else {
01169                     if ($properties['section'] === self::PART_HEADER) {
01170                         $jsFiles .= LF . $tag;
01171                     } else {
01172                         $jsFooterFiles .= LF . $tag;
01173                     }
01174                 }
01175             }
01176         }
01177 
01178         if (count($this->jsInline)) {
01179             foreach ($this->jsInline as $name => $properties) {
01180                 if ($properties['forceOnTop']) {
01181                     if ($properties['section'] === self::PART_HEADER) {
01182                         $jsInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsInline;
01183                     } else {
01184                         $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsFooterInline;
01185                     }
01186                 } else {
01187                     if ($properties['section'] === self::PART_HEADER) {
01188                         $jsInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
01189                     } else {
01190                         $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
01191                     }
01192                 }
01193             }
01194         }
01195 
01196 
01197         if ($jsInline) {
01198             $jsInline = $this->inlineJavascriptWrap[0] . $jsInline . $this->inlineJavascriptWrap[1];
01199         }
01200 
01201         if ($jsFooterInline) {
01202             $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
01203         }
01204 
01205 
01206             // get template
01207         $templateFile = t3lib_div::getFileAbsFileName($this->templateFile, TRUE);
01208         $template = t3lib_div::getURL($templateFile);
01209 
01210         if ($this->removeEmptyLinesFromTemplate) {
01211             $template = strtr($template, array(LF => '', CR => ''));
01212         }
01213         if ($part != self::PART_COMPLETE) {
01214             $templatePart = explode('###BODY###', $template);
01215             $template = $templatePart[$part - 1];
01216         }
01217 
01218         if ($this->moveJsFromHeaderToFooter) {
01219             $jsFooterLibs = $jsLibs . LF . $jsFooterLibs;
01220             $jsLibs = '';
01221             $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
01222             $jsFiles = '';
01223             $jsFooterInline = $jsInline . LF . $jsFooterInline;
01224             $jsInline = '';
01225         }
01226 
01227         $markerArray = array(
01228             'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
01229             'HTMLTAG'           => $this->htmlTag,
01230             'HEADTAG'           => $this->headTag,
01231             'METACHARSET'       => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
01232             'INLINECOMMENT'     => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
01233             'BASEURL'           => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
01234             'SHORTCUT'          => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
01235             'CSS_INCLUDE'       => $cssFiles,
01236             'CSS_INLINE'        => $cssInline,
01237             'JS_INLINE'         => $jsInline,
01238             'JS_INCLUDE'        => $jsFiles,
01239             'JS_LIBS'           => $jsLibs,
01240             'TITLE'             => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
01241             'META'              => $metaTags,
01242             'HEADERDATA'        => $this->headerData ? implode(LF, $this->headerData) : '',
01243             'FOOTERDATA'        => $this->footerData ? implode(LF, $this->footerData) : '',
01244             'JS_LIBS_FOOTER'    => $jsFooterLibs,
01245             'JS_INCLUDE_FOOTER' => $jsFooterFiles,
01246             'JS_INLINE_FOOTER'  => $jsFooterInline,
01247             'BODY'              => $this->bodyContent,
01248         );
01249 
01250         $markerArray = array_map('trim', $markerArray);
01251 
01252         $this->reset();
01253         return trim(t3lib_parsehtml::substituteMarkerArray($template, $markerArray, '###|###'));
01254     }
01255 
01256     /**
01257      * helper function for render the javascript libraries
01258      *
01259      * @return string   content with javascript libraries
01260      */
01261     protected function renderJsLibraries() {
01262         $out = '';
01263 
01264         if ($this->addPrototype) {
01265             $out .= '<script src="' . $this->processJsFile($this->backPath  . 'contrib/prototype/prototype.js') .
01266                 '" type="text/javascript"></script>' . LF;
01267             unset($this->jsFiles[$this->backPath . 'contrib/prototype/prototype.js']);
01268         }
01269 
01270         if ($this->addScriptaculous) {
01271             $mods = array ();
01272             foreach ($this->addScriptaculousModules as $key => $value) {
01273                 if ($this->addScriptaculousModules[$key]) {
01274                     $mods[] = $key;
01275                 }
01276             }
01277                 // resolve dependencies
01278             if (in_array('dragdrop', $mods) || in_array('controls', $mods)) {
01279                 $mods = array_merge(array('effects'), $mods);
01280             }
01281 
01282             if (count($mods)) {
01283                 foreach ($mods as $module) {
01284                     $out .= '<script src="' . $this->processJsFile($this->backPath .
01285                         'contrib/scriptaculous/' . $module . '.js') . '" type="text/javascript"></script>' . LF;
01286                     unset($this->jsFiles[$this->backPath . 'contrib/scriptaculous/' . $module . '.js']);
01287                 }
01288             }
01289             $out .= '<script src="' . $this->processJsFile($this->backPath .
01290                 'contrib/scriptaculous/scriptaculous.js') . '" type="text/javascript"></script>' . LF;
01291             unset($this->jsFiles[$this->backPath . 'contrib/scriptaculous/scriptaculous.js']);
01292         }
01293 
01294             // include extCore
01295         if ($this->addExtCore) {
01296             $out .= '<script src="' . $this->processJsFile($this->backPath .
01297                 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
01298                 '" type="text/javascript"></script>' . LF;
01299             unset($this->jsFiles[$this->backPath . 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
01300         }
01301 
01302             // include extJS
01303         if ($this->addExtJS) {
01304                 // use the base adapter all the time
01305             $out .= '<script src="' . $this->processJsFile($this->backPath .
01306                 'contrib/extjs/adapter/' . ($this->enableExtJsDebug ?
01307                     str_replace('.js', '-debug.js', $this->extJSadapter) : $this->extJSadapter)) .
01308                 '" type="text/javascript"></script>' . LF;
01309             $out .= '<script src="' . $this->processJsFile($this->backPath .
01310                 'contrib/extjs/ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
01311                 '" type="text/javascript"></script>' . LF;
01312 
01313                 // add extJS localization
01314             $localeMap = $this->csConvObj->isoArray; // load standard ISO mapping and modify for use with ExtJS
01315             $localeMap[''] = 'en';
01316             $localeMap['default'] = 'en';
01317             $localeMap['gr'] = 'el_GR'; // Greek
01318             $localeMap['no'] = 'no_BO'; // Norwegian Bokmaal
01319             $localeMap['se'] = 'se_SV'; // Swedish
01320 
01321 
01322             $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
01323                 // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
01324             $extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $extJsLang . '.js';
01325             if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
01326                 $out .= '<script src="' . $this->processJsFile($this->backPath .
01327                     $extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
01328             }
01329 
01330 
01331                 // remove extjs from JScodeLibArray
01332             unset(
01333                 $this->jsFiles[$this->backPath . 'contrib/extjs/ext-all.js'], $this->jsFiles[$this->backPath . 'contrib/extjs/ext-all-debug.js']
01334             );
01335         }
01336 
01337             // Convert labels/settings back to UTF-8 since json_encode() only works with UTF-8:
01338         if ($this->getCharSet() !== 'utf-8') {
01339             if ($this->inlineLanguageLabels) {
01340                 $this->csConvObj->convArray($this->inlineLanguageLabels, $this->getCharSet(), 'utf-8');
01341             }
01342             if ($this->inlineSettings) {
01343                 $this->csConvObj->convArray($this->inlineSettings, $this->getCharSet(), 'utf-8');
01344             }
01345         }
01346 
01347         $inlineSettings = $this->inlineLanguageLabels ? 'TYPO3.lang = ' . json_encode($this->inlineLanguageLabels) . ';' : '';
01348         $inlineSettings .= $this->inlineSettings ? 'TYPO3.settings = ' . json_encode($this->inlineSettings) . ';' : '';
01349 
01350         if ($this->addExtCore || $this->addExtJS) {
01351                 // set clear.gif, move it on top, add handler code
01352             $code = '';
01353             if (count($this->extOnReadyCode)) {
01354                 foreach ($this->extOnReadyCode as $block) {
01355                     $code .= $block;
01356                 }
01357             }
01358 
01359             $out .= $this->inlineJavascriptWrap[0] . '
01360                 Ext.ns("TYPO3");
01361                 Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl($this->backPath . 'gfx/clear.gif')) . '";' . LF .
01362                 $inlineSettings .
01363                 'Ext.onReady(function() {' .
01364                 ($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . LF : '') . $code .
01365                 ' });' . $this->inlineJavascriptWrap[1];
01366             unset ($this->extOnReadyCode);
01367 
01368             if ($this->extJStheme) {
01369                 if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
01370                     $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
01371                 } else {
01372                     $this->addCssFile($this->backPath . 'contrib/extjs/resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
01373                 }
01374             }
01375             if ($this->extJScss) {
01376                 if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
01377                     $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE, TRUE);
01378                 } else {
01379                     $this->addCssFile($this->backPath . 'contrib/extjs/resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
01380                 }
01381             }
01382         } else {
01383             if ($inlineSettings) {
01384                 $out .= $this->inlineJavascriptWrap[0] . $inlineSettings . $this->inlineJavascriptWrap[1];
01385             }
01386         }
01387 
01388         return $out;
01389     }
01390 
01391     /*****************************************************/
01392     /*                                                   */
01393     /*  Tools                                            */
01394     /*                                                   */
01395     /*                                                   */
01396     /*****************************************************/
01397 
01398     /**
01399      * concatenate files into one file
01400      * registered handler
01401      *
01402      * @return void
01403      */
01404     protected function doConcatenate() {
01405         // traverse the arrays, concatenate in one file
01406         // then remove concatenated files from array and add the concatenated file
01407 
01408         if ($this->concatenateFiles) {
01409             $params = array (
01410                 'jsLibs'         => &$this->jsLibs,
01411                 'jsFiles'        => &$this->jsFiles,
01412                 'jsFooterFiles'  => &$this->jsFooterFiles,
01413                 'cssFiles'       => &$this->cssFiles,
01414                 'headerData'     => &$this->headerData,
01415                 'footerData'     => &$this->footerData,
01416             );
01417 
01418             if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler']) {
01419                 // use extern concatenate routine
01420                 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler'], $params, $this);
01421             } elseif (TYPO3_MODE === 'BE') {
01422                 $cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
01423                 $this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
01424             }
01425         }
01426     }
01427 
01428     /**
01429      * compress inline code
01430      *
01431      * @return void
01432      */
01433     protected function doCompress() {
01434 
01435         if ($this->compressJavascript && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler']) {
01436             // use extern compress routine
01437             $params = array (
01438                 'jsInline'        => &$this->jsInline,
01439                 'jsFooterInline'  => &$this->jsFooterInline,
01440                 'jsLibs'          => &$this->jsLibs,
01441                 'jsFiles'         => &$this->jsFiles,
01442                 'jsFooterFiles'   => &$this->jsFooterFiles,
01443                 'headerData'      => &$this->headerData,
01444                 'footerData'      => &$this->footerData,
01445             );
01446             t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
01447         } else {
01448                 // traverse the arrays, compress files
01449             $this->compressError = '';
01450 
01451             if ($this->compressJavascript) {
01452                 if (count($this->jsInline)) {
01453                     foreach ($this->jsInline as $name => $properties) {
01454                         if ($properties['compress']) {
01455                             $error = '';
01456                             $this->jsInline[$name]['code'] = t3lib_div::minifyJavaScript($properties['code'], $error);
01457                             if ($error) {
01458                                 $this->compressError .= 'Error with minify JS Inline Block "' . $name . '": ' . $error . LF;
01459                             }
01460                         }
01461                     }
01462                 }
01463                 if (TYPO3_MODE === 'BE') {
01464                     $this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
01465                     $this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
01466                 }
01467             }
01468         }
01469         if ($this->compressCss) {
01470                 // use extern compress routine
01471             $params = array (
01472                 'cssInline'  => &$this->cssInline,
01473                 'cssFiles'   => &$this->cssFiles,
01474                 'headerData' => &$this->headerData,
01475                 'footerData' => &$this->footerData,
01476             );
01477 
01478             if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler']) {
01479                 // use extern concatenate routine
01480                 t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
01481             } elseif (TYPO3_MODE === 'BE') {
01482                 $this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
01483             }
01484         }
01485     }
01486 
01487     /**
01488      * Returns instance of t3lib_Compressor
01489      *
01490      * @return  t3lib_Compressor        Instance of t3lib_Compressor
01491      */
01492     protected function getCompressor() {
01493         if ($this->compressor === NULL) {
01494             $this->compressor = t3lib_div::makeInstance('t3lib_Compressor');
01495         }
01496         return $this->compressor;
01497     }
01498 
01499     /**
01500      * Processes a Javascript file dependent on the current context
01501      *
01502      * Adds the version number for Frontend, compresses the file for Backend
01503      *
01504      * @param   string  $filename       Filename
01505      * @return  string      new filename
01506      */
01507     protected function processJsFile($filename) {
01508         switch (TYPO3_MODE) {
01509             case 'FE':
01510                 $filename = t3lib_div::createVersionNumberedFilename($filename);
01511                 break;
01512             case 'BE':
01513                 if ($this->compressJavascript) {
01514                     $filename = $this->getCompressor()->compressJsFile($filename);
01515                 }
01516                 break;
01517         }
01518         return $filename;
01519     }
01520 }
01521 
01522 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
01523     include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);
01524 }
01525 ?>

Generated on Sat Jul 24 04:17:17 2010 for TYPO3 API by  doxygen 1.4.7