Location: PHPKode > projects > chillyCMS > chillyCMS/core/page.class.php
<?php
//#################################################################################################
//	Page class
//#################################################################################################
//	chillyCMS - Content Management System
//	Copyright (C) 2008
//	Stefanie Wiegand <hide@address.com> & Johannes Cox <hide@address.com>
//	
//	This program is licensed under the GPL 3.0 license. For more information see LICENSE.txt.
//#################################################################################################
defined('DOIT') or die('Restricted access');

//load settings, no matter from where this script is called
if (file_exists('core/settings.include.php')) {
	require_once('core/settings.include.php');
} elseif (file_exists('../core/settings.include.php')) {
	require_once('../core/settings.include.php');
} elseif (file_exists('../../core/settings.include.php')) {
	require_once('../../core/settings.include.php');
}
//load languagefile if it exists
if (isset($settings) && file_exists(PATH."/languages/$settings[language].php")) {
	require_once(PATH."/languages/$settings[language].php");
}

//load various classes
require_once(PATH.'/core/form.class.php');
require_once(PATH.'/core/menuitem.class.php');
require_once(PATH.'/core/module.class.php');
require_once(PATH.'/core/webuser.class.php');
require_once(PATH.'/core/session.class.php');


abstract class Page {
	//Class variables//////////////////////////////////////////////////////////////////////////
	protected $doctype;
	protected $title;
	protected $meta;
	protected $stylesheets;
	protected $scripts;
	protected $content;

	protected $db;
	protected $num_queries;
	protected $queries;
	protected $start_time;
	protected $stop_time;
	protected $load_time;
	protected $debug_info;

	//Functions////////////////////////////////////////////////////////////////////////////////
	//Constructor
	function __construct() {
		global $settings,$title;
		
		$this->db		= new Database();
		$this->num_queries	= 2;
		$this->queries		= array("select * from site_settings order by 1","select * from system_groups order by 1");
		$this->start_time	= microtime(true);
		$this->stop_time	= false;
		$this->load_time	= false;

		//doctype
		$this->doctype = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" ".
		"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n".
		"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"".$settings["language"]."\" ".
		"lang=\"".$settings["language"]."\">\n".
		"<head>\n";

		//metatags
		$this->meta = "\t<meta http-equiv=\"Content-Type\" content=\"text/html;charset=iso-8859-1\" />\n".
		"\t<meta name=\"Content-Language\" content=\"".$settings["language"]."\" />\n";
		
		//to be filled in child classes
		$this->title = $this->stylesheets = $this->scripts = $this->content = "";
	}
	//Destructor
	function __destruct() {
		$this->db->close();
		$this->doctype = $this->title = $this->meta = $this->stylesheets = $this->scripts = $this->num_queries =
		$this->start_time = $this->stop_time = $this->load_time = false;
	}
	//add something to the page content
	public function add($string) {
		if ($this->content .= $string) {
			return true;
		} else {
			return false;
		}
	}
	//simulate a query being executed
	public function query($sql) {
		$this->queries[] = $sql;
		if ($this->db->query($sql)) {
			$this->num_queries += 1;
			return true;
		} else {
			return false;
		}
	}
	//add something to debug info
	public function debug($string,$class=false) {
		if (is_array($string) && !empty($string)) {
			$this->debug_info .= '<p>Array:</p><ul>';
			foreach ($string as $k=>$v) {
				if (is_array($v)) {
					$this->debug_info .= '<li>['.$k.']<ul>';
					foreach ($v as $key=>$val) {
						$this->debug_info .= '<li>['.$key.'] => '.$val.'</li>';
					}
					$this->debug_info .= '</ul></li>';
				} else {
					$this->debug_info .= '<li>['.$k.'] => '.$v.'</li>';
				}
			}
			$this->debug_info .= '</ul>';
		} elseif ($string && $string!='') {
			$this->debug_info .= '<p';
			if($class) {
				$this->debug_info .= ' class="'.$class.'"';
			}
			$this->debug_info .= '>'.escape_html($string).'</p>';
		}
	}
} ?>
Return current item: chillyCMS