* $Author:: $ *
* -------------------------------------------------------------------- *
* Copyright (c) 2003 - 2009 by Roland Haeder *
- * Copyright (c) 2009, 2010 by Mailer Developer Team *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team *
* For more information visit: http://www.mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
// Caching class
class CacheSystem {
- // Define variables
- var $ret = 'init';
+ // Status code
+ var $statusCode = 'init';
+
+ // Full-qualified filename
var $fqfn = '';
+
+ // Resource to cache file
var $pointer = false;
+
+ // Data array from cache
var $data = array();
+
+ // Version data from cache
var $version = array();
+
+ // Cache name
var $name = '';
var $rebuilt = array();
+
+ // File extension
var $extension = '.cache';
- var $statusDone = 'done';
var $status = array();
var $readable = array();
+ var $fullPath = '';
// Constructor
function CacheSystem () {
- // Failed is the default
- $this->ret = 'failed';
+ // Construct full path
+ $this->fullPath = getPath() . getCachePath();
- // Remeber path
+ // Failed is the default
+ $this->setStatusCode('failed');
// Check if path exists
- if (isDirectory(getCachePath())) {
+ if (isDirectory($this->fullPath)) {
// Is there a .htaccess file?
- if (isFileReadable(getCachePath() . '.htaccess')) {
+ if (isFileReadable($this->fullPath . '.htaccess')) {
// All done!
- $this->ret = $this->statusDone;
+ $this->setStatusCode('done');
} else {
// Stop! Set a .htaccess file first
- $this->ret = 'htaccess';
+ $this->setStatusCode('htaccess');
}
} // END - if
}
$this->name = $cacheName;
// Construct FQFN (full qualified file name)
- $this->fqfn = getCachePath() . $cacheName . $this->extension;
+ $this->fqfn = $this->fullPath . $cacheName . $this->extension;
// Check if file exists and if version matches
if (!isset($this->status[$cacheName])) {
// Initializes the cache file
function init () {
// This will destory an existing cache file!
- if ($this->ret == $this->statusDone) {
+ if ($this->getStatusCode() == 'done') {
// Reset read status
$this->resetCacheReadStatus();
} else {
$GLOBALS['cache_array']['admin'][$k][$data['admin_id']] = $v;
}
+ } elseif ($this->name == 'admin_acls') {
+ // Access control lines
+ $GLOBALS['cache_array']['admin_acls'][$k][$data['admin_id']][] = $v;
} elseif ($this->name == 'refdepths') {
// Referal levels
$GLOBALS['cache_array']['refdepths'][$k][$data['id']] = $v;
// Remove cache
$this->removeCacheFile(true);
- // Unsupported cache found!
+ // Unsupported/unhandled cache detected
debug_report_bug(__METHOD__, __LINE__, 'Unsupported cache ' . $this->name . ' detected.');
}
} // END - if
} else {
// Cache file not found or not readable
- debug_report_bug(__METHOD__, __LINE__, $this->name);
- addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): ' . getMaskedMessage('CACHE_CANNOT_LOAD', $this->fqfn));
+ debug_report_bug(__METHOD__, __LINE__, '{%message,CACHE_CANNOT_LOAD=' . $this->name . '%}');
// Try to remove it
$this->removeCacheFile();
} // END - if
// Remove cache file from system
+ //* DEBUG: */ debug_report_bug(__METHOD__, __LINE__, 'About to remove ' . basename($this->fqfn) . '!');
removeFile($this->fqfn);
// Reset read status
$this->rebuilt[$this->name] = true;
} else {
// Not removed!
- addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): ' . getMaskedMessage('CACHE_CANNOT_UNLINK', $this->fqfn));
+ debug_report_bug(__METHOD__, __LINE__, '{%message,CACHE_CANNOT_UNLINK=' . $this->name . '%}');
}
} // END - if
}
// Unused method:
function removeEntry ($search, $data, $array) {
- if ($this->status[$this->name] == $this->statusDone) {
+ if ($this->status[$this->name] == 'done') {
// Load cache into dummy array
$dummy = $this->getArrayFromCache();
// Close cache file
$this->finalize();
- }
+ } // END - if
} else {
// Cannot write to cache!
addFatalMessage(__METHOD__, __LINE__, '(<font color="#0000aa">' . __LINE__ . '</font>): {--CACHE_PROBLEMS_DETECTED');
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 .= $this->rewriteEntry($k, $v2);
- }
+ } // END - foreach
} else {
// Single line found
$LINE = $this->rewriteEntry($k, $v);
// Unused method
function replaceEntry ($search, $replace, $search_key, $array) {
- if ($this->status[$this->name] == $this->statusDone) {
+ if ($this->status[$this->name] == 'done') {
// Load cache into dummy array
$dummy = $this->getArrayFromCache();
// Does it match?
$GLOBALS[__METHOD__][$ext_name] = ((isset($this->version[$this->name][$ext_name])) && ($this->version[$this->name][$ext_name] == $ext_ver));
} elseif ($this->isCacheReadable()) {
- // No cache version found!
+ // No cache version found
logDebugMessage(__METHOD__, __LINE__, 'Cache ' . $this->name . ' has missing version entry for extension ' . $ext_name . '! Purging cache...');
// Remove the cache file
return $line;
}
- // Getter for cache status
- function getStatus () {
- return $this->ret;
+ // Getter for cache status code
+ function getStatusCode () {
+ return $this->statusCode;
+ }
+
+ // Setter for cache status code
+ function setStatusCode ($status) {
+ $this->statusCode = $status;
}
// Checks wether the current cache file is readable