コード例 #1
0
ファイル: PageRegular.php プロジェクト: rikaix/core
 /**
  * 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;
 }
コード例 #2
0
ファイル: PageRegular.php プロジェクト: bytehead/contao-core
 /**
  * Create all header scripts
  *
  * @param \PageModel   $objPage
  * @param \LayoutModel $objLayout
  */
 protected function createHeaderScripts($objPage, $objLayout)
 {
     $strStyleSheets = '';
     $strCcStyleSheets = '';
     $arrStyleSheets = deserialize($objLayout->stylesheet);
     $blnXhtml = $objPage->outputFormat == 'xhtml';
     $arrFramework = deserialize($objLayout->framework);
     // Google web fonts
     if ($objLayout->webfonts != '') {
         $strStyleSheets .= \Template::generateStyleTag('//fonts.googleapis.com/css?family=' . str_replace('|', '%7C', $objLayout->webfonts), 'all', $blnXhtml) . "\n";
     }
     // Add the Contao CSS framework style sheets
     if (is_array($arrFramework)) {
         foreach ($arrFramework as $strFile) {
             if ($strFile != 'tinymce.css') {
                 $GLOBALS['TL_FRAMEWORK_CSS'][] = 'assets/contao/css/' . $strFile;
             }
         }
     }
     // Add the TinyMCE style sheet
     if (is_array($arrFramework) && in_array('tinymce.css', $arrFramework) && file_exists(TL_ROOT . '/' . \Config::get('uploadPath') . '/tinymce.css')) {
         $GLOBALS['TL_FRAMEWORK_CSS'][] = \Config::get('uploadPath') . '/tinymce.css';
     }
     // Make sure TL_USER_CSS is set
     if (!is_array($GLOBALS['TL_USER_CSS'])) {
         $GLOBALS['TL_USER_CSS'] = array();
     }
     // 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;
                 }
                 // Style sheets with a CC or a combination of font-face and media-type != all cannot be aggregated (see #5216)
                 if ($objStylesheets->cc || $objStylesheets->hasFontFace && $media != 'all') {
                     $strStyleSheet = '';
                     // External style sheet
                     if ($objStylesheets->type == 'external') {
                         $objFile = \FilesModel::findByPk($objStylesheets->singleSRC);
                         if ($objFile !== null) {
                             $strStyleSheet = \Template::generateStyleTag(TL_ASSETS_URL . $objFile->path, $media, $blnXhtml);
                         }
                     } else {
                         $strStyleSheet = \Template::generateStyleTag(TL_ASSETS_URL . 'assets/css/' . $objStylesheets->name . '.css', $media, $blnXhtml);
                     }
                     if ($objStylesheets->cc) {
                         $strStyleSheet = '<!--[' . $objStylesheets->cc . ']>' . $strStyleSheet . '<![endif]-->';
                     }
                     $strCcStyleSheets .= $strStyleSheet . "\n";
                 } else {
                     // External style sheet
                     if ($objStylesheets->type == 'external') {
                         $objFile = \FilesModel::findByPk($objStylesheets->singleSRC);
                         if ($objFile !== null) {
                             $GLOBALS['TL_USER_CSS'][] = $objFile->path . '|' . $media . '|static|' . filemtime(TL_ROOT . '/' . $objFile->path);
                         }
                     } else {
                         $GLOBALS['TL_USER_CSS'][] = 'assets/css/' . $objStylesheets->name . '.css|' . $media . '|static|' . max($objStylesheets->tstamp, $objStylesheets->tstamp2, $objStylesheets->tstamp3);
                     }
                 }
             }
         }
     }
     $arrExternal = deserialize($objLayout->external);
     // External style sheets
     if (!empty($arrExternal) && is_array($arrExternal)) {
         // Consider the sorting order (see #5038)
         if ($objLayout->orderExt != '') {
             $tmp = deserialize($objLayout->orderExt);
             if (!empty($tmp) && is_array($tmp)) {
                 // Remove all values
                 $arrOrder = array_map(function () {
                 }, array_flip($tmp));
                 // Move the matching elements to their position in $arrOrder
                 foreach ($arrExternal as $k => $v) {
                     if (array_key_exists($v, $arrOrder)) {
                         $arrOrder[$v] = $v;
                         unset($arrExternal[$k]);
                     }
                 }
                 // Append the left-over style sheets at the end
                 if (!empty($arrExternal)) {
                     $arrOrder = array_merge($arrOrder, array_values($arrExternal));
                 }
                 // Remove empty (unreplaced) entries
                 $arrExternal = array_values(array_filter($arrOrder));
                 unset($arrOrder);
             }
         }
         // Get the file entries from the database
         $objFiles = \FilesModel::findMultipleByUuids($arrExternal);
         if ($objFiles !== null) {
             $arrFiles = array();
             while ($objFiles->next()) {
                 if (file_exists(TL_ROOT . '/' . $objFiles->path)) {
                     $arrFiles[] = $objFiles->path . '|static';
                 }
             }
             // Inject the external style sheets before or after the internal ones (see #6937)
             if ($objLayout->loadingOrder == 'external_first') {
                 array_splice($GLOBALS['TL_USER_CSS'], 0, 0, $arrFiles);
             } else {
                 array_splice($GLOBALS['TL_USER_CSS'], count($GLOBALS['TL_USER_CSS']), 0, $arrFiles);
             }
         }
     }
     // Add a placeholder for dynamic style sheets (see #4203)
     $strStyleSheets .= '[[TL_CSS]]';
     // Add the debug style sheet
     if (\Config::get('debugMode')) {
         $strStyleSheets .= \Template::generateStyleTag($this->addStaticUrlTo('assets/contao/css/debug.css'), 'all', $blnXhtml) . "\n";
     }
     // Always add conditional style sheets at the end
     $strStyleSheets .= $strCcStyleSheets;
     $newsfeeds = deserialize($objLayout->newsfeeds);
     $calendarfeeds = deserialize($objLayout->calendarfeeds);
     // Add newsfeeds
     if (!empty($newsfeeds) && is_array($newsfeeds)) {
         $objFeeds = \NewsFeedModel::findByIds($newsfeeds);
         if ($objFeeds !== null) {
             while ($objFeeds->next()) {
                 $strStyleSheets .= \Template::generateFeedTag(($objFeeds->feedBase ?: \Environment::get('base')) . 'share/' . $objFeeds->alias . '.xml', $objFeeds->format, $objFeeds->title, $blnXhtml) . "\n";
             }
         }
     }
     // Add calendarfeeds
     if (!empty($calendarfeeds) && is_array($calendarfeeds)) {
         $objFeeds = \CalendarFeedModel::findByIds($calendarfeeds);
         if ($objFeeds !== null) {
             while ($objFeeds->next()) {
                 $strStyleSheets .= \Template::generateFeedTag(($objFeeds->feedBase ?: \Environment::get('base')) . 'share/' . $objFeeds->alias . '.xml', $objFeeds->format, $objFeeds->title, $blnXhtml) . "\n";
             }
         }
     }
     // Add a placeholder for dynamic <head> tags (see #4203)
     $strHeadTags = '[[TL_HEAD]]';
     // Add the user <head> tags
     if (($strHead = trim($objLayout->head)) != false) {
         $strHeadTags .= $strHead . "\n";
     }
     $this->Template->stylesheets = $strStyleSheets;
     $this->Template->head = $strHeadTags;
 }
