00001 <?php 00002 00003 /******************************************************************************* 00004 * Aliro - the modern, accessible content management system 00005 * 00006 * Aliro is open source software, free to use, and licensed under GPL. 00007 * You can find the full licence at http://www.gnu.org/copyleft/gpl.html GNU/GPL 00008 * 00009 * The author freely draws attention to the fact that Aliro derives from Mambo, 00010 * software that is controlled by the Mambo Foundation. However, this section 00011 * of code is totally new. If it should contain any fragments that are similar 00012 * to Mambo, please bear in mind (1) there are only so many ways to do things 00013 * and (2) the author of Aliro is also the author and copyright owner for large 00014 * parts of Mambo 4.6. 00015 * 00016 * Tribute should be paid to all the developers who took Mambo to the stage 00017 * it had reached at the time Aliro was created. It is a feature rich system 00018 * that contains a good deal of innovation. 00019 * 00020 * Your attention is also drawn to the fact that Aliro relies on other items of 00021 * open source software, which is very much in the spirit of open source. Aliro 00022 * wishes to give credit to those items of code. Please refer to 00023 * http://aliro.org/credits for details. The credits are not included within 00024 * the Aliro package simply to avoid providing a marker that allows hackers to 00025 * identify the system. 00026 * 00027 * Copyright in this code is strictly reserved by its author, Martin Brampton. 00028 * If it seems appropriate, the copyright will be vested in the Aliro Organisation 00029 * at a suitable time. 00030 * 00031 * Copyright (c) 2007 Martin Brampton 00032 * 00033 * http://aliro.org 00034 * 00035 * counterpoint@aliro.org 00036 * 00037 * aliroCache emulates the PEAR light cache, but is much less code 00038 * 00039 */ 00040 00041 class aliroSimpleCache extends aliroBasicCache { 00042 protected $group = ''; 00043 protected $idencoded = ''; 00044 protected $caching = true; 00045 protected $timeout = _ALIRO_HTML_CACHE_TIME_LIMIT; 00046 protected $sizelimit = _ALIRO_HTML_CACHE_SIZE_LIMIT; 00047 protected $livesite = ''; 00048 00049 public function __construct ($group) { 00050 if ($group) $this->group = $group; 00051 else trigger_error ('Cannot create cache without specifying group name'); 00052 parent::__construct(); 00053 } 00054 00055 protected function getGroupPath () { 00056 $grouppath = $this->basepath."html/$this->group/"; 00057 if (!file_exists($grouppath)) aliroFileManager::getInstance()->createDirectory ($grouppath); 00058 return $grouppath; 00059 } 00060 00061 protected function getCachePath ($name) { 00062 return $this->getGroupPath().$name; 00063 } 00064 00065 public function clean () { 00066 $path = $this->getGroupPath(); 00067 $dir = new aliroDirectory($path); 00068 $dir->deleteFiles(); 00069 } 00070 00071 public function get ($id) { 00072 $this->idencoded = $this->encodeID($id); 00073 return $this->retrieve ($this->idencoded); 00074 } 00075 00076 public function save ($data, $id=null) { 00077 if ($id) $this->idencoded = $this->encodeID($id); 00078 return $this->store ($data, $this->idencoded); 00079 } 00080 00081 protected function encodeID ($id) { 00082 return md5(serialize($id).$this->livesite); 00083 } 00084 } 00085 00086 class aliroCache extends aliroSimpleCache { 00087 00088 public function __construct ($group) { 00089 $this->caching = aliroCore::getInstance()->getCfg('caching') ? true : false; 00090 $this->livesite = aliroCore::getInstance()->getCfg('live_site'); 00091 parent::__construct($group); 00092 } 00093 00094 public function call () { 00095 $arguments = func_get_args(); 00096 $cached = $this->caching ? $this->get($arguments) : null; 00097 if (!$cached) { 00098 ob_start(); 00099 ob_implicit_flush(false); 00100 $function = array_shift($arguments); 00101 call_user_func_array($function, $arguments); 00102 $html = ob_get_contents(); 00103 ob_end_clean(); 00104 $cached = new stdClass(); 00105 $cached->html = $html; 00106 if ($this->caching) { 00107 aliroRequest::getInstance()->setMetadataInCache($cached); 00108 $cached->pathway = aliroPathway::getInstance()->getPathway(); 00109 $this->save($cached); 00110 } 00111 } 00112 else { 00113 aliroRequest::getInstance()->setMetadataFromCache($cached); 00114 aliroPathway::getInstance()->setPathway($cached->pathway); 00115 } 00116 echo $cached->html; 00117 } 00118 00119 } 00120 00125 class mosCache { 00129 static function getCache ($group) { 00130 return new aliroCache ($group); 00131 } 00135 public static function cleanCache ($group=false) { 00136 if (aliroCore::get('mosConfig_caching')) { 00137 $cache = mosCache::getCache( $group ); 00138 $cache->clean ($group); 00139 } 00140 } 00141 }
1.5.5