[BUGFIX] concatenateJs/Css does not consider forceOnTop 72/27672/2
authorMarkus Klein <klein.t3@mfc-linz.at>
Sun, 16 Feb 2014 10:11:15 +0000 (11:11 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Thu, 20 Feb 2014 21:12:04 +0000 (22:12 +0100)
Setting the forceOnTop property for a JS or CSS file is not
observed if concatenateJs/Css is set as well.

Resolves: #53116
Resolves: #56019
Releases: 6.2, 6.1
Change-Id: Ica31656bd72f4a0249513206bac45aa16b929761
Reviewed-on: https://review.typo3.org/27672
Reviewed-by: Stefan Neufeind
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/core/Classes/Page/PageRenderer.php
typo3/sysext/core/Classes/Resource/ResourceCompressor.php

index ad07776..64758a5 100644 (file)
@@ -2274,10 +2274,11 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface {
                                if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
                                        $tag = str_replace('|', $tag, $properties['allWrap']);
                                }
+                               $tag .= LF;
                                if ($properties['forceOnTop']) {
-                                       $cssFiles = $tag . LF . $cssFiles;
+                                       $cssFiles = $tag . $cssFiles;
                                } else {
-                                       $cssFiles .= LF . $tag;
+                                       $cssFiles .= $tag;
                                }
                        }
                }
@@ -2293,10 +2294,11 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface {
                $cssInline = '';
                if (count($this->cssInline)) {
                        foreach ($this->cssInline as $name => $properties) {
+                               $cssCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
                                if ($properties['forceOnTop']) {
-                                       $cssInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $cssInline;
+                                       $cssInline = $cssCode . $cssInline;
                                } else {
-                                       $cssInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
+                                       $cssInline .= $cssCode;
                                }
                        }
                        $cssInline = $this->inlineCssWrap[0] . $cssInline . $this->inlineCssWrap[1];
@@ -2320,17 +2322,18 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface {
                                if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
                                        $tag = str_replace('|', $tag, $properties['allWrap']);
                                }
+                               $tag .= LF;
                                if ($properties['forceOnTop']) {
                                        if ($properties['section'] === self::PART_HEADER) {
-                                               $jsLibs = $tag . LF . $jsLibs;
+                                               $jsLibs = $tag . $jsLibs;
                                        } else {
-                                               $jsFooterLibs = $tag . LF . $jsFooterLibs;
+                                               $jsFooterLibs = $tag . $jsFooterLibs;
                                        }
                                } else {
                                        if ($properties['section'] === self::PART_HEADER) {
-                                               $jsLibs .= LF . $tag;
+                                               $jsLibs .= $tag;
                                        } else {
-                                               $jsFooterLibs .= LF . $tag;
+                                               $jsFooterLibs .= $tag;
                                        }
                                }
                        }
@@ -2358,23 +2361,24 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface {
                                if ($properties['allWrap'] && strpos($properties['allWrap'], '|') !== FALSE) {
                                        $tag = str_replace('|', $tag, $properties['allWrap']);
                                }
+                               $tag .= LF;
                                if ($properties['forceOnTop']) {
                                        if ($properties['section'] === self::PART_HEADER) {
-                                               $jsFiles = $tag . LF . $jsFiles;
+                                               $jsFiles = $tag . $jsFiles;
                                        } else {
-                                               $jsFooterFiles = $tag . LF . $jsFooterFiles;
+                                               $jsFooterFiles = $tag . $jsFooterFiles;
                                        }
                                } else {
                                        if ($properties['section'] === self::PART_HEADER) {
-                                               $jsFiles .= LF . $tag;
+                                               $jsFiles .= $tag;
                                        } else {
-                                               $jsFooterFiles .= LF . $tag;
+                                               $jsFooterFiles .= $tag;
                                        }
                                }
                        }
                }
                if ($this->moveJsFromHeaderToFooter) {
-                       $jsFooterFiles = $jsFiles . LF . $jsFooterFiles;
+                       $jsFooterFiles = $jsFiles . $jsFooterFiles;
                        $jsFiles = '';
                }
                return array($jsFiles, $jsFooterFiles);
