mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 14:17:49 +02:00
Fixes for JS/CSS Cache. Correct file-count displayed in admin. minify code on output.
This commit is contained in:
@@ -91,7 +91,8 @@ if (isset($_POST['trigger_empty_cache']))
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'empty_jscss':
|
case 'empty_jscss':
|
||||||
e107::getCache()->clearAll('jscss');
|
e107::getCache()->clearAll('js');
|
||||||
|
e107::getCache()->clearAll('css');
|
||||||
// e107::getAdminLog()->flushMessages(CACLAN_5);
|
// e107::getAdminLog()->flushMessages(CACLAN_5);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -111,7 +112,7 @@ $syscache_files = glob(e_CACHE_CONTENT.'S_*.*');
|
|||||||
$cache_files = glob(e_CACHE_CONTENT.'C_*.*');
|
$cache_files = glob(e_CACHE_CONTENT.'C_*.*');
|
||||||
$imgcache_files = glob(e_CACHE_IMAGE.'*.cache.bin');
|
$imgcache_files = glob(e_CACHE_IMAGE.'*.cache.bin');
|
||||||
$dbcache_files = glob(e_CACHE_DB.'*.php');
|
$dbcache_files = glob(e_CACHE_DB.'*.php');
|
||||||
$jscsscache_files = glob(e_WEB.'cache/*.*');
|
$jscsscache_files = glob(e_WEB.'cache/*.{css,js}',GLOB_BRACE);
|
||||||
|
|
||||||
$syscache_files_num = count($syscache_files);
|
$syscache_files_num = count($syscache_files);
|
||||||
$cache_files_num = count($cache_files);
|
$cache_files_num = count($cache_files);
|
||||||
|
@@ -326,10 +326,16 @@ class ecache {
|
|||||||
$mask = ($mask == null) ? '.*\.cache\.bin' : $mask;
|
$mask = ($mask == null) ? '.*\.cache\.bin' : $mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($type == 'jscss')
|
if($type == 'js')
|
||||||
{
|
{
|
||||||
$path = e_WEB."cache/";
|
$path = e_WEB."cache/";
|
||||||
$mask = ($mask == null) ? '.*(\.js|\.css)$' : $mask;
|
$mask = ($mask == null) ? '.*\.js' : $mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($type == 'css')
|
||||||
|
{
|
||||||
|
$path = e_WEB."cache/";
|
||||||
|
$mask = ($mask == null) ? '.*\.css' : $mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((null == $path) || (null == $mask))
|
if((null == $path) || (null == $mask))
|
||||||
|
@@ -1349,13 +1349,11 @@ class e_jsmanager
|
|||||||
*/
|
*/
|
||||||
private function addCache($type,$path)
|
private function addCache($type,$path)
|
||||||
{
|
{
|
||||||
if($this->_cache_enabled != true)
|
if($this->_cache_enabled != true || $this->isInAdmin() || substr($path,0,2) == '//' )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(substr($path,0,2) == '//' || e_ADMIN_AREA){ return false; }
|
|
||||||
|
|
||||||
$localPath = e107::getParser()->replaceConstants($path);
|
$localPath = e107::getParser()->replaceConstants($path);
|
||||||
$this->_cache_list[$type][] = $localPath;
|
$this->_cache_list[$type][] = $localPath;
|
||||||
|
|
||||||
@@ -1371,7 +1369,7 @@ class e_jsmanager
|
|||||||
*/
|
*/
|
||||||
public function renderCached($type)
|
public function renderCached($type)
|
||||||
{
|
{
|
||||||
if($this->_cache_enabled != true)
|
if($this->_cache_enabled != true || $this->isInAdmin())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1389,7 +1387,7 @@ 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\n";
|
$content .= "\n\n/* File: ".str_replace("../",'',$path)." */\n";
|
||||||
$content .= $this->getCacheFileContent($path, $type);
|
$content .= $this->getCacheFileContent($path, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1438,7 +1436,7 @@ class e_jsmanager
|
|||||||
if($type == 'js')
|
if($type == 'js')
|
||||||
{
|
{
|
||||||
// e107::minify() todo
|
// e107::minify() todo
|
||||||
return $content;
|
return $this->compress($content);
|
||||||
}
|
}
|
||||||
|
|
||||||
preg_match_all('/url\([\'"]?([^\'"\) ]*)[\'"]?\)/',$content, $match);
|
preg_match_all('/url\([\'"]?([^\'"\) ]*)[\'"]?\)/',$content, $match);
|
||||||
@@ -1446,7 +1444,7 @@ class e_jsmanager
|
|||||||
|
|
||||||
if(empty($match[0]))
|
if(empty($match[0]))
|
||||||
{
|
{
|
||||||
return $content;
|
return $this->compress($content);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($match[1] as $k=>$v)
|
foreach($match[1] as $k=>$v)
|
||||||
@@ -1461,7 +1459,20 @@ class e_jsmanager
|
|||||||
$newpath[$k] = $dir;
|
$newpath[$k] = $dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str_replace($match[0], $newpath, $content);
|
$result = str_replace($match[0], $newpath, $content);
|
||||||
|
return $this->compress($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function compress( $minify )
|
||||||
|
{
|
||||||
|
/* remove comments */
|
||||||
|
$minify = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $minify );
|
||||||
|
|
||||||
|
/* remove tabs, spaces, newlines, etc. */
|
||||||
|
$minify = str_replace( array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $minify );
|
||||||
|
|
||||||
|
return $minify;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user