Location: PHPKode > projects > Modularized Information Environment > mie/includes/script.inc
<?php
/**
 * @file includes/script.inc
 * @brief Script 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('SCRIPT_INC') && exit;
define('SCRIPT_INC', true);

class SCRIPT {

	/// Script Data
	public $data;

	/// Construct Object
	function __construct() {
		$this->data = $this->by_path(mie_path());
	}

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

	/// Class Set Interface
	function __set($_id, $_value) {
		$this->data[$_id] = $_value;
	}

	/// Get Script 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{scripts} AS s LEFT JOIN t{script_shields} AS x ON x.k{script_id} = s.k{id} WHERE (x.k{script_id} IS NULL$sanctions) AND s.k{path} = %c", $_path);
		$data = $db->result($sql);
		if(!isset($data['id'])) { // Invalid script
			mie_jump(mie_page('/missing'));
		}
		return $data;
	}

	/// Execute Script
	function execute() {
		global $db;
		$script_conf = unserialize((string)$this->data['conf']);
		if(is_file($file = mie_root($this->data['file']))) {
			include_once $file;
		}
		if(!empty($this->data['class'])) {
			$s = new $this->data['class']($script_conf);
			if(method_exists($s, 'initialize_script')) {
				$s->initialize_script();
			}
			if(method_exists($s, 'execute')) {
				$s->execute();
			}
		}
	}
}

?>
Return current item: Modularized Information Environment