filename =& $this->fn; $this->me = strtoupper(get_class($this)); $this->searchpath = $GLOBALS[$this->me . "_SEARCH"]; if (defined($this->me . "_COMPRESS")) { foreach(array(array('gzcompress', 'gzuncompress'), array('gzdeflate', 'gzinflate')) as $grp) { if (function_exists($grp[0])) { $this->def = $grp[0]; $this->inf = $grp[1]; break; } } } $this->fn = $name; $this->refresh(); } function set($varname, $value = ''){ $this->vars[$varname] = $value; } function get($varname) { return $this->vars[$varname]; } function refresh() { if (!preg_match('/\.([^\.\/\s]+)$/', $this->fn, $found) ) { $this->cached($this->fn); $this->fn = null; $this->error = null; return; } $subdirs = preg_split('/([\s]*;[\s]*)/', $this->searchpath); if (! $subdirs) $subdirs = array(''); list($a, $up, $b, $path) = preg_match('/^(([\.]+\/)*)(.+)/', $this->fn, $found) ? $found : array('', '', '', $found[0]); foreach($subdirs as $subdir) { $sub = _slashjoin($up, $subdir); if ($subdir and !is_dir($sub)) { $sub = _dirlist(dirname($sub), preg_replace('/([^0-9a-z]+)$/', '', $subdir) ); } $this->searchdir = _slashjoin($sub, $path); $exists = (file_exists($this->searchdir) and filesize($this->searchdir) > 0); if ($exists) { $this->searchpath = $sub; break; } } $readable = ($exists and is_readable($this->searchdir) ); $soort = ($readable) ? filetype($this->searchdir) : ""; if ($readable and $soort == "file") { $this->cached( join('', file($this->searchdir)) ); $this->error = null; } elseif (!$exists) { $this->error( sprintf("'%s' bestaat niet.", $this->searchdir) ); } elseif (!$readable) { $this->error( sprintf("'%s' kan niet worden gelezen.", $this->searchdir) ); } elseif ($exists && $soort != "file") { $this->error( sprintf("'%s' is geen geldig bestand; %s", $this->searchdir, $soort) ); } return; } function error($str) { $text = sprintf('%s %s [in %s]', $this->me, $str, $_SERVER['SCRIPT_NAME']); $this->error = $text; if ($_SERVER['IS_DEVEL'] and $this->error) error_log($this->error); } function parse($vars = array()) { $vars = $vars + $this->vars; if ($this->searchpath) $vars['_searchpath'] = trim(_slashjoin($this->searchpath, ' ')); $match = array(); $repl = array(); foreach(array_keys($vars) as $key){ $match[] = sprintf("/(%%\[%s\]%%)/i", preg_quote($key)); $repl[] = $vars[$key]; } $match[] = '/%\[[^\[\]]+\]%/'; # Catch all $repl[] = ''; return preg_replace($match, $repl, $this->cached()); } function extractData() { $reg = '/<\!--(\s*([^=\s\<\>]+)[\s=]+[\'"]?([^\'"\s\<\>]+))+\s*-->/'; $comment = '/<\!--\s*(.+)\s*-->/'; $fields = '/([^=\s<>]+)[\s=]+([\'\"])?([^\s<>\2]+)/'; if (! preg_match_all($comment, $this->cached(), $found) ) return false; foreach($found[1] as $line) { preg_match_all($fields, $line, $res); for($i=0; $i < sizeof($res[0]); $i++) { $this->vars[$res[1][$i]] = $res[3][$i]; } } return $this->vars; } function cached($str = null) { if (is_null($str)) { $do = $this->inf; return ($this->compressed() and $this->ch) ? $do($this->ch) : $this->ch; } $do = $this->def; $this->ch = ($this->compressed()) ? $do($str, 9) : $str; } function compressed() { return ($this->inf || $this->def); } } ?>