mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
Corrected JS/CSS Cache minify.
This commit is contained in:
@@ -2851,7 +2851,7 @@ class e107
|
|||||||
{
|
{
|
||||||
if(empty($js))
|
if(empty($js))
|
||||||
{
|
{
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once(e_HANDLER."jsshrink/Minifier.php");
|
require_once(e_HANDLER."jsshrink/Minifier.php");
|
||||||
|
@@ -1387,8 +1387,9 @@ class e_jsmanager
|
|||||||
|
|
||||||
foreach($this->_cache_list[$type] as $k=>$path)
|
foreach($this->_cache_list[$type] as $k=>$path)
|
||||||
{
|
{
|
||||||
$content .= "\n\n/* File: ".str_replace("../",'',$path)." */\n";
|
$content .= "/* File: ".str_replace("../",'',$path)." */\n";
|
||||||
$content .= $this->getCacheFileContent($path, $type);
|
$content .= $this->getCacheFileContent($path, $type);
|
||||||
|
$content .= "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!@file_put_contents($saveFilePath, $content))
|
if(!@file_put_contents($saveFilePath, $content))
|
||||||
@@ -1429,22 +1430,22 @@ class e_jsmanager
|
|||||||
* @param $type string (js|css)
|
* @param $type string (js|css)
|
||||||
* @return mixed|string
|
* @return mixed|string
|
||||||
*/
|
*/
|
||||||
function getCacheFileContent($path, $type)
|
private function getCacheFileContent($path, $type)
|
||||||
{
|
{
|
||||||
$content = @file_get_contents($path);
|
$content = @file_get_contents($path);
|
||||||
|
|
||||||
if($type == 'js')
|
if($type == 'js')
|
||||||
{
|
{
|
||||||
// e107::minify() todo
|
return $this->compress($content, 'js');
|
||||||
return $this->compress($content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Correct relative paths in css files.
|
||||||
preg_match_all('/url\([\'"]?([^\'"\) ]*)[\'"]?\)/',$content, $match);
|
preg_match_all('/url\([\'"]?([^\'"\) ]*)[\'"]?\)/',$content, $match);
|
||||||
$newpath = array();
|
$newpath = array();
|
||||||
|
|
||||||
if(empty($match[0]))
|
if(empty($match[0]))
|
||||||
{
|
{
|
||||||
return $this->compress($content);
|
return $this->compress($content, 'css');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($match[1] as $k=>$v)
|
foreach($match[1] as $k=>$v)
|
||||||
@@ -1460,12 +1461,27 @@ class e_jsmanager
|
|||||||
}
|
}
|
||||||
|
|
||||||
$result = str_replace($match[0], $newpath, $content);
|
$result = str_replace($match[0], $newpath, $content);
|
||||||
return $this->compress($result);
|
|
||||||
|
return $this->compress($result, 'css');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function compress( $minify )
|
/**
|
||||||
|
* Minify JS/CSS for output
|
||||||
|
* @param string $minify
|
||||||
|
* @param string $type (js|css)
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function compress($minify, $type = 'js' )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if($type == 'js')
|
||||||
|
{
|
||||||
|
return e107::minify($minify);
|
||||||
|
}
|
||||||
|
|
||||||
|
// css
|
||||||
|
|
||||||
/* remove comments */
|
/* remove comments */
|
||||||
$minify = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $minify );
|
$minify = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $minify );
|
||||||
|
|
||||||
@@ -1476,7 +1492,12 @@ class e_jsmanager
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getCacheFileId($paths)
|
/**
|
||||||
|
* Generate a Cache-File ID from path list.
|
||||||
|
* @param array $paths
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getCacheFileId($paths)
|
||||||
{
|
{
|
||||||
$id = '';
|
$id = '';
|
||||||
foreach($paths as $p)
|
foreach($paths as $p)
|
||||||
|
Reference in New Issue
Block a user