コード例 #3
0
ファイル: PageRegular.php プロジェクト: rburch/core
 /**
  * Create all header scripts
  * @param object
  * @param object
  * @throws \Exception
  */
 protected function createHeaderScripts($objPage, $objLayout)
 {
     $strStyleSheets = '';
     $strCcStyleSheets = '';
     $arrStyleSheets = deserialize($objLayout->stylesheet);
     $blnXhtml = $objPage->outputFormat == 'xhtml';
     $strTagEnding = $blnXhtml ? ' />' : '>';
     $arrFramework = deserialize($objLayout->framework);
     // Google web fonts
     if ($objLayout->webfonts != '') {
         $protocol = \Environment::get('ssl') ? 'https://' : 'http://';
         $strStyleSheets .= '<link' . ($blnXhtml ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . $protocol . 'fonts.googleapis.com/css?family=' . $objLayout->webfonts . '"' . $strTagEnding . "\n";
     }
     // Add the Contao CSS framework style sheets
     if (is_array($arrFramework)) {
         foreach ($arrFramework as $strFile) {
             if ($strFile != 'tinymce.css') {
                 $GLOBALS['TL_FRAMEWORK_CSS'][] = 'assets/contao/css/' . $strFile;
             }
         }
     }
     // Add the TinyMCE style sheet
     if (is_array($arrFramework) && in_array('tinymce.css', $arrFramework) && file_exists(TL_ROOT . '/' . $GLOBALS['TL_CONFIG']['uploadPath'] . '/tinymce.css')) {
         $GLOBALS['TL_FRAMEWORK_CSS'][] = $GLOBALS['TL_CONFIG']['uploadPath'] . '/tinymce.css';
     }
     // 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) {
                     $GLOBALS['TL_USER_CSS'][] = 'assets/css/' . $objStylesheets->name . '.css|' . $media . '|static|' . max($objStylesheets->tstamp, $objStylesheets->tstamp2, $objStylesheets->tstamp3);
                 } else {
                     $strStyleSheet = '<link' . ($blnXhtml ? ' type="text/css"' : '') . ' rel="stylesheet" href="' . TL_ASSETS_URL . 'assets/css/' . $objStylesheets->name . '.css"' . ($media != '' && $media != 'all' ? ' 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)) {
         // Get the file entries from the database
         $objFiles = \FilesModel::findMultipleByIds($arrExternal);
         if ($objFiles !== null) {
             while ($objFiles->next()) {
                 if (file_exists(TL_ROOT . '/' . $objFiles->path)) {
                     $GLOBALS['TL_USER_CSS'][] = $objFiles->path . '||static';
                 }
             }
         }
     }
     // Add a placeholder for dynamic style sheets (see #4203)
     $strStyleSheets .= '[[TL_CSS]]';
     // Add the debug style sheet
     if ($GLOBALS['TL_CONFIG']['debugMode']) {
         $strStyleSheets .= '<link rel="stylesheet" href="' . $this->addStaticUrlTo('assets/contao/css/debug.css') . '"' . $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 = \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";
             }
         }
     }
     // Add a placeholder for dynamic <head> tags (see #4203)
     $strHeadTags = '[[TL_HEAD]]';
     // Add the user <head> tags
     if (($strHead = trim($objLayout->head)) != false) {
         $strHeadTags .= $strHead . "\n";
     }
     $this->Template->stylesheets = $strStyleSheets;
     $this->Template->head = $strHeadTags;
 }