page_title = $page_title; } function pull_template ($template, $output = 0) { // we need this to be global for the links global $user; // check for admin template $template = $this->check_admin($template); // check if template exists $this->check_template ($template, 1); // call the template and store the contents in a variable ob_start(); include (TEMPLATE_DIR.$template.'.php'); $template_output = ob_get_contents(); ob_end_clean(); // determine whether or not to output the template that is called if ($output == 1) { echo $this->replace_variables ($template_output, '{', '}'); return true; } else { return $this->replace_variables ($template_output, '{', '}'); } } function output_page ($template) { // determine which type of page it is if ($template == 'redirect') { $this->pull_template('redirect', 1); exit; } else if ($template == 'error') { $this->pull_template('error', 1); exit; } else { // check to see if template exists first $template = $this->check_template($template); $this->pull_template('header', 1); $this->pull_template($template, 1); $this->pull_template('footer', 1); exit; } } function check_template ($template, $output_page = 0) { // check for admin template $template = $this->check_admin($template); if (!file_exists(TEMPLATE_DIR.$template.'.php')) { global $title; $title = "Template '" . TEMPLATE_DIR.$template.".php" . "' could not be found."; if ($output_page == 1) { $this->output_page (ERROR_DIR.'template'); exit; } else { return ERROR_DIR.'template'; } } else { return $template; } } function check_admin ($template) { // check if it's an admin page if (substr($template, 0, strlen(ADMIN_PREFIX)) == ADMIN_PREFIX) { $template = ADMIN_DIR . $template; } return $template; } function replace_variables ($text, $start, $end) { foreach (split("\n", $text) as $line_num => $line) { $current = $line; do { // check for variable on this line if (eregi($start, $current) && eregi($end, $current)) { $startpos = strpos ($current, $start); $endpos = strpos ($current, $end); if ($startpos < $endpos) { $var = substr($current, $startpos+strlen($start), $endpos-$startpos-strlen($start)); $array_var = $this->array_variable ($var); if (count($array_var) != 0) { $replace['name'] = $array_var['name']; $replace['value'] = $array_var['value']; } else { global $$var; $replace['name'] = $var; $replace['value'] = $$var; } $name[] = $replace['name']; $content[] = strval($replace['value']); $current = substr($current, $endpos+strlen($end)); } else { $current = substr($current, $startpos+strlen($start)); } } else { $current = ''; } } while (strlen($current) > 0); for ($x = 0; $x < count($name); ++$x) { $line = str_replace ($start . $name[$x] . $end, $content[$x], $line); } $new[] = $line; unset($name, $content); } return implode ("\n", $new); } function array_variable ($var) { // check for array bracket if (eregi("\[", $var) && eregi("\]", $var)) { $startpos = strpos ($var, "["); $endpos = strpos ($var, "]"); $key = substr ($var, $startpos+1, $endpos-$startpos-1); $array_name = substr($var, 0, $startpos); global $$array_name; $replacement['value'] = ${$array_name}[$key]; $replacement['name'] = $array_name."[".$key."]"; } return $replacement; } function no_permission () { if (empty($_SERVER['HTTP_REFERER'])) $ref = 'search.php'; else $ref = $_SERVER['HTTP_REFERER']; $this->page_title = 'No Permission'; $this->redirect_message = 'You do not have permission to access this page.'; $this->redirect_url = $ref; $this->output_page ('redirect'); exit; } } ?>