filename = $filename; $this->set_tags(); return $this->reload(); } function set_tags($start_tag = '%', $end_tag = '%') { $this->start_tag = $start_tag; $this->end_tag = $end_tag; } function load($filename) { if (file_exists($filename)) { $this->html = join('', file($filename)); $this->_set_file(); return 1; } return 0; } function reload() { if (isset($this->filename)) return $this->load($this->filename); return 0; } function add_before($string) { $this->html = $string . $this->html; } function add_after($string) { $this->html .= $string; } function set($key, $value = "") { if(gettype($key) == "array") { while ( list ($k, $v) = each ($key) ) { if (!(empty($k))) { /* Empty values are allowed. Empty Keys are NOT. */ $this->set($k, $v); } } } else { $regexp = $this->start_tag . $key . ( isset($this->end_tag) ? $this->end_tag : '\b' ); if (isset($value)) { $this->html = preg_replace("/$regexp/i", $value, $this->html); } } $this->_set_file(); } function _set_file() { $regexp = $this->start_tag . 'file:([^%\b]+)' . ( isset($this->end_tag) ? $this->end_tag : '\b' ); while (preg_match("/$regexp/i", $this->html, $matches)){ $filename = $matches[1]; $filename_with_path = dirname($this->filename) . '/' . $filename; if (file_exists($filename_with_path)) { $value = join('', file($filename_with_path)); } else { $value = ""; } $filename = addslashes($filename); $regexp2 = $this->start_tag . "file:$filename" . ( isset($this->end_tag) ? $this->end_tag : '\b' ); $this->html = preg_replace("/$regexp2/i", $value, $this->html); } } function is_key($key) { $regexp = $this->start_tag . $key . ( isset($this->end_tag) ? $this->end_tag : '\b' ); return preg_match("/$regexp/i", $this->html); } function get_keys() { $regexp = $this->start_tag . '([\w][_\w\d]*)'. ( isset($this->end_tag) ? $this->end_tag : '\b' ); preg_match_all("/$regexp/i", $this->html, $matches); return $matches[1]; } function hide() { $regexp = $this->start_tag . '\w+'; $regexp .= ( isset($this->end_tag) ? $this->end_tag : '\b' ); $this->html = preg_replace("/($regexp)/i", '', $this->html); return $this->html(); } function clean() { $regexp = $this->start_tag . '\w+' . ( isset($this->end_tag) ? $this->end_tag : '\b' ); $this->html = preg_replace("/$regexp/i", '', $this->html); return $this->html(); } function html() { return $this->html; } function html_array() { $regexp = $this->start_tag . 'include:([^%\b]+)' . ( isset($this->end_tag) ? $this->end_tag : '\b' ) . ''; preg_match_all("/$regexp/is", $this->html, $matches); return array(preg_split("/$regexp/is", $this->html), $matches[1]); } } ?>