From 1ead4c9d59cd309ccdbb1ee651848a1a0b0035ee Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 21 Sep 2015 21:02:27 +0100 Subject: [PATCH] *Everything is broken!* Begin converting everything over to a new environment object. Currently only the core has been converted. --- core.php | 57 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/core.php b/core.php index 5b2005b..b09b566 100644 --- a/core.php +++ b/core.php @@ -7,53 +7,63 @@ $start_time = time(true); /////////////// Do not edit below this line unless you know what you are doing! /////////////// /////////////////////////////////////////////////////////////////////////////////////////////// $version = "0.7"; +$env = new stdClass(); +$env->action = $settings->defaultaction; +$env->page = ""; +$env->user = "Anonymous"; +$env->is_logged_in = false; +$env->is_admin = false; + session_start(); ///////// Login System ///////// -//clear expired sessions +// Clear expired sessions if(isset($_SESSION["$settings->sessionprefix-expiretime"]) and $_SESSION["$settings->sessionprefix-expiretime"] < time()) { - //clear the session variables + // Clear the session variables $_SESSION = []; session_destroy(); + $env->is_logged_in = false; + $env->user = "Anonymous"; } if(!isset($_SESSION[$settings->sessionprefix . "-user"]) and !isset($_SESSION[$settings->sessionprefix . "-pass"])) { - //the user is not logged in - $isloggedin = false; + // The user is not logged in + $env->is_logged_in = false; } else { - $user = $_SESSION[$settings->sessionprefix . "-user"]; + $env->user = $_SESSION[$settings->sessionprefix . "-user"]; $pass = $_SESSION[$settings->sessionprefix . "-pass"]; if($settings->users[$user] == $pass) { - //the user is logged in - $isloggedin = true; + // The user is logged in + $env->is_logged_in = true; } else { - //the user's login details are invalid (what is going on here?) - //unset the session variables, treat them as an anonymous user, and get out of here - $isloggedin = false; - unset($user); + // The user's login details are invalid (what is going on here?) + // Unset the session variables, treat them as an anonymous user, + // and get out of here + $env->is_logged_in = false; + $env->user = "Anonymous"; unset($pass); - //clear the session data + // Clear the session data $_SESSION = []; //delete al lthe variables session_destroy(); //destroy the session } } //check to see if the currently logged in user is an admin -$isadmin = false; -if($isloggedin) +$env->is_admin = false; +if($env->is_logged_in) { foreach($settings->admins as $admin_username) { - if($admin_username == $user) + if($admin_username == $env->user) { - $isadmin = true; + $env->is_admin = true; break; } } @@ -314,7 +324,9 @@ if(makepathsafe($_GET["page"]) !== $_GET["page"]) header("x-actual-page: " . makepathsafe($_GET["page"])); exit(); } -$page = $_GET["page"]; + +$env->page = $_GET["page"]; +$env->action = strtolower($_GET["action"]); /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// @@ -370,6 +382,8 @@ class page_renderer // Registers a function as a part post processor. public static function register_part_preprocessor($function) { + global $settings; + // Make sure that the function we are about to register is valid if(!is_callable($function)) { @@ -464,7 +478,7 @@ class page_renderer */ public static function render_navigation_bar($nav_links, $nav_links_extra, $class = "") { - global $settings, $user, $isloggedin, $page; + global $settings, $env; $result = "