2007-03-31 01:18:33 +00:00
< ? php
2006-12-02 04:36:16 +00:00
/*
2008-12-22 03:15:04 +00:00
* e107 website system
*
2010-05-13 15:47:31 +00:00
* Copyright ( C ) 2008 - 2010 e107 Inc ( e107 . org )
2008-12-22 03:15:04 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* General purpose file
*
2010-05-13 15:47:31 +00:00
* $URL $
* $Id $
2008-12-22 03:15:04 +00:00
*
2006-12-02 04:36:16 +00:00
*/
//
// *** Code sequence for startup ***
// IMPORTANT: These items are in a carefully constructed order. DO NOT REARRANGE
// without checking with experienced devs! Various subtle things WILL break.
//
// A Get the current CPU time so we know how long all of this takes
// B Remove output buffering so we are in control of text sent to user
// C Remove registered globals (SECURITY for all following code)
// D Setup PHP error handling (now we can see php errors ;))
// E Setup other PHP essentials
// F Grab e107_config to get directory paths
// G Retrieve Query from URI (i.e. what are the request parameters?!)
// H Initialize debug handling (NOTE: A-G cannot use debug tools!)
// I: Sanity check to ensure e107_config is ok
// J: MYSQL setup (NOTE: A-I cannot use database!)
// K: Compatibility mode
// L: Retrieve core prefs
// M: Subdomain and language selection
// N: Other misc setups (NOTE: Put most 'random' things here that don't require user session or theme
// O: Start user session
// P: Load theme
// Q: Other setups
2009-12-13 21:52:32 +00:00
/**
* @ package e107
*/
2006-12-02 04:36:16 +00:00
//
// A: Honest global beginning point for processing time
//
$eTimingStart = microtime (); // preserve these when destroying globals in step C
2007-03-04 21:47:15 +00:00
if ( function_exists ( 'getrusage' ) ) { $eTimingStartCPU = getrusage (); }
2006-12-02 04:36:16 +00:00
$oblev_before_start = ob_get_level ();
//
// B: Remove all output buffering
//
2008-01-22 00:39:08 +00:00
if ( ! isset ( $_E107 ) || ! is_array ( $_E107 )) { $_E107 = array (); }
2009-08-05 19:58:32 +00:00
if ( isset ( $_E107 [ 'cli' ]) && ! isset ( $_E107 [ 'debug' ]) && isset ( $_SERVER [ " HTTP_USER_AGENT " ]))
2008-01-22 00:39:08 +00:00
{
2009-10-30 20:58:52 +00:00
exit ();
2008-01-22 00:39:08 +00:00
}
2008-11-27 02:18:25 +00:00
2009-09-15 13:34:09 +00:00
if ( ! isset ( $_E107 [ 'cli' ]))
2008-01-21 03:54:10 +00:00
{
while ( @ ob_end_clean ()); // destroy all ouput buffering
ob_start (); // start our own.
$oblev_at_start = ob_get_level (); // preserve when destroying globals in step C
}
2006-12-02 04:36:16 +00:00
//
// C: Find out if register globals is enabled and destroy them if so
// (DO NOT use the value of any variables before this point! They could have been set by the user)
//
2009-11-24 16:30:08 +00:00
// Can't be moved to e107, required here for e107_config vars security
2006-12-02 04:36:16 +00:00
$register_globals = true ;
2008-11-27 02:18:25 +00:00
if ( function_exists ( 'ini_get' ))
{
2006-12-02 04:36:16 +00:00
$register_globals = ini_get ( 'register_globals' );
}
// Destroy! (if we need to)
2008-11-27 02:18:25 +00:00
if ( $register_globals == true )
{
2008-01-06 22:16:37 +00:00
if ( isset ( $_REQUEST [ '_E107' ])) { unset ( $_E107 ); }
2008-11-27 02:18:25 +00:00
while ( list ( $global ) = each ( $GLOBALS ))
{
if ( ! preg_match ( '/^(_POST|_GET|_COOKIE|_SERVER|_FILES|_SESSION|GLOBALS|HTTP.*|_REQUEST|_E107|retrieve_prefs|eplug_admin|eTimingStart.*|oblev_.*)$/' , $global ))
{
2006-12-02 04:36:16 +00:00
unset ( $$global );
}
}
unset ( $global );
}
2009-11-24 16:30:08 +00:00
// MOVED TO $e107->prepare_request()
2009-09-29 17:45:06 +00:00
// TODO - better ajax detection method (headers when possible)
2009-11-24 16:30:08 +00:00
//define('e_AJAX_REQUEST', isset($_REQUEST['ajax_used']));
2010-02-10 21:53:56 +00:00
//unset($_REQUEST['ajax_used']); // removed because it's auto-appended from JS (AJAX), could break something...
2009-11-24 16:30:08 +00:00
//
//if(isset($_E107['minimal']) || e_AJAX_REQUEST)
//{
// $_e107vars = array('forceuserupdate', 'online', 'theme', 'menus', 'prunetmp');
// foreach($_e107vars as $v)
// {
// $noname = 'no_'.$v;
// if(!isset($_E107[$v]))
// {
// $_E107[$noname] = 1;
// }
// unset($_E107[$v]);
// }
//}
// MOVED TO $e107->prepare_request()
2007-02-05 10:54:44 +00:00
// e107 uses relative url's, which are broken by "pretty" URL's. So for now we don't support / after .php
2009-11-24 16:30:08 +00:00
//if(($pos = strpos($_SERVER['PHP_SELF'], '.php/')) !== false) // redirect bad URLs to the correct one.
//{
// $new_url = substr($_SERVER['PHP_SELF'], 0, $pos+4);
// $new_loc = ($_SERVER['QUERY_STRING']) ? $new_url.'?'.$_SERVER['QUERY_STRING'] : $new_url;
// header('Location: '.$new_loc);
// exit();
//}
2006-12-02 04:36:16 +00:00
// If url contains a .php in it, PHP_SELF is set wrong (imho), affecting all paths. We need to 'fix' it if it does.
2009-11-24 16:30:08 +00:00
//$_SERVER['PHP_SELF'] = (($pos = strpos($_SERVER['PHP_SELF'], '.php')) !== false ? substr($_SERVER['PHP_SELF'], 0, $pos+4) : $_SERVER['PHP_SELF']);
2006-12-02 04:36:16 +00:00
//
// D: Setup PHP error handling
2006-12-05 09:33:20 +00:00
// (Now we can see PHP errors) -- but note that DEBUG is not yet enabled!
2006-12-02 04:36:16 +00:00
//
$error_handler = new error_handler ();
2008-11-27 02:18:25 +00:00
set_error_handler ( array ( & $error_handler , 'handle_error' ));
2006-12-02 04:36:16 +00:00
//
// E: Setup other essential PHP parameters
//
2008-11-27 02:18:25 +00:00
define ( 'e107_INIT' , true );
2006-12-02 04:36:16 +00:00
2009-11-24 16:30:08 +00:00
// MOVED TO $e107->prepare_request()
2006-12-02 04:36:16 +00:00
// setup some php options
2009-11-24 16:30:08 +00:00
//e107_ini_set('magic_quotes_runtime', 0);
//e107_ini_set('magic_quotes_sybase', 0);
//e107_ini_set('arg_separator.output', '&');
//e107_ini_set('session.use_only_cookies', 1);
//e107_ini_set('session.use_trans_sid', 0);
2006-12-02 04:36:16 +00:00
2009-11-24 16:30:08 +00:00
// DEPRECATED, use e107::getConfig() and e107::getPlugConfig()
2008-11-27 02:18:25 +00:00
if ( isset ( $retrieve_prefs ) && is_array ( $retrieve_prefs ))
{
foreach ( $retrieve_prefs as $key => $pref_name )
{
2006-12-02 04:36:16 +00:00
$retrieve_prefs [ $key ] = preg_replace ( " / \ W/ " , '' , $pref_name );
}
2008-11-27 02:18:25 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
unset ( $retrieve_prefs );
}
2009-11-24 16:30:08 +00:00
// MOVED TO e107->set_constants()
//define("MAGIC_QUOTES_GPC", (ini_get('magic_quotes_gpc') ? true : false));
//
//// Define the domain name and subdomain name.
//if($_SERVER['HTTP_HOST'] && is_numeric(str_replace(".","",$_SERVER['HTTP_HOST'])))
//{
// $srvtmp = ''; // Host is an IP address.
//}
//else
//{
// $srvtmp = explode('.',str_replace('www.', '', $_SERVER['HTTP_HOST']));
//}
//
//define('e_SUBDOMAIN', (count($srvtmp)>2 && $srvtmp[2] ? $srvtmp[0] : false)); // needs to be available to e107_config.
//
//if(e_SUBDOMAIN)
//{
// unset($srvtmp[0]);
//}
//
//define('e_DOMAIN',(count($srvtmp) > 1 ? (implode('.', $srvtmp)) : false)); // if it's an IP it must be set to false.
//
//unset($srvtmp);
2007-03-31 01:18:33 +00:00
2006-12-02 04:36:16 +00:00
2009-11-24 16:30:08 +00:00
// MOVED TO $e107->prepare_request()
2006-12-02 04:36:16 +00:00
// Ensure thet '.' is the first part of the include path
2009-11-24 16:30:08 +00:00
//$inc_path = explode(PATH_SEPARATOR, ini_get('include_path'));
//if($inc_path[0] != '.')
//{
// array_unshift($inc_path, '.');
// $inc_path = implode(PATH_SEPARATOR, $inc_path);
// e107_ini_set('include_path', $inc_path);
//}
//unset($inc_path);
2006-12-02 04:36:16 +00:00
//
// F: Grab e107_config, get directory paths and create $e107 object
//
@ include_once ( realpath ( dirname ( __FILE__ ) . '/e107_config.php' ));
2009-11-22 23:36:23 +00:00
2010-08-20 09:25:10 +00:00
if ( isset ( $CLASS2_INCLUDE ) && ( $CLASS2_INCLUDE != '' ))
2011-06-07 12:40:34 +00:00
{
require_once ( realpath ( dirname ( __FILE__ ) . '/' . $CLASS2_INCLUDE ));
2010-08-20 00:00:54 +00:00
}
2009-11-24 16:30:08 +00:00
//define("MPREFIX", $mySQLprefix); moved to $e107->set_constants()
2009-11-22 23:36:23 +00:00
2008-08-03 08:00:19 +00:00
if ( ! isset ( $ADMIN_DIRECTORY ))
{
// e107_config.php is either empty, not valid or doesn't exist so redirect to installer..
2008-11-27 02:18:25 +00:00
header ( 'Location: install.php' );
2008-08-03 08:00:19 +00:00
exit ();
2006-12-02 04:36:16 +00:00
}
//
2008-11-24 18:06:03 +00:00
// clever stuff that figures out where the paths are on the fly.. no more need for hard-coded e_HTTP :)
2006-12-02 04:36:16 +00:00
//
2009-08-05 19:58:32 +00:00
$tmp = realpath ( dirname ( __FILE__ ) . '/' . $HANDLERS_DIRECTORY );
2009-08-28 15:21:23 +00:00
//Core functions - now API independent
2009-08-05 19:58:32 +00:00
@ require_once ( $tmp . '/core_functions.php' );
e107_require_once ( $tmp . '/e107_class.php' );
unset ( $tmp );
2009-12-15 11:05:17 +00:00
$e107_paths = compact ( 'ADMIN_DIRECTORY' , 'FILES_DIRECTORY' , 'IMAGES_DIRECTORY' , 'THEMES_DIRECTORY' , 'PLUGINS_DIRECTORY' , 'HANDLERS_DIRECTORY' , 'LANGUAGES_DIRECTORY' , 'HELP_DIRECTORY' , 'DOWNLOADS_DIRECTORY' , 'UPLOADS_DIRECTORY' , 'MEDIA_DIRECTORY' , 'CACHE_DIRECTORY' , 'LOGS_DIRECTORY' );
2009-11-24 16:30:08 +00:00
$sql_info = compact ( 'mySQLserver' , 'mySQLuser' , 'mySQLpassword' , 'mySQLdefaultdb' , 'mySQLprefix' );
2010-03-08 10:02:22 +00:00
$e107 = e107 :: getInstance () -> initCore ( $e107_paths , realpath ( dirname ( __FILE__ )), $sql_info , varset ( $E107_CONFIG , array ()));
2009-11-24 16:30:08 +00:00
2011-11-25 17:17:09 +00:00
### NEW Register Autoload - do it asap
if ( ! function_exists ( 'spl_autoload_register' ))
{
// PHP >= 5.1.2 required
die ( 'Fatal exception - spl_autoload_* required.' );
}
// allow disable of autoloading - may be removed as e107::autoload_register() is flexible enough
if ( ! defset ( 'E107_DISABLE_AUTOLOAD' , false ))
{
e107 :: autoload_register ( array ( 'e107' , 'autoload' ));
}
2010-10-26 07:41:20 +00:00
/**
* NEW - system security levels
* Could be overridden by e107_config . php OR $CLASS2_INCLUDE script ( if not set earlier )
2011-06-07 12:40:34 +00:00
*
2010-10-26 07:41:20 +00:00
* 0 disabled
* 5 safe mode ( balanced )
* 7 high
2011-06-07 12:40:34 +00:00
* 9 paranoid
2010-10-26 07:41:20 +00:00
* 10 insane
* for more detailed info see e_session SECURITY_LEVEL_ * constants
* default is e_session :: SECURITY_LEVEL_BALANCED ( 5 )
*/
2011-06-07 12:40:34 +00:00
if ( ! defined ( 'e_SECURITY_LEVEL' ))
2010-10-26 07:41:20 +00:00
{
require_once ( e_HANDLER . 'session_handler.php' );
define ( 'e_SECURITY_LEVEL' , e_session :: SECURITY_LEVEL_BALANCED );
}
2010-09-10 01:01:48 +00:00
2009-11-24 16:30:08 +00:00
// MOVED TO $e107->set_request()
//$inArray = array("'", ';', '/**/', '/UNION/', '/SELECT/', 'AS ');
//if (strpos($_SERVER['PHP_SELF'], 'trackback') === false)
//{
// foreach($inArray as $res)
// {
// if(stristr($_SERVER['QUERY_STRING'], $res))
// {
// die('Access denied.');
// }
// }
//}
2006-12-02 04:36:16 +00:00
2009-07-19 11:44:30 +00:00
2006-12-02 04:36:16 +00:00
//
// Start the parser; use it to grab the full query string
//
2009-08-28 15:21:23 +00:00
//DEPRECATED, BC
2009-07-23 15:29:07 +00:00
//$e107->url = e107::getUrl(); - caught by __get()
//TODO - find & replace $e107->url
//DEPRECATED, BC, $e107->tp caught by __get()
$tp = e107 :: getParser (); //TODO - find & replace $tp, $e107->tp
2006-12-02 04:36:16 +00:00
//define("e_QUERY", $matches[2]);
//define("e_QUERY", $_SERVER['QUERY_STRING']);
2009-11-24 16:30:08 +00:00
// MOVED TO $e107->set_request()
//$e_QUERY = str_replace("&","&",$tp->post_toForm($e_QUERY));
//define('e_QUERY', $e_QUERY);
2006-12-02 04:36:16 +00:00
//$e_QUERY = e_QUERY;
2009-11-24 16:30:08 +00:00
// MOVED TO $e107->set_request()
//define('e_TBQS', $_SERVER['QUERY_STRING']);
//$_SERVER['QUERY_STRING'] = e_QUERY;
// MOVED TO $e107->set_constants()
//define('e_UC_PUBLIC', 0);
//define('e_UC_MAINADMIN', 250);
//define('e_UC_READONLY', 251);
//define('e_UC_GUEST', 252);
//define('e_UC_MEMBER', 253);
//define('e_UC_ADMIN', 254);
//define('e_UC_NOBODY', 255);
2006-12-02 04:36:16 +00:00
2009-11-24 16:30:08 +00:00
// MOVED TO $e107->set_urls() - DEPRECATED, use e107->getFolder()
//define('ADMINDIR', $ADMIN_DIRECTORY);
2006-12-02 04:36:16 +00:00
//
// H: Initialize debug handling
// (NO E107 DEBUG CONSTANTS OR CODE ARE AVAILABLE BEFORE THIS POINT)
// All debug objects and constants are defined in the debug handler
// i.e. from here on you can use E107_DEBUG_LEVEL or any
// E107_DBG_* constant for debug testing.
2010-10-26 07:41:20 +00:00
// TODO - rewrite the debug init phase, add e107 class getters
2006-12-02 04:36:16 +00:00
//
2008-11-27 02:18:25 +00:00
require_once ( e_HANDLER . 'debug_handler.php' );
2006-12-02 04:36:16 +00:00
2008-11-27 02:18:25 +00:00
if ( E107_DEBUG_LEVEL && isset ( $db_debug ) && is_object ( $db_debug ))
{
2006-12-02 04:36:16 +00:00
$db_debug -> Mark_Time ( 'Start: Init ErrHandler' );
}
//
// I: Sanity check on e107_config.php
// e107_config.php upgrade check
2010-10-26 07:41:20 +00:00
// FIXME - obsolete check, rewrite it
2008-11-27 02:18:25 +00:00
if ( ! $ADMIN_DIRECTORY && ! $DOWNLOADS_DIRECTORY )
{
message_handler ( 'CRITICAL_ERROR' , 8 , ': generic, ' , 'e107_config.php' );
2006-12-02 04:36:16 +00:00
exit ;
}
//
// J: MYSQL INITIALIZATION
//
2009-09-13 10:29:56 +00:00
e107 :: getSingleton ( 'e107_traffic' ); // We start traffic counting ASAP
2010-02-10 21:53:56 +00:00
//$eTraffic->Calibrate($eTraffic);
2006-12-02 04:36:16 +00:00
2010-10-26 07:41:20 +00:00
// e107_require_once(e_HANDLER.'mysql_class.php');
2006-12-02 04:36:16 +00:00
2009-07-23 15:29:07 +00:00
//DEPRECATED, BC, $e107->sql caught by __get()
$sql = e107 :: getDb (); //TODO - find & replace $sql, $e107->sql
2006-12-02 04:36:16 +00:00
$sql -> db_SetErrorReporting ( FALSE );
$sql -> db_Mark_Time ( 'Start: SQL Connect' );
$merror = $sql -> db_Connect ( $mySQLserver , $mySQLuser , $mySQLpassword , $mySQLdefaultdb );
2009-07-23 15:29:07 +00:00
2009-07-22 00:49:35 +00:00
// create after the initial connection.
2009-08-28 15:21:23 +00:00
//DEPRECATED, BC, call the method only when needed
2009-07-23 15:29:07 +00:00
$sql2 = e107 :: getDb ( 'sql2' ); //TODO find & replace all $sql2 calls
2011-06-07 12:40:34 +00:00
$sql -> db_Mark_Time ( 'Start: Prefs, misc tables' );
2006-12-30 03:07:50 +00:00
2009-07-23 15:29:07 +00:00
//DEPRECATED, BC, call the method only when needed, $e107->admin_log caught by __get()
$admin_log = e107 :: getAdminLog (); //TODO - find & replace $admin_log, $e107->admin_log
2006-12-02 04:36:16 +00:00
2009-08-28 15:21:23 +00:00
if ( $merror === 'e1' )
2009-07-22 00:49:35 +00:00
{
2008-11-27 02:18:25 +00:00
message_handler ( 'CRITICAL_ERROR' , 6 , ': generic, ' , 'class2.php' );
2006-12-02 04:36:16 +00:00
exit ;
}
2008-11-27 02:18:25 +00:00
elseif ( $merror === 'e2' )
{
message_handler ( " CRITICAL_ERROR " , 7 , ': generic, ' , 'class2.php' );
2006-12-02 04:36:16 +00:00
exit ;
}
//
// K: Load compatability mode.
//
2008-01-06 22:16:37 +00:00
/* PHP Compatabilty should *always* be on. */
2008-11-27 02:18:25 +00:00
e107_require_once ( e_HANDLER . 'php_compatibility_handler.php' );
2006-12-02 04:36:16 +00:00
//
// L: Extract core prefs from the database
//
$sql -> db_Mark_Time ( 'Start: Extract Core Prefs' );
2009-11-24 16:30:08 +00:00
// TODO - remove it from here, auto-loaded when required
2006-12-02 04:36:16 +00:00
e107_require_once ( e_HANDLER . 'cache_handler.php' );
2009-07-22 00:49:35 +00:00
2009-07-23 15:29:07 +00:00
//DEPRECATED, BC, call the method only when needed, $e107->arrayStorage caught by __get()
$eArrayStorage = e107 :: getArrayStorage (); //TODO - find & replace $eArrayStorage, $e107->arrayStorage
2006-12-02 04:36:16 +00:00
2009-07-23 15:29:07 +00:00
//DEPRECATED, BC, call the method only when needed, $e107->e_event caught by __get()
$e_event = e107 :: getEvent (); //TODO - find & replace $e_event, $e107->e_event
2008-12-03 00:43:00 +00:00
2009-11-24 16:30:08 +00:00
// TODO - DEPRECATED - remove
2009-08-05 19:58:32 +00:00
e107_require_once ( e_HANDLER . " pref_class.php " );
$sysprefs = new prefs ;
// Check core preferences
//FIXME - message_handler is dying after message_handler(CRITICAL_ERROR) call
2010-10-28 13:33:05 +00:00
e107 :: getConfig () -> load (); // extra load, required if mysql handler already called e107::getConfig()
2009-08-05 19:58:32 +00:00
if ( ! e107 :: getConfig () -> hasData ())
{
// Core prefs error - admin log
e107 :: getAdminLog () -> log_event ( 'CORE_LAN8' , 'CORE_LAN7' , E_LOG_WARNING );
2009-08-28 15:21:23 +00:00
2009-08-05 19:58:32 +00:00
// Try for the automatic backup..
if ( e107 :: getConfig ( 'core_backup' ) -> hasData ())
{
// auto backup found, use backup to restore the core
e107 :: getConfig () -> loadData ( e107 :: getConfig ( 'core_backup' ) -> getPref (), false )
-> save ( false , true );
2009-08-28 15:21:23 +00:00
2009-08-05 19:58:32 +00:00
message_handler ( 'CRITICAL_ERROR' , 3 , __LINE__ , __FILE__ );
}
2009-08-28 15:21:23 +00:00
else
2009-08-05 19:58:32 +00:00
{
// No auto backup, try for the 'old' prefs system.
if ( ! e107 :: getConfig ( 'core_old' ) -> hasData ())
{
// Core could not restore from automatic backup. Execution halted.
2009-08-28 15:21:23 +00:00
e107 :: getAdminLog () -> log_event ( 'CORE_LAN8' , 'CORE_LAN9' , E_LOG_FATAL );
2009-08-05 19:58:32 +00:00
message_handler ( 'CRITICAL_ERROR' , 3 , __LINE__ , __FILE__ );
// No old system, so point in the direction of resetcore :(
2009-08-28 15:21:23 +00:00
message_handler ( 'CRITICAL_ERROR' , 4 , __LINE__ , __FILE__ ); //this will never appear till message_handler() is fixed
2009-08-05 19:58:32 +00:00
exit ;
}
2009-08-28 15:21:23 +00:00
else
2009-08-05 19:58:32 +00:00
{
// resurrect core from old prefs
e107 :: getConfig () -> loadData ( e107 :: getConfig ( 'core_old' ) -> getPref (), false )
-> save ( false , true );
2009-08-28 15:21:23 +00:00
2009-08-05 19:58:32 +00:00
// resurrect core_backup from old prefs
e107 :: getConfig ( 'core_backup' ) -> loadData ( e107 :: getConfig ( 'core_old' ) -> getPref (), false )
-> save ( false , true );
}
}
2009-08-28 15:21:23 +00:00
2009-08-05 19:58:32 +00:00
}
2010-10-26 07:41:20 +00:00
//DEPRECATED, BC, call e107::getPref/findPref() instead
2009-08-05 19:58:32 +00:00
$pref = e107 :: getPref ();
2009-11-24 16:30:08 +00:00
//this could be part of e107->init() method now, prefs will be auto-initialized
2009-08-05 19:58:32 +00:00
//when proper called (e107::getPref())
2010-02-10 21:53:56 +00:00
// $e107->set_base_path(); moved to init().
2006-12-02 04:36:16 +00:00
2009-08-05 19:58:32 +00:00
//DEPRECATED, BC, call e107::getConfig('menu')->get('pref_name') only when needed
$menu_pref = e107 :: getConfig ( 'menu' ) -> getPref (); //extract menu prefs
2010-11-21 12:49:36 +00:00
// NEW - force ssl
if ( e107 :: getPref ( 'ssl_enabled' ) && ! deftrue ( 'e_SSL_DISABLE' ))
{
// NOTE: e_SSL_DISABLE check is here to help webmasters fix 'ssl_enabled'
// if set by accident on site with no SSL support - just define it in e107_config.php
if ( strpos ( e_REQUEST_URL , 'http://' ) === 0 )
{
// e_REQUEST_URL and e_REQUEST_URI introduced
2011-06-07 12:40:34 +00:00
$url = 'https://' . substr ( e_REQUEST_URL , 7 );
2010-11-21 12:49:36 +00:00
header ( 'Location: ' . $url );
exit ;
}
}
2009-07-16 02:55:19 +00:00
2010-09-10 01:01:48 +00:00
// $sql->db_Mark_Time('(Extracting Core Prefs Done)');
$sql -> db_Mark_Time ( 'Start: Init Language and detect changes' );
e107 :: getLanguage () -> detect ();
2006-12-02 04:36:16 +00:00
//
// M: Subdomain and Language Selection
//
2008-05-19 09:42:28 +00:00
2008-11-27 02:18:25 +00:00
// if a cookie name pref isn't set, make one :)
2010-10-26 07:41:20 +00:00
// e_COOKIE used as unique session cookie name now (see session handler)
2008-11-27 02:18:25 +00:00
if ( ! $pref [ 'cookie_name' ]) { $pref [ 'cookie_name' ] = 'e107cookie' ; }
define ( 'e_COOKIE' , $pref [ 'cookie_name' ]);
2008-05-19 09:42:28 +00:00
2009-11-24 16:30:08 +00:00
// MOVED TO $e107->set_urls()
//define('SITEURLBASE', ($pref['ssl_enabled'] == '1' ? 'https://' : 'http://').$_SERVER['HTTP_HOST']);
//define('SITEURL', SITEURLBASE.e_HTTP);
2006-12-02 04:36:16 +00:00
// if the option to force users to use a particular url for the site is enabled, redirect users there as needed
// Now matches RFC 2616 (sec 3.2): case insensitive, https/:443 and http/:80 are equivalent.
// And, this is robust against hack attacks. Malignant users can put **anything** in HTTP_HOST!
if ( $pref [ 'redirectsiteurl' ] && $pref [ 'siteurl' ]) {
2008-04-26 02:12:13 +00:00
if ( isset ( $pref [ 'multilanguage_subdomain' ]) && $pref [ 'multilanguage_subdomain' ])
{
2011-12-06 08:00:42 +00:00
if ( substr ( e_REQUEST_URL , 7 , 4 ) == 'www.' || substr ( e_REQUEST_URL , 8 , 4 ) == 'www.' )
2008-04-26 02:12:13 +00:00
{
2011-12-06 08:00:42 +00:00
$self = e_REQUEST_URL ;
//if(e_QUERY){ $self .= '?'.e_QUERY; }
2008-11-27 02:18:25 +00:00
$location = str_replace ( '://www.' , '://' , $self );
2008-04-26 02:12:13 +00:00
header ( " Location: { $location } " , true , 301 ); // send 301 header, not 302
exit ();
2006-12-02 04:36:16 +00:00
}
2008-04-26 02:12:13 +00:00
}
else
{
// Find domain and port from user and from pref
list ( $urlbase , $urlport ) = explode ( ':' , $_SERVER [ 'HTTP_HOST' ] . ':' );
if ( ! $urlport ) { $urlport = $_SERVER [ 'SERVER_PORT' ]; }
if ( ! $urlport ) { $urlport = 80 ; }
$aPrefURL = explode ( '/' , $pref [ 'siteurl' ], 4 );
2008-11-27 02:18:25 +00:00
if ( count ( $aPrefURL ) > 2 ) // we can do this -- there's at least http[s]://dom.ain/whatever
2008-12-02 18:27:35 +00:00
{
2008-04-26 02:12:13 +00:00
$PrefRoot = $aPrefURL [ 2 ];
list ( $PrefSiteBase , $PrefSitePort ) = explode ( ':' , $PrefRoot . ':' );
2008-11-27 02:18:25 +00:00
if ( ! $PrefSitePort )
{
$PrefSitePort = ( $aPrefURL [ 0 ] == 'https:' ) ? 443 : 80 ; // no port so set port based on 'scheme'
2008-04-26 02:12:13 +00:00
}
2006-12-02 04:36:16 +00:00
2008-04-26 02:12:13 +00:00
// Redirect only if
// -- ports do not match (http <==> https)
// -- base domain does not match (case-insensitive)
// -- NOT admin area
2011-12-06 08:00:42 +00:00
if (( $urlport != $PrefSitePort || stripos ( $PrefSiteBase , $urlbase ) === false ) && strpos ( e_REQUEST_SELF , ADMINDIR ) === false )
2008-11-27 02:18:25 +00:00
{
2011-12-06 08:00:42 +00:00
$aeSELF = explode ( '/' , e_REQUEST_SELF , 4 );
2008-04-26 02:12:13 +00:00
$aeSELF [ 0 ] = $aPrefURL [ 0 ]; // Swap in correct type of query (http, https)
$aeSELF [ 1 ] = '' ; // Defensive code: ensure http:// not http:/<garbage>/
$aeSELF [ 2 ] = $aPrefURL [ 2 ]; // Swap in correct domain and possibly port
2011-12-06 08:00:42 +00:00
$location = implode ( '/' , $aeSELF ) . ( $_SERVER [ 'QUERY_STRING' ] ? '?' . $_SERVER [ 'QUERY_STRING' ] : '' );
2008-04-26 02:12:13 +00:00
header ( " Location: { $location } " , true , 301 ); // send 301 header, not 302
exit ();
}
}
2006-12-02 04:36:16 +00:00
}
}
2010-09-10 01:01:48 +00:00
/**
* Set the User ' s Language
*/
$sql -> db_Mark_Time ( 'Start: Set User Language' );
2011-06-07 12:40:34 +00:00
// SESSION Needs to be started after:
// - Site preferences are available
// - Language detection (because of session.cookie_domain)
2010-10-26 07:41:20 +00:00
// to avoid multi-language 'access-denied' issues.
//session_start(); see e107::getSession() above
e107 :: getSession (); //init core _SESSION - actually here for reference only, it's done by language handler set() method
2011-06-07 12:40:34 +00:00
e107 :: getLanguage () -> set (); // set e_LANGUAGE, USERLAN, Language Session / Cookies etc. requires $pref;
2006-12-02 04:36:16 +00:00
2010-09-10 01:01:48 +00:00
if ( varset ( $pref [ 'multilanguage' ]) && ( e_LANGUAGE != $pref [ 'sitelanguage' ]))
2008-11-27 02:18:25 +00:00
{
2010-09-10 01:01:48 +00:00
$sql -> mySQLlanguage = e_LANGUAGE ;
$sql2 -> mySQLlanguage = e_LANGUAGE ;
2006-12-02 04:36:16 +00:00
}
2010-10-31 14:50:40 +00:00
//do it only once and with the proper function
// e107_include_once(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'.php');
// e107_include_once(e_LANGUAGEDIR.e_LANGUAGE.'/'.e_LANGUAGE.'_custom.php');
include ( e_LANGUAGEDIR . e_LANGUAGE . '/' . e_LANGUAGE . '.php' ); // FASTEST - ALWAYS load
$customLan = e_LANGUAGEDIR . e_LANGUAGE . '/' . e_LANGUAGE . '_custom.php' ;
if ( is_readable ( $customLan )) // FASTER - if exist, should be done 'once' by the core
{
2011-06-07 12:40:34 +00:00
include ( $customLan );
2010-10-31 14:50:40 +00:00
}
unset ( $customLan );
2006-12-02 04:36:16 +00:00
2010-10-26 07:41:20 +00:00
e107 :: getSession ()
-> challenge () // Create a unique challenge string for CHAP login
-> check (); // Token protection
2010-10-31 14:50:40 +00:00
2006-12-02 04:36:16 +00:00
//
// N: misc setups: online user tracking, cache
//
2010-10-26 07:41:20 +00:00
$sql -> db_Mark_Time ( 'Start: Misc resources. Online user tracking, cache' );
2006-12-02 04:36:16 +00:00
2009-07-23 15:29:07 +00:00
//DEPRECATED, BC, call the method only when needed, $e107->ecache caught by __get()
$e107cache = e107 :: getCache (); //TODO - find & replace $e107cache, $e107->ecache
2006-12-02 04:36:16 +00:00
2009-07-23 15:29:07 +00:00
//DEPRECATED, BC, call the method only when needed, $e107->override caught by __get()
2010-04-24 11:39:14 +00:00
$override = e107 :: getSingleton ( 'override' , true ); //TODO - find & replace $override, $e107->override
2006-12-02 04:36:16 +00:00
2009-07-23 15:29:07 +00:00
//DEPRECATED, BC, call the method only when needed, $e107->user_class caught by __get()
$e_userclass = e107 :: getUserClass (); //TODO - find & replace $e_userclass, $e107->user_class
2008-11-30 23:15:15 +00:00
2009-07-23 15:29:07 +00:00
//TODO - move the check to e107::notify()? What's the idea behind $pref['notify']?
2008-11-27 02:18:25 +00:00
if ( isset ( $pref [ 'notify' ]) && $pref [ 'notify' ] == true )
{
2006-12-02 04:36:16 +00:00
e107_require_once ( e_HANDLER . 'notify_class.php' );
}
//
// O: Start user session
//
$sql -> db_Mark_Time ( 'Start: Init session' );
init_session ();
2010-02-10 21:53:56 +00:00
//DEPRECATED but necessary. BC Fix.
function getip ()
2009-11-19 10:07:32 +00:00
{
return e107 :: ipDecode ( USERIP );
}
2006-12-02 04:36:16 +00:00
// for multi-language these definitions needs to come after the language loaded.
2010-01-09 20:32:51 +00:00
define ( 'SITENAME' , trim ( $tp -> toHTML ( $pref [ 'sitename' ], '' , 'USER_TITLE,er_on' )));
2008-11-27 02:18:25 +00:00
define ( 'SITEBUTTON' , $tp -> replaceConstants ( $pref [ 'sitebutton' ]));
2010-01-02 21:42:51 +00:00
define ( 'SITETAG' , $tp -> toHTML ( $pref [ 'sitetag' ], false , 'emotes_off,defs' ));
define ( 'SITEDESCRIPTION' , $tp -> toHTML ( $pref [ 'sitedescription' ], '' , 'emotes_off,defs' ));
2008-11-27 02:18:25 +00:00
define ( 'SITEADMIN' , $pref [ 'siteadmin' ]);
define ( 'SITEADMINEMAIL' , $pref [ 'siteadminemail' ]);
2010-01-02 21:42:51 +00:00
define ( 'SITEDISCLAIMER' , $tp -> toHTML ( $pref [ 'sitedisclaimer' ], '' , 'emotes_off,defs' ));
define ( 'SITECONTACTINFO' , $tp -> toHTML ( $pref [ 'sitecontactinfo' ], true , 'emotes_off,defs' ));
2006-12-02 04:36:16 +00:00
2008-10-11 11:55:18 +00:00
/* Withdrawn 0.8
2006-12-02 04:36:16 +00:00
// legacy module.php file loading.
if ( isset ( $pref [ 'modules' ]) && $pref [ 'modules' ]) {
$mods = explode ( " , " , $pref [ 'modules' ]);
foreach ( $mods as $mod ) {
if ( is_readable ( e_PLUGIN . " { $mod } /module.php " )) {
require_once ( e_PLUGIN . " { $mod } /module.php " );
}
}
}
2008-10-11 11:55:18 +00:00
*/
2007-09-27 20:58:11 +00:00
$js_body_onload = array (); // Initialise this array in case a module wants to add to it
2006-12-02 04:36:16 +00:00
// Load e_modules after all the constants, but before the themes, so they can be put to use.
2008-11-27 02:18:25 +00:00
if ( isset ( $pref [ 'e_module_list' ]) && $pref [ 'e_module_list' ])
{
foreach ( $pref [ 'e_module_list' ] as $mod )
{
if ( is_readable ( e_PLUGIN . " { $mod } /e_module.php " ))
{
2006-12-02 04:36:16 +00:00
require_once ( e_PLUGIN . " { $mod } /e_module.php " );
}
}
}
//
// P: THEME LOADING
//
$sql -> db_Mark_Time ( 'Start: Load Theme' );
//########### Module redefinable functions ###############
2008-11-27 02:18:25 +00:00
if ( ! function_exists ( 'checkvalidtheme' ))
{
2009-07-12 14:44:57 +00:00
2008-11-27 02:18:25 +00:00
function checkvalidtheme ( $theme_check )
{
2006-12-02 04:36:16 +00:00
// arg1 = theme to check
2011-01-03 10:54:08 +00:00
//global $ADMIN_DIRECTORY, $tp, $e107;
$e107 = e107 :: getInstance ();
$tp = e107 :: getParser ();
$ADMIN_DIRECTORY = $e107 -> getFolder ( 'admin' );
2011-11-25 17:17:09 +00:00
// e_QUERY not set when in single entry mod
if ( ADMIN && strpos ( $_SERVER [ 'QUERY_STRING' ], 'themepreview' ) !== false )
2008-11-27 02:18:25 +00:00
{
2006-12-02 04:36:16 +00:00
list ( $action , $id ) = explode ( '.' , e_QUERY );
2009-07-12 14:44:57 +00:00
2009-07-06 05:59:42 +00:00
require_once ( e_HANDLER . 'theme_handler.php' );
2009-07-12 14:44:57 +00:00
$themeobj = new themeHandler ;
$themeArray = $themeobj -> getThemes ( 'id' );
$themeDef = $themeobj -> findDefault ( $themeArray [ $id ]);
define ( 'THEME_LAYOUT' , $themeDef );
2009-07-06 05:59:42 +00:00
2008-11-27 02:18:25 +00:00
define ( 'PREVIEWTHEME' , e_THEME . $themeArray [ $id ] . '/' );
define ( 'PREVIEWTHEMENAME' , $themeArray [ $id ]);
define ( 'THEME' , e_THEME . $themeArray [ $id ] . '/' );
define ( 'THEME_ABS' , e_THEME_ABS . $themeArray [ $id ] . '/' );
2006-12-02 04:36:16 +00:00
return ;
}
2008-11-27 02:18:25 +00:00
if ( @ fopen ( e_THEME . $theme_check . '/theme.php' , 'r' ))
{
define ( 'THEME' , e_THEME . $theme_check . '/' );
define ( 'THEME_ABS' , e_THEME_ABS . $theme_check . '/' );
2006-12-02 04:36:16 +00:00
$e107 -> site_theme = $theme_check ;
2008-11-27 02:18:25 +00:00
}
else
{
function search_validtheme ()
{
2011-01-03 10:54:08 +00:00
$e107 = e107 :: getInstance ();
2008-11-27 02:18:25 +00:00
$th = substr ( e_THEME , 0 , - 1 );
$handle = opendir ( $th );
while ( $file = readdir ( $handle ))
{
if ( is_dir ( e_THEME . $file ) && is_readable ( e_THEME . $file . '/theme.php' ))
{
2006-12-02 04:36:16 +00:00
closedir ( $handle );
$e107 -> site_theme = $file ;
return $file ;
}
}
closedir ( $handle );
}
$e107tmp_theme = search_validtheme ();
2008-11-27 02:18:25 +00:00
define ( 'THEME' , e_THEME . $e107tmp_theme . '/' );
define ( 'THEME_ABS' , e_THEME_ABS . $e107tmp_theme . '/' );
if ( ADMIN && strpos ( e_SELF , $ADMIN_DIRECTORY ) === false )
{
2006-12-02 04:36:16 +00:00
echo '<script>alert("' . $tp -> toJS ( CORE_LAN1 ) . '")</script>' ;
}
}
2011-01-03 10:54:08 +00:00
$themes_dir = $e107 -> getFolder ( 'themes' );
2006-12-02 04:36:16 +00:00
$e107 -> http_theme_dir = " { $e107 -> server_path } { $themes_dir } { $e107 -> site_theme } / " ;
}
}
//
// Q: ALL OTHER SETUP CODE
//
$sql -> db_Mark_Time ( 'Start: Misc Setup' );
//------------------------------------------------------------------------------------------------------------------------------------//
2009-10-20 16:00:38 +00:00
if ( ! class_exists ( 'e107table' , false ))
2008-11-27 02:18:25 +00:00
{
2009-12-13 21:52:32 +00:00
/**
* @ package e107
*/
2008-11-27 02:18:25 +00:00
class e107table
{
2009-08-14 15:57:45 +00:00
public $eMenuCount = 0 ;
public $eMenuArea ;
2009-08-16 23:58:33 +00:00
public $eMenuTotal = array ();
2009-08-14 22:31:09 +00:00
public $eSetStyle ;
2009-08-14 15:57:45 +00:00
2008-11-27 02:18:25 +00:00
function tablerender ( $caption , $text , $mode = 'default' , $return = false )
{
2011-11-29 23:37:44 +00:00
2006-12-02 04:36:16 +00:00
/*
# Render style table
# - parameter #1: string $caption, caption text
# - parameter #2: string $text, body text
2009-08-14 15:57:45 +00:00
# - return null
# - scope public
2006-12-02 04:36:16 +00:00
*/
2009-07-22 00:49:35 +00:00
$override_tablerender = e107 :: getSingleton ( 'override' , e_HANDLER . 'override_class.php' ) -> override_check ( 'tablerender' );
2006-12-02 04:36:16 +00:00
2009-07-22 00:49:35 +00:00
if ( $override_tablerender )
2008-11-27 02:18:25 +00:00
{
$result = call_user_func ( $override_tablerender , $caption , $text , $mode , $return );
2006-12-02 04:36:16 +00:00
2008-11-27 02:18:25 +00:00
if ( $result == 'return' )
{
2009-07-22 00:49:35 +00:00
return '' ;
2006-12-02 04:36:16 +00:00
}
extract ( $result );
}
2008-11-27 02:18:25 +00:00
if ( $return )
{
2009-08-14 15:57:45 +00:00
if ( ! empty ( $text ) && $this -> eMenuArea )
{
$this -> eMenuCount ++ ;
}
2006-12-02 04:36:16 +00:00
ob_start ();
2009-09-04 14:35:01 +00:00
tablestyle ( $caption , $text , $mode , array ( 'menuArea' => $this -> eMenuArea , 'menuCount' => $this -> eMenuCount , 'menuTotal' => varset ( $this -> eMenuTotal [ $this -> eMenuArea ]), 'setStyle' => $this -> eSetStyle ));
2006-12-02 04:36:16 +00:00
$ret = ob_get_contents ();
ob_end_clean ();
2009-08-14 15:57:45 +00:00
2006-12-02 04:36:16 +00:00
return $ret ;
2009-08-14 15:57:45 +00:00
2008-11-27 02:18:25 +00:00
}
else
{
2009-08-14 15:57:45 +00:00
if ( ! empty ( $text ) && $this -> eMenuArea )
{
$this -> eMenuCount ++ ;
}
2009-09-10 10:23:12 +00:00
tablestyle ( $caption , $text , $mode , array ( 'menuArea' => $this -> eMenuArea , 'menuCount' => $this -> eMenuCount , 'menuTotal' => varset ( $this -> eMenuTotal [ $this -> eMenuArea ]), 'setStyle' => $this -> eSetStyle ));
2009-07-22 00:49:35 +00:00
return '' ;
2006-12-02 04:36:16 +00:00
}
}
}
}
//#############################################################
2009-07-23 15:29:07 +00:00
//DEPRECATED, BC, call the method only when needed, $e107->ns caught by __get()
$ns = e107 :: getRender (); //TODO - find & replace $ns, $e107->ns
2006-12-02 04:36:16 +00:00
2010-10-27 11:26:21 +00:00
// EONE-134 - bad e_module could destroy e107 instance
$e107 = e107 :: getInstance ();
2006-12-02 04:36:16 +00:00
$e107 -> ban ();
2008-01-06 22:16:37 +00:00
if ( varset ( $pref [ 'force_userupdate' ]) && USER && ! isset ( $_E107 [ 'no_forceuserupdate' ]))
{
2009-12-07 20:47:37 +00:00
if ( force_userupdate ( $currentUser ))
2008-08-03 08:00:19 +00:00
{
2008-11-27 02:18:25 +00:00
header ( 'Location: ' . e_BASE . 'usersettings.php?update' );
2008-08-03 08:00:19 +00:00
exit ();
2006-12-02 04:36:16 +00:00
}
}
$sql -> db_Mark_Time ( 'Start: Signup/splash/admin' );
2009-08-20 13:54:42 +00:00
if (( $pref [ 'membersonly_enabled' ] && ! isset ( $_E107 [ 'allow_guest' ])) || $pref [ 'maintainance_flag' ])
2008-01-06 22:16:37 +00:00
{
2009-08-20 13:54:42 +00:00
//XXX move force_userupdate() also?
2009-11-22 14:10:09 +00:00
e107 :: getRedirect () -> checkMaintenance ();
e107 :: getRedirect () -> checkMembersOnly ();
2006-12-02 04:36:16 +00:00
}
2008-05-19 08:54:38 +00:00
// ------------------------------------------------------------------------
2008-01-06 22:16:37 +00:00
if ( ! isset ( $_E107 [ 'no_prunetmp' ]))
{
2008-11-27 02:18:25 +00:00
$sql -> db_Delete ( 'tmp' , 'tmp_time < ' . ( time () - 300 ) . " AND tmp_ip!='data' AND tmp_ip!='submitted_link' " );
2008-01-06 22:16:37 +00:00
}
2006-12-02 04:36:16 +00:00
2009-01-04 16:00:19 +00:00
2006-12-02 04:36:16 +00:00
$sql -> db_Mark_Time ( '(Start: Login/logout/ban/tz)' );
2009-01-04 16:00:19 +00:00
2008-11-25 16:26:03 +00:00
if ( isset ( $_POST [ 'userlogin' ]) || isset ( $_POST [ 'userlogin_x' ]))
2008-06-13 20:20:23 +00:00
{
2010-05-14 18:45:51 +00:00
e107 :: getUser () -> login ( $_POST [ 'username' ], $_POST [ 'userpass' ], $_POST [ 'autologin' ], varset ( $_POST [ 'hashchallenge' ], '' ), false );
// e107_require_once(e_HANDLER.'login.php');
// $usr = new userlogin($_POST['username'], $_POST['userpass'], $_POST['autologin'], varset($_POST['hashchallenge'],''));
2006-12-02 04:36:16 +00:00
}
2010-10-26 07:41:20 +00:00
// $_SESSION['ubrowser'] check not needed anymore - see session handler
2011-11-25 17:17:09 +00:00
// e_QUERY not defined in single entry mod
if (( $_SERVER [ 'QUERY_STRING' ] == 'logout' ) /* || (($pref['user_tracking'] == 'session') && isset($_SESSION['ubrowser']) && ($_SESSION['ubrowser'] != $ubrowser))*/ )
2007-12-15 15:06:40 +00:00
{
2009-01-04 16:00:19 +00:00
if ( USER )
{
if ( check_class ( varset ( $pref [ 'user_audit_class' ], '' )))
{ // Need to note in user audit trail
$admin_log -> user_audit ( USER_AUDIT_LOGOUT , '' );
}
2007-12-15 15:06:40 +00:00
}
2006-12-02 04:36:16 +00:00
$ip = $e107 -> getip ();
2008-11-27 02:18:25 +00:00
$udata = ( USER === true ? USERID . '.' . USERNAME : '0' );
2011-06-07 12:40:34 +00:00
2010-10-26 07:41:20 +00:00
// TODO - should be done inside online handler, more core areas need it (session handler for example)
2011-08-12 19:27:13 +00:00
if ( isset ( $pref [ 'track_online' ]) && $pref [ 'track_online' ])
{
$sql -> db_Update ( 'online' , " online_user_id = 0, online_pagecount=online_pagecount+1 WHERE online_user_id = ' { $udata } ' LIMIT 1 " );
}
2011-12-06 08:00:42 +00:00
// earlier event trigger with user data still available
e107 :: getEvent () -> trigger ( 'logout' );
2006-12-02 04:36:16 +00:00
2009-08-28 15:21:23 +00:00
if ( $pref [ 'user_tracking' ] == 'session' )
2009-01-04 16:00:19 +00:00
{
2006-12-02 04:36:16 +00:00
session_destroy ();
2008-11-27 02:18:25 +00:00
$_SESSION [ e_COOKIE ] = '' ;
2006-12-02 04:36:16 +00:00
}
2008-11-27 02:18:25 +00:00
cookie ( e_COOKIE , '' , ( time () - 2592000 ));
2011-09-14 11:30:58 +00:00
e107 :: getUser () -> logout ();
2011-11-25 17:17:09 +00:00
e107 :: getRedirect () -> redirect ( SITEURL );
2009-11-22 14:10:09 +00:00
// header('location:'.e_BASE.'index.php');
2009-05-26 20:18:07 +00:00
exit ();
2006-12-02 04:36:16 +00:00
}
/*
* Calculate time zone offset , based on session cookie set in e107 . js .
* ( Buyer beware : this may be wrong for the first pageview in a session ,
* which is while the user is logged out , so not a problem ... )
*
* Time offset is SECONDS . Seconds is much better than hours as a base ,
* as some places have 30 and 45 minute time zones .
* It matches user clock time , instead of only time zones .
* Add the offset to MySQL / server time to get user time .
* Subtract the offset from user time to get server time .
*
*/
$e_deltaTime = 0 ;
2008-11-27 02:18:25 +00:00
if ( isset ( $_COOKIE [ 'e107_tdOffset' ]))
{
2006-12-02 04:36:16 +00:00
// Actual seconds of delay. See e107.js and footer_default.php
2011-03-10 18:47:36 +00:00
$e_deltaTime = ( 15 * floor (( $_COOKIE [ 'e107_tdOffset' ] / 60 ) / 15 )) * 60 ; // Delay in seconds rounded to the lowest quarter hour
2006-12-02 04:36:16 +00:00
}
2008-11-27 02:18:25 +00:00
if ( isset ( $_COOKIE [ 'e107_tzOffset' ]))
{
2006-12-02 04:36:16 +00:00
// Relative client-to-server time zone offset in seconds.
$e_deltaTime += ( - ( $_COOKIE [ 'e107_tzOffset' ] * 60 + date ( " Z " )));
}
2008-11-27 02:18:25 +00:00
define ( 'TIMEOFFSET' , $e_deltaTime );
2006-12-02 04:36:16 +00:00
2009-07-07 16:04:51 +00:00
// ----------------------------------------------------------------------------
2009-07-12 14:44:57 +00:00
$sql -> db_Mark_Time ( '(Start: Find/Load Theme)' );
2009-11-22 14:10:09 +00:00
if ( e_ADMIN_AREA ) // Load admin phrases ASAP
2010-02-10 21:53:56 +00:00
{
2009-11-22 14:10:09 +00:00
e107 :: includeLan ( e_LANGUAGEDIR . e_LANGUAGE . '/admin/lan_admin.php' );
}
2009-07-12 14:44:57 +00:00
if ( ! defined ( 'THEME' ))
{
2010-02-10 21:53:56 +00:00
2009-10-01 15:05:41 +00:00
if ( e_ADMIN_AREA && varsettrue ( $pref [ 'admintheme' ]))
2009-07-12 14:44:57 +00:00
{
2009-08-19 14:39:57 +00:00
//We have now e_IFRAME mod and USER_AREA force
// && (strpos(e_SELF.'?'.e_QUERY, 'menus.php?configure') === FALSE)
2009-08-28 15:21:23 +00:00
2009-07-12 14:44:57 +00:00
/* if ( strpos ( e_SELF , " newspost.php " ) !== FALSE )
{
define ( " MAINTHEME " , e_THEME . $pref [ 'sitetheme' ] . " / " ); MAINTHEME no longer used in core distribution
} */
2009-07-18 10:17:56 +00:00
checkvalidtheme ( $pref [ 'admintheme' ]);
2009-07-12 14:44:57 +00:00
}
2009-09-29 17:45:06 +00:00
elseif ( USERTHEME !== false /* && USERTHEME != 'USERTHEME'*/ && ! e_ADMIN_AREA )
2009-07-12 14:44:57 +00:00
{
2009-07-18 10:17:56 +00:00
checkvalidtheme ( USERTHEME );
2009-07-12 14:44:57 +00:00
}
else
{
2009-07-18 10:17:56 +00:00
checkvalidtheme ( $pref [ 'sitetheme' ]);
2009-07-12 14:44:57 +00:00
}
}
$theme_pref = varset ( $pref [ 'sitetheme_pref' ]);
// --------------------------------------------------------------
$sql -> db_Mark_Time ( '(Start: Find/Load Theme-Layout)' ); // needs to run after checkvalidtheme() (for theme previewing).
2009-07-07 16:04:51 +00:00
if ( ! defined ( " THEME_LAYOUT " ))
{
$def = " " ; // no custom pages found yet.
2009-09-06 22:12:39 +00:00
$cusPagePref = ( varset ( $user_pref [ 'sitetheme_custompages' ])) ? $user_pref [ 'sitetheme_custompages' ] : varset ( $pref [ 'sitetheme_custompages' ]);
2009-07-07 16:04:51 +00:00
2009-07-24 12:54:39 +00:00
if ( is_array ( $cusPagePref ) && count ( $cusPagePref ) > 0 ) // check if we match a page in layout custompages.
2009-07-07 16:04:51 +00:00
{
2011-06-07 12:40:34 +00:00
//e_SELF.(e_QUERY ? '?'.e_QUERY : '');
2011-12-02 16:33:31 +00:00
$c_url = str_replace ( array ( '&' ), array ( '&' ), e_REQUEST_URL ); //.(e_QUERY ? '?'.e_QUERY : '');// mod_rewrite support
2009-07-07 22:56:13 +00:00
foreach ( $cusPagePref as $lyout => $cusPageArray )
2009-07-07 16:04:51 +00:00
{
2009-09-25 20:21:30 +00:00
if ( ! is_array ( $cusPageArray )) { continue ; }
2011-12-02 16:33:31 +00:00
// NEW - Front page template check - early
if ( in_array ( 'FRONTPAGE' , $cusPageArray ) && ( $c_url == SITEURL || rtrim ( $c_url , '/' ) == SITEURL . 'index.php' ))
{
$def = $lyout ;
break ;
}
2009-07-07 16:04:51 +00:00
foreach ( $cusPageArray as $kpage )
{
2009-09-25 20:21:30 +00:00
if ( substr ( $kpage , - 1 ) === '!' )
{
$kpage = rtrim ( $kpage , '!' );
if ( substr ( $c_url , - strlen ( $kpage )) === $kpage )
{
$def = $lyout ;
break 2 ;
}
continue ;
}
2011-12-06 09:44:28 +00:00
if ( $kpage && ( $kpage == defset ( 'e_PAGE' ) || strpos ( $c_url , $kpage ) !== false ))
2009-07-07 16:04:51 +00:00
{
2009-07-09 08:31:38 +00:00
// $def = ($lyout) ? $lyout : "legacyCustom";
$def = $lyout ;
2009-08-27 12:56:23 +00:00
break 2 ;
2009-07-07 16:04:51 +00:00
}
}
}
}
2009-08-19 14:39:57 +00:00
/* Done via e_IFRAME and USER_AREA force combination , check moved to menu . php
2009-07-09 08:31:38 +00:00
if ( strpos ( e_SELF . '?' . e_QUERY , $ADMIN_DIRECTORY . 'menus.php?configure' ) !== FALSE )
{
$menus_equery = explode ( '.' , e_QUERY );
$def = $menus_equery [ 1 ];
}
2009-08-19 14:39:57 +00:00
*/
2009-08-28 15:21:23 +00:00
2009-07-07 16:04:51 +00:00
if ( $def ) // custom-page layout.
{
define ( " THEME_LAYOUT " , $def );
}
else // default layout.
{
2009-07-09 08:31:38 +00:00
$deflayout = ( ! isset ( $user_pref [ 'sitetheme_deflayout' ])) ? varset ( $pref [ 'sitetheme_deflayout' ]) : $user_pref [ 'sitetheme_deflayout' ];
2009-12-13 21:52:32 +00:00
/**
* @ ignore
*/
2009-07-07 22:56:13 +00:00
define ( " THEME_LAYOUT " , $deflayout ); // default layout.
2009-07-07 16:04:51 +00:00
}
2009-07-09 08:31:38 +00:00
unset ( $def , $lyout , $cusPagePref , $menus_equery , $deflayout );
2009-07-07 22:56:13 +00:00
2009-07-07 16:04:51 +00:00
}
// -----------------------------------------------------------------------
2006-12-02 04:36:16 +00:00
$sql -> db_Mark_Time ( 'Start: Get menus' );
2008-01-06 22:16:37 +00:00
if ( ! isset ( $_E107 [ 'no_menus' ]))
{
2009-08-16 16:30:56 +00:00
e107 :: getMenu () -> init ();
2009-07-06 05:59:42 +00:00
}
2008-01-06 22:16:37 +00:00
// here we USE the theme
2009-11-22 14:10:09 +00:00
if ( e_ADMIN_AREA )
2008-01-06 22:16:37 +00:00
{
2009-08-19 14:39:57 +00:00
if ( file_exists ( THEME . 'admin_theme.php' ) && ( strpos ( e_SELF . '?' . e_QUERY , $ADMIN_DIRECTORY . 'menus.php?configure' ) === FALSE )) // no admin theme when previewing.
{
require_once ( THEME . 'admin_theme.php' );
}
else
{
require_once ( THEME . 'theme.php' );
}
2008-11-25 16:26:03 +00:00
}
else
2008-05-29 21:12:55 +00:00
{
2009-08-19 14:39:57 +00:00
require_once ( THEME . 'theme.php' );
2006-12-02 04:36:16 +00:00
}
2008-05-29 21:12:55 +00:00
2008-08-14 13:18:26 +00:00
//----------------------------
// Load shortcode handler
//----------------------------
// ********* This is probably a bodge! Work out what to do properly. Has to be done when $pref valid
//FIXED - undefined $register_sc
2009-07-23 15:29:07 +00:00
//$tp->sch_load(); - will be auto-initialized by first $tp->e_sc call - see e_parse->__get()
2008-05-29 21:12:55 +00:00
2009-08-28 16:15:57 +00:00
/*
2008-11-27 02:18:25 +00:00
$exclude_lan = array ( 'lan_signup.php' ); // required for multi-language.
2006-12-02 04:36:16 +00:00
2008-05-29 21:12:55 +00:00
if ( $inAdminDir )
{
2009-08-19 14:39:57 +00:00
e107_include_once ( e_LANGUAGEDIR . e_LANGUAGE . '/admin/lan_' . e_PAGE );
e107_include_once ( e_LANGUAGEDIR . 'English/admin/lan_' . e_PAGE );
2008-11-25 16:26:03 +00:00
}
2008-11-27 02:18:25 +00:00
elseif ( ! in_array ( 'lan_' . e_PAGE , $exclude_lan ) && ! $isPluginDir )
2008-05-29 21:12:55 +00:00
{
2009-08-19 14:39:57 +00:00
e107_include_once ( e_LANGUAGEDIR . e_LANGUAGE . '/lan_' . e_PAGE );
e107_include_once ( e_LANGUAGEDIR . 'English/lan_' . e_PAGE );
2006-12-02 04:36:16 +00:00
}
2009-08-28 16:15:57 +00:00
*/
2006-12-02 04:36:16 +00:00
2008-11-27 02:18:25 +00:00
if ( $pref [ 'anon_post' ] ? define ( 'ANON' , true ) : define ( 'ANON' , false ));
2006-12-02 04:36:16 +00:00
2008-11-27 02:18:25 +00:00
if ( empty ( $pref [ 'newsposts' ]) ? define ( 'ITEMVIEW' , 15 ) : define ( 'ITEMVIEW' , $pref [ 'newsposts' ]));
2006-12-02 04:36:16 +00:00
2008-11-25 16:26:03 +00:00
if ( $pref [ 'antiflood1' ] == 1 )
2007-09-18 21:15:41 +00:00
{
2009-08-19 14:39:57 +00:00
define ( 'FLOODPROTECT' , TRUE );
define ( 'FLOODTIMEOUT' , max ( varset ( $pref [ 'antiflood_timeout' ], 10 ), 3 ));
2007-09-18 21:15:41 +00:00
}
else
{
2009-12-13 21:52:32 +00:00
/**
* @ ignore
*/
define ( 'FLOODPROTECT' , FALSE );
2006-12-02 04:36:16 +00:00
}
$layout = isset ( $layout ) ? $layout : '_default' ;
2008-11-27 02:18:25 +00:00
define ( 'HEADERF' , e_THEME . " templates/header { $layout } .php " );
define ( 'FOOTERF' , e_THEME . " templates/footer { $layout } .php " );
2006-12-02 04:36:16 +00:00
2008-11-27 02:18:25 +00:00
if ( ! file_exists ( HEADERF ))
{
message_handler ( 'CRITICAL_ERROR' , 'Unable to find file: ' . HEADERF , __LINE__ - 2 , __FILE__ );
2006-12-02 04:36:16 +00:00
}
2008-11-27 02:18:25 +00:00
if ( ! file_exists ( FOOTERF ))
{
message_handler ( 'CRITICAL_ERROR' , 'Unable to find file: ' . FOOTERF , __LINE__ - 2 , __FILE__ );
2006-12-02 04:36:16 +00:00
}
2008-11-27 02:18:25 +00:00
define ( 'LOGINMESSAGE' , '' );
define ( 'OPEN_BASEDIR' , ( ini_get ( 'open_basedir' ) ? true : false ));
define ( 'SAFE_MODE' , ( ini_get ( 'safe_mode' ) ? true : false ));
define ( 'FILE_UPLOADS' , ( ini_get ( 'file_uploads' ) ? true : false ));
define ( 'INIT' , true );
if ( isset ( $_SERVER [ 'HTTP_REFERER' ]))
{
2006-12-02 04:36:16 +00:00
$tmp = explode ( " ? " , $_SERVER [ 'HTTP_REFERER' ]);
2011-12-06 09:44:28 +00:00
define ( 'e_REFERER_SELF' ,( $tmp [ 0 ] == e_REQUEST_SELF ));
unset ( $tmp );
2008-11-27 02:18:25 +00:00
}
else
{
2009-12-13 21:52:32 +00:00
/**
* @ ignore
*/
2006-12-02 04:36:16 +00:00
define ( 'e_REFERER_SELF' , FALSE );
}
2009-10-20 16:00:38 +00:00
//BC, DEPRECATED - use e107::getDateConvert(), catched by __autoload as well
/* if ( ! class_exists ( 'convert' ))
2006-12-02 04:36:16 +00:00
{
2008-11-27 02:18:25 +00:00
require_once ( e_HANDLER . 'date_handler.php' );
2009-10-20 16:00:38 +00:00
} */
2006-12-02 04:36:16 +00:00
//@require_once(e_HANDLER."IPB_int.php");
//@require_once(e_HANDLER."debug_handler.php");
2009-08-03 19:51:24 +00:00
//-------------------------------------------------------------------------------------------------------------------------------------------
2008-11-27 02:18:25 +00:00
function js_location ( $qry )
{
2006-12-05 09:33:20 +00:00
global $error_handler ;
2008-11-27 02:18:25 +00:00
if ( count ( $error_handler -> errors ))
{
2006-12-05 09:33:20 +00:00
echo $error_handler -> return_errors ();
exit ;
2008-11-27 02:18:25 +00:00
}
else
{
2008-12-02 18:27:35 +00:00
echo " <script type='text/javascript'>document.location.href=' { $qry } '</script> \n " ;
2008-11-27 02:18:25 +00:00
exit ;
2007-12-26 13:21:34 +00:00
}
2006-12-05 09:33:20 +00:00
}
2006-12-02 04:36:16 +00:00
2008-11-27 02:18:25 +00:00
function check_email ( $email )
{
return preg_match ( " /^([_a-zA-Z0-9-+]+)( \ .[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+)( \ .[a-zA-Z0-9-]+)*( \ .[a-zA-Z] { 2,6}) $ / " , $email ) ? $email : false ;
2006-12-02 04:36:16 +00:00
}
2009-08-03 19:51:24 +00:00
//---------------------------------------------------------------------------------------------------------------------------------------------
// $var is a single class number or name, or a comma-separated list of the same.
// If a class is prefixed with '-' this means 'exclude' - returns FALSE if the user is in this class (overrides 'includes').
// Otherwise returns TRUE if the user is in any of the classes listed in $var.
2007-01-12 02:36:18 +00:00
function check_class ( $var , $userclass = USERCLASS_LIST , $uid = 0 )
2006-12-02 04:36:16 +00:00
{
2009-08-03 19:51:24 +00:00
$e107 = e107 :: getInstance ();
2009-08-05 19:58:32 +00:00
if ( $var == e_LANGUAGE )
{
return TRUE ;
}
2007-12-15 09:55:37 +00:00
2007-01-12 02:36:18 +00:00
if ( is_numeric ( $uid ) && $uid > 0 )
2009-08-03 19:51:24 +00:00
{ // userid has been supplied, go build that user's class list
2007-01-12 02:36:18 +00:00
$userclass = class_list ( $uid );
2006-12-02 04:36:16 +00:00
}
2008-11-27 02:18:25 +00:00
if ( $userclass == '' )
2006-12-02 04:36:16 +00:00
{
2009-08-08 23:09:08 +00:00
return FALSE ;
2006-12-02 04:36:16 +00:00
}
2010-05-02 18:41:20 +00:00
$class_array = ! is_array ( $userclass ) ? explode ( ',' , $userclass ) : $userclass ;
2006-12-02 04:36:16 +00:00
2010-05-02 18:41:20 +00:00
$varList = ! is_array ( $var ) ? explode ( ',' , $var ) : $var ;
2009-08-03 19:51:24 +00:00
$latchedAccess = FALSE ;
2008-11-25 16:26:03 +00:00
2007-01-12 02:36:18 +00:00
foreach ( $varList as $v )
{
2009-08-08 23:09:08 +00:00
$v = trim ( $v );
2009-08-03 19:51:24 +00:00
$invert = FALSE ;
2009-08-08 23:09:08 +00:00
//value to test is a userclass name (or garbage, of course), go get the id
if ( ! is_numeric ( $v ))
2006-12-02 04:36:16 +00:00
{
2009-08-08 23:09:08 +00:00
if ( substr ( $v , 0 , 1 ) == '-' )
2009-08-03 19:51:24 +00:00
{
$invert = TRUE ;
2009-08-08 23:09:08 +00:00
$v = substr ( $v , 1 );
2009-08-03 19:51:24 +00:00
}
$v = $e107 -> user_class -> ucGetClassIDFromName ( $v );
2006-12-02 04:36:16 +00:00
}
2009-08-03 19:51:24 +00:00
elseif ( $v < 0 )
2007-01-12 02:36:18 +00:00
{
2009-08-03 19:51:24 +00:00
$invert = TRUE ;
$v = - $v ;
}
if ( $v !== FALSE )
2009-08-08 23:09:08 +00:00
{
// Ignore non-valid userclass names
if ( in_array ( $v , $class_array ) || ( $v === '0' ) || ( $v === 0 ))
2007-01-12 02:36:18 +00:00
{
2009-08-03 19:51:24 +00:00
if ( $invert )
2007-01-12 02:36:18 +00:00
{
2009-08-03 19:51:24 +00:00
return FALSE ;
2006-12-02 04:36:16 +00:00
}
2009-08-03 19:51:24 +00:00
$latchedAccess = TRUE ;
2007-01-12 02:36:18 +00:00
}
2009-08-03 19:51:24 +00:00
elseif ( $invert && count ( $varList ) == 1 )
2007-01-12 02:36:18 +00:00
{
2009-08-08 23:09:08 +00:00
// Handle scenario where only an 'exclude' class is passed
$latchedAccess = TRUE ;
2006-12-02 04:36:16 +00:00
}
}
}
2009-08-03 19:51:24 +00:00
return $latchedAccess ;
2006-12-02 04:36:16 +00:00
}
2009-08-03 19:51:24 +00:00
2008-11-27 02:18:25 +00:00
function getperms ( $arg , $ap = ADMINPERMS )
{
2011-06-07 12:40:34 +00:00
// $ap = "4"; // Just for testing.
2011-05-11 11:52:50 +00:00
if ( ! ADMIN || trim ( $ap ) === '' )
{
return FALSE ;
}
2011-06-07 12:40:34 +00:00
2011-05-11 11:52:50 +00:00
if ( $arg === 0 ) // Common-error avoidance with getperms(0)
2008-11-27 02:18:25 +00:00
{
2011-05-11 11:52:50 +00:00
$arg = '0' ;
2006-12-02 04:36:16 +00:00
}
2010-02-10 21:53:56 +00:00
if ( $ap === '0' || $ap === '0.' ) // BC fix.
2008-11-27 02:18:25 +00:00
{
2011-05-11 11:52:50 +00:00
return TRUE ;
2006-12-02 04:36:16 +00:00
}
2009-09-12 16:42:44 +00:00
if ( $arg == 'P' && preg_match ( " #(.*?)/ " . e107 :: getInstance () -> getFolder ( 'plugins' ) . " (.*?)/(.*?)# " , e_SELF , $matches ))
2008-11-27 02:18:25 +00:00
{
2009-12-24 10:51:23 +00:00
$sql = e107 :: getDb ( 'psql' );
2010-02-10 21:53:56 +00:00
2010-05-02 18:41:20 +00:00
// FIXME - cache it, avoid sql query here
2009-12-24 10:51:23 +00:00
if ( $sql -> db_Select ( 'plugin' , 'plugin_id' , " plugin_path = ' " . $matches [ 2 ] . " ' LIMIT 1 " ))
2008-11-27 02:18:25 +00:00
{
2009-12-24 10:51:23 +00:00
$row = $sql -> db_Fetch ();
2010-02-10 21:53:56 +00:00
$arg = 'P' . $row [ 'plugin_id' ];
2006-12-02 04:36:16 +00:00
}
}
2010-02-10 21:53:56 +00:00
2009-12-24 10:51:23 +00:00
$ap_array = explode ( '.' , $ap );
2009-08-05 14:18:09 +00:00
2011-05-11 11:52:50 +00:00
if ( in_array ( $arg , $ap_array , FALSE ))
2008-11-27 02:18:25 +00:00
{
2011-05-11 11:52:50 +00:00
return TRUE ;
2008-11-27 02:18:25 +00:00
}
2009-09-29 09:25:35 +00:00
elseif ( strpos ( $arg , " | " )) // check for multiple perms - separated by '|'.
2009-08-05 14:18:09 +00:00
{
2009-09-29 09:25:35 +00:00
$tmp = explode ( " | " , $arg );
2009-08-05 14:18:09 +00:00
foreach ( $tmp as $val )
{
2011-05-11 11:52:50 +00:00
if ( in_array ( $val , $ap_array ))
2009-08-05 14:18:09 +00:00
{
2011-05-11 11:52:50 +00:00
return TRUE ;
2009-08-05 14:18:09 +00:00
}
}
}
2008-11-27 02:18:25 +00:00
else
{
2011-05-11 11:52:50 +00:00
return FALSE ;
2006-12-02 04:36:16 +00:00
}
}
/**
* Get the user data from user and user_extended tables
2010-05-17 15:51:42 +00:00
* SO MUCH DEPRECATED !
*
2006-12-02 04:36:16 +00:00
*
* @ return array
*/
2008-11-27 02:18:25 +00:00
function get_user_data ( $uid , $extra = '' )
2006-12-02 04:36:16 +00:00
{
2010-05-17 15:51:42 +00:00
if ( e107 :: getPref ( 'developer' ))
{
e107 :: getAdminLog () -> log_event (
'Deprecated call - get_user_data()' ,
'Call to deprecated function get_user_data() (class2.php)' ,
E_LOG_INFORMATIVE ,
'DEPRECATED'
);
// TODO - debug screen Deprecated Functions (e107)
e107 :: getMessage () -> addDebug ( 'Deprecated get_user_data() backtrace:<pre>' . " \n " . print_r ( debug_backtrace (), true ) . '</pre>' );
}
$var = array ();
$user = e107 :: getSystemUser ( $uid , true );
if ( $user )
{
$var = $user -> getUserData ();
}
return $var ;
/* $e107 = e107 :: getInstance ();
2008-11-26 15:00:56 +00:00
$uid = ( int ) $uid ;
2006-12-02 04:36:16 +00:00
$var = array ();
if ( $uid == 0 ) { return $var ; }
if ( $ret = getcachedvars ( " userdata_ { $uid } " ))
{
return $ret ;
}
$qry = "
2008-12-22 03:15:04 +00:00
SELECT u .* , ue .* FROM `#user` AS u
LEFT JOIN `#user_extended` AS ue ON ue . user_extended_id = u . user_id
2007-11-09 05:55:45 +00:00
WHERE u . user_id = { $uid } { $extra }
2006-12-02 04:36:16 +00:00
" ;
2008-11-30 23:15:15 +00:00
if ( ! $e107 -> sql -> db_Select_gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
2007-11-09 05:55:45 +00:00
$qry = " SELECT * FROM #user AS u WHERE u.user_id = { $uid } { $extra } " ;
2008-11-30 23:15:15 +00:00
if ( ! $e107 -> sql -> db_Select_gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
return FALSE ;
}
}
2008-12-02 18:27:35 +00:00
$var = $e107 -> sql -> db_Fetch ( MYSQL_ASSOC );
2006-12-02 04:36:16 +00:00
2008-12-22 03:15:04 +00:00
if ( ! $e107 -> extended_struct = getcachedvars ( 'extended_struct' ))
2006-12-02 04:36:16 +00:00
{
2008-11-30 23:15:15 +00:00
if ( $tmp = $e107 -> ecache -> retrieve_sys ( 'nomd5_extended_struct' ))
{
2008-12-22 03:15:04 +00:00
$e107 -> extended_struct = $e107 -> arrayStorage -> ReadArray ( $tmp );
2008-11-30 23:15:15 +00:00
}
else
2006-12-02 04:36:16 +00:00
{
2008-12-22 03:15:04 +00:00
$qry = 'SHOW COLUMNS FROM `#user_extended` ' ;
2008-11-30 23:15:15 +00:00
if ( $e107 -> sql -> db_Select_gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
2008-11-30 23:15:15 +00:00
while ( $row = $e107 -> sql -> db_Fetch ())
2006-12-02 04:36:16 +00:00
{
2008-12-22 03:15:04 +00:00
$e107 -> extended_struct [] = $row ;
2006-12-02 04:36:16 +00:00
}
}
2008-12-22 03:15:04 +00:00
$tmp = $e107 -> arrayStorage -> WriteArray ( $e107 -> extended_struct , false );
2008-11-30 23:15:15 +00:00
$e107 -> ecache -> set_sys ( 'nomd5_extended_struct' , $tmp );
unset ( $tmp );
}
2008-12-22 03:15:04 +00:00
if ( isset ( $e107 -> extended_struct ))
2008-11-30 23:15:15 +00:00
{
2008-12-22 03:15:04 +00:00
cachevars ( 'extended_struct' , $e107 -> extended_struct );
2006-12-02 04:36:16 +00:00
}
}
2008-12-22 03:15:04 +00:00
if ( isset ( $e107 -> extended_struct ) && is_array ( $e107 -> extended_struct ))
2006-12-02 04:36:16 +00:00
{
2008-12-22 03:15:04 +00:00
foreach ( $e107 -> extended_struct as $row )
2006-12-02 04:36:16 +00:00
{
2008-11-27 02:18:25 +00:00
if ( $row [ 'Default' ] != '' && ( $var [ $row [ 'Field' ]] == NULL || $var [ $row [ 'Field' ]] == '' ))
2006-12-02 04:36:16 +00:00
{
$var [ $row [ 'Field' ]] = $row [ 'Default' ];
}
}
}
2008-11-25 16:26:03 +00:00
2010-05-17 15:51:42 +00:00
2010-05-03 21:31:29 +00:00
if ( $var [ 'user_perms' ] == '0.' ) $var [ 'user_perms' ] = '0' ; // Handle some legacy situations
2007-12-22 12:39:27 +00:00
//===========================================================
2008-12-28 22:37:43 +00:00
$var [ 'user_baseclasslist' ] = $var [ 'user_class' ]; // Keep track of which base classes are in DB
2007-12-22 12:39:27 +00:00
// Now look up the 'inherited' user classes
2008-12-04 21:05:05 +00:00
$var [ 'user_class' ] = $e107 -> user_class -> get_all_user_classes ( $var [ 'user_class' ]);
2008-11-25 16:26:03 +00:00
2007-12-22 12:39:27 +00:00
//===========================================================
2008-11-25 16:26:03 +00:00
2008-12-22 03:15:04 +00:00
cachevars ( " userdata_ { $uid } " , $var );
2006-12-02 04:36:16 +00:00
return $var ;
2010-05-17 15:51:42 +00:00
*/
2006-12-02 04:36:16 +00:00
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
2009-08-17 14:40:23 +00:00
//SO MUCH DEPRECATED - use e107::getConfig(alias)->save() instead
2008-01-16 10:53:57 +00:00
function save_prefs ( $table = 'core' , $uid = USERID , $row_val = '' )
2007-02-03 12:43:53 +00:00
{
2010-03-14 02:11:23 +00:00
global $pref , $user_pref , $tp , $PrefCache , $sql , $eArrayStorage , $theme_pref ;
2009-08-28 15:21:23 +00:00
2010-05-17 15:51:42 +00:00
if ( e107 :: getPref ( 'developer' ))
{
e107 :: getAdminLog () -> log_event (
'Deprecated call - save_prefs()' ,
'Call to deprecated function save_prefs() (class2.php)' ,
E_LOG_INFORMATIVE ,
'DEPRECATED'
);
// TODO - debug screen Deprecated Functions (e107)
e107 :: getMessage () -> addDebug ( 'Deprecated save_prefs() backtrace:<pre>' . " \n " . print_r ( debug_backtrace (), true ) . '</pre>' );
}
2009-08-17 14:40:23 +00:00
switch ( $table )
{
case 'core' :
//brute load, force update
return e107 :: getConfig () -> loadData ( $pref , false ) -> save ( false , true );
break ;
2009-08-28 15:21:23 +00:00
2009-08-17 14:40:23 +00:00
case 'theme' :
//brute load, force update
return e107 :: getConfig () -> set ( 'sitetheme_pref' , $theme_pref ) -> save ( false , true );
break ;
2009-08-28 15:21:23 +00:00
2009-08-17 14:40:23 +00:00
default :
2010-09-06 21:35:04 +00:00
$_user_pref = $tp -> toDB ( $user_pref , true , true , 'pReFs' );
2009-08-17 14:40:23 +00:00
$tmp = $eArrayStorage -> WriteArray ( $_user_pref );
$sql -> db_Update ( 'user' , " user_prefs=' $tmp ' WHERE user_id= " . intval ( $uid ));
return $tmp ;
break ;
}
/*
2008-11-25 16:26:03 +00:00
if ( $table == 'core' )
2007-02-03 12:43:53 +00:00
{
2008-11-25 16:26:03 +00:00
if ( $row_val == '' )
2008-01-16 10:53:57 +00:00
{ // Save old version as a backup first
$sql -> db_Select_gen ( " REPLACE INTO `#core` (e107_name,e107_value) values ('SitePrefs_Backup', ' " . addslashes ( $PrefCache ) . " ') " );
// Now save the updated values
// traverse the pref array, with toDB on everything
2008-12-22 03:15:04 +00:00
$_pref = $tp -> toDB ( $pref , true , true );
2008-01-16 10:53:57 +00:00
// Create the data to be stored
if ( $sql -> db_Select_gen ( " REPLACE INTO `#core` (e107_name,e107_value) values ('SitePrefs', ' " . $eArrayStorage -> WriteArray ( $_pref ) . " ') " ))
{
2009-08-16 23:58:33 +00:00
ecache :: clear_sys ( 'Config_core' );
2008-11-27 02:18:25 +00:00
return true ;
2008-01-16 10:53:57 +00:00
}
else
{
2008-11-27 02:18:25 +00:00
return false ;
2008-01-16 10:53:57 +00:00
}
2007-03-04 21:47:15 +00:00
}
2007-02-03 12:43:53 +00:00
}
2009-07-06 05:59:42 +00:00
elseif ( $table == " theme " )
{
$pref [ 'sitetheme_pref' ] = $theme_pref ;
save_prefs ();
}
2008-11-25 16:26:03 +00:00
else
2007-02-03 12:43:53 +00:00
{
2009-07-04 13:36:15 +00:00
// $_user_pref = $tp -> toDB($user_pref);
// $tmp=addslashes(serialize($_user_pref));
$_user_pref = $tp -> toDB ( $user_pref , true , true );
$tmp = $eArrayStorage -> WriteArray ( $_user_pref );
2008-12-22 03:15:04 +00:00
$sql -> db_Update ( 'user' , " user_prefs=' $tmp ' WHERE user_id= " . intval ( $uid ));
2007-03-04 21:47:15 +00:00
return $tmp ;
2007-02-03 12:43:53 +00:00
}
2009-08-17 14:40:23 +00:00
*/
2006-12-02 04:36:16 +00:00
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
2009-07-22 00:49:35 +00:00
//DEPRECATED - use e107::setRegistry()
2008-11-27 02:18:25 +00:00
function cachevars ( $id , $var )
{
2009-07-22 00:49:35 +00:00
e107 :: setRegistry ( 'core/cachedvars/' . $id , $var );
2006-12-02 04:36:16 +00:00
}
2009-07-22 00:49:35 +00:00
//DEPRECATED - use e107::getRegistry()
2008-11-27 02:18:25 +00:00
function getcachedvars ( $id )
{
2009-08-06 22:39:36 +00:00
return e107 :: getRegistry ( 'core/cachedvars/' . $id , false );
2006-12-02 04:36:16 +00:00
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
2009-12-13 21:52:32 +00:00
/**
* @ package e107
*/
2008-11-27 02:18:25 +00:00
class floodprotect
{
function flood ( $table , $orderfield )
{
2006-12-02 04:36:16 +00:00
/*
# Test for possible flood
#
# - parameter #1 string $table, table being affected
# - parameter #2 string $orderfield, date entry in respective table
# - return boolean
# - scope public
*/
$sql = new db ;
2008-11-27 02:18:25 +00:00
if ( FLOODPROTECT == true )
{
$sql -> db_Select ( $table , '*' , 'ORDER BY ' . $orderfield . ' DESC LIMIT 1' , 'no_where' );
2006-12-02 04:36:16 +00:00
$row = $sql -> db_Fetch ();
2008-11-27 02:18:25 +00:00
return ( $row [ $orderfield ] > ( time () - FLOODTIMEOUT ) ? false : true );
}
else
{
2006-12-02 04:36:16 +00:00
return TRUE ;
}
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
2010-05-14 18:45:51 +00:00
/**
* The whole could happen inside e_user class
* @ return void
*/
2008-11-27 02:18:25 +00:00
function init_session ()
{
2006-12-02 04:36:16 +00:00
/*
# Validate user
#
# - parameters none
# - return boolean
# - scope public
*/
2010-02-10 21:53:56 +00:00
2010-05-14 18:45:51 +00:00
global $user_pref , $currentUser ;
2010-02-10 21:53:56 +00:00
2010-05-13 15:47:31 +00:00
$e107 = e107 :: getInstance ();
2010-02-10 21:53:56 +00:00
2010-05-14 18:45:51 +00:00
// New user model
$user = e107 :: getUser ();
2006-12-02 04:36:16 +00:00
define ( 'USERIP' , $e107 -> getip ());
2010-05-19 15:28:52 +00:00
define ( 'POST_REFERER' , md5 ( $user -> getToken ()));
// Check for intruders - outside the model for now
2010-10-26 07:41:20 +00:00
// TODO replace __referer with e-token, remove the above
2010-05-19 15:28:52 +00:00
if (( isset ( $_POST [ '__referer' ]) && ! $user -> checkToken ( $_POST [ '__referer' ]))
|| ( isset ( $_GET [ '__referer' ]) && ! $user -> checkToken ( $_GET [ '__referer' ])))
{
// Die, die, die! DIE!!!
die ( 'Unauthorized access!' );
}
2010-02-10 21:53:56 +00:00
2010-05-14 18:45:51 +00:00
if ( e107 :: isCli ())
2008-01-22 00:39:08 +00:00
{
2009-12-24 09:59:21 +00:00
define ( 'USER' , true );
define ( 'USERID' , 1 );
define ( 'USERNAME' , 'e107-cli' );
define ( 'USERTHEME' , false );
define ( 'ADMIN' , true );
define ( 'GUEST' , false );
define ( 'USERCLASS' , '' );
define ( 'USEREMAIL' , '' );
define ( 'USERCLASS_LIST' , '' );
2010-02-10 21:53:56 +00:00
define ( 'USERCLASS' , '' );
2009-12-24 09:59:21 +00:00
return ;
2008-01-22 00:39:08 +00:00
}
2010-05-14 18:45:51 +00:00
if ( $user -> hasBan ())
{
$msg = e107 :: findPref ( 'ban_messages/6' );
if ( $msg ) echo e107 :: getParser () -> toHTML ( $msg );
exit ;
}
if ( ! $user -> isUser ())
2008-01-22 00:39:08 +00:00
{
2008-11-27 02:18:25 +00:00
define ( 'USER' , false );
2008-06-13 20:20:23 +00:00
define ( 'USERID' , 0 );
2008-11-27 02:18:25 +00:00
define ( 'USERTHEME' , false );
define ( 'ADMIN' , false );
define ( 'GUEST' , true );
2006-12-02 04:36:16 +00:00
define ( 'USERCLASS' , '' );
define ( 'USEREMAIL' , '' );
2010-05-14 18:45:51 +00:00
if ( $user -> hasSessionError ())
{
define ( 'LOGINMESSAGE' , CORE_LAN10 );
define ( 'CORRUPT_COOKIE' , true );
}
2008-01-22 00:39:08 +00:00
}
else
{
2010-05-14 18:45:51 +00:00
// we shouldn't use getValue() here, it's there for e.g. shortcodes, profile page render etc.
define ( 'USERID' , $user -> getId ());
define ( 'USERNAME' , $user -> get ( 'user_name' ));
// define('USERURL', $user->get('user_homepage', false)); OLD?
define ( 'USEREMAIL' , $user -> get ( 'user_email' ));
define ( 'USER' , true );
define ( 'USERCLASS' , $user -> get ( 'user_class' ));
define ( 'USERIMAGE' , $user -> get ( 'user_image' ));
define ( 'USERPHOTO' , $user -> get ( 'user_sess' ));
define ( 'ADMIN' , $user -> isAdmin ());
define ( 'ADMINID' , $user -> getAdminId ());
define ( 'ADMINNAME' , $user -> getAdminName ());
define ( 'ADMINPERMS' , $user -> getAdminPerms ());
define ( 'ADMINEMAIL' , $user -> getAdminEmail ());
define ( 'ADMINPWCHANGE' , $user -> getAdminPwchange ());
if ( ADMIN ) // XXX - why for admins only?
{
e107 :: getRedirect () -> setPreviousUrl ();
}
define ( 'USERLV' , $user -> get ( 'user_lastvisit' ));
// BC - FIXME - get rid of them!
$currentUser = $user -> getData ();
2011-11-25 17:17:09 +00:00
$currentUser [ 'user_realname' ] = $user -> get ( 'user_login' ); // Used by force_userupdate
2010-05-14 18:45:51 +00:00
$e107 -> currentUser = & $currentUser ;
2011-11-29 23:37:44 +00:00
// if(defined('SETTHEME')) //override - within e_module for example.
// {
// $_POST['sitetheme'] = SETTHEME;
// $_POST['settheme'] = 1;
// }
2010-05-15 17:33:11 +00:00
// XXX could go to e_user class as well
2010-05-14 18:45:51 +00:00
if ( $user -> checkClass ( e107 :: getPref ( 'allow_theme_select' , false ), false ))
{ // User can set own theme
if ( isset ( $_POST [ 'settheme' ]))
{
$uconfig = $user -> getConfig ();
if ( e107 :: getPref ( 'sitetheme' ) != $_POST [ 'sitetheme' ])
{
require_once ( e_HANDLER . " theme_handler.php " );
$utheme = new themeHandler ;
$ut = $utheme -> themeArray [ $_POST [ 'sitetheme' ]];
$uconfig -> setPosted ( 'sitetheme' , $_POST [ 'sitetheme' ])
-> setPosted ( 'sitetheme_custompages' , $ut [ 'custompages' ])
-> setPosted ( 'sitetheme_deflayout' , $utheme -> findDefault ( $_POST [ 'sitetheme' ]));
}
else
{
$uconfig -> remove ( 'sitetheme' )
-> remove ( 'sitetheme_custompages' )
-> remove ( 'sitetheme_deflayout' );
}
$uconfig -> save ( true );
unset ( $ut );
}
}
elseif ( $user -> getPref ( 'sitetheme' ))
{
$user -> getConfig ()
-> remove ( 'sitetheme' )
-> remove ( 'sitetheme_custompages' )
-> remove ( 'sitetheme_deflayout' )
-> save ( false );
}
2010-05-15 17:33:11 +00:00
// XXX could go to e_user class as well END
2011-11-29 23:37:44 +00:00
if ( ! defined ( " USERTHEME " ))
{
define ( 'USERTHEME' , ( $user -> getPref ( 'sitetheme' ) && file_exists ( e_THEME . $user -> getPref ( 'sitetheme' ) . " /theme.php " ) ? $user -> getPref ( 'sitetheme' ) : false ));
}
2010-05-14 18:45:51 +00:00
$user_pref = $user -> getPref ();
}
define ( 'USERCLASS_LIST' , $user -> getClassList ( true ));
2010-05-15 17:33:11 +00:00
define ( 'e_CLASS_REGEXP' , $user -> getClassRegex ());
2010-05-14 18:45:51 +00:00
define ( 'e_NOBODY_REGEXP' , '(^|,)' . e_UC_NOBODY . '(,|$)' );
/* XXX - remove it after everything is working well !!
2008-03-13 19:15:56 +00:00
if ( ! isset ( $_E107 [ 'cli' ]))
2008-01-22 00:39:08 +00:00
{
2008-05-19 09:42:28 +00:00
list ( $uid , $upw ) = ( isset ( $_COOKIE [ e_COOKIE ]) && $_COOKIE [ e_COOKIE ] ? explode ( " . " , $_COOKIE [ e_COOKIE ]) : explode ( " . " , $_SESSION [ e_COOKIE ]));
2008-01-22 00:39:08 +00:00
}
2010-05-13 15:47:31 +00:00
else // FIXME - this will never happen - see above
2008-01-22 00:39:08 +00:00
{
2008-12-22 03:15:04 +00:00
list ( $uid , $upw ) = explode ( '.' , $cli_log );
2008-01-22 00:39:08 +00:00
}
2006-12-02 04:36:16 +00:00
2008-11-25 16:26:03 +00:00
if ( empty ( $uid ) || empty ( $upw ))
2008-06-13 20:20:23 +00:00
{
2009-11-22 14:10:09 +00:00
//$_SESSION[] = e_SELF."?".e_QUERY;
2010-02-10 21:53:56 +00:00
2008-11-27 02:18:25 +00:00
cookie ( e_COOKIE , '' , ( time () - 2592000 ));
2008-05-19 09:42:28 +00:00
$_SESSION [ e_COOKIE ] = " " ;
2006-12-02 04:36:16 +00:00
session_destroy ();
2008-11-27 02:18:25 +00:00
define ( 'ADMIN' , false );
define ( 'USER' , false );
2008-06-13 20:20:23 +00:00
define ( 'USERID' , 0 );
2008-11-27 02:18:25 +00:00
define ( 'USERCLASS' , '' );
2009-07-07 21:39:18 +00:00
define ( 'USERCLASS_LIST' , class_list ());
2008-11-27 02:18:25 +00:00
define ( 'LOGINMESSAGE' , CORE_LAN10 . '<br /><br />' );
return ( false );
2006-12-02 04:36:16 +00:00
}
$result = get_user_data ( $uid );
if ( is_array ( $result ) && md5 ( $result [ 'user_password' ]) == $upw )
{
2008-11-27 02:18:25 +00:00
define ( 'USERID' , $result [ 'user_id' ]);
define ( 'USERNAME' , $result [ 'user_name' ]);
define ( 'USERURL' , ( isset ( $result [ 'user_homepage' ]) ? $result [ 'user_homepage' ] : false ));
define ( 'USEREMAIL' , $result [ 'user_email' ]);
define ( 'USER' , true );
define ( 'USERCLASS' , $result [ 'user_class' ]);
2009-08-06 22:39:36 +00:00
//define('USERVIEWED', $result['user_viewed']); - removed from the DB
2008-11-27 02:18:25 +00:00
define ( 'USERIMAGE' , $result [ 'user_image' ]);
define ( 'USERPHOTO' , $result [ 'user_sess' ]);
2006-12-02 04:36:16 +00:00
$update_ip = ( $result [ 'user_ip' ] != USERIP ? " , user_ip = ' " . USERIP . " ' " : " " );
if ( $result [ 'user_currentvisit' ] + 3600 < time () || ! $result [ 'user_lastvisit' ])
{
$result [ 'user_lastvisit' ] = $result [ 'user_currentvisit' ];
$result [ 'user_currentvisit' ] = time ();
2008-12-19 22:56:22 +00:00
$sql -> db_Update ( 'user' , " user_visits = user_visits + 1, user_lastvisit = ' { $result [ 'user_lastvisit' ] } ', user_currentvisit = ' { $result [ 'user_currentvisit' ] } ' { $update_ip } WHERE user_id=' " . USERID . " ' " );
2006-12-02 04:36:16 +00:00
}
else
{
$result [ 'user_currentvisit' ] = time ();
2008-11-27 02:18:25 +00:00
$sql -> db_Update ( 'user' , " user_currentvisit = ' { $result [ 'user_currentvisit' ] } ' { $update_ip } WHERE user_id=' " . USERID . " ' " );
2006-12-02 04:36:16 +00:00
}
$currentUser = $result ;
$currentUser [ 'user_realname' ] = $result [ 'user_login' ]; // Used by force_userupdate
2008-12-02 18:27:35 +00:00
$e107 -> currentUser = & $currentUser ;
2008-11-27 02:18:25 +00:00
define ( 'USERLV' , $result [ 'user_lastvisit' ]);
2006-12-02 04:36:16 +00:00
2008-11-25 16:26:03 +00:00
if ( $result [ 'user_ban' ] == 1 )
{
2007-12-09 16:42:23 +00:00
if ( isset ( $pref [ 'ban_messages' ]))
{
echo $tp -> toHTML ( varsettrue ( $pref [ 'ban_messages' ][ 6 ])); // Show message if one set
}
2008-11-25 16:26:03 +00:00
exit ;
2007-12-09 16:42:23 +00:00
}
2006-12-02 04:36:16 +00:00
2009-08-28 15:21:23 +00:00
if ( $result [ 'user_admin' ])
2009-07-09 21:22:52 +00:00
{
define ( 'ADMIN' , TRUE );
define ( 'ADMINID' , $result [ 'user_id' ]);
define ( 'ADMINNAME' , $result [ 'user_name' ]);
define ( 'ADMINPERMS' , $result [ 'user_perms' ]);
define ( 'ADMINEMAIL' , $result [ 'user_email' ]);
define ( 'ADMINPWCHANGE' , $result [ 'user_pwchange' ]);
2009-11-22 14:10:09 +00:00
e107 :: getRedirect () -> setPreviousUrl ();
2010-02-10 21:53:56 +00:00
2009-08-28 15:21:23 +00:00
}
else
2009-07-09 21:22:52 +00:00
{
define ( 'ADMIN' , FALSE );
}
2009-07-04 13:36:15 +00:00
if ( $result [ 'user_prefs' ])
{
$user_pref = ( substr ( $result [ 'user_prefs' ], 0 , 5 ) == " array " ) ? $eArrayStorage -> ReadArray ( $result [ 'user_prefs' ]) : unserialize ( $result [ 'user_prefs' ]);
}
2009-07-09 21:22:52 +00:00
$tempClasses = class_list ();
if ( check_class ( varset ( $pref [ 'allow_theme_select' ], FALSE ), $tempClasses ))
2009-01-29 21:09:43 +00:00
{ // User can set own theme
2009-07-04 13:36:15 +00:00
if ( isset ( $_POST [ 'settheme' ]))
{
2009-07-07 22:56:13 +00:00
if ( $pref [ 'sitetheme' ] != $_POST [ 'sitetheme' ])
{
require_once ( e_HANDLER . " theme_handler.php " );
$utheme = new themeHandler ;
$ut = $utheme -> themeArray [ $_POST [ 'sitetheme' ]];
$user_pref [ 'sitetheme' ] = $_POST [ 'sitetheme' ];
$user_pref [ 'sitetheme_custompages' ] = $ut [ 'custompages' ];
$user_pref [ 'sitetheme_deflayout' ] = $utheme -> findDefault ( $_POST [ 'sitetheme' ]);
}
else
{
unset ( $user_pref [ 'sitetheme' ], $user_pref [ 'sitetheme_custompages' ], $user_pref [ 'sitetheme_deflayout' ]);
}
2009-07-04 13:36:15 +00:00
save_prefs ( 'user' );
2009-07-07 22:56:13 +00:00
unset ( $ut );
2009-07-04 13:36:15 +00:00
}
}
elseif ( isset ( $user_pref [ 'sitetheme' ]))
{ // User obviously no longer allowed his own theme - clear it
2009-07-07 22:56:13 +00:00
unset ( $user_pref [ 'sitetheme' ], $user_pref [ 'sitetheme_custompages' ], $user_pref [ 'sitetheme_deflayout' ]);
2009-07-04 13:36:15 +00:00
save_prefs ( 'user' );
2009-01-29 21:09:43 +00:00
}
2009-08-28 15:21:23 +00:00
2006-12-02 04:36:16 +00:00
2008-11-27 02:18:25 +00:00
define ( 'USERTHEME' , ( isset ( $user_pref [ 'sitetheme' ]) && file_exists ( e_THEME . $user_pref [ 'sitetheme' ] . " /theme.php " ) ? $user_pref [ 'sitetheme' ] : false ));
2009-07-09 21:22:52 +00:00
// global $ADMIN_DIRECTORY, $PLUGINS_DIRECTORY;
2010-05-14 18:45:51 +00:00
} */
/* else
2008-06-13 20:20:23 +00:00
{
2008-11-27 02:18:25 +00:00
define ( 'USER' , false );
2008-06-13 20:20:23 +00:00
define ( 'USERID' , 0 );
2008-11-27 02:18:25 +00:00
define ( 'USERTHEME' , false );
define ( 'ADMIN' , false );
define ( 'CORRUPT_COOKIE' , true );
define ( 'USERCLASS' , '' );
2006-12-02 04:36:16 +00:00
}
2010-05-14 18:45:51 +00:00
} */
2006-12-02 04:36:16 +00:00
2010-05-14 18:45:51 +00:00
/* define ( 'USERCLASS_LIST' , class_list ());
2008-11-27 02:18:25 +00:00
define ( 'e_CLASS_REGEXP' , '(^|,)(' . str_replace ( ',' , '|' , USERCLASS_LIST ) . ')(,|$)' );
2010-05-14 18:45:51 +00:00
define ( 'e_NOBODY_REGEXP' , '(^|,)' . e_UC_NOBODY . '(,|$)' ); */
2006-12-02 04:36:16 +00:00
}
2008-06-13 20:20:23 +00:00
2006-12-02 04:36:16 +00:00
$sql -> db_Mark_Time ( 'Start: Go online' );
2008-01-06 22:16:37 +00:00
if ( ! isset ( $_E107 [ 'no_online' ]) && varset ( $pref [ 'track_online' ]))
{
2010-05-15 17:33:11 +00:00
e107 :: getOnline () -> goOnline ( $pref [ 'track_online' ], $pref [ 'flood_protect' ]);
2006-12-02 04:36:16 +00:00
}
2010-10-26 07:41:20 +00:00
/**
* Set Cookie
* @ param string $name
* @ param string $value
* @ param integer $expire seconds
* @ param string $path
* @ param string $domain
* @ param boolean $secure
* @ return void
*/
2010-09-10 01:01:48 +00:00
function cookie ( $name , $value , $expire = 0 , $path = e_HTTP , $domain = '' , $secure = 0 )
2008-11-27 02:18:25 +00:00
{
2006-12-02 04:36:16 +00:00
setcookie ( $name , $value , $expire , $path , $domain , $secure );
}
2008-05-19 09:42:28 +00:00
// generic function for retaining values across pages. ie. cookies or sessions.
2011-06-07 12:40:34 +00:00
function session_set ( $name , $value , $expire = '' , $path = e_HTTP , $domain = '' , $secure = 0 )
2008-05-19 09:42:28 +00:00
{
global $pref ;
2008-12-22 03:15:04 +00:00
if ( $pref [ 'user_tracking' ] == 'session' )
2008-05-19 09:42:28 +00:00
{
$_SESSION [ $name ] = $value ;
}
else
{
setcookie ( $name , $value , $expire , $path , $domain , $secure );
$_COOKIE [ $name ] = $value ;
}
}
2006-12-02 04:36:16 +00:00
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
2008-12-22 03:15:04 +00:00
function message_handler ( $mode , $message , $line = 0 , $file = '' )
2008-11-27 02:18:25 +00:00
{
e107_require_once ( e_HANDLER . 'message_handler.php' );
2006-12-02 04:36:16 +00:00
show_emessage ( $mode , $message , $line , $file );
}
2008-12-21 22:29:38 +00:00
/*
2006-12-02 04:36:16 +00:00
// -----------------------------------------------------------------------------
2008-11-27 02:18:25 +00:00
function table_exists ( $check )
{
if ( ! $GLOBALS [ 'mySQLtablelist' ])
{
2006-12-02 04:36:16 +00:00
$tablist = mysql_list_tables ( $GLOBALS [ 'mySQLdefaultdb' ]);
2008-11-27 02:18:25 +00:00
while ( list ( $temp ) = mysql_fetch_array ( $tablist ))
{
2006-12-02 04:36:16 +00:00
$GLOBALS [ 'mySQLtablelist' ][] = $temp ;
}
}
$mltable = MPREFIX . strtolower ( $check );
2008-11-27 02:18:25 +00:00
foreach ( $GLOBALS [ 'mySQLtablelist' ] as $lang )
{
if ( strpos ( $lang , $mltable ) !== FALSE )
{
2006-12-02 04:36:16 +00:00
return TRUE ;
}
}
}
2008-12-21 22:29:38 +00:00
*/
2006-12-02 04:36:16 +00:00
2007-01-12 02:36:18 +00:00
function class_list ( $uid = '' )
{
$clist = array ();
2006-12-02 04:36:16 +00:00
2007-01-12 02:36:18 +00:00
if ( is_numeric ( $uid ) || USER === true )
2006-12-02 04:36:16 +00:00
{
2007-01-12 02:36:18 +00:00
if ( is_numeric ( $uid ))
2006-12-02 04:36:16 +00:00
{
2007-01-12 02:36:18 +00:00
if ( $ud = get_user_data ( $uid ))
2006-12-02 04:36:16 +00:00
{
2007-01-12 02:36:18 +00:00
$admin_status = $ud [ 'user_admin' ];
$class_list = $ud [ 'user_class' ];
$admin_perms = $ud [ 'user_perms' ];
2006-12-02 04:36:16 +00:00
}
2007-01-12 02:36:18 +00:00
else
{
$admin_status = false ;
$class_list = " " ;
$admin_perms = " " ;
2006-12-02 04:36:16 +00:00
}
}
2007-01-12 02:36:18 +00:00
else
{
$admin_status = ADMIN ;
$class_list = USERCLASS ;
$admin_perms = ADMINPERMS ;
}
if ( $class_list )
{
$clist = explode ( ',' , $class_list );
}
2008-11-25 16:26:03 +00:00
2007-01-12 02:36:18 +00:00
$clist [] = e_UC_MEMBER ;
2008-11-25 16:26:03 +00:00
2007-01-12 02:36:18 +00:00
if ( $admin_status == true )
{
$clist [] = e_UC_ADMIN ;
}
if ( $admin_perms === '0' )
{
$clist [] = e_UC_MAINADMIN ;
}
}
else
{
$clist [] = e_UC_GUEST ;
2006-12-02 04:36:16 +00:00
}
2008-11-25 16:26:03 +00:00
2007-01-12 02:36:18 +00:00
$clist [] = e_UC_READONLY ;
$clist [] = e_UC_PUBLIC ;
2008-11-25 16:26:03 +00:00
2007-01-12 02:36:18 +00:00
return implode ( ',' , $clist );
2006-12-02 04:36:16 +00:00
}
// ---------------------------------------------------------------------------
2009-11-12 01:53:16 +00:00
/**
2009-11-17 09:37:22 +00:00
* Will be deprecated , probably by e107 :: includeLan ();
*
* @ param string $path
* @ param boolean $force [ optional ] Please use the default
* @ return void
2009-11-12 01:53:16 +00:00
*/
2008-11-25 16:26:03 +00:00
function include_lan ( $path , $force = false )
2008-08-11 20:45:01 +00:00
{
2009-09-19 15:27:26 +00:00
return e107 :: includeLan ( $path , $force );
2006-12-02 04:36:16 +00:00
}
2008-12-07 21:41:04 +00:00
/*
withdrawn - use loadLanFiles ( $path , 'admin' ) instead
2008-08-11 20:45:01 +00:00
// Searches a defined set of paths and file names to load language files used for admin (including install etc)
function include_lan_admin ( $path )
{
include_lan ( $path . 'languages/' . e_LANGUAGE . '/lan_config.php' );
include_lan ( $path . 'languages/admin/' . e_LANGUAGE . '.php' );
}
2008-12-07 21:41:04 +00:00
*/
// Routine looks in standard paths for language files associated with a plugin or theme - primarily for core routines, which won't know
// for sure where the author has put them.
// $unitName is the name (directory path) of the plugin or theme
// $type determines what is to be loaded:
// 'runtime' - the standard runtime language file for a plugin
// 'admin' - the standard admin language file for a plugin
// 'theme' - the standard language file for a plugin (these are usually pretty small, so one is enough)
// Otherwise, $type is treated as part of a filename within the plugin's language directory, prefixed with the current language
// Returns FALSE on failure (not found).
// Returns the include_once error return if there is one
// Otherwise returns an empty string.
// Note - if the code knows precisely where the language file is located, use include_lan()
// $pref['noLanguageSubs'] can be set TRUE to prevent searching for the English files if the files for the current site language don't exist.
2009-07-22 14:32:51 +00:00
//DEPRECATED - use e107::loadLanFiles();
2008-12-07 21:41:04 +00:00
function loadLanFiles ( $unitName , $type = 'runtime' )
{
2009-07-22 14:32:51 +00:00
return e107 :: loadLanFiles ( $unitName , $type );
2008-12-07 21:41:04 +00:00
}
2008-08-11 20:45:01 +00:00
2009-08-05 19:58:32 +00:00
2006-12-02 04:36:16 +00:00
2009-12-07 20:47:37 +00:00
/**
* Check that all required user fields ( including extended fields ) are valid .
* @ param array $currentUser - data for user
* @ return boolean TRUE if update required
*/
function force_userupdate ( $currentUser )
2007-08-12 21:40:49 +00:00
{
2009-12-07 20:47:37 +00:00
if ( e_PAGE == 'usersettings.php' || strpos ( e_SELF , ADMINDIR ) == TRUE || ( defined ( 'FORCE_USERUPDATE' ) && ( FORCE_USERUPDATE == FALSE )))
2006-12-02 04:36:16 +00:00
{
return FALSE ;
}
2008-11-27 02:18:25 +00:00
$signup_option_names = array ( 'realname' , 'signature' , 'image' , 'timezone' , 'class' );
2006-12-02 04:36:16 +00:00
foreach ( $signup_option_names as $key => $value )
{
2009-12-07 20:47:37 +00:00
if ( e107 :: getPref ( 'signup_option_' . $value , 0 ) == 2 && ! $currentUser [ 'user_' . $value ])
2006-12-02 04:36:16 +00:00
{
return TRUE ;
}
}
2009-12-07 20:47:37 +00:00
if ( ! e107 :: getPref ( 'disable_emailcheck' , TRUE ) && ! trim ( $currentUser [ 'user_email' ])) return TRUE ;
2007-08-12 21:40:49 +00:00
2010-01-02 14:56:13 +00:00
if ( e107 :: getDb () -> db_Select ( 'user_extended_struct' , 'user_extended_struct_applicable, user_extended_struct_write, user_extended_struct_name, user_extended_struct_type' , 'user_extended_struct_required = 1 AND user_extended_struct_applicable != ' . e_UC_NOBODY ))
2006-12-02 04:36:16 +00:00
{
2009-12-07 20:47:37 +00:00
while ( $row = e107 :: getDb () -> db_Fetch ())
2006-12-02 04:36:16 +00:00
{
2009-12-07 20:47:37 +00:00
if ( ! check_class ( $row [ 'user_extended_struct_applicable' ])) { continue ; } // Must be applicable to this user class
if ( ! check_class ( $row [ 'user_extended_struct_write' ])) { continue ; } // And user must be able to change it
$user_extended_struct_name = " user_ { $row [ 'user_extended_struct_name' ] } " ;
if (( ! $currentUser [ $user_extended_struct_name ]) || (( $row [ 'user_extended_struct_type' ] == 7 ) && ( $currentUser [ $user_extended_struct_name ] == '0000-00-00' )))
{
//e107::admin_log->e_log_event(4, __FILE__."|".__FUNCTION__."@".__LINE__, 'FORCE', 'Force User update', 'Trigger field: '.$user_extended_struct_name, FALSE, LOG_TO_ROLLING);
return TRUE ;
}
2006-12-02 04:36:16 +00:00
}
}
return FALSE ;
}
2009-12-07 20:47:37 +00:00
2009-12-13 21:52:32 +00:00
/**
* @ package e107
*/
2008-11-27 02:18:25 +00:00
class error_handler
{
2006-12-02 04:36:16 +00:00
var $errors ;
var $debug = false ;
2008-11-27 02:18:25 +00:00
function error_handler ()
{
2006-12-05 09:33:20 +00:00
//
// This is initialized before the current debug level is known
//
2008-12-22 03:15:04 +00:00
global $_E107 ;
if ( isset ( $_E107 [ 'debug' ]))
2008-01-21 03:54:10 +00:00
{
$this -> debug = true ;
error_reporting ( E_ALL );
return ;
2008-12-22 03:15:04 +00:00
}
if ( isset ( $_E107 [ 'cli' ]))
2008-01-21 03:54:10 +00:00
{
2008-12-22 03:15:04 +00:00
error_reporting ( E_ALL ^ E_NOTICE );
2008-01-21 03:54:10 +00:00
return ;
}
2009-07-21 14:20:13 +00:00
if (( isset ( $_SERVER [ 'QUERY_STRING' ]) && strpos ( $_SERVER [ 'QUERY_STRING' ], 'debug=' ) !== FALSE ) || isset ( $_COOKIE [ 'e107_debug_level' ]) && strpos ( $_SERVER [ 'QUERY_STRING' ], 'debug=-' ) !== TRUE )
2008-11-27 02:18:25 +00:00
{
2009-07-21 14:20:13 +00:00
$this -> debug = true ;
error_reporting ( E_ALL );
2008-11-27 02:18:25 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
error_reporting ( E_ERROR | E_PARSE );
}
}
function handle_error ( $type , $message , $file , $line , $context ) {
2006-12-05 09:33:20 +00:00
$startup_error = ( ! defined ( 'E107_DEBUG_LEVEL' )); // Error before debug system initialized
2006-12-02 04:36:16 +00:00
switch ( $type ) {
case E_NOTICE :
2008-11-27 02:18:25 +00:00
if ( $startup_error || E107_DBG_ALLERRORS )
{
2006-12-02 04:36:16 +00:00
$error [ 'short' ] = " Notice: { $message } , Line { $line } of { $file } <br /> \n " ;
$trace = debug_backtrace ();
$backtrace [ 0 ] = ( isset ( $trace [ 1 ]) ? $trace [ 1 ] : " " );
$backtrace [ 1 ] = ( isset ( $trace [ 2 ]) ? $trace [ 2 ] : " " );
$error [ 'trace' ] = $backtrace ;
$this -> errors [] = $error ;
}
break ;
case E_WARNING :
2008-11-27 02:18:25 +00:00
if ( $startup_error || E107_DBG_BASIC )
{
2006-12-02 04:36:16 +00:00
$error [ 'short' ] = " Warning: { $message } , Line { $line } of { $file } <br /> \n " ;
$trace = debug_backtrace ();
$backtrace [ 0 ] = ( isset ( $trace [ 1 ]) ? $trace [ 1 ] : " " );
$backtrace [ 1 ] = ( isset ( $trace [ 2 ]) ? $trace [ 2 ] : " " );
$error [ 'trace' ] = $backtrace ;
$this -> errors [] = $error ;
}
break ;
case E_USER_ERROR :
2008-11-27 02:18:25 +00:00
if ( $this -> debug == true )
{
2006-12-02 04:36:16 +00:00
$error [ 'short' ] = " Internal Error Message: { $message } , Line { $line } of { $file } <br /> \n " ;
$trace = debug_backtrace ();
$backtrace [ 0 ] = ( isset ( $trace [ 1 ]) ? $trace [ 1 ] : " " );
$backtrace [ 1 ] = ( isset ( $trace [ 2 ]) ? $trace [ 2 ] : " " );
$error [ 'trace' ] = $backtrace ;
$this -> errors [] = $error ;
}
default :
return true ;
break ;
}
}
2008-11-27 02:18:25 +00:00
function return_errors ()
{
2006-12-02 04:36:16 +00:00
$index = 0 ; $colours [ 0 ] = " #C1C1C1 " ; $colours [ 1 ] = " #B6B6B6 " ;
2009-07-21 14:20:13 +00:00
$ret = " " ;
2006-12-05 09:33:20 +00:00
if ( E107_DBG_ERRBACKTRACE )
{
2008-11-27 02:18:25 +00:00
foreach ( $this -> errors as $key => $value )
{
$ret .= " \t <tr> \n \t \t <td class='forumheader3' > { $value [ 'short' ] } </td><td><input class='button' type ='button' style='cursor: hand; cursor: pointer;' size='30' value='Back Trace' onclick= \" expandit('bt_ { $key } ') \" /></td> \n \t </tr> \n " ;
$ret .= " \t <tr> \n <td style='display: none;' colspan='2' id='bt_ { $key } '> " . print_a ( $value [ 'trace' ], true ) . " </td></tr> \n " ;
if ( $index == 0 ) { $index = 1 ; } else { $index = 0 ; }
}
2006-12-02 04:36:16 +00:00
}
2008-11-27 02:18:25 +00:00
else
{
2006-12-30 03:07:50 +00:00
foreach ( $this -> errors as $key => $value )
2006-12-05 09:33:20 +00:00
{
$ret .= " <tr class='forumheader3'><td> { $value [ 'short' ] } </td></tr> \n " ;
}
}
2009-07-21 14:20:13 +00:00
return ( $ret ) ? " <table class='fborder'> \n " . $ret . " </table> " : FALSE ;
2006-12-02 04:36:16 +00:00
}
2008-11-27 02:18:25 +00:00
function trigger_error ( $information , $level )
{
2006-12-02 04:36:16 +00:00
trigger_error ( $information );
}
}
$sql -> db_Mark_Time ( '(After class2)' );
2008-11-27 02:18:25 +00:00
function e107_ini_set ( $var , $value )
{
if ( function_exists ( 'ini_set' ))
{
2008-11-29 13:10:56 +00:00
return ini_set ( $var , $value );
2006-12-02 04:36:16 +00:00
}
2008-11-29 13:10:56 +00:00
return FALSE ;
2006-12-02 04:36:16 +00:00
}
2008-11-27 02:18:25 +00:00
// Return true if specified plugin installed, false if not
2009-07-22 14:32:51 +00:00
//DEPRECATED - use e107::isInstalled();
2008-10-07 21:29:25 +00:00
function plugInstalled ( $plugname )
{
2009-07-22 14:32:51 +00:00
return e107 :: isInstalled ( $plugname );
/* global $pref ;
2008-10-07 21:29:25 +00:00
// Could add more checks here later if appropriate
2009-07-22 14:32:51 +00:00
return isset ( $pref [ 'plug_installed' ][ $plugname ]); */
2008-10-07 21:29:25 +00:00
}