Project

General

Profile

Bug #22410 » 14050_cleaning_t3lib_pagerenderer.patch

Administrator Admin, 2010-11-24 13:31

View differences:

t3lib/class.t3lib_pagerenderer.php (revision )
/* @var t3lib_Compressor Instance of t3lib_Compressor */
protected $compressor;
// static array containing associative array for the included files
// static array containing associative array for the included files
protected static $jsFiles = array ();
protected static $jsFiles = array();
protected static $jsFooterFiles = array ();
protected static $jsFooterFiles = array();
protected static $jsLibs = array ();
protected static $jsLibs = array();
protected static $jsFooterLibs = array ();
protected static $jsFooterLibs = array();
protected static $cssFiles = array ();
protected static $cssFiles = array();
protected $title;
protected $charSet;
......
protected $renderXhtml = TRUE;
// static header blocks
// static header blocks
protected $xmlPrologAndDocType = '';
protected $metaTags = array ();
protected $metaTags = array();
protected $inlineComments = array ();
protected $inlineComments = array();
protected $headerData = array ();
protected $headerData = array();
protected $footerData = array ();
protected $footerData = array();
protected $titleTag = '<title>|</title>';
protected $metaCharsetTag = '<meta http-equiv="Content-Type" content="text/html; charset=|" />';
protected $htmlTag = '<html>';
......
protected $shortcutTag = '<link rel="shortcut icon" href="%1$s"%2$s />
<link rel="icon" href="%1$s"%2$s />';
// static inline code blocks
// static inline code blocks
protected $jsInline = array ();
protected $jsInline = array();
protected $jsFooterInline = array ();
protected $jsFooterInline = array();
protected $extOnReadyCode = array ();
protected $extOnReadyCode = array();
protected $cssInline = array ();
protected $cssInline = array();
protected $bodyContent;
protected $templateFile;
protected $jsLibraryNames = array ('prototype', 'scriptaculous', 'extjs');
protected $jsLibraryNames = array('prototype', 'scriptaculous', 'extjs');
const PART_COMPLETE = 0;
const PART_HEADER = 1;
const PART_FOOTER = 2;
// paths to contibuted libraries
// paths to contibuted libraries
protected $prototypePath = 'contrib/prototype/';
protected $scriptaculousPath = 'contrib/scriptaculous/';
protected $extCorePath = 'contrib/extjs/';
......
protected $svgPath = 'contrib/websvg/';
// internal flags for JS-libraries
// internal flags for JS-libraries
protected $addPrototype = FALSE;
protected $addScriptaculous = FALSE;
protected $addScriptaculousModules = array ('builder' => FALSE, 'effects' => FALSE, 'dragdrop' => FALSE, 'controls' => FALSE, 'slider' => FALSE);
protected $addScriptaculousModules = array('builder' => FALSE, 'effects' => FALSE, 'dragdrop' => FALSE, 'controls' => FALSE, 'slider' => FALSE);
protected $addExtJS = FALSE;
protected $addExtCore = FALSE;
protected $extJSadapter = 'ext/ext-base.js';
......
protected $enableExtJsDebug = FALSE;
protected $enableExtCoreDebug = FALSE;
// available adapters for extJs
// available adapters for extJs
const EXTJS_ADAPTER_JQUERY = 'jquery';
const EXTJS_ADAPTER_PROTOTYPE = 'prototype';
const EXTJS_ADAPTER_YUI = 'yui';
......
protected $extJStheme = TRUE;
protected $extJScss = TRUE;
protected $enableExtJSQuickTips = false;
protected $enableExtJSQuickTips = FALSE;
protected $inlineLanguageLabels = array ();
protected $inlineLanguageLabels = array();
protected $inlineLanguageLabelFiles = array();
protected $inlineSettings = array ();
protected $inlineSettings = array();
protected $inlineJavascriptWrap = array ();
protected $inlineJavascriptWrap = array();
// saves error messages generated during compression
// saves error messages generated during compression
protected $compressError = '';
// SVG library
// SVG library
protected $addSvg = FALSE;
protected $enableSvgDebug = FALSE;
// used by BE modules
// used by BE modules
public $backPath;
/**
......
*/
protected function reset() {
$this->templateFile = TYPO3_mainDir . 'templates/template_page_backend.html';
$this->jsFiles = array ();
$this->jsFiles = array();
$this->jsFooterFiles = array ();
$this->jsFooterFiles = array();
$this->jsInline = array ();
$this->jsInline = array();
$this->jsFooterInline = array ();
$this->jsFooterInline = array();
$this->jsLibs = array ();
$this->jsLibs = array();
$this->cssFiles = array ();
$this->cssFiles = array();
$this->cssInline = array ();
$this->cssInline = array();
$this->metaTags = array ();
$this->metaTags = array();
$this->inlineComments = array ();
$this->inlineComments = array();
$this->headerData = array ();
$this->headerData = array();
$this->footerData = array ();
$this->footerData = array();
$this->extOnReadyCode = array ();
$this->extOnReadyCode = array();
}
/*****************************************************/
/* */
/* Public Setters */
......
/**
* Adds header data
*
* @param string $data free header data for HTML header
* @param string $data free header data for HTML header
* @return void
*/
public function addHeaderData($data) {
......
/**
* Adds footer data
*
* @param string $data free header data for HTML header
* @param string $data free header data for HTML header
* @return void
*/
public function addFooterData($data) {
......
$type = 'text/javascript';
}
if (!in_array(strtolower($name), $this->jsLibs)) {
$this->jsLibs[strtolower($name)] = array (
$this->jsLibs[strtolower($name)] = array(
'file' => $file,
'file' => $file,
'type' => $type,
'type' => $type,
'section' => self::PART_HEADER,
'section' => self::PART_HEADER,
'compress' => $compress,
'compress' => $compress,
'forceOnTop' => $forceOnTop,
'forceOnTop' => $forceOnTop,
'allWrap' => $allWrap
'allWrap' => $allWrap
);
}
......
$type = 'text/javascript';
}
if (!in_array(strtolower($name), $this->jsLibs)) {
$this->jsLibs[strtolower($name)] = array (
$this->jsLibs[strtolower($name)] = array(
'file' => $file,
'file' => $file,
'type' => $type,
'type' => $type,
'section' => self::PART_FOOTER,
'section' => self::PART_FOOTER,
'compress' => $compress,
'compress' => $compress,
'forceOnTop' => $forceOnTop,
'forceOnTop' => $forceOnTop,
'allWrap' => $allWrap
'allWrap' => $allWrap
);
}
......
$type = 'text/javascript';
}
if (!isset($this->jsFiles[$file])) {
$this->jsFiles[$file] = array (
$this->jsFiles[$file] = array(
'type' => $type,
'type' => $type,
'section' => self::PART_HEADER,
'section' => self::PART_HEADER,
'compress' => $compress,
'compress' => $compress,
'forceOnTop' => $forceOnTop,
'forceOnTop' => $forceOnTop,
'allWrap' => $allWrap
'allWrap' => $allWrap
);
}
}
......
$type = 'text/javascript';
}
if (!isset($this->jsFiles[$file])) {
$this->jsFiles[$file] = array (
$this->jsFiles[$file] = array(
'type' => $type,
'type' => $type,
'section' => self::PART_FOOTER,
'section' => self::PART_FOOTER,
'compress' => $compress,
'compress' => $compress,
'forceOnTop' => $forceOnTop,
'forceOnTop' => $forceOnTop,
'allWrap' => $allWrap
'allWrap' => $allWrap
);
}
}
......
*/
public function addJsInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
if (!isset($this->jsInline[$name]) && !empty($block)) {
$this->jsInline[$name] = array (
$this->jsInline[$name] = array(
'code' => $block . LF,
'code' => $block . LF,
'section' => self::PART_HEADER,
'section' => self::PART_HEADER,
'compress' => $compress,
'compress' => $compress,
'forceOnTop' => $forceOnTop
'forceOnTop' => $forceOnTop
);
}
}
......
*/
public function addJsFooterInlineCode($name, $block, $compress = TRUE, $forceOnTop = FALSE) {
if (!isset($this->jsInline[$name]) && !empty($block)) {
$this->jsInline[$name] = array (
$this->jsInline[$name] = array(
'code' => $block . LF,
'code' => $block . LF,
'section' => self::PART_FOOTER,
'section' => self::PART_FOOTER,
'compress' => $compress,
'compress' => $compress,
'forceOnTop' => $forceOnTop
'forceOnTop' => $forceOnTop
);
}
}
......
*/
public function addCssFile($file, $rel = 'stylesheet', $media = 'all', $title = '', $compress = TRUE, $forceOnTop = FALSE, $allWrap = '') {
if (!isset($this->cssFiles[$file])) {
$this->cssFiles[$file] = array (
$this->cssFiles[$file] = array(
'rel' => $rel,
'rel' => $rel,
'media' => $media,
'media' => $media,
'title' => $title,
'title' => $title,
'compress' => $compress,
'compress' => $compress,
'forceOnTop' => $forceOnTop,
'allWrap' => $allWrap
'allWrap' => $allWrap
);
}
}
......
*/
public function addCssInlineBlock($name, $block, $compress = FALSE, $forceOnTop = FALSE) {
if (!isset($this->cssInline[$name]) && !empty($block)) {
$this->cssInline[$name] = array (
$this->cssInline[$name] = array(
'code' => $block,
'code' => $block,
'compress' => $compress,
'compress' => $compress,
'forceOnTop' => $forceOnTop
);
}
......
* @return void
*/
public function loadScriptaculous($modules = 'all') {
// Scriptaculous require prototype, so load prototype too.
// Scriptaculous require prototype, so load prototype too.
$this->addPrototype = TRUE;
$this->addScriptaculous = TRUE;
if ($modules) {
......
*/
public function loadExtJS($css = TRUE, $theme = TRUE, $adapter = '') {
if ($adapter) {
// empty $adapter will always load the ext adapter
// empty $adapter will always load the ext adapter
switch (t3lib_div::strtolower(trim($adapter))) {
case self::EXTJS_ADAPTER_YUI :
$this->extJSadapter = 'yui/ext-yui-adapter.js';
break;
break;
case self::EXTJS_ADAPTER_PROTOTYPE :
$this->extJSadapter = 'prototype/ext-prototype-adapter.js';
break;
break;
case self::EXTJS_ADAPTER_JQUERY :
$this->extJSadapter = 'jquery/ext-jquery-adapter.js';
break;
break;
}
}
$this->addExtJS = TRUE;
......
$jsFooterLibs = '';
$jsFooterFiles = '';
// preRenderHook for possible manuipulation
// preRenderHook for possible manuipulation
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'])) {
$params = array (
$params = array(
'jsLibs' => &$this->jsLibs,
'jsLibs' => &$this->jsLibs,
'jsFiles' => &$this->jsFiles,
'jsFiles' => &$this->jsFiles,
'jsFooterFiles' => &$this->jsFooterFiles,
'jsFooterFiles' => &$this->jsFooterFiles,
'cssFiles' => &$this->cssFiles,
'cssFiles' => &$this->cssFiles,
'headerData' => &$this->headerData,
'headerData' => &$this->headerData,
'footerData' => &$this->footerData,
'footerData' => &$this->footerData,
'jsInline' => &$this->jsInline,
'jsInline' => &$this->jsInline,
'cssInline' => &$this->cssInline,
'cssInline' => &$this->cssInline,
);
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'] as $hook) {
t3lib_div::callUserFunction($hook, $params, $this);
......
$file = t3lib_div::resolveBackPath($file);
$file = t3lib_div::createVersionNumberedFilename($file);
$tag = '<link rel="' . htmlspecialchars($properties['rel']) . '" type="text/css" href="' .
htmlspecialchars($file) . '" media="' . htmlspecialchars($properties['media']) . '"' .
($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '') .
$endingSlash . '>';
htmlspecialchars($file) . '" media="' . htmlspecialchars($properties['media']) . '"' .
($properties['title'] ? ' title="' . htmlspecialchars($properties['title']) . '"' : '') .
$endingSlash . '>';
if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
$tag = str_replace('|', $tag, $properties['allWrap']);
}
......
$markerArray = array(
'XMLPROLOG_DOCTYPE' => $this->xmlPrologAndDocType,
'HTMLTAG' => $this->htmlTag,
'HTMLTAG' => $this->htmlTag,
'HEADTAG' => $this->headTag,
'HEADTAG' => $this->headTag,
'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
'METACHARSET' => $this->charSet ? str_replace('|', htmlspecialchars($this->charSet), $this->metaCharsetTag) : '',
'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
'INLINECOMMENT' => $this->inlineComments ? LF . LF . '<!-- ' . LF . implode(LF, $this->inlineComments) . '-->' . LF . LF : '',
'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
'BASEURL' => $this->baseUrl ? str_replace('|', $this->baseUrl, $this->baseUrlTag) : '',
'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
'SHORTCUT' => $this->favIcon ? sprintf($this->shortcutTag, htmlspecialchars($this->favIcon), $this->iconMimeType) : '',
'CSS_INCLUDE' => $cssFiles,
'CSS_INCLUDE' => $cssFiles,
'CSS_INLINE' => $cssInline,
'CSS_INLINE' => $cssInline,
'JS_INLINE' => $jsInline,
'JS_INLINE' => $jsInline,
'JS_INCLUDE' => $jsFiles,
'JS_INCLUDE' => $jsFiles,
'JS_LIBS' => $jsLibs,
'JS_LIBS' => $jsLibs,
'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
'TITLE' => $this->title ? str_replace('|', htmlspecialchars($this->title), $this->titleTag) : '',
'META' => $metaTags,
'META' => $metaTags,
'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
'HEADERDATA' => $this->headerData ? implode(LF, $this->headerData) : '',
'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
'FOOTERDATA' => $this->footerData ? implode(LF, $this->footerData) : '',
'JS_LIBS_FOOTER' => $jsFooterLibs,
'JS_LIBS_FOOTER' => $jsFooterLibs,
'JS_INCLUDE_FOOTER' => $jsFooterFiles,
'JS_INLINE_FOOTER' => $jsFooterInline,
'JS_INLINE_FOOTER' => $jsFooterInline,
'BODY' => $this->bodyContent,
'BODY' => $this->bodyContent,
);
$markerArray = array_map('trim', $markerArray);
......
$out = '';
if ($this->addSvg) {
$out .= '<script src="' . $this->processJsFile($this->backPath . $this->svgPath . 'svg.js') .
$out .= '<script src="' . $this->processJsFile($this->backPath . $this->svgPath . 'svg.js') .
'" data-path="' . $this->backPath . $this->svgPath .
'" data-path="' . $this->backPath . $this->svgPath .
'"' . ($this->enableSvgDebug ? ' data-debug="true"' : '') . '></script>';
'"' . ($this->enableSvgDebug ? ' data-debug="true"' : '') . '></script>';
}
if ($this->addPrototype) {
$out .= '<script src="' . $this->processJsFile($this->backPath . $this->prototypePath . 'prototype.js') .
$out .= '<script src="' . $this->processJsFile($this->backPath . $this->prototypePath . 'prototype.js') .
'" type="text/javascript"></script>' . LF;
'" type="text/javascript"></script>' . LF;
unset($this->jsFiles[$this->backPath . $this->prototypePath .'prototype.js']);
unset($this->jsFiles[$this->backPath . $this->prototypePath . 'prototype.js']);
}
if ($this->addScriptaculous) {
$mods = array ();
$mods = array();
foreach ($this->addScriptaculousModules as $key => $value) {
if ($this->addScriptaculousModules[$key]) {
$mods[] = $key;
......
if (count($mods)) {
foreach ($mods as $module) {
$out .= '<script src="' . $this->processJsFile($this->backPath .
$this->scriptaculousPath . $module . '.js') . '" type="text/javascript"></script>' . LF;
$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 . $this->scriptaculousPath .
'scriptaculous.js') . '" type="text/javascript"></script>' . LF;
'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 .
$this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
'" type="text/javascript"></script>' . LF;
$this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js') .
'" type="text/javascript"></script>' . LF;
unset($this->jsFiles[$this->backPath . $this->extCorePath . 'ext-core' . ($this->enableExtCoreDebug ? '-debug' : '') . '.js']);
}
......
if ($this->addExtJS) {
// use the base adapter all the time
$out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
'adapter/' . ($this->enableExtJsDebug ?
'adapter/' . ($this->enableExtJsDebug ?
str_replace('.js', '-debug.js', $this->extJSadapter) : $this->extJSadapter)) .
'" type="text/javascript"></script>' . LF;
'" type="text/javascript"></script>' . LF;
$out .= '<script src="' . $this->processJsFile($this->backPath . $this->extJsPath .
'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
'" type="text/javascript"></script>' . LF;
'ext-all' . ($this->enableExtJsDebug ? '-debug' : '') . '.js') .
'" type="text/javascript"></script>' . LF;
// add extJS localization
$localeMap = $this->csConvObj->isoArray; // load standard ISO mapping and modify for use with ExtJS
......
$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;
$extJsLocaleFile) . '" type="text/javascript" charset="utf-8"></script>' . LF;
}
// remove extjs from JScodeLibArray
unset(
$this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'],
$this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']
$this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all.js'],
$this->jsFiles[$this->backPath . $this->extJsPath . 'ext-all-debug.js']
);
}
......
$out .= $this->inlineJavascriptWrap[0] . '
Ext.ns("TYPO3");
Ext.BLANK_IMAGE_URL = "' . htmlspecialchars(t3lib_div::locationHeaderUrl($this->backPath . 'gfx/clear.gif')) . '";' . LF .
$inlineSettings .
'Ext.onReady(function() {' .
($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . LF : '') . $code .
' });' . $this->inlineJavascriptWrap[1];
$inlineSettings .
'Ext.onReady(function() {' .
($this->enableExtJSQuickTips ? 'Ext.QuickTips.init();' . LF : '') . $code .
' });' . $this->inlineJavascriptWrap[1];
unset ($this->extOnReadyCode);
if ($this->extJStheme) {
......
$this->inlineLanguageLabels = array_merge($this->inlineLanguageLabels, $labelsFromFile);
}
}
/*****************************************************/
/* */
/* Tools */
......
* @return void
*/
protected function doConcatenate() {
// traverse the arrays, concatenate in one file
// then remove concatenated files from array and add the concatenated file
// traverse the arrays, concatenate in one file
// then remove concatenated files from array and add the concatenated file
if ($this->concatenateFiles) {
$params = array (
$params = array(
'jsLibs' => &$this->jsLibs,
'jsLibs' => &$this->jsLibs,
'jsFiles' => &$this->jsFiles,
'jsFiles' => &$this->jsFiles,
'jsFooterFiles' => &$this->jsFooterFiles,
'jsFooterFiles' => &$this->jsFooterFiles,
'cssFiles' => &$this->cssFiles,
'cssFiles' => &$this->cssFiles,
'headerData' => &$this->headerData,
'headerData' => &$this->headerData,
'footerData' => &$this->footerData,
'footerData' => &$this->footerData,
);
if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler']) {
// use extern concatenate routine
// use extern concatenate routine
t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['concatenateHandler'], $params, $this);
} elseif (TYPO3_MODE === 'BE') {
$cssOptions = array('baseDirectories' => $GLOBALS['TBE_TEMPLATE']->getSkinStylesheetDirectories());
......
protected function doCompress() {
if ($this->compressJavascript && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler']) {
// use extern compress routine
// use extern compress routine
$params = array (
$params = array(
'jsInline' => &$this->jsInline,
'jsInline' => &$this->jsInline,
'jsFooterInline' => &$this->jsFooterInline,
'jsFooterInline' => &$this->jsFooterInline,
'jsLibs' => &$this->jsLibs,
'jsLibs' => &$this->jsLibs,
'jsFiles' => &$this->jsFiles,
'jsFiles' => &$this->jsFiles,
'jsFooterFiles' => &$this->jsFooterFiles,
'jsFooterFiles' => &$this->jsFooterFiles,
'headerData' => &$this->headerData,
'headerData' => &$this->headerData,
'footerData' => &$this->footerData,
'footerData' => &$this->footerData,
);
t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
} else {
......
}
if ($this->compressCss) {
// use extern compress routine
$params = array (
$params = array(
'cssInline' => &$this->cssInline,
'cssInline' => &$this->cssInline,
'cssFiles' => &$this->cssFiles,
'cssFiles' => &$this->cssFiles,
'headerData' => &$this->headerData,
'footerData' => &$this->footerData,
);
if ($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler']) {
// use extern concatenate routine
// use extern concatenate routine
t3lib_div::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
} elseif (TYPO3_MODE === 'BE') {
$this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
......
switch (TYPO3_MODE) {
case 'FE':
$filename = t3lib_div::createVersionNumberedFilename($filename);
break;
break;
case 'BE':
if ($this->compressJavascript) {
$filename = $this->getCompressor()->compressJsFile($filename);
}
break;
break;
}
return $filename;
}
......
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']);
}
?>
?>
(40-40/93)