# # Usage: # # To display content of a variable $foo # new viewvar("This is foo",$foo); class viewvar { function viewvar($name="varview",$variable) { print ""; switch (gettype($variable)) { case "integer": $this->ShowVar($name,"Integer",$variable); break; case "double": $this->ShowVar($name,"Double",$variable); break; case "string": $this->ShowVar($name,"String",$variable); break; case "array": $this->ShowArray($name,$variable); break; case "object": $this->ShowObject($name,$variable); break; case "unknown type": default: $this->DumpVar($name,"String",$variable); break; } print "
\n"; } function ShowArray($name,$in) { Print "".$name.""; while(list($key,$val)=each($in)) { print ""; } Print "
Array"; new viewvar($key,$val); print "
\n"; } function ShowObject($name,$in) { Print "".$name.""; $Object=get_object_vars ($in); while(list($key,$val)=each($Object)) { print ""; } $Methods= get_class_methods($in); while(list($key,$val)=each($Methods)) { print ""; } Print "
Object"; new viewvar($key,$val); print "
Method"; new viewvar($key,$val); print "
\n"; } function ShowVar($name,$type,$content) { Print "$name$type$content"; } function DumpVar($name,$type,$content) { Print "$name$type"; var_dump($content); Print ""; } } ?> template = $this->get_template($template); } function put($name,$value) { $this->template = str_replace($this->start.$name.$this->end,$value, $this->template); } function set($tpl_var) { if (empty($tpl_var)) { $this->_QError("Invalid replacement input"); } $items = explode("|", $tpl_var); $this->template = str_replace($this->start.$items[0].$this->end,"$items[1]", $this->template); } function get_template($template){ if (!file_exists($template)) { $this->_QError("Template does not exist
$template"); } $file_pointer = fopen($template, "r"); $file_read = fread($file_pointer, filesize($template)); fclose($file_pointer); return $file_read; } function putBlock($name,$array){ if (empty($array)) { $this->_QError("Invalid Block data"); } $loop_code = ''; $start_pos = strpos(strtolower($this->template), '') + strlen(''); $end_pos = strpos(strtolower($this->template), ''); $loop_code = substr($this->template, $start_pos, $end_pos-$start_pos); // new viewvar("block code vor",$loop_code); $start_tag = substr($this->template, strpos(strtolower($this->template), ''),strlen('')); $end_tag = substr($this->template, strpos(strtolower($this->template), ''),strlen('')); if($loop_code != ''){ $new_code = ''; $temp_code = $loop_code; while(list($key,$val) = each($array)){ $temp_code = str_replace($this->start.$key.$this->end,$val, $temp_code); } $new_code .= $temp_code; $this->template = str_replace($start_tag.$loop_code.$end_tag, $new_code, $this->template); } } function setloop($array_name){ global $$array_name; //new viewvar("Arrayname Loop",$$array_name); if (empty($array_name)) { $this->_QError("Invalid loop data"); } $loop_code = ''; $start_pos = strpos(strtolower($this->template), '') + strlen(''); $end_pos = strpos(strtolower($this->template), ''); $loop_code = substr($this->template, $start_pos, $end_pos-$start_pos); $start_tag = substr($this->template, strpos(strtolower($this->template), ''),strlen('')); $end_tag = substr($this->template, strpos(strtolower($this->template), ''),strlen('')); if($loop_code != ''){ $new_code = ''; for($i=0; $istart.$key.$this->end,${$array_name}[$i][$key], $temp_code); } $new_code .= $temp_code; } $this->template = str_replace($start_tag.$loop_code.$end_tag, $new_code, $this->template); } } function tagchange($tag){ if (empty($tag)) { $this->_QError("Empty tag data"); } $this->start = $tag; $this->end = $tag; } function tplblock($tpl_block){ if (empty($tpl_block)) { $this->_QError("Invalid block input"); } $items = explode("|", $tpl_block); $this->block = $this->get_template($items[1]); $this->template = str_replace($this->start.$items[0].$this->end,$this->block, $this->template); } function display(){ $this->template = stripslashes($this->template); return $this->template; } function _QError($errmes) { echo "ERROR:
$errmes
" ; exit(); } } ?>