@@ -2390,17 +2394,18 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface {
                $jsFooterInline = '';
                if (count($this->jsInline)) {
                        foreach ($this->jsInline as $name => $properties) {
+                               $jsCode = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
                                if ($properties['forceOnTop']) {
                                        if ($properties['section'] === self::PART_HEADER) {
-                                               $jsInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsInline;
+                                               $jsInline = $jsCode . $jsInline;
                                        } else {
-                                               $jsFooterInline = '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF . $jsFooterInline;
+                                               $jsFooterInline = $jsCode . $jsFooterInline;
                                        }
                                } else {
                                        if ($properties['section'] === self::PART_HEADER) {
-                                               $jsInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
+                                               $jsInline .= $jsCode;
                                        } else {
-                                               $jsFooterInline .= '/*' . htmlspecialchars($name) . '*/' . LF . $properties['code'] . LF;
+                                               $jsFooterInline .= $jsCode;
                                        }
                                }
                        }
@@ -2412,7 +2417,7 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface {
                        $jsFooterInline = $this->inlineJavascriptWrap[0] . $jsFooterInline . $this->inlineJavascriptWrap[1];
                }
                if ($this->moveJsFromHeaderToFooter) {
-                       $jsFooterInline = $jsInline . LF . $jsFooterInline;
+                       $jsFooterInline = $jsInline . $jsFooterInline;
                        $jsInline = '';
                }
                return array($jsInline, $jsFooterInline);
index 2a924b0..236e7aa 100644 (file)
@@ -188,19 +188,25 @@ class ResourceCompressor {
                        $filenameFromMainDir = $this->getFilenameFromMainDir($fileOptions['file']);
                        // if $options['baseDirectories'] set, we only include files below these directories
                        if ((!isset($options['baseDirectories']) || $this->checkBaseDirectory($filenameFromMainDir, array_merge($options['baseDirectories'], array($this->targetDirectory)))) && $fileOptions['media'] === 'all') {
-                               $filesToInclude[] = $filenameFromMainDir;
+                               if ($fileOptions['forceOnTop']) {
+                                       array_unshift($filesToInclude, $filenameFromMainDir);
+                               } else {
+                                       $filesToInclude[] = $filenameFromMainDir;
+                               }
                                // remove the file from the incoming file array
                                unset($cssFiles[$key]);
                        }
                }
-               if (count($filesToInclude)) {
+               if (!empty($filesToInclude)) {
                        $targetFile = $this->createMergedCssFile($filesToInclude);
                        $targetFileRelative = $this->relativePath . $targetFile;
                        $concatenatedOptions = array(
                                'file' => $targetFileRelative,
                                'rel' => 'stylesheet',
                                'media' => 'all',
-                               'compress' => TRUE
+                               'compress' => TRUE,
+                               'forceOnTop' => FALSE,
+                               'allWrap' => ''
                        );
                        // place the merged stylesheet on top of the stylesheets
                        $cssFiles = array_merge(array($targetFileRelative => $concatenatedOptions), $cssFiles);
@@ -222,7 +228,12 @@ class ResourceCompressor {
                                continue;
                        }
                        // we remove BACK_PATH from $filename, so make it relative to root path
-                       $filesToInclude[$fileOptions['section']][] = $this->getFilenameFromMainDir($fileOptions['file']);
+                       $filenameFromMainDir = $this->getFilenameFromMainDir($fileOptions['file']);
+                       if ($fileOptions['forceOnTop']) {
+                               array_unshift($filesToInclude[$fileOptions['section']], $filenameFromMainDir);
+                       } else {
+                               $filesToInclude[$fileOptions['section']][] = $filenameFromMainDir;
+                       }
                        // remove the file from the incoming file array
                        unset($jsFiles[$key]);
                }