1,7 → 1,6 |
<?php |
|
class template_handler { |
private $data = array(); |
private $files = array(); |
private $vars = array(); |
private $root; |
15,21 → 14,37 |
} |
|
function add_text($text) { |
array_push($this->files, array('TEXT' => $text)); |
array_push($this->files, array('TEXT' => htmlspecialchars($text), "WITH_VARIABLES" => false)); |
} |
|
function add_html_text($text) { |
array_push($this->files, array('TEXT' => $text, "WITH_VARIABLES" => false)); |
} |
|
function add_html_text_with_variables($text) { |
array_push($this->files, array('TEXT' => $text, "WITH_VARIABLES" => true)); |
} |
|
function __toString() { |
$form = ''; |
|
foreach($this->files as $f) { |
if(array_key_exists('FILE', $f)) { |
$this->data = array_merge($this->data, file($this->root.'/'.$f['FILE'].'.tpl')); |
$file_data = file($this->root.'/'.$f['FILE'].'.tpl'); |
|
foreach($file_data as $l) { |
$form .= $this->replace_variables($l); |
} |
} |
if(array_key_exists('TEXT', $f)) { |
array_push($this->data, $f['TEXT']."\n"); |
if($f['WITH_VARIABLES']) { |
$form .= $this->replace_variables($f['TEXT']); |
} |
else { |
$form .= $f['TEXT']; |
} |
foreach($this->data as $l) { |
$form = $form.$this->replace_variables($l); |
} |
} |
|
return $form; |
} |
49,6 → 64,14 |
|
function add_variables($args) { |
if(is_array($args)) { |
foreach($args as $key => $value) { |
$this->vars[$key] = htmlspecialchars($value); |
} |
} |
} |
|
function add_html_variables($args) { |
if(is_array($args)) { |
$this->vars = array_merge($this->vars, $args); |
} |
} |
59,22 → 82,9 |
$label = $url; |
} |
|
return '<A HREF="'.$url.'">'.$label.'</a>'; |
return '<A HREF="' . htmlspecialchars($url) . '">' . htmlspecialchars($label) . '</a>'; |
} |
|
function s_text($text) { |
if(is_array($text)) { |
for($i=0;$i<sizeof($text);$i++) { |
$text[$i] = ereg_replace('<', '<', $text[$i]); |
$text[$i] = ereg_replace('>', '>', $text[$i]); |
} |
} else { |
$text = ereg_replace('<', '<', $text); |
} |
|
return $text; |
} |
|
class Table { |
#Define somewhere to store the rows |
protected $rowid = 0; |
122,36 → 132,44 |
return $this->build(); |
} |
|
public function build() { |
$tag = "table"; |
if($this->table_class) $tag .= " class=\"$this->table_class\""; |
|
$output = "<$tag>\n"; |
|
#Display the header |
if($this->hdr) { |
$output .= "\t<thead>\n\t\t<tr>\n"; |
|
foreach($this->hdr as $cell) { |
private function build_cell($cell, $default_tag) { |
if(!is_array($cell)) $cell = array('text' => $cell); |
|
$tag = $cell['tag'] ? $cell['tag'] : 'th'; |
$tag = $cell['tag'] ? htmlspecialchars($cell['tag']) : $default_tag; |
|
$output .= "\t\t\t<" . $tag; |
$output = "\t\t\t<" . $tag; |
if($cell['class']) { |
$output .= " class=\"$class\""; |
$output .= ' class="' . htmlspecialchars($cell['class']) . '"'; |
} |
if($cell['comment']) { |
$output .= " title=\"" . htmlspecialchars($cell['comment']) . "\""; |
} |
|
if($cell['text']) { |
$html = s_text($cell['text']); |
$html = htmlspecialchars($cell['text']); |
} |
else { |
$html = $cell['html']; |
} |
if(!$html) $html = ' '; |
|
$output .= ">" . $html . "</" . $tag . ">\n"; |
return ($output . ">" . $html . "</" . $tag . ">\n"); |
} |
|
public function build() { |
$tag = "table"; |
if($this->table_class) $tag .= " class=\"" . htmlspecialchars($this->table_class) . "\""; |
|
$output = "<$tag>\n"; |
|
#Display the header |
if($this->hdr) { |
$output .= "\t<thead>\n\t\t<tr>\n"; |
|
foreach($this->hdr as $cell) { |
$output .= $this->build_cell($cell, 'th'); |
} |
|
$output .= "\t\t</tr>\n\t</thead>\n"; |
} |
|
161,24 → 179,9 |
$output .= "\t\t<tr>\n"; |
|
foreach($row as $cell) { |
$tag = $cell['tag'] ? $cell['tag'] : 'td'; |
|
$output .= "\t\t\t<" . $tag; |
if($cell['class']) { |
$output .= ' class="' . $cell['class'] . '"'; |
$output .= $this->build_cell($cell, 'td'); |
} |
|
if($cell['text']) { |
$html = s_text($cell['text']); |
} |
else { |
$html = $cell['html']; |
} |
if(!$html) $html = ' '; |
|
$output .= ">" . $html . "</" . $tag . ">\n"; |
} |
|
$output .= "\t\t</tr>\n"; |
} |
|
188,46 → 191,9 |
} |
} |
|
function Form($method, $action, $text) { |
$form = '<form method="'.$method.'" action="'.$action.'">'."\n"; |
$form .= $text; |
$form .= "</form>\n"; |
return $form; |
function display_input($type, $name, $value = '') { |
return '<input type="' . htmlspecialchars($type) . '" name="' |
. htmlspecialchars($name) . '" value="' . htmlspecialchars($value) . "\">"; |
} |
|
function Input($type,$name,$value = '') { |
return '<input type="'.$type.'" name="'.$name.'" value="'.$value.'">'."\n"; |
} |
|
function Combo($name, $data, $default) { |
if(is_array($data)) { |
$output = '<SELECT NAME="'.$name."\">\n"; |
foreach($data as $options) { |
$output .= "\t<OPTION "; |
if(is_array($options)) { |
$op = array_values($options); |
if($default == $op[0]) { |
$output .= 'SELECTED '; |
} |
$output .= 'value="'.$op[0].'">'; |
if($op[1] == '') { |
$output .= $op[0]; |
} else { |
$output .= $op[1]; |
} |
$output .= '</OPTION>'."\n"; |
} else { |
if($options == $default) { |
$output .= 'SELECTED '; |
} |
$output .= 'value="'.$options.'">1'.$options; |
} |
$output .= "</option>\n"; |
} |
$output .= '</SELECT>'."\n"; |
} |
|
return $output; |
} |
|
?> |