$this->cache_path=$path;
// Check if path exists
- if ((file_exists($path)) && (is_dir($path)) && (!$tested))
- {
+ if ((is_dir($path)) && (!$tested)) {
// Check if we can create a file inside the path
@touch($path."dummy.tmp", 'w');
- if (file_exists($path."dummy.tmp")) {
+ if (FILE_READABLE($path."dummy.tmp")) {
// Yes, we can do. So let's remove it
@unlink($path."dummy.tmp");
// Is there a .htaccess file?
- if (file_exists($path.".htaccess")) {
+ if (FILE_READABLE($path.".htaccess")) {
// Update database that we have tested it
UPDATE_CONFIG("cache_tested", 1);
return "failed";
}
- function cache_file($file, $ignore_ctime=false)
- {
+ function cache_file($file, $ignore_ctime=false) {
global $INC;
// Construct FQFN (full qualified file name)
$inc = $this->cache_path.$file.".cache";
$this->cache_inc = $inc;
// Check if file exists
- $status = (file_exists($inc) && (is_readable($inc)) && (is_writeable($inc)));
- if ($status)
- {
+ $status = (FILE_READABLE($inc) && (is_writeable($inc)));
+ if ($status) {
// Yes, it does. So let's get it's last changed date/time
$ctime = filectime($inc);
- }
- else
- {
+ } else {
// No, it doesn't. Zero date/time
$ctime = "0";
}
$this->cache_ctime = $ctime;
// Is the cache file outdated?
- if (((time() - $ctime) >= $this->update_interval) && (!$ignore_ctime))
- {
+ if (((time() - $ctime) >= $this->update_interval) && (!$ignore_ctime)) {
// Ok, we need an update!
$status = false;
}
+
+ // Return status
return $status;
}
- function cache_init($array)
- {
+ function cache_init($array) {
// This will destory an existing cache file!
- if ($this->ret == "done")
- {
+ if ($this->ret == "done") {
// Create file
- if (file_exists($this->cache_inc)) @chmod($this->cache_inc, 0666);
+ if (FILE_READABLE($this->cache_inc)) @chmod($this->cache_inc, 0666);
$fp = @fopen($this->cache_inc, 'w') or mxchange_die("Cannot write to cache ".$this->cache_inc." !");
// Begin of cache file
// Remember file pointer
$this->cache_pointer = $fp;
- }
- else
- {
+ } else {
// Cannot create file
ADD_FATAL(__FILE__."(".__LINE__."): ".CACHE_PROBLEMS_DETECTED);
}
}
- function add_row($data) {
+ function add_row ($data) {
+ global $cacheArray;
+
if (is_resource($this->cache_pointer)) {
// Write every array element to cache file
- foreach ($data as $k=>$v) {
+ foreach ($data as $k => $v) {
+ // Write global cache array for immediate access
+ if ((substr($k, 0, 4) == "ext_") && (isset($data['ext_name'])) && (isset($data['ext_id']))) {
+ if ($k != "ext_name") {
+ $cacheArray['extensions'][$k][$data['ext_name']] = $v;
+ } else {
+ $cacheArray['extensions'][$k][$data['ext_id']] = $v;
+ }
+ if (($k == "ext_keep") && ($v == "Y")) {
+ $cacheArray['active_extensions'][$data['ext_name']] = $v;
+ } // END - if
+ } // END - if
+
+ // Write cache line to file
@fwrite($this->cache_pointer, "\$data['".$k."'][] = \"".$v."\";\n");
}
} else {
@fclose($this->cache_pointer);
// Set rights
- if (file_exists($this->cache_inc)) @chmod($this->cache_inc, 0666);
+ if (FILE_READABLE($this->cache_inc)) @chmod($this->cache_inc, 0666);
// Remove pointer
unset($this->cache_pointer);
function cache_load()
{
- if ((file_exists($this->cache_inc)) && (is_readable($this->cache_inc)))
- {
+ if (FILE_READABLE($this->cache_inc)) {
// Prepare temporary array
$data = array();
function cache_destroy()
{
- if (file_exists($this->cache_inc))
+ if (FILE_READABLE($this->cache_inc))
{
// Remove cache file from system
@unlink($this->cache_inc);
- if (!file_exists($this->cache_inc))
+ if (!FILE_READABLE($this->cache_inc))
{
// Close cache automatically (we don't need it anymore!)
$this->cache_close();
function cache_remove($search, $data, $array)
{
global $ARRAY;
- if ((file_exists($this->cache_inc)) && (is_writeable($this->cache_inc)))
+ if ((FILE_READABLE($this->cache_inc)) && (is_writeable($this->cache_inc)))
{
// Load cache into dummy array
$dummy = $this->cache_load();
// Flush array to cache file
$fp = fopen($this->cache_inc, 'w');
fwrite($fp, "\$ARRAY = \"".$ARRAY."\";\n");
- foreach ($dummy as $k=>$v)
+ foreach ($dummy as $k => $v)
{
if (is_array($v))
{
// Multi line(s) found
$LINE = "";
- foreach($v as $k2=>$v2)
+ foreach($v as $k2 => $v2)
{
// Put every array element in a row...
$LINE .= "\$data['".$k."'][] = \"".$v2."\";\n";
function cache_replace($search, $replace, $search_key, $array)
{
global $ARRAY;
- if ((file_exists($this->cache_inc)) && (is_writeable($this->cache_inc)))
+ if ((FILE_READABLE($this->cache_inc)) && (is_writeable($this->cache_inc)))
{
// Load cache into dummy array
$dummy = $this->cache_load();
{
$key = $search_key;
// Key (hopefully) found?
- foreach ($dummy as $a=>$v)
+ foreach ($dummy as $a => $v)
{
// So we can update all entries
if ($a == $search)
// Flush array to cache file
$fp = fopen($this->cache_inc, 'w');
fwrite($fp, "\$dummy = \"".$ARRAY."\";\n");
- foreach ($dummy as $k=>$v)
+ foreach ($dummy as $k => $v)
{
if (is_array($v))
{
// Multi line(s) found
$LINE = "";
- foreach($v as $k2=>$v2)
+ foreach($v as $k2 => $v2)
{
// Put every array element in a row...
$LINE .= "\$data['".$k."'][] = \"".$v2."\";\n";