1
0
mirror of https://github.com/e107inc/e107.git synced 2025-04-20 04:32:01 +02:00

Fixes for JS/CSS Cache. Correct file-count displayed in admin. minify code on output.

This commit is contained in:
Cameron 2016-02-05 16:26:33 -08:00
parent a1c4707bcf
commit eb3cb3b287
3 changed files with 30 additions and 12 deletions

View File

@ -91,7 +91,8 @@ if (isset($_POST['trigger_empty_cache']))
break;
case 'empty_jscss':
e107::getCache()->clearAll('jscss');
e107::getCache()->clearAll('js');
e107::getCache()->clearAll('css');
// e107::getAdminLog()->flushMessages(CACLAN_5);
break;
@ -111,7 +112,7 @@ $syscache_files = glob(e_CACHE_CONTENT.'S_*.*');
$cache_files = glob(e_CACHE_CONTENT.'C_*.*');
$imgcache_files = glob(e_CACHE_IMAGE.'*.cache.bin');
$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);
$cache_files_num = count($cache_files);

View File

@ -326,10 +326,16 @@ class ecache {
$mask = ($mask == null) ? '.*\.cache\.bin' : $mask;
}
if($type == 'jscss')
if($type == 'js')
{
$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))

View File

@ -1349,13 +1349,11 @@ class e_jsmanager
*/
private function addCache($type,$path)
{
if($this->_cache_enabled != true)
if($this->_cache_enabled != true || $this->isInAdmin() || substr($path,0,2) == '//' )
{
return false;
}
if(substr($path,0,2) == '//' || e_ADMIN_AREA){ return false; }
$localPath = e107::getParser()->replaceConstants($path);
$this->_cache_list[$type][] = $localPath;
@ -1371,7 +1369,7 @@ class e_jsmanager
*/
public function renderCached($type)
{
if($this->_cache_enabled != true)
if($this->_cache_enabled != true || $this->isInAdmin())
{
return false;
}
@ -1389,7 +1387,7 @@ class e_jsmanager
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);
}
@ -1438,7 +1436,7 @@ class e_jsmanager
if($type == 'js')
{
// e107::minify() todo
return $content;
return $this->compress($content);
}
preg_match_all('/url\([\'"]?([^\'"\) ]*)[\'"]?\)/',$content, $match);
@ -1446,7 +1444,7 @@ class e_jsmanager
if(empty($match[0]))
{
return $content;
return $this->compress($content);
}
foreach($match[1] as $k=>$v)
@ -1461,10 +1459,23 @@ class e_jsmanager
$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;
}
function getCacheFileId($paths)
{
$id = '';