All pastes #792273 Raw Edit

Stuff

public text v1 · immutable
·published 2007-11-21 08:03 UTC
rendered paste body
<?php

// -------------------------------------------------------------
// liquid application framework.
// Copyright (C) 2007 DNA
//
// INSERT LICENSE INFO HERE
// -------------------------------------------------------------

ini_set('error_reporting', E_ALL);

include 'class.plugin.php';

class liquid
{
	// Liquid Plugins
	static $plugin_manager; 
	// Applications installed.
	static $liquid_apps; 
		
	public function __construct ()
	{
		// Initialize variables.
		$this->_plugin_manager = null;
		$this->_conf = null;
	}

	/* Executes the liquid framework. */
	public function execute ()
	{
		/* LOAD LIQUID APPLICATION FRAMEWORK CONFIGURATION FROM DATABASE */
		global $liquid_config;
		
		$cfg = liquid::load_configuration();
		$database = Singleton::instance('Database');
	
		$database->query('SELECT config_key, config_value FROM liquid_config');

		while($row = $database->fetch_assoc())
		{
			$cfg[$row['config_key']] = $row['config_value'];

		}

		$liquid_config = $cfg;
		/* END LOAD CONFIGURATION */
		
		/* GET HTTP $_GET VALUES FROM CLEAN URL */
		$http_vars = liquid::get_http_vars();

		/* LOAD APPLICATIONS.  If no application is selected, launch default application.
		 * Make sure the application is enabled.
		 */
		$database->query('SELECT app_name, app_enabled FROM liquid_applications');

		while ($row = $database->fetch_assoc())
		{
			if($row['app_enabled'])
				$liquid_config['apps'][] = $row['app_name'];
		}

		if (in_array($http_vars[0], $liquid_config['apps']))
			liquid::run_application($http_vars[0]);
		else
			liquid::run_application(liquid::get_default_application());
	}

	/* Loads configuration for liquid from the configuration file */	
	static function load_configuration ()
	{
		if (file_exists('conf/config.php'))
		{
			if (!include('conf/config.php'))
			{
				die('Configuration file could not be found, please install or reinstall liquid!');
			}
		}
		else
		{
			die('Configuration file could not be found, please install or reinstall liquid!');
		}
				
		return $cfg;
	}
	
	/* Gets all variables in the URL */
	static function get_http_vars ()
	{
		$ret_vars = null; // Initialize return array.

		if(isset($_GET['url']))
		{
			$ret_vars = explode('/', $_GET['url']);			
		}

		return $ret_vars;
	}

	/* Returns the default application */
	static function get_default_application ()
	{
		global $liquid_config; 

		return $liquid_config['config_default_app'];
	}

	/* Runs an an application based off of $application */
	static function run_application ( $application )
	{
		$return_var = null;

		$app_file = 'apps/' . $application . '/application.php';

		if (file_exists($app_file))
		{
			if (!include($app_file))
			{
				die('Application Class for ' . $application . ' could not be found!');
			}

			if (class_exists('Application')) 
			{
				$app_obj = new Application ();
			}
			else
			{
				die('Application Class for ' . $application . ' could not be found!');
			}
		}
		else
		{
			die('Application Class for ' . $application . ' could not be found!');
		}

		return $return_var;
	}
}
?>