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
*
2020-01-19 14:33:11 +01:00
* Copyright ( C ) 2008 - 2020 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 (); }
2020-12-10 15:52:48 -08:00
if ( isset ( $_E107 [ 'cli' ], $_SERVER [ " HTTP_USER_AGENT " ]) && ! isset ( $_E107 [ 'debug' ]))
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
2016-12-01 11:20:56 -08:00
if ( function_exists ( 'utf8_encode' ) === false )
{
2016-12-01 12:07:13 -08:00
echo " e107 requires the PHP <a href='http://php.net/manual/en/dom.setup.php'>XML</a> package. Please install it to use e107. " ;
2016-12-01 11:20:56 -08:00
exit ();
}
2009-09-15 13:34:09 +00:00
if ( ! isset ( $_E107 [ 'cli' ]))
2008-01-21 03:54:10 +00:00
{
2020-12-08 12:21:12 -08:00
while ( ob_get_length () !== false ) // destroy all ouput buffering
{
ob_end_clean ();
}
2008-01-21 03:54:10 +00:00
ob_start (); // start our own.
$oblev_at_start = ob_get_level (); // preserve when destroying globals in step C
}
2021-01-05 08:54:09 -08:00
if ( ! empty ( $_E107 [ 'minimal' ]))
{
$_E107 [ 'no_prunetmp' ] = true ;
$_E107 [ 'no_menus' ] = true ;
$_E107 [ 'no_theme' ] = true ;
$_E107 [ 'no_online' ] = true ;
$_E107 [ 'no_lan' ] = true ;
$_E107 [ 'no_module' ] = true ;
$_E107 [ 'no_maintenance' ] = true ;
$_E107 [ 'no_forceuserupdate' ] = true ;
$_E107 [ 'no_event' ] = true ;
2021-02-05 18:31:54 -08:00
// $_E107['no_session'] = true;
2021-01-05 16:40:01 -08:00
// $_E107['no_parser'] = true;
2021-01-05 08:54:09 -08:00
$_E107 [ 'no_override' ] = true ;
$_E107 [ 'no_log' ] = true ;
2021-01-05 16:40:01 -08:00
// $_E107['no_autoload'] = true;
2021-01-05 08:54:09 -08:00
}
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
2020-12-10 18:02:28 -08: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' );
2020-12-10 18:02:28 -08:00
} */
2006-12-02 04:36:16 +00:00
// Destroy! (if we need to)
2020-12-10 18:02:28 -08:00
/*
2020-12-10 15:52:48 -08:00
if ( $register_globals === true )
2008-11-27 02:18:25 +00:00
{
2008-01-06 22:16:37 +00:00
if ( isset ( $_REQUEST [ '_E107' ])) { unset ( $_E107 ); }
2020-12-08 07:29:17 -08:00
foreach ( $GLOBALS as $global => $var )
2008-11-27 02:18:25 +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 );
}
}
2020-12-10 15:52:48 -08:00
unset ( $global );
2020-12-10 18:02:28 -08:00
} */
2006-12-02 04:36:16 +00:00
2009-11-24 16:30:08 +00:00
2018-02-04 18:42:39 -08:00
// Set Absolute file-path of directory containing class2.php
if ( ! defined ( 'e_ROOT' ))
{
2020-12-10 15:52:48 -08:00
$e_ROOT = realpath ( __DIR__ . '/' );
2018-02-04 18:42:39 -08:00
if (( substr ( $e_ROOT , - 1 ) !== '/' ) && ( substr ( $e_ROOT , - 1 ) !== '\\' ) )
{
$e_ROOT .= DIRECTORY_SEPARATOR ; // Should function correctly on both windows and Linux now.
}
define ( 'e_ROOT' , $e_ROOT );
unset ( $e_ROOT );
}
2009-11-24 16:30:08 +00:00
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
//
2020-01-18 18:57:43 +01:00
global $error_handler ;
2006-12-02 04:36:16 +00:00
$error_handler = new error_handler ();
//
// 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
2016-02-14 12:15:55 -08: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 );
}
2018-02-04 18:42:39 -08:00
@ include ( e_ROOT . 'e107_config.php' );
2009-11-22 23:36:23 +00:00
2012-10-16 07:35:42 +00:00
if ( ! defined ( 'e_POWEREDBY_DISABLE' ))
{
define ( 'e_POWEREDBY_DISABLE' , false );
}
2020-12-10 15:52:48 -08:00
if ( ! empty ( $CLASS2_INCLUDE ))
2011-06-07 12:40:34 +00:00
{
2018-02-04 18:42:39 -08:00
require_once ( e_ROOT . $CLASS2_INCLUDE );
2010-08-20 00:00:54 +00:00
}
2019-05-22 13:57:51 -07:00
if ( empty ( $HANDLERS_DIRECTORY ))
{
$HANDLERS_DIRECTORY = 'e107_handlers/' ;
}
if ( empty ( $PLUGINS_DIRECTORY ))
{
$PLUGINS_DIRECTORY = 'e107_plugins/' ;
}
2009-11-24 16:30:08 +00:00
//define("MPREFIX", $mySQLprefix); moved to $e107->set_constants()
2009-11-22 23:36:23 +00:00
2019-05-17 13:27:36 -07:00
if ( empty ( $mySQLdefaultdb ))
2008-08-03 08:00:19 +00:00
{
// 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
}
2017-12-11 13:44:23 -08:00
// Upgrade Compatibility - Disable CL_WIDGETS before e107_class.php is loaded.
2018-02-04 18:42:39 -08:00
$tmpPlugDir = e_ROOT . $PLUGINS_DIRECTORY ;
2020-12-10 15:52:48 -08:00
if ( is_dir ( $tmpPlugDir . '/cl_widgets' ))
2017-12-11 13:44:23 -08:00
{
2020-12-10 15:52:48 -08:00
rename ( $tmpPlugDir . '/cl_widgets' , $tmpPlugDir . '/cl_widgets__' );
2017-12-11 13:44:23 -08:00
}
unset ( $tmpPlugDir );
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
//
2019-05-17 13:27:36 -07:00
2019-05-22 13:57:51 -07:00
2019-05-17 13:27:36 -07:00
2018-02-04 18:42:39 -08:00
$tmp = e_ROOT . $HANDLERS_DIRECTORY ;
2009-08-05 19:58:32 +00:00
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 );
2019-02-08 11:01:42 -08:00
/** @note compact() causes issues with PHP7.3 */
$dirPaths = array ( 'ADMIN_DIRECTORY' , 'FILES_DIRECTORY' , 'IMAGES_DIRECTORY' , 'THEMES_DIRECTORY' , 'PLUGINS_DIRECTORY' , 'HANDLERS_DIRECTORY' , 'LANGUAGES_DIRECTORY' , 'HELP_DIRECTORY' , 'DOWNLOADS_DIRECTORY' , 'UPLOADS_DIRECTORY' , 'SYSTEM_DIRECTORY' , 'MEDIA_DIRECTORY' , 'CACHE_DIRECTORY' , 'LOGS_DIRECTORY' , 'CORE_DIRECTORY' , 'WEB_DIRECTORY' );
$e107_paths = array ();
foreach ( $dirPaths as $v )
{
if ( isset ( $$v ))
{
$e107_paths [ $v ] = $$v ;
}
}
2017-12-11 13:44:23 -08:00
2019-02-08 11:01:42 -08:00
// $e107_paths = compact('ADMIN_DIRECTORY', 'FILES_DIRECTORY', 'IMAGES_DIRECTORY', 'THEMES_DIRECTORY', 'PLUGINS_DIRECTORY', 'HANDLERS_DIRECTORY', 'LANGUAGES_DIRECTORY', 'HELP_DIRECTORY', 'DOWNLOADS_DIRECTORY','UPLOADS_DIRECTORY','SYSTEM_DIRECTORY', 'MEDIA_DIRECTORY','CACHE_DIRECTORY','LOGS_DIRECTORY', 'CORE_DIRECTORY', 'WEB_DIRECTORY');
$sql_info = compact ( 'mySQLserver' , 'mySQLuser' , 'mySQLpassword' , 'mySQLdefaultdb' , 'mySQLprefix' );
if ( isset ( $mySQLport ))
{
$sql_info [ 'mySQLport' ] = $mySQLport ;
}
2018-02-04 18:42:39 -08:00
$e107 = e107 :: getInstance () -> initCore ( $e107_paths , e_ROOT , $sql_info , varset ( $E107_CONFIG , array ()));
2011-12-28 10:01:25 +00:00
e107 :: getSingleton ( 'eIPHandler' ); // This auto-handles bans etc
2020-12-08 07:29:17 -08:00
unset ( $dirPaths , $e107_paths );
2011-12-28 10:01:25 +00:00
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
2006-12-02 04:36:16 +00:00
//
// Start the parser; use it to grab the full query string
//
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_parser' ]))
{
$tp = e107 :: getParser (); //TODO - find & replace $tp, $e107->tp
}
2009-11-24 16:30:08 +00:00
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.
//
2021-01-15 09:03:07 -08:00
2008-11-27 02:18:25 +00:00
require_once ( e_HANDLER . 'debug_handler.php' );
2020-04-26 13:32:18 -07:00
e107_debug :: init (); // defines E107_DEBUG_LEVEL
2021-01-15 09:03:07 -08:00
/** @var e107_db_debug $dbg */
2020-05-03 16:24:06 +02:00
$dbg = e107 :: getDebug ();
2006-12-02 04:36:16 +00:00
2020-04-26 13:32:18 -07:00
if ( E107_DEBUG_LEVEL )
2008-11-27 02:18:25 +00:00
{
2020-05-04 12:10:22 -07:00
$dbg -> active ( true );
2020-05-02 15:35:30 -07:00
/** @deprecated $db_debug */
$db_debug = $dbg ;
$dbg -> logTime ( 'Init ErrHandler' );
2006-12-02 04:36:16 +00:00
}
//
// I: Sanity check on e107_config.php
// e107_config.php upgrade check
2019-02-26 15:54:51 -08:00
// obsolete check, rewrite it
// if (!$ADMIN_DIRECTORY && !$DOWNLOADS_DIRECTORY)
// {
// message_handler('CRITICAL_ERROR', 8, ': generic, ', 'e107_config.php');
// exit;
// }
2006-12-02 04:36:16 +00:00
//
// 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
2009-07-23 15:29:07 +00:00
//DEPRECATED, BC, $e107->sql caught by __get()
2020-01-19 14:33:11 +01:00
/** @var e_db $sql */
2009-07-23 15:29:07 +00:00
$sql = e107 :: getDb (); //TODO - find & replace $sql, $e107->sql
2016-06-02 08:38:39 -07:00
$sql -> db_SetErrorReporting ( false );
2006-12-02 04:36:16 +00:00
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'SQL Connect' );
2020-12-08 07:29:17 -08:00
$merror = $sql -> db_Connect ( $sql_info [ 'mySQLserver' ], $sql_info [ 'mySQLuser' ], $sql_info [ 'mySQLpassword' ], $mySQLdefaultdb );
unset ( $sql_info );
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
2021-01-25 07:57:24 -08:00
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()
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_log' ]))
{
$admin_log = e107 :: getLog (); //TODO - find & replace $admin_log, $e107->admin_log
}
2020-12-10 15:52:48 -08:00
if ( $merror === 'e1' )
{
message_handler ( 'CRITICAL_ERROR' , 6 , ': generic, ' , 'class2.php' );
exit ;
}
if ( $merror === 'e2' )
{
message_handler ( " CRITICAL_ERROR " , 7 , ': generic, ' , 'class2.php' );
exit ;
}
2006-12-02 04:36:16 +00:00
//
// K: Load compatability mode.
//
2008-01-06 22:16:37 +00:00
/* PHP Compatabilty should *always* be on. */
2021-01-25 07:57:24 -08:00
$dbg -> logTime ( 'Php compatibility handler' );
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
2018-02-12 06:50:43 -06:00
// SITEURL constant depends on the database
// See https://github.com/e107inc/e107/issues/3033 for details.
2021-01-25 07:57:24 -08:00
$dbg -> logTime ( 'Set urlsdeferred' );
2018-02-12 06:50:43 -06:00
$e107 -> set_urls_deferred ();
2006-12-02 04:36:16 +00:00
//
// L: Extract core prefs from the database
//
2017-01-22 14:19:47 -08:00
2006-12-02 04:36:16 +00:00
2009-11-24 16:30:08 +00:00
// TODO - remove it from here, auto-loaded when required
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'Load Cache Handler' );
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()
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'Load Array Storage Handler' );
2013-03-22 20:06:23 -07:00
e107_require_once ( e_HANDLER . 'arraystorage_class.php' ); // ArrayData(); BC Fix only.
$eArrayStorage = e107 :: getArrayStorage (); //TODO - find & replace $eArrayStorage with e107::getArrayStorage();
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()
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'Load Event Handler' );
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_event' ]))
{
$e_event = e107 :: getEvent (); //TODO - find & replace $e_event, $e107->e_event
}
2021-01-25 07:57:24 -08:00
2017-01-22 14:19:47 -08:00
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'Load Core Prefs' );
2021-01-25 07:57:24 -08:00
2009-08-05 19:58:32 +00:00
2017-01-22 14:19:47 -08:00
2009-08-05 19:58:32 +00:00
// 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 ())
{
2018-01-25 16:10:51 -08:00
2009-08-05 19:58:32 +00:00
// Core prefs error - admin log
2020-12-21 10:00:28 -08:00
e107 :: getLog () -> add ( '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.
2020-12-21 10:00:28 -08:00
e107 :: getLog () -> add ( 'CORE_LAN8' , 'CORE_LAN9' , E_LOG_FATAL );
2009-08-28 15:21:23 +00:00
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
2020-12-10 15:52:48 -08:00
// resurrect core from old prefs
e107 :: getConfig () -> loadData ( e107 :: getConfig ( 'core_old' ) -> getPref (), false )
-> save ( false , true );
// resurrect core_backup from old prefs
e107 :: getConfig ( 'core_backup' ) -> loadData ( e107 :: getConfig ( 'core_old' ) -> getPref (), false )
-> save ( false , true );
2009-08-05 19:58:32 +00:00
}
2009-08-28 15:21:23 +00:00
2009-08-05 19:58:32 +00:00
}
2021-01-25 07:57:24 -08:00
$pref = e107 :: getPref (); // include pref class.
// e107_require_once(e_HANDLER. 'pref_class.php');
// TODO - DEPRECATED - remove
$sysprefs = new prefs ;
2010-10-26 07:41:20 +00:00
//DEPRECATED, BC, call e107::getPref/findPref() instead
2021-01-25 07:57:24 -08:00
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
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_menus' ]))
{
$dbg -> logTime ( 'Load Menu Prefs' );
$menu_pref = e107 :: getConfig ( 'menu' ) -> getPref (); //extract menu prefs
}
2010-11-21 12:49:36 +00:00
// NEW - force ssl
2020-12-10 15:52:48 -08:00
if ( empty ( $_E107 [ 'cli' ]) && e107 :: getPref ( 'ssl_enabled' ) && ! deftrue ( 'e_SSL_DISABLE' ) )
2010-11-21 12:49:36 +00:00
{
// 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
2020-12-10 15:52:48 -08:00
if ( strncmp ( e_REQUEST_URL , 'http://' , 7 ) === 0 )
2010-11-21 12:49:36 +00:00
{
// e_REQUEST_URL and e_REQUEST_URI introduced
2011-06-07 12:40:34 +00:00
$url = 'https://' . substr ( e_REQUEST_URL , 7 );
2016-12-01 15:38:40 -08:00
e107 :: redirect ( $url );
2010-11-21 12:49:36 +00:00
exit ;
}
}
2009-07-16 02:55:19 +00:00
2020-05-02 15:35:30 -07:00
// $dbg->logTime('(Extracting Core Prefs Done)');
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_lan' ]))
{
$dbg -> logTime ( 'Init Language and detect changes' );
$lng = e107 :: getLanguage (); // required for v1.0 BC.
$lng -> detect ();
}
2021-01-05 16:40:01 -08:00
else
{
define ( 'e_LAN' , 'en' );
}
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!
2016-02-14 19:00:12 -08:00
if ( ! empty ( $pref [ 'redirectsiteurl' ]) && ! empty ( $pref [ 'siteurl' ])) {
2008-04-26 02:12:13 +00:00
if ( isset ( $pref [ 'multilanguage_subdomain' ]) && $pref [ 'multilanguage_subdomain' ])
{
2020-12-10 15:52:48 -08: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 );
2016-02-14 19:00:12 -08:00
if ( defined ( 'e_DEBUG' ) && e_DEBUG === true )
{
2020-12-10 15:52:48 -08:00
echo 'Redirecting to location: ' . $location ;
2016-02-14 19:00:12 -08:00
}
e107 :: getRedirect () -> go ( $location , true , 301 );
// header("Location: {$location}", true, 301); // send 301 header, not 302
2008-04-26 02:12:13 +00:00
exit ();
2006-12-02 04:36:16 +00:00
}
2008-04-26 02:12:13 +00:00
}
2016-02-14 19:00:12 -08:00
elseif ( deftrue ( 'e_DOMAIN' ))
2008-04-26 02:12:13 +00:00
{
// Find domain and port from user and from pref
list ( $urlbase , $urlport ) = explode ( ':' , $_SERVER [ 'HTTP_HOST' ] . ':' );
2020-12-10 15:52:48 -08:00
if ( ! $urlport )
{
$urlport = ( int ) $_SERVER [ 'SERVER_PORT' ];
}
if ( ! $urlport )
{
$urlport = 80 ;
}
2008-04-26 02:12:13 +00:00
$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 )
{
2020-12-10 15:52:48 -08:00
$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
2020-12-10 15:52:48 -08: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' ] : '' );
2016-12-02 12:04:08 -08:00
$location = filter_var ( $location , FILTER_SANITIZE_URL );
2016-02-14 19:00:12 -08:00
//
// header("Location: {$location}", true, 301); // send 301 header, not 302
if ( defined ( 'e_DEBUG' ) && e_DEBUG === true )
{
2020-12-10 15:52:48 -08:00
echo " DEBUG INFO: site-redirect preference enabled.<br />Redirecting to: <a hre=' " . $location . " '> " . $location . '</a>' ;
echo '<br />e_DOMAIN: ' . e_DOMAIN ;
echo '<br />e_SUBDOMAIN: ' . e_SUBDOMAIN ;
2016-02-14 19:00:12 -08:00
}
else
{
e107 :: getRedirect () -> go ( $location , true , 301 );
}
exit ();
2008-04-26 02:12:13 +00:00
}
}
2006-12-02 04:36:16 +00:00
}
}
2010-09-10 01:01:48 +00:00
/**
* Set the User ' s 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
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_session' ]) && ! isset ( $_E107 [ 'no_lan' ]))
{
$dbg -> logTime ( 'Load Session Handler' );
e107 :: getSession (); //init core _SESSION - actually here for reference only, it's done by language handler set() method
$dbg -> logTime ( 'Set User Language Session' );
e107 :: getLanguage () -> set (); // set e_LANGUAGE, USERLAN, Language Session / Cookies etc. requires $pref;
}
else
{
define ( 'e_LANGUAGE' , 'English' );
}
2006-12-02 04:36:16 +00:00
2020-12-10 15:52:48 -08:00
if ( ! empty ( $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');
2015-06-05 12:25:32 -07:00
// v1 Custom language File Path.
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_lan' ]))
2015-06-05 12:25:32 -07:00
{
2021-01-05 08:54:09 -08:00
$dbg -> logTime ( 'Include Global Core Language Files' );
if (( e_ADMIN_AREA === true ) && ! empty ( $pref [ 'adminlanguage' ]))
{
include ( e_LANGUAGEDIR . $pref [ 'adminlanguage' ] . '/' . $pref [ 'adminlanguage' ] . '.php' );
}
else
{
include ( e_LANGUAGEDIR . e_LANGUAGE . '/' . e_LANGUAGE . '.php' ); // FASTEST - ALWAYS load
}
2015-06-05 12:25:32 -07:00
2021-01-05 08:54:09 -08:00
$customLan = e_LANGUAGEDIR . e_LANGUAGE . '/' . e_LANGUAGE . '_custom.php' ;
if ( is_readable ( $customLan )) // FASTER - if exist, should be done 'once' by the core
{
include ( $customLan );
}
2013-11-03 03:12:09 -08:00
2021-01-05 08:54:09 -08:00
// v2 Custom language File Path.
$customLan2 = e_SYSTEM . '/lans/' . e_LANGUAGE . '_custom.php' ;
if ( is_readable ( $customLan2 )) // FASTER - if exist, should be done 'once' by the core
{
include ( $customLan2 );
}
unset ( $customLan , $customLan2 );
2013-11-03 03:12:09 -08:00
2021-01-05 08:54:09 -08:00
$lng -> bcDefs (); // defined v1.x definitions for old templates.
2006-12-02 04:36:16 +00:00
2021-01-05 08:54:09 -08:00
$dbg -> logTime ( 'Include Global Plugin Language Files' );
if ( isset ( $pref [ 'lan_global_list' ]))
2012-12-12 18:46:34 -08:00
{
2021-01-05 08:54:09 -08:00
foreach ( $pref [ 'lan_global_list' ] as $path )
2017-12-16 12:25:18 -08:00
{
2021-01-05 08:54:09 -08:00
if ( e107 :: plugLan ( $path , 'global' , true ) === false )
{
e107 :: plugLan ( $path , 'global' );
}
2017-12-16 12:25:18 -08:00
2021-01-05 08:54:09 -08:00
}
}
2012-12-12 18:46:34 -08:00
}
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_session' ]))
{
$dbg -> logTime ( 'CHAP challenge' );
2012-12-12 18:46:34 -08:00
2021-01-05 08:54:09 -08:00
$die = e_AJAX_REQUEST !== true ;
e107 :: getSession ()
-> challenge () // Make sure there is a unique challenge string for CHAP login
-> check ( $die ); // Token protection
unset ( $die );
}
2006-12-02 04:36:16 +00:00
//
// N: misc setups: online user tracking, cache
//
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'Misc resources. Online user tracking, cache' );
2006-12-02 04:36:16 +00:00
2015-02-15 16:07:27 -08:00
/**
* @ deprecated BC , call the method only when needed , $e107 -> ecache caught by __get ()
*/
2009-07-23 15:29:07 +00:00
$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()
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_override' ]))
{
$override = e107 :: getSingleton ( 'override' );
}
2009-07-23 15:29:07 +00:00
//DEPRECATED, BC, call the method only when needed, $e107->user_class caught by __get()
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_session' ]))
{
$e_userclass = e107 :: getUserClass (); //TODO - find & replace $e_userclass, $e107->user_class
}
2008-11-30 23:15:15 +00:00
2015-03-07 16:30:46 -08:00
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_event' ]))
{
$dbg -> logTime ( 'Init Event Handler' );
e107 :: getEvent () -> init ();
$dbg -> logTime ( 'Register Core Events' );
e107 :: getNotify () -> registerEvents ();
}
2006-12-02 04:36:16 +00:00
//
// O: Start user session
//
2013-06-09 20:53:44 +01:00
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_session' ]))
{
$dbg -> logTime ( 'User session' );
init_session (); // Set up a lot of the user-related constants
}
else
{
define ( 'ADMIN' , false );
define ( 'USER' , true );
2021-01-05 16:40:01 -08:00
define ( 'USERCLASS_LIST' , '0' );
2021-01-05 08:54:09 -08:00
}
2013-06-09 20:53:44 +01:00
2006-12-02 04:36:16 +00:00
2020-12-21 10:00:28 -08:00
2009-11-19 10:07:32 +00:00
2015-05-30 17:06:22 -07:00
$developerMode = ( vartrue ( $pref [ 'developer' ], false ) || E107_DEBUG_LEVEL > 0 );
2021-01-05 16:40:01 -08:00
2021-01-05 08:54:09 -08:00
// for multi-language these definitions needs to come after the language loaded.
2021-01-05 16:40:01 -08:00
if ( ! defined ( 'SITENAME' )) // Allow override by English_custom.php or English_global.php plugin files.
{
define ( 'SITENAME' , trim ( $tp -> toHTML ( $pref [ 'sitename' ], '' , 'USER_TITLE,er_on,defs' )));
}
if ( ! defined ( 'SITEDESCRIPTION' )) // Allow override by English_custom.php or English_global.php plugin files.
{
define ( 'SITEDESCRIPTION' , $tp -> toHTML ( $pref [ 'sitedescription' ], '' , 'emotes_off,defs' ));
}
2019-01-28 12:02:10 -08:00
2021-01-05 16:40:01 -08:00
define ( 'SITEBUTTON' , $tp -> replaceConstants ( $pref [ 'sitebutton' ], 'abs' ));
define ( 'SITETAG' , $tp -> toHTML ( $pref [ 'sitetag' ], false , 'emotes_off,defs' ));
2019-01-28 12:02:10 -08:00
2021-01-05 16:40:01 -08:00
define ( 'SITEADMIN' , $pref [ 'siteadmin' ]);
define ( 'SITEADMINEMAIL' , $pref [ 'siteadminemail' ]);
define ( 'SITEDISCLAIMER' , $tp -> toHTML ( $pref [ 'sitedisclaimer' ], '' , 'emotes_off,defs' ));
define ( 'SITECONTACTINFO' , $tp -> toHTML ( $pref [ 'sitecontactinfo' ], true , 'emotes_off,defs' ));
define ( 'SITEEMAIL' , vartrue ( $pref [ 'replyto_email' ], $pref [ 'siteadminemail' ]));
define ( 'USER_REGISTRATION' , vartrue ( $pref [ 'user_reg' ], false )); // User Registration System Active or Not.
define ( 'e_DEVELOPER' , $developerMode );
define ( 'e_VERSION' , varset ( $pref [ 'version' ]));
2017-04-27 15:21:20 -07:00
2021-01-05 16:40:01 -08:00
unset ( $developerMode );
2012-07-12 01:43:38 +00:00
2021-01-05 16:40:01 -08:00
if ( ! empty ( $pref [ 'xurl' ]) && is_array ( $pref [ 'xurl' ]))
{
define ( 'XURL_FACEBOOK' , vartrue ( $pref [ 'xurl' ][ 'facebook' ], false ));
define ( 'XURL_TWITTER' , vartrue ( $pref [ 'xurl' ][ 'twitter' ], false ));
define ( 'XURL_YOUTUBE' , vartrue ( $pref [ 'xurl' ][ 'youtube' ], false ));
define ( 'XURL_GOOGLE' , vartrue ( $pref [ 'xurl' ][ 'google' ], false ));
define ( 'XURL_LINKEDIN' , vartrue ( $pref [ 'xurl' ][ 'linkedin' ], false ));
define ( 'XURL_GITHUB' , vartrue ( $pref [ 'xurl' ][ 'github' ], false ));
define ( 'XURL_FLICKR' , vartrue ( $pref [ 'xurl' ][ 'flickr' ], false ));
define ( 'XURL_INSTAGRAM' , vartrue ( $pref [ 'xurl' ][ 'instagram' ], false ));
define ( 'XURL_PINTEREST' , vartrue ( $pref [ 'xurl' ][ 'pinterest' ], false ));
define ( 'XURL_STEAM' , vartrue ( $pref [ 'xurl' ][ 'steam' ], false ));
define ( 'XURL_VIMEO' , vartrue ( $pref [ 'xurl' ][ 'vimeo' ], false ));
define ( 'XURL_TWITCH' , vartrue ( $pref [ 'xurl' ][ 'twitch' ], false ));
define ( 'XURL_VK' , vartrue ( $pref [ 'xurl' ][ 'vk' ], false ));
2013-03-16 03:58:12 -07:00
}
2021-01-05 16:40:01 -08:00
else
{
define ( 'XURL_FACEBOOK' , false );
define ( 'XURL_TWITTER' , false );
define ( 'XURL_YOUTUBE' , false );
define ( 'XURL_GOOGLE' , false );
define ( 'XURL_LINKEDIN' , false );
define ( 'XURL_GITHUB' , false );
define ( 'XURL_FLICKR' , false );
define ( 'XURL_INSTAGRAM' , false );
define ( 'XURL_PINTEREST' , false );
define ( 'XURL_STEAM' , false );
define ( 'XURL_VIMEO' , false );
define ( 'XURL_TWITCH' , false );
define ( 'XURL_VK' , false );
}
2014-10-23 04:35:42 -07:00
if ( ! defined ( 'MAIL_IDENTIFIER' ))
{
define ( 'MAIL_IDENTIFIER' , 'X-e107-id' );
}
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
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'Load Plugin Modules' );
2014-01-12 05:34:48 -08: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.
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_module' ]))
2008-11-27 02:18:25 +00:00
{
2021-01-05 08:54:09 -08:00
if ( isset ( $pref [ 'e_module_list' ]) && $pref [ 'e_module_list' ])
2008-11-27 02:18:25 +00:00
{
2021-01-05 08:54:09 -08:00
foreach ( $pref [ 'e_module_list' ] as $mod )
2008-11-27 02:18:25 +00:00
{
2021-01-05 08:54:09 -08:00
if ( is_readable ( e_PLUGIN . " { $mod } /e_module.php " ))
{
$dbg -> logTime ( '[e_module in ' . $mod . ']' );
require_once ( e_PLUGIN . " { $mod } /e_module.php " );
}
}
2006-12-02 04:36:16 +00:00
}
}
//
// P: THEME LOADING
//
2021-01-05 08:54:09 -08:00
if ( ! defined ( 'USERTHEME' ) && ! isset ( $_E107 [ 'no_theme' ]))
2016-09-12 10:09:33 -07:00
{
2021-01-05 08:54:09 -08:00
$dbg -> logTime ( 'Load Theme' );
2020-12-10 15:52:48 -08:00
define ( 'USERTHEME' , ( e107 :: getUser () -> getPref ( 'sitetheme' ) && file_exists ( e_THEME . e107 :: getUser () -> getPref ( 'sitetheme' ) . '/theme.php' ) ? e107 :: getUser () -> getPref ( 'sitetheme' ) : false ));
2016-09-12 10:09:33 -07:00
}
2006-12-02 04:36:16 +00:00
//
// Q: ALL OTHER SETUP CODE
//
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'Misc Setup' );
2006-12-02 04:36:16 +00:00
//------------------------------------------------------------------------------------------------------------------------------------//
2013-05-09 00:24:02 -07:00
2021-01-18 08:52:10 -08:00
if ( ! isset ( $_E107 [ 'no_theme' ]))
{
$ns = e107 :: getRender (); // load theme render class.
2013-05-09 00:24:02 -07:00
2021-01-18 08:52:10 -08:00
if ( ! class_exists ( 'e107table' , false )) // BC Fix.
{
class e107table extends e_render
2020-04-28 14:00:19 -07:00
{
2013-05-08 17:11:17 -07:00
}
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
2011-12-28 10:01:25 +00:00
$e107 = e107 :: getInstance (); // Is this needed now?
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'IP Handler and Ban Check' );
2011-12-28 10:01:25 +00:00
e107 :: getIPHandler () -> ban ();
2006-12-02 04:36:16 +00:00
2020-12-10 18:02:28 -08:00
if ( USER && ! isset ( $_E107 [ 'no_forceuserupdate' ]) && $_SERVER [ 'QUERY_STRING' ] !== 'logout' && varset ( $pref [ 'force_userupdate' ]))
2008-01-06 22:16:37 +00:00
{
2019-02-08 11:01:42 -08:00
if ( isset ( $currentUser ) && force_userupdate ( $currentUser ))
2008-08-03 08:00:19 +00:00
{
2012-06-01 14:31:02 +00:00
header ( 'Location: ' . SITEURL . 'usersettings.php?update' );
2008-08-03 08:00:19 +00:00
exit ();
2006-12-02 04:36:16 +00:00
}
}
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'Signup/splash/admin' );
2006-12-02 04:36:16 +00:00
2014-11-19 17:13:08 -08:00
if (( $pref [ 'membersonly_enabled' ] && ! isset ( $_E107 [ 'allow_guest' ])) || ( $pref [ 'maintainance_flag' ] && empty ( $_E107 [ 'cli' ]) && empty ( $_E107 [ 'no_maintenance' ])))
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' ]))
{
2016-02-15 00:56:08 -08:00
$sql -> 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
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'Login/logout/ban/tz' );
2006-12-02 04:36:16 +00:00
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
{
2020-12-08 07:29:17 -08:00
e107 :: getUser () -> login ( $_POST [ 'username' ], $_POST [ 'userpass' ], $_POST [ 'autologin' ], varset ( $_POST [ 'hashchallenge' ]), false );
2010-05-14 18:45:51 +00:00
// 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
}
2013-06-09 20:53:44 +01: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
2020-12-10 15:52:48 -08:00
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 )
{
2020-12-08 07:29:17 -08:00
if ( check_class ( varset ( $pref [ 'user_audit_class' ]))) // Need to note in user audit trail
2016-03-16 13:53:57 -07:00
{
2019-02-08 11:01:42 -08:00
e107 :: getLog () -> user_audit ( USER_AUDIT_LOGOUT , null , USERID , USERNAME );
2009-01-04 16:00:19 +00:00
}
2007-12-15 15:06:40 +00:00
}
2020-12-21 17:46:32 -08:00
// $ip = e107::getIPHandler()->getIP(false); Appears to not be used, so removed
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' ])
{
2016-02-15 00:56:08 -08:00
$sql -> update ( 'online' , " online_user_id = 0, online_pagecount=online_pagecount+1 WHERE online_user_id = ' { $udata } ' " );
2011-08-12 19:27:13 +00:00
}
2011-12-06 08:00:42 +00:00
// earlier event trigger with user data still available
e107 :: getEvent () -> trigger ( 'logout' );
2012-06-15 11:30:37 +00:00
// first model logout and session destroy..
e107 :: getUser () -> logout ();
// it might be removed soon
2020-12-10 15:52:48 -08: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 ] = '' ;
2013-06-09 20:53:44 +01:00
// @TODO: Need to destroy the session cookie as well (not done by session_destroy()
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
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
}
2016-12-13 21:31:59 +01:00
2016-12-13 20:48:45 +01:00
/**
* @ addtogroup timezone
* @ {
*/
/**
* Generate an array of time zones .
*
* @ return array
* Array of time zones .
*/
function systemTimeZones ()
{
// Never do something time consuming twice if you can hold onto the results
// and re-use them. So we re-use the statically cached value to save time
// and memory.
static $zones = array ();
// If Timezone list is not populated yet.
if ( empty ( $zones ))
{
$zonelist = timezone_identifiers_list ();
$timeNow = date ( 'm/d/Y H:i' , $_SERVER [ 'REQUEST_TIME' ]);
2021-01-25 07:57:24 -08:00
/*
$zonelist = DateTimeZone :: listIdentifiers (
DateTimeZone :: AFRICA |
DateTimeZone :: AMERICA |
DateTimeZone :: ANTARCTICA |
DateTimeZone :: ASIA |
DateTimeZone :: ATLANTIC |
DateTimeZone :: AUSTRALIA |
DateTimeZone :: EUROPE |
DateTimeZone :: INDIAN |
DateTimeZone :: PACIFIC |
DateTimeZone :: UTC
); */
2016-12-13 20:48:45 +01:00
foreach ( $zonelist as $zone )
{
// Because many time zones exist in PHP only for backward compatibility
// reasons and should not be used, the list is filtered by a regular
// expression.
if ( preg_match ( '!^((Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Europe|Indian|Pacific)/|UTC$)!' , $zone ))
{
$dateTimeZone = new DateTimeZone ( $zone );
$dateTime = new DateTime ( $timeNow , $dateTimeZone );
$offset = $dateTime -> format ( 'O' );
$offset = chunk_split ( $offset , 3 , ':' );
$zones [ $zone ] = str_replace ( '_' , ' ' , $zone ) . ' (' . rtrim ( $offset , ':' ) . ')' ;
}
}
2006-12-02 04:36:16 +00:00
2016-12-13 20:48:45 +01:00
// Sort time zones alphabetically.
asort ( $zones );
}
2014-01-17 07:20:11 -08:00
2016-12-13 20:48:45 +01:00
return $zones ;
}
/**
* Validate a timezone .
*
* @ param string $zone
* Timezone .
*
* @ return bool
*/
function systemTimeZoneIsValid ( $zone = '' )
{
$zones = systemTimeZones ();
2021-01-25 07:57:24 -08:00
2016-12-13 20:48:45 +01:00
$zoneKeys = array_keys ( $zones );
2020-12-10 15:52:48 -08:00
if ( in_array ( $zone , $zoneKeys , true ))
2016-12-13 20:48:45 +01:00
{
return true ;
}
return false ;
}
2016-12-13 21:31:59 +01:00
$e_deltaTime = 0 ;
2006-12-02 04:36:16 +00:00
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
2020-12-10 15:52:48 -08:00
$e_deltaTime = ( 15 * floor ((( int ) $_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.
2020-12-10 15:52:48 -08:00
$e_deltaTime += ( - (( int ) $_COOKIE [ 'e107_tzOffset' ] * 60 + date ( 'Z' )));
2006-12-02 04:36:16 +00:00
}
2008-11-27 02:18:25 +00:00
define ( 'TIMEOFFSET' , $e_deltaTime );
2006-12-02 04:36:16 +00:00
2016-12-13 21:31:59 +01:00
/**
* @ } End of " addtogroup timezone " .
*/
2014-01-17 07:20:11 -08:00
2009-07-07 16:04:51 +00:00
// ----------------------------------------------------------------------------
2009-07-12 14:44:57 +00:00
2021-01-05 08:54:09 -08:00
if ( e_ADMIN_AREA && ! isset ( $_E107 [ 'no_lan' ])) // Load admin phrases ASAP
2020-01-19 12:06:06 -08:00
{
e107 :: includeLan ( e_LANGUAGEDIR . e_LANGUAGE . '/admin/lan_admin.php' );
}
2021-01-05 08:54:09 -08:00
if ( ! defined ( 'THEME' ) && ! isset ( $_E107 [ 'no_theme' ]))
2009-07-12 14:44:57 +00:00
{
2021-01-05 08:54:09 -08:00
$dbg -> logTime ( 'Find/Load Theme' );
2010-02-10 21:53:56 +00:00
2015-02-14 23:34:15 -08:00
if ( e_ADMIN_AREA && vartrue ( $pref [ 'admintheme' ]))
2009-07-12 14:44:57 +00:00
{
2020-12-21 17:46:32 -08:00
e_theme :: initTheme ( $pref [ 'admintheme' ]);
2009-07-12 14:44:57 +00:00
}
2021-01-01 14:05:51 -08:00
elseif ( deftrue ( 'USERTHEME' ) && e_ADMIN_AREA === false )
2009-07-12 14:44:57 +00:00
{
2020-12-21 17:46:32 -08:00
e_theme :: initTheme ( USERTHEME );
2009-07-12 14:44:57 +00:00
}
else
{
2020-12-21 17:46:32 -08:00
e_theme :: initTheme ( $pref [ 'sitetheme' ]);
2009-07-12 14:44:57 +00:00
}
}
$theme_pref = varset ( $pref [ 'sitetheme_pref' ]);
// --------------------------------------------------------------
2009-07-07 16:04:51 +00:00
2019-04-11 10:47:50 -07:00
// Load library dependencies.
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_theme' ]))
2019-04-11 10:47:50 -07:00
{
2021-01-05 08:54:09 -08:00
$dbg -> logTime ( 'Load Libraries' );
if ( deftrue ( 'e_ADMIN_AREA' ))
{
$clearThemeCache = ( deftrue ( 'e_ADMIN_HOME' , false ) || deftrue ( 'e_ADMIN_UPDATE' , false ));
e107 :: getTheme ( 'current' , $clearThemeCache ) -> loadLibrary ();
unset ( $clearThemeCache );
}
else
{
e107 :: getTheme ( 'current' ) -> loadLibrary ();
}
2019-04-11 10:47:50 -07:00
}
2020-12-12 11:38:31 -08:00
//echo "\nRun Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n";
2009-07-07 16:04:51 +00:00
// -----------------------------------------------------------------------
2021-02-13 18:55:44 -08:00
2009-07-06 05:59:42 +00:00
2008-01-06 22:16:37 +00:00
// here we USE the theme
2021-01-05 08:54:09 -08:00
if ( ! isset ( $_E107 [ 'no_theme' ]))
2008-01-06 22:16:37 +00:00
{
2021-01-05 08:54:09 -08:00
$dbg -> logTime ( " Load admin_/theme.php file " );
if ( e_ADMIN_AREA )
2009-08-19 14:39:57 +00:00
{
2021-01-05 08:54:09 -08:00
$dbg -> logTime ( 'Loading Admin Theme' );
if ( file_exists ( THEME . 'admin_theme.php' ) && ! deftrue ( 'e_MENUMANAGER_ACTIVE' )) // no admin theme when previewing.
{
require_once ( THEME . 'admin_theme.php' );
}
else
{
require_once ( THEME . 'theme.php' );
}
2009-08-19 14:39:57 +00:00
}
else
{
2021-01-05 08:54:09 -08:00
$dbg -> logTime ( 'Loading Site Theme' );
2009-08-19 14:39:57 +00:00
require_once ( THEME . 'theme.php' );
2021-01-05 08:54:09 -08:00
if ( isset ( $SC_WRAPPER ))
{
e107 :: scStyle ( $SC_WRAPPER );
}
2009-08-19 14:39:57 +00:00
}
2021-01-05 08:54:09 -08:00
$dbg -> logTime ( " Init Theme Class " );
2021-01-27 12:20:58 -08:00
e107 :: getRender () -> _init ( e_ADMIN_AREA ); // initialize theme class.
2021-01-05 08:54:09 -08:00
if ( $pref [ 'anon_post' ])
2016-02-26 12:50:48 -08:00
{
2021-01-05 08:54:09 -08:00
define ( 'ANON' , true );
}
else
{
define ( 'ANON' , false );
2016-02-26 12:50:48 -08:00
}
2008-05-29 21:12:55 +00:00
2021-01-05 08:54:09 -08:00
if ( empty ( $pref [ 'newsposts' ]))
{
define ( 'ITEMVIEW' , 15 );
}
else
{
define ( 'ITEMVIEW' , $pref [ 'newsposts' ]);
}
2006-12-02 04:36:16 +00:00
2021-01-05 08:54:09 -08:00
$layout = isset ( $layout ) ? $layout : '_default' ;
define ( 'HEADERF' , e_CORE . " templates/header { $layout } .php " );
define ( 'FOOTERF' , e_CORE . " 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__ );
}
2019-02-08 11:01:42 -08:00
}
2006-12-02 04:36:16 +00:00
2021-01-05 08:54:09 -08:00
2020-12-10 15:52:48 -08:00
if ( ! empty ( $pref [ 'antiflood1' ]) && ! defined ( 'FLOODPROTECT' ))
2007-09-18 21:15:41 +00:00
{
2020-12-21 17:46:32 -08:00
define ( 'FLOODPROTECT' , true );
2009-08-19 14:39:57 +00:00
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
*/
2020-12-21 17:46:32 -08:00
define ( 'FLOODPROTECT' , false );
2006-12-02 04:36:16 +00:00
}
2012-02-07 16:37:44 +00:00
//define('LOGINMESSAGE', ''); - not needed, breaks login messages
2008-11-27 02:18:25 +00:00
define ( 'OPEN_BASEDIR' , ( ini_get ( 'open_basedir' ) ? true : false ));
2020-12-10 18:02:28 -08:00
define ( 'SAFE_MODE' , false );
2008-11-27 02:18:25 +00:00
define ( 'FILE_UPLOADS' , ( ini_get ( 'file_uploads' ) ? true : false ));
define ( 'INIT' , true );
if ( isset ( $_SERVER [ 'HTTP_REFERER' ]))
{
2020-12-10 15:52:48 -08:00
$tmp = explode ( '?' , $_SERVER [ 'HTTP_REFERER' ]);
define ( 'e_REFERER_SELF' ,( $tmp [ 0 ] === e_REQUEST_SELF ));
2011-12-06 09:44:28 +00:00
unset ( $tmp );
2008-11-27 02:18:25 +00:00
}
else
{
2009-12-13 21:52:32 +00:00
/**
* @ ignore
*/
2020-12-21 17:46:32 -08:00
define ( 'e_REFERER_SELF' , false );
2006-12-02 04:36:16 +00:00
}
2020-12-21 17:46:32 -08:00
/**
* @ deprecated Use e107 :: getRedirect () -> go ( $url ) instead .
* @ param $qry
*/
2008-11-27 02:18:25 +00:00
function js_location ( $qry )
{
2020-12-21 17:46:32 -08:00
trigger_error ( '<b>js_location() is deprecated.</b> e107::getRedirect()->go($url) instead.' , E_USER_DEPRECATED ); // NO LAN
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
}
2020-12-10 15:52:48 -08:00
echo " <script type='text/javascript'>document.location.href=' { $qry } '</script> \n " ;
exit ;
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 )
2015-08-25 13:00:53 -07:00
{
if ( empty ( $email ))
{
return false ;
}
if ( is_numeric ( substr ( $email , - 1 ))) // fix for eCaptcha accidently typed on wrong line.
{
return false ;
}
2014-05-22 18:16:44 -07:00
if ( filter_var ( $email , FILTER_VALIDATE_EMAIL ))
{
return $email ;
}
return false ;
// 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
//---------------------------------------------------------------------------------------------------------------------------------------------
2019-02-08 11:01:42 -08:00
/**
* @ param mixed $var is a single class number or name , or a comma - separated list of the same .
* @ param mixed $userclass a custom list of userclasses or leave blank for the current user ' s permissions .
2020-12-21 17:46:32 -08:00
* 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 .
2019-02-08 11:01:42 -08:00
* @ param int $uid
* @ return bool
*/
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 ();
2020-12-10 18:02:28 -08:00
if ( $var === e_LANGUAGE )
2009-08-05 19:58:32 +00:00
{
2020-12-10 18:02:28 -08:00
return true ;
2009-08-05 19:58:32 +00:00
}
2007-12-15 09:55:37 +00:00
2020-12-10 18:02:28 -08:00
if ( e107 :: isCli ())
2015-04-16 15:23:57 -07:00
{
2019-03-08 12:10:28 -08:00
global $_E107 ;
2020-12-10 18:02:28 -08:00
if ( empty ( $_E107 [ 'phpunit' ]))
2019-03-08 12:10:28 -08:00
{
return true ;
}
2015-04-16 15:23:57 -07:00
}
2020-12-10 18:02:28 -08:00
if ( is_numeric ( $uid ) && $uid > 0 )
{ // 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
}
2020-12-10 18:02:28 -08:00
if ( $userclass == '' )
2006-12-02 04:36:16 +00:00
{
2020-12-10 18:02:28 -08: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 ;
2020-12-10 18:02:28 -08:00
$latchedAccess = false ;
2008-11-25 16:26:03 +00:00
2020-12-10 18:02:28 -08:00
foreach ( $varList as $v )
2007-01-12 02:36:18 +00:00
{
2009-08-08 23:09:08 +00:00
$v = trim ( $v );
2020-12-10 18:02:28 -08: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
2020-12-10 18:02:28 -08:00
if ( ! is_numeric ( $v ))
2006-12-02 04:36:16 +00:00
{
2020-12-10 18:02:28 -08:00
if ( $v === '' )
{
return false ;
}
if ( $v [ 0 ] === '-' )
2009-08-03 19:51:24 +00:00
{
2020-12-21 17:46:32 -08: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
{
2020-12-10 18:02:28 -08:00
$invert = true ;
2009-08-03 19:51:24 +00:00
$v = - $v ;
}
2020-12-21 17:46:32 -08:00
if ( $v !== false )
2009-08-08 23:09:08 +00:00
{
2020-12-10 18:02:28 -08:00
// var_dump($v);
2009-08-08 23:09:08 +00:00
// Ignore non-valid userclass names
2020-12-10 18:02:28 -08:00
if (( $v === '0' ) || ( $v === 0 ) || in_array ( $v , $class_array ))
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
{
2020-12-10 18:02:28 -08:00
return false ;
2006-12-02 04:36:16 +00:00
}
2020-12-21 17:46:32 -08:00
$latchedAccess = true ;
2007-01-12 02:36:18 +00:00
}
2020-12-10 18:02:28 -08: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
2020-12-10 18:02:28 -08:00
$latchedAccess = true ;
2006-12-02 04:36:16 +00:00
}
}
}
2020-12-10 18:02:28 -08: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
2019-02-08 11:01:42 -08:00
/**
* @ param $arg
* @ param bool | mixed | string $ap
* @ return bool
*/
2021-01-22 17:09:55 -08:00
function getperms ( $arg , $ap = ADMINPERMS , $path = e_SELF )
2008-11-27 02:18:25 +00:00
{
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 ) === '' )
{
2019-02-08 11:01:42 -08:00
return false ;
2011-05-11 11:52:50 +00:00
}
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
{
2019-02-08 11:01:42 -08:00
return true ;
2006-12-02 04:36:16 +00:00
}
2009-09-12 16:42:44 +00:00
2021-01-22 17:09:55 -08:00
if ( $arg === 'P' && preg_match ( '#(.*?)/' . e107 :: getInstance () -> getFolder ( 'plugins' ) . '(.*?)/(.*?)#' , $path , $matches ))
2008-11-27 02:18:25 +00:00
{
2009-12-24 10:51:23 +00:00
$sql = e107 :: getDb ( 'psql' );
2021-01-22 17:09:55 -08:00
/* $id = e107 :: getPlug () -> load ( $matches [ 2 ]) -> getId ();
$arg = 'P' . $id ; */
2010-02-10 21:53:56 +00:00
2016-02-15 00:56:08 -08:00
if ( $sql -> select ( 'plugin' , 'plugin_id' , " plugin_path = ' " . $matches [ 2 ] . " ' LIMIT 1 " ))
2008-11-27 02:18:25 +00:00
{
2016-02-15 00:56:08 -08:00
$row = $sql -> 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
2020-12-21 17:46:32 -08:00
if ( in_array ( $arg , $ap_array , false ))
2008-11-27 02:18:25 +00:00
{
2019-02-08 11:01:42 -08:00
return true ;
2008-11-27 02:18:25 +00:00
}
2020-12-10 15:52:48 -08:00
if ( strpos ( $arg , " | " ))
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
{
2019-02-08 11:01:42 -08:00
return true ;
2009-08-05 14:18:09 +00:00
}
}
}
2020-04-26 13:32:18 -07:00
return false ;
2006-12-02 04:36:16 +00:00
}
/**
2015-02-15 16:07:27 -08:00
* @ deprecated
2006-12-02 04:36:16 +00:00
* Get the user data from user and user_extended tables
2013-03-31 04:23:11 -07:00
* SO MUCH DEPRECATED ! Use e107 :: user ( $uid );
2019-02-08 11:01:42 -08:00
* @ param int $uid
* @ param string $extra
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
{
2020-12-21 10:00:28 -08:00
trigger_error ( '<b>get_user_data() is deprecated.</b> Use e107::user($uid) instead.' , E_USER_DEPRECATED ); // NO LAN
2010-05-17 15:51:42 +00:00
if ( e107 :: getPref ( 'developer' ))
{
2020-12-21 10:00:28 -08:00
e107 :: getLog () -> add (
2010-05-17 15:51:42 +00:00
'Deprecated call - get_user_data()' ,
2015-01-26 18:03:14 -08:00
'Call to deprecated function get_user_data() (class2.php) ' . " \n " . print_r ( debug_backtrace ( null , 2 ), true ),
2010-05-17 15:51:42 +00:00
E_LOG_INFORMATIVE ,
'DEPRECATED'
);
// TODO - debug screen Deprecated Functions (e107)
2015-01-26 18:03:14 -08:00
e107 :: getMessage () -> addDebug ( 'Deprecated get_user_data() backtrace:<pre>' . " \n " . print_r ( debug_backtrace ( null , 2 ), true ) . '</pre>' );
2010-05-17 15:51:42 +00:00
}
2019-02-26 15:54:51 -08:00
unset ( $extra );
2010-05-17 15:51:42 +00:00
$var = array ();
2020-12-08 07:29:17 -08:00
$user = e107 :: getSystemUser ( $uid );
2010-05-17 15:51:42 +00:00
if ( $user )
{
$var = $user -> getUserData ();
}
return $var ;
2006-12-02 04:36:16 +00:00
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
2014-01-10 07:36:54 -08:00
//SO MUCH DEPRECATED
/**
2020-12-18 09:39:02 -08:00
* @ deprecated Use instead : e107 :: getConfig ( alias ) ->-> setPref ( $array ) -> save ();
2014-01-10 07:36:54 -08:00
* @ example Use instead : e107 :: getConfig ( alias ) ->-> setPref ( $array ) -> save (); Not to be used for saving plugin or theme prefs !
2019-02-08 11:01:42 -08:00
* @ param string $table
* @ param int | mixed $uid
* @ param string $row_val
* @ return bool | int | string
2014-01-10 07:36:54 -08:00
*/
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
{
2020-12-21 10:00:28 -08:00
trigger_error ( '<b>save_prefs() is deprecated.</b> Use e107::getConfig(table)->->setPref($array)->save() instead.' , E_USER_DEPRECATED ); // NO LAN
2010-03-14 02:11:23 +00:00
global $pref , $user_pref , $tp , $PrefCache , $sql , $eArrayStorage , $theme_pref ;
2020-04-26 13:32:18 -07:00
unset ( $row_val );
2009-08-28 15:21:23 +00:00
2010-05-17 15:51:42 +00:00
if ( e107 :: getPref ( 'developer' ))
{
2014-01-10 07:36:54 -08:00
$backtrace = debug_backtrace ( false );
2020-12-21 10:00:28 -08:00
e107 :: getLog () -> add (
2010-05-17 15:51:42 +00:00
'Deprecated call - save_prefs()' ,
2014-01-10 07:36:54 -08:00
" Call to deprecated function save_prefs() (class2.php). Backtrace: \n " . print_r ( $backtrace , true ),
2010-05-17 15:51:42 +00:00
E_LOG_INFORMATIVE ,
'DEPRECATED'
);
2014-01-10 07:36:54 -08:00
e107 :: getMessage () -> addDebug ( 'Deprecated save_prefs() backtrace:<pre>' . " \n " . print_r ( $backtrace , true ) . '</pre>' );
2010-05-17 15:51:42 +00:00
}
2017-01-18 19:56:27 -08:00
2009-08-17 14:40:23 +00:00
switch ( $table )
{
case 'core' :
//brute load, force update
2017-01-18 19:56:27 -08:00
if ( count ( $pref ) < 100 ) // precaution for old plugins
{
$backtrace = debug_backtrace ( false );
2020-12-21 10:00:28 -08:00
e107 :: getLog () -> add (
2017-01-18 19:56:27 -08:00
'Core pref corruption avoided' ,
" Call to deprecated function save_prefs() (class2.php) with too few prefs. Backtrace: \n " . print_r ( $backtrace , true ),
E_LOG_INFORMATIVE ,
'DEPRECATED'
);
e107 :: getMessage () -> addDebug ( 'Core-pref corruption avoided. Too few prefs sent to save_prefs(). Backtrace:<pre>' . " \n " . print_r ( $backtrace , true ) . '</pre>' );
return false ;
}
2009-08-17 14:40:23 +00:00
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' );
2020-12-21 10:00:28 -08:00
$tmp = e107 :: serialize ( $_user_pref );
2020-12-10 15:52:48 -08:00
$sql -> update ( 'user' , " user_prefs=' $tmp ' WHERE user_id= " . ( int ) $uid );
2009-08-17 14:40:23 +00:00
return $tmp ;
break ;
}
2020-04-26 13:32:18 -07:00
2020-12-08 12:21:12 -08:00
2006-12-02 04:36:16 +00:00
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
2015-02-15 16:07:27 -08:00
/**
* @ deprecated use e107 :: setRegistry ()
* @ param $id
* @ param $var
*/
2008-11-27 02:18:25 +00:00
function cachevars ( $id , $var )
{
2020-12-21 10:00:28 -08:00
trigger_error ( '<b>cachevars() is deprecated.</b> Use e107::setRegistry() instead.' , E_USER_DEPRECATED ); // NO LAN
2009-07-22 00:49:35 +00:00
e107 :: setRegistry ( 'core/cachedvars/' . $id , $var );
2006-12-02 04:36:16 +00:00
}
2015-02-15 16:07:27 -08:00
/**
* @ deprecated use e107 :: getRegistry ()
* @ param $id
* @ return mixed
*/
2008-11-27 02:18:25 +00:00
function getcachedvars ( $id )
{
2020-12-21 10:00:28 -08:00
trigger_error ( '<b>getcachedvars() is deprecated.</b> Use e107::getRegistry() instead.' , E_USER_DEPRECATED ); // NO LAN
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
*/
2020-04-26 13:32:18 -07:00
$sql = e107 :: getDb ( 'flood' );
2006-12-02 04:36:16 +00:00
2020-12-10 15:52:48 -08:00
if ( FLOODPROTECT === true )
2008-11-27 02:18:25 +00:00
{
2016-02-15 00:56:08 -08:00
$sql -> select ( $table , '*' , 'ORDER BY ' . $orderfield . ' DESC LIMIT 1' , 'no_where' );
$row = $sql -> fetch ();
2020-12-10 15:52:48 -08:00
return ( $row [ $orderfield ] <= ( time () - FLOODTIMEOUT ));
2006-12-02 04:36:16 +00:00
}
2020-12-10 15:52:48 -08:00
2020-12-21 17:46:32 -08:00
return true ;
2006-12-02 04:36:16 +00:00
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
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
*/
2012-06-14 04:13:16 +00:00
// ----------------------------------------
2010-02-10 21:53:56 +00:00
2017-12-09 23:30:20 +01:00
// Set 'UTC' as default timezone to avoid PHP warnings.
date_default_timezone_set ( 'UTC' );
2010-02-10 21:53:56 +00:00
2020-12-28 12:50:44 -08:00
global $user_pref , $currentUser , $_E107 ;
2010-02-10 21:53:56 +00:00
2021-01-24 17:16:49 -08:00
e107 :: getDebug () -> logTime ( '[init_session: getInstance]' );
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
2021-01-24 17:16:49 -08:00
e107 :: getDebug () -> logTime ( '[init_session: getUser]' );
2010-05-14 18:45:51 +00:00
$user = e107 :: getUser ();
2006-12-02 04:36:16 +00:00
2016-12-13 21:31:59 +01:00
// Get user timezone.
2021-01-24 17:16:49 -08:00
e107 :: getDebug () -> logTime ( '[init_session: getTimezone]' );
2016-12-13 21:31:59 +01:00
$tzUser = $user -> getTimezone ();
// If user timezone is valid.
2021-01-24 17:16:49 -08:00
e107 :: getDebug () -> logTime ( '[init_session: systemTimeZoneIsValid]' );
2016-12-13 21:31:59 +01:00
if ( varset ( $tzUser , false ) && systemTimeZoneIsValid ( $tzUser ))
{
// Sets the default timezone used by all date/time functions.
date_default_timezone_set ( $tzUser );
// Save timezone for later use.
define ( 'USERTIMEZONE' , $tzUser );
unset ( $tzUser );
}
else
{
// Use system default timezone.
$pref = e107 :: getPref ();
$tz = vartrue ( $pref [ 'timezone' ], 'UTC' );
// Sets the default timezone used by all date/time functions.
date_default_timezone_set ( $tz );
// Save timezone for later use.
define ( 'USERTIMEZONE' , $tz );
unset ( $tz );
}
2021-01-24 17:16:49 -08:00
e107 :: getDebug () -> log ( " Timezone: " . USERTIMEZONE ); // remove later on.
2018-05-24 15:16:02 -07:00
2021-01-24 17:16:49 -08:00
e107 :: getDebug () -> logTime ( '[init_session: getIP]' );
2020-12-08 07:29:17 -08:00
define ( 'USERIP' , e107 :: getIPHandler () -> getIP ());
2021-01-24 17:16:49 -08:00
e107 :: getDebug () -> logTime ( '[init_session: getToken]' );
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' );
2021-01-11 18:05:29 -08:00
define ( 'ADMINNAME' , 'e107-cli' );
2009-12-24 09:59:21 +00:00
define ( 'USERTHEME' , false );
define ( 'ADMIN' , true );
2020-03-23 17:04:44 -05:00
define ( 'ADMINPERMS' , '0' );
2009-12-24 09:59:21 +00:00
define ( 'GUEST' , false );
define ( 'USERCLASS' , '' );
define ( 'USEREMAIL' , '' );
2018-07-19 20:49:16 -07:00
define ( 'USERCLASS_LIST' , '253,254,250,251,0' ); // needed to run some queries.
2012-07-21 03:55:04 +00:00
define ( 'USERJOINED' , '' );
2021-01-06 11:54:51 -08:00
define ( 'e_CLASS_REGEXP' , '(^|,)(253|254|250|251|0)(,|$)' );
define ( 'e_NOBODY_REGEXP' , '(^|,)255(,|$)' );
2009-12-24 09:59:21 +00:00
return ;
2008-01-22 00:39:08 +00:00
}
2021-01-24 17:16:49 -08:00
e107 :: getDebug () -> logTime ( '[init_session: hasBan]' );
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 ;
}
2021-01-24 17:16:49 -08:00
e107 :: getDebug () -> logTime ( '[init_session: Constants]' );
2020-12-05 00:54:13 +01:00
define ( 'ADMIN' , $user -> isAdmin ());
define ( 'ADMINID' , $user -> getAdminId ());
define ( 'ADMINNAME' , $user -> getAdminName ());
define ( 'ADMINPERMS' , $user -> getAdminPerms ());
define ( 'ADMINEMAIL' , $user -> getAdminEmail ());
define ( 'ADMINPWCHANGE' , $user -> getAdminPwchange ());
2021-01-24 17:16:49 -08:00
e107 :: getDebug () -> logTime ( '[init_session: isUser]' );
2010-05-14 18:45:51 +00:00
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 ( 'GUEST' , true );
2006-12-02 04:36:16 +00:00
define ( 'USERCLASS' , '' );
define ( 'USEREMAIL' , '' );
2013-03-19 19:04:32 -07:00
define ( 'USERSIGNATURE' , '' );
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' ));
2012-07-21 03:55:04 +00:00
define ( 'USERURL' , $user -> get ( 'user_homepage' , false )); //required for BC
2010-05-14 18:45:51 +00:00
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' ));
2012-07-21 03:55:04 +00:00
define ( 'USERJOINED' , $user -> get ( 'user_join' ));
2017-01-13 12:22:47 -08:00
define ( 'USERCURRENTVISIT' , $user -> get ( 'user_currentvisit' ));
2012-07-21 03:55:04 +00:00
define ( 'USERVISITS' , $user -> get ( 'user_visits' ));
2013-03-19 19:04:32 -07:00
define ( 'USERSIGNATURE' , $user -> get ( 'user_signature' ));
2010-05-14 18:45:51 +00:00
2020-12-28 12:50:44 -08:00
if ( ADMIN && empty ( $_E107 [ 'no_online' ]) && empty ( $_E107 [ 'no_forceuserupdate' ])) // XXX - why for admins only?
2010-05-14 18:45:51 +00:00
{
e107 :: getRedirect () -> setPreviousUrl ();
}
2020-12-28 12:50:44 -08:00
2010-05-14 18:45:51 +00:00
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 ();
2020-12-10 15:52:48 -08:00
if ( e107 :: getPref ( 'sitetheme' ) !== $_POST [ 'sitetheme' ])
2010-05-14 18:45:51 +00:00
{
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 );
}
2016-09-12 10:09:33 -07:00
2010-05-14 18:45:51 +00:00
}
elseif ( $user -> getPref ( 'sitetheme' ))
{
$user -> getConfig ()
-> remove ( 'sitetheme' )
-> remove ( 'sitetheme_custompages' )
-> remove ( 'sitetheme_deflayout' )
2019-02-08 11:01:42 -08:00
-> save ();
2010-05-14 18:45:51 +00:00
}
2016-09-12 10:09:33 -07:00
2010-05-14 18:45:51 +00:00
$user_pref = $user -> getPref ();
}
2021-01-24 17:16:49 -08:00
e107 :: getDebug () -> logTime ( '[init_session: getClassList]' );
2010-05-14 18:45:51 +00:00
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 . '(,|$)' );
2006-12-02 04:36:16 +00:00
}
2008-06-13 20:20:23 +00:00
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( 'Go online' );
2020-05-23 15:49:40 +02:00
if ( ! isset ( $_E107 [ 'no_online' ]))
2008-01-06 22:16:37 +00:00
{
2020-05-23 15:49:40 +02:00
e107 :: getOnline () -> goOnline ( $pref [ 'track_online' ], $pref [ 'antiflood1' ]);
2006-12-02 04:36:16 +00:00
}
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( '(After Go online)' );
2021-01-19 13:31:20 -08:00
$dbg -> logTime ( 'Frontpage detection' );
$fpUrl = str_replace ( SITEURL , '' , rtrim ( e_REQUEST_URL , '?/' ));
$fpPref = e107 :: getFrontpage ();
if ( $fpUrl === $fpPref )
{
e107 :: canonical ( '_SITEURL_' );
}
unset ( $fpUrl , $fpPref );
2021-02-21 14:10:47 -08:00
$dbg -> logTime ( 'Legacy Route detection' );
// Reverse lookup of current URI against legacy e_url entry to determine route.
if ( ! deftrue ( 'e_SINGLE_ENTRY' ) && deftrue ( 'e_CURRENT_PLUGIN' ))
{
if ( $route = e107 :: detectRoute ( e_CURRENT_PLUGIN , e_REQUEST_URI ))
{
e107 :: route ( $route );
}
unset ( $route );
}
2021-01-19 13:31:20 -08:00
2018-01-13 14:11:46 -08:00
2010-10-26 07:41:20 +00:00
/**
* Set Cookie
2019-02-08 11:01:42 -08:00
*
* @ param string $name
* @ param string $value
2010-10-26 07:41:20 +00:00
* @ param integer $expire seconds
2019-02-08 11:01:42 -08:00
* @ param string $path
* @ param string $domain
* @ param int $secure
2010-10-26 07:41:20 +00:00
* @ 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
{
2021-01-18 07:40:17 -08:00
global $_E107 ;
if ( ! empty ( $_E107 [ 'cli' ]))
{
return null ;
}
2021-01-21 08:06:20 -08:00
/*
2020-12-21 17:46:32 -08:00
if ( ! e_SUBDOMAIN || ( defined ( 'MULTILANG_SUBDOMAIN' ) && MULTILANG_SUBDOMAIN === true ))
2013-05-26 13:46:31 -07:00
{
2020-12-10 15:52:48 -08:00
$domain = ( e_DOMAIN !== false ) ? " . " . e_DOMAIN : " " ;
2021-01-21 08:06:20 -08:00
}
*/
if (( empty ( $domain ) && ! e_SUBDOMAIN ) || ( defined ( 'MULTILANG_SUBDOMAIN' ) && MULTILANG_SUBDOMAIN === true ))
{
$domain = ( e_DOMAIN !== false ) ? " . " . e_DOMAIN : '' ;
}
if ( defined ( 'e_MULTISITE_MATCH' ) && deftrue ( 'e_ADMIN_AREA' ))
{
$path = '/' ;
}
2013-05-26 13:46:31 -07:00
2016-08-19 16:13:38 -07:00
setcookie ( $name , $value , $expire , $path , $domain , $secure , true );
2006-12-02 04:36:16 +00:00
}
2021-01-21 08:06:20 -08:00
//
/**
*
* generic function for retaining values across pages . ie . cookies or sessions .
* @ deprecated Use e107 :: getUserSession () -> makeUserCookie ( $userData , $autologin ); instead .
* @ param $name
* @ param $value
* @ param string $expire
* @ param string $path
* @ param string $domain
* @ param int $secure
*/
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
{
2021-01-21 08:06:20 -08:00
//$userData = ['user_name
// e107::getUserSession()->makeUserCookie($userData, $autologin);
2008-05-19 09:42:28 +00:00
global $pref ;
2020-12-10 15:52:48 -08:00
if ( $pref [ 'user_tracking' ] === 'session' )
2008-05-19 09:42:28 +00:00
{
$_SESSION [ $name ] = $value ;
}
else
{
2020-12-21 17:46:32 -08:00
if (( empty ( $domain ) && ! e_SUBDOMAIN ) || ( defined ( 'MULTILANG_SUBDOMAIN' ) && MULTILANG_SUBDOMAIN === true ))
2013-07-24 08:42:25 -07:00
{
2020-12-21 17:46:32 -08:00
$domain = ( e_DOMAIN !== false ) ? " . " . e_DOMAIN : " " ;
2017-10-11 18:57:32 -07:00
}
if ( defined ( 'e_MULTISITE_MATCH' ))
{
$path = '/' ;
}
2013-07-24 08:42:25 -07:00
2016-08-19 16:13:38 -07:00
setcookie ( $name , $value , $expire , $path , $domain , $secure , true );
2008-05-19 09:42:28 +00:00
$_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
{
2015-05-16 19:06:13 -07:00
if ( ! defined ( 'e_HANDLER' ))
2014-07-03 19:45:50 -07:00
{
2015-05-16 19:06:13 -07:00
echo $message ;
2014-07-03 19:45:50 -07:00
return ;
}
2016-03-14 19:17:37 -07:00
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 );
}
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
{
2015-01-26 18:03:14 -08:00
if ( $ud = e107 :: user ( $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
/**
2020-12-21 10:00:28 -08:00
* @ deprecated by e107 :: lan ();
2009-11-17 09:37:22 +00:00
* @ param string $path
* @ param boolean $force [ optional ] Please use the default
2019-02-08 11:01:42 -08:00
* @ return bool
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
{
2020-12-21 10:00:28 -08:00
trigger_error ( '<b>include_lan() is deprecated.</b> Use e107::lan() instead.' , E_USER_DEPRECATED ); // NO LAN
2009-09-19 15:27:26 +00:00
return e107 :: includeLan ( $path , $force );
2006-12-02 04:36:16 +00:00
}
2020-12-21 10:00:28 -08:00
2008-12-07 21:41:04 +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
2020-12-21 17:46:32 -08:00
* @ return boolean true if update required
2009-12-07 20:47:37 +00:00
*/
function force_userupdate ( $currentUser )
2007-08-12 21:40:49 +00:00
{
2020-12-21 17:46:32 -08:00
if ( e_PAGE == 'usersettings.php' || ( defined ( 'FORCE_USERUPDATE' ) && ( FORCE_USERUPDATE == false )) || strpos ( e_SELF , ADMINDIR ) == true )
2006-12-02 04:36:16 +00:00
{
2020-12-21 17:46:32 -08:00
return false ;
2006-12-02 04:36:16 +00:00
}
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 )
{
2020-12-10 15:52:48 -08:00
if ( ! $currentUser [ 'user_' . $value ] && e107 :: getPref ( 'signup_option_' . $value , 0 ) == 2 )
2006-12-02 04:36:16 +00:00
{
2020-12-10 15:52:48 -08:00
return true ;
2006-12-02 04:36:16 +00:00
}
}
2020-12-21 17:46:32 -08:00
if ( ! e107 :: getPref ( 'disable_emailcheck' , true ) && ! trim ( $currentUser [ 'user_email' ])) return true ;
2007-08-12 21:40:49 +00:00
2016-02-15 00:56:08 -08:00
if ( e107 :: getDb () -> 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
{
2016-02-15 00:56:08 -08:00
while ( $row = e107 :: getDb () -> 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' ] } " ;
2012-01-14 23:01:21 +00:00
if ( ! isset ( $currentUser [ $user_extended_struct_name ]))
{
2020-12-21 17:46:32 -08:00
//e107::admin_log->addEvent(4, __FILE__."|".__FUNCTION__."@".__LINE__, 'FORCE', 'Force User update', 'Trigger field: '.$user_extended_struct_name, false, LOG_TO_ROLLING);
return true ;
2012-01-14 23:01:21 +00:00
}
if (( $row [ 'user_extended_struct_type' ] == 7 ) && ( $currentUser [ $user_extended_struct_name ] == '0000-00-00' ))
2009-12-07 20:47:37 +00:00
{
2020-12-21 17:46:32 -08:00
//e107::admin_log->addEvent(4, __FILE__."|".__FUNCTION__."@".__LINE__, 'FORCE', 'Force User update', 'Trigger field: '.$user_extended_struct_name, false, LOG_TO_ROLLING);
return true ;
2009-12-07 20:47:37 +00:00
}
2006-12-02 04:36:16 +00:00
}
}
2020-12-21 17:46:32 -08:00
return false ;
2006-12-02 04:36:16 +00:00
}
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
2020-01-18 18:57:43 +01:00
public $errors = [];
public $debug = false ;
2016-02-12 12:58:44 -08:00
protected $xdebug = false ;
protected $docroot = '' ;
protected $label = array ();
2019-02-08 11:01:42 -08:00
protected $color = null ;
2006-12-02 04:36:16 +00:00
2016-02-12 12:58:44 -08:00
function __construct ()
2008-11-27 02:18:25 +00:00
{
2016-02-12 12:58:44 -08:00
$this -> label = array ( E_NOTICE => " Notice " , E_WARNING => " Warning " , E_DEPRECATED => " Deprecated " , E_STRICT => " Strict " );
$this -> color = array ( E_NOTICE => 'info' , E_WARNING => 'warning' , E_DEPRECATED => 'danger' , E_STRICT => 'primary' );
2018-02-04 18:42:39 -08:00
$this -> docroot = e_ROOT ; // dirname(realpath(__FILE__)).DIRECTORY_SEPARATOR;
2016-02-12 12:58:44 -08:00
2006-12-05 09:33:20 +00:00
// This is initialized before the current debug level is known
2016-02-12 12:58:44 -08:00
if ( function_exists ( 'xdebug_get_function_stack' ))
{
$this -> xdebug = true ;
}
2006-12-05 09:33:20 +00:00
//
2008-12-22 03:15:04 +00:00
global $_E107 ;
2016-12-22 10:29:34 -08:00
if ( ! empty ( $_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
}
2016-12-22 10:29:34 -08:00
if ( ! empty ( $_E107 [ 'cli' ]))
2008-01-21 03:54:10 +00:00
{
2016-12-22 11:36:13 -08:00
error_reporting ( E_ALL & ~ E_STRICT & ~ E_NOTICE );
2008-01-21 03:54:10 +00:00
return ;
}
2020-12-10 15:52:48 -08:00
if (( isset ( $_SERVER [ 'QUERY_STRING' ]) && ( strpos ( $_SERVER [ 'QUERY_STRING' ], 'debug=' ) !== false )) || isset ( $_COOKIE [ 'e107_debug_level' ]) && (( strpos ( $_SERVER [ 'QUERY_STRING' ], 'debug=-' )) === false ) )
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 );
}
2020-01-17 14:48:55 +01:00
set_error_handler ( array ( & $this , 'handle_error' ));
2006-12-02 04:36:16 +00:00
}
2019-05-25 11:53:29 -07:00
/**
* Deftrue function independent of core function .
* @ param $value
* @ return bool
*/
private function deftrue ( $value )
{
2020-12-10 15:52:48 -08:00
return defined ( $value ) && constant ( $value );
}
private function addError ( $type , $message , $line , $file )
{
$error = [];
$error [ 'short' ] = " <span class='label label- " . $this -> color [ $type ] . " '> " . $this -> label [ $type ] . " </span> { $message } , Line <mark> { $line } </mark> of { $file } <br /> \n " ;
if ( $this -> xdebug )
2019-05-25 11:53:29 -07:00
{
2020-12-10 15:52:48 -08:00
$backtrace = xdebug_get_function_stack ();
}
else
{
$trace = debug_backtrace ();
$backtrace [ 0 ] = ( isset ( $trace [ 1 ]) ? $trace [ 1 ] : " " );
$backtrace [ 1 ] = ( isset ( $trace [ 2 ]) ? $trace [ 2 ] : " " );
2019-05-25 11:53:29 -07:00
}
2020-12-10 15:52:48 -08:00
$error [ 'trace' ] = $backtrace ;
$this -> errors [] = $error ;
2019-05-25 11:53:29 -07:00
}
2019-02-08 11:01:42 -08:00
/**
* @ param $type
* @ param $message
* @ param $file
* @ param $line
2020-11-27 17:00:32 +01:00
* @ param $context ( deprecated since PHP 7.2 . 0 )
2019-02-08 11:01:42 -08:00
* @ return bool
*/
2020-11-27 17:00:32 +01:00
function handle_error ( $type , $message , $file , $line , $context = null ) {
2006-12-05 09:33:20 +00:00
$startup_error = ( ! defined ( 'E107_DEBUG_LEVEL' )); // Error before debug system initialized
2016-02-12 12:58:44 -08:00
2020-12-21 10:00:28 -08:00
switch ( $type )
{
case E_USER_DEPRECATED :
if ( $this -> deftrue ( 'E107_DBG_DEPRECATED' ))
{
$trace = debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS , 3 );
e107 :: getDebug () -> logDeprecated ( $message , varset ( $trace [ 2 ][ 'file' ]), varset ( $trace [ 2 ][ 'line' ]));
}
break ;
2016-02-12 12:58:44 -08:00
2006-12-02 04:36:16 +00:00
case E_NOTICE :
2016-02-12 12:58:44 -08:00
// case E_STRICT:
2019-05-25 11:53:29 -07:00
if ( $startup_error || $this -> deftrue ( 'E107_DBG_ALLERRORS' ) || $this -> deftrue ( 'E107_DBG_ERRBACKTRACE' ))
2008-11-27 02:18:25 +00:00
{
2020-12-10 15:52:48 -08:00
$this -> addError ( $type , $message , $line , $file );
2006-12-02 04:36:16 +00:00
}
break ;
case E_WARNING :
2019-05-25 11:53:29 -07:00
if ( $startup_error || $this -> deftrue ( 'E107_DBG_BASIC' ) || $this -> deftrue ( 'E107_DBG_ERRBACKTRACE' ))
2008-11-27 02:18:25 +00:00
{
2020-12-10 15:52:48 -08:00
$this -> addError ( $type , $message , $line , $file );
2006-12-02 04:36:16 +00:00
}
break ;
case E_USER_ERROR :
2008-11-27 02:18:25 +00:00
if ( $this -> debug == true )
{
2016-02-12 19:28:35 -08:00
$error [ 'short' ] = " Internal Error Message: { $message } , Line <mark> { $line } </mark> of { $file } <br /> \n " ;
2006-12-02 04:36:16 +00:00
$trace = debug_backtrace ();
$backtrace [ 0 ] = ( isset ( $trace [ 1 ]) ? $trace [ 1 ] : " " );
$backtrace [ 1 ] = ( isset ( $trace [ 2 ]) ? $trace [ 2 ] : " " );
$error [ 'trace' ] = $backtrace ;
$this -> errors [] = $error ;
}
2019-02-08 11:01:42 -08:00
break ;
2006-12-02 04:36:16 +00:00
default :
return true ;
break ;
}
2020-04-26 13:32:18 -07:00
return null ;
2006-12-02 04:36:16 +00:00
}
2016-02-12 12:58:44 -08:00
function render_trace ( $array )
{
if ( $this -> xdebug == false )
{
return print_a ( $array , true );
}
array_pop ( $array );
2016-02-12 19:28:35 -08:00
$text = " <table class='table table-bordered table-striped table-condensed'>
2016-02-12 12:58:44 -08:00
< tr class = 'danger' >< th > #</th><th>Function</th><th>Location</th></tr>";
foreach ( $array as $key => $val )
{
$text .= "
< tr >
2020-12-19 10:50:08 -08:00
< td > " . $key . " </ td >
< td > " ;
2016-02-12 12:58:44 -08:00
$text .= ! empty ( $val [ 'class' ]) ? $val [ 'class' ] . " -> " : '' ;
$text .= ! empty ( $val [ 'include_filename' ]) ? " include: " . str_replace ( $this -> docroot , '' , $val [ 'include_filename' ]) : '' ;
2020-12-20 11:50:10 -08:00
$text .= ! empty ( $val [ 'function' ]) ? htmlentities ( $val [ 'function' ]) . " ( " : " " ;
2016-02-12 12:58:44 -08:00
$text .= ! empty ( $val [ 'params' ]) ? print_r ( $val [ 'params' ], true ) : '' ;
$text .= ! empty ( $val [ 'function' ]) ? " ) " : " " ;
$text .= " </td>
2020-12-20 11:50:10 -08:00
< td style = 'width:20%' > " ;
2016-02-12 12:58:44 -08:00
$text .= str_replace ( $this -> docroot , '' , $val [ 'file' ]) . " : " . $val [ 'line' ];
$text .= " </td>
</ tr > " ;
}
$text .= " </table> " ;
return $text ;
}
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 = " " ;
2012-12-06 14:16:55 -08:00
// print_a($this->errors);
2006-12-05 09:33:20 +00:00
if ( E107_DBG_ERRBACKTRACE )
{
2016-02-12 12:58:44 -08:00
2008-11-27 02:18:25 +00:00
foreach ( $this -> errors as $key => $value )
{
2020-12-19 10:50:08 -08:00
$ret .= " \t <tr> \n \t \t <td> { $value [ 'short' ] } </td><td><input class='btn btn-info button e-expandit' data-target = 'bt_ { $key } ' type ='button' style='cursor: hand; cursor: pointer;' size='30' value='Back Trace' /> \n " ;
2016-02-12 19:28:35 -08:00
$ret .= " </td> \n \t </tr> " ;
2016-02-12 12:58:44 -08:00
$ret .= " \t <tr> \n <td style='display: none;' colspan='2' id='bt_ { $key } '> " . $this -> render_trace ( $value [ 'trace' ]) . " </td></tr> \n " ;
2016-02-12 19:28:35 -08:00
2008-11-27 02:18:25 +00:00
if ( $index == 0 ) { $index = 1 ; } else { $index = 0 ; }
}
2012-12-06 14:16:55 -08:00
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
{
2020-12-19 10:50:08 -08:00
$ret .= " <tr><td> { $value [ 'short' ] } </td></tr> \n " ;
2006-12-05 09:33:20 +00:00
}
}
2009-07-21 14:20:13 +00:00
2020-12-21 17:46:32 -08:00
return ( $ret ) ? " <table class='table table-condensed'> \n " . $ret . " </table> " : false ;
2006-12-02 04:36:16 +00:00
}
2019-02-08 11:01:42 -08:00
/**
* @ param $information
* @ param $level
*/
2008-11-27 02:18:25 +00:00
function trigger_error ( $information , $level )
{
2019-02-26 15:54:51 -08:00
trigger_error ( $information , $level );
2006-12-02 04:36:16 +00:00
}
}
2014-05-24 20:40:51 -07:00
/**
* Manage Headers sent to browser .
* It is important to specify one of Expires or Cache - Control max - age , and one of Last - Modified or ETag , for all cacheable resources .
* It is redundant to specify both Expires and Cache - Control : max - age , or to specify both Last - Modified and ETag .
* Reference : http :// css - tricks . com / snippets / php / intelligent - php - cache - control /
* XXX Etag cannot be relied on as some hosts have Etag disabled .
* XXX session_cache_limiter ( 'private' ) will override some of the things below and bring back our browser cache issues .
*/
class e_http_header
{
private $content ;
private $etag ;
private $compress_output = false ;
private $compression_level = 6 ;
private $compression_browser_support = false ;
private $compression_server_support = false ;
private $headers = array ();
2016-03-19 17:14:22 -07:00
private $length = 0 ;
2014-05-24 20:40:51 -07:00
function __construct ()
{
2020-12-10 15:52:48 -08:00
if ( strpos ( varset ( $_SERVER [ 'HTTP_ACCEPT_ENCODING' ]), 'gzip' ) !== false )
2014-05-24 20:40:51 -07:00
{
$this -> compression_browser_support = true ;
}
2020-12-10 15:52:48 -08:00
if ( function_exists ( " gzencode " ) && ini_get ( " zlib.output_compression " ) == '' )
2014-05-24 20:40:51 -07:00
{
$this -> compression_server_support = true ;
}
2016-03-19 17:14:22 -07:00
if ( $this -> compression_server_support == true && $this -> compression_browser_support == true )
{
2020-04-26 13:32:18 -07:00
$this -> compress_output = ( bool ) e107 :: getPref ( 'compress_output' , false );
2016-03-19 17:14:22 -07:00
}
2014-05-24 20:40:51 -07:00
}
2016-03-22 06:11:37 -07:00
function setContent ( $content , $search = null , $replace = null )
2014-05-24 20:40:51 -07:00
{
2021-01-16 13:32:35 -08:00
global $_E107 ;
if ( $content == 'buffer' && empty ( $_E107 [ 'cli' ]))
2016-03-19 17:14:22 -07:00
{
$this -> length = ob_get_length ();
2016-03-22 06:11:37 -07:00
$this -> content = ob_get_clean ();
if ( ! empty ( $search ) && ! empty ( $replace ))
{
$this -> content = str_replace ( $search , $replace , $this -> content );
$this -> length = strlen ( $this -> content );
}
2016-03-19 17:14:22 -07:00
}
else
{
$this -> content = $content ;
$this -> length = strlen ( $content );
}
$this -> etag = md5 ( $this -> content );
//print_a($this->length);
// return $this->content;
}
/**
* Return Content ( with or without encoding )
* @ return mixed
*/
function getOutput ()
{
return $this -> content ;
2014-05-24 20:40:51 -07:00
}
function setHeader ( $header , $force = false , $response_code = null )
{
2021-01-16 10:02:52 -08:00
if ( e107 :: isCli ())
{
return null ;
}
2014-05-24 20:40:51 -07:00
list ( $key , $val ) = explode ( ':' , $header , 2 );
$this -> headers [ $key ] = $val ;
header ( $header , $force , $response_code );
}
2016-03-19 17:14:22 -07:00
function debug () // needs to be disabled if PHP gzip is to work
2014-05-24 20:40:51 -07:00
{
2016-03-19 17:14:22 -07:00
if ( ! ADMIN )
{
return null ;
}
2014-05-24 20:40:51 -07:00
2016-03-19 17:14:22 -07:00
$text = " <h3>Server Headers</h3> " ;
2014-05-24 20:40:51 -07:00
$server = getallheaders ();
ksort ( $server );
2016-03-19 17:14:22 -07:00
$text .= print_a ( $server , true );
$text .= " <h3>e107 Headers</h3> " ;
2014-05-24 20:40:51 -07:00
ksort ( $this -> headers );
2016-03-19 17:14:22 -07:00
$text .= print_a ( $this -> headers , true );
$text .= " <h4>Compress Output</h4> " ;
$text .= print_a ( $this -> compress_output , true );
2014-05-24 20:40:51 -07:00
$server = array ();
foreach ( $_SERVER as $k => $v )
{
2020-12-10 15:52:48 -08:00
if ( strncmp ( $k , 'HTTP' , 4 ) === 0 )
2014-05-24 20:40:51 -07:00
{
$server [ $k ] = $v ;
}
}
2016-03-19 17:14:22 -07:00
$text .= " <h3>_SERVER</h3> " ;
$text .= " <h4>zlib.output_compression</h4> " ;
$text .= print_a ( ini_get ( " zlib.output_compression " ), true );
$text .= print_a ( $server , true );
2017-05-16 14:31:23 -07:00
if ( $this -> compress_output === true )
2016-03-19 17:14:22 -07:00
{
$text = gzencode ( $text , $this -> compression_level );
}
echo $text ;
2014-05-24 20:40:51 -07:00
2019-02-08 11:01:42 -08:00
}
2017-10-23 12:59:30 -07:00
2014-05-24 20:40:51 -07:00
function send ()
{
2017-10-23 12:59:30 -07:00
2014-05-24 20:40:51 -07:00
$canCache = e107 :: canCache ();
// $this->setHeader("Cache-Control: must-revalidate", true);
2021-01-16 10:02:52 -08:00
if ( isset ( $_SERVER [ 'REQUEST_METHOD' ]) && $_SERVER [ 'REQUEST_METHOD' ] === 'GET' && $_SERVER [ 'QUERY_STRING' ] != 'logout' && $canCache && ! deftrue ( 'e_NOCACHE' ))
2014-05-24 20:40:51 -07:00
{
// header("Cache-Control: must-revalidate", true);
if ( e107 :: getPref ( 'site_page_expires' )) // TODO - allow per page
{
if ( function_exists ( 'date_default_timezone_set' ))
{
date_default_timezone_set ( 'UTC' );
}
$time = time () + ( integer ) e107 :: getPref ( 'site_page_expires' );
$this -> setHeader ( 'Expires: ' . gmdate ( " D, d M Y H:i:s " , $time ) . ' GMT' , true );
}
}
else
{
$canCache = false ;
}
2017-05-16 14:31:23 -07:00
if ( $this -> compress_output !== false )
2014-05-24 20:40:51 -07:00
{
2017-05-16 14:31:23 -07:00
$this -> setHeader ( 'ETag: "' . $this -> etag . '-gzip"' , true );
2016-03-19 17:14:22 -07:00
$this -> content = gzencode ( $this -> content , $this -> compression_level );
2017-05-16 14:31:23 -07:00
$this -> length = strlen ( $this -> content );
2016-03-19 17:14:22 -07:00
$this -> setHeader ( 'Content-Encoding: gzip' , true );
$this -> setHeader ( " Content-Length: " . $this -> length , true );
2014-05-24 20:40:51 -07:00
}
else
{
2016-03-19 17:14:22 -07:00
2017-05-16 14:31:23 -07:00
$this -> setHeader ( 'ETag: "' . $this -> etag . '"' , true );
2016-03-19 17:14:22 -07:00
$this -> setHeader ( " Content-Length: " . $this -> length , true );
2014-05-24 20:40:51 -07:00
}
2014-07-03 19:45:50 -07:00
if ( defset ( 'X-POWERED-BY' ) !== false )
{
$this -> setHeader ( " X-Powered-By: e107 " , true ); // no less secure than e107-specific html.
}
2017-04-28 12:06:27 -07:00
2014-05-24 20:40:51 -07:00
if ( $this -> compression_server_support == true )
{
$this -> setHeader ( 'Vary: Accept-Encoding' );
}
2016-03-19 17:14:22 -07:00
else
2014-05-24 20:40:51 -07:00
{
2016-03-19 17:14:22 -07:00
$this -> setHeader ( 'Vary: Accept' );
2014-05-24 20:40:51 -07:00
}
2017-10-23 12:59:30 -07:00
2018-08-03 17:14:39 -07:00
if ( defset ( 'X-FRAME-SAMEORIGIN' ) !== false )
{
$this -> setHeader ( 'X-Frame-Options: SAMEORIGIN' );
}
2017-10-23 12:59:30 -07:00
2014-05-24 20:40:51 -07:00
// should come after the Etag header
if ( $canCache && isset ( $_SERVER [ 'HTTP_IF_NONE_MATCH' ]))
{
$IF_NONE_MATCH = str_replace ( '"' , '' , $_SERVER [ 'HTTP_IF_NONE_MATCH' ]);
if ( $IF_NONE_MATCH == $this -> etag || ( $IF_NONE_MATCH == ( $this -> etag . " -gzip " )))
{
$this -> setHeader ( 'HTTP/1.1 304 Not Modified' );
exit ();
}
}
}
2008-10-07 21:29:25 +00:00
}
2014-07-03 19:45:50 -07:00
2020-05-02 15:35:30 -07:00
$dbg -> logTime ( '(After class2)' );