Code Search for Developers
 
 
  

engine.php from ECP (EliteCore Project) at Krugle


Show engine.php syntax highlighted

<?php


// PHP Manual
// get_magic_quotes_gpc
// Example 2. Disabling magic quotes at runtime
// (encrypted login fix 2006-04-05)
function stripslashes_deep($value) {
	$value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
	return $value;
}
if (get_magic_quotes_gpc()) {
	$_POST = array_map('stripslashes_deep', $_POST);
	$_GET = array_map('stripslashes_deep', $_GET);
	$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

/* EXCEPTIONS */
require_once ('core/exceptions/undefineddata.php');
require_once ('core/exceptions/ajaxflush.php');
require_once ('core/exceptions/nomodule.php');

/* INTERFACES */
require_once ('core/interface/module_class.php'); // DEPRECATED
require_once ('core/interface/encryption.php');
require_once ('core/interface/session_interface.php');
require_once ('core/interface/form.php');

/* CORE */
require_once ('core/Location.php');
require_once ('core/Page.php');
require_once ('core/reflection.php');
require_once ('core/string.php');
require_once ('core/debug.php');
require_once ('core/config.php');
require_once ('core/events.php');
require_once ('core/mod_rewrite.php');
require_once ('core/db.php');
require_once ('core/storage.php');
require_once ('core/perspective.php');
require_once ('core/date.php');
require_once ('core/user.php');
require_once ('core/ModulesManager.php');
require_once ('core/session_passport.php');
require_once ('core/wysiwyg_texy.php');
require_once ('core/cache.php');
require_once ('core/mailer.php');
require_once ('core/xhtml_form.php');
require_once ('core/XMLForms.php');
require_once ('core/filesystem.php');
require_once ('core/texy.php');
require_once ('core/ajax.php');
require_once ('core/user_cache.php');
require_once ('core/template.php');
require_once ('core/i18n.php');
require_once ('core/XHTMLParser.php');
require_once ('core/Icon.php');
require_once ('core/MusicTags.php');

require_once ('ext/geshi/geshi.php');

/* DEFAULT RENDERER */
require_once ('core/renderers/default.php');

/* 3rd party */
//require_once ('ext/opendocument51.php');
require_once ('ext/PEAR/PEAR.php');
require_once ('ext/Net_UserAgent_Detect-2.1.0/Detect.php');
//require_once ('ext/crypt/Blowfish.php');
require_once ('ext/php-captcha.inc.php');
require_once ('ext/pclzip.lib.php');

class ArrayToObject {
	private $DataArray = false;
	public function __get($var) {
		if ($this->DataArray && isset ($this->DataArray[$var]))
			return $this->DataArray[$var];
		else
			return false;
	}
	public function __construct($DataArray = false) {
		$this->DataArray = $DataArray;
	}
}

function j($input) {
	if (strpos($input, '{') !== 0) {
		$quote = false;
		if (strpos($input, '"') === false) {
			$quote = '"';
		} else
			if (strpos($input, "'") === false) {
				$quote = "'";
			}

		if ($quote) {
			$chunks = explode(',', $input);
			$input = '';
			foreach ($chunks as $key => $chunk) {
				$var = explode(':', $chunk);
				$input .= $quote . $var[0] . $quote . ':' . $quote . $var[1] . $quote;
				if ($key != sizeof($chunks) - 1) {
					$input .= ',';
				}
			}
		}

		$input = '{' . $input . '}';
	}
	return json_decode($input);
}

/**
 * Main methods that can be used in every project. (based on ECP open-source core by Luke Satin)
 *
 * Static properties can be accessed with Engine::[property_name] ,
 * others with $ECP object.
 * @package Engine
 * @author Luke Satin <cyberluk@seznam.cz>
 * @version alpha
 */
class Engine {
	private $version = "alpha";

	const FORCEURL = 0;
	const LOAD_POSITION = 1;
	const ALLOW_ADMIN = 10;
	const FORCE_USER_THEME = 11;
	const HORIZONTAL = "horizontal";
	const VERTICAL = "vertical";

	/**#@+
	* @access private
	*/
	private static $flags = array ();
	private static $file_root = "";
	private static $instance = false;
	private static $countStart = 0;
	private static $countEnd = 0;
	private $content = array (
		"-1" => array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array ()
	);
	private $content_behavior = array (
		"-1" => array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array (),
		array ()
	);
	private $lastSource = false;
	private $unique_content_file = 0;
	private $template_variables = array ();
	private $template_variable_values = array ();
	private $template_variable_scope = array ();
	private $block_content = false;
	private $defaultTheme = "cyberluke.co.uk";
	private $defaultThemeMode = Engine :: ALLOW_ADMIN;
	private $defaultAdminTheme;
	private $adminThemeMode;
	private $mode; // current mode - master or slave
	private $master; // info about master
	/**#@-*/

	/**
	 * Number of defined positions, where the content can be placed.
	 */
	public static $content_positions = false;
	/**
	 * Static object variable of Encryption class.
	 *
	 * This object is created automaticaly by the {@link Engine} at {@link Boot}.
	 * You don't need to create anything - just use the methods of Encryption class
	 * <code>
	 * self :: $encryption = new Encryption(cipher, private_key, [mcrypt_mode]);
	 * </code>
	 * @var Encryption
	 */
	public static $encryption = null;

	public static $cache = null;

	public static function setFileRoot($root) {
		self :: $file_root = $root;
	}
	public static function getFileRoot() {
		return self :: $file_root;
	}
	public static function getPath($file) {
		global $Config;
		if (@ file_exists($file) === true)
			return $Config->getPath() . $file;
		else
			return $Config->getMaster() . $file;
	}
	public static function file_exists($file) {
		if (@ file_exists($file) === true)
			return true;
		else
			return @ file_exists(self :: getFileRoot() . $file);
	}

	/**
	 * Static method used to configure default values and create a singleton of {@link Engine} object.
	 *
	 * @param bool $do_debug
	 * @return Engine Engine reference for the use of public (non static) methods.
	 */
	public static function getInstance($do_debug = false) {
		if (self :: $instance === false) {
			Event :: Call("onBoot");
			self :: $instance = new Engine($do_debug);
		}
		return self :: $instance;
	}
	/**
	 * This method is useful for testing variables that can be remotely changed (eg. $_GET array).
	 *
	 * It protects from loading/executing files that are not in current script directory.
	 * If system detects that something is wrong, it will exit and display a nice message :-)
	 * @param var $var
	 */
	public static function TestPathSecurity($var) {
		if (is_array($var)) {
			foreach ($var as $var_item) {
				self :: TestPathSecurity($var_item);
			}
		}
		if (ereg("^%[^a-zA-Z0-9]", $var))
			exit ("<p>You are lame hacker!</p>"); //     /etc/passwd gives error
		if (ereg("%[^a-zA-Z0-9()_-]{2,}", $var))
			exit ("<p>You are lame hacker!</p>"); //     ./dir//file.inc gives error

	}

	/**
	 * This method uses {@link Redirect} method. It will call an error page with given error code.
	 *
	 * @param int $code
	 */
	public static function CallError($code) {
		Location :: Redirect("error.php?code=" . $code);
	}
	/**
	 * This function will convert the well-formed XML document in the file
	 * specified by filename to an object of class SimpleXMLElement(at this
	 * time). If any errors occur during file access or interpretation, the
	 * function returns false.
	 *
	 * @param string $filename
	 * @return object|false Returns an object that represents loaded XML file or
	 * false if any errors occur.
	 */
	public static function loadXML($filename) {
		if (strpos((string) $filename, ".") == 0)
			$path = (string) $filename;
		else
			$path = getcwd() . "/" . $filename;
		if (@ file_exists($path) && false !== ($xml = simplexml_load_file($path))) {
			return $xml;
		} else {
			exit ("ERROR Loading XML document located at: " . $path);
		}
	}
	private function __construct() {
		global $Config;
		i18n :: setLanguage($Config->getLanguage());
		$this->block_content = $this->content;
		Debug :: doDebug($Config->Debug());
		require_once ("core/sql/" . $Config->getLayer() . ".php");
		if (!isset ($_GET['module']))
			$_GET['module'] = "";
		if (!isset ($_GET['op']))
			$_GET['op'] = "";
		if (!isset ($_GET['file']))
			$_GET['file'] = "";
		if (!isset ($_GET['block']))
			$_GET['block'] = "";
		if (!isset ($_GET['offset']))
			$_GET['offset'] = 0;
		foreach ($_GET as $name => $var) {
			if ($name != 'query')
				self :: TestPathSecurity($var);
		}

		$this->prepareEncryption();

		self :: $content_positions = sizeof($this->content);

		Event :: registerHandler("onConnect", array (
			$this,
			"onConnect"
		));
		Event :: registerHandler("onExit", array (
			"Storage",
			"Write"
		));
		Event :: registerHandler("onDebugPrint", array (
			"Storage",
			"Write"
		));
		Event :: registerHandler("onExit", array (
			"Rewrite",
			"End"
		));

		Ajax :: Init();
	}

	private function preCache() {
		// users
		$TA = new TA();
		$TA->addQuery(TA :: SELECT, "ecp_engine_users");
		$TA->addParam("id");
		$TA->addParam("nick");
		$TA->addParam("name");
		$TA->addParam("email");
		$TA->addParam("mobile_email");
		$TA->addParam("group");
		$TA->addParam("language");
		$TA->addParam("picture");
		$TA->addParam("www");
		$TA->Execute();
		while ($author = $TA->Result()->FetchObject()) {
			Cache :: addObject('engine_users', $author->id, $author);
		}
		$TA->End();
		// users
	}
	/**
	 *
	 * @access private
	 */
	private function prepareEncryption() {
		global $Config;
		if ($Config->use_mcrypt())
			require_once ('core/mcrypt.php');
		else
			require_once ('core/' . $Config->getEncryption('cipher') . '.php');

		self :: $encryption = new Encryption($Config->getEncryption('cipher'), $Config->getEncryption('key'), $Config->getEncryption('mode'));
	}

	/**
	 * Sometimes (eg. in administration) you may want to not print some
	 * positions defined in current style (header,footer,specific columns). This
	 * can be done easily with the use of this method.
	 *
	 * @param int $pos
	 * @deprecated 2005-02-22
	 */
	public function blockContent($pos) {
		$this->block_content[(string) $pos] = true;
	}
	public function getServers() {
		if (isset ($this->_servers))
			return $this->_servers;
		$TA = new TA();
		$TA->addQuery(TA :: SELECT, "master");
		$servers = array ();
		$TA->Execute();
		while ($object = $TA->Result()->FetchObject()) {
			$servers[] = $object;
		}
		$TA->End();
		foreach ($servers as $server) {
			$result = DB :: Query("SELECT `value` FROM `" . $server->prefix . "_engine_config` WHERE `name`='pagetitle' LIMIT 1;");
			$server->pagetitle = DB :: FetchObject($result)->value;
		}
		$this->_servers = $servers;
		return $servers;
	}
	/**
	 * @return string Returns current runLevel (mode) of this site.Mode can be
	 * currently a 'master' or 'slave'.
	 */
	public function getMode() {
		return $this->mode;
	}
	/**
	 * This method checks the query and changes it so it reflects the right
	 * format that is used with current server mode.
	 *
	 * @return string Returns new query;
	 * @deprecated 2005-02-23
	 */
	public function processQuery($original_query) {
		$new_query = $original_query;
		/*if (!$ECPInstallModeOn) {
		$prefix = false;
		if (isset ($this->master) && !empty ($this->mode) && ($this->mode != "master" || isset ($_GET['site']))) {
		$prefix = $this->master->prefix;
		}
		else
		if (DB::$prefix != "ecp") {
		$prefix = DB::$prefix;
		}
		if ($prefix !== false) {
		$query = explode(" ", $original_query);
		$shared = explode(";", $this->master->shared);
		// search for table name in query
		$x = 0;
		for ($i = 0; $i < sizeof($query); $i ++) {
		if (false !== strpos($query[$i], DB::$prefix."_")) {
		$x = $i;
		break;
		}
		}
		$query[$x] = str_replace("`", "", $query[$x]);
		$table = explode("ecp_", $query[$x]);
		// if this table is shared from master or prefix is not 'ecp'
		if (in_array($table[sizeof($table) - 1], $shared) || $prefix == DB::$prefix) {
		$new_query = "";
		for ($i = 0; $i < sizeof($query); $i ++) {
		if ($i == $x) {
		$query[$i] = "`".$prefix."_".$table[sizeof($table) - 1]."`";
		}
		$new_query .= $query[$i]." ";
		}
		}
		}

		}*/
		return $new_query;
	}

	public function getMaster() {
		return $this->master;
	}
	public function getServer() {
		return $this->server;
	}
	/**
	 * Event handler invoked when the connection to database has been
	 * estabilished and thus can be used.
	 */
	public function onConnect() {
		Storage :: INIT();
		Perspective :: readFromDatabase();
		$TA = new TA();
		$TA->addQuery(TA :: SELECT, "master");
		$TA->WHERE("level='master'");
		$TA->LIMIT(1);
		$TA->Execute();
		$object = $TA->Result()->FetchObject();
		$TA->removeQuery();
		$this->master = $object;

		$TA->addQuery(TA :: SELECT, "master");
		$TA->WHERE("prefix='" . DB :: $prefix . "'");
		$TA->LIMIT(1);
		$TA->Execute();
		$object = $TA->Result()->FetchObject();
		$this->server = $object;
		$TA->End();
		if ($object->level == "master")
			$this->mode = "master";
		else
			$this->mode = "slave";

		// loads the default site theme
		try {
			if (isset ($_GET['style'])) {
				$this->defaultTheme = $_GET['style'];
				Storage :: Save('style', $_GET['style'], Storage :: USER, Storage :: WEEK);
			} else {
				$this->defaultTheme = Storage :: Load('style', Storage :: USER, Storage :: WEEK);
			}
		} catch (StorageException $e) {
			$this->defaultTheme = Storage :: Load("theme");
			Cache :: addObject("javascript", "usePortableTheme", "true");
		}
		// loads the default site ADMIN theme
		$this->defaultAdminTheme = Storage :: Load("admin_theme");
		// reads the adminThemeMode value
		$this->adminThemeMode = Storage :: Load("admin_theme_mode");
		// loads page title
		Page :: setTitle(Storage :: Load("pagetitle"));

		// loads current theme content behavior
		$xml = Engine :: loadXML("/styles/" . $this->getDefaultTheme() . "/main.xml");
		if (isset ($xml->content_behavior)) {
			for ($i = 0; isset ($xml->content_behavior-> {
				"position_" . $i }); $i++) {
				foreach ($xml->content_behavior-> {
					"position_" . $i }
				as $behavior) {
					$this->content_behavior[$i] = $behavior;
				}
			}
		}
		$this->preCache();
		$serverName = Storage :: Load('server');
		Mailer :: newInstance('noreply@' . $serverName, $serverName);
	}

	private function _loadContent($number) {
		Renderer :: PrintContent($number);
	}

	public function getContent() {
		$_content = '';
		$ECP = Engine :: getInstance();
		foreach ($this->content as $content_number => $_templates) {
			$_vars = array ();
			foreach ($_templates as $key => $_ECP_template_content) {
				$_ECP_string = explode(';', $_ECP_template_content);
				// content is an existing file (=include it)
				if (Engine :: file_exists($_ECP_string[0]) && strpos($_ECP_string[0], ".php")) {
					foreach ($this->template_variables as $key => $variable) {
						if ($this->template_variable_scope[$key] == $_ECP_string[0] . ";" . $_ECP_string[1]) {
							${ $variable } = $this->template_variable_values[$key];
							$_vars[] = $variable;
						}
					}

					// INCLUDE CONTENT FILE
					// REWRITE AND CACHE TEMPLATE FILES
					$rewriteTemplate = Template :: getFileName($_ECP_string[0]);
					if (@ file_exists($rewriteTemplate))
						$_ECP_string[0] = $rewriteTemplate;

					$_content_2 = ob_get_contents();
					ob_end_clean();
					ob_start();
					require ($_ECP_string[0]);
					$_content .= ob_get_contents();
					ob_end_clean();
					ob_start();
					echo $_content_2;
				}
			}
			foreach ($_vars as $variable) {
				unset ($variable);
			}
		}
		return $_content;
	}
	/**
	 * There are some undocumented block-style features, which will be documented in future tutorials.
	 *
	 * @param int $number Number of place which will be printed in current place. Default values are : header=0,left side=1,main content=2,right side=3,footer=4 and top side(under the header)=5.
	 */
	public function printContent($_ECP_number, $_currentModule = false) {
		global $XCS, $ECP;

		if (!ModulesManager :: isEnabled($_currentModule))
			return false;

		if (Engine :: getFlag("output") === true) {
			if ($_ECP_number != 2)
				$this->_loadContent(2);
			$this->_loadContent($_ECP_number);
		}
		$_ECP_block_file = "styles/" . $this->GetDefaultTheme() . "/block.php";
		$_ECP_block_file_exists = Engine :: file_exists($_ECP_block_file);
		// module start for actual content number
		$_ECP_module_start = "styles/" . $this->GetDefaultTheme() . "/module_start_" . $_ECP_number . ".php";
		$_ECP_module_start_exists = Engine :: file_exists($_ECP_module_start);
		if (!$_ECP_module_start_exists) {
			// module start for all content numbers
			$_ECP_module_start = "styles/" . $this->GetDefaultTheme() . "/module_start.php";
			$_ECP_module_start_exists = Engine :: file_exists($_ECP_module_start);
		}
		// module end for actual content number
		$_ECP_module_end = "styles/" . $this->GetDefaultTheme() . "/module_end_" . $_ECP_number . ".php";
		$_ECP_module_end_exists = Engine :: file_exists($_ECP_module_end);
		if (!$_ECP_module_end_exists) {
			// module end for all content numbers
			$_ECP_module_end = "styles/" . $this->GetDefaultTheme() . "/module_end.php";
			$_ECP_module_end_exists = Engine :: file_exists($_ECP_module_end);
		}
		if ($_ECP_block_file_exists) {
			if (false !== ($file = fopen(Engine :: getFileRoot() . $_ECP_block_file, "r"))) {
				$_ECP_fcontent = fread($file, filesize(Engine :: getFileRoot() . $_ECP_block_file));
				fclose($file);
				$_ECP_fcontent = explode("{CONTENT}", $_ECP_fcontent);
			}
		} else
			if (!isset ($_ECP_fcontent)) {
				$_ECP_fcontent = array (
					"",
					""
				);
			}
		$this->lastSource = false;
		$_ECP_i = 0;
		if ($_currentModule === false) {
			echo '<div id="ecp_c' . $_ECP_number . '">';
		}
		if (!isset ($this->content[$_ECP_number]))
			exit ('content doesn\'t exists (' . $_ECP_number . ')');
		$currentModule = null;
		foreach ($this->content[$_ECP_number] as $key => $_ECP_template_content) {
			$_ECP_i++;
			$_ECP_string = explode(';', $_ECP_template_content);
			// content is an existing file (=include it)
			if (Engine :: file_exists($_ECP_string[0]) && strpos($_ECP_string[0], ".php")) {
				foreach ($this->template_variables as $key => $variable) {
					if ($this->template_variable_scope[$key] == $_ECP_string[0] . ";" . $_ECP_string[1]) {
						${ $variable } = $this->template_variable_values[$key];
					}
				}
				if ($_ECP_module_start_exists && $_ECP_module_end_exists && is_module($currentModule)) {
					if ($this->lastSource === false && $_ECP_string[3] == 1) {
						include ($_ECP_module_start);
					} else
						if ($this->lastSource[2] != $_ECP_string[2]) {
							if ($this->lastSource[3] == 1) {
								include ($_ECP_module_end);
							}
							if ($_ECP_i <= sizeof($this->content[$_ECP_number]) && $_ECP_string[3] == 1) {
								include ($_ECP_module_start);
							}
						}
				}

				echo $_ECP_fcontent[0]; // block.php start

				// INCLUDE CONTENT FILE
				// REWRITE AND CACHE TEMPLATE FILES
				$rewriteTemplate = Template :: getFileName($_ECP_string[0]);
				if (@ file_exists($rewriteTemplate))
					$_ECP_string[0] = $rewriteTemplate;

				if (is_module($currentModule))
					Engine :: setFlag('currentModule', $currentModule);
				require ($_ECP_string[0]);
				//unset ($_GET['___moduleRewrite___']);

				echo $_ECP_fcontent[1]; // block.php end
				if ($_ECP_module_start_exists && $_ECP_module_end_exists && is_module($currentModule)) {
					if ($_ECP_string[3] == 1) {
						if ($_ECP_i >= sizeof($this->content[$_ECP_number])) {
							include ($_ECP_module_end);
						}
					}
				}
				$this->lastSource = $_ECP_string;
			} else {
				echo $_ECP_fcontent[0]; // block.php start
				echo $_ECP_template_content; // print the content (plain text)
				echo $_ECP_fcontent[1]; // block.php end
			}
		}
		if ($_currentModule === false) {
			echo '</div>';
		}

	}

	/**
	 * This AJAX method verifies the user with the help of Captcha protection
	 */
	public function VerifyUser($callFunction = false) {
		global $Config;

		try {
			if ($callFunction === false) {
				$callFunction = Ajax :: getClientFunction();
			}
			//$verifyCode = Storage :: Load('ecp_user_verified', Storage :: USER);
			$verifyCode = Session :: getSID();
			$UA = new Net_UserAgent_Detect();
			if (strpos('verification:', $verifyCode) !== false && strpos($Config->GetMaster(), $verifyCode) !== false && strpos($UA->getBrowserString(), $verifyCode) !== false && strpos($UA->getOSString(), $verifyCode) !== false) {
				throw new StorageException;
			}
			if ($callFunction !== false && Storage :: Load('captcha') == '1') {
				Ajax :: Action(TabCallFunction :: getBehavior($callFunction, false));
			}
			Storage :: Delete('captcha');
			Storage :: Write();
		} catch (StorageException $e) {
			if ($callFunction === false) {
				Engine :: CallError(401);
			}

			Storage :: Save('ecp_captcha_call', $callFunction, Storage :: USER);
			Storage :: Write();
			Ajax :: Action(TabCallFunction :: getBehavior('displayECPWindow', $Config->getMaster() . 'captcha.php'));
		}

		$retval = Ajax :: ReturnValue(false);
		if (!empty ($retval) && $retval !== false)
			throw new AjaxFlushException($retval);
	}
	public function VerifyCode($code) {
		global $Config;

		if (PhpCaptcha :: Validate($code)) {
			try {
				$callFunction = Storage :: Load('ecp_captcha_call', Storage :: USER);
				Ajax :: Action(TabEval :: getBehavior("parent.closeit();"));
				Ajax :: Action(TabEval :: getBehavior("parent." . $callFunction . "();"));
				Session :: generateSID();
				Storage :: Save('userid', 0);
				Storage :: Save('nick', 'Anonymous');
				Storage :: Save('captcha', '1');
				Storage :: Write();
			} catch (StorageException $e) {
				Ajax :: Action(TabAlert :: getBehavior($this->localeString('captcha', 'wrongcode')));
				Ajax :: Action(TabEval :: getBehavior('window.location.reload();'));
			}
		} else {
			Ajax :: Action(TabAlert :: getBehavior($this->localeString('captcha', 'wrongcode')));
			Ajax :: Action(TabEval :: getBehavior('window.location.reload();'));
		}

		return Ajax :: ReturnValue(true);
	}

	public static function generateUniqueToken() {
		global $Config;

		$UA = new Net_UserAgent_Detect();
		$token = 'verification:' . User :: $profile->id . uniqid($Config->getMaster(), true) . $UA->getBrowserString() . $UA->getOSString();
		return base64_encode($token);
	}
	public function GetPage($Location) {
		ob_end_clean();
		$Location = str_replace('#', '', $Location);
		echo "+:TabRedirect|" . $Location;
		exit ();
	}
	public function SendContent($_ECP_content, $_link = false, $_oldSource = false, $_template_file = false) {
		global $XCS, $ECP, $currentModule;

		$_theme_path = "styles/" . $this->getDefaultTheme() . "/";
		if ($_template_file !== false && @ file_exists($_theme_path . $_template_file)) {
			if (false !== ($file = fopen($_theme_path . $_template_file, "r"))) {
				$_ECP_fcontent = fread($file, filesize($_theme_path . $_template_file));
				fclose($file);
				$_ECP_fcontent = explode("{CONTENT}", $_ECP_fcontent);
			}
		} else {
			$_ECP_fcontent = array (
				'',
				''
			);
		}
		try {
			$currentModule = ModulesManager :: loadModule($_GET['module']);
		} catch (NoModuleException $e) {
			exit ('Module Exception: ' . $e->getMessage());
		}

		Engine :: setFlag('currentModule', $currentModule);
		if (isset ($_POST['rsargs'])) {
			if (sizeof($_POST['rsargs']) == 3) {
				$encodedPostData = TinyAjax :: decode($_POST['rsargs'][sizeof($_POST['rsargs']) - 1]);
				if ($encodedPostData && !Engine :: getFlag('launchParam'))
					Engine :: setFlag('launchParam', $encodedPostData);
			} else {
				if (!Engine :: getFlag('launchParam'))
					Engine :: setFlag('launchParam', Ajax :: getPostData());
			}
		}

		if (is_numeric($_ECP_content)) {
			$_ECP_DIV = "ecp_c" . $_ECP_content;
		} else {
			$_ECP_DIV = explode(":", $_ECP_content);
			if (sizeof($_ECP_DIV) != 2)
				exit ('invalid length');

			$_ECP_content = $_ECP_DIV[1];
			$_ECP_DIV = $_ECP_DIV[0];
		}

		ob_end_clean();
		Renderer :: setRenderingNode($_ECP_DIV);
		try {
			ModulesManager :: launchState($currentModule);
			ob_end_clean();
			ob_start();
			echo "TabInnerHtml|" . $_ECP_DIV . "|";
			echo $_ECP_fcontent[0];
			// print only current module
			ModulesManager :: disableAll();
			ModulesManager :: enableModule($currentModule);
			$this->printContent($_ECP_content, $currentModule);
			echo $_ECP_fcontent[1];
			$Title=Page :: getTitle();
			if (!empty($Title)) {
				echo "~TabSetTitle|" . $Title . "|";
			}
			Rewrite :: End();
		} catch (AjaxFlushException $e) {
			$Title=Page :: getTitle();
			if (!empty($Title)) {
				echo "~TabSetTitle|" . $Title . "|";
			}
			Rewrite :: End();
		}

		exit;
	}

	/**
	 * This method registers a variable, which can be then used in your template file.
	 *
	 * @param mixed $value Value that will be used in your template file.
	 * @param string $variable Name which will carry the value $value in your template file.
	 * @param string $file Name of file that matches to your template filename (previously registered with {@link AddContent}).
	 */
	public function registerVariable($value, $variable, $file) {
		$file = $file . ";" . $this->unique_content_file;
		array_push($this->template_variables, $variable);
		array_push($this->template_variable_values, $value);
		array_push($this->template_variable_scope, $file);
	}
	public static function setFlag($name, $value) {
		self :: $flags[$name] = $value;
	}
	public static function getFlag($name) {
		if (isset (self :: $flags[$name]))
			return self :: $flags[$name];
		else
			return false;
	}

	/**
	 * This method adds a content to position that corresponds with {@link PrintContent}.
	 *
	 * Use this method to add some data which will be then printed OR if you pass a template filename to $content parametr,
	 * you can that start adding dynamic variables which you can use in your static template. See {@link RegisterVariable()} for details.
	 * @see PrintContent()
	 * @param mixed $content Data or template filename that will be printed in desired position.
	 * @param int $number Position, where the content will be printed.
	 * @param string $source Unique identificator that will tell the
	 * printContent method when to encapsulate printed content with
	 * module_start.php and module_end.php files of current style.
	 */
	public function addContent($content, $number, $source = "", $display_border = 1) {
		if ($number > sizeof($this->content))
			$number = sizeof($this->content);
		if (Engine :: file_exists($content) === true && strpos($content, ".php")) {
			$this->unique_content_file++;
			$content .= ";" . $this->unique_content_file;
			$content .= ";" . $source;
			$content .= ";" . $display_border;
		}
		$this->content[$number][] = $content;
	}
	public function ArrayToObject($array, $recursive = false) {
		$object = new StdClass();
		foreach ($array as $name => $value) {
			if ($recursive && is_array($value)) {
				$value = $this->ArrayToObject($value, $recursive);
			}
			$object-> {
				$name }
			= $value;
		}
		return $object;
	}
	public function ArrayToObjectRecursive($array) {
		return $this->ArrayToObject($array, true);
	}
	/**
	 *
	 * @return string Returns current theme/style.
	 */
	public function getDefaultTheme($mode = false) {
		if ($mode === false)
			$mode = $this->getDefaultThemeMode();
		if (User :: inAdmin() && $mode == Engine :: ALLOW_ADMIN) {
			if ($this->getAdminThemeMode() == 1) {
				return $this->getDefaultAdminTheme();
			} else
				if ($this->getAdminThemeMode() == 2) {
					if (Engine :: file_exists("styles/" . $this->defaultTheme . "/_admin/index.php"))
						return $this->defaultTheme . "/_admin";
					else
						return $this->getDefaultAdminTheme();

				} else
					if ($this->getAdminThemeMode() == 3) {
						if (Engine :: file_exists("styles/" . $this->defaultTheme . "/_admin/index.php"))
							return $this->defaultTheme . "/_admin";
						else
							return $this->defaultTheme;
					}
		} else {
			return $this->defaultTheme;
		}
	}
	public function getDefaultThemeMode() {
		return $this->defaultThemeMode;
	}
	public function setDefaultThemeMode($mode) {
		$this->defaultThemeMode = $mode;
	}
	/**
	 *
	 * @return string Returns current theme/style for Administration interface.
	 */
	public function getDefaultAdminTheme() {
		return $this->defaultAdminTheme;
	}
	public function getAdminThemeMode() {
		return $this->adminThemeMode;
	}
	/**
	 *
	 * @return string Returns relative path to current theme folder eg.
	 * styles/my_theme/
	 */
	public function getThemePath() {
		global $Config;
		return $Config->getPath() . "styles/" . $this->getDefaultTheme() . "/";
	}

	/**
	*
	* @return int Returns the size of content = maximal number you can pass to
	* addContent() methods or similar.
	*/
	public function getContentSize() {
		return sizeof($this->content);
	}
	/**
	 * @return mixed Returns the content behavior for current position in current theme (vertical or horizontal at this time) or FALSE on error.
	 */
	public function getContentBehavior($pos) {
		if (isset ($this->content_behavior[$pos]))
			return $this->content_behavior[$pos];
		else
			return false;
	}
	/**
	 * @param int Position at which should be searched.
	 * @return int $pos Returns the biggest height number for specified
	 * position.
	 */
	public function getMaxHeight($pos) {
		$height = 0;
		$get_modules = ModulesManager :: loadModule("get_modules");
		foreach (ModulesManager :: getModules() as $Module) {
			if ($Module->getHeight() > $height && $Module->getPosition() == $pos && $get_modules->object->getOutput($Module->getName()) == 1) {
				//if ($Module->getHeight() > $height && $Module->getPosition() == $pos)
				$height = $Module->getHeight();
			}
		}
		return $height;
	}

	public function localeString($namespace, $id, $locales = false) {
		return i18n :: TranslateDEPRECATED($namespace, $id, $locales = false);
	}
	/**
	 * This method reads ecp_engine_ranks table and returns group names in an array.
	 *
	 * @return array an array of objects (this object has same properties as
	 * in the ecp_engine_ranks table - eg. object->group and object->rank at this time)
	 */
	public function getGroupNames() {
		$TA = new TA();
		$TA->addQuery(TA :: SELECT, "ecp_engine_ranks");
		$TA->ORDER("rank", TA :: ASCENDING);
		$TA->Execute();
		$array = array ();

		while ($object = $TA->Result()->FetchObject()) {
			$array[] = $object;
		}
		$TA->End();

		$object->rank = $this->localeString("engine", "group0");
		$object->group = 0;
		$array[] = $object;

		return $array;
	}
	/**
	 * Searches for group's name by ID and returns this name as a string.
	 *
	 *
	 * @param int $group_id Group ID
	 * @return string Returns the group name or FALSE
	 */
	public function getGroupName($group_id) {
		$TA = new TA();
		$TA->addQuery(TA :: SELECT, "ecp_engine_ranks");
		$TA->WHERE("`group`=" . $group_id);
		$TA->LIMIT(1);
		$TA->Execute();
		$object = $TA->Result()->FetchObject();

		if ($object)
			$retval = $object->rank;
		else
			$retval = $this->localeString("engine", "group0");

		return $retval;
	}

	public function getSiteIndex($extension = 'php') {
		$file = 'styles/' . $this->getDefaultTheme() . '/index.' . $extension;
		if (@ file_exists($file)) {
			return $file;
		} else {
			throw new Exception;
		}
	}

	public function insertObject($path, $type, $width = "auto", $height = "auto", $alt = 'image') {
		$retval = "";
		if ($type == "swf") {
			$id = String :: createRandomWord(3);
			$retval .= '<span id="' . $id . '">&nbsp;</span><script type="text/javascript">// <![CDATA[var myObject = new FlashObject("' . $path . '", "' . $id . '", "' . $width . '", "' . $height . '", "7", "#000000");myObject.write("' . $id . '");]]></script>';
		} else {
			if ($width == 'auto' || $height == 'auto')
				$retval .= '<img src="' . $path . '" alt="' . $alt . '" />';
			else
				$retval .= '<img src="' . $path . '" alt="' . $alt . '" width="' . $width . '" height="' . $height . '" />';
		}
		return $retval;
	}
	/**
	 * @return string Returns information about Engine version and a short
	 * description.
	 */
	public function toString() {
		return 'ECP (EliteCore Project) v' . $this->version . ' - Luke \'CyberLuke\' Satin (c)' . date("Y") . ' all rights reserved';
	}
}

$Config = new Config();
require_once ('core/mime.php');
$XCS = $ECP = Engine :: getInstance();
?>



See more files for this project here

ECP (EliteCore Project)

EliteCore Project is a PHP5.1/Javascript/AJAX/XHTML/CSS framework for creating WEB 2.0 applications and services.The basic open-source instalation can be also used as an interactive personal page or BLOG.This project uses the latest features available.

Project homepage: http://sourceforge.net/projects/elitecore
Programming language(s): JavaScript,PHP,XML
License: cpl

  debug/
    content.php
  exceptions/
    ajaxflush.php
    nomodule.php
    undefineddata.php
  interface/
    encryption.php
    form.php
    module_class.php
    session_interface.php
  renderers/
    default.php
  sql/
    mysql.php
    mysqli.php
  themes/
    ECP/
      accept.png
      add.png
      alt_star.gif
      anchor.png
      arrow_refresh.png
      asterisk_orange.png
      asterisk_yellow.png
      attach.png
      back.png
      cog_error.png
      cog_go.png
      comment.png
      comment_add.png
      comment_delete.png
      comment_edit.png
      comments.png
      comments_add.png
      comments_delete.png
      control_play_blue.png
      drive.png
      gnome-fs-directory.png
      gnome-mime-audio.png
      layers.png
      layout.png
      layout_add.png
      layout_content.png
      layout_delete.png
      layout_edit.png
      layout_error.png
      layout_header.png
      layout_link.png
      layout_sidebar.png
      lightbulb.png
      lightbulb_add.png
      lightbulb_delete.png
      lightbulb_off.png
      lightning.png
      lightning_add.png
      lightning_delete.png
      lightning_go.png
      link.png
      link_add.png
      link_break.png
      link_delete.png
      link_edit.png
      link_error.png
      link_go.png
      lock.png
      lock_add.png
      lock_break.png
      lock_delete.png
      lock_edit.png
      lock_go.png
      lock_open.png
      newspaper.png
      newspaper_add.png
      newspaper_delete.png
      newspaper_go.png
      newspaper_link.png
      note.gif
      note.png
      note_add.png
      note_delete.gif
      note_delete.png
      note_edit.png
      note_error.png
      note_go.png
      note_new.gif
      overlays.png
      package.png
      package_add.png
      package_delete.png
      package_go.png
      package_green.png
      package_link.png
      page.gif
      page.png
      page_add.png
      page_attach.png
      page_code.png
      page_copy.png
      page_delete.png
      page_edit.png
      page_error.png
      page_excel.png
      page_find.png
      page_gear.png
      page_go.png
      page_green.png
      page_key.png
      page_lightning.png
      page_link.png
      page_paintbrush.png
      page_paste.png
      page_red.png
      page_refresh.png
      page_save.png
      page_white.png
      pencil.png
      pencil_add.png
      pencil_delete.png
      pencil_go.png
      photo.png
      photo_add.png
      photo_delete.png
      photo_link.png
      photos.png
      picture.png
      picture_add.png
      picture_delete.png
      picture_edit.png
      picture_empty.png
      picture_error.png
      picture_go.png
      picture_key.png
      picture_link.png
      picture_save.png
      pictures.png
      plugin.png
      plugin_add.png
      plugin_delete.png
      plugin_disabled.png
      plugin_edit.png
      plugin_error.png
      plugin_go.png
      plugin_link.png
      report.png
      report_add.png
      report_delete.png
      report_disk.png
      report_edit.png
      report_go.png
      report_key.png
      report_link.png
      report_magnify.png
      report_picture.png
      report_user.png
      report_word.png
      script.png
      script_add.png
      script_code.png
      script_code_red.png
      script_delete.png
      script_edit.png
      script_error.png
      script_gear.png
      script_go.png
      script_key.png
      script_lightning.png
      script_link.png
      script_palette.png
      script_save.png
      star.png
      star_rating.gif
      stop.png
      style.png
      text_align_center.png
      text_align_justify.png
      text_align_left.png
      text_align_right.png
      text_allcaps.png
      text_bold.png
      text_columns.png
      text_dropcaps.png
      text_heading_1.png
      text_heading_2.png
      text_heading_3.png
      text_heading_4.png
      text_heading_5.png
      text_heading_6.png
      text_horizontalrule.png
      text_indent.png
      text_indent_remove.png
      text_italic.png
      text_kerning.png
      text_letter_omega.png
      text_letterspacing.png
      text_linespacing.png
      text_list_bullets.png
      text_list_numbers.png
      text_lowercase.png
      text_padding_bottom.png
      text_padding_left.png
      text_padding_right.png
      text_padding_top.png
      text_replace.png
      text_signature.png
      text_smallcaps.png
      text_strikethrough.png
      text_subscript.png
      text_superscript.png
      text_underline.png
      text_uppercase.png
      textfield.png
      textfield_add.png
      textfield_delete.png
      textfield_key.png
      textfield_rename.png
      tux.png
      vert_star.gif
    ECP.xml
  Icon.php
  Location.php
  Module.php
  ModulesManager.php
  MusicTags.php
  Page.php
  XHTMLParser.php
  XMLForms.php
  ajax.php
  author.html
  cache.php
  config.php
  date.php
  db.php
  debug.php
  ecp-full.php
  ecp-mini.php
  engine.php
  events.php
  filesystem.php
  footer.html
  i18n.php
  mailer.php
  main.css
  mcrypt.php
  mime.php
  mod_rewrite.php
  perspective.php
  rc4.php
  reflection.php
  session_passport.php
  storage.php
  string.php
  template.php
  texy.php
  user.php
  user_cache.php
  wysiwyg_texy.php
  xhtml_form.php
  xtea.php