Index.php
<?php
require 'php/stdlib.php';
$site->page->render();
foreach($page as $var => $value) {
echo $var ." is ". $value." <br/>";
}
?>
stdlib.php
<?php
//*************Site Initialization**********///
define("INC_DIR","inc/");
define("CSS_DIR","css/");
define("DEFAULT_HEAD",INC_DIR."index_h.php");
define("DEFAULT_FOOT",INC_DIR."index_f.php");
$currentPage="";
function __autoload($class) {
include "classes/$class.php";
}
function site_ini($site)
{
$siteprop = array(
"siteName" => "Coredrilling Etc",
"dbusername" => "root",
"dbpassword" => "#######",
"dbhostname" => "localhost",
"defaultdbname" => "cce",
"mtable" => "fed_tax_married",
"stable" => "fed_tax_single"
);
foreach($siteprop as $memb => $val )
{
try{
$site->set($memb, $val);
}
catch(Exception $e){
{
throw new Exception( 'Can Not set site Variable'.$memb, 0, $e);
}
}
}
}
$site = new csite();
site_ini($site);
$page = new cpage("welcome");
$site->setPage($page);
?>
cpage.php
<?php
class cpage{
public $name;
public $headers;
public $footers;
public $contents;
private $writeback;
public function get($property)
{
if (property_exists($this, $property))
{
return $this->{$property};
}
}
public function set($property,$new_value)
{
if (!property_exists($this, $property))
{
$this->{$property} = $new_value;
}
}
public function __construct(){
$args = func_get_args();
if (func_num_args() == 1){
$this->name = $args[0];
$this->headers = DEFAULT_HEAD;
$this->footers = DEFAULT_FOOT;
}
if(func_num_args() == 2){
$this->name = $args[0];
$this->pri_get_header($args[1]);
$this->footers = DEFAULT_FOOT;
}
if (func_num_args()== 3){
$this->name = $args[0];
$this->pri_get_header($args[1]);
$this->pri_get_footer($args[2]);
}
$this->pri_get_contents();
}
public function render(){
include $this->headers;
include $this->contents;
include $this->footers;
}
public function get_headers(){
return $this->headers;
}
public function __toString() {
return $this->name;
}
////////PRIVATE FUNCTIONS
private function pri_get_header($header){
$files = scandir(INC_DIR);
foreach($files as $html_file)
{
if($html_file = $header){
$this->headers = INC_DIR . $html_file;
}
}
}
private function pri_get_footer($footer){
$files = scandir(INC_DIR);
foreach($files as $html_file)
{
if($html_file = $footer){
$this->footers = HTML_DIR . $html_file;
}
}
}
private function pri_get_contents(){
$files = scandir(INC_DIR);
foreach($files as $html_file)
{
if($html_file = $this->name.".php"){
$this->contents = INC_DIR . $html_file;
}
}
}
}
?>
csite.php
<?php
class csite
{
public $page;
public function _construct()
{
}
public function get($property)
{
if (property_exists($this, $property))
{
return $this->{$property};
}
}
public function set($property,$new_value)
{
if (!property_exists($this, $property))
{
$this->{$property} = $new_value;
}
}
public function setPage(cpage $page) {
$this->page = $page;
}
public function render_page(){
$this->page->render();
}
}
?>