Bug #22565 ยป 14277.diff

Administrator Admin, 2010-05-02 01:09

View differences:

t3lib/class.t3lib_compressor.php (Arbeitskopie)
63 63
				$this->gzipCompressionLevel = $compressionLevel;
64 64
			}
65 65
		}
66

  
67
			// decide whether we should create gzipped versions or not
68
		$compressionLevel = $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['compressionLevel'];
69
			// we need zlib for gzencode()
70
		if (extension_loaded('zlib') && $compressionLevel) {
71
			$this->createGzipped = TRUE;
72
				// $compressionLevel can also be TRUE
73
			if (t3lib_div::testInt($compressionLevel)) {
74
				$this->gzipCompressionLevel = $compressionLevel;
75
			}
76
		}
66 77
	}
67 78

  
68 79
	/**
......
71 82
	 * Options:
72 83
	 *   baseDirectories		If set, only include files below one of the base directories
73 84
	 *
74
	 * @param	array	$cssFiles		CSS files added to the PageRenderer
85
	 * @param	array	$cssFiles		CSS files to process
75 86
	 * @param	array	$options		Additional options
76 87
	 * @return	array	CSS files
77 88
	 */
......
256 267
	}
257 268

  
258 269
	/**
270
	 * Compress multiple javascript files
271
	 *
272
	 * @param	array	$jsFiles		The files to compress (array key = filename)
273
	 * @return	array		The js files after compression (array key = new filename)
274
		*/
275
	public function compressJsFiles(array $jsFiles) {
276
		$filesAfterCompression = array();
277
		foreach ($jsFiles as $filename => $fileOptions) {
278
				// we remove BACK_PATH from $filename, so make it relative to TYPO3_mainDir
279
			$filenameFromMainDir = substr($filename, strlen($GLOBALS['BACK_PATH']));
280
				// if compression is enabled
281
			if ($fileOptions['compress']) {
282
				$filesAfterCompression[$GLOBALS['BACK_PATH'] . $this->compressJsFile($filename)] = $fileOptions;
283
			} else {
284
				$filesAfterCompression[$filename] = $fileOptions;
285
			}
286
		}
287
		return $filesAfterCompression;
288
	}
289

  
290
	/**
291
	 * Compresses a javascript file
292
	 *
293
	 * Options:
294
	 *   baseDirectories		If set, only include files below one of the base directories
295
	 *
296
	 * @param	string	$filename		Source filename relative to requested page
297
	 * @return	string		Filename of the compressed file
298
	 */
299
	public function compressJsFile($filename) {
300
			// generate the unique name of the file
301
		$filenameAbsolute = t3lib_div::resolveBackPath(PATH_typo3 . substr($filename, strlen($GLOBALS['BACK_PATH'])));
302
		$unique = $filenameAbsolute . filemtime($filenameAbsolute) . filesize($filenameAbsolute);
303

  
304
		$pathinfo = pathinfo($filename);
305
		$targetFile = $this->targetDirectory . $pathinfo['filename'] . '-' . md5($unique) . '.js';
306
			// only create it, if it doesn't exist, yet
307
		if (!file_exists(PATH_site . $targetFile) || ($this->createGzipped && !file_exists(PATH_site . $targetFile . '.gz'))) {
308
			$contents = t3lib_div::getUrl($filenameAbsolute);
309
			$this->writeFileAndCompressed($targetFile, $contents);
310
		}
311
		return $GLOBALS['BACK_PATH'] . '../' . $this->returnFileReference($targetFile);
312
	}
313

  
314
	/**
259 315
	 * Decides whether a CSS file comes from one of the baseDirectories
260 316
	 *
261 317
	 * @param	string	$filename		Filename
t3lib/class.t3lib_pagerenderer.php (Arbeitskopie)
47 47
	protected $csConvObj;
48 48
	protected $lang;
49 49

  
50
	/* @var t3lib_compressor Instance of t3lib_compressor */
51
	protected $compressor;
52

  
50 53
	// static array containing associative array for the included files
51 54
	protected static $jsFiles = array ();
52 55
	protected static $jsFooterFiles = array ();
......
1178 1181
		$out = '';
1179 1182

  
1180 1183
		if ($this->addPrototype) {
1181
			$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
1182
				'contrib/prototype/prototype.js') . '" type="text/javascript"></script>' . LF;
