All pastes #640958 Raw Edit

Miscellany

public php v1 · immutable
#640958 ·published 2007-07-31 20:32 UTC
rendered paste body
<?phprequire("constants.php");// This is the content engine for Sophisteriaclass SophEngine{	private function __construct() { }	function __destruct() { }		public static $instance;	// Only one instance		private $authtype;			// AuthType.ALLOW or DENY	private $authgroups;		// Groups to ALLOW or DENY		private $running_script;	// The current Running Script	private $appsettings;		// Application Settings array		// Load the Configuration File	public static function Initialize($config) {		if (!isset(self::$instance)) {			$c = __CLASS__;			self::$instance = new $c;		}		XmlConfigurator::Load($config);	}		// Set User Authentication Level	private function SetAuthenticationLevel($type, $groups) {		self::$instance->authtype = $type;		self::$instance->authgroups = $groups;	}			// Run PHP Script	private function RunScript($source) {		self::$instance->running_script = $source;		include(self::$instance->appsettings['RootDirectory'] . $source);	}		// Add Application Setting	public function AddApplicationSetting($key, $value) {		self::$instance->appsettings[$key] = $value;	}		// Process URL Requests	public function ProcessClientRequest($path, $userinfo) {		if (preg_match("(/login)", $path)) {			self::$instance->RunScript("/content/src/login.php");			return;		}		if (preg_match("(/logout)", $path)) {			self::$instance->RunScript("/content/src/logout.php");			return;		}		self::$instance->RunScript("/content/src/index.php");	}		// Load Templates and Display Content	public function RenderHtmlTemplate($templatevars) {		preg_match("(/content/src/(.+?)\.php)", self::$instance->running_script, $matches);		ob_start();		include(self::$instance->appsettings['RootDirectory'] . "/content/html/" . $matches[1] . ".php");		$contents = ob_get_clean();				preg_match_all("({TPL_([A-Za-z0-9]+)})", $contents, $templatetags);		for ($i=0; $i<count($templatetags[1]); $i++) {			ob_start();			include(self::$instance->appsettings['RootDirectory'] . "/content/html/templates/" . strtolower($templatetags[1][$i]) . ".php");			$contents = preg_replace("(" . $templatetags[0][$i] . ")", ob_get_clean(), $contents);		}		print $contents;	}}// This class parses an XML file and adds it to the AppSettings arrayclass XmlConfigurator{	public static function Load($config) {		$file = $config;		$depth = array();		function startElement($parser, $name, $attrs) {			global $tagname;			$tagname = $name;		}				function dataHandler($parser, $data) {			global $tagname;			if ($tagname != "" && $tagname != "Configuration")				SophEngine::AddApplicationSetting($tagname, $data);		}				function endElement($parser, $name) {			global $tagname;			$tagname = "";		}				$xml_parser = xml_parser_create();		xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);		xml_set_element_handler($xml_parser, "startElement", "endElement");		xml_set_character_data_handler($xml_parser, "dataHandler");				if (!($fp = fopen($file, "r"))) {		    die("could not open XML input");		}		while ($data = fread($fp, 4096)) {		    if (!xml_parse($xml_parser, $data, feof($fp))) {        		die(sprintf("XML error: %s at line %d",                		    xml_error_string(xml_get_error_code($xml_parser)),		                    xml_get_current_line_number($xml_parser)));		    }		}		xml_parser_free($xml_parser);	}}?>