rendered paste body<?phpclass Template { var $vars; var $path; function Template($path = null) { $this->path = $path; $this->vars = array(); } function set_path($path) { $this->path = $path; } function set($name, $value) { $this->vars[$name] = $value; } function set_vars($vars, $clear = false) { if($clear) { $this->vars = $vars; } else { if(is_array($vars)) $this->vars = array_merge($this->vars, $vars); } } function fetch($file) { extract($this->vars); ob_start(); include($this->path . $file); $contents = ob_get_contents(); ob_end_clean(); return $contents; }}class CachedTemplate extends Template { var $cache_id; var $expire; var $cached; function CachedTemplate($path, $cache_id = null, $expire = 900) { $this->Template($path); $this->cache_id = $cache_id ? 'cache/' . md5($cache_id) : $cache_id; $this->expire = $expire; } function is_cached() { if($this->cached) return true; // Passed a cache_id? if(!$this->cache_id) return false; // Cache file exists? if(!file_exists($this->cache_id)) return false; if(!($mtime = filemtime($this->cache_id))) return false; // Cache expired? if(($mtime + $this->expire) < time()) { @unlink($this->cache_id); return false; } else { $this->cached = true; return true; } } function fetch_cache($file) { if($this->is_cached()) { $fp = @fopen($this->cache_id, 'r'); $contents = fread($fp, filesize($this->cache_id)); fclose($fp); return $contents; } else { $contents = $this->fetch($file); // Write the cache if($fp = @fopen($this->cache_id, 'w')) { fwrite($fp, $contents); fclose($fp); } else { die('Unable to write cache.'); } return $contents; } }}?>