1184
			$out .= '<script src="' . $this->processJsFile($this->backPath  . 'contrib/prototype/prototype.js') .
1185
				'" type="text/javascript"></script>' . LF;
1183 1186
			unset($this->jsFiles[$this->backPath . 'contrib/prototype/prototype.js']);
1184 1187
		}
1185 1188

  
......
1198 1201
			if (count($mods)) {
1199 1202
				$moduleLoadString = '?load=' . implode(',', $mods);
1200 1203
			}
1201
			$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
1202
				'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString, TRUE) .
1203
				'" type="text/javascript"></script>' . LF;
1204
			$filename = $this->backPath . 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString;
1205
			if (TYPO3_MODE === 'FE') {
1206
				$filename = t3lib_div::createVersionNumberedFilename($filename, TRUE);
1207
			} else {
1208
				$filename = $this->getCompressor()->compressJsFile($filename);
1209
			}
1210
			$out .= '<script src="' . $filename . '" type="text/javascript"></script>' . LF;
1204 1211
			unset($this->jsFiles[$this->backPath . 'contrib/scriptaculous/scriptaculous.js' . $moduleLoadString]);
1205 1212
		}
1206 1213

  
1207 1214
			// include extCore
1208 1215
		if ($this->addExtCore) {
1209
			$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
1216
			$out .= '<script src="' . $this->processJsFile($this->backPath .
1210 1217
				'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
1211 1218
				'" type="text/javascript"></script>' . LF;
1212 1219
			unset($this->jsFiles[$this->backPath . 'contrib/extjs/ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
......
1215 1222
			// include extJS
1216 1223
		if ($this->addExtJS) {
1217 1224
				// use the base adapter all the time
1218
			$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
1225
			$out .= '<script src="' . $this->processJsFile($this->backPath .
1219 1226
				'contrib/extjs/adapter/' . ($this->enableExtJsDebug ?
1220 1227
					str_replace('.js', '-debug.js', $this->extJSadapter) : $this->extJSadapter)) .
1221 1228
				'" type="text/javascript"></script>' . LF;
1222
			$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
1229
			$out .= '<script src="' . $this->processJsFile($this->backPath .
1223 1230
				'contrib/extjs/ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
1224 1231
				'" type="text/javascript"></script>' . LF;
1225 1232

  
......
1236 1243
				// TODO autoconvert file from UTF8 to current BE charset if necessary!!!!
1237 1244
			$extJsLocaleFile = 'contrib/extjs/locale/ext-lang-' . $extJsLang . '.js';
1238 1245
			if (file_exists(PATH_typo3 . $extJsLocaleFile)) {
1239
				$out .= '<script src="' . t3lib_div::createVersionNumberedFilename($this->backPath .
1246
				$out .= '<script src="' . $this->processJsFile($this->backPath .
1240 1247
					$extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
1241 1248
			}
1242 1249

  
......
1280 1287

  
1281 1288
			if ($this->extJStheme) {
1282 1289
				if (isset($GLOBALS['TBE_STYLES']['extJS']['theme'])) {
1283
					$this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'screen', '', FALSE, TRUE);
1290
					$this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['theme'], 'stylesheet', 'all', '', TRUE, TRUE);
1284 1291
				} else {
1285
					$this->addCssFile($this->backPath . 'contrib/extjs/resources/css/xtheme-blue.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1292
					$this->addCssFile($this->backPath . 'contrib/extjs/resources/css/xtheme-blue.css', 'stylesheet', 'all', '', TRUE, TRUE);
1286 1293
				}
1287 1294
			}
1288 1295
			if ($this->extJScss) {
1289 1296
				if (isset($GLOBALS['TBE_STYLES']['extJS']['all'])) {
1290
					$this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'screen', '', FALSE, TRUE);
1297
					$this->addCssFile($this->backPath . $GLOBALS['TBE_STYLES']['extJS']['all'], 'stylesheet', 'all', '', TRUE, TRUE);
1291 1298
				} else {
1292
					$this->addCssFile($this->backPath . 'contrib/extjs/resources/css/ext-all-notheme.css', 'stylesheet', 'screen', '', FALSE, TRUE);
1299
					$this->addCssFile($this->backPath . 'contrib/extjs/resources/css/ext-all-notheme.css', 'stylesheet', 'all', '', TRUE, TRUE);
1293 1300
				}
1294 1301
			}
1295 1302
		} else {
......
1311 1318
	/**
1312 1319
	 * concatenate files into one file
1313 1320
	 * registered handler
1314
	 * TODO: implement own method
1315 1321
	 *
1316 1322
	 * @return void
1317 1323
	 */
......
1333 1339
				// use extern concatenate routine
1334 1340
				t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler'], $params, $this);
1335 1341
			} elseif (TYPO3_MODE === 'BE') {
1336
				$compressor = t3lib_div::makeInstance('t3lib_compressor');
1337 1342
				$cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
1338
				$this->cssFiles = $compressor->concatenateCssFiles($this->cssFiles, $cssOptions);
1343
				$this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles, $cssOptions);
1339 1344
			}
1340 1345
		}
1341 1346
	}
......
1374 1379
						}
1375 1380
					}
