[BUGFIX] t3lib_Compressor fails with external files
authorXavier Perseguers <xavier@typo3.org>
Mon, 12 Sep 2011 14:02:41 +0000 (16:02 +0200)
committerXavier Perseguers <xavier@typo3.org>
Thu, 15 Sep 2011 06:58:12 +0000 (08:58 +0200)
Externally-referenced files such as jQuery included from a CDN fail to be
concatenated or compressed.

Change-Id: Idd02d85c98811167cccafd2e6a6a96fefda6a936
Fixes: #29695
Releases: 4.6
Reviewed-on: http://review.typo3.org/4924
Reviewed-by: Björn Pedersen
Reviewed-by: Tolleiv Nietsch
Tested-by: Tolleiv Nietsch
Tested-by: Björn Pedersen
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
t3lib/class.t3lib_compressor.php

index a00435d..79a77eb 100644 (file)
@@ -286,7 +286,10 @@ class t3lib_Compressor {
                        // we add up the filenames, filemtimes and filsizes to later build a checksum over
                        // it and include it in the temporary file name
                $unique = '';
-               foreach ($filesToInclude as $filename) {
+               foreach ($filesToInclude as &$filename) {
+                       if (t3lib_div::isValidUrl($filename)) {
+                               $filename = $this->retrieveExternalFile($filename);
+                       }
                        $filepath = t3lib_div::resolveBackPath($this->rootPath . $filename);
                        $unique .= $filename . filemtime($filepath) . filesize($filepath);
                }
@@ -645,6 +648,19 @@ class t3lib_Compressor {
                }
        }
 
+       /**
+        * Retrieves an external file and stores it locally.
+        *
+        * @param string $url
+        * @return string Temporary local filename for the externally-retrieved file
+        */
+       protected function retrieveExternalFile($url) {
+               $externalContent = t3lib_div::getUrl($url);
+               $filename = $this->targetDirectory . 'external-' . md5($url);
+               t3lib_div::writeFile(PATH_site . $filename, $externalContent);
+               return $filename;
+       }
+
 }
 
 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_compressor.php'])) {