<commit_before><?php
/**
 * The file that defines the Controller class.
 *
 * @author <NAME> (JadeIT cc) <<EMAIL>> - initial API and implementation
 * @copyright Copyright (c) 2009 JadeIT cc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available {@link http://www.eclipse.org/legal/epl-v10.html here}
 * @license http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0
 * @package Core
 */

/**
 * The main controller for the Backend
 *
 */
class Controller {
	public static $debug;

	public static $area = 'home';
	public static $action = 'index';

	public static $parameters = array();
	
	//TODO move this to the config or Application class
	public static $salt = false;
	public static $view = false;
		
	protected static $started = false;
	protected static $init = false;
	
	public static $firephp = false;
	
	public static function serve(array $info = array()) {
		self::init();
		self::start();
		list ($controller, $result) = self::action();
		self::display($controller, $result);
		self::finish();
	}

	public static function init() {
		if (!self::$init) {
			session_set_cookie_params(0, WEB_SUB_FOLDER, null, null, true);
			session_name('Controller');
			session_start();

			date_default_timezone_set('Africa/Johannesburg');

			self::check_quotes();
			self::$salt = Backend::getConfig('application.salt', 'Change this to something random!');

			$user = BackendAccount::checkUser();
			//Debugging
			self::$debug = false;
			if (SITE_STATE != 'production' || ($user && in_array('superadmin', $user->roles))) {
				switch (true) {
					case array_key_exists('debug', $_REQUEST):
						//Default to lowest level
						self::$debug = is_numeric($_REQUEST['debug']) ? (int)$_REQUEST['debug'] : 1;
						break;
				}
			}

			Backend::add('debug', self::$debug);
			if (SITE_STATE != 'production' || self::$debug) {
				ini_set('display_errors', 1);
				ini_set('error_reporting', E_ALL | E_STRICT);
			} else {
				ini_set('display_errors', 0);
			}

			$query = Request::getQuery();
			$query = Hook::run('init', 'pre', array($query));
			self::parseQuery($query);

			//View
			self::$view = self::getView();
			if (!self::$view instanceof View) {
				die('Unrecognized Request');
			}

			//Sessions
			if (array_key_exists('error', $_SESSION)) {
				Backend::setError($_SESSION['error']);
			}
			if (array_key_exists('notice', $_SESSION)) {
				Backend::setNotice($_SESSION['notice']);
			}
			if (array_key_exists('success', $_SESSION)) {
				Backend::setSuccess($_SESSION['success']);
			}
			
			Hook::run('init', 'post');
			self::$init = true;
		}
	}

	/**
	 * Startup the application by parsing the query, etc
	 *<commit_msg>Allow Backend::init to add messages<commit_after><?php
/**
 * The file that defines the Controller class.
 *
 * @author <NAME> (JadeIT cc) <<EMAIL>> - initial API and implementation
 * @copyright Copyright (c) 2009 JadeIT cc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available {@link http://www.eclipse.org/legal/epl-v10.html here}
 * @license http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0
 * @package Core
 */

/**
 * The main controller for the Backend
 *
 */
class Controller {
	public static $debug;

	public static $area = 'home';
	public static $action = 'index';

	public static $parameters = array();
	
	//TODO move this to the config or Application class
	public static $salt = false;
	public static $view = false;
		
	protected static $started = false;
	protected static $init = false;
	
	public static $firephp = false;
	
	public static function serve(array $info = array()) {
		self::init();
		self::start();
		list ($controller, $result) = self::action();
		self::display($controller, $result);
		self::finish();
	}

	public static function init() {
		if (!self::$init) {
			session_set_cookie_params(0, WEB_SUB_FOLDER, null, null, true);
			session_name('Controller');
			session_start();

			date_default_timezone_set('Africa/Johannesburg');

			self::check_quotes();
			self::$salt = Backend::getConfig('application.salt', 'Change this to something random!');

			$user = BackendAccount::checkUser();
			//Debugging
			self::$debug = false;
			if (SITE_STATE != 'production' || ($user && in_array('superadmin', $user->roles))) {
				switch (true) {
					case array_key_exists('debug', $_REQUEST):
						//Default to lowest level
						self::$debug = is_numeric($_REQUEST['debug']) ? (int)$_REQUEST['debug'] : 1;
						break;
				}
			}

			Backend::add('debug', self::$debug);
			if (SITE_STATE != 'production' || self::$debug) {
				ini_set('display_errors', 1);
				ini_set('error_reporting', E_ALL | E_STRICT);
			} else {
				ini_set('display_errors', 0);
			}

			$query = Request::getQuery();
			$query = Hook::run('init', 'pre', array($query));
			self::parseQuery($query);

			//View
			self::$view = self::getView();
			if (!self::$view instanceof View) {
				die('Unrecognized Request');
			}

			//Sessions
			if (array_key_exists('error', $_SESSION)) {
				Backend::addError($_SESSION['error']);
			}
			if (array_key_exists('notice', $_SESSION)) {
				Backend::addNotice($_SESSION['notice']);
			}
			if (array_key_exists('success', $_SESSION)) {
				Backend::addSuccess($_SESSION['success']);
			}
			
			Hook::run('init', 'post');
			self::$init = true;
		}
	}

	/**
	 * Startup the application by parsing the query, etc
	 *
{'fraction_non_alphanumeric': 0.16092362344582592, 'fraction_numerical': 0.005683836589698046, 'mean_word_length': 3.996450754214729, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1750068', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1741, 'n_words': 466}