Here is the Page class. It may run out to the right a bit.
<?php
/*
##################################################
#
# Filename..........: $RCSfile: Page.php,v $
# Original Author...: Anthony L. Awtrey
# Version...........: $Revision: 0.1 $
# Last Modified By..: $Author: aawtrey $
# Last Modified.....: $Date: 2006/09/21 18:15:56 $
#
# Copyright 2006 Anthony Awtrey
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
*/
/*
* Simple templating system for this web application.
*/
class Page {
var $template = "default.tpl";
var $relpath;
var $reluri;
var $relfile;
var $title = "Worship-Organizer";
var $header;
var $description;
var $favicon = "/favicon.ico";
var $keywords = "geneva,florida,usa,united methodist,methodist";
var $colors = array(
'BACKGROUND_COLOR' => "#FFFFFF",
'ACCENT_COLOR' => "#F0FFF0",
'HEADING_COLOR' => "#009000",
'TEXT_COLOR' => "#000000",
'REGULAR_LINK_COLOR' => "#009000",
'VISITED_LINK_COLOR' => "#009000",
'ACTIVE_LINK_COLOR' => "#00FF00",
'HOVER_LINK_COLOR' => "#00FF00"
);
var $menu = array();
var $content;
/*
* Class initialization
*/
function __construct() {
global $_SERVER;
global $_SESSION;
global $_SERVER;
global $_POST;
global $_GET;
if ( is_file("menu.php") ) {
include_once("menu.php");
$this->menu = $menu;
}
$this->relpath = constant("RELPATH");
$this->reluri = constant("RELURI");
if ( defined("RELFILE") ) {
$this->relfile = constant("RELFILE");
}
}
function __destruct()
{
}
/*
* Generates the side menu based on login status and the contents of the
* 'menu.php' file.
*/
function generate_menu() {
if ( $this->relpath == "" && $this->relfile == "" ) {
$output .= " <a href="#">Home</a>n";
} elseif ( $this->relfile != "" ) {
$output .= " <a href="./">Back</a>n";
} else {
$output .= " <a href="../">Back</a>n";
}
if ( count($this->menu) > 0 ) {
foreach ($this->menu as $key => $val) {
if ( @preg_match($val,basename($_SERVER["SCRIPT_FILENAME"])) ) {
$output .= "<a href="#">$key</a>n";
} else {
$output .= "<a href="$val">$key</a>n";
}
}
}
return($output);
}
function generate_login() {
if ( $_SESSION['login'] ) {
$account = new Data("account");
$result = $account->get_record_by_id($_SESSION['login']);
$output .= " <p>" . $result['name'] . "<br />n";
$output .= " <a href="" . $this->relpath . "account.php?action=edit">Change Information</a>n";
$output .= " <a href="" . $this->relpath . "account.php?action=logout&backto=" . $this->reluri . "">Logout</a>n";
} elseif ( $this->relpath == "" && $this->relfile == "account.php" ) {
// display nothing
} else {
$output .= " <a href="" . $this->relpath . "account.php?backto=" . $this->reluri . "">Login</a>n";
}
$output .= " </p>n";
return($output);
}
/*
* Replaces the tokens in the template with the stored content and then
* displays the page to the browser.
*/
function display($html2str=0) {
if ( $this->template == 'blank' ) {
$this_page = $this->content;
} else {
$this_page = file_get_contents($this->template,true);
$this_page = @preg_replace("/[RELPATH]/","$this->relpath",$this_page);
$this_page = @preg_replace("/[TITLE]/","$this->title",$this_page);
$this_page = @preg_replace("/[FAVICON]/","$this->favicon",$this_page);
foreach ($this->colors as $key => $val) {
$this_page = @preg_replace("/[$key]/","$val",$this_page);
}
$this_page = @preg_replace("/[DESCRIPTION]/","$this->description",$this_page);
$this_page = @preg_replace("/[KEYWORDS]/","$this->keywords",$this_page);
$this_page = @preg_replace("/[HEADER]/","$this->header",$this_page);
$this_page = @preg_replace("/[MENU]/",$this->generate_menu(),$this_page);
$this_page = @preg_replace("/[CONTENT]/","$this->content",$this_page);
$this_page = @preg_replace("/[YEAR]/",date("Y"),$this_page);
$this_page = @preg_replace("/[LAST_MODIFIED]/",date("H:i Y/m/d",filemtime(basename($_SERVER['SCRIPT_FILENAME']))),$this_page);
$this_page = @preg_replace("/[LOGIN]/",$this->generate_login(),$this_page);
}
$this_page = stripslashes($this_page);
if ( $html2str == 0 ) {
$this_page = htmlentity2str($this_page);
}
echo $this_page;
exit;
}
}
?>