1376 1381
				}
1382
				if (TYPO3_MODE === 'BE') {
1383
					$this->jsFiles = $this->getCompressor()->compressJsFiles($this->jsFiles);
1384
					$this->jsFooterFiles = $this->getCompressor()->compressJsFiles($this->jsFooterFiles);
1385
				}
1377 1386
			}
1378 1387
		}
1379 1388
		if ($this->compressCss) {
......
1389 1398
				// use extern concatenate routine
1390 1399
				t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
1391 1400
			} elseif (TYPO3_MODE === 'BE') {
1392
				$compressor = t3lib_div::makeInstance('t3lib_compressor');
1393
				$this->cssFiles = $compressor->compressCssFiles($this->cssFiles);
1401
				$this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
1394 1402
			}
1395 1403
		}
1396 1404
	}
1397 1405

  
1406
	/**
1407
	 * Returns instance of t3lib_compressor
1408
	 *
1409
	 * @return	t3lib_compressor		Instance of t3lib_compressor
1410
	 */
1411
	protected function getCompressor() {
1412
		if ($this->compressor === NULL) {
1413
			$this->compressor = t3lib_div::makeInstance('t3lib_compressor');
1414
		}
1415
		return $this->compressor;
1416
	}
1417

  
1418
	/**
1419
	 * Processes a Javascript file dependent on the current context
1420
	 *
1421
	 * Adds the version number for Frontend, compresses the file for Backend
1422
	 *
1423
	 * @param	string	$filename		Filename
1424
	 * @return	string		new filename
1425
	 */
1426
	protected function processJsFile($filename) {
1427
		switch (TYPO3_MODE) {
1428
			case 'FE':
1429
				$filename = t3lib_div::createVersionNumberedFilename($filename);
1430
				break;
1431
			case 'BE':
1432
				$filename = $this->getCompressor()->compressJsFile($filename);
1433
				break;
1434
		}
1435
		return $filename;
1436
	}
1398 1437
}
1399 1438

  
1400 1439
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_pagerenderer.php']) {
typo3/template.php (Arbeitskopie)
306 306
			$this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
307 307
			$this->pageRenderer->enableConcatenateFiles();
308 308
			$this->pageRenderer->enableCompressCss();
309
			$this->pageRenderer->enableCompressJavascript();
309 310
		}
310 311
		return $this->pageRenderer;
311 312
	}
typo3/backend.php (Arbeitskopie)
127 127
			'js/iecompatibility.js',
128 128
			'js/flashupload.js',
129 129
			'../t3lib/jsfunc.evalfield.js',
130
			'ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Backend',
131 130
			'../t3lib/js/extjs/ux/flashmessages.js',
132 131
			'js/backend.js',
133 132
			'js/loginrefresh.js',
......
238 237
		foreach ($this->jsFiles as $jsFile) {
239 238
			$this->pageRenderer->addJsFile($jsFile);
240 239
		}
240
			// we mustn't compress this file
241
		$this->pageRenderer->addJsFile('ajax.php?ajaxID=ExtDirect::getAPI&namespace=TYPO3.Backend', NULL, FALSE);
241 242

  
242 243
		$this->generateJavascript();
243 244
		$this->pageRenderer->addJsInlineCode('BackendInlineJavascript', $this->js);
    (1-1/1)