public function generate(\PageModel $page, \LayoutModel $layout, \PageRegular $pageRegular) { $this->pageModel = $page; $this->layoutModel = $layout; $this->pageRegular = $pageRegular; // $arrFileIds = $this->filesCollector(); if (count($arrFileIds) > 0) { // fetch file path // contao 3.2 compability if (method_exists($this->FilesModel, 'findMultipleByUuids')) { $arrFiles = $this->FilesModel->findMultipleByUuids($arrFileIds); } else { $arrFiles = $this->FilesModel->findMultipleByIds($arrFileIds); } if (is_object($arrFiles) && $arrFiles->count() > 0) { $arrFilePaths = $arrFiles->fetchEach('path'); $combiner = new \Combiner(); foreach (array_unique($arrFilePaths) as $fileId => $filePath) { // compile & combine // todo: catch exceptions $fileData = $this->assetCompiler($filePath); $combiner->add($fileData[0], $fileData[1]); // filePath, version } // add to page $this->addAssetToPage($combiner->getCombinedFile()); } } }
/** * Modify the page or layout object - Add in Foundation JS and CSS first! * @param objPage * @param objPage * @return void */ public function run($objPage, &$objLayout, $objPageRegular) { //Load up our Required Foundation JS into a Combiner $objCombiner = new \Combiner(); foreach ($GLOBALS['FOUNDATION_JS'] as $strFile) { $objCombiner->add($strFile); } array_insert($GLOBALS['TL_JAVASCRIPT'], 0, array($objCombiner->getCombinedFile() . "|static")); //Load in Foundation CSS by Theme array_insert($GLOBALS['TL_CSS'], 0, array(SCSS::compile($objLayout->getRelated('pid')) . "|screen|static")); $objLayout->script .= "\n" . "<script>(function(\$) { \$(document).foundation(); })(jQuery);</script>"; }
/** * Get the combined file * * @return null|string */ public function getCombinedFile() { $assets = $this->getAssets(); if (empty($assets)) { return null; } $combiner = new \Combiner(); /** @var LocalAsset $asset */ foreach ($assets as $asset) { if (!$asset->isValid()) { continue; } $asset->setTemporaryFileExtension('css'); $combiner->add($asset->generate()); } if (!$combiner->hasEntries()) { return null; } return $combiner->getCombinedFile(); }
/** * Generate the content element */ protected function compile() { $this->Template->code = htmlspecialchars($this->code); // Syntax highlighter if ($this->highlight) { $arrMapper = array('AS3' => 'shBrushAS3', 'Bash' => 'shBrushBash', 'C' => 'shBrushCpp', 'CSharp' => 'shBrushCSharp', 'CSS' => 'shBrushCss', 'Delphi' => 'shBrushDelphi', 'Diff' => 'shBrushDiff', 'Groovy' => 'shBrushGroovy', 'Java' => 'shBrushJava', 'JavaFX' => 'shBrushJavaFX', 'JavaScript' => 'shBrushJScript', 'Perl' => 'shBrushPerl', 'PHP' => 'shBrushPhp', 'PowerShell' => 'shBrushPowerShell', 'Python' => 'shBrushPython', 'Ruby' => 'shBrushRuby', 'Scala' => 'shBrushScala', 'SQL' => 'shBrushSql', 'Text' => 'shBrushPlain', 'VB' => 'shBrushVb', 'XHTML' => 'shBrushXml', 'XML' => 'shBrushXml'); $this->Template->shClass = 'brush: ' . strtolower($this->highlight); if ($this->shClass) { $this->Template->shClass .= '; ' . $this->shClass; } // Add the style sheet $GLOBALS['TL_CSS'][] = 'plugins/highlighter/shCore.css'; // Add the core scripts $objCombiner = new Combiner(); $objCombiner->add('plugins/highlighter/XRegExp.js', HIGHLIGHTER); $objCombiner->add('plugins/highlighter/shCore.js', HIGHLIGHTER); $GLOBALS['TL_JAVASCRIPT'][] = $objCombiner->getCombinedFile(TL_PLUGINS_URL); // Add the brushes separately in case there are multiple code elements $GLOBALS['TL_JAVASCRIPT'][] = 'plugins/highlighter/' . $arrMapper[$this->highlight] . '.js'; global $objPage; // Initialization if ($objPage->outputFormat == 'xhtml') { $strInit = '<script type="text/javascript">' . "\n"; $strInit .= '/* <![CDATA[ */' . "\n"; } else { $strInit = '<script>' . "\n"; } $strInit .= 'SyntaxHighlighter.defaults.toolbar = false;' . "\n"; $strInit .= 'SyntaxHighlighter.all();' . "\n"; if ($objPage->outputFormat == 'xhtml') { $strInit .= '/* ]]> */' . "\n"; } $strInit .= '</script>'; // Add the initialization script to the head section and not (!) to TL_JAVASCRIPT $GLOBALS['TL_HEAD'][] = $strInit; } }
/** * add tree to the output * * @param string $strTable * @param string $strTreeClass javascript class * @param string $strFile file * @param array|null $arrOptions * * @throws \Exception */ protected function addTree($strTable, $strTreeClass, $strFile = null, $arrOptions = null) { if (!isset($this->arrScripts['tree'])) { $this->objCombiner->add('system/modules/be_improved_theme/assets/BackendImprovedSearchWidget.js', $this->intDebug); $this->objCombiner->add('system/modules/be_improved_theme/assets/BackendImprovedTree.js', $this->intDebug); } $arrOptions['table'] = $strTable; $arrOptions['storagePrefix'] = $GLOBALS['TL_CONFIG']['websitePath']; if (!isset($arrOptions['toggleIcon'])) { // contao 2.11 support if (isset($GLOBALS['TL_LANG']['MSC']['toggleAll'])) { $arrOptions['toggleIcon'] =& $GLOBALS['TL_LANG']['MSC']['toggleAll']; } else { $arrOptions['toggleIcon'] = array($GLOBALS['TL_LANG']['MSC']['toggleNodes']); } } $this->objCombiner->add($strFile != null ? $strFile : 'system/modules/be_improved_theme/assets/' . $strTreeClass . '.js', $this->intDebug); $this->arrScripts['tree'] .= 'var ' . $strTable . 'Tree = new ' . $strTreeClass . '(' . json_encode($arrOptions) . ');' . "\r\n"; }
/** * Create all header scripts * @param Database_Result * @param Database_Result */ protected function createHeaderScripts(Database_Result $objPage, Database_Result $objLayout) { $strStyleSheets = ''; $strCcStyleSheets = ''; $arrStyleSheets = deserialize($objLayout->stylesheet); $strTagEnding = ($objPage->outputFormat == 'xhtml') ? ' />' : '>'; // Google web fonts if ($objLayout->webfonts != '') { $protocol = $this->Environment->ssl ? 'https://' : 'http://'; $strStyleSheets .= '<link' . (($objPage->outputFormat == 'xhtml') ? ' type="text/css"' : '') .' rel="stylesheet" href="' . $protocol . 'fonts.googleapis.com/css?family=' . $objLayout->webfonts . '"' . $strTagEnding . "\n"; } $objCombiner = new Combiner(); // Skip the Contao framework style sheet if (!$objLayout->skipFramework) { $objCombiner->add('system/contao.css'); } // Skip the TinyMCE style sheet if (!$objLayout->skipTinymce && file_exists(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/tinymce.css')) { $objCombiner->add($GLOBALS['TL_CONFIG']['uploadPath'] . '/tinymce.css', filemtime(TL_ROOT .'/'. $GLOBALS['TL_CONFIG']['uploadPath'] . '/tinymce.css'), 'all'); } // Internal style sheets if (is_array($GLOBALS['TL_CSS']) && !empty($GLOBALS['TL_CSS'])) { foreach (array_unique($GLOBALS['TL_CSS']) as $stylesheet) { list($stylesheet, $media, $mode) = explode('|', $stylesheet); if ($mode == 'static') { $objCombiner->add($stylesheet, filemtime(TL_ROOT . '/' . $stylesheet), $media); } else { $strStyleSheets .= '<link' . (($objPage->outputFormat == 'xhtml') ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . $this->addStaticUrlTo($stylesheet) . '" media="' . (($media != '') ? $media : 'all') . '"' . $strTagEnding . "\n"; } } } // User style sheets if (is_array($arrStyleSheets) && strlen($arrStyleSheets[0])) { $objStylesheets = $this->Database->execute("SELECT *, (SELECT MAX(tstamp) FROM tl_style WHERE tl_style.pid=tl_style_sheet.id) AS tstamp2, (SELECT COUNT(*) FROM tl_style WHERE tl_style.selector='@font-face' AND tl_style.pid=tl_style_sheet.id) AS hasFontFace FROM tl_style_sheet WHERE id IN (" . implode(', ', $arrStyleSheets) . ") ORDER BY FIELD(id, " . implode(', ', $arrStyleSheets) . ")"); while ($objStylesheets->next()) { $media = implode(',', deserialize($objStylesheets->media)); // Overwrite the media type with a custom media query if ($objStylesheets->mediaQuery != '') { $media = $objStylesheets->mediaQuery; } // Aggregate regular style sheets if (!$objStylesheets->cc && !$objStylesheets->hasFontFace) { $objCombiner->add('system/scripts/' . $objStylesheets->name . '.css', max($objStylesheets->tstamp, $objStylesheets->tstamp2), $media); } else { $strStyleSheet = '<link' . (($objPage->outputFormat == 'xhtml') ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . TL_SCRIPT_URL . 'system/scripts/' . $objStylesheets->name . '.css" media="' . $media . '"' . $strTagEnding; if ($objStylesheets->cc) { $strStyleSheet = '<!--[' . $objStylesheets->cc . ']>' . $strStyleSheet . '<![endif]-->'; } $strCcStyleSheets .= $strStyleSheet . "\n"; } } } // Create the aggregated style sheet if ($objCombiner->hasEntries()) { $strStyleSheets .= '<link' . (($objPage->outputFormat == 'xhtml') ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . $objCombiner->getCombinedFile() . '" media="all"' . $strTagEnding . "\n"; } // Always add conditional style sheets at the end $strStyleSheets .= $strCcStyleSheets; $newsfeeds = deserialize($objLayout->newsfeeds); $calendarfeeds = deserialize($objLayout->calendarfeeds); // Add newsfeeds if (is_array($newsfeeds) && !empty($newsfeeds)) { $objFeeds = $this->Database->execute("SELECT * FROM tl_news_archive WHERE makeFeed=1 AND id IN(" . implode(',', array_map('intval', $newsfeeds)) . ")"); while($objFeeds->next()) { $base = strlen($objFeeds->feedBase) ? $objFeeds->feedBase : $this->Environment->base; $strStyleSheets .= '<link rel="alternate" href="' . $base . $objFeeds->alias . '.xml" type="application/' . $objFeeds->format . '+xml" title="' . $objFeeds->title . '"' . $strTagEnding . "\n"; } } // Add calendarfeeds if (is_array($calendarfeeds) && !empty($calendarfeeds)) { $objFeeds = $this->Database->execute("SELECT * FROM tl_calendar WHERE makeFeed=1 AND id IN(" . implode(',', array_map('intval', $calendarfeeds)) . ")"); while($objFeeds->next()) { $base = strlen($objFeeds->feedBase) ? $objFeeds->feedBase : $this->Environment->base; $strStyleSheets .= '<link rel="alternate" href="' . $base . $objFeeds->alias . '.xml" type="application/' . $objFeeds->format . '+xml" title="' . $objFeeds->title . '"' . $strTagEnding . "\n"; } } $strHeadTags = ''; // Add internal scripts if (is_array($GLOBALS['TL_JAVASCRIPT']) && !empty($GLOBALS['TL_JAVASCRIPT'])) { foreach (array_unique($GLOBALS['TL_JAVASCRIPT']) as $javascript) { $strHeadTags .= '<script' . (($objPage->outputFormat == 'xhtml') ? ' type="text/javascript"' : '') . ' src="' . $this->addStaticUrlTo($javascript) . '"></script>' . "\n"; } } // Add internal <head> tags if (is_array($GLOBALS['TL_HEAD']) && !empty($GLOBALS['TL_HEAD'])) { foreach (array_unique($GLOBALS['TL_HEAD']) as $head) { $strHeadTags .= trim($head) . "\n"; } } // Add user <head> tags if (($strHead = trim($objLayout->head)) != false) { $strHeadTags .= $strHead . "\n"; } $this->Template->stylesheets = $strStyleSheets; $this->Template->head = $strHeadTags; }
/** * Replace the dynamic script tags (see #4203) * * @param string $strBuffer The string with the tags to be replaced * * @return string The string with the replaced tags */ public static function replaceDynamicScriptTags($strBuffer) { // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['replaceDynamicScriptTags']) && is_array($GLOBALS['TL_HOOKS']['replaceDynamicScriptTags'])) { foreach ($GLOBALS['TL_HOOKS']['replaceDynamicScriptTags'] as $callback) { $strBuffer = static::importStatic($callback[0])->{$callback[1]}($strBuffer); } } /** @var \PageModel $objPage */ global $objPage; $arrReplace = array(); $blnXhtml = $objPage->outputFormat == 'xhtml'; $strScripts = ''; // Add the internal jQuery scripts if (!empty($GLOBALS['TL_JQUERY']) && is_array($GLOBALS['TL_JQUERY'])) { foreach (array_unique($GLOBALS['TL_JQUERY']) as $script) { $strScripts .= "\n" . trim($script) . "\n"; } } $arrReplace['[[TL_JQUERY]]'] = $strScripts; $strScripts = ''; // Add the internal MooTools scripts if (!empty($GLOBALS['TL_MOOTOOLS']) && is_array($GLOBALS['TL_MOOTOOLS'])) { foreach (array_unique($GLOBALS['TL_MOOTOOLS']) as $script) { $strScripts .= "\n" . trim($script) . "\n"; } } $arrReplace['[[TL_MOOTOOLS]]'] = $strScripts; $strScripts = ''; // Add the internal <body> tags if (!empty($GLOBALS['TL_BODY']) && is_array($GLOBALS['TL_BODY'])) { foreach (array_unique($GLOBALS['TL_BODY']) as $script) { $strScripts .= trim($script) . "\n"; } } // Add the syntax highlighter scripts if (!empty($GLOBALS['TL_HIGHLIGHTER']) && is_array($GLOBALS['TL_HIGHLIGHTER'])) { $objCombiner = new \Combiner(); foreach (array_unique($GLOBALS['TL_HIGHLIGHTER']) as $script) { $objCombiner->add($script); } $strScripts .= "\n" . \Template::generateScriptTag($objCombiner->getCombinedFile(), $blnXhtml); $strScripts .= "\n" . \Template::generateInlineScript('SyntaxHighlighter.defaults.toolbar=false;SyntaxHighlighter.all()', $blnXhtml) . "\n"; } // Command scheduler if (!\Config::get('disableCron')) { $strScripts .= "\n" . \Template::generateInlineScript('setTimeout(function(){var e=function(e,t){try{var n=new XMLHttpRequest}catch(r){return}n.open("GET",e,!0),n.onreadystatechange=function(){this.readyState==4&&this.status==200&&typeof t=="function"&&t(this.responseText)},n.send()},t="system/cron/cron.";e(t+"txt",function(n){parseInt(n||0)<Math.round(+(new Date)/1e3)-' . \Frontend::getCronTimeout() . '&&e(t+"php")})},5e3);', $blnXhtml) . "\n"; } $arrReplace['[[TL_BODY]]'] = $strScripts; $strScripts = ''; $objCombiner = new \Combiner(); // Add the CSS framework style sheets if (!empty($GLOBALS['TL_FRAMEWORK_CSS']) && is_array($GLOBALS['TL_FRAMEWORK_CSS'])) { foreach (array_unique($GLOBALS['TL_FRAMEWORK_CSS']) as $stylesheet) { $objCombiner->add($stylesheet); } } // Add the internal style sheets if (!empty($GLOBALS['TL_CSS']) && is_array($GLOBALS['TL_CSS'])) { foreach (array_unique($GLOBALS['TL_CSS']) as $stylesheet) { $options = \StringUtil::resolveFlaggedUrl($stylesheet); if ($options->static) { if ($options->mtime === null) { $options->mtime = filemtime(TL_ROOT . '/' . $stylesheet); } $objCombiner->add($stylesheet, $options->mtime, $options->media); } else { $strScripts .= \Template::generateStyleTag(static::addStaticUrlTo($stylesheet), $options->media, $blnXhtml) . "\n"; } } } // Add the user style sheets if (!empty($GLOBALS['TL_USER_CSS']) && is_array($GLOBALS['TL_USER_CSS'])) { foreach (array_unique($GLOBALS['TL_USER_CSS']) as $stylesheet) { $options = \StringUtil::resolveFlaggedUrl($stylesheet); if ($options->static) { if ($options->mtime === null) { $options->mtime = filemtime(TL_ROOT . '/' . $stylesheet); } $objCombiner->add($stylesheet, $options->mtime, $options->media); } else { $strScripts .= \Template::generateStyleTag(static::addStaticUrlTo($stylesheet), $options->media, $blnXhtml) . "\n"; } } } // Create the aggregated style sheet if ($objCombiner->hasEntries()) { $strScripts .= \Template::generateStyleTag($objCombiner->getCombinedFile(), 'all', $blnXhtml) . "\n"; } $arrReplace['[[TL_CSS]]'] = $strScripts; $strScripts = ''; // Add the internal scripts if (!empty($GLOBALS['TL_JAVASCRIPT']) && is_array($GLOBALS['TL_JAVASCRIPT'])) { $objCombiner = new \Combiner(); $objCombinerAsync = new \Combiner(); foreach (array_unique($GLOBALS['TL_JAVASCRIPT']) as $javascript) { $options = \StringUtil::resolveFlaggedUrl($javascript); if ($options->static) { if ($options->mtime === null) { $options->mtime = filemtime(TL_ROOT . '/' . $javascript); } $options->async ? $objCombinerAsync->add($javascript, $options->mtime) : $objCombiner->add($javascript, $options->mtime); } else { $strScripts .= \Template::generateScriptTag(static::addStaticUrlTo($javascript), $blnXhtml, $options->async) . "\n"; } } // Create the aggregated script and add it before the non-static scripts (see #4890) if ($objCombiner->hasEntries()) { $strScripts = \Template::generateScriptTag($objCombiner->getCombinedFile(), $blnXhtml) . "\n" . $strScripts; } if ($objCombinerAsync->hasEntries()) { $strScripts = \Template::generateScriptTag($objCombinerAsync->getCombinedFile(), $blnXhtml, true) . "\n" . $strScripts; } } // Add the internal <head> tags if (!empty($GLOBALS['TL_HEAD']) && is_array($GLOBALS['TL_HEAD'])) { foreach (array_unique($GLOBALS['TL_HEAD']) as $head) { $strScripts .= trim($head) . "\n"; } } $arrReplace['[[TL_HEAD]]'] = $strScripts; return str_replace(array_keys($arrReplace), array_values($arrReplace), $strBuffer); }
/** * Create all header scripts * @param object * @param object * @throws \Exception */ protected function createHeaderScripts($objPage, $objLayout) { $strStyleSheets = ''; $strCcStyleSheets = ''; $arrStyleSheets = deserialize($objLayout->stylesheet); $strTagEnding = $objPage->outputFormat == 'xhtml' ? ' />' : '>'; // Google web fonts if ($objLayout->webfonts != '') { $protocol = \Environment::get('ssl') ? 'https://' : 'http://'; $strStyleSheets .= '<link' . ($objPage->outputFormat == 'xhtml' ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . $protocol . 'fonts.googleapis.com/css?family=' . $objLayout->webfonts . '"' . $strTagEnding . "\n"; } $objCombiner = new \Combiner(); // Skip the Contao framework style sheet if (!$objLayout->skipFramework) { $objCombiner->add('assets/contao/framework.css'); } // Skip the TinyMCE style sheet if (!$objLayout->skipTinymce && file_exists(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/tinymce.css')) { $objCombiner->add($GLOBALS['TL_CONFIG']['uploadPath'] . '/tinymce.css', filemtime(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/tinymce.css'), 'all'); } // Internal style sheets if (is_array($GLOBALS['TL_CSS']) && !empty($GLOBALS['TL_CSS'])) { foreach (array_unique($GLOBALS['TL_CSS']) as $stylesheet) { list($stylesheet, $media, $mode) = explode('|', $stylesheet); if ($mode == 'static') { $objCombiner->add($stylesheet, filemtime(TL_ROOT . '/' . $stylesheet), $media); } else { $strStyleSheets .= '<link' . ($objPage->outputFormat == 'xhtml' ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . $this->addStaticUrlTo($stylesheet) . '" media="' . ($media ?: 'all') . '"' . $strTagEnding . "\n"; } } } // User style sheets if (is_array($arrStyleSheets) && strlen($arrStyleSheets[0])) { $objStylesheets = \StyleSheetModel::findByIds($arrStyleSheets); if ($objStylesheets !== null) { while ($objStylesheets->next()) { $media = implode(',', deserialize($objStylesheets->media)); // Overwrite the media type with a custom media query if ($objStylesheets->mediaQuery != '') { $media = $objStylesheets->mediaQuery; } // Aggregate regular style sheets if (!$objStylesheets->cc && !$objStylesheets->hasFontFace) { $objCombiner->add('assets/css/' . $objStylesheets->name . '.css', max($objStylesheets->tstamp, $objStylesheets->tstamp2), $media); } else { $strStyleSheet = '<link' . ($objPage->outputFormat == 'xhtml' ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . TL_SCRIPT_URL . 'css/' . $objStylesheets->name . '.css" media="' . $media . '"' . $strTagEnding; if ($objStylesheets->cc) { $strStyleSheet = '<!--[' . $objStylesheets->cc . ']>' . $strStyleSheet . '<![endif]-->'; } $strCcStyleSheets .= $strStyleSheet . "\n"; } } } } $arrExternal = deserialize($objLayout->external); // External style sheets if (is_array($arrExternal) && !empty($arrExternal)) { foreach (array_unique($arrExternal) as $stylesheet) { if ($stylesheet == '') { continue; } // Validate the file name if (strpos($stylesheet, '..') !== false || strncmp($stylesheet, $GLOBALS['TL_CONFIG']['uploadPath'] . '/', strlen($GLOBALS['TL_CONFIG']['uploadPath']) + 1) !== 0) { throw new \Exception("Invalid path {$stylesheet}"); } list($stylesheet, $media, $mode) = explode('|', $stylesheet); // Only .css files are allowed if (substr($stylesheet, -4) != '.css') { throw new \Exception("Invalid file extension {$stylesheet}"); } // Check whether the file exists if (!file_exists(TL_ROOT . '/' . $stylesheet)) { continue; } // Include the file if ($mode == 'static') { $objCombiner->add($stylesheet, filemtime(TL_ROOT . '/' . $stylesheet), $media); } else { $strStyleSheets .= '<link' . ($objPage->outputFormat == 'xhtml' ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . $this->addStaticUrlTo($stylesheet) . '" media="' . ($media ?: 'all') . '"' . $strTagEnding . "\n"; } } } // Create the aggregated style sheet if ($objCombiner->hasEntries()) { $strStyleSheets .= '<link' . ($objPage->outputFormat == 'xhtml' ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . $objCombiner->getCombinedFile() . '" media="all"' . $strTagEnding . "\n"; } // Add the debug style sheet if ($GLOBALS['TL_CONFIG']['debugMode']) { $strStyleSheets .= '<link rel="stylesheet" href="' . $this->addStaticUrlTo('assets/contao/debug.css') . '" media="all">' . "\n"; } // Always add conditional style sheets at the end $strStyleSheets .= $strCcStyleSheets; $newsfeeds = deserialize($objLayout->newsfeeds); $calendarfeeds = deserialize($objLayout->calendarfeeds); // Add newsfeeds if (is_array($newsfeeds) && !empty($newsfeeds)) { $objFeeds = \NewsFeedModel::findByIds($newsfeeds); if ($objFeeds !== null) { while ($objFeeds->next()) { $base = $objFeeds->feedBase ?: \Environment::get('base'); $strStyleSheets .= '<link rel="alternate" href="' . $base . 'share/' . $objFeeds->alias . '.xml" type="application/' . $objFeeds->format . '+xml" title="' . $objFeeds->title . '"' . $strTagEnding . "\n"; } } } // Add calendarfeeds if (is_array($calendarfeeds) && !empty($calendarfeeds)) { $objFeeds = \CalendarFeedModel::findByIds($calendarfeeds); if ($objFeeds !== null) { while ($objFeeds->next()) { $base = $objFeeds->feedBase ?: \Environment::get('base'); $strStyleSheets .= '<link rel="alternate" href="' . $base . 'share/' . $objFeeds->alias . '.xml" type="application/' . $objFeeds->format . '+xml" title="' . $objFeeds->title . '"' . $strTagEnding . "\n"; } } } $strHeadTags = ''; // Add internal scripts if (is_array($GLOBALS['TL_JAVASCRIPT']) && !empty($GLOBALS['TL_JAVASCRIPT'])) { foreach (array_unique($GLOBALS['TL_JAVASCRIPT']) as $javascript) { $strHeadTags .= '<script' . ($objPage->outputFormat == 'xhtml' ? ' type="text/javascript"' : '') . ' src="' . $this->addStaticUrlTo($javascript) . '"></script>' . "\n"; } } // Add internal <head> tags if (is_array($GLOBALS['TL_HEAD']) && !empty($GLOBALS['TL_HEAD'])) { foreach (array_unique($GLOBALS['TL_HEAD']) as $head) { $strHeadTags .= trim($head) . "\n"; } } // Add user <head> tags if (($strHead = trim($objLayout->head)) != false) { $strHeadTags .= $strHead . "\n"; } $this->Template->stylesheets = $strStyleSheets; $this->Template->head = $strHeadTags; }
/** * Replace the dynamic script tags (see #4203) * * @param string $strBuffer The string with the tags to be replaced * * @return string The string with the replaced tags */ public static function replaceDynamicScriptTags($strBuffer) { // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['replaceDynamicScriptTags']) && is_array($GLOBALS['TL_HOOKS']['replaceDynamicScriptTags'])) { foreach ($GLOBALS['TL_HOOKS']['replaceDynamicScriptTags'] as $callback) { $strBuffer = static::importStatic($callback[0])->{$callback}[1]($strBuffer); } } global $objPage; $arrReplace = array(); $blnXhtml = $objPage->outputFormat == 'xhtml'; $strTagEnding = $blnXhtml ? ' />' : '>'; $strScripts = ''; // Add the internal jQuery scripts if (is_array($GLOBALS['TL_JQUERY']) && !empty($GLOBALS['TL_JQUERY'])) { foreach (array_unique($GLOBALS['TL_JQUERY']) as $script) { $strScripts .= "\n" . trim($script) . "\n"; } } $arrReplace['[[TL_JQUERY]]'] = $strScripts; $strScripts = ''; // Add the internal MooTools scripts if (is_array($GLOBALS['TL_MOOTOOLS']) && !empty($GLOBALS['TL_MOOTOOLS'])) { foreach (array_unique($GLOBALS['TL_MOOTOOLS']) as $script) { $strScripts .= "\n" . trim($script) . "\n"; } } $arrReplace['[[TL_MOOTOOLS]]'] = $strScripts; $strScripts = ''; // Add the syntax highlighter scripts if (is_array($GLOBALS['TL_HIGHLIGHTER']) && !empty($GLOBALS['TL_HIGHLIGHTER'])) { $objCombiner = new \Combiner(); foreach (array_unique($GLOBALS['TL_HIGHLIGHTER']) as $script) { $objCombiner->add($script); } $strScripts .= "\n" . '<script' . ($blnXhtml ? ' type="text/javascript"' : '') . ' src="' . $objCombiner->getCombinedFile() . '"></script>'; if ($blnXhtml) { $strScripts .= "\n" . '<script type="text/javascript">' . "\n/* <![CDATA[ */\n" . 'SyntaxHighlighter.defaults.toolbar=false;SyntaxHighlighter.all()' . "\n/* ]]> */\n" . '</script>' . "\n"; } else { $strScripts .= "\n" . '<script>SyntaxHighlighter.defaults.toolbar=false;SyntaxHighlighter.all()</script>' . "\n"; } } $arrReplace['[[TL_HIGHLIGHTER]]'] = $strScripts; $strScripts = ''; $objCombiner = new \Combiner(); // Add the CSS framework style sheets if (is_array($GLOBALS['TL_FRAMEWORK_CSS']) && !empty($GLOBALS['TL_FRAMEWORK_CSS'])) { foreach (array_unique($GLOBALS['TL_FRAMEWORK_CSS']) as $stylesheet) { $objCombiner->add($stylesheet); } } // Add the internal style sheets if (is_array($GLOBALS['TL_CSS']) && !empty($GLOBALS['TL_CSS'])) { foreach (array_unique($GLOBALS['TL_CSS']) as $stylesheet) { list($stylesheet, $media, $mode) = explode('|', $stylesheet); if ($mode == 'static') { $objCombiner->add($stylesheet, filemtime(TL_ROOT . '/' . $stylesheet), $media); } else { $strScripts .= '<link' . ($blnXhtml ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . static::addStaticUrlTo($stylesheet) . '"' . ($media != '' && $media != 'all' ? ' media="' . $media . '"' : '') . $strTagEnding . "\n"; } } } // Add the user style sheets if (is_array($GLOBALS['TL_USER_CSS']) && !empty($GLOBALS['TL_USER_CSS'])) { foreach (array_unique($GLOBALS['TL_USER_CSS']) as $stylesheet) { list($stylesheet, $media, $mode, $version) = explode('|', $stylesheet); if (!$version) { $version = filemtime(TL_ROOT . '/' . $stylesheet); } if ($mode == 'static') { $objCombiner->add($stylesheet, $version, $media); } else { $strScripts .= '<link' . ($blnXhtml ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . static::addStaticUrlTo($stylesheet) . '"' . ($media != '' && $media != 'all' ? ' media="' . $media . '"' : '') . $strTagEnding . "\n"; } } } // Create the aggregated style sheet if ($objCombiner->hasEntries()) { $strScripts .= '<link' . ($blnXhtml ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . $objCombiner->getCombinedFile() . '"' . $strTagEnding . "\n"; } $arrReplace['[[TL_CSS]]'] = $strScripts; $strScripts = ''; // Add the internal scripts if (is_array($GLOBALS['TL_JAVASCRIPT']) && !empty($GLOBALS['TL_JAVASCRIPT'])) { $objCombiner = new \Combiner(); foreach (array_unique($GLOBALS['TL_JAVASCRIPT']) as $javascript) { list($javascript, $mode) = explode('|', $javascript); if ($mode == 'static') { $objCombiner->add($javascript, filemtime(TL_ROOT . '/' . $javascript)); } else { $strScripts .= '<script' . ($blnXhtml ? ' type="text/javascript"' : '') . ' src="' . static::addStaticUrlTo($javascript) . '"></script>' . "\n"; } } // Create the aggregated script and add it before the non-static scripts (see #4890) if ($objCombiner->hasEntries()) { $strScripts = '<script' . ($blnXhtml ? ' type="text/javascript"' : '') . ' src="' . $objCombiner->getCombinedFile() . '"></script>' . "\n" . $strScripts; } } // Add the internal <head> tags if (is_array($GLOBALS['TL_HEAD']) && !empty($GLOBALS['TL_HEAD'])) { foreach (array_unique($GLOBALS['TL_HEAD']) as $head) { $strScripts .= trim($head) . "\n"; } } $arrReplace['[[TL_HEAD]]'] = $strScripts; return str_replace(array_keys($arrReplace), array_values($arrReplace), $strBuffer); }
/** * Combine the single given file, and save it to the cache * * @param $id string The id to save the new file as * @param $file string The file to combine or array of files to combine * @param $output bool (optional) default TRUE When set to TRUE, outputs the resulted combined file */ private function CombineFiles($id, &$file, $output = TRUE) { $combiner = new Combiner($this->sourceFolder, $file, $this->minify); $result = $combiner->GetResult(); if ($this->encoding != 'none') { $result = gzencode($result, 9, $this->encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); } if ($output) { $this->output->SetContent($result); } $this->cache->Save($id, $result); }