Bug #22565 ยป 14277.diff
t3lib/class.t3lib_compressor.php (Arbeitskopie) | ||
---|---|---|
$this->gzipCompressionLevel = $compressionLevel;
|
||
}
|
||
}
|
||
// decide whether we should create gzipped versions or not
|
||
$compressionLevel = $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['compressionLevel'];
|
||
// we need zlib for gzencode()
|
||
if (extension_loaded('zlib') && $compressionLevel) {
|
||
$this->createGzipped = TRUE;
|
||
// $compressionLevel can also be TRUE
|
||
if (t3lib_div::testInt($compressionLevel)) {
|
||
$this->gzipCompressionLevel = $compressionLevel;
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
... | ... | |
* Options:
|
||
* baseDirectories If set, only include files below one of the base directories
|
||
*
|
||
* @param array $cssFiles CSS files added to the PageRenderer
|
||
* @param array $cssFiles CSS files to process
|
||
* @param array $options Additional options
|
||
* @return array CSS files
|
||
*/
|
||
... | ... | |
}
|
||
/**
|
||
* Compress multiple javascript files
|
||
*
|
||
* @param array $jsFiles The files to compress (array key = filename)
|
||
* @return array The js files after compression (array key = new filename)
|
||
*/
|
||
public function compressJsFiles(array $jsFiles) {
|
||
$filesAfterCompression = array();
|
||
foreach ($jsFiles as $filename => $fileOptions) {
|
||
// we remove BACK_PATH from $filename, so make it relative to TYPO3_mainDir
|
||
$filenameFromMainDir = substr($filename, strlen($GLOBALS['BACK_PATH']));
|
||
// if compression is enabled
|
||
if ($fileOptions['compress']) {
|
||
$filesAfterCompression[$GLOBALS['BACK_PATH'] . $this->compressJsFile($filename)] = $fileOptions;
|
||
} else {
|
||
$filesAfterCompression[$filename] = $fileOptions;
|
||
}
|
||
}
|
||
return $filesAfterCompression;
|
||
}
|
||
/**
|
||
* Compresses a javascript file
|
||
*
|
||
* Options:
|
||
* baseDirectories If set, only include files below one of the base directories
|
||
*
|
||
* @param string $filename Source filename relative to requested page
|
||
* @return string Filename of the compressed file
|
||
*/
|
||
public function compressJsFile($filename) {
|
||
// generate the unique name of the file
|
||
$filenameAbsolute = t3lib_div::resolveBackPath(PATH_typo3 . substr($filename, strlen($GLOBALS['BACK_PATH'])));
|
||
$unique = $filenameAbsolute . filemtime($filenameAbsolute) . filesize($filenameAbsolute);
|
||
$pathinfo = pathinfo($filename);
|
||
$targetFile = $this->targetDirectory . $pathinfo['filename'] . '-' . md5($unique) . '.js';
|
||
// only create it, if it doesn't exist, yet
|
||
if (!file_exists(PATH_site . $targetFile) || ($this->createGzipped && !file_exists(PATH_site . $targetFile . '.gz'))) {
|
||
$contents = t3lib_div::getUrl($filenameAbsolute);
|
||
$this->writeFileAndCompressed($targetFile, $contents);
|
||
}
|
||
return $GLOBALS['BACK_PATH'] . '../' . $this->returnFileReference($targetFile);
|
||
}
|
||
/**
|
||
* Decides whether a CSS file comes from one of the baseDirectories
|
||
*
|
||
* @param string $filename Filename
|
t3lib/class.t3lib_pagerenderer.php (Arbeitskopie) | ||
---|---|---|
protected $csConvObj;
|
||
protected $lang;
|
||
/* @var t3lib_compressor Instance of t3lib_compressor */
|
||
protected $compressor;
|
||
// static array containing associative array for the included files
|
||
protected static $jsFiles = array ();
|
||
protected static $jsFooterFiles = array ();
|
||
... | ... | |
$out = '';
|
||
if ($this->addPrototype) {
|
||
$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
|
||
'contrib/prototype/prototype.js') . '" type="text/javascript"></script>' . LF;
|
||
$out .= '<script src="' . $this->processJsFile($this->backPath . 'contrib/prototype/prototype.js') .
|
||
'" type="text/javascript"></script>' . LF;
|
||
unset($this->jsFiles[$this->backPath . 'contrib/prototype/prototype.js']);
|
||
}
|
||
... | ... | |
if (count($mods)) {
|
||
$moduleLoadString = '?load=' . implode(',', $mods);
|
||
}
|
||
$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
|
||
'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString, TRUE) .
|
||
'" type="text/javascript"></script>' . LF;
|
||
$filename = $this->backPath . 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString;
|
||
if (TYPO3_MODE === 'FE') {
|
||
$filename = t3lib_div::createVersionNumberedFilename($filename, TRUE);
|
||
} else {
|
||
$filename = $this->getCompressor()->compressJsFile($filename);
|
||
}
|
||
$out .= '<script src="' . $filename . '" type="text/javascript"></script>' . LF;
|
||
unset($this->jsFiles[$this->backPath . 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString]);
|
||
}
|
||
// include extCore
|
||
if ($this->addExtCore) {
|
||
$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
|
||
$out .= '<script src="' . $this->processJsFile($this->backPath .
|
||
'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
|
||
'" type="text/javascript"></script>' . LF;
|
||
unset($this->jsFiles[$this->backPath . 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
|
||
... | ... | |
// include extJS
|
||
if ($this->addExtJS) {
|
||
// use the base adapter all the time
|
||
$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
|
||
$out .= '<script src="' . $this->processJsFile($this->backPath .
|
||
'contrib/extjs/adapter/' . ($this->enableExtJsDebug ?
|
||
str_replace('.js', '-debug.js', $this->extJSadapter) : $this->extJSadapter)) .
|
||
'" type="text/javascript"></script>' . LF;
|
||
$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
|
||
$out .= '<script src="' . $this->processJsFile($this->backPath .
|
||
'contrib/extjs/ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
|
||
'" type="text/javascript"></script>' . LF;
|
||
... | ... | |
// TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
|
||
$extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $extJsLang . '.js';
|
||
if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
|
||
$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
|
||
$out .= '<script src="' . $this->processJsFile($this->backPath .
|
||
$extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
|
||
}
|
||
... | ... | |
if ($this->extJStheme) {
|
||
if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
|
||
$this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'screen', '', FALSE, TRUE);
|
||
$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', 'screen', '', FALSE, TRUE);
|
||
$this->addCssFile($this->backPath . 'contrib/extjs/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', 'screen', '', FALSE, TRUE);
|
||
$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', 'screen', '', FALSE, TRUE);
|
||
$this->addCssFile($this->backPath . 'contrib/extjs/resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
|
||
}
|
||
}
|
||
} else {
|
||
... | ... | |
/**
|
||
* concatenate files into one file
|
||
* registered handler
|
||
* TODO: implement own method
|
||
*
|
||
* @return void
|
||
*/
|
||
... | ... | |
// use extern concatenate routine
|
||
t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler'], $params, $this);
|
||
} elseif (TYPO3_MODE === 'BE') {
|
||
$compressor = t3lib_div::makeInstance('t3lib_compressor');
|
||
$cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
|
||
$this->cssFiles = $compressor->concatenateCssFiles($this->cssFiles, $cssOptions);
|
||
$this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
}
|
||
}
|
||
}
|
||
if (TYPO3_MODE === 'BE') {
|
||
$this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
|
||
$this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
|
||
}
|
||
}
|
||
}
|
||
if ($this->compressCss) {
|
||
... | ... | |
// use extern concatenate routine
|
||
t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
|
||
} elseif (TYPO3_MODE === 'BE') {
|
||
$compressor = t3lib_div::makeInstance('t3lib_compressor');
|
||
$this->cssFiles = $compressor->compressCssFiles($this->cssFiles);
|
||
$this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
|
||
}
|
||
}
|
||
}
|
||
/**
|
||
* Returns instance of t3lib_compressor
|
||
*
|
||
* @return t3lib_compressor Instance of t3lib_compressor
|
||
*/
|
||
protected function getCompressor() {
|
||
if ($this->compressor === NULL) {
|
||
$this->compressor = t3lib_div::makeInstance('t3lib_compressor');
|
||
}
|
||
return $this->compressor;
|
||
}
|
||
/**
|
||
* Processes a Javascript file dependent on the current context
|
||
*
|
||
* Adds the version number for Frontend, compresses the file for Backend
|
||
*
|
||
* @param string $filename Filename
|
||
* @return string new filename
|
||
*/
|
||
protected function processJsFile($filename) {
|
||
switch (TYPO3_MODE) {
|
||
case 'FE':
|
||
$filename = t3lib_div::createVersionNumberedFilename($filename);
|
||
break;
|
||
case 'BE':
|
||
$filename = $this->getCompressor()->compressJsFile($filename);
|
||
break;
|
||
}
|
||
return $filename;
|
||
}
|
||
}
|
||
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
|
typo3/template.php (Arbeitskopie) | ||
---|---|---|
$this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
|
||
$this->pageRenderer->enableConcatenateFiles();
|
||
$this->pageRenderer->enableCompressCss();
|
||
$this->pageRenderer->enableCompressJavascript();
|
||
}
|
||
return $this->pageRenderer;
|
||
}
|
typo3/backend.php (Arbeitskopie) | ||
---|---|---|
'js/iecompatibility.js',
|
||
'js/flashupload.js',
|
||
'../t3lib/jsfunc.evalfield.js',
|
||
'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Backend',
|
||
'../t3lib/js/extjs/ux/flashmessages.js',
|
||
'js/backend.js',
|
||
'js/loginrefresh.js',
|
||
... | ... | |
foreach ($this->jsFiles as $jsFile) {
|
||
$this->pageRenderer->addJsFile($jsFile);
|
||
}
|
||
// we mustn't compress this file
|
||
$this->pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Backend', NULL, FALSE);
|
||
$this->generateJavascript();
|
||
$this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js);
|