Skip to content

Commit

Permalink
Revises load order to allow for theme previewing
Browse files Browse the repository at this point in the history
  • Loading branch information
dleffler committed Aug 26, 2011
1 parent f0e275e commit 240fd6b
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 121 deletions.
41 changes: 31 additions & 10 deletions exponent.php
Expand Up @@ -32,6 +32,37 @@


// Initialize the MVC framework - for objects we need loaded now // Initialize the MVC framework - for objects we need loaded now
require_once(BASE.'framework/core/expFramework.php'); require_once(BASE.'framework/core/expFramework.php');

// Initialize the Sessions Subsystem
expSession::initialize();

// Initialize the theme subsystem 1.0 compatibility layer
require_once(BASE.'framework/core/subsystems-1/theme.php');
if (!defined('DISPLAY_THEME')) {
/* exdoc
* The directory and class name of the current active theme. This may be different
* than the configure theme (DISPLAY_THEME_REAL) due to previewing.
*/
define('DISPLAY_THEME',DISPLAY_THEME_REAL);
}

if (!defined('THEME_ABSOLUTE')) {
/* exdoc
* The absolute path to the current active theme's files. This is similar to the BASE constant
*/
define('THEME_ABSOLUTE',BASE.'themes/'.DISPLAY_THEME.'/'); // This is the recommended way
}

if (!defined('THEME_RELATIVE')) {
/* exdoc
* The relative web path to the current active theme. This is similar to the PATH_RELATIVE constant.
*/
define('THEME_RELATIVE',PATH_RELATIVE.'themes/'.DISPLAY_THEME.'/');
}
// add our theme folder to autoload and place it first
$auto_dirs2[] = BASE.'themes/'.DISPLAY_THEME_REAL.'/modules';
$auto_dirs2 = array_reverse($auto_dirs2);

/** /**
* the list of available/active controllers * the list of available/active controllers
* @global array $available_controllers * @global array $available_controllers
Expand All @@ -40,17 +71,7 @@
$available_controllers = initializeControllers(); //original position $available_controllers = initializeControllers(); //original position
//$available_controllers = array(); //$available_controllers = array();


// Initialize the Sessions Subsystem
expSession::initialize();

// Initialize the theme subsystem 1.0 compatibility layer
require_once(BASE.'framework/core/subsystems-1/theme.php');
//$validateTheme = array("headerinfo"=>false,"footerinfo"=>false);

// Initialize the language subsystem // Initialize the language subsystem
//$cur_lang = array();
//$default_lang = array();
//$target_lang_file = '';
expLang::loadLang(); expLang::loadLang();


// Initialize the Core Subsystem // Initialize the Core Subsystem
Expand Down
24 changes: 1 addition & 23 deletions exponent_bootstrap.php
Expand Up @@ -75,29 +75,7 @@ function __realpath($path) {
require_once(BASE . 'framework/core/subsystems/expSettings.php'); // we don't have our autoloader loaded yet require_once(BASE . 'framework/core/subsystems/expSettings.php'); // we don't have our autoloader loaded yet
expSettings::initialize(); expSettings::initialize();


if (!defined('DISPLAY_THEME')) { // Process PHP-wrapper settings (ini_sets and settings)
/* exdoc
* The directory and class name of the current active theme. This may be different
* than the configure theme (DISPLAY_THEME_REAL) due to previewing.
*/
define('DISPLAY_THEME',DISPLAY_THEME_REAL);
}

if (!defined('THEME_ABSOLUTE')) {
/* exdoc
* The absolute path to the current active theme's files. This is similar to the BASE constant
*/
define('THEME_ABSOLUTE',BASE.'themes/'.DISPLAY_THEME.'/'); // This is the recommended way
}

if (!defined('THEME_RELATIVE')) {
/* exdoc
* The relative web path to the current active theme. This is similar to the PATH_RELATIVE constant.
*/
define('THEME_RELATIVE',PATH_RELATIVE.'themes/'.DISPLAY_THEME.'/');
}

// Process PHP-wrapper settings (ini_sets and setting and eventually the autoloader)
require_once(BASE . 'exponent_php_setup.php'); require_once(BASE . 'exponent_php_setup.php');


