Fixed bug #15383: [Unit tests] Add tests for t3lib_div::validEmail
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_pagerenderer.php
index f0fc4ac..0e64759 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2009 Steffen Kamper (info@sk-typo3.de)
+ *  (c) 2009-2010 Steffen Kamper (info@sk-typo3.de)
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -94,6 +94,13 @@ class t3lib_PageRenderer implements t3lib_Singleton {
        const PART_HEADER = 1;
        const PART_FOOTER = 2;
 
+       // paths to contibuted libraries
+       protected $prototypePath = 'contrib/prototype/';
+       protected $scriptaculousPath = 'contrib/scriptaculous/';
+       protected $extCorePath = 'contrib/extjs/';
+       protected $extJsPath = 'contrib/extjs/';
+
+
        // internal flags for JS-libraries
        protected $addPrototype = FALSE;
        protected $addScriptaculous = FALSE;
@@ -309,12 +316,53 @@ class t3lib_PageRenderer implements t3lib_Singleton {
                $this->bodyContent = $content;
        }
 
+       /**
+        * Sets Path for prototype library (relative to typo3 directory)
+        *
+        * @param string path
+        * @return void
+        */
+       public function setPrototypePath($path) {
+               $this->prototypePath = $path;
+       }
+
+       /**
+        * Sets Path for scriptaculous library (relative to typo3 directory)
+        *
+        * @param string $path
+        * @return void
+        */
+       public function setScriptaculousPath($path) {
+               $this->scriptaculousPath = $path;
+       }
+
+       /**
+        * Sets Path for Ext Core library (relative to typo3 directory)
+        *
+        * @param string $path
+        * @return void
+        */
+       public function setExtCorePath($path) {
+               $this->extCorePath = $path;
+       }
+
+       /**
+        * Sets Path for ExtJs library (relative to typo3 directory)
+        *
+        * @param string $path
+        * @return void
+        */
+       public function setExtJsPath($path) {
+               $this->extJsPath = $path;
+       }
+
        /*****************************************************/
        /*                                                   */
-       /*  Public Enablers                                  */
+       /*  Public Enablers / Disablers                      */
        /*                                                   */
        /*                                                   */
        /*****************************************************/
+
        /**
         * Enables MoveJsFromHeaderToFooter
         *
@@ -326,6 +374,16 @@ class t3lib_PageRenderer implements t3lib_Singleton {
        }
 
        /**
+        * Disables MoveJsFromHeaderToFooter
+        *
+        * @param void
+        * @return void
+        */
+       public function disableMoveJsFromHeaderToFooter() {
+               $this->moveJsFromHeaderToFooter = FALSE;
+       }
+
+       /**
         * Enables compression of javascript
         *
         * @param void
@@ -336,6 +394,16 @@ class t3lib_PageRenderer implements t3lib_Singleton {
        }
 
        /**
+        * Disables compression of javascript
+        *
+        * @param void
+        * @return void
+        */
+       public function disableCompressJavascript() {
+               $this->compressJavascript = FALSE;
+       }
+
+       /**
         * Enables compression of css
         *
         * @param void
@@ -346,6 +414,15 @@ class t3lib_PageRenderer implements t3lib_Singleton {
        }
 
        /**
+        * Disables compression of css
+        *
+        * @param void
+        * @return void
+        */
+       public function disableCompressCss() {
+               $this->compressCss = FALSE;
+       }
+
        /**
         * Enables concatenation of js/css files
         *
@@ -357,6 +434,16 @@ class t3lib_PageRenderer implements t3lib_Singleton {
        }
 
        /**
+        * Disables concatenation of js/css files
+        *
+        * @param void
+        * @return void
+        */
+       public function disableConcatenateFiles() {
+               $this->concatenateFiles = FALSE;
+       }
+
+       /**
         * Sets removal of all line breaks in template
         *
         * @param void
@@ -366,6 +453,30 @@ class t3lib_PageRenderer implements t3lib_Singleton {
                $this->removeLineBreaksFromTemplate = TRUE;
        }
 
+       /**
+        * Unsets removal of all line breaks in template
+        *
+        * @param void
+        * @return void
+        */
+       public function disableRemoveLineBreaksFromTemplate() {
+               $this->removeLineBreaksFromTemplate = FALSE;
+       }
+
+       /**
+        * Enables Debug Mode
+        * This is a shortcut to switch off all compress/concatenate features to enable easier debug
+        *
+        * @param void
+        * @return void
+        */
+       public function enableDebugMode() {
+               $this->compressJavascript = FALSE;
+               $this->compressCss = FALSE;
+               $this->concatenateFiles = FALSE;
+               $this->removeLineBreaksFromTemplate = FALSE;
+       }
+
        /*****************************************************/
        /*                                                   */
        /*  Public Getters                                   */
@@ -517,6 +628,42 @@ class t3lib_PageRenderer implements t3lib_Singleton {
                return $this->bodyContent;
        }
 
+       /**
+        * Gets Path for prototype library (relative to typo3 directory)
+        *
+        * @return string
+        */
+       public function getPrototypePath() {
+               return $this->prototypePath;
+       }
+
+       /**
+        * Gets Path for scriptaculous library (relative to typo3 directory)
+        *
+        * @return string
+        */
+       public function getScriptaculousPath() {
+               return $this->scriptaculousPath;
+       }
+
+       /**
+        * Gets Path for Ext Core library (relative to typo3 directory)
+        *
+        * @return string
+        */
+       public function getExtCorePath() {
+               return $this->extCorePath;
+       }
+
+       /**
+        * Gets Path for ExtJs library (relative to typo3 directory)
+        *
+        * @return string
+        */
+       public function getExtJsPath() {
+               return $this->extJsPath;
+       }
+
        /*****************************************************/
        /*                                                   */
        /*  Public Function to add Data                      */
@@ -679,7 +826,7 @@ class t3lib_PageRenderer implements t3lib_Singleton {
         * @return void
         */
        public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
-               if (!isset($this->jsInline[$name])) {
+               if (!isset($this->jsInline[$name]) && !empty($block)) {
                        $this->jsInline[$name] = array (
                                'code'        => $block . LF,
                                'section'     => self::PART_HEADER,
@@ -699,7 +846,7 @@ class t3lib_PageRenderer implements t3lib_Singleton {
         * @return void
         */
        public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
-               if (!isset($this->jsInline[$name])) {
+               if (!isset($this->jsInline[$name]) && !empty($block)) {
                        $this->jsInline[$name] = array (
                                'code'        => $block . LF,
                                'section'     => self::PART_FOOTER,
@@ -764,7 +911,7 @@ class t3lib_PageRenderer implements t3lib_Singleton {
         * @return void
         */
        public function addCssInlineBlock($name, $block, $compressed = FALSE, $forceOnTop = FALSE) {
-               if (!isset($this->cssInline[$name])) {
+               if (!isset($this->cssInline[$name]) && !empty($block)) {
                        $this->cssInline[$name] = array (
                                'code'       => $block,
                                'compress'   => $compress,
@@ -1198,9 +1345,9 @@ class t3lib_PageRenderer implements t3lib_Singleton {
                $out = '';
 
                if ($this->addPrototype) {
-                       $out .= '<script src="' . $this->processJsFile($this->backPath  . 'contrib/prototype/prototype.js') .
+                       $out .= '<script src="' . $this->processJsFile($this->backPath  . $this->prototypePath . 'prototype.js') .
                                '" type="text/javascript"></script>' . LF;
-                       unset($this->jsFiles[$this->backPath . 'contrib/prototype/prototype.js']);
+                       unset($this->jsFiles[$this->backPath . $this->prototypePath .'prototype.js']);
                }
 
                if ($this->addScriptaculous) {
@@ -1218,32 +1365,32 @@ class t3lib_PageRenderer implements t3lib_Singleton {
                        if (count($mods)) {
                                foreach ($mods as $module) {
                                        $out .= '<script src="' . $this->processJsFile($this->backPath .
-                                               'contrib/scriptaculous/' . $module . '.js') . '" type="text/javascript"></script>' . LF;
-                                       unset($this->jsFiles[$this->backPath . 'contrib/scriptaculous/' . $module . '.js']);
+                                               $this->scriptaculousPath . $module . '.js') . '" type="text/javascript"></script>' . LF;
+                                       unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . $module . '.js']);
                                }
                        }
-                       $out .= '<script src="' . $this->processJsFile($this->backPath .
-                               'contrib/scriptaculous/scriptaculous.js') . '" type="text/javascript"></script>' . LF;
-                       unset($this->jsFiles[$this->backPath . 'contrib/scriptaculous/scriptaculous.js']);
+                       $out .= '<script src="' . $this->processJsFile($this->backPath . $this->scriptaculousPath .
+                               'scriptaculous.js') . '" type="text/javascript"></script>' . LF;
+                       unset($this->jsFiles[$this->backPath . $this->scriptaculousPath . 'scriptaculous.js']);
                }
 
                        // include extCore
                if ($this->addExtCore) {
                        $out .= '<script src="' . $this->processJsFile($this->backPath .
-                               'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
+                               $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
                                '" type="text/javascript"></script>' . LF;
-                       unset($this->jsFiles[$this->backPath . 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
+                       unset($this->jsFiles[$this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
                }
 
                        // include extJS
                if ($this->addExtJS) {
                                // use the base adapter all the time
-                       $out .= '<script src="' . $this->processJsFile($this->backPath .
-                               'contrib/extjs/adapter/' . ($this->enableExtJsDebug ?
+                       $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
+                               'adapter/' . ($this->enableExtJsDebug ?
                                        str_replace('.js', '-debug.js', $this->extJSadapter) : $this->extJSadapter)) .
                                '" type="text/javascript"></script>' . LF;
-                       $out .= '<script src="' . $this->processJsFile($this->backPath .
-                               'contrib/extjs/ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
+                       $out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
+                               'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
                                '" type="text/javascript"></script>' . LF;
 
                                // add extJS localization
@@ -1257,7 +1404,7 @@ class t3lib_PageRenderer implements t3lib_Singleton {
 
                        $extJsLang = isset($localeMap[$this->lang]) ? $localeMap[$this->lang] : $this->lang;
                                // TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
-                       $extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $extJsLang . '.js';
+                       $extJsLocaleFile = $this->extJsPath . 'locale/ext-lang-' . $extJsLang . '.js';
                        if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
                                $out .= '<script src="' . $this->processJsFile($this->backPath .
                                        $extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
@@ -1266,7 +1413,8 @@ class t3lib_PageRenderer implements t3lib_Singleton {
 
                                // remove extjs from JScodeLibArray
                        unset(
-                               $this->jsFiles[$this->backPath . 'contrib/extjs/ext-all.js'], $this->jsFiles[$this->backPath . 'contrib/extjs/ext-all-debug.js']
+                               $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'],
+                               $this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']
                        );
                }
 
@@ -1305,14 +1453,14 @@ class t3lib_PageRenderer implements t3lib_Singleton {
                                if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
                                        $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
                                } else {
-                                       $this->addCssFile($this->backPath . 'contrib/extjs/resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
+                                       $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
                                }
                        }
                        if ($this->extJScss) {
                                if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
                                        $this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE, TRUE);
                                } else {
-                                       $this->addCssFile($this->backPath . 'contrib/extjs/resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
+                                       $this->addCssFile($this->backPath . $this->extJsPath . 'resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
                                }
                        }
                } else {
@@ -1458,4 +1606,4 @@ class t3lib_PageRenderer implements t3lib_Singleton {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
        include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']);
 }
-?>
+?>
\ No newline at end of file