mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
Preference added to enable experimental JS/CSS Caching. JS/CSS Caching tweaked to correct broken paths.
This commit is contained in:
@@ -55,6 +55,7 @@ if (isset($_POST['submit_cache']))
|
|||||||
{
|
{
|
||||||
e107::getConfig()->set('cachestatus', intval($_POST['cachestatus']))
|
e107::getConfig()->set('cachestatus', intval($_POST['cachestatus']))
|
||||||
->set('syscachestatus', intval($_POST['syscachestatus']))
|
->set('syscachestatus', intval($_POST['syscachestatus']))
|
||||||
|
->set('jscsscachestatus', intval($_POST['jscsscachestatus']))
|
||||||
->save(false);
|
->save(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +90,11 @@ if (isset($_POST['trigger_empty_cache']))
|
|||||||
e107::getAdminLog()->flushMessages(CACLAN_25);
|
e107::getAdminLog()->flushMessages(CACLAN_25);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'empty_jscss':
|
||||||
|
e107::getCache()->clearAll('jscss');
|
||||||
|
// e107::getAdminLog()->flushMessages(CACLAN_5);
|
||||||
|
break;
|
||||||
|
|
||||||
// all
|
// all
|
||||||
default:
|
default:
|
||||||
e107::getCache()->clearAll('content');
|
e107::getCache()->clearAll('content');
|
||||||
@@ -105,16 +111,19 @@ $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/*.*');
|
||||||
|
|
||||||
$syscache_files_num = count($syscache_files);
|
$syscache_files_num = count($syscache_files);
|
||||||
$cache_files_num = count($cache_files);
|
$cache_files_num = count($cache_files);
|
||||||
$imgcache_files_num = count($imgcache_files);
|
$imgcache_files_num = count($imgcache_files);
|
||||||
$dbcache_files_num = count($dbcache_files);
|
$dbcache_files_num = count($dbcache_files);
|
||||||
|
$jscsscache_files_num = count($jscsscache_files);
|
||||||
|
|
||||||
$syscache_label = $syscache_files_num.' '.($syscache_files_num != 1 ? CACLAN_19 : CACLAN_18);
|
$syscache_label = $syscache_files_num.' '.($syscache_files_num != 1 ? CACLAN_19 : CACLAN_18);
|
||||||
$contentcache_label = $cache_files_num.' '.($cache_files_num != 1 ? CACLAN_19 : CACLAN_18);
|
$contentcache_label = $cache_files_num.' '.($cache_files_num != 1 ? CACLAN_19 : CACLAN_18);
|
||||||
$imgcache_label = $imgcache_files_num.' '.($imgcache_files_num != 1 ? CACLAN_19 : CACLAN_18);
|
$imgcache_label = $imgcache_files_num.' '.($imgcache_files_num != 1 ? CACLAN_19 : CACLAN_18);
|
||||||
$dbcache_label = $dbcache_files_num.' '.($dbcache_files_num != 1 ? CACLAN_19 : CACLAN_18);
|
$dbcache_label = $dbcache_files_num.' '.($dbcache_files_num != 1 ? CACLAN_19 : CACLAN_18);
|
||||||
|
$jscsscache_label = $jscsscache_files_num.' '.($jscsscache_files_num != 1 ? CACLAN_19 : CACLAN_18);
|
||||||
|
|
||||||
$text = "
|
$text = "
|
||||||
<form method='post' action='".e_SELF."'>
|
<form method='post' action='".e_SELF."'>
|
||||||
@@ -154,6 +163,19 @@ $text = "
|
|||||||
".$frm->radio_switch('syscachestatus', e107::getPref('syscachestatus'))."
|
".$frm->radio_switch('syscachestatus', e107::getPref('syscachestatus'))."
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<strong class='e-tip'>".CACLAN_28." <span class='label label-warning'>Experimental</span></strong>
|
||||||
|
<div class='field-help'>".CACLAN_29."</div>
|
||||||
|
</td>
|
||||||
|
<td>{$jscsscache_label}</td>
|
||||||
|
<td class='left middle'>
|
||||||
|
".$frm->radio_switch('jscsscachestatus', e107::getPref('jscsscachestatus'))."
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<strong class='e-tip'>".CACLAN_20."</strong>
|
<strong class='e-tip'>".CACLAN_20."</strong>
|
||||||
@@ -174,6 +196,9 @@ $text = "
|
|||||||
".LAN_ENABLED."
|
".LAN_ENABLED."
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div class='buttons-bar form-inline'>
|
<div class='buttons-bar form-inline'>
|
||||||
@@ -182,6 +207,7 @@ $text = "
|
|||||||
'empty_all' => CACLAN_26,
|
'empty_all' => CACLAN_26,
|
||||||
'empty_contentcache' => CACLAN_5,
|
'empty_contentcache' => CACLAN_5,
|
||||||
'empty_syscache' => CACLAN_16,
|
'empty_syscache' => CACLAN_16,
|
||||||
|
'empty_jscss' => CACLAN_30,
|
||||||
'empty_dbcache' => CACLAN_24,
|
'empty_dbcache' => CACLAN_24,
|
||||||
'empty_imgcache' => CACLAN_25,
|
'empty_imgcache' => CACLAN_25,
|
||||||
'empty_browsercache' => CACLAN_27,
|
'empty_browsercache' => CACLAN_27,
|
||||||
|
@@ -326,6 +326,12 @@ class ecache {
|
|||||||
$mask = ($mask == null) ? '.*\.cache\.bin' : $mask;
|
$mask = ($mask == null) ? '.*\.cache\.bin' : $mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($type == 'jscss')
|
||||||
|
{
|
||||||
|
$path = e_WEB."cache/";
|
||||||
|
$mask = ($mask == null) ? '.*(\.js|\.css)$' : $mask;
|
||||||
|
}
|
||||||
|
|
||||||
if((null == $path) || (null == $mask))
|
if((null == $path) || (null == $mask))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@@ -206,6 +206,9 @@ class e_jsmanager
|
|||||||
*/
|
*/
|
||||||
protected $_dependenceLoaded = array();
|
protected $_dependenceLoaded = array();
|
||||||
|
|
||||||
|
|
||||||
|
protected $_cache_enabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@@ -275,6 +278,7 @@ class e_jsmanager
|
|||||||
}
|
}
|
||||||
|
|
||||||
$customJqueryUrls = e107::getPref('library-jquery-urls');
|
$customJqueryUrls = e107::getPref('library-jquery-urls');
|
||||||
|
$this->_cache_enabled = e107::getPref('jscsscachestatus',false);
|
||||||
|
|
||||||
if(vartrue($customJqueryUrls) && $this->_in_admin === false)
|
if(vartrue($customJqueryUrls) && $this->_in_admin === false)
|
||||||
{
|
{
|
||||||
@@ -1345,7 +1349,12 @@ class e_jsmanager
|
|||||||
*/
|
*/
|
||||||
private function addCache($type,$path)
|
private function addCache($type,$path)
|
||||||
{
|
{
|
||||||
return false; //return false if cache is disabled - CURRENTLY DISABLED - TODO Add Pref etc.
|
if($this->_cache_enabled != true)
|
||||||
|
{
|
||||||
|
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;
|
||||||
@@ -1362,6 +1371,10 @@ class e_jsmanager
|
|||||||
*/
|
*/
|
||||||
public function renderCached($type)
|
public function renderCached($type)
|
||||||
{
|
{
|
||||||
|
if($this->_cache_enabled != true)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if(!empty($this->_cache_list[$type]))
|
if(!empty($this->_cache_list[$type]))
|
||||||
{
|
{
|
||||||
@@ -1376,8 +1389,8 @@ class e_jsmanager
|
|||||||
|
|
||||||
foreach($this->_cache_list[$type] as $k=>$path)
|
foreach($this->_cache_list[$type] as $k=>$path)
|
||||||
{
|
{
|
||||||
$content .= "\n\n/* ".str_replace("../",'',$path)." */ \n\n";
|
$content .= "\n\n/* File: ".str_replace("../",'',$path)." */ \n\n";
|
||||||
$content .= file_get_contents($path);
|
$content .= $this->getCacheFileContent($path, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!@file_put_contents($saveFilePath, $content))
|
if(!@file_put_contents($saveFilePath, $content))
|
||||||
@@ -1412,6 +1425,46 @@ class e_jsmanager
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get js/css file to be cached and update url links.
|
||||||
|
* @param $path string
|
||||||
|
* @param $type string (js|css)
|
||||||
|
* @return mixed|string
|
||||||
|
*/
|
||||||
|
function getCacheFileContent($path, $type)
|
||||||
|
{
|
||||||
|
$content = @file_get_contents($path);
|
||||||
|
|
||||||
|
if($type == 'js')
|
||||||
|
{
|
||||||
|
// e107::minify() todo
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
preg_match_all('/url\([\'"]?([^\'"\) ]*)[\'"]?\)/',$content, $match);
|
||||||
|
$newpath = array();
|
||||||
|
|
||||||
|
if(empty($match[0]))
|
||||||
|
{
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($match[1] as $k=>$v)
|
||||||
|
{
|
||||||
|
if(substr($v,5) == 'data:')
|
||||||
|
{
|
||||||
|
unset($match[0][$k]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dir = "url(../../".dirname($path)."/".$v.")"; // relative to e_WEB_ABS."cache/";
|
||||||
|
$newpath[$k] = $dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str_replace($match[0], $newpath, $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function getCacheFileId($paths)
|
function getCacheFileId($paths)
|
||||||
{
|
{
|
||||||
$id = '';
|
$id = '';
|
||||||
|
@@ -32,4 +32,8 @@ define("CACLAN_24", "Empty DB Structure Cache");
|
|||||||
define("CACLAN_25", "Empty Thumbnail Cache");
|
define("CACLAN_25", "Empty Thumbnail Cache");
|
||||||
define("CACLAN_26", "Empty All Cache");
|
define("CACLAN_26", "Empty All Cache");
|
||||||
define("CACLAN_27", "Empty Browser Cache");
|
define("CACLAN_27", "Empty Browser Cache");
|
||||||
|
|
||||||
|
define("CACLAN_28", "JS/CSS Cache");
|
||||||
|
define("CACLAN_29", "Consolidate and cache javascript files and cascading stylesheet files.");
|
||||||
|
define("CACLAN_30", "Empty JS/CSS Cache");
|
||||||
?>
|
?>
|
0
e107_web/cache/index.html
vendored
Normal file
0
e107_web/cache/index.html
vendored
Normal file
Reference in New Issue
Block a user