2007-06-21 16:55:10 +00:00
|
|
|
<?php
|
2006-12-02 04:36:16 +00:00
|
|
|
/*
|
2009-09-13 10:29:56 +00:00
|
|
|
* e107 website system
|
|
|
|
*
|
2010-05-16 11:14:19 +00:00
|
|
|
* Copyright (C) 2008-2010 e107 Inc (e107.org)
|
2009-09-13 10:29:56 +00:00
|
|
|
* Released under the terms and conditions of the
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
|
|
|
*
|
|
|
|
* Cache handler
|
|
|
|
*
|
2010-05-14 09:32:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2006-12-02 04:36:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('e107_INIT')) { exit; }
|
|
|
|
|
2020-12-16 14:46:43 -08:00
|
|
|
define('CACHE_PREFIX','<?php exit; ?>');
|
2009-02-01 16:18:08 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
/**
|
2009-09-13 10:29:56 +00:00
|
|
|
* Class to cache data as files, improving site speed and throughput.
|
2009-11-24 16:30:08 +00:00
|
|
|
* FIXME - pref independant cache handler, cache drivers
|
2010-03-03 17:06:33 +00:00
|
|
|
*
|
2009-09-13 10:29:56 +00:00
|
|
|
* @package e107
|
2010-05-14 09:32:16 +00:00
|
|
|
* @subpackage e107_handlers
|
|
|
|
* @version $Id$
|
|
|
|
* @author e107 Inc
|
2009-09-13 10:29:56 +00:00
|
|
|
*/
|
2006-12-02 04:36:16 +00:00
|
|
|
class ecache {
|
|
|
|
|
2010-03-03 17:06:33 +00:00
|
|
|
public $CachePageMD5;
|
|
|
|
public $CachenqMD5;
|
|
|
|
public $UserCacheActive; // Checkable flag - TRUE if user cache enabled
|
|
|
|
public $SystemCacheActive; // Checkable flag - TRUE if system cache enabled
|
2020-12-16 09:45:11 -08:00
|
|
|
private $lastError;
|
2020-12-28 10:56:21 -08:00
|
|
|
private $lastFile;
|
2010-03-03 17:06:33 +00:00
|
|
|
|
2020-12-16 14:46:43 -08:00
|
|
|
const CACHE_PREFIX = '<?php exit; ?>';
|
2008-12-20 10:39:29 +00:00
|
|
|
|
2010-05-16 11:14:19 +00:00
|
|
|
function __construct()
|
2008-12-20 10:39:29 +00:00
|
|
|
{
|
2012-12-15 03:49:15 -08:00
|
|
|
//$this->UserCacheActive = e107::getPref('cachestatus');
|
|
|
|
//$this->SystemCacheActive = e107::getPref('syscachestatus');
|
2008-12-20 10:39:29 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2013-03-19 19:08:16 -07:00
|
|
|
/**
|
|
|
|
* Set the MD5 Hash
|
|
|
|
*/
|
2016-06-01 08:58:32 -07:00
|
|
|
public function setMD5($text, $hash=true)
|
2013-03-19 19:08:16 -07:00
|
|
|
{
|
2016-12-13 08:58:00 -08:00
|
|
|
if($text === null)
|
|
|
|
{
|
|
|
|
$this->CachePageMD5 = md5(e_BASE.e_LANGUAGE.THEME.USERCLASS_LIST.defset('e_QUERY').filemtime(THEME.'theme.php'));
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-06-01 08:58:32 -07:00
|
|
|
$this->CachePageMD5 = ($hash === true) ? md5($text) : $text;
|
2015-06-25 18:17:08 -07:00
|
|
|
return $this;
|
2013-03-19 19:08:16 -07:00
|
|
|
}
|
|
|
|
|
2016-12-18 10:27:12 -08:00
|
|
|
|
|
|
|
public function getMD5()
|
|
|
|
{
|
|
|
|
return $this->CachePageMD5;
|
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
* @param string $query
|
|
|
|
* @desc Internal class function that returns the filename of a cache file based on the query.
|
|
|
|
* @scope private
|
|
|
|
* If the tag begins 'menu_', e_QUERY is not included in the hash which creates the file name
|
|
|
|
*/
|
2007-02-04 17:36:16 +00:00
|
|
|
function cache_fname($CacheTag, $syscache = false)
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
if(strpos($CacheTag, "nomd5_") === 0) {
|
|
|
|
// Add 'nomd5' to indicate we are not calculating an md5
|
|
|
|
$CheckTag = '_nomd5';
|
|
|
|
}
|
2010-03-03 17:06:33 +00:00
|
|
|
elseif (isset($this) && $this instanceof ecache)
|
2008-12-20 10:39:29 +00:00
|
|
|
{
|
2010-03-03 17:06:33 +00:00
|
|
|
if (defined("THEME"))
|
2008-12-20 10:39:29 +00:00
|
|
|
{
|
2010-03-03 17:06:33 +00:00
|
|
|
if (strpos($CacheTag, "nq_") === 0)
|
2008-12-20 10:39:29 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
// We do not care about e_QUERY, so don't use it in the md5 calculation
|
2010-03-03 17:06:33 +00:00
|
|
|
if (!$this->CachenqMD5)
|
2008-12-20 10:39:29 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
$this->CachenqMD5 = md5(e_BASE.(defined("ADMIN") && ADMIN == true ? "admin" : "").e_LANGUAGE.THEME.USERCLASS_LIST.filemtime(THEME.'theme.php'));
|
|
|
|
}
|
|
|
|
// Add 'nq' to indicate we are not using e_QUERY
|
|
|
|
$CheckTag = '_nq_'.$this->CachenqMD5;
|
2010-03-03 17:06:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
2008-12-20 10:39:29 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
// It's a page - need the query in the hash
|
2010-03-03 17:06:33 +00:00
|
|
|
if (!$this->CachePageMD5)
|
2008-12-20 10:39:29 +00:00
|
|
|
{
|
2012-01-11 10:37:12 +00:00
|
|
|
$this->CachePageMD5 = md5(e_BASE.e_LANGUAGE.THEME.USERCLASS_LIST.defset('e_QUERY').filemtime(THEME.'theme.php'));
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
$CheckTag = '_'.$this->CachePageMD5;
|
|
|
|
}
|
2010-03-03 17:06:33 +00:00
|
|
|
}
|
|
|
|
else
|
2008-12-20 10:39:29 +00:00
|
|
|
{
|
2010-03-03 17:06:33 +00:00
|
|
|
// Check if a custom CachePageMD5 is in use in e_module.php.
|
2007-12-09 00:12:08 +00:00
|
|
|
$CheckTag = ($this->CachePageMD5) ? "_".$this->CachePageMD5 : "";
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2010-03-03 17:06:33 +00:00
|
|
|
}
|
|
|
|
else
|
2008-12-20 10:39:29 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
$CheckTag = '';
|
|
|
|
}
|
2007-02-04 17:36:16 +00:00
|
|
|
$q = ($syscache ? "S_" : "C_").preg_replace("#\W#", "_", $CacheTag);
|
2012-12-15 16:22:50 -08:00
|
|
|
|
|
|
|
if($syscache === true)
|
|
|
|
{
|
|
|
|
$CheckTag = ''; // no MD5 on system cache. XXX To be Checked.
|
|
|
|
}
|
2019-06-03 15:27:36 -07:00
|
|
|
|
2010-03-03 17:06:33 +00:00
|
|
|
$fname = e_CACHE_CONTENT.$q.$CheckTag.'.cache.php';
|
2007-02-04 17:36:16 +00:00
|
|
|
//echo "cache f_name = $fname <br />";
|
2020-12-28 10:56:21 -08:00
|
|
|
$this->lastFile = $fname;
|
2006-12-02 04:36:16 +00:00
|
|
|
return $fname;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-22 17:59:29 -08:00
|
|
|
* Retrieve Cache data.
|
|
|
|
* @param $CacheTag
|
|
|
|
* @param bool|int $MaximumAge the time in minutes before the cache file 'expires'
|
|
|
|
* @param bool $ForcedCheck check even if cache pref is disabled.
|
|
|
|
* @param bool $syscache set to true when checking sys cache.
|
|
|
|
* @return string
|
|
|
|
* @desc Returns the data from the cache file associated with $query, else it returns false if there is no cache for $query.
|
|
|
|
* @scope public
|
|
|
|
*/
|
2013-03-19 19:08:16 -07:00
|
|
|
public function retrieve($CacheTag, $MaximumAge = false, $ForcedCheck = false, $syscache = false)
|
2009-02-01 16:18:08 +00:00
|
|
|
{
|
2010-05-16 11:14:19 +00:00
|
|
|
if(($ForcedCheck != false ) || ($syscache == false && $this->UserCacheActive) || ($syscache == true && $this->SystemCacheActive) && !e107::getParser()->checkHighlighting())
|
2007-02-04 17:36:16 +00:00
|
|
|
{
|
2012-12-15 03:49:15 -08:00
|
|
|
$cache_file = (isset($this) && $this instanceof ecache ? $this->cache_fname($CacheTag, $syscache) : self::cache_fname($CacheTag, $syscache));
|
2016-12-22 17:59:29 -08:00
|
|
|
|
|
|
|
if(file_exists($cache_file))
|
2009-02-01 16:18:08 +00:00
|
|
|
{
|
2016-12-22 17:59:29 -08:00
|
|
|
if ($MaximumAge !== false && (filemtime($cache_file) + ($MaximumAge * 60)) < time()) {
|
2006-12-02 04:36:16 +00:00
|
|
|
unlink($cache_file);
|
|
|
|
return false;
|
2010-03-03 17:06:33 +00:00
|
|
|
}
|
|
|
|
else
|
2009-02-01 16:18:08 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
$ret = file_get_contents($cache_file);
|
2020-12-16 09:45:11 -08:00
|
|
|
|
|
|
|
if($ret === false)
|
|
|
|
{
|
|
|
|
$this->lastError = "Couldn't read ".$cache_file;
|
|
|
|
}
|
|
|
|
|
2020-12-16 14:46:43 -08:00
|
|
|
if (strpos($ret, self::CACHE_PREFIX) === 0)
|
2009-02-01 16:18:08 +00:00
|
|
|
{
|
2010-03-03 17:06:33 +00:00
|
|
|
$ret = substr($ret, strlen(self::CACHE_PREFIX));
|
2009-02-01 16:18:08 +00:00
|
|
|
}
|
2020-12-16 14:46:43 -08:00
|
|
|
elseif(strpos($ret, '<?php exit;') === 0)
|
|
|
|
{
|
|
|
|
$ret = substr($ret, 11);
|
|
|
|
}
|
|
|
|
elseif(strpos($ret,'<?php') === 0)
|
2009-02-01 16:18:08 +00:00
|
|
|
{
|
|
|
|
$ret = substr($ret, 5); // Handle the history for now
|
|
|
|
}
|
2020-12-16 09:45:11 -08:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
2016-12-22 17:59:29 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-16 09:45:11 -08:00
|
|
|
$this->lastError = "Cache file not found: ".$cache_file;
|
2006-12-02 04:36:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-16 09:45:11 -08:00
|
|
|
/**
|
|
|
|
* Return the last error encountered during cache processing.
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getLastError()
|
|
|
|
{
|
|
|
|
return $this->lastError;
|
|
|
|
}
|
|
|
|
|
2020-12-28 10:56:21 -08:00
|
|
|
/**
|
|
|
|
* Return the last error encountered during cache processing.
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getLastFile()
|
|
|
|
{
|
|
|
|
return $this->lastFile;
|
|
|
|
}
|
|
|
|
|
2007-02-04 17:36:16 +00:00
|
|
|
/**
|
2012-12-15 03:49:15 -08:00
|
|
|
* @return string
|
|
|
|
* @param string $CacheTag
|
2007-02-04 17:36:16 +00:00
|
|
|
* @param int $MaximumAge the time in minutes before the cache file 'expires'
|
2012-12-15 03:49:15 -08:00
|
|
|
* @param boolean $force
|
2007-02-04 17:36:16 +00:00
|
|
|
* @desc Returns the data from the cache file associated with $query, else it returns false if there is no cache for $query.
|
|
|
|
* @scope public
|
|
|
|
*/
|
|
|
|
function retrieve_sys($CacheTag, $MaximumAge = false, $ForcedCheck = false)
|
|
|
|
{
|
2009-08-03 18:21:46 +00:00
|
|
|
if(isset($this) && $this instanceof ecache)
|
2007-02-04 17:36:16 +00:00
|
|
|
{
|
|
|
|
return $this->retrieve($CacheTag, $MaximumAge, $ForcedCheck, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-15 03:49:15 -08:00
|
|
|
return self::retrieve($CacheTag, $MaximumAge, $ForcedCheck, true);
|
2007-02-04 17:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
/**
|
2010-03-03 17:06:33 +00:00
|
|
|
*
|
2013-03-19 19:08:16 -07:00
|
|
|
* @param string $CacheTag - name of tag for future retrieval - should NOT contain an MD5.
|
2016-04-20 17:25:32 -07:00
|
|
|
* @param string $Data - data to be cached
|
2013-03-19 19:08:16 -07:00
|
|
|
* @param boolean $ForceCache [optional] if TRUE, writes cache even when disabled in admin prefs.
|
2009-10-24 10:07:30 +00:00
|
|
|
* @param boolean $bRaw [optional] if TRUE, writes data exactly as provided instead of prefacing with php leadin
|
|
|
|
* @param boolean $syscache [optional]
|
2009-12-13 21:52:32 +00:00
|
|
|
* @return none
|
2009-10-24 10:07:30 +00:00
|
|
|
*/
|
2010-03-03 17:06:33 +00:00
|
|
|
public function set($CacheTag, $Data, $ForceCache = false, $bRaw=0, $syscache = false)
|
2009-02-01 16:18:08 +00:00
|
|
|
{
|
2019-06-03 15:27:36 -07:00
|
|
|
if(defined('E107_INSTALL') && E107_INSTALL === true)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-05-16 11:14:19 +00:00
|
|
|
if(($ForceCache != false ) || ($syscache == false && $this->UserCacheActive) || ($syscache == true && $this->SystemCacheActive) && !e107::getParser()->checkHighlighting())
|
2007-02-04 17:36:16 +00:00
|
|
|
{
|
2012-12-15 03:49:15 -08:00
|
|
|
$cache_file = (isset($this) && $this instanceof ecache ? $this->cache_fname($CacheTag, $syscache) : self::cache_fname($CacheTag, $syscache));
|
2012-12-07 15:42:54 -08:00
|
|
|
@file_put_contents($cache_file, ($bRaw? $Data : self::CACHE_PREFIX.$Data) );
|
2007-03-04 15:01:28 +00:00
|
|
|
@chmod($cache_file, 0755); //Cache should not be world-writeable
|
2006-12-02 04:36:16 +00:00
|
|
|
@touch($cache_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-04 17:36:16 +00:00
|
|
|
/**
|
|
|
|
* @return void
|
2013-03-19 19:08:16 -07:00
|
|
|
* @param string $CacheTag - name of tag for future retrieval - should NOT contain an MD5
|
2007-02-04 17:36:16 +00:00
|
|
|
* @param string $Data - data to be cached
|
|
|
|
* @param bool $ForceCache (optional, default false) - if TRUE, writes cache even when disabled
|
|
|
|
* @param bool $bRaw (optional, default false) - if TRUE, writes data exactly as provided instead of prefacing with php leadin
|
|
|
|
* @desc Creates / overwrites the cache file for $query, $text is the data to store for $query.
|
|
|
|
* @scope public
|
|
|
|
*/
|
|
|
|
function set_sys($CacheTag, $Data, $ForceCache = false, $bRaw=0)
|
|
|
|
{
|
2009-08-03 18:21:46 +00:00
|
|
|
if(isset($this) && $this instanceof ecache)
|
2007-02-04 17:36:16 +00:00
|
|
|
{
|
2020-12-16 09:45:11 -08:00
|
|
|
$this->set($CacheTag, $Data, $ForceCache, $bRaw, true);
|
2007-02-04 17:36:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-15 16:22:50 -08:00
|
|
|
self::set($CacheTag, $Data, $ForceCache, $bRaw, true);
|
2007-02-04 17:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
/**
|
2009-09-25 20:17:34 +00:00
|
|
|
* Deletes cache files. If $query is set, deletes files named {$CacheTag}*.cache.php, if not it deletes all cache files - (*.cache.php)
|
2010-03-03 17:06:33 +00:00
|
|
|
*
|
2009-09-25 20:17:34 +00:00
|
|
|
* @param string $CacheTag
|
|
|
|
* @param boolean $syscache
|
2010-03-03 17:06:33 +00:00
|
|
|
* @param boolean $related clear also 'nq_' and 'nomd5_' entries
|
2009-09-25 20:17:34 +00:00
|
|
|
* @return bool
|
2010-03-03 17:06:33 +00:00
|
|
|
*
|
2009-09-25 20:17:34 +00:00
|
|
|
*/
|
2013-03-19 19:08:16 -07:00
|
|
|
public function clear($CacheTag = '', $syscache = false, $related = false)
|
2008-01-10 03:14:09 +00:00
|
|
|
{
|
2016-12-22 17:59:29 -08:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
$file = ($CacheTag) ? preg_replace("#\W#", "_", $CacheTag)."*.cache.php" : "*.cache.php";
|
2010-03-03 17:06:33 +00:00
|
|
|
e107::getEvent()->triggerAdminEvent('cache_clear', "cachetag=$CacheTag&file=$file&syscache=$syscache");
|
2012-12-15 03:49:15 -08:00
|
|
|
$ret = self::delete(e_CACHE_CONTENT, $file, $syscache);
|
2010-03-03 17:06:33 +00:00
|
|
|
|
2009-09-25 20:17:34 +00:00
|
|
|
if($CacheTag && $related) //TODO - too dirty - add it to the $file pattern above
|
|
|
|
{
|
2012-12-15 03:49:15 -08:00
|
|
|
self::delete(e_CACHE_CONTENT, 'nq_'.$file, $syscache);
|
|
|
|
self::delete(e_CACHE_CONTENT, 'nomd5_'.$file, $syscache);
|
|
|
|
//ecache::delete(e_CACHE_CONTENT, 'nq_'.$file, $syscache);
|
|
|
|
//ecache::delete(e_CACHE_CONTENT, 'nomd5_'.$file, $syscache);
|
2009-09-25 20:17:34 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2007-02-04 17:36:16 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
* @param string $CacheTag
|
|
|
|
* @desc Deletes cache files. If $query is set, deletes files named {$CacheTag}*.cache.php, if not it deletes all cache files - (*.cache.php)
|
|
|
|
*/
|
2009-09-25 20:17:34 +00:00
|
|
|
function clear_sys($CacheTag = '', $related = false)
|
2007-02-04 17:36:16 +00:00
|
|
|
{
|
2016-12-22 17:59:29 -08:00
|
|
|
|
|
|
|
|
2009-08-03 18:21:46 +00:00
|
|
|
if(isset($this) && $this instanceof ecache)
|
2007-02-04 17:36:16 +00:00
|
|
|
{
|
2009-09-25 20:17:34 +00:00
|
|
|
return $this->clear($CacheTag, true, $related);
|
2007-02-04 17:36:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-15 03:49:15 -08:00
|
|
|
self::clear($CacheTag, true, $related);
|
|
|
|
// ecache::clear($CacheTag, true, $related);
|
2007-02-04 17:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
* @param string $dir
|
|
|
|
* @param string $pattern
|
|
|
|
* @desc Internal class function to allow deletion of cache files using a pattern, default '*.*'
|
|
|
|
* @scope private
|
|
|
|
*/
|
2007-02-04 17:36:16 +00:00
|
|
|
function delete($dir, $pattern = "*.*", $syscache = false) {
|
|
|
|
$pattern = ($syscache ? "S_" : "C_").$pattern;
|
2006-12-02 04:36:16 +00:00
|
|
|
$pattern = str_replace(array("\*", "\?"), array(".*", "."), preg_quote($pattern));
|
|
|
|
if (substr($dir, -1) != "/") {
|
|
|
|
$dir .= "/";
|
|
|
|
}
|
2008-01-16 10:54:33 +00:00
|
|
|
if (is_dir($dir))
|
|
|
|
{
|
|
|
|
$d = opendir($dir);
|
2006-12-02 04:36:16 +00:00
|
|
|
while ($file = readdir($d)) {
|
|
|
|
if (is_file($dir.$file) && preg_match("/^{$pattern}$/", $file)) {
|
2021-09-04 15:06:19 +02:00
|
|
|
unlink($dir.$file);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($d);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-04-26 01:33:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-03-19 19:08:16 -07:00
|
|
|
* Clear Full Cache
|
2017-01-29 15:10:32 -08:00
|
|
|
* @param string $type: content | system| browser | db | image | js | css | library
|
2012-04-26 01:33:33 +00:00
|
|
|
* @example clearAll('db');
|
|
|
|
*/
|
|
|
|
|
2012-07-29 02:36:18 +00:00
|
|
|
function clearAll($type,$mask = null)
|
|
|
|
{
|
2012-04-26 01:33:33 +00:00
|
|
|
$path = null;
|
|
|
|
|
|
|
|
if($type =='content')
|
|
|
|
{
|
|
|
|
$this->clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-29 15:10:32 -08:00
|
|
|
if($type === 'system')
|
2012-04-26 01:33:33 +00:00
|
|
|
{
|
|
|
|
$this->clear_sys();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-29 15:10:32 -08:00
|
|
|
if($type === 'browser')
|
2012-04-26 01:33:33 +00:00
|
|
|
{
|
|
|
|
e107::getConfig()->set('e_jslib_browser_cache', time())->save(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-29 15:10:32 -08:00
|
|
|
if($type === 'db')
|
2012-04-26 01:33:33 +00:00
|
|
|
{
|
|
|
|
$path = e_CACHE_DB;
|
2012-12-06 14:53:58 -08:00
|
|
|
$mask = ($mask == null) ? '.*\.php' : $mask;
|
2012-04-26 01:33:33 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 15:10:32 -08:00
|
|
|
if($type === 'image')
|
2012-04-26 01:33:33 +00:00
|
|
|
{
|
|
|
|
$path = e_CACHE_IMAGE;
|
2017-10-25 15:17:53 -07:00
|
|
|
$mask = ($mask == null) ? '.*(\.cache\.bin|\.jpg|\.jpeg|\.png|\.gif)' : $mask;
|
2012-04-26 01:33:33 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 15:10:32 -08:00
|
|
|
if($type === 'js')
|
2016-02-05 15:31:54 -08:00
|
|
|
{
|
|
|
|
$path = e_WEB."cache/";
|
2016-02-05 16:26:33 -08:00
|
|
|
$mask = ($mask == null) ? '.*\.js' : $mask;
|
|
|
|
}
|
|
|
|
|
2017-01-29 15:10:32 -08:00
|
|
|
if($type === 'css')
|
2016-02-05 16:26:33 -08:00
|
|
|
{
|
|
|
|
$path = e_WEB."cache/";
|
|
|
|
$mask = ($mask == null) ? '.*\.css' : $mask;
|
2016-02-05 15:31:54 -08:00
|
|
|
}
|
|
|
|
|
2017-01-29 15:10:32 -08:00
|
|
|
if($type === 'library')
|
|
|
|
{
|
|
|
|
$path = e_CACHE_CONTENT;
|
|
|
|
$mask = ($mask == null) ? 'S_Library_.*\.cache\.php' : $mask;
|
|
|
|
}
|
|
|
|
|
2012-04-26 01:33:33 +00:00
|
|
|
if((null == $path) || (null == $mask))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$fl = e107::getFile(false);
|
|
|
|
$fl->mode = 'fname';
|
2012-07-29 02:36:18 +00:00
|
|
|
$files = $fl->get_files($path, $mask);
|
2017-01-29 15:10:32 -08:00
|
|
|
|
2012-04-26 01:33:33 +00:00
|
|
|
if($files)
|
|
|
|
{
|
|
|
|
foreach ($files as $file)
|
|
|
|
{
|
|
|
|
unlink($path.$file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|