Location: PHPKode > projects > Modularized Information Environment > mie/includes/page.inc
<?php
/**
 * @file includes/page.inc
 * @brief Page Object
 * @author Kenneth Smith <hide@address.com>
 *
 * Modularized Information Environment (MIE)
 * Copyright (C) 2005-2006 by Kenneth Smith. All rights reserved.
 *
 * 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.
 */

defined('VALIE_MIE') || die(_('Direct access not allowed'));
defined('PAGE_INC') && exit;
define('PAGE_INC', true);

require_once 'includes/xml.inc';
require_once 'includes/menu.inc';

$javascript = new TAG();
$style = new TAG();
$menu = new MENU();

class PAGE {

	/// Page Areas
	public $area;
	/// Page Data
	public $data;

	/// Construct Object
	function __construct() {
		$this->area = array();
		$this->data = $this->by_path(mie_path());
		$this->data['dtd'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
	}

	/// Class Get Interface
	function __get($_id) {
		return $this->data[$_id];
	}

	/// Get Page by Path
	function by_path($_path) {
		global $db, $user;
		// Determine sanctions
		$sanctions = '';
		if(isset($user)) {
			if($user->id == 1) { // The root user
				$sanctions = ' OR TRUE';
			}
			elseif($user->sanctions) { // User has sanctions
				$sanctions = $db->rewrite(' OR x.k{action_id} IN (' . implode(',', mie_extract_key($user->sanctions, 'id')) . ')');
			}
		}
		// Read page data
		$sql = $db->rewrite("SELECT * FROM t{pages} p LEFT JOIN t{page_shields} x ON x.k{page_id} = p.k{id} WHERE (x.k{page_id} IS NULL$sanctions) AND p.k{path} = %c", $_path);
		$data = $db->result($sql);
		if(!isset($data['id'])) { // Invalid page
			$sql = $db->rewrite('SELECT * FROM t{pages} WHERE k{path} = %c', '/');
			$data = $db->result($sql);
			mie_warning(_('Missing'), _('The page (or script) you are trying to access either does not exist or you do not have the proper rights for viewing it.'));
		}
		// Read layout data
		$sql = $db->rewrite("SELECT w.k{name} k{name}, w.k{class} k{class}, w.k{file} k{file}, w.k{conf} k{conf}, l.k{area_id} k{area_id} FROM t{layouts} l LEFT JOIN t{gadgets} w ON l.k{gadget_id} = w.k{id} LEFT JOIN t{gadget_shields} x ON x.k{gadget_id} = w.k{id} WHERE (x.k{gadget_id} IS NULL$sanctions) AND l.k{page_id} = %i ORDER BY l.k{area_id}, l.k{weight}", $data['id']);
		$data['layout'] = $db->table($sql);
		return $data;
	}

	/// Append Gadgets
	function initialize() {
		foreach($this->data['layout'] as $r) {
			$gadget_conf = unserialize((string)$r['conf']);
			if(is_file($file = mie_root($r['file']))) {
				include_once $file;
			}
			if(!empty($r['class'])) {
				$g = new $r['class']($gadget_conf);
				if(method_exists($g, 'initialize_gadget')) {
					$g->initialize_gadget();
				}
				if(isset($r['area_id'])) {
					if(!isset($this->area[$r['area_id']])) {
						$this->area[$r['area_id']] = new TAG();
					}
					$this->area[$r['area_id']]->append($g);
				}
			}
		}
	}

	/// Render Page
	function render() {
		$this->initialize();
		include_once mie_root(mie_theme('theme.template'));
	}
}

?>
Return current item: Modularized Information Environment