$info = gd_info(); $info = gd_info();
Expand Down
117 changes: 54 additions & 63 deletions exponent_php_setup.php
Expand Up @@ -40,31 +40,22 @@
@date_default_timezone_set(DISPLAY_DEFAULT_TIMEZONE); @date_default_timezone_set(DISPLAY_DEFAULT_TIMEZONE);


// Initialize the AutoLoader subsystem - for objects we want loaded on the fly // Initialize the AutoLoader subsystem - for objects we want loaded on the fly
/** exdoc
* In PHP5, the autoloader function will check these
* directories when it tries to load a class definition
* file. Other parts of the system should append to this
* directory as needed, in order to take full advantage
* of autoloading
* @node Subsystems:Autoloader
*/
//$auto_dirs = array(BASE.'datatypes', BASE.'framework/core/subsystems-1/forms', BASE.'framework/core/subsystems-1/forms/controls');
$auto_dirs = array( $auto_dirs = array(
BASE.'framework/core/models-1', // old 1.0 /datatypes BASE.'framework/core/models-1', // old 1.0 /datatypes
BASE.'framework/core/subsystems-1/forms', BASE.'framework/core/subsystems-1/forms',
BASE.'framework/core/subsystems-1/forms/controls', BASE.'framework/core/subsystems-1/forms/controls',
BASE.'framework/core/controllers', BASE.'framework/core/controllers',
BASE.'framework/core/models', // used to be framework/core/datatypes & framework/datatypes BASE.'framework/core/models', // used to be framework/core/datatypes & framework/datatypes
BASE.'framework/core/subsystems', BASE.'framework/core/subsystems',
BASE.'framework/modules/ecommerce/billingcalculators', BASE.'framework/modules/ecommerce/billingcalculators',
BASE.'framework/modules/ecommerce/shippingcalculators', BASE.'framework/modules/ecommerce/shippingcalculators',
BASE.'framework/modules/ecommerce/products/controllers', //FIXME does NOT exist BASE.'framework/modules/ecommerce/products/controllers', //FIXME does NOT exist
BASE.'framework/modules/ecommerce/products/datatypes', // models BASE.'framework/modules/ecommerce/products/datatypes', // models
); );


$auto_dirs2 = array( $auto_dirs2 = array(
BASE.'themes/'.DISPLAY_THEME_REAL.'/modules', // BASE.'themes/'.DISPLAY_THEME_REAL.'/modules', //FIXME add this dynamically
BASE.'framework/modules' BASE.'framework/modules'
); );


/** exdoc /** exdoc
Expand All @@ -86,48 +77,48 @@ function expLoadClasses($class) {
} }


// recursive function used for (auto?)loading 2.0 modules controllers & models instead of using initializeControllers() // recursive function used for (auto?)loading 2.0 modules controllers & models instead of using initializeControllers()
// foreach ($auto_dirs2 as $dir) { foreach ($auto_dirs2 as $dir) {
// if (is_readable($dir)) { if (is_readable($dir)) {
// $dh = opendir($dir); $dh = opendir($dir);
// while (($file = readdir($dh)) !== false) { while (($file = readdir($dh)) !== false) {
// if (is_dir($dir.'/'.$file) && ($file != '..' && $file != '.')) { if (is_dir($dir.'/'.$file) && ($file != '..' && $file != '.')) {
// // load controllers // load controllers
// $dirpath = $dir.'/'.$file.'/controllers'; $dirpath = $dir.'/'.$file.'/controllers';
// if (file_exists($dirpath)) { if (file_exists($dirpath)) {
// $controller_dir = opendir($dirpath); $controller_dir = opendir($dirpath);
// while (($ctl_file = readdir($controller_dir)) !== false) { while (($ctl_file = readdir($controller_dir)) !== false) {
// if (substr($ctl_file,0,-4) == $class && substr($ctl_file,-4,4) == ".php") { if (substr($ctl_file,0,-4) == $class && substr($ctl_file,-4,4) == ".php") {
// include_once($dirpath.'/'.$ctl_file); include_once($dirpath.'/'.$ctl_file);
// return; return;
// } }
// } }
// } }
// // load models // load models
// $dirpath = $dir.'/'.$file.'/models'; $dirpath = $dir.'/'.$file.'/models';
// if (file_exists($dirpath)) { if (file_exists($dirpath)) {
// $controller_dir = opendir($dirpath); $controller_dir = opendir($dirpath);
// while (($ctl_file = readdir($controller_dir)) !== false) { while (($ctl_file = readdir($controller_dir)) !== false) {
// if (substr($ctl_file,0,-4) == $class && substr($ctl_file,-4,4) == ".php") { if (substr($ctl_file,0,-4) == $class && substr($ctl_file,-4,4) == ".php") {
// include_once($dirpath.'/'.$ctl_file); include_once($dirpath.'/'.$ctl_file);
// return; return;
// } }
// } }
// } }
// } }
// } }
// } }
// } }
//
// autoload the old school modules instead of using exponent_modules_initialize() // autoload the old school modules instead of using exponent_modules_initialize()
// if (is_readable(BASE.'framework/modules-1')) { if (is_readable(BASE.'framework/modules-1')) {
// $dh = opendir(BASE.'framework/modules-1'); $dh = opendir(BASE.'framework/modules-1');
// while (($file = readdir($dh)) !== false) { while (($file = readdir($dh)) !== false) {
// if ($file == $class && is_dir(BASE.'framework/modules-1/'.$file) && is_readable(BASE.'framework/modules-1/'.$file.'/class.php')) { if ($file == $class && is_dir(BASE.'framework/modules-1/'.$file) && is_readable(BASE.'framework/modules-1/'.$file.'/class.php')) {
// include_once(BASE.'framework/modules-1/'.$file.'/class.php'); include_once(BASE.'framework/modules-1/'.$file.'/class.php');
// return; return;
// } }
// } }
// } }


} }


Expand Down
40 changes: 25 additions & 15 deletions framework/core/subsystems/expSession.php
Expand Up @@ -87,7 +87,7 @@ public static function clearUserCache() {
self::clearCurrentUserSessionCache(); self::clearCurrentUserSessionCache();
} }


/* exdoc /** exdoc
* Runs necessary code to initialize sessions for use. * Runs necessary code to initialize sessions for use.
* This sends the session cookie header (via the session_start * This sends the session cookie header (via the session_start
* PHP function) and sets up session variables needed by the * PHP function) and sets up session variables needed by the
Expand All @@ -98,7 +98,7 @@ public static function initialize() {


// session key may be overridden // session key may be overridden
if (!defined('SYS_SESSION_KEY')) { if (!defined('SYS_SESSION_KEY')) {
/* exdoc /** exdoc
* @state <b>UNDOCUMENTED</b> * @state <b>UNDOCUMENTED</b>
* @node Undocumented * @node Undocumented
*/ */
Expand All @@ -110,10 +110,10 @@ public static function initialize() {
define('SYS_SESSION_COOKIE','PHPSESSID'); define('SYS_SESSION_COOKIE','PHPSESSID');
} }


$sessid = ''; // $sessid = '';
if (isset($_GET['expid'])) if (isset($_GET['expid']))
{ {
$sessid = $_GET['expid']; $sessid = $_GET['expid'];
} }
else if (isset($_POST['expid'])) else if (isset($_POST['expid']))
{ {
Expand Down Expand Up @@ -147,7 +147,7 @@ public static function initialize() {
} }
} }


/* exdoc /** exdoc
* Validates the stored session ticket against the database. This is used * Validates the stored session ticket against the database. This is used
* to force refreshes and force logouts. It also updates activity time. * to force refreshes and force logouts. It also updates activity time.
* @node Subsystems:Sessions * @node Subsystems:Sessions
Expand Down Expand Up @@ -195,10 +195,12 @@ public static function validate() {
define('SITE_403_HTML', SITE_403_REAL_HTML); define('SITE_403_HTML', SITE_403_REAL_HTML);
} }


/* exdoc /** exdoc
* Creates user ticket in sessionticket table and session * Creates user ticket in sessionticket table and session
* *
* @param $ticket
* @param User $user The user object of the newly logged-in user. Uses id of 0 if not supplied. * @param User $user The user object of the newly logged-in user. Uses id of 0 if not supplied.
* @return
* @node Subsystems:Sessions * @node Subsystems:Sessions
*/ */
public static function updateTicket($ticket, $user){ public static function updateTicket($ticket, $user){
Expand All @@ -211,12 +213,14 @@ public static function updateTicket($ticket, $user){
return $ticket; return $ticket;
} }


/* exdoc /** exdoc
* Checks to see if the session holds a set variable of the given name. * Checks to see if the session holds a set variable of the given name.
* *
* Note that some session variables (like the user object and the ticket) * Note that some session variables (like the user object and the ticket)
* cannot be changed using this call (for security / sanity reason) * cannot be changed using this call (for security / sanity reason)
* @node Subsystems:Sessions * @node Subsystems:Sessions
* @param $var
* @return bool
*/ */
public static function is_set($var) { public static function is_set($var) {
return isset($_SESSION[SYS_SESSION_KEY]['vars'][$var]); return isset($_SESSION[SYS_SESSION_KEY]['vars'][$var]);
Expand All @@ -241,7 +245,7 @@ public static function getTicketString() {
} }
} }


/* exdoc /** exdoc
* Removes a variable from the session. * Removes a variable from the session.
* *
* Note that some session variables (like the user object and the ticket) * Note that some session variables (like the user object and the ticket)
Expand Down Expand Up @@ -270,7 +274,7 @@ public static function login($user) {
exponent_permissions_load($user); exponent_permissions_load($user);
} }


/* exdoc /** exdoc
* Clears the session of all user data, used when a user logs out. * Clears the session of all user data, used when a user logs out.
* This gets rid of stale session tickets, and resets the session * This gets rid of stale session tickets, and resets the session
* to a blank state. * to a blank state.
Expand All @@ -286,11 +290,12 @@ public static function logout() {
//redirect_to(array('section'=>SITE_DEFAULT_SECTION)); //redirect_to(array('section'=>SITE_DEFAULT_SECTION));
} }


/* exdoc /** exdoc
* Looks at the session data to see if the current session is * Looks at the session data to see if the current session is
* that of a logged in user. Returns true if the viewer is logged * that of a logged in user. Returns true if the viewer is logged
* in, and false if it is not * in, and false if it is not
* @node Subsystems:Sessions * @node Subsystems:Sessions
* @return bool
*/ */
public static function loggedIn() { public static function loggedIn() {
//if ($anon){ //if ($anon){
Expand All @@ -301,7 +306,7 @@ public static function loggedIn() {
//} //}
} }


/* exdoc /** exdoc
* Clears global users session cache * Clears global users session cache
* *
* @param Modules $modules If not set, applies to all modules. If set, will only clear cache for that module * @param Modules $modules If not set, applies to all modules. If set, will only clear cache for that module
Expand Down Expand Up @@ -342,11 +347,12 @@ public static function clearAllUsersSessionCache($modules = null, $user = null)
*/ */
} }


/* exdoc /** exdoc
* Clears current users session cache * Clears current users session cache
* *
* @param Modules $modules Array or string. If not set, applies to all modules. If set, will only clear cache for that module * @param Modules $modules Array or string. If not set, applies to all modules. If set, will only clear cache for that module
* @param User $user if not set,applies to all users. If set, will only clear for that user *
* @internal param \User $user if not set,applies to all users. If set, will only clear for that user
* @node Subsystems:Sessions * @node Subsystems:Sessions
*/ */
public static function clearCurrentUserSessionCache($modules = null) { public static function clearCurrentUserSessionCache($modules = null) {
Expand All @@ -364,17 +370,21 @@ public static function clearCurrentUserSessionCache($modules = null) {
} }
} }


//Clears entire user session data and truncates the sessionticket table /**
* Clears entire user session data and truncates the sessionticket table
*
*/
public static function clearAllSessionData(){ public static function clearAllSessionData(){
global $db; global $db;
$db->delete('sessionticket',"1"); $db->delete('sessionticket',"1");
unset($_SESSION[SYS_SESSION_KEY]); unset($_SESSION[SYS_SESSION_KEY]);
} }


/* exdoc /** exdoc
* Creates user ticket in sessionticket table and session * Creates user ticket in sessionticket table and session
* *
* @param User $user The user object of the newly logged-in user. Uses id of 0 if not supplied. * @param User $user The user object of the newly logged-in user. Uses id of 0 if not supplied.
* @return null
* @node Subsystems:Sessions * @node Subsystems:Sessions
*/ */
static function createTicket($user = null){ static function createTicket($user = null){
Expand Down

0 comments on commit 240fd6b

Please sign in to comment.