2007-03-31 01:18:33 +00:00
|
|
|
<?php
|
2006-12-02 04:36:16 +00:00
|
|
|
/*
|
|
|
|
+ ----------------------------------------------------------------------------+
|
|
|
|
| e107 website system
|
|
|
|
|
|
|
|
|
| Steve Dunstan 2001-2002
|
|
|
|
| http://e107.org
|
|
|
|
| jalist@e107.org
|
|
|
|
|
|
|
|
|
| Released under the terms and conditions of the
|
|
|
|
| GNU General Public License (http://gnu.org).
|
|
|
|
|
|
|
|
|
| $Source: /cvs_backup/e107_0.8/class2.php,v $
|
2008-11-26 15:00:56 +00:00
|
|
|
| $Revision: 1.74 $
|
|
|
|
| $Date: 2008-11-26 15:00:56 $
|
2008-11-25 16:26:03 +00:00
|
|
|
| $Author: mcfly_e107 $
|
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
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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(); }
|
2008-11-21 11:08:53 +00:00
|
|
|
if(varset($_E107['cli']) && !varset($_E107['debug']) && isset($_SERVER["HTTP_USER_AGENT"]))
|
2008-01-22 00:39:08 +00:00
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
2008-01-21 03:54:10 +00:00
|
|
|
if(!$_E107['cli'])
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
//
|
|
|
|
$register_globals = true;
|
|
|
|
if(function_exists('ini_get')) {
|
|
|
|
$register_globals = ini_get('register_globals');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy! (if we need to)
|
|
|
|
if($register_globals == true){
|
2008-01-06 22:16:37 +00:00
|
|
|
if(isset($_REQUEST['_E107'])) { unset($_E107); }
|
2006-12-02 04:36:16 +00:00
|
|
|
while (list($global) = each($GLOBALS)) {
|
2008-01-06 22:16:37 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-01-22 00:39:08 +00:00
|
|
|
|
2008-01-06 22:16:37 +00:00
|
|
|
if(isset($_E107['minimal']))
|
|
|
|
{
|
|
|
|
$_e107vars = array('forceuserupdate', 'online', 'theme', 'menus', 'prunetmp');
|
|
|
|
foreach($_e107vars as $v)
|
|
|
|
{
|
|
|
|
$noname = 'no_'.$v;
|
|
|
|
if(!isset($_E107[$v]))
|
|
|
|
{
|
|
|
|
$_E107[$noname] = 1;
|
|
|
|
}
|
|
|
|
unset($_E107[$v]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2006-12-02 04:36:16 +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;
|
2008-08-03 08:00:19 +00:00
|
|
|
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.
|
|
|
|
$_SERVER['PHP_SELF'] = (($pos = strpos($_SERVER['PHP_SELF'], ".php")) !== false ? substr($_SERVER['PHP_SELF'], 0, $pos+4) : $_SERVER['PHP_SELF']);
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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();
|
|
|
|
set_error_handler(array(&$error_handler, "handle_error"));
|
|
|
|
|
|
|
|
//
|
|
|
|
// E: Setup other essential PHP parameters
|
|
|
|
//
|
|
|
|
define("e107_INIT", TRUE);
|
|
|
|
|
|
|
|
// setup some php options
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
if(isset($retrieve_prefs) && is_array($retrieve_prefs)) {
|
|
|
|
foreach ($retrieve_prefs as $key => $pref_name) {
|
|
|
|
$retrieve_prefs[$key] = preg_replace("/\W/", '', $pref_name);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unset($retrieve_prefs);
|
|
|
|
}
|
|
|
|
|
|
|
|
define("MAGIC_QUOTES_GPC", (ini_get('magic_quotes_gpc') ? TRUE : FALSE));
|
2007-03-31 01:18:33 +00:00
|
|
|
|
|
|
|
// Define the domain name and subdomain name.
|
2008-01-21 03:54:10 +00:00
|
|
|
if($_SERVER['HTTP_HOST'] && is_numeric(str_replace(".","",$_SERVER['HTTP_HOST']))){
|
2007-03-31 01:18:33 +00:00
|
|
|
$srvtmp = ""; // Host is an IP address.
|
|
|
|
}else{
|
2008-04-26 02:12:13 +00:00
|
|
|
$srvtmp = explode(".",str_replace("www.","",$_SERVER['HTTP_HOST']));
|
2007-03-31 01:18:33 +00:00
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
define("e_SUBDOMAIN", (count($srvtmp)>2 && $srvtmp[2] ? $srvtmp[0] : FALSE)); // needs to be available to e107_config.
|
2007-10-30 00:48:23 +00:00
|
|
|
|
|
|
|
if(e_SUBDOMAIN)
|
|
|
|
{
|
|
|
|
unset($srvtmp[0]);
|
2007-03-31 01:18:33 +00:00
|
|
|
}
|
|
|
|
|
2007-10-30 00:48:23 +00:00
|
|
|
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
|
|
|
|
|
|
|
// Ensure thet '.' is the first part of the include path
|
|
|
|
$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);
|
|
|
|
|
|
|
|
//
|
|
|
|
// F: Grab e107_config, get directory paths and create $e107 object
|
|
|
|
//
|
|
|
|
@include_once(realpath(dirname(__FILE__).'/e107_config.php'));
|
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..
|
|
|
|
header("Location: install.php");
|
|
|
|
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
|
|
|
//
|
|
|
|
e107_require_once(realpath(dirname(__FILE__).'/'.$HANDLERS_DIRECTORY).'/e107_class.php');
|
|
|
|
$e107_paths = compact('ADMIN_DIRECTORY', 'FILES_DIRECTORY', 'IMAGES_DIRECTORY', 'THEMES_DIRECTORY', 'PLUGINS_DIRECTORY', 'HANDLERS_DIRECTORY', 'LANGUAGES_DIRECTORY', 'HELP_DIRECTORY', 'DOWNLOADS_DIRECTORY');
|
2008-11-24 18:06:03 +00:00
|
|
|
$e107 = e107::getInstance();
|
|
|
|
$e107->_init($e107_paths, realpath(dirname(__FILE__)));
|
|
|
|
//$e107 = new e107($e107_paths, realpath(dirname(__FILE__)));
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
|
|
$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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// G: Retrieve Query data from URI
|
|
|
|
// (Until this point, we have no idea what the user wants to do)
|
|
|
|
//
|
|
|
|
if (preg_match("#\[(.*?)](.*)#", $_SERVER['QUERY_STRING'], $matches)) {
|
|
|
|
define("e_MENU", $matches[1]);
|
|
|
|
$e_QUERY = $matches[2];
|
|
|
|
|
|
|
|
if(strlen(e_MENU) == 2) // language code ie. [fr]
|
|
|
|
{
|
|
|
|
require_once(e_HANDLER."language_class.php");
|
|
|
|
$lng = new language;
|
|
|
|
define("e_LANCODE",TRUE);
|
|
|
|
$_GET['elan'] = $lng->convert(e_MENU);
|
|
|
|
}
|
|
|
|
|
|
|
|
}else {
|
|
|
|
define("e_MENU", "");
|
|
|
|
$e_QUERY = $_SERVER['QUERY_STRING'];
|
|
|
|
define("e_LANCODE", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Start the parser; use it to grab the full query string
|
|
|
|
//
|
|
|
|
|
2008-11-24 18:06:03 +00:00
|
|
|
e107_require_once(e_HANDLER.'e107Url.php');
|
|
|
|
$e107->url = new eURL;
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
e107_require_once(e_HANDLER.'e_parse_class.php');
|
2008-11-24 20:18:59 +00:00
|
|
|
$e107->tp = new e_parse;
|
|
|
|
$tp = &$e107->tp;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
|
|
//define("e_QUERY", $matches[2]);
|
|
|
|
//define("e_QUERY", $_SERVER['QUERY_STRING']);
|
2007-03-31 01:18:33 +00:00
|
|
|
$e_QUERY = str_replace("&","&",$tp->post_toForm($e_QUERY));
|
2006-12-02 04:36:16 +00:00
|
|
|
define("e_QUERY", $e_QUERY);
|
|
|
|
//$e_QUERY = e_QUERY;
|
|
|
|
|
|
|
|
define("e_TBQS", $_SERVER['QUERY_STRING']);
|
|
|
|
$_SERVER['QUERY_STRING'] = e_QUERY;
|
|
|
|
|
|
|
|
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);
|
|
|
|
define("ADMINDIR", $ADMIN_DIRECTORY);
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
require_once(e_HANDLER.'debug_handler.php');
|
|
|
|
|
|
|
|
if(E107_DEBUG_LEVEL && isset($db_debug) && is_object($db_debug)) {
|
|
|
|
$db_debug->Mark_Time('Start: Init ErrHandler');
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// I: Sanity check on e107_config.php
|
|
|
|
// e107_config.php upgrade check
|
|
|
|
if (!$ADMIN_DIRECTORY && !$DOWNLOADS_DIRECTORY) {
|
|
|
|
message_handler("CRITICAL_ERROR", 8, ": generic, ", "e107_config.php");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// J: MYSQL INITIALIZATION
|
|
|
|
//
|
|
|
|
@require_once(e_HANDLER.'traffic_class.php');
|
|
|
|
$eTraffic=new e107_traffic; // We start traffic counting ASAP
|
|
|
|
$eTraffic->Calibrate($eTraffic);
|
|
|
|
|
|
|
|
define("MPREFIX", $mySQLprefix);
|
|
|
|
|
|
|
|
e107_require_once(e_HANDLER."mysql_class.php");
|
|
|
|
|
2008-11-25 16:26:03 +00:00
|
|
|
$e107->sql =& new db;
|
|
|
|
$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);
|
2008-11-25 16:26:03 +00:00
|
|
|
$sql2 =& new db; // create after the initial connection.
|
2006-12-02 04:36:16 +00:00
|
|
|
$sql->db_Mark_Time('Start: Prefs, misc tables');
|
|
|
|
|
2006-12-30 03:07:50 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
require_once(e_HANDLER.'admin_log_class.php');
|
2008-11-25 16:26:03 +00:00
|
|
|
$e107->admin_log =& new e_admin_log;
|
|
|
|
$admin_log = &$e107->admin_log;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2008-05-18 16:35:47 +00:00
|
|
|
if ($merror === "e1") {
|
2006-12-02 04:36:16 +00:00
|
|
|
message_handler("CRITICAL_ERROR", 6, ": generic, ", "class2.php");
|
|
|
|
exit;
|
|
|
|
}
|
2008-05-18 16:35:47 +00:00
|
|
|
else if ($merror === "e2") {
|
2006-12-02 04:36:16 +00:00
|
|
|
message_handler("CRITICAL_ERROR", 7, ": generic, ", "class2.php");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// K: Load compatability mode.
|
|
|
|
//
|
2008-01-06 22:16:37 +00:00
|
|
|
|
|
|
|
/* PHP Compatabilty should *always* be on. */
|
2006-12-02 04:36:16 +00:00
|
|
|
e107_require_once(e_HANDLER."php_compatibility_handler.php");
|
|
|
|
|
|
|
|
//
|
|
|
|
// L: Extract core prefs from the database
|
|
|
|
//
|
|
|
|
$sql->db_Mark_Time('Start: Extract Core Prefs');
|
|
|
|
e107_require_once(e_HANDLER."pref_class.php");
|
|
|
|
$sysprefs = new prefs;
|
|
|
|
|
|
|
|
e107_require_once(e_HANDLER.'cache_handler.php');
|
|
|
|
e107_require_once(e_HANDLER.'arraystorage_class.php');
|
|
|
|
$eArrayStorage = new ArrayData();
|
|
|
|
|
2007-02-04 17:36:16 +00:00
|
|
|
$PrefCache = ecache::retrieve_sys('SitePrefs', 24 * 60, true);
|
2006-12-02 04:36:16 +00:00
|
|
|
if(!$PrefCache){
|
|
|
|
// No cache of the prefs array, going for the db copy..
|
|
|
|
$retrieve_prefs[] = 'SitePrefs';
|
|
|
|
$sysprefs->ExtractPrefs($retrieve_prefs, TRUE);
|
|
|
|
$PrefData = $sysprefs->get('SitePrefs');
|
|
|
|
$pref = $eArrayStorage->ReadArray($PrefData);
|
|
|
|
if(!$pref){
|
|
|
|
$admin_log->log_event("CORE_LAN8", "CORE_LAN7", E_LOG_WARNING); // Core prefs error, core is attempting to
|
|
|
|
// Try for the automatic backup..
|
|
|
|
$PrefData = $sysprefs->get('SitePrefs_Backup');
|
|
|
|
$pref = $eArrayStorage->ReadArray($PrefData);
|
|
|
|
if(!$pref){
|
|
|
|
// No auto backup, try for the 'old' prefs system.
|
|
|
|
$PrefData = $sysprefs->get('pref');
|
|
|
|
$pref = unserialize($PrefData);
|
|
|
|
if(!is_array($pref)){
|
|
|
|
message_handler("CRITICAL_ERROR", 3, __LINE__, __FILE__);
|
|
|
|
// No old system, so point in the direction of resetcore :(
|
|
|
|
message_handler("CRITICAL_ERROR", 4, __LINE__, __FILE__);
|
|
|
|
$admin_log->log_event("CORE_LAN8", "CORE_LAN9", E_LOG_FATAL); // Core could not restore from automatic backup. Execution halted.
|
|
|
|
exit;
|
|
|
|
} else {
|
|
|
|
// old prefs found, remove old system, and update core with new system
|
|
|
|
$PrefOutput = $eArrayStorage->WriteArray($pref);
|
|
|
|
if(!$sql->db_Update('core', "e107_value='{$PrefOutput}' WHERE e107_name='SitePrefs'")){
|
|
|
|
$sql->db_Insert('core', "'SitePrefs', '{$PrefOutput}'");
|
|
|
|
}
|
|
|
|
if(!$sql->db_Update('core', "e107_value='{$PrefOutput}' WHERE e107_name='SitePrefs_Backup'")){
|
|
|
|
$sql->db_Insert('core', "'SitePrefs_Backup', '{$PrefOutput}'");
|
|
|
|
}
|
|
|
|
$sql->db_Delete('core', "`e107_name` = 'pref'");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
message_handler("CRITICAL_ERROR", 3, __LINE__, __FILE__);
|
|
|
|
// auto backup found, use backup to restore the core
|
|
|
|
if(!$sql->db_Update('core', "`e107_value` = '".addslashes($PrefData)."' WHERE `e107_name` = 'SitePrefs'")){
|
|
|
|
$sql->db_Insert('core', "'SitePrefs', '".addslashes($PrefData)."'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// write pref cache array
|
|
|
|
$PrefCache = $eArrayStorage->WriteArray($pref, false);
|
|
|
|
// store the prefs in cache if cache is enabled
|
2007-02-04 17:36:16 +00:00
|
|
|
ecache::set_sys('SitePrefs', $PrefCache);
|
2006-12-02 04:36:16 +00:00
|
|
|
} else {
|
|
|
|
// cache of core prefs was found, so grab all the useful core rows we need
|
|
|
|
if(!isset($sysprefs->DefaultIgnoreRows)){
|
|
|
|
$sysprefs->DefaultIgnoreRows = "";
|
|
|
|
}
|
|
|
|
$sysprefs->DefaultIgnoreRows .= '|SitePrefs';
|
|
|
|
$sysprefs->prefVals['core']['SitePrefs'] = $PrefCache;
|
|
|
|
if(isset($retrieve_prefs))
|
|
|
|
{
|
|
|
|
$sysprefs->ExtractPrefs($retrieve_prefs, TRUE);
|
|
|
|
}
|
|
|
|
$pref = $eArrayStorage->ReadArray($PrefCache);
|
|
|
|
}
|
|
|
|
|
|
|
|
$e107->set_base_path();
|
|
|
|
|
|
|
|
// extract menu prefs
|
|
|
|
$menu_pref = unserialize(stripslashes($sysprefs->get('menu_pref')));
|
|
|
|
|
|
|
|
$sql->db_Mark_Time('(Extracting Core Prefs Done)');
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// M: Subdomain and Language Selection
|
|
|
|
//
|
2008-05-19 09:42:28 +00:00
|
|
|
|
|
|
|
if (!$pref['cookie_name']) // if a cookie name pref isn't set, make one :)
|
|
|
|
{
|
|
|
|
$pref['cookie_name'] = "e107cookie";
|
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
define("SITEURLBASE", ($pref['ssl_enabled'] == '1' ? "https://" : "http://").$_SERVER['HTTP_HOST']);
|
|
|
|
define("SITEURL", SITEURLBASE.e_HTTP);
|
2008-05-19 09:42:28 +00:00
|
|
|
define("e_COOKIE", $pref['cookie_name']);
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
|
|
// let the subdomain determine the language (when enabled).
|
2007-03-31 01:18:33 +00:00
|
|
|
|
2008-01-06 22:16:37 +00:00
|
|
|
if(varset($pref['multilanguage_subdomain']) && ($pref['user_tracking'] == "session") && e_DOMAIN && MULTILANG_SUBDOMAIN !== FALSE)
|
|
|
|
{
|
|
|
|
$mtmp = explode("\n",$pref['multilanguage_subdomain']);
|
|
|
|
foreach($mtmp as $val)
|
|
|
|
{
|
|
|
|
if(e_DOMAIN == trim($val))
|
2007-10-30 00:48:23 +00:00
|
|
|
{
|
2008-01-06 22:16:37 +00:00
|
|
|
$domain_active = TRUE;
|
2008-05-19 09:42:28 +00:00
|
|
|
break;
|
2007-10-30 00:48:23 +00:00
|
|
|
}
|
2008-01-06 22:16:37 +00:00
|
|
|
}
|
2007-09-20 21:45:33 +00:00
|
|
|
|
2008-01-06 22:16:37 +00:00
|
|
|
if($domain_active || ($pref['multilanguage_subdomain'] == "1"))
|
|
|
|
{
|
|
|
|
e107_ini_set("session.cookie_domain",".".e_DOMAIN);
|
|
|
|
require_once(e_HANDLER."language_class.php");
|
|
|
|
$lng = new language;
|
2008-05-19 09:42:28 +00:00
|
|
|
if(!e_SUBDOMAIN)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2008-01-06 22:16:37 +00:00
|
|
|
$GLOBALS['elan'] = $pref['sitelanguage'];
|
|
|
|
}
|
|
|
|
elseif($eln = $lng->convert(e_SUBDOMAIN))
|
|
|
|
{
|
|
|
|
$GLOBALS['elan'] = $eln;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2008-01-06 22:16:37 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// start a session if session based login is enabled
|
2008-05-19 09:42:28 +00:00
|
|
|
if ($pref['user_tracking'] == "session")
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
session_start();
|
2008-06-13 20:20:23 +00:00
|
|
|
if (!isset($_SESSION['challenge']))
|
|
|
|
{ // New session
|
|
|
|
$_SESSION['challenge'] = sha1(time().session_id()); // Create a unique challenge string for CHAP login
|
|
|
|
}
|
|
|
|
$ubrowser = md5('E107'.$_SERVER['HTTP_USER_AGENT']);
|
2008-11-25 16:26:03 +00:00
|
|
|
if (!isset($_SESSION['ubrowser']))
|
2008-06-13 20:20:23 +00:00
|
|
|
{
|
|
|
|
$_SESSION['ubrowser'] = $ubrowser;
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
define("e_SELF", ($pref['ssl_enabled'] == '1' ? "https://".$_SERVER['HTTP_HOST'] : "http://".$_SERVER['HTTP_HOST']) . ($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_FILENAME']));
|
|
|
|
|
|
|
|
// 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'])
|
|
|
|
{
|
|
|
|
if(substr(e_SELF,7,4)=="www." || substr(e_SELF,8,4)=="www.")
|
|
|
|
{
|
2008-04-28 13:42:23 +00:00
|
|
|
$self = e_SELF;
|
|
|
|
if(e_QUERY){ $self .= "?".e_QUERY; }
|
|
|
|
$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);
|
|
|
|
if (count($aPrefURL) > 2) { // we can do this -- there's at least http[s]://dom.ain/whatever
|
|
|
|
$PrefRoot = $aPrefURL[2];
|
|
|
|
list($PrefSiteBase,$PrefSitePort) = explode(':',$PrefRoot.':');
|
|
|
|
if (!$PrefSitePort) {
|
|
|
|
$PrefSitePort = ( $aPrefURL[0] == "https:" ) ? 443 : 80; // no port so set port based on 'scheme'
|
|
|
|
}
|
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
|
|
|
|
if (($urlport != $PrefSitePort || stripos($PrefSiteBase, $urlbase) === FALSE) && strpos(e_SELF, ADMINDIR) === FALSE) {
|
|
|
|
$aeSELF = explode('/',e_SELF,4);
|
|
|
|
$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
|
|
|
|
$location = implode('/',$aeSELF).(e_QUERY ? "?".e_QUERY : "");
|
|
|
|
|
|
|
|
header("Location: {$location}", true, 301); // send 301 header, not 302
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$page = substr(strrchr($_SERVER['PHP_SELF'], "/"), 1);
|
|
|
|
define("e_PAGE", $page);
|
|
|
|
|
|
|
|
// sort out the users language selection
|
2008-05-19 09:42:28 +00:00
|
|
|
if (isset($_POST['setlanguage']) || isset($_GET['elan']) || isset($GLOBALS['elan']))
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
if($_GET['elan']) // query support, for language selection splash pages. etc
|
|
|
|
{
|
2007-08-25 05:51:48 +00:00
|
|
|
$_POST['sitelanguage'] = str_replace(array(".","/","%"),"",$_GET['elan']);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
if($GLOBALS['elan'] && !isset($_POST['sitelanguage']))
|
|
|
|
{
|
|
|
|
$_POST['sitelanguage'] = $GLOBALS['elan'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql->mySQLlanguage = $_POST['sitelanguage'];
|
|
|
|
$sql2->mySQLlanguage = $_POST['sitelanguage'];
|
2008-05-19 09:42:28 +00:00
|
|
|
session_set('e107language_'.e_COOKIE, $_POST['sitelanguage'], time() + 86400);
|
|
|
|
if ($pref['user_tracking'] != "session" && (strpos(e_SELF, ADMINDIR) === FALSE))
|
|
|
|
{
|
|
|
|
$locat = ((!$_GET['elan'] && e_QUERY) || (e_QUERY && e_LANCODE)) ? e_SELF."?".e_QUERY : e_SELF;
|
|
|
|
header("Location:".$locat);
|
2008-08-03 08:00:19 +00:00
|
|
|
exit();
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2008-05-19 09:42:28 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$user_language='';
|
|
|
|
// Multi-language options.
|
2008-05-19 09:42:28 +00:00
|
|
|
if (isset($pref['multilanguage']) && $pref['multilanguage'])
|
|
|
|
{
|
|
|
|
if ($pref['user_tracking'] == "session")
|
|
|
|
{
|
|
|
|
$user_language=(array_key_exists('e107language_'.e_COOKIE, $_SESSION) ? $_SESSION['e107language_'.e_COOKIE] : "");
|
2006-12-02 04:36:16 +00:00
|
|
|
$sql->mySQLlanguage=($user_language) ? $user_language : "";
|
|
|
|
$sql2->mySQLlanguage = $sql->mySQLlanguage;
|
2008-05-19 09:42:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$user_language= (isset($_COOKIE['e107language_'.e_COOKIE])) ? $_COOKIE['e107language_'.e_COOKIE] : "";
|
2006-12-02 04:36:16 +00:00
|
|
|
$sql->mySQLlanguage=($user_language) ? $user_language : "";
|
|
|
|
$sql2->mySQLlanguage = $sql->mySQLlanguage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get Language List for rights checking.
|
|
|
|
if(!$tmplan = getcachedvars("language-list")){
|
|
|
|
$handle=opendir(e_LANGUAGEDIR);
|
|
|
|
while ($file = readdir($handle)) {
|
|
|
|
if (is_dir(e_LANGUAGEDIR.$file) && $file !="." && $file !=".." && $file !="CVS") {
|
|
|
|
$lanlist[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($handle);
|
|
|
|
$tmplan = implode(",",$lanlist);
|
|
|
|
cachevars("language-list", $tmplan);
|
|
|
|
}
|
|
|
|
|
|
|
|
define("e_LANLIST",(isset($tmplan) ? $tmplan : ""));
|
|
|
|
|
2008-05-19 09:42:28 +00:00
|
|
|
$language=(isset($_COOKIE['e107language_'.e_COOKIE]) ? $_COOKIE['e107language_'.e_COOKIE] : ($pref['sitelanguage'] ? $pref['sitelanguage'] : "English"));
|
2006-12-02 04:36:16 +00:00
|
|
|
$language = preg_replace("#\W#", "", $language);
|
|
|
|
define("USERLAN", ($user_language && (strpos(e_SELF, $PLUGINS_DIRECTORY) !== FALSE || (strpos(e_SELF, $ADMIN_DIRECTORY) === FALSE && file_exists(e_LANGUAGEDIR.$user_language."/lan_".e_PAGE)) || (strpos(e_SELF, $ADMIN_DIRECTORY) !== FALSE && file_exists(e_LANGUAGEDIR.$user_language."/admin/lan_".e_PAGE)) || file_exists(dirname($_SERVER['SCRIPT_FILENAME'])."/languages/".$user_language."/lan_".e_PAGE) || ( (strpos(e_SELF, $ADMIN_DIRECTORY) == FALSE) && (strpos(e_SELF, $PLUGINS_DIRECTORY) == FALSE) && file_exists(e_LANGUAGEDIR.$user_language."/".$user_language.".php") ) ) ? $user_language : FALSE));
|
|
|
|
define("e_LANGUAGE", (!USERLAN || !defined("USERLAN") ? $language : USERLAN));
|
|
|
|
|
|
|
|
e107_include(e_LANGUAGEDIR.e_LANGUAGE."/".e_LANGUAGE.".php");
|
|
|
|
e107_include_once(e_LANGUAGEDIR.e_LANGUAGE."/".e_LANGUAGE."_custom.php");
|
|
|
|
|
2008-11-13 20:41:20 +00:00
|
|
|
$tp->initCharset(); // Now we know the site CHARSET, define how to handle utf-8 as necessary
|
|
|
|
|
2008-11-25 16:26:03 +00:00
|
|
|
if($pref['sitelanguage'] != e_LANGUAGE && isset($pref['multilanguage']) && $pref['multilanguage'] && !$pref['multilanguage_subdomain'])
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
list($clc) = explode("_",CORE_LC);
|
|
|
|
define("e_LAN", strtolower($clc));
|
|
|
|
define("e_LANQRY", "[".e_LAN."]");
|
|
|
|
unset($clc);
|
2008-11-25 16:26:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
define("e_LAN", FALSE);
|
2006-12-02 04:36:16 +00:00
|
|
|
define("e_LANQRY", FALSE);
|
|
|
|
}
|
|
|
|
$sql->db_Mark_Time('(Start: Pref/multilang done)');
|
|
|
|
|
|
|
|
//
|
|
|
|
// N: misc setups: online user tracking, cache
|
|
|
|
//
|
|
|
|
$sql -> db_Mark_Time('Start: Misc resources. Online user tracking, cache');
|
|
|
|
|
|
|
|
// cache class
|
2008-11-25 16:26:03 +00:00
|
|
|
$e107->ecache = new ecache;
|
|
|
|
$e107cache = &$e107->ecache;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
|
|
e107_require_once(e_HANDLER."override_class.php");
|
2008-11-25 16:26:03 +00:00
|
|
|
$e107->override = new override;
|
|
|
|
$override = &$e107->override;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
|
|
e107_require_once(e_HANDLER."event_class.php");
|
2008-11-25 16:26:03 +00:00
|
|
|
$e107->e_event = new e107_event;
|
|
|
|
$e_event = &$e107->e_event;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
|
|
if (isset($pref['notify']) && $pref['notify'] == true) {
|
|
|
|
e107_require_once(e_HANDLER.'notify_class.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// O: Start user session
|
|
|
|
//
|
|
|
|
$sql -> db_Mark_Time('Start: Init session');
|
|
|
|
init_session();
|
|
|
|
|
|
|
|
// for multi-language these definitions needs to come after the language loaded.
|
2007-01-07 15:59:42 +00:00
|
|
|
define("SITENAME", trim($tp->toHTML($pref['sitename'], "", "emotes_off, defs, no_make_clickable")));
|
2008-01-16 10:53:57 +00:00
|
|
|
define("SITEBUTTON", $tp->replaceConstants($pref['sitebutton']));
|
2007-01-07 15:59:42 +00:00
|
|
|
define("SITETAG", $tp->toHTML($pref['sitetag'], FALSE, "emotes_off, defs"));
|
|
|
|
define("SITEDESCRIPTION", $tp->toHTML($pref['sitedescription'], "", "emotes_off, defs"));
|
2006-12-02 04:36:16 +00:00
|
|
|
define("SITEADMIN", $pref['siteadmin']);
|
|
|
|
define("SITEADMINEMAIL", $pref['siteadminemail']);
|
2007-01-07 15:59:42 +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.
|
|
|
|
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")) {
|
|
|
|
require_once(e_PLUGIN."{$mod}/e_module.php");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// P: THEME LOADING
|
|
|
|
//
|
|
|
|
|
|
|
|
$sql->db_Mark_Time('Start: Load Theme');
|
|
|
|
|
|
|
|
//########### Module redefinable functions ###############
|
|
|
|
if (!function_exists('checkvalidtheme')) {
|
|
|
|
function checkvalidtheme($theme_check) {
|
|
|
|
// arg1 = theme to check
|
|
|
|
global $ADMIN_DIRECTORY, $tp, $e107;
|
|
|
|
|
2007-01-04 23:43:02 +00:00
|
|
|
if (ADMIN && strpos(e_QUERY, "themepreview") !== FALSE) {
|
2006-12-02 04:36:16 +00:00
|
|
|
list($action, $id) = explode('.', e_QUERY);
|
|
|
|
require_once(e_HANDLER."theme_handler.php");
|
|
|
|
$themeArray = themeHandler :: getThemes("id");
|
|
|
|
define("PREVIEWTHEME", e_THEME.$themeArray[$id]."/");
|
|
|
|
define("PREVIEWTHEMENAME", $themeArray[$id]);
|
|
|
|
define("THEME", e_THEME.$themeArray[$id]."/");
|
|
|
|
define("THEME_ABS", e_THEME_ABS.$themeArray[$id]."/");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (@fopen(e_THEME.$theme_check."/theme.php", "r")) {
|
|
|
|
define("THEME", e_THEME.$theme_check."/");
|
|
|
|
define("THEME_ABS", e_THEME_ABS.$theme_check."/");
|
|
|
|
$e107->site_theme = $theme_check;
|
|
|
|
} else {
|
|
|
|
function search_validtheme() {
|
|
|
|
global $e107;
|
|
|
|
$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')) {
|
|
|
|
closedir($handle);
|
|
|
|
$e107->site_theme = $file;
|
|
|
|
return $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($handle);
|
|
|
|
}
|
|
|
|
$e107tmp_theme = search_validtheme();
|
|
|
|
define("THEME", e_THEME.$e107tmp_theme."/");
|
|
|
|
define("THEME_ABS", e_THEME_ABS.$e107tmp_theme."/");
|
|
|
|
if (ADMIN && strpos(e_SELF, $ADMIN_DIRECTORY) === FALSE) {
|
|
|
|
echo '<script>alert("'.$tp->toJS(CORE_LAN1).'")</script>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$themes_dir = $e107->e107_dirs["THEMES_DIRECTORY"];
|
|
|
|
$e107->http_theme_dir = "{$e107->server_path}{$themes_dir}{$e107->site_theme}/";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Q: ALL OTHER SETUP CODE
|
|
|
|
//
|
|
|
|
$sql->db_Mark_Time('Start: Misc Setup');
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------------------//
|
|
|
|
if (!class_exists('e107_table')) {
|
|
|
|
class e107table {
|
|
|
|
function tablerender($caption, $text, $mode = "default", $return = false) {
|
|
|
|
/*
|
|
|
|
# Render style table
|
|
|
|
# - parameter #1: string $caption, caption text
|
|
|
|
# - parameter #2: string $text, body text
|
|
|
|
# - return null
|
|
|
|
# - scope public
|
|
|
|
*/
|
|
|
|
global $override;
|
|
|
|
|
|
|
|
if ($override_tablerender = $override->override_check('tablerender')) {
|
|
|
|
$result=call_user_func($override_tablerender, $caption, $text, $mode, $return);
|
|
|
|
|
|
|
|
if ($result == "return") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
extract($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($return) {
|
|
|
|
ob_start();
|
|
|
|
tablestyle($caption, $text, $mode);
|
|
|
|
$ret=ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
return $ret;
|
|
|
|
} else {
|
|
|
|
tablestyle($caption, $text, $mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//#############################################################
|
|
|
|
|
2008-11-25 16:26:03 +00:00
|
|
|
|
|
|
|
$e107->ns = new e107table;
|
|
|
|
$ns = &$e107->ns;
|
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']))
|
|
|
|
{
|
2008-11-25 16:26:03 +00:00
|
|
|
if(force_userupdate())
|
2008-08-03 08:00:19 +00:00
|
|
|
{
|
|
|
|
header("Location: ".e_BASE."usersettings.php?update");
|
|
|
|
exit();
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql->db_Mark_Time('Start: Signup/splash/admin');
|
|
|
|
|
|
|
|
define("e_SIGNUP", e_BASE.(file_exists(e_BASE."customsignup.php") ? "customsignup.php" : "signup.php"));
|
|
|
|
define("e_LOGIN", e_BASE.(file_exists(e_BASE."customlogin.php") ? "customlogin.php" : "login.php"));
|
|
|
|
|
2008-05-19 09:42:28 +00:00
|
|
|
// --------- Send user to Membersonly-page when not logged in ---------------.
|
2008-01-06 22:16:37 +00:00
|
|
|
if ($pref['membersonly_enabled'] && !USER && e_SELF != SITEURL.e_SIGNUP && e_SELF != SITEURL."index.php" && e_SELF != SITEURL."fpw.php" && e_SELF != SITEURL.e_LOGIN && strpos(e_PAGE, "admin") === FALSE && e_SELF != SITEURL.'membersonly.php' && e_SELF != SITEURL.'sitedown.php')
|
|
|
|
{
|
|
|
|
if(!isset($_E107['allow_guest']))
|
|
|
|
{
|
2008-11-16 09:17:13 +00:00
|
|
|
if($_POST['ajax_used'] || $_GET['ajax_used'] || e_PAGE == "e_ajax.php" || e_PAGE == "e_js.php" || e_PAGE == "e_jslib.php")
|
2008-05-19 08:54:38 +00:00
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
// remember the url for after-login.
|
2008-05-19 09:42:28 +00:00
|
|
|
$afterlogin = e_COOKIE.'_afterlogin';
|
2008-05-19 08:54:38 +00:00
|
|
|
$url = (e_QUERY) ? e_SELF."?".e_QUERY : e_SELF;
|
2008-05-19 09:42:28 +00:00
|
|
|
session_set($afterlogin,$url,time()+300);
|
2008-05-19 08:54:38 +00:00
|
|
|
header("Location: ".e_HTTP."membersonly.php");
|
2008-08-03 08:00:19 +00:00
|
|
|
exit();
|
2008-01-06 22:16:37 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2008-05-19 08:54:38 +00:00
|
|
|
// ----- Redirect to previously logged-in page ---------------------------.
|
2008-05-19 09:42:28 +00:00
|
|
|
if(USER && $pref['membersonly_enabled'] && ($_SESSION[e_COOKIE.'_afterlogin'] || $_COOKIE[e_COOKIE.'_afterlogin']))
|
2008-05-19 08:54:38 +00:00
|
|
|
{
|
2008-05-19 10:09:05 +00:00
|
|
|
$url = ($_SESSION[e_COOKIE.'_afterlogin']) ? $_SESSION[e_COOKIE.'_afterlogin'] : $_COOKIE[e_COOKIE.'_afterlogin'];
|
2008-05-19 09:42:28 +00:00
|
|
|
session_set(e_COOKIE.'_afterlogin',FALSE,-1000);
|
|
|
|
header("Location: ".$url);
|
2008-08-03 08:00:19 +00:00
|
|
|
exit();
|
2008-05-19 08:54:38 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
|
2008-01-06 22:16:37 +00:00
|
|
|
if(!isset($_E107['no_prunetmp']))
|
|
|
|
{
|
|
|
|
$sql->db_Delete("tmp", "tmp_time < ".(time() - 300)." AND tmp_ip!='data' AND tmp_ip!='submitted_link'");
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
if ($pref['maintainance_flag'] && ADMIN == FALSE && strpos(e_SELF, "admin.php") === FALSE && strpos(e_SELF, "sitedown.php") === FALSE) {
|
|
|
|
header("Location: ".SITEURL."sitedown.php");
|
2008-08-03 08:00:19 +00:00
|
|
|
exit();
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$sql->db_Mark_Time('(Start: Login/logout/ban/tz)');
|
|
|
|
|
2008-11-25 16:26:03 +00:00
|
|
|
if (isset($_POST['userlogin']) || isset($_POST['userlogin_x']))
|
2008-06-13 20:20:23 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
e107_require_once(e_HANDLER."login.php");
|
2008-06-13 20:20:23 +00:00
|
|
|
$usr = new userlogin($_POST['username'], $_POST['userpass'], $_POST['autologin'],varset($_POST['hashchallenge'],''));
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2008-06-13 20:20:23 +00:00
|
|
|
if ((e_QUERY == 'logout') || (($pref['user_tracking'] == "session") && isset($_SESSION['ubrowser']) && ($_SESSION['ubrowser'] != $ubrowser)))
|
2008-11-25 16:26:03 +00:00
|
|
|
//if (e_QUERY == 'logout')
|
2007-12-15 15:06:40 +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,'');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
$ip = $e107->getip();
|
|
|
|
$udata=(USER === TRUE) ? USERID.".".USERNAME : "0";
|
|
|
|
$sql->db_Update("online", "online_user_id = '0', online_pagecount=online_pagecount+1 WHERE online_user_id = '{$udata}' LIMIT 1");
|
|
|
|
|
|
|
|
if ($pref['user_tracking'] == "session") {
|
|
|
|
session_destroy();
|
2008-05-19 09:42:28 +00:00
|
|
|
$_SESSION[e_COOKIE]="";
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2008-05-19 09:42:28 +00:00
|
|
|
cookie(e_COOKIE, "", (time() - 2592000));
|
2006-12-02 04:36:16 +00:00
|
|
|
$e_event->trigger("logout");
|
|
|
|
echo "<script type='text/javascript'>document.location.href = '".SITEURL."index.php'</script>\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
if (isset($_COOKIE['e107_tdOffset'])) {
|
|
|
|
// Actual seconds of delay. See e107.js and footer_default.php
|
|
|
|
$e_deltaTime = $_COOKIE['e107_tdOffset'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_COOKIE['e107_tzOffset'])) {
|
|
|
|
// Relative client-to-server time zone offset in seconds.
|
|
|
|
$e_deltaTime += (-($_COOKIE['e107_tzOffset'] * 60 + date("Z")));
|
|
|
|
}
|
|
|
|
|
|
|
|
define("TIMEOFFSET", $e_deltaTime);
|
|
|
|
|
|
|
|
$sql->db_Mark_Time('Start: Get menus');
|
2008-01-06 22:16:37 +00:00
|
|
|
if(!isset($_E107['no_menus']))
|
|
|
|
{
|
2008-01-27 01:57:23 +00:00
|
|
|
$menu_data = $e107cache->retrieve_sys("menus_".USERCLASS_LIST."_".md5(e_LANGUAGE));
|
|
|
|
$menu_data = $eArrayStorage->ReadArray($menu_data);
|
|
|
|
$eMenuList = array();
|
|
|
|
$eMenuActive = array();
|
|
|
|
$eMenuArea = array();
|
2008-01-06 22:16:37 +00:00
|
|
|
if(!is_array($menu_data))
|
|
|
|
{
|
|
|
|
if ($sql->db_Select('menus', '*', "menu_location > 0 AND menu_class IN (".USERCLASS_LIST.") ORDER BY menu_order"))
|
|
|
|
{
|
|
|
|
while ($row = $sql->db_Fetch())
|
|
|
|
{
|
2008-01-27 11:02:34 +00:00
|
|
|
$eMenuList[$row['menu_location']][] =$row;
|
2008-01-27 01:57:23 +00:00
|
|
|
$eMenuArea[$row['menu_location']][$row['menu_name']] =1;
|
2008-01-27 11:02:34 +00:00
|
|
|
$eMenuActive[$row['menu_name']] = $row['menu_name'];
|
2008-01-06 22:16:37 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2008-01-27 01:57:23 +00:00
|
|
|
$menu_data['menu_area'] = $eMenuArea;
|
2008-01-06 22:16:37 +00:00
|
|
|
$menu_data['menu_list'] = $eMenuList;
|
|
|
|
$menu_data['menu_active'] = $eMenuActive;
|
|
|
|
$menu_data = $eArrayStorage->WriteArray($menu_data, false);
|
|
|
|
$e107cache->set_sys("menus_".USERCLASS_LIST."_".md5(e_LANGUAGE), $menu_data);
|
|
|
|
unset($menu_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-01-27 11:02:34 +00:00
|
|
|
$eMenuArea = $menu_data['menu_area'];
|
|
|
|
$eMenuList = $menu_data['menu_list'];
|
2008-01-06 22:16:37 +00:00
|
|
|
$eMenuActive = $menu_data['menu_active'];
|
|
|
|
unset($menu_data);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$sql->db_Mark_Time('(Start: Find/Load Theme)');
|
|
|
|
|
2008-05-29 21:12:55 +00:00
|
|
|
|
|
|
|
// Work out which theme to use
|
|
|
|
//----------------------------
|
|
|
|
// The following files are assumed to use admin theme:
|
|
|
|
// 1. Any file in the admin directory (check for non-plugin added to avoid mismatches)
|
2008-11-25 16:26:03 +00:00
|
|
|
// 2. any plugin file starting with 'admin_'
|
|
|
|
// 3. any plugin file in a folder called admin/
|
2008-05-29 21:12:55 +00:00
|
|
|
// 4. any file that specifies $eplug_admin = TRUE;
|
|
|
|
//
|
|
|
|
// e_SELF has the full HTML path
|
|
|
|
$inAdminDir = FALSE;
|
|
|
|
$isPluginDir = strpos(e_SELF,'/'.$PLUGINS_DIRECTORY) !== FALSE; // True if we're in a plugin
|
|
|
|
$e107Path = str_replace($e107->base_path, "", e_SELF); // Knock off the initial bits
|
2008-11-25 16:26:03 +00:00
|
|
|
if (
|
2008-05-29 21:12:55 +00:00
|
|
|
(!$isPluginDir && strpos($e107Path, $ADMIN_DIRECTORY) === 0 ) // Core admin directory
|
|
|
|
|| ($isPluginDir && (strpos(e_PAGE,"admin_") === 0 || strpos($e107Path, "admin/") !== FALSE)) // Plugin admin file or directory
|
|
|
|
|| (varsettrue($eplug_admin)) // Admin forced
|
|
|
|
)
|
2008-01-06 22:16:37 +00:00
|
|
|
{
|
2008-05-29 21:12:55 +00:00
|
|
|
$inAdminDir = TRUE;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-29 21:12:55 +00:00
|
|
|
if(!defined("THEME"))
|
|
|
|
{
|
|
|
|
if ($inAdminDir && varsettrue($pref['admintheme'])&& (strpos(e_SELF.'?'.e_QUERY, 'menus.php?configure') === FALSE))
|
|
|
|
{
|
2008-11-25 16:26:03 +00:00
|
|
|
/* if (strpos(e_SELF, "newspost.php") !== FALSE)
|
2008-05-29 21:12:55 +00:00
|
|
|
{
|
|
|
|
define("MAINTHEME", e_THEME.$pref['sitetheme']."/"); MAINTHEME no longer used in core distribution
|
|
|
|
} */
|
|
|
|
checkvalidtheme($pref['admintheme']);
|
2008-11-25 16:26:03 +00:00
|
|
|
}
|
|
|
|
elseif (USERTHEME !== FALSE && USERTHEME != "USERTHEME")
|
2008-05-29 21:12:55 +00:00
|
|
|
{
|
|
|
|
checkvalidtheme(USERTHEME);
|
2008-11-25 16:26:03 +00:00
|
|
|
}
|
|
|
|
else
|
2008-05-29 21:12:55 +00:00
|
|
|
{
|
|
|
|
checkvalidtheme($pref['sitetheme']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------
|
|
|
|
|
2008-05-29 21:12:55 +00:00
|
|
|
|
2008-01-06 22:16:37 +00:00
|
|
|
// here we USE the theme
|
2008-05-29 21:12:55 +00:00
|
|
|
if ($inAdminDir)
|
2008-01-06 22:16:37 +00:00
|
|
|
{
|
2008-11-25 16:26:03 +00:00
|
|
|
if (file_exists(THEME.'admin_theme.php'))
|
2008-05-29 21:12:55 +00:00
|
|
|
{
|
|
|
|
require_once(THEME.'admin_theme.php');
|
2008-11-25 16:26:03 +00:00
|
|
|
}
|
|
|
|
else
|
2008-05-29 21:12:55 +00:00
|
|
|
{
|
|
|
|
require_once(THEME."theme.php");
|
|
|
|
}
|
2008-11-25 16:26:03 +00:00
|
|
|
}
|
|
|
|
else
|
2008-05-29 21:12:55 +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
|
|
|
|
$tp->sch_load();
|
2008-05-29 21:12:55 +00:00
|
|
|
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
$exclude_lan = array("lan_signup.php"); // required for multi-language.
|
|
|
|
|
2008-05-29 21:12:55 +00:00
|
|
|
if ($inAdminDir)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
elseif (!in_array("lan_".e_PAGE,$exclude_lan) && !$isPluginDir)
|
2008-05-29 21:12:55 +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
|
|
|
}
|
|
|
|
|
2008-05-29 21:12:55 +00:00
|
|
|
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
if(!defined("IMODE")) define("IMODE", "lite");
|
|
|
|
|
2006-12-07 15:41:50 +00:00
|
|
|
if (IMODE == 'lite') {
|
|
|
|
$imode = 'nuvola_light';
|
|
|
|
} else if (IMODE == 'dark') {
|
|
|
|
$imode = 'nuvola_dark';
|
|
|
|
} else {
|
|
|
|
$imode = IMODE;
|
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
if ($pref['anon_post'] ? define("ANON", TRUE) : define("ANON", FALSE));
|
|
|
|
|
|
|
|
if (Empty($pref['newsposts']) ? define("ITEMVIEW", 15) : define("ITEMVIEW", $pref['newsposts']));
|
|
|
|
|
2008-11-25 16:26:03 +00:00
|
|
|
if ($pref['antiflood1'] == 1)
|
2007-09-18 21:15:41 +00:00
|
|
|
{
|
|
|
|
define('FLOODPROTECT', TRUE);
|
|
|
|
define('FLOODTIMEOUT', max(varset($pref['antiflood_timeout'],10),3));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
define('FLOODPROTECT', FALSE);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$layout = isset($layout) ? $layout : '_default';
|
|
|
|
define("HEADERF", e_THEME."templates/header{$layout}.php");
|
|
|
|
define("FOOTERF", e_THEME."templates/footer{$layout}.php");
|
|
|
|
|
|
|
|
if (!file_exists(HEADERF)) {
|
|
|
|
message_handler("CRITICAL_ERROR", "Unable to find file: ".HEADERF, __LINE__ - 2, __FILE__);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file_exists(FOOTERF)) {
|
|
|
|
message_handler("CRITICAL_ERROR", "Unable to find file: ".FOOTERF, __LINE__ - 2, __FILE__);
|
|
|
|
}
|
|
|
|
|
|
|
|
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'])) {
|
|
|
|
$tmp = explode("?", $_SERVER['HTTP_REFERER']);
|
|
|
|
define("e_REFERER_SELF",($tmp[0] == e_SELF));
|
|
|
|
} else {
|
|
|
|
define('e_REFERER_SELF', FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists('convert'))
|
|
|
|
{
|
|
|
|
require_once(e_HANDLER."date_handler.php");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//@require_once(e_HANDLER."IPB_int.php");
|
|
|
|
//@require_once(e_HANDLER."debug_handler.php");
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
|
|
|
|
function js_location($qry){
|
2006-12-05 09:33:20 +00:00
|
|
|
global $error_handler;
|
|
|
|
if (count($error_handler->errors)) {
|
|
|
|
echo $error_handler->return_errors();
|
|
|
|
exit;
|
|
|
|
} else {
|
2006-12-02 04:36:16 +00:00
|
|
|
echo "<script type='text/javascript'>document.location.href='{$qry}'</script>\n"; 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
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
|
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
|
|
|
{
|
|
|
|
global $tp;
|
2007-01-12 02:36:18 +00:00
|
|
|
if($var == e_LANGUAGE)
|
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-12-22 12:39:27 +00:00
|
|
|
// if (is_numeric($var) && ($var == e_UC_PUBLIC)) return TRUE; // Accept numeric class zero - 'PUBLIC'
|
2007-12-15 09:55:37 +00:00
|
|
|
|
2007-01-12 02:36:18 +00:00
|
|
|
// userid has been supplied, go build that user's class list
|
|
|
|
if(is_numeric($uid) && $uid > 0)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2007-01-12 02:36:18 +00:00
|
|
|
$userclass = class_list($uid);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
2007-01-12 02:36:18 +00:00
|
|
|
if ($userclass == "")
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-01-12 02:36:18 +00:00
|
|
|
$class_array = explode(",", $userclass);
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2007-01-12 02:36:18 +00:00
|
|
|
$lans = explode(",", e_LANLIST);
|
|
|
|
$varList = explode(",", trim($var));
|
2008-11-25 16:26:03 +00:00
|
|
|
|
2007-01-12 02:36:18 +00:00
|
|
|
rsort($varList); // check the language first.(ie. numbers come last)
|
|
|
|
foreach($varList as $v)
|
|
|
|
{
|
|
|
|
if (in_array($v, $lans) && strpos($v, e_LANGUAGE) === FALSE)
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-01-12 02:36:18 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!is_numeric($v)) //value to test is a userclass name, go get the id
|
|
|
|
{
|
|
|
|
$sql=new db;
|
|
|
|
$v = trim($v);
|
|
|
|
if($sql->db_Select("userclass_classes", "userclass_id", "userclass_name='".$tp->toDB($v)."' "))
|
|
|
|
{
|
|
|
|
$row = $sql->db_Fetch();
|
|
|
|
$v = $row['userclass_id'];
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2007-01-12 02:36:18 +00:00
|
|
|
}
|
2008-01-06 17:57:06 +00:00
|
|
|
if (in_array($v, $class_array) || (ctype_digit($v) && ($v == 0)))
|
2007-01-12 02:36:18 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getperms($arg, $ap = ADMINPERMS) {
|
|
|
|
global $PLUGINS_DIRECTORY;
|
|
|
|
if ($ap == "0") {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if ($ap == "") {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
$ap='.'.$ap;
|
|
|
|
if ($arg == 'P' && preg_match("#(.*?)/".$PLUGINS_DIRECTORY."(.*?)/(.*?)#", e_SELF, $matches)) {
|
|
|
|
$psql=new db;
|
|
|
|
if ($psql->db_Select('plugin', 'plugin_id', "plugin_path = '".$matches[2]."' ")) {
|
|
|
|
$row=$psql->db_Fetch();
|
|
|
|
$arg='P'.$row[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strpos($ap, ".".$arg.".") !== FALSE) {
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the user data from user and user_extended tables
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function get_user_data($uid, $extra = "")
|
|
|
|
{
|
|
|
|
global $pref, $sql;
|
2008-11-26 15:00:56 +00:00
|
|
|
$e107 = e107::getInstance();
|
|
|
|
$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 = "
|
|
|
|
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
|
|
|
";
|
|
|
|
if (!$sql->db_Select_gen($qry))
|
|
|
|
{
|
2007-11-09 05:55:45 +00:00
|
|
|
$qry = "SELECT * FROM #user AS u WHERE u.user_id = {$uid} {$extra}";
|
2006-12-02 04:36:16 +00:00
|
|
|
if(!$sql->db_Select_gen($qry))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$var = $sql->db_Fetch();
|
|
|
|
$extended_struct = getcachedvars("extended_struct");
|
|
|
|
if(!$extended_struct)
|
|
|
|
{
|
|
|
|
unset($extended_struct);
|
|
|
|
$qry = "SHOW COLUMNS FROM #user_extended ";
|
|
|
|
if($sql->db_Select_gen($qry))
|
|
|
|
{
|
|
|
|
while($row = $sql->db_Fetch())
|
|
|
|
{
|
|
|
|
if($row['Default'] != "")
|
|
|
|
{
|
|
|
|
$extended_struct[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($extended_struct))
|
|
|
|
{
|
|
|
|
cachevars("extended_struct", $extended_struct);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($extended_struct))
|
|
|
|
{
|
|
|
|
foreach($extended_struct as $row)
|
|
|
|
{
|
|
|
|
if($row['Default'] != "" && ($var[$row['Field']] == NULL || $var[$row['Field']] == "" ))
|
|
|
|
{
|
|
|
|
$var[$row['Field']] = $row['Default'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-25 16:26:03 +00:00
|
|
|
|
2007-12-22 12:39:27 +00:00
|
|
|
//===========================================================
|
|
|
|
// Now look up the 'inherited' user classes
|
2008-01-05 22:02:31 +00:00
|
|
|
global $e_userclass;
|
2008-11-25 16:26:03 +00:00
|
|
|
if (!isset($e_userclass) && !is_object($e_userclass))
|
2007-12-22 12:39:27 +00:00
|
|
|
{
|
|
|
|
require_once(e_HANDLER."userclass_class.php");
|
2008-11-25 16:26:03 +00:00
|
|
|
$e107->e_userclass = new user_class;
|
|
|
|
$e_userclass = &$e107->e_userclass;
|
2007-12-22 12:39:27 +00:00
|
|
|
}
|
|
|
|
$var['user_class'] = $e_userclass->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
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
cachevars("userdata_{$uid}", $var);
|
|
|
|
return $var;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
|
|
|
|
|
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
|
|
|
{
|
|
|
|
global $pref, $user_pref, $tp, $PrefCache, $sql, $eArrayStorage;
|
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
|
|
|
|
$_pref = $tp -> toDB($pref, true, true);
|
|
|
|
// Create the data to be stored
|
|
|
|
if($sql->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('SitePrefs', '".$eArrayStorage->WriteArray($_pref)."') "))
|
|
|
|
{
|
|
|
|
ecache::clear('SitePrefs');
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-03-04 21:47:15 +00:00
|
|
|
}
|
2007-02-03 12:43:53 +00:00
|
|
|
}
|
2008-11-25 16:26:03 +00:00
|
|
|
else
|
2007-02-03 12:43:53 +00:00
|
|
|
{
|
2007-03-04 21:47:15 +00:00
|
|
|
$_user_pref = $tp -> toDB($user_pref);
|
|
|
|
$tmp=addslashes(serialize($_user_pref));
|
|
|
|
$sql->db_Update("user", "user_prefs='$tmp' WHERE user_id=".intval($uid));
|
|
|
|
return $tmp;
|
2007-02-03 12:43:53 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
|
|
|
|
function cachevars($id, $var) {
|
|
|
|
global $cachevar;
|
|
|
|
$cachevar[$id]=$var;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getcachedvars($id) {
|
|
|
|
global $cachevar;
|
|
|
|
return (isset($cachevar[$id]) ? $cachevar[$id] : false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
|
|
|
|
class floodprotect {
|
|
|
|
function flood($table, $orderfield) {
|
|
|
|
/*
|
|
|
|
# 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;
|
|
|
|
|
|
|
|
if (FLOODPROTECT == TRUE) {
|
|
|
|
$sql->db_Select($table, "*", "ORDER BY ".$orderfield." DESC LIMIT 1", "no_where");
|
|
|
|
$row=$sql->db_Fetch();
|
|
|
|
return ($row[$orderfield] > (time() - FLOODTIMEOUT) ? FALSE : TRUE);
|
|
|
|
} else {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
|
|
|
|
function init_session() {
|
|
|
|
/*
|
|
|
|
# Validate user
|
|
|
|
#
|
|
|
|
# - parameters none
|
|
|
|
# - return boolean
|
|
|
|
# - scope public
|
|
|
|
*/
|
2008-01-22 00:39:08 +00:00
|
|
|
global $sql, $pref, $user_pref, $tp, $currentUser, $e107, $_E107;
|
2006-12-02 04:36:16 +00:00
|
|
|
|
|
|
|
define('USERIP', $e107->getip());
|
2008-01-22 00:39:08 +00:00
|
|
|
|
2008-03-13 19:15:56 +00:00
|
|
|
if(isset($_E107['cli']) && $_SERVER['argv'][1])
|
2008-01-22 00:39:08 +00:00
|
|
|
{
|
|
|
|
require_once(e_HANDLER."cli_class.php");
|
|
|
|
$cli = new eCLI;
|
|
|
|
$arg = $cli->parse_args();
|
|
|
|
if($arg['u'] && $arg['p'])
|
|
|
|
{
|
|
|
|
e107_require_once(e_HANDLER."login.php");
|
|
|
|
$usr = new userlogin;
|
|
|
|
$cli_log = $usr->userlogin(trim($arg['u']), trim($arg['p']), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-19 09:42:28 +00:00
|
|
|
if (!isset($_COOKIE[e_COOKIE]) && !isset($_SESSION[e_COOKIE]) && !isset($_E107['cli']))
|
2008-01-22 00:39:08 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
define("USER", FALSE);
|
2008-06-13 20:20:23 +00:00
|
|
|
define('USERID', 0);
|
2006-12-02 04:36:16 +00:00
|
|
|
define("USERTHEME", FALSE);
|
|
|
|
define("ADMIN", FALSE);
|
|
|
|
define("GUEST", TRUE);
|
|
|
|
define('USERCLASS', '');
|
|
|
|
define('USEREMAIL', '');
|
2008-01-22 00:39:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list($uid, $upw)= explode(".", $cli_log);
|
|
|
|
}
|
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
|
|
|
{
|
2008-05-19 09:42:28 +00:00
|
|
|
cookie(e_COOKIE, "", (time() - 2592000));
|
|
|
|
$_SESSION[e_COOKIE] = "";
|
2006-12-02 04:36:16 +00:00
|
|
|
session_destroy();
|
|
|
|
define("ADMIN", FALSE);
|
|
|
|
define("USER", FALSE);
|
2008-06-13 20:20:23 +00:00
|
|
|
define('USERID', 0);
|
2006-12-02 04:36:16 +00:00
|
|
|
define("USERCLASS", "");
|
|
|
|
define("LOGINMESSAGE",CORE_LAN10."<br /><br />");
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = get_user_data($uid);
|
|
|
|
if(is_array($result) && md5($result['user_password']) == $upw)
|
|
|
|
{
|
|
|
|
|
|
|
|
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']);
|
|
|
|
define("USERREALM", $result['user_realm']);
|
|
|
|
define("USERVIEWED", $result['user_viewed']);
|
|
|
|
define("USERIMAGE", $result['user_image']);
|
2008-01-09 22:00:23 +00:00
|
|
|
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();
|
|
|
|
$sql->db_Update("user", "user_visits = user_visits + 1, user_lastvisit = '{$result['user_lastvisit']}', user_currentvisit = '{$result['user_currentvisit']}', user_viewed = ''{$update_ip} WHERE user_id='".USERID."' ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$result['user_currentvisit'] = time();
|
|
|
|
$sql->db_Update("user", "user_currentvisit = '{$result['user_currentvisit']}'{$update_ip} WHERE user_id='".USERID."' ");
|
|
|
|
}
|
|
|
|
|
|
|
|
$currentUser = $result;
|
|
|
|
$currentUser['user_realname'] = $result['user_login']; // Used by force_userupdate
|
|
|
|
define("USERLV", $result['user_lastvisit']);
|
|
|
|
|
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
|
|
|
|
2007-04-15 16:07:39 +00:00
|
|
|
$user_pref = ($result['user_prefs']) ? unserialize($result['user_prefs']) : '';
|
2006-12-02 04:36:16 +00:00
|
|
|
|
2008-11-25 16:26:03 +00:00
|
|
|
if (isset($_POST['settheme']))
|
2008-06-13 20:20:23 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
$user_pref['sitetheme'] = ($pref['sitetheme'] == $_POST['sitetheme'] ? "" : $_POST['sitetheme']);
|
|
|
|
save_prefs("user");
|
|
|
|
}
|
|
|
|
|
|
|
|
define("USERTHEME", (isset($user_pref['sitetheme']) && file_exists(e_THEME.$user_pref['sitetheme']."/theme.php") ? $user_pref['sitetheme'] : FALSE));
|
|
|
|
global $ADMIN_DIRECTORY, $PLUGINS_DIRECTORY;
|
2008-11-25 16:26:03 +00:00
|
|
|
if ($result['user_admin'])
|
2008-06-13 20:20:23 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +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']);
|
2008-11-25 16:26:03 +00:00
|
|
|
}
|
|
|
|
else
|
2008-06-13 20:20:23 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
define("ADMIN", FALSE);
|
|
|
|
}
|
2008-11-25 16:26:03 +00:00
|
|
|
}
|
|
|
|
else
|
2008-06-13 20:20:23 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
define("USER", FALSE);
|
2008-06-13 20:20:23 +00:00
|
|
|
define('USERID', 0);
|
2006-12-02 04:36:16 +00:00
|
|
|
define("USERTHEME", FALSE);
|
|
|
|
define("ADMIN", FALSE);
|
|
|
|
define("CORRUPT_COOKIE", TRUE);
|
|
|
|
define("USERCLASS", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
define('USERCLASS_LIST', class_list());
|
|
|
|
define('e_CLASS_REGEXP', "(^|,)(".str_replace(",", "|", USERCLASS_LIST).")(,|$)");
|
2006-12-03 03:26:22 +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']))
|
|
|
|
{
|
|
|
|
e107_require_once(e_HANDLER."online_class.php");
|
2008-11-25 16:26:03 +00:00
|
|
|
$e107->e_online = new e_online;
|
|
|
|
$e_online = &$e107->e_online;
|
2006-12-02 04:36:16 +00:00
|
|
|
$e_online->online($pref['track_online'], $pref['flood_protect']);
|
|
|
|
}
|
|
|
|
|
2008-07-04 20:19:46 +00:00
|
|
|
function cookie($name, $value, $expire=0, $path = "/", $domain = "", $secure = 0) {
|
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.
|
|
|
|
function session_set($name, $value, $expire="", $path = "/", $domain = "", $secure = 0)
|
|
|
|
{
|
|
|
|
global $pref;
|
|
|
|
if ($pref['user_tracking'] == "session")
|
|
|
|
{
|
|
|
|
$_SESSION[$name] = $value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setcookie($name, $value, $expire, $path, $domain, $secure);
|
|
|
|
$_COOKIE[$name] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
//
|
|
|
|
// Use these to combine isset() and use of the set value. or defined and use of a constant
|
|
|
|
// i.e. to fix if($pref['foo']) ==> if ( varset($pref['foo']) ) will use the pref, or ''.
|
|
|
|
// Can set 2nd param to any other default value you like (e.g. false, 0, or whatever)
|
|
|
|
// $testvalue adds additional test of the value (not just isset())
|
|
|
|
// Examples:
|
|
|
|
// $something = pref; // Bug if pref not set ==> $something = varset(pref);
|
|
|
|
// $something = isset(pref) ? pref : ""; ==> $something = varset(pref);
|
|
|
|
// $something = isset(pref) ? pref : default; ==> $something = varset(pref,default);
|
2007-01-20 14:55:06 +00:00
|
|
|
// $something = isset(pref) && pref ? pref : default; ==> use varsettrue(pref,default)
|
2006-12-02 04:36:16 +00:00
|
|
|
//
|
2007-01-20 14:55:06 +00:00
|
|
|
function varset(&$val,$default='') {
|
2006-12-02 04:36:16 +00:00
|
|
|
if (isset($val)) {
|
2007-01-20 14:55:06 +00:00
|
|
|
return $val;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
return $default;
|
|
|
|
}
|
2007-01-20 14:55:06 +00:00
|
|
|
function defset($str,$default='') {
|
2006-12-02 04:36:16 +00:00
|
|
|
if (defined($str)) {
|
2007-01-20 14:55:06 +00:00
|
|
|
return constant($str);
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// These variants are like the above, but only return the value if both set AND 'true'
|
|
|
|
//
|
|
|
|
function varsettrue(&$val,$default='') {
|
|
|
|
if (isset($val) && $val) return $val;
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
function defsettrue($str,$default='') {
|
|
|
|
if (defined($str) && constant($str)) return constant($str);
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
|
|
|
|
function message_handler($mode, $message, $line = 0, $file = "") {
|
|
|
|
e107_require_once(e_HANDLER."message_handler.php");
|
|
|
|
show_emessage($mode, $message, $line, $file);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
function table_exists($check) {
|
|
|
|
if (!$GLOBALS['mySQLtablelist']) {
|
|
|
|
$tablist=mysql_list_tables($GLOBALS['mySQLdefaultdb']);
|
|
|
|
while (list($temp) = mysql_fetch_array($tablist)) {
|
|
|
|
$GLOBALS['mySQLtablelist'][] = $temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$mltable=MPREFIX.strtolower($check);
|
|
|
|
|
|
|
|
foreach ($GLOBALS['mySQLtablelist'] as $lang) {
|
|
|
|
if (strpos($lang, $mltable) !== FALSE) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function e107_include($fname) {
|
|
|
|
global $e107_debug;
|
|
|
|
$ret = ($e107_debug ? include($fname) : @include($fname));
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
function e107_include_once($fname) {
|
|
|
|
global $e107_debug;
|
|
|
|
if(is_readable($fname)){
|
|
|
|
$ret = (!$e107_debug)? @include_once($fname) : include_once($fname);
|
|
|
|
}
|
|
|
|
return (isset($ret)) ? $ret : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
function e107_require_once($fname) {
|
|
|
|
global $e107_debug;
|
|
|
|
$ret = ($e107_debug ? require_once($fname) : @require_once($fname));
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
function e107_require($fname) {
|
|
|
|
global $e107_debug;
|
|
|
|
$ret = ($e107_debug ? require($fname) : @require($fname));
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2008-08-11 20:45:01 +00:00
|
|
|
|
|
|
|
|
2008-11-25 16:26:03 +00:00
|
|
|
function include_lan($path, $force = false)
|
2008-08-11 20:45:01 +00:00
|
|
|
{
|
2008-11-25 16:26:03 +00:00
|
|
|
if (!is_readable($path))
|
2008-08-11 20:45:01 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
$path = str_replace(e_LANGUAGE, 'English', $path);
|
|
|
|
}
|
|
|
|
$ret = ($force) ? include($path) : include_once($path);
|
|
|
|
return (isset($ret)) ? $ret : "";
|
|
|
|
}
|
|
|
|
|
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-11-25 16:26:03 +00:00
|
|
|
if(!function_exists("print_a"))
|
2008-07-17 19:31:33 +00:00
|
|
|
{
|
2008-11-25 16:26:03 +00:00
|
|
|
function print_a($var, $return = false)
|
2008-07-17 19:31:33 +00:00
|
|
|
{
|
2007-11-09 05:41:37 +00:00
|
|
|
$charset = "utf-8";
|
2008-11-25 16:26:03 +00:00
|
|
|
if(defined("CHARSET"))
|
2008-07-17 19:31:33 +00:00
|
|
|
{
|
|
|
|
$charset = CHARSET;
|
2007-11-09 05:41:37 +00:00
|
|
|
}
|
2008-07-17 19:31:33 +00:00
|
|
|
if(!$return)
|
|
|
|
{
|
|
|
|
echo '<pre>'.htmlspecialchars(print_r($var, true), ENT_QUOTES, $charset).'</pre>';
|
|
|
|
return true;
|
2008-11-25 16:26:03 +00:00
|
|
|
}
|
|
|
|
else
|
2008-07-17 19:31:33 +00:00
|
|
|
{
|
|
|
|
return '<pre>'.htmlspecialchars(print_r($var, true), ENT_QUOTES, $charset).'</pre>';
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2008-07-17 19:31:33 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-12 21:40:49 +00:00
|
|
|
// Check that all required user fields (including extended fields) are valid.
|
|
|
|
// Return TRUE if update required
|
2008-11-25 16:26:03 +00:00
|
|
|
function force_userupdate()
|
2007-08-12 21:40:49 +00:00
|
|
|
{
|
2006-12-02 04:36:16 +00:00
|
|
|
global $sql,$pref,$currentUser;
|
|
|
|
|
2007-11-13 07:25:54 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$signup_option_names = array("realname", "signature", "image", "timezone", "class");
|
|
|
|
|
|
|
|
foreach($signup_option_names as $key => $value)
|
|
|
|
{
|
|
|
|
if ($pref['signup_option_'.$value] == 2 && !$currentUser['user_'.$value])
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-12 21:40:49 +00:00
|
|
|
if (!varset($pref['disable_emailcheck'],TRUE) && !trim($currentUser['user_email'])) return TRUE;
|
|
|
|
|
2008-05-28 21:23:05 +00:00
|
|
|
if($sql -> db_Select("user_extended_struct", "user_extended_struct_name, user_extended_struct_type", "user_extended_struct_required = '1'"))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2008-05-28 21:23:05 +00:00
|
|
|
while($row = $sql -> db_Fetch())
|
|
|
|
{
|
|
|
|
$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')))
|
2006-12-02 04:36:16 +00:00
|
|
|
{
|
2008-05-28 21:23:05 +00:00
|
|
|
return TRUE;
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2008-05-28 21:23:05 +00:00
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
class error_handler {
|
|
|
|
|
|
|
|
var $errors;
|
|
|
|
var $debug = false;
|
|
|
|
|
|
|
|
function error_handler() {
|
2006-12-05 09:33:20 +00:00
|
|
|
//
|
|
|
|
// This is initialized before the current debug level is known
|
|
|
|
//
|
2008-01-21 03:54:10 +00:00
|
|
|
global $_E107;
|
2008-03-13 19:15:56 +00:00
|
|
|
if(isset($_E107['debug']))
|
2008-01-21 03:54:10 +00:00
|
|
|
{
|
|
|
|
$this->debug = true;
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-13 19:15:56 +00:00
|
|
|
if(isset($_E107['cli']))
|
2008-01-21 03:54:10 +00:00
|
|
|
{
|
|
|
|
error_reporting(E_ALL ^ E_NOTICE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
if ((isset($_SERVER['QUERY_STRING']) && strpos($_SERVER['QUERY_STRING'], 'debug=') !== FALSE) || isset($_COOKIE['e107_debug_level'])) {
|
|
|
|
$this->debug = true;
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
} else {
|
|
|
|
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:
|
2006-12-05 09:33:20 +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:
|
2006-12-05 09:33:20 +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:
|
|
|
|
if ($this->debug == true) {
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function return_errors() {
|
|
|
|
$index = 0; $colours[0] = "#C1C1C1"; $colours[1] = "#B6B6B6";
|
|
|
|
$ret = "<table class='fborder'>\n";
|
2006-12-05 09:33:20 +00:00
|
|
|
if (E107_DBG_ERRBACKTRACE)
|
|
|
|
{
|
2006-12-02 04:36:16 +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-05 09:33:20 +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";
|
|
|
|
}
|
|
|
|
}
|
2006-12-02 04:36:16 +00:00
|
|
|
$ret .= "</table>";
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
function trigger_error($information, $level) {
|
|
|
|
trigger_error($information);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strips slashes from a var if magic_quotes_gqc is enabled
|
|
|
|
*
|
|
|
|
* @param mixed $data
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function strip_if_magic($data) {
|
|
|
|
if (MAGIC_QUOTES_GPC == true) {
|
|
|
|
return array_stripslashes($data);
|
|
|
|
} else {
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Strips slashes from a string or an array
|
|
|
|
*
|
|
|
|
* @param mixed $value
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function array_stripslashes($data) {
|
|
|
|
return is_array($data) ? array_map('array_stripslashes', $data) : stripslashes($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql->db_Mark_Time('(After class2)');
|
|
|
|
|
|
|
|
|
|
|
|
function e107_ini_set($var, $value){
|
|
|
|
if (function_exists('ini_set')){
|
|
|
|
ini_set($var, $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-07 21:29:25 +00:00
|
|
|
|
|
|
|
// Return TRUE if specified plugin installed, FALSE if not
|
|
|
|
function plugInstalled($plugname)
|
|
|
|
{
|
|
|
|
global $pref;
|
|
|
|
if (!isset($pref['plug_installed'][$plugname])) return FALSE;
|
|
|
|
// Could add more checks here later if appropriate
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-27 11:02:34 +00:00
|
|
|
function echo_gzipped_page() {
|
|
|
|
|
|
|
|
if( headers_sent() ){
|
|
|
|
$encoding = false;
|
|
|
|
}elseif( strpos($_SERVER["HTTP_ACCEPT_ENCODING"], 'x-gzip') !== false ){
|
|
|
|
$encoding = 'x-gzip';
|
|
|
|
}elseif( strpos($_SERVER["HTTP_ACCEPT_ENCODING"],'gzip') !== false ){
|
|
|
|
$encoding = 'gzip';
|
|
|
|
}else{
|
|
|
|
$encoding = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $encoding ){
|
|
|
|
$contents = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
header('Content-Encoding: '.$encoding);
|
|
|
|
print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
|
|
|
|
$size = strlen($contents);
|
|
|
|
$contents = gzcompress($contents, 9);
|
|
|
|
$contents = substr($contents, 0, $size);
|
|
|
|
print($contents);
|
|
|
|
exit();
|
|
|
|
}else{
|
|
|
|
ob_end_flush();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-11 05:15:24 +00:00
|
|
|
?>
|