| [ Index ] |
PHP Cross Reference of E107 v0.7.22 code documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | 6 | Steve Dunstan 2001-2002 7 | http://e107.org 8 | jalist@e107.org 9 | 10 | Released under the terms and conditions of the 11 | GNU General Public License (http://gnu.org). 12 | 13 | $Source: /cvs_backup/e107_0.7/class2.php,v $ 14 | $Revision: 11518 $ 15 | $Date: 2010-05-03 17:31:18 -0400 (Mon, 03 May 2010) $ 16 | $Author: e107steved $ 17 +----------------------------------------------------------------------------+ 18 */ 19 // 20 // *** Code sequence for startup *** 21 // IMPORTANT: These items are in a carefully constructed order. DO NOT REARRANGE 22 // without checking with experienced devs! Various subtle things WILL break. 23 // 24 // A Get the current CPU time so we know how long all of this takes 25 // B Remove output buffering so we are in control of text sent to user 26 // C Remove registered globals (SECURITY for all following code) 27 // D Setup PHP error handling (now we can see php errors ;)) 28 // E Setup other PHP essentials 29 // F Grab e107_config to get directory paths 30 // G Retrieve Query from URI (i.e. what are the request parameters?!) 31 // H Initialize debug handling (NOTE: A-G cannot use debug tools!) 32 // I: Sanity check to ensure e107_config is ok 33 // J: MYSQL setup (NOTE: A-I cannot use database!) 34 // K: Compatibility mode 35 // L: Retrieve core prefs 36 // M: Subdomain and language selection 37 // N: Other misc setups (NOTE: Put most 'random' things here that don't require user session or theme 38 // O: Start user session 39 // P: Load theme 40 // Q: Other setups 41 42 // 43 // A: Honest global beginning point for processing time 44 // 45 $eTimingStart = microtime(); // preserve these when destroying globals in step C 46 $oblev_before_start = ob_get_level(); 47 48 // 49 // B: Remove all output buffering 50 // 51 while (@ob_end_clean()); // destroy all ouput buffering 52 ob_start(); // start our own. 53 $oblev_at_start = ob_get_level(); // preserve when destroying globals in step C 54 55 // 56 // C: Find out if register globals is enabled and destroy them if so 57 // (DO NOT use the value of any variables before this point! They could have been set by the user) 58 // 59 $register_globals = true; 60 if(function_exists('ini_get')) { 61 $register_globals = ini_get('register_globals'); 62 } 63 64 // Destroy! (if we need to) 65 if($register_globals == true){ 66 while (list($global) = each($GLOBALS)) { 67 if (!preg_match('/^(_POST|_GET|_COOKIE|_SERVER|_FILES|GLOBALS|HTTP.*|_REQUEST|retrieve_prefs|eplug_admin|eTimingStart)|oblev_.*$/', $global)) { 68 unset($$global); 69 } 70 } 71 unset($global); 72 } 73 74 75 if(($pos = strpos($_SERVER['PHP_SELF'], ".php/")) !== false) // redirect bad URLs to the correct one. 76 { 77 $new_url = substr($_SERVER['PHP_SELF'], 0, $pos+4); 78 $new_loc = ($_SERVER['QUERY_STRING']) ? $new_url."?".$_SERVER['QUERY_STRING'] : $new_url; 79 header("Location: ".$new_loc); 80 exit(); 81 } 82 // If url contains a .php in it, PHP_SELF is set wrong (imho), affecting all paths. We need to 'fix' it if it does. 83 $_SERVER['PHP_SELF'] = (($pos = strpos($_SERVER['PHP_SELF'], ".php")) !== false ? substr($_SERVER['PHP_SELF'], 0, $pos+4) : $_SERVER['PHP_SELF']); 84 85 // 86 // D: Setup PHP error handling 87 // (Now we can see PHP errors) -- but note that DEBUG is not yet enabled! 88 // 89 $error_handler = new error_handler(); 90 set_error_handler(array(&$error_handler, "handle_error")); 91 92 // 93 // E: Setup other essential PHP parameters 94 // 95 define("e107_INIT", TRUE); 96 97 // setup some php options 98 e107_ini_set('magic_quotes_runtime', 0); 99 e107_ini_set('magic_quotes_sybase', 0); 100 e107_ini_set('arg_separator.output', '&'); 101 e107_ini_set('session.use_only_cookies', 1); 102 e107_ini_set('session.use_trans_sid', 0); 103 104 105 if(isset($retrieve_prefs) && is_array($retrieve_prefs)) { 106 foreach ($retrieve_prefs as $key => $pref_name) { 107 $retrieve_prefs[$key] = preg_replace("/\W/", '', $pref_name); 108 } 109 } else { 110 unset($retrieve_prefs); 111 } 112 113 define("MAGIC_QUOTES_GPC", (ini_get('magic_quotes_gpc') ? TRUE : FALSE)); 114 115 // Define the domain name and subdomain name. 116 if(is_numeric(str_replace(".","",$_SERVER['HTTP_HOST']))){ 117 $srvtmp = ""; // Host is an IP address. 118 }else{ 119 $srvtmp = explode(".",str_replace("www.","",$_SERVER['HTTP_HOST'])); 120 } 121 122 define("e_SUBDOMAIN", (count($srvtmp)>2 && $srvtmp[2] ? $srvtmp[0] : FALSE)); // needs to be available to e107_config. 123 124 if(e_SUBDOMAIN) 125 { 126 unset($srvtmp[0]); 127 } 128 129 define("e_DOMAIN",(count($srvtmp) > 1 ? (implode(".",$srvtmp)) : FALSE)); // if it's an IP it must be set to FALSE. 130 131 unset($srvtmp); 132 133 134 // Ensure thet '.' is the first part of the include path 135 $inc_path = explode(PATH_SEPARATOR, ini_get('include_path')); 136 if($inc_path[0] != ".") { 137 array_unshift($inc_path, "."); 138 $inc_path = implode(PATH_SEPARATOR, $inc_path); 139 e107_ini_set("include_path", $inc_path); 140 } 141 unset($inc_path); 142 143 // 144 // F: Grab e107_config, get directory paths and create $e107 object 145 // 146 @include_once(realpath(dirname(__FILE__).'/e107_config.php')); 147 if(!isset($ADMIN_DIRECTORY)) 148 { 149 // e107_config.php is either empty, not valid or doesn't exist so redirect to installer.. 150 header("Location: install.php"); 151 exit(); 152 } 153 154 // 155 // clever stuff that figures out where the paths are on the fly.. no more need fo hard-coded e_HTTP :) 156 // 157 e107_require_once(realpath(dirname(__FILE__).'/'.$HANDLERS_DIRECTORY).'/e107_class.php'); 158 $e107_paths = compact('ADMIN_DIRECTORY', 'FILES_DIRECTORY', 'IMAGES_DIRECTORY', 'THEMES_DIRECTORY', 'PLUGINS_DIRECTORY', 'HANDLERS_DIRECTORY', 'LANGUAGES_DIRECTORY', 'HELP_DIRECTORY', 'DOWNLOADS_DIRECTORY'); 159 $e107 = new e107($e107_paths, realpath(dirname(__FILE__))); 160 161 $inArray = array("'", ";", "/**/", "/UNION/", "/SELECT/", "AS "); 162 if (strpos($_SERVER['PHP_SELF'], "trackback") === false) { 163 foreach($inArray as $res) { 164 if(stristr($_SERVER['QUERY_STRING'], $res)) { 165 die("Access denied."); 166 } 167 } 168 } 169 170 // 171 // G: Retrieve Query data from URI 172 // (Until this point, we have no idea what the user wants to do) 173 // 174 if (preg_match("#\[(.*?)](.*)#", $_SERVER['QUERY_STRING'], $matches)) { 175 define("e_MENU", $matches[1]); 176 $e_QUERY = $matches[2]; 177 178 if(strlen(e_MENU) == 2) // language code ie. [fr] 179 { 180 require_once(e_HANDLER."language_class.php"); 181 $slng = new language; 182 define("e_LANCODE",TRUE); 183 $_GET['elan'] = $slng->convert(e_MENU); 184 } 185 186 }else { 187 define("e_MENU", ""); 188 $e_QUERY = $_SERVER['QUERY_STRING']; 189 define("e_LANCODE", ""); 190 } 191 192 // 193 // Start the parser; use it to grab the full query string 194 // 195 196 e107_require_once(e_HANDLER.'e_parse_class.php'); 197 $tp = new e_parse; 198 199 $e_QUERY = str_replace(array('{', '}', '%7B', '%7b', '%7D', '%7d'), '', rawurldecode($e_QUERY)); 200 $e_QUERY = str_replace('&', '&', $tp->post_toForm($e_QUERY)); 201 202 /** 203 * e_QUERY notes: 204 * It seems _GET / _POST / _COOKIE are doing pre-urldecode on their data. 205 * There is no official documentation/php.ini setting to confirm this. 206 * We could add rawurlencode() after the replacement above if problems are reported. 207 * 208 * @var string 209 */ 210 define('e_QUERY', $e_QUERY); 211 212 //$e_QUERY = e_QUERY; 213 214 define("e_TBQS", $_SERVER['QUERY_STRING']); 215 $_SERVER['QUERY_STRING'] = e_QUERY; 216 217 define("e_UC_PUBLIC", 0); 218 define("e_UC_MAINADMIN", 250); 219 define("e_UC_READONLY", 251); 220 define("e_UC_GUEST", 252); 221 define("e_UC_MEMBER", 253); 222 define("e_UC_ADMIN", 254); 223 define("e_UC_NOBODY", 255); 224 define("ADMINDIR", $ADMIN_DIRECTORY); 225 226 // 227 // H: Initialize debug handling 228 // (NO E107 DEBUG CONSTANTS OR CODE ARE AVAILABLE BEFORE THIS POINT) 229 // All debug objects and constants are defined in the debug handler 230 // i.e. from here on you can use E107_DEBUG_LEVEL or any 231 // E107_DBG_* constant for debug testing. 232 // 233 require_once(e_HANDLER.'debug_handler.php'); 234 235 if(E107_DEBUG_LEVEL && isset($db_debug) && is_object($db_debug)) { 236 $db_debug->Mark_Time('Start: Init ErrHandler'); 237 } 238 239 // 240 // I: Sanity check on e107_config.php 241 // e107_config.php upgrade check 242 if (!$ADMIN_DIRECTORY && !$DOWNLOADS_DIRECTORY) { 243 message_handler("CRITICAL_ERROR", 8, ": generic, ", "e107_config.php"); 244 exit; 245 } 246 247 // 248 // J: MYSQL INITIALIZATION 249 // 250 @require_once(e_HANDLER.'traffic_class.php'); 251 $eTraffic=new e107_traffic; // We start traffic counting ASAP 252 $eTraffic->Calibrate($eTraffic); 253 254 define("MPREFIX", $mySQLprefix); 255 256 e107_require_once(e_HANDLER."mysql_class.php"); 257 258 $sql = new db; 259 $sql2 = new db; 260 261 $sql->db_SetErrorReporting(FALSE); 262 263 $sql->db_Mark_Time('Start: SQL Connect'); 264 $merror=$sql->db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb); 265 $sql->db_Mark_Time('Start: Prefs, misc tables'); 266 267 require_once(e_HANDLER.'admin_log_class.php'); 268 $admin_log = new e_admin_log(); 269 270 if ($merror == "e1") { 271 message_handler("CRITICAL_ERROR", 6, ": generic, ", "class2.php"); 272 exit; 273 } 274 else if ($merror == "e2") { 275 message_handler("CRITICAL_ERROR", 7, ": generic, ", "class2.php"); 276 exit; 277 } 278 279 // 280 // K: Load compatability mode. 281 // 282 /* At a later date add a check to load e107 compat mode by $pref 283 PHP Compatabilty should *always* be on. */ 284 e107_require_once(e_HANDLER."php_compatibility_handler.php"); 285 e107_require_once(e_HANDLER."e107_Compat_handler.php"); 286 $aj = new textparse; // required for backwards compatibility with 0.6 plugins. 287 288 // 289 // L: Extract core prefs from the database 290 // 291 $sql->db_Mark_Time('Start: Extract Core Prefs'); 292 e107_require_once(e_HANDLER."pref_class.php"); 293 $sysprefs = new prefs; 294 295 e107_require_once(e_HANDLER.'cache_handler.php'); 296 e107_require_once(e_HANDLER.'arraystorage_class.php'); 297 $eArrayStorage = new ArrayData(); 298 299 $PrefCache = ecache::retrieve('SitePrefs', 24 * 60, true); 300 if(!$PrefCache){ 301 // No cache of the prefs array, going for the db copy.. 302 $retrieve_prefs[] = 'SitePrefs'; 303 $sysprefs->ExtractPrefs($retrieve_prefs, TRUE); 304 $PrefData = $sysprefs->get('SitePrefs'); 305 $pref = $eArrayStorage->ReadArray($PrefData); 306 if(!$pref){ 307 $admin_log->log_event("CORE_LAN8", "CORE_LAN7", E_LOG_WARNING); // Core prefs error, core is attempting to 308 // Try for the automatic backup.. 309 $PrefData = $sysprefs->get('SitePrefs_Backup'); 310 $pref = $eArrayStorage->ReadArray($PrefData); 311 if(!$pref){ 312 // No auto backup, try for the 'old' prefs system. 313 $PrefData = $sysprefs->get('pref'); 314 $pref = unserialize($PrefData); 315 if(!is_array($pref)){ 316 message_handler("CRITICAL_ERROR", 3, __LINE__, __FILE__); 317 // No old system, so point in the direction of resetcore :( 318 message_handler("CRITICAL_ERROR", 4, __LINE__, __FILE__); 319 $admin_log->log_event("CORE_LAN8", "CORE_LAN9", E_LOG_FATAL); // Core could not restore from automatic backup. Execution halted. 320 exit; 321 } else { 322 // old prefs found, remove old system, and update core with new system 323 $PrefOutput = $eArrayStorage->WriteArray($pref); 324 if(!$sql->db_Update('core', "e107_value='{$PrefOutput}' WHERE e107_name='SitePrefs'")){ 325 $sql->db_Insert('core', "'SitePrefs', '{$PrefOutput}'"); 326 } 327 if(!$sql->db_Update('core', "e107_value='{$PrefOutput}' WHERE e107_name='SitePrefs_Backup'")){ 328 $sql->db_Insert('core', "'SitePrefs_Backup', '{$PrefOutput}'"); 329 } 330 $sql->db_Delete('core', "`e107_name` = 'pref'"); 331 } 332 } else { 333 message_handler("CRITICAL_ERROR", 3, __LINE__, __FILE__); 334 // auto backup found, use backup to restore the core 335 if(!$sql->db_Update('core', "`e107_value` = '".addslashes($PrefData)."' WHERE `e107_name` = 'SitePrefs'")){ 336 $sql->db_Insert('core', "'SitePrefs', '".addslashes($PrefData)."'"); 337 } 338 } 339 } 340 // write pref cache array 341 $PrefCache = $eArrayStorage->WriteArray($pref, false); 342 // store the prefs in cache if cache is enabled 343 ecache::set('SitePrefs', $PrefCache); 344 } else { 345 // cache of core prefs was found, so grab all the useful core rows we need 346 if(!isset($sysprefs->DefaultIgnoreRows)){ 347 $sysprefs->DefaultIgnoreRows = ""; 348 } 349 $sysprefs->DefaultIgnoreRows .= '|SitePrefs'; 350 $sysprefs->prefVals['core']['SitePrefs'] = $PrefCache; 351 if(isset($retrieve_prefs)) 352 { 353 $sysprefs->ExtractPrefs($retrieve_prefs, TRUE); 354 } 355 $pref = $eArrayStorage->ReadArray($PrefCache); 356 } 357 358 $e107->set_base_path(); 359 360 // extract menu prefs 361 $menu_pref = unserialize(stripslashes($sysprefs->get('menu_pref'))); 362 363 $sql->db_Mark_Time('(Extracting Core Prefs Done)'); 364 365 366 // 367 // M: Subdomain and Language Selection 368 // 369 define("SITEURLBASE", ($pref['ssl_enabled'] == '1' ? "https://" : "http://").$_SERVER['HTTP_HOST']); 370 define("SITEURL", SITEURLBASE.e_HTTP); 371 372 // let the subdomain determine the language (when enabled). 373 374 // Ensure $pref['sitelanguage'] is set if upgrading from 0.6 375 $pref['sitelanguage'] = (isset($pref['sitelanguage']) ? $pref['sitelanguage'] : 'English'); 376 377 if(varset($pref['multilanguage_subdomain']) && ($pref['user_tracking'] == "session") && e_DOMAIN && MULTILANG_SUBDOMAIN !== FALSE) 378 { 379 $mtmp = explode("\n", $pref['multilanguage_subdomain']); 380 foreach($mtmp as $val) 381 { 382 if(e_DOMAIN == trim($val)) 383 { 384 $domain_active = TRUE; 385 } 386 } 387 388 if($domain_active || ($pref['multilanguage_subdomain'] == "1")) 389 { 390 e107_ini_set("session.cookie_domain", ".".e_DOMAIN); 391 require_once(e_HANDLER."language_class.php"); 392 $slng = new language; 393 if(!e_SUBDOMAIN) 394 { 395 $GLOBALS['elan'] = $pref['sitelanguage']; 396 } 397 elseif($eln = $slng->convert(e_SUBDOMAIN)) 398 { 399 $GLOBALS['elan'] = $eln; 400 } 401 } 402 } 403 404 405 // if a cookie name pref isn't set, make one :) 406 if (!$pref['cookie_name']) { 407 $pref['cookie_name'] = "e107cookie"; 408 } 409 410 // start a session if session based login is enabled 411 if ($pref['user_tracking'] == "session") 412 { 413 session_start(); 414 } 415 416 define("e_SELF", ($pref['ssl_enabled'] == '1' ? "https://".$_SERVER['HTTP_HOST'] : "http://".$_SERVER['HTTP_HOST']) . ($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_FILENAME'])); 417 418 // if the option to force users to use a particular url for the site is enabled, redirect users there as needed 419 // Now matches RFC 2616 (sec 3.2): case insensitive, https/:443 and http/:80 are equivalent. 420 // And, this is robust against hack attacks. Malignant users can put **anything** in HTTP_HOST! 421 if($pref['redirectsiteurl'] && $pref['siteurl']) { 422 423 if(isset($pref['multilanguage_subdomain']) && $pref['multilanguage_subdomain']) 424 { 425 if(substr(e_SELF,7,4)=="www." || substr(e_SELF,8,4)=="www.") 426 { 427 $self = e_SELF; 428 if(e_QUERY){ $self .= "?".e_QUERY; } 429 $location = str_replace("://www.","://",$self); 430 header("Location: {$location}", true, 301); // send 301 header, not 302 431 exit(); 432 } 433 } 434 else 435 { 436 // Find domain and port from user and from pref 437 list($urlbase,$urlport) = explode(':',$_SERVER['HTTP_HOST'].':'); 438 if (!$urlport) { $urlport = $_SERVER['SERVER_PORT']; } 439 if (!$urlport) { $urlport = 80; } 440 $aPrefURL = explode('/',$pref['siteurl'],4); 441 if (count($aPrefURL) > 2) { // we can do this -- there's at least http[s]://dom.ain/whatever 442 $PrefRoot = $aPrefURL[2]; 443 list($PrefSiteBase,$PrefSitePort) = explode(':',$PrefRoot.':'); 444 if (!$PrefSitePort) { 445 $PrefSitePort = ( $aPrefURL[0] == "https:" ) ? 443 : 80; // no port so set port based on 'scheme' 446 } 447 448 // Redirect only if 449 // -- ports do not match (http <==> https) 450 // -- base domain does not match (case-insensitive) 451 // -- NOT admin area 452 if (($urlport != $PrefSitePort || stripos($PrefSiteBase, $urlbase) === FALSE) && strpos(e_SELF, ADMINDIR) === FALSE) { 453 $aeSELF = explode('/',e_SELF,4); 454 $aeSELF[0] = $aPrefURL[0]; // Swap in correct type of query (http, https) 455 $aeSELF[1] = ''; // Defensive code: ensure http:// not http:/<garbage>/ 456 $aeSELF[2] = $aPrefURL[2]; // Swap in correct domain and possibly port 457 $location = implode('/',$aeSELF).(e_QUERY ? "?".e_QUERY : ""); 458 459 header("Location: {$location}", true, 301); // send 301 header, not 302 460 exit(); 461 } 462 463 } 464 } 465 } 466 467 $page = substr(strrchr($_SERVER['PHP_SELF'], "/"), 1); 468 define("e_PAGE", $page); 469 470 // sort out the users language selection 471 if (isset($_POST['setlanguage']) || isset($_GET['elan']) || isset($GLOBALS['elan'])) 472 { 473 // query support, for language selection splash pages. etc 474 if($_GET['elan']) 475 { 476 $_POST['sitelanguage'] = str_replace(array(".", "/", "%"), "", $_GET['elan']); 477 } 478 if($GLOBALS['elan'] && !isset($_POST['sitelanguage'])) 479 { 480 $_POST['sitelanguage'] = $GLOBALS['elan']; 481 } 482 483 $sql->mySQLlanguage = $_POST['sitelanguage']; 484 $sql2->mySQLlanguage = $_POST['sitelanguage']; 485 486 if ($pref['user_tracking'] == "session") 487 { 488 $_SESSION['e107language_'.$pref['cookie_name']] = $_POST['sitelanguage']; 489 } 490 else 491 { 492 setcookie('e107language_'.$pref['cookie_name'], $_POST['sitelanguage'], time() + 86400, "/"); 493 $_COOKIE['e107language_'.$pref['cookie_name']] = $_POST['sitelanguage']; 494 if (strpos(e_SELF, ADMINDIR) === FALSE) 495 { 496 $locat = ((!$_GET['elan'] && e_QUERY) || (e_QUERY && e_LANCODE)) ? e_SELF."?".e_QUERY : e_SELF; 497 header("Location:".$locat); 498 exit(); 499 } 500 } 501 } 502 503 // Multi-language options. 504 505 // Get language list for rights checking. 506 if( ! $tmplan = getcachedvars('language-list')) 507 { 508 $handle = opendir(e_LANGUAGEDIR); 509 while ($file = readdir($handle)) 510 { 511 // add only if e_LANGUAGEDIR.e_LANGUAGE/e_LANGUAGE 512 if ($file != '.' && $file != '..' && is_readable(e_LANGUAGEDIR.$file.'/'.$file.'.php')) 513 { 514 $lanlist[] = $file; 515 } 516 } 517 closedir($handle); 518 $tmplan = implode(',', $lanlist); 519 cachevars('language-list', $tmplan); 520 } 521 // Save language flat list 522 define('e_LANLIST', $tmplan); 523 524 // Set $language fallback to $pref['sitelanguage'] for the time being 525 $language = $pref['sitelanguage']; 526 527 // Get user language choice 528 /// Force no multilingual sites to keep there preset languages? if (varset($pref['multilanguage'])) 529 { 530 if ($pref['user_tracking'] == 'session') 531 { 532 $user_language = (array_key_exists('e107language_'.$pref['cookie_name'], $_SESSION) ? $_SESSION['e107language_'.$pref['cookie_name']] : ''); 533 } 534 else 535 { 536 $user_language= (isset($_COOKIE['e107language_'.$pref['cookie_name']])) ? $_COOKIE['e107language_'.$pref['cookie_name']] : ''; 537 } 538 // Strip $user_language 539 //TODO allow [a-z][A-Z][0-9]_ 540 $user_language = preg_replace('#\W#', '', $user_language); 541 542 // Is user language choice available? 543 if( ! in_array($user_language, $lanlist)) 544 { 545 // Reset session 546 if(isset($_SESSION)) 547 { 548 unset($_SESSION['e107language_'.$pref['cookie_name']]); 549 } 550 // Reset cookie 551 if(isset($_COOKIE['e107language_'.$pref['cookie_name']])) 552 { 553 unset($_COOKIE['e107language_'.$pref['cookie_name']]); 554 } 555 $user_language = ''; 556 } 557 else 558 { 559 $language = $user_language; 560 } 561 562 // Ensure db got the proper language - default is empty 563 if (varset($pref['multilanguage'])) 564 { 565 $sql->mySQLlanguage = $user_language; 566 $sql2->mySQLlanguage = $user_language; 567 } 568 } 569 // We should have the language by now 570 define('e_LANGUAGE', $language); 571 572 // Keep USERLAN for backward compatibility 573 define('USERLAN', e_LANGUAGE); 574 575 //TODO do it only once and with the proper function 576 include_lan(e_LANGUAGEDIR.e_LANGUAGE."/".e_LANGUAGE.".php"); 577 include_lan(e_LANGUAGEDIR.e_LANGUAGE."/".e_LANGUAGE."_custom.php"); 578 579 if($pref['sitelanguage'] != e_LANGUAGE && varset($pref['multilanguage']) && !$pref['multilanguage_subdomain']) 580 { 581 list($clc) = explode("_",CORE_LC); 582 define("e_LAN", strtolower($clc)); 583 define("e_LANQRY", "[".e_LAN."]"); 584 unset($clc); 585 } 586 else 587 { 588 define("e_LAN", FALSE); 589 define("e_LANQRY", FALSE); 590 } 591 $sql->db_Mark_Time('(Start: Pref/multilang done)'); 592 593 // 594 // N: misc setups: online user tracking, cache 595 // 596 $sql -> db_Mark_Time('Start: Misc resources. Online user tracking, cache'); 597 $e_online = new e_online(); 598 599 // cache class 600 $e107cache = new ecache; 601 602 603 if (isset($pref['del_unv']) && $pref['del_unv'] && $pref['user_reg_veri'] != 2) { 604 $threshold=(time() - ($pref['del_unv'] * 60)); 605 $sql->db_Delete("user", "user_ban = 2 AND user_join < '{$threshold}' "); 606 } 607 608 e107_require_once(e_HANDLER."override_class.php"); 609 $override=new override; 610 611 e107_require_once(e_HANDLER."event_class.php"); 612 $e_event=new e107_event; 613 614 if (isset($pref['notify']) && $pref['notify'] == true) { 615 e107_require_once(e_HANDLER.'notify_class.php'); 616 } 617 618 // 619 // O: Start user session 620 // 621 $sql -> db_Mark_Time('Start: Init session'); 622 init_session(); 623 624 // for multi-language these definitions needs to come after the language loaded. 625 define("SITENAME", trim($tp->toHTML($pref['sitename'], "", 'USER_TITLE,value,defs'))); 626 define("SITEBUTTON", $pref['sitebutton']); 627 define("SITETAG", $tp->toHTML($pref['sitetag'], FALSE, "emotes_off, defs")); 628 define("SITEDESCRIPTION", $tp->toHTML($pref['sitedescription'], "", "emotes_off,defs")); 629 define("SITEADMIN", $pref['siteadmin']); 630 define("SITEADMINEMAIL", $pref['siteadminemail']); 631 define("SITEDISCLAIMER", $tp->toHTML($pref['sitedisclaimer'], "", "emotes_off,defs")); 632 define("SITECONTACTINFO", $tp->toHTML($pref['sitecontactinfo'], TRUE, "emotes_off,defs")); 633 634 // legacy module.php file loading. 635 if (isset($pref['modules']) && $pref['modules']) { 636 $mods=explode(",", $pref['modules']); 637 foreach ($mods as $mod) { 638 if (is_readable(e_PLUGIN."{$mod}/module.php")) { 639 require_once(e_PLUGIN."{$mod}/module.php"); 640 } 641 } 642 } 643 644 645 $js_body_onload = array(); // Initialise this array in case a module wants to add to it 646 647 648 // Load e_modules after all the constants, but before the themes, so they can be put to use. 649 if(isset($pref['e_module_list']) && $pref['e_module_list']){ 650 foreach ($pref['e_module_list'] as $mod){ 651 if (is_readable(e_PLUGIN."{$mod}/e_module.php")) { 652 require_once(e_PLUGIN."{$mod}/e_module.php"); 653 } 654 } 655 } 656 657 // 658 // P: THEME LOADING 659 // 660 661 $sql->db_Mark_Time('Start: Load Theme'); 662 663 //########### Module redefinable functions ############### 664 if (!function_exists('checkvalidtheme')) 665 { 666 // arg1 = theme to check 667 function checkvalidtheme($theme_check) 668 { 669 global $ADMIN_DIRECTORY, $tp, $e107; 670 671 if (ADMIN && strpos(e_QUERY, "themepreview") !== FALSE) 672 { // Theme preview 673 list($action, $id) = explode('.', e_QUERY); 674 require_once(e_HANDLER."theme_handler.php"); 675 $themeArray = themeHandler :: getThemes("id"); 676 define("PREVIEWTHEME", e_THEME.$themeArray[$id]."/"); 677 define("PREVIEWTHEMENAME", $themeArray[$id]); 678 define("THEME", e_THEME.$themeArray[$id]."/"); 679 define("THEME_ABS", e_THEME_ABS.$themeArray[$id]."/"); 680 return; 681 } 682 if (@fopen(e_THEME.$theme_check."/theme.php", "r")) 683 { // 'normal' theme load 684 define("THEME", e_THEME.$theme_check."/"); 685 define("THEME_ABS", e_THEME_ABS.$theme_check."/"); 686 $e107->site_theme = $theme_check; 687 } 688 else 689 { 690 function search_validtheme() 691 { 692 global $e107; 693 $th=substr(e_THEME, 0, -1); 694 $handle=opendir($th); 695 while ($file = readdir($handle)) 696 { 697 if (is_dir(e_THEME.$file) && is_readable(e_THEME.$file.'/theme.php')) 698 { 699 closedir($handle); 700 $e107->site_theme = $file; 701 return $file; 702 } 703 } 704 closedir($handle); 705 } 706 707 $e107tmp_theme = search_validtheme(); 708 define("THEME", e_THEME.$e107tmp_theme."/"); 709 define("THEME_ABS", e_THEME_ABS.$e107tmp_theme."/"); 710 if (ADMIN && strpos(e_SELF, $ADMIN_DIRECTORY) === FALSE) 711 { 712 echo '<script>alert("'.$tp->toJS(CORE_LAN1).'")</script>'; 713 } 714 } 715 $themes_dir = $e107->e107_dirs["THEMES_DIRECTORY"]; 716 $e107->http_theme_dir = "{$e107->server_path}{$themes_dir}{$e107->site_theme}/"; 717 } 718 } 719 720 // 721 // Q: ALL OTHER SETUP CODE 722 // 723 $sql->db_Mark_Time('Start: Misc Setup'); 724 725 //------------------------------------------------------------------------------------------------------------------------------------// 726 if (!class_exists('e107table')) 727 { 728 class e107table 729 { 730 function tablerender($caption, $text, $mode = "default", $return = false) { 731 /* 732 # Render style table 733 # - parameter #1: string $caption, caption text 734 # - parameter #2: string $text, body text 735 # - return null 736 # - scope public 737 */ 738 global $override; 739 740 if ($override_tablerender = $override->override_check('tablerender')) { 741 $result=call_user_func($override_tablerender, $caption, $text, $mode, $return); 742 743 if ($result == "return") { 744 return; 745 } 746 extract($result); 747 } 748 749 if ($return) { 750 ob_start(); 751 tablestyle($caption, $text, $mode); 752 $ret=ob_get_contents(); 753 ob_end_clean(); 754 return $ret; 755 } else { 756 tablestyle($caption, $text, $mode); 757 } 758 } 759 } 760 } 761 //############################################################# 762 763 $ns=new e107table; 764 765 $e107->ban(); 766 767 if(varset($pref['force_userupdate']) && USER) 768 { 769 if(force_userupdate()) 770 { 771 header("Location: ".e_BASE."usersettings.php?update"); 772 exit(); 773 } 774 } 775 776 $sql->db_Mark_Time('Start: Signup/splash/admin'); 777 778 define("e_SIGNUP", e_BASE.(file_exists(e_BASE."customsignup.php") ? "customsignup.php" : "signup.php")); 779 define("e_LOGIN", e_BASE.(file_exists(e_BASE."customlogin.php") ? "customlogin.php" : "login.php")); 780 781 if ($pref['membersonly_enabled'] && !USER && e_SELF != SITEURL.e_SIGNUP && e_SELF != SITEURL."index.php" && e_SELF != SITEURL."fpw.php" && e_SELF != SITEURL.e_LOGIN && strpos(e_PAGE, "admin") === FALSE && e_SELF != SITEURL.'membersonly.php' && e_SELF != SITEURL.'sitedown.php') { 782 header("Location: ".e_HTTP."membersonly.php"); 783 exit(); 784 } 785 786 $sql->db_Delete("tmp", "tmp_time < ".(time() - 300)." AND tmp_ip!='data' AND tmp_ip!='submitted_link'"); 787 788 789 790 if (varset($pref['maintainance_flag']) 791 && strpos(e_SELF, 'admin.php') === FALSE && strpos(e_SELF, 'sitedown.php') === FALSE) 792 { 793 if(!ADMIN || ($pref['maintainance_flag'] == e_UC_MAINADMIN && !getperms('0'))) 794 { 795 // 307 Temporary Redirect 796 header('Location: '.SITEURL.'sitedown.php', TRUE, 307); 797 exit(); 798 } 799 } 800 801 $sql->db_Mark_Time('(Start: Login/logout/ban/tz)'); 802 803 if (isset($_POST['userlogin']) || isset($_POST['userlogin_x'])) { 804 e107_require_once(e_HANDLER."login.php"); 805 $usr = new userlogin($_POST['username'], $_POST['userpass'], $_POST['autologin']); 806 } 807 808 if (e_QUERY == 'logout') 809 { 810 $ip = $e107->getip(); 811 $udata=(USER === TRUE) ? USERID.".".USERNAME : "0"; 812 $sql->db_Update("online", "online_user_id = '0', online_pagecount=online_pagecount+1 WHERE online_user_id = '{$udata}' LIMIT 1"); 813 814 if ($pref['user_tracking'] == 'session') 815 { 816 session_destroy(); 817 $_SESSION[$pref['cookie_name']]=''; 818 } 819 820 cookie($pref['cookie_name'], '', (time() - 2592000)); 821 $e_event->trigger('logout'); 822 header('location:'.e_BASE.'index.php'); 823 exit(); 824 } 825 826 827 /* 828 * Calculate time zone offset, based on session cookie set in e107.js. 829 * (Buyer beware: this may be wrong for the first pageview in a session, 830 * which is while the user is logged out, so not a problem...) 831 * 832 * Time offset is SECONDS. Seconds is much better than hours as a base, 833 * as some places have 30 and 45 minute time zones. 834 * It matches user clock time, instead of only time zones. 835 * Add the offset to MySQL/server time to get user time. 836 * Subtract the offset from user time to get server time. 837 * 838 */ 839 840 $e_deltaTime=0; 841 842 if (isset($_COOKIE['e107_tdOffset'])) { 843 // Actual seconds of delay. See e107.js and footer_default.php 844 $e_deltaTime = $_COOKIE['e107_tdOffset']; 845 } 846 847 if (isset($_COOKIE['e107_tzOffset'])) { 848 // Relative client-to-server time zone offset in seconds. 849 $e_deltaTime += (-($_COOKIE['e107_tzOffset'] * 60 + date("Z"))); 850 } 851 852 define("TIMEOFFSET", $e_deltaTime); 853 854 $sql->db_Mark_Time('Start: Get menus'); 855 856 $menu_data = $e107cache->retrieve("menus_".USERCLASS_LIST."_".md5(e_LANGUAGE)); 857 $menu_data = $eArrayStorage->ReadArray($menu_data); 858 $eMenuList=array(); 859 $eMenuActive=array(); 860 if(!is_array($menu_data)) { 861 if ($sql->db_Select('menus', '*', "menu_location > 0 AND menu_class IN (".USERCLASS_LIST.") ORDER BY menu_order")) { 862 while ($row = $sql->db_Fetch()) { 863 $eMenuList[$row['menu_location']][]=$row; 864 $eMenuActive[]=$row['menu_name']; 865 } 866 } 867 $menu_data['menu_list'] = $eMenuList; 868 $menu_data['menu_active'] = $eMenuActive; 869 $menu_data = $eArrayStorage->WriteArray($menu_data, false); 870 $e107cache->set("menus_".USERCLASS_LIST."_".md5(e_LANGUAGE), $menu_data); 871 unset($menu_data); 872 } else { 873 $eMenuList = $menu_data['menu_list']; 874 $eMenuActive = $menu_data['menu_active']; 875 unset($menu_data); 876 } 877 878 $sql->db_Mark_Time('(Start: Find/Load Theme)'); 879 880 881 // Work out which theme to use 882 //---------------------------- 883 // The following files are assumed to use admin theme: 884 // 1. Any file in the admin directory (check for non-plugin added to avoid mismatches) 885 // 2. any plugin file starting with 'admin_' 886 // 3. any plugin file in a folder called admin/ 887 // 4. any file that specifies $eplug_admin = TRUE; 888 // 889 // e_SELF has the full HTML path 890 $inAdminDir = FALSE; 891 $isPluginDir = strpos(e_SELF,'/'.$PLUGINS_DIRECTORY) !== FALSE; // True if we're in a plugin 892 $e107Path = str_replace($e107->base_path, "", e_SELF); // Knock off the initial bits 893 if ( 894 (!$isPluginDir && strpos($e107Path, $ADMIN_DIRECTORY) === 0 ) // Core admin directory 895 || ($isPluginDir && (strpos(e_PAGE,"admin_") === 0 || strpos($e107Path, "admin/") !== FALSE)) // Plugin admin file or directory 896 || (varsettrue($eplug_admin)) // Admin forced 897 ) 898 { 899 $inAdminDir = TRUE; 900 // Load admin phrases ASAP 901 include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_admin.php'); 902 } 903 904 905 if(!defined("THEME")) 906 { 907 if ($inAdminDir && varsettrue($pref['admintheme'])&& (strpos(e_SELF.'?'.e_QUERY, 'menus.php?configure') === FALSE)) 908 { 909 /* if (strpos(e_SELF, "newspost.php") !== FALSE) 910 { 911 define("MAINTHEME", e_THEME.$pref['sitetheme']."/"); MAINTHEME no longer used in core distribution 912 } */ 913 checkvalidtheme($pref['admintheme']); 914 } 915 elseif (USERTHEME !== FALSE && USERTHEME != "USERTHEME" && !$inAdminDir) 916 { 917 checkvalidtheme(USERTHEME); 918 } 919 else 920 { 921 checkvalidtheme($pref['sitetheme']); 922 } 923 } 924 925 926 // -------------------------------------------------------------- 927 928 929 // here we USE the theme 930 if ($inAdminDir) 931 { 932 if (file_exists(THEME.'admin_theme.php')) 933 { 934 require_once(THEME.'admin_theme.php'); 935 } 936 else 937 { 938 require_once(THEME."theme.php"); 939 } 940 } 941 else 942 { 943 require_once(THEME."theme.php"); 944 } 945 946 947 948 949 $exclude_lan = array("lan_signup.php"); // required for multi-language. 950 951 //TODO remove autoload 952 if ($inAdminDir) 953 { 954 include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_".e_PAGE); 955 } 956 elseif (!in_array("lan_".e_PAGE,$exclude_lan) && !$isPluginDir) 957 { 958 include_lan(e_LANGUAGEDIR.e_LANGUAGE."/lan_".e_PAGE); 959 } 960 961 962 963 964 if(!defined("IMODE")) define("IMODE", "lite"); 965 966 if ($pref['anon_post'] ? define("ANON", TRUE) : define("ANON", FALSE)); 967 968 if (Empty($pref['newsposts']) ? define("ITEMVIEW", 15) : define("ITEMVIEW", $pref['newsposts'])); 969 970 if ($pref['antiflood1'] == 1) 971 { 972 define('FLOODPROTECT', TRUE); 973 define('FLOODTIMEOUT', max(varset($pref['antiflood_timeout'],10),3)); 974 } 975 else 976 { 977 define('FLOODPROTECT', FALSE); 978 } 979 980 $layout = isset($layout) ? $layout : '_default'; 981 define("HEADERF", e_THEME."templates/header{$layout}.php"); 982 define("FOOTERF", e_THEME."templates/footer{$layout}.php"); 983 984 if (!file_exists(HEADERF)) { 985 message_handler("CRITICAL_ERROR", "Unable to find file: ".HEADERF, __LINE__ - 2, __FILE__); 986 } 987 988 if (!file_exists(FOOTERF)) { 989 message_handler("CRITICAL_ERROR", "Unable to find file: ".FOOTERF, __LINE__ - 2, __FILE__); 990 } 991 992 define("LOGINMESSAGE", ""); 993 define("OPEN_BASEDIR", (ini_get('open_basedir') ? TRUE : FALSE)); 994 define("SAFE_MODE", (ini_get('safe_mode') ? TRUE : FALSE)); 995 define("FILE_UPLOADS", (ini_get('file_uploads') ? TRUE : FALSE)); 996 define("INIT", TRUE); 997 if(isset($_SERVER['HTTP_REFERER'])) { 998 $tmp = explode("?", $_SERVER['HTTP_REFERER']); 999 define("e_REFERER_SELF",($tmp[0] == e_SELF)); 1000 } else { 1001 define('e_REFERER_SELF', FALSE); 1002 } 1003 1004 if (!class_exists('convert')) 1005 { 1006 require_once(e_HANDLER."date_handler.php"); 1007 } 1008 1009 1010 1011 1012 1013 //@require_once(e_HANDLER."IPB_int.php"); 1014 //@require_once(e_HANDLER."debug_handler.php"); 1015 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// 1016 function js_location($qry){ 1017 global $error_handler; 1018 if (count($error_handler->errors)) { 1019 echo $error_handler->return_errors(); 1020 exit; 1021 } else { 1022 echo "<script type='text/javascript'>document.location.href='{$qry}'</script>\n"; exit; 1023 } 1024 } 1025 1026 function check_email($email) { 1027 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; 1028 } 1029 1030 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// 1031 1032 /** 1033 * 1034 * @param mixed $var 1035 * @param string $userclass 1036 * @param mixed $peer 1037 * @param boolean $debug 1038 * @return boolean 1039 */ 1040 function check_class($var, $userclass = USERCLASS, $peer = FALSE, $debug = FALSE) 1041 { 1042 global $tp; 1043 if($var == e_LANGUAGE){ 1044 return TRUE; 1045 } 1046 1047 if (is_numeric($var) && !$var) return TRUE; // Accept numeric class zero - 'PUBLIC' 1048 1049 if (!$var || $var == '') 1050 { // ....but an empty string or NULL variable is not valid 1051 return FALSE; 1052 } 1053 1054 if(strpos($var, ',') !== FALSE) 1055 { 1056 $lans = explode(',', e_LANLIST); 1057 $varList = explode(',', $var); 1058 rsort($varList); // check the language first.(ie. numbers come last) 1059 foreach($varList as $v) 1060 { 1061 if (in_array($v,$lans) && strpos($v, e_LANGUAGE) === FALSE) { 1062 return FALSE; 1063 } 1064 1065 if(check_class($v, $userclass, $debug)) { 1066 return TRUE; 1067 } 1068 } 1069 return FALSE; 1070 } 1071 1072 //if peer is array, assume it's a user record 1073 if(is_array($peer)) { 1074 $_adminperms = ($peer['user_admin'] === 1 ? $peer['user_perms'] : ''); 1075 $_user = true; 1076 $_admin = $peer['user_admin'] === 1; 1077 $peer = false; 1078 } else { 1079 $_adminperms = ADMINPERMS; 1080 $_user = USER; 1081 $_admin = ADMIN; 1082 } 1083 1084 //Test 'special' userclass numbers 1085 if (preg_match("/^([0-9]+)$/", $var) && !$peer) 1086 { 1087 if ($var == e_UC_MAINADMIN && getperms('0', $_adminperms)) 1088 { 1089 return TRUE; 1090 } 1091 1092 if ($var == e_UC_MEMBER && $_user == TRUE) 1093 { 1094 return TRUE; 1095 } 1096 1097 if ($var == e_UC_GUEST && $_user == FALSE) { 1098 return TRUE; 1099 } 1100 1101 if ($var == e_UC_PUBLIC) { 1102 return TRUE; 1103 } 1104 1105 if ($var == e_UC_NOBODY) { 1106 return FALSE; 1107 } 1108 1109 if ($var == e_UC_ADMIN && $_admin) { 1110 return TRUE; 1111 } 1112 if ($var == e_UC_READONLY) { 1113 return TRUE; 1114 } 1115 } 1116 1117 if ($debug) { 1118 echo "USERCLASS: ".$userclass.", \$var = $var : "; 1119 } 1120 1121 if (!defined("USERCLASS") || $userclass == "") { 1122 if ($debug) { 1123 echo "FALSE<br />"; 1124 } 1125 return FALSE; 1126 } 1127 1128 // user has classes set - continue 1129 if (preg_match("/^([0-9]+)$/", $var)) { 1130 $tmp=explode(',', $userclass); 1131 if (is_numeric(array_search($var, $tmp))) { 1132 if ($debug) { 1133 echo "TRUE<br />"; 1134 } 1135 return TRUE; 1136 } 1137 } else { 1138 // var is name of class ... 1139 $sql=new db; 1140 if ($sql->db_Select("userclass_classes", "*", "userclass_name='".$tp -> toDB($var)."' ")) { 1141 $row=$sql->db_Fetch(); 1142 $tmp=explode(',', $userclass); 1143 if (is_numeric(array_search($row['userclass_id'], $tmp))) { 1144 if ($debug) { 1145 echo "TRUE<br />"; 1146 } 1147 return TRUE; 1148 } 1149 } 1150 } 1151 1152 if ($debug) { 1153 echo "NOTNUM! FALSE<br />"; 1154 } 1155 1156 return FALSE; 1157 } 1158 1159 function getperms($arg, $ap = ADMINPERMS) 1160 { 1161 global $PLUGINS_DIRECTORY; 1162 1163 if(!ADMIN) 1164 { 1165 return FALSE; 1166 } 1167 if ($ap == "0") 1168 { 1169 return TRUE; 1170 } 1171 if ($ap == "") 1172 { 1173 return FALSE; 1174 } 1175 $ap='.'.$ap; 1176 if ($arg == 'P' && preg_match("#(.*?)/".$PLUGINS_DIRECTORY."(.*?)/(.*?)#", e_SELF, $matches)) 1177 { 1178 $psql=new db; 1179 if ($psql->db_Select('plugin', 'plugin_id', "plugin_path = '".$matches[2]."' ")) 1180 { 1181 $row=$psql->db_Fetch(); 1182 $arg='P'.$row[0]; 1183 } 1184 } 1185 if (strpos($ap, ".".$arg.".") !== FALSE) 1186 { 1187 return TRUE; 1188 } 1189 else 1190 { 1191 return FALSE; 1192 } 1193 } 1194 1195 /** 1196 * Get the user data from user and user_extended tables 1197 * 1198 * @return array 1199 */ 1200 function get_user_data($uid, $extra = "") 1201 { 1202 global $pref, $sql; 1203 $uid = intval($uid); 1204 $var = array(); 1205 if($uid == 0) { return $var; } 1206 if($ret = getcachedvars("userdata_{$uid}")) 1207 { 1208 return $ret; 1209 } 1210 1211 $qry = " 1212 SELECT u.*, ue.* FROM #user AS u 1213 LEFT JOIN #user_extended AS ue ON ue.user_extended_id = u.user_id 1214 WHERE u.user_id = {$uid} {$extra} 1215 "; 1216 if (!$sql->db_Select_gen($qry)) 1217 { 1218 $qry = "SELECT * FROM #user AS u WHERE u.user_id = {$uid} {$extra}"; 1219 if(!$sql->db_Select_gen($qry)) 1220 { 1221 return FALSE; 1222 } 1223 } 1224 1225 $var = $sql->db_Fetch(); 1226 $extended_struct = getcachedvars("extended_struct"); 1227 if(!$extended_struct) 1228 { 1229 unset($extended_struct); 1230 $qry = "SHOW COLUMNS FROM #user_extended "; 1231 if($sql->db_Select_gen($qry)) 1232 { 1233 while($row = $sql->db_Fetch()) 1234 { 1235 if($row['Default'] != "") 1236 { 1237 $extended_struct[] = $row; 1238 } 1239 } 1240 if(isset($extended_struct)) 1241 { 1242 cachevars("extended_struct", $extended_struct); 1243 } 1244 } 1245 } 1246 1247 if(isset($extended_struct)) 1248 { 1249 foreach($extended_struct as $row) 1250 { 1251 if($row['Default'] != "" && ($var[$row['Field']] == NULL || $var[$row['Field']] == "" )) 1252 { 1253 $var[$row['Field']] = $row['Default']; 1254 } 1255 } 1256 } 1257 if ($var['user_perms'] == '0.') $var['user_perms'] = '0'; // Handle some legacy situations 1258 cachevars("userdata_{$uid}", $var); 1259 return $var; 1260 } 1261 1262 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// 1263 1264 function save_prefs($table = 'core', $uid = USERID, $row_val = '') 1265 { 1266 global $pref, $user_pref, $tp, $PrefCache, $sql, $eArrayStorage; 1267 if ($table == 'core') 1268 { 1269 if ($row_val == '') 1270 { // Save old version as a backup first 1271 $sql->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('SitePrefs_Backup', '".addslashes($PrefCache)."') "); 1272 1273 // Now save the updated values 1274 // traverse the pref array, with toDB on everything 1275 $_pref = $tp -> toDB($pref, true, true); 1276 // Create the data to be stored 1277 $sql->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('SitePrefs', '".$eArrayStorage->WriteArray($_pref)."') "); 1278 ecache::clear('SitePrefs'); 1279 } 1280 } 1281 else 1282 { 1283 $_user_pref = $tp -> toDB($user_pref); 1284 $tmp=addslashes(serialize($_user_pref)); 1285 $sql->db_Update("user", "user_prefs='$tmp' WHERE user_id=".intval($uid)); 1286 return $tmp; 1287 } 1288 } 1289 1290 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// 1291 1292 class e_online { 1293 function online($online_tracking = false, $flood_control = false) { 1294 if($online_tracking == true || $flood_control == true) 1295 { 1296 global $online_timeout, $online_warncount, $online_bancount; 1297 if(!isset($online_timeout)) { 1298 $online_timeout = 300; 1299 } 1300 if(!isset($online_warncount)) { 1301 $online_warncount = 90; 1302 } 1303 if(!isset($online_bancount)) { 1304 $online_bancount = 100; 1305 } 1306 global $sql, $pref, $e107, $listuserson, $e_event, $tp; 1307 $page = (strpos(e_SELF, "forum_") !== FALSE) ? e_SELF.".".e_QUERY : e_SELF; 1308 $page = (strpos(e_SELF, "comment") !== FALSE) ? e_SELF.".".e_QUERY : $page; 1309 $page = (strpos(e_SELF, "content") !== FALSE) ? e_SELF.".".e_QUERY : $page; 1310 $page = $tp -> toDB($page, true); 1311 1312 $ip = $e107->getip(); 1313 $udata = (USER === true ? USERID.".".USERNAME : "0"); 1314 1315 if (USER) 1316 { 1317 // Find record that matches IP or visitor, or matches user info 1318 if ($sql->db_Select("online", "*", "(`online_ip` = '{$ip}' AND `online_user_id` = '0') OR `online_user_id` = '{$udata}'")) { 1319 $row = $sql->db_Fetch(); 1320 1321 if ($row['online_user_id'] == $udata) { 1322 //Matching user record 1323 if ($row['online_timestamp'] < (time() - $online_timeout)) { 1324 //It has been at least 'timeout' seconds since this user has connected 1325 //Update user record with timestamp, current IP, current page and set pagecount to 1 1326 $query = "online_timestamp='".time()."', online_ip='{$ip}', online_location='{$page}', online_pagecount=1 WHERE online_user_id='{$row['online_user_id']}' LIMIT 1"; 1327 } else { 1328 if (!ADMIN) { 1329 $row['online_pagecount'] ++; 1330 } 1331 // Update user record with current IP, current page and increment pagecount 1332 $query = "online_ip='{$ip}', `online_location` = '{$page}', `online_pagecount` = '".intval($row['online_pagecount'])."' WHERE `online_user_id` = '{$row['online_user_id']}' LIMIT 1"; 1333 } 1334 } else { 1335 //Found matching visitor record (ip only) for this user 1336 if ($row['online_timestamp'] < (time() - $online_timeout)) { 1337 // It has been at least 'timeout' seconds since this user has connected 1338 // Update record with timestamp, current IP, current page and set pagecount to 1 1339 $query = "`online_timestamp` = '".time()."', `online_user_id` = '{$udata}', `online_location` = '{$page}', `online_pagecount` = 1 WHERE `online_ip` = '{$ip}' AND `online_user_id` = '0' LIMIT 1"; 1340 } else { 1341 if (!ADMIN) { 1342 $row['online_pagecount'] ++; 1343 } 1344 //Update record with current IP, current page and increment pagecount 1345 $query = "`online_user_id` = '{$udata}', `online_location` = '{$page}', `online_pagecount` = ".intval($row['online_pagecount'])." WHERE `online_ip` = '{$ip}' AND `online_user_id` = '0' LIMIT 1"; 1346 } 1347 } 1348 $sql->db_Update("online", $query); 1349 } else { 1350 $sql->db_Insert("online", " '".time()."', '0', '{$udata}', '{$ip}', '{$page}', 1, 0"); 1351 } 1352 } 1353 else 1354 { 1355 //Current page request is from a visitor 1356 if ($sql->db_Select("online", "*", "`online_ip` = '{$ip}' AND `online_user_id` = '0'")) { 1357 $row = $sql->db_Fetch(); 1358 1359 if ($row['online_timestamp'] < (time() - $online_timeout)) //It has been at least 'timeout' seconds since this ip has connected 1360 { 1361 //Update record with timestamp, current page, and set pagecount to 1 1362 $query = "`online_timestamp` = '".time()."', `online_location` = '{$page}', `online_pagecount` = 1 WHERE `online_ip` = '{$ip}' AND `online_user_id` = '0' LIMIT 1"; 1363 } else { 1364 //Update record with current page and increment pagecount 1365 $row['online_pagecount'] ++; 1366 // echo "here {$online_pagecount}"; 1367 $query="`online_location` = '{$page}', `online_pagecount` = {$row['online_pagecount']} WHERE `online_ip` = '{$ip}' AND `online_user_id` = '0' LIMIT 1"; 1368 } 1369 $sql->db_Update("online", $query); 1370 } else { 1371 $sql->db_Insert("online", " '".time()."', '0', '0', '{$ip}', '{$page}', 1, 0"); 1372 } 1373 } 1374 1375 if (ADMIN || ($pref['autoban'] != 1 && $pref['autoban'] != 2) || (!isset($row['online_pagecount']))) // Auto-Ban is switched off. (0 or 3) 1376 { 1377 $row['online_pagecount'] = 1; 1378 } 1379 1380 if ($row['online_pagecount'] > $online_bancount && ($row['online_ip'] != "127.0.0.1")) 1381 { 1382 include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_banlist.php'); 1383 $sql->db_Insert('banlist', "'{$ip}', '0', '".str_replace('--HITS--',$row['online_pagecount'],BANLAN_78)."' "); 1384 $e_event->trigger("flood", $ip); 1385 exit(); 1386 } 1387 if ($row['online_pagecount'] >= $online_warncount && $row['online_ip'] != "127.0.0.1") { 1388 echo "<div style='text-align:center; font: 11px verdana, tahoma, arial, helvetica, sans-serif;'><b>".LAN_WARNING."</b><br /><br />".CORE_LAN6."<br /></div>"; 1389 exit(); 1390 } 1391 1392 $sql->db_Delete("online", "`online_timestamp` < ".(time() - $online_timeout)); 1393 1394 global $members_online, $total_online, $member_list, $listuserson; 1395 $total_online = $sql->db_Count("online"); 1396 if ($members_online = $sql->db_Select("online", "*", "online_user_id != '0' ")) { 1397 $member_list = ''; 1398 $listuserson = array(); 1399 while ($row = $sql->db_Fetch()) { 1400 $vals = explode(".", $row['online_user_id'], 2); 1401 $member_list .= "<a href='".e_BASE."user.php?id.{$vals[0]}'>{$vals[1]}</a> "; 1402 $listuserson[$row['online_user_id']] = $row['online_location']; 1403 } 1404 } 1405 define("TOTAL_ONLINE", $total_online); 1406 define("MEMBERS_ONLINE", $members_online); 1407 define("GUESTS_ONLINE", $total_online - $members_online); 1408 define("ON_PAGE", $sql->db_Count("online", "(*)", "WHERE `online_location` = '{$page}' ")); 1409 define("MEMBER_LIST", $member_list); 1410 } 1411 else 1412 { 1413 define("e_TRACKING_DISABLED", true); 1414 define("TOTAL_ONLINE", ""); 1415 define("MEMBERS_ONLINE", ""); 1416 define("GUESTS_ONLINE", ""); 1417 define("ON_PAGE", ""); 1418 define("MEMBER_LIST", ""); // 1419 } 1420 } 1421 } 1422 1423 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// 1424 function cachevars($id, $var) { 1425 global $cachevar; 1426 $cachevar[$id]=$var; 1427 } 1428 1429 function getcachedvars($id) { 1430 global $cachevar; 1431 return (isset($cachevar[$id]) ? $cachevar[$id] : false); 1432 } 1433 1434 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// 1435 class floodprotect { 1436 function flood($table, $orderfield) { 1437 /* 1438 # Test for possible flood 1439 # 1440 # - parameter #1 string $table, table being affected 1441 # - parameter #2 string $orderfield, date entry in respective table 1442 # - return boolean 1443 # - scope public 1444 */ 1445 $sql=new db; 1446 1447 if (FLOODPROTECT == TRUE) { 1448 $sql->db_Select($table, "*", "ORDER BY ".$orderfield." DESC LIMIT 1", "no_where"); 1449 $row=$sql->db_Fetch(); 1450 return ($row[$orderfield] > (time() - FLOODTIMEOUT) ? FALSE : TRUE); 1451 } else { 1452 return TRUE; 1453 } 1454 } 1455 } 1456 1457 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// 1458 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// 1459 function init_session() { 1460 /* 1461 # Validate user 1462 # 1463 # - parameters none 1464 # - return boolean 1465 # - scope public 1466 */ 1467 global $sql, $pref, $user_pref, $tp, $currentUser, $e107; 1468 1469 define('USERIP', $e107->getip()); 1470 if (!isset($_COOKIE[$pref['cookie_name']]) && !isset($_SESSION[$pref['cookie_name']])) 1471 { 1472 define("USER", FALSE); 1473 define('USERID', 0); 1474 define("USERTHEME", FALSE); 1475 define("ADMIN", FALSE); 1476 define("GUEST", TRUE); 1477 define('USERCLASS', ''); 1478 define('USEREMAIL', ''); 1479 } 1480 else 1481 { 1482 list($uid, $upw)=(isset($_COOKIE[$pref['cookie_name']]) && $_COOKIE[$pref['cookie_name']] ? explode(".", $_COOKIE[$pref['cookie_name']]) : explode(".", $_SESSION[$pref['cookie_name']])); 1483 1484 if (empty($uid) || empty($upw)) 1485 { 1486 cookie($pref['cookie_name'], "", (time() - 2592000)); 1487 $_SESSION[$pref['cookie_name']] = ""; 1488 session_destroy(); 1489 define("ADMIN", FALSE); 1490 define("USER", FALSE); 1491 define('USERID', 0); 1492 define("USERCLASS", ""); 1493 define('USERCLASS_LIST', class_list()); 1494 define("LOGINMESSAGE",CORE_LAN10."<br /><br />"); 1495 return (FALSE); 1496 } 1497 1498 $result = get_user_data($uid); 1499 if(is_array($result) && md5($result['user_password']) == $upw) 1500 { 1501 define("USERID", $result['user_id']); 1502 define("USERNAME", $result['user_name']); 1503 define("USERURL", (isset($result['user_homepage']) ? $result['user_homepage'] : false)); 1504 define("USEREMAIL", $result['user_email']); 1505 define("USER", TRUE); 1506 define("USERCLASS", $result['user_class']); 1507 define("USERREALM", $result['user_realm']); 1508 define("USERVIEWED", $result['user_viewed']); 1509 define("USERIMAGE", $result['user_image']); 1510 define("USERSESS", $result['user_sess']); 1511 1512 $update_ip = ($result['user_ip'] != USERIP ? ", user_ip = '".USERIP."'" : ""); 1513 1514 if($result['user_currentvisit'] + 3600 < time() || !$result['user_lastvisit']) 1515 { 1516 $result['user_lastvisit'] = $result['user_currentvisit']; 1517 $result['user_currentvisit'] = time(); 1518 $sql->db_Update("user", "user_visits = user_visits + 1, user_lastvisit = '{$result['user_lastvisit']}', user_currentvisit = '{$result['user_currentvisit']}', user_viewed = ''{$update_ip} WHERE user_id='".USERID."' "); 1519 } 1520 else 1521 { 1522 $result['user_currentvisit'] = time(); 1523 $sql->db_Update("user", "user_currentvisit = '{$result['user_currentvisit']}'{$update_ip} WHERE user_id='".USERID."' "); 1524 } 1525 1526 $currentUser = $result; 1527 $currentUser['user_realname'] = $result['user_login']; // Used by force_userupdate 1528 define("USERLV", $result['user_lastvisit']); 1529 1530 if ($result['user_ban'] == 1) { exit; } 1531 1532 if ($result['user_admin']) 1533 { 1534 define('ADMIN', TRUE); 1535 define('ADMINID', $result['user_id']); 1536 define('ADMINNAME', $result['user_name']); 1537 define('ADMINPERMS', $result['user_perms']); 1538 define('ADMINEMAIL', $result['user_email']); 1539 define('ADMINPWCHANGE', $result['user_pwchange']); 1540 } 1541 else 1542 { 1543 define('ADMIN', FALSE); 1544 } 1545 1546 $user_pref = unserialize($result['user_prefs']); 1547 1548 $tempClasses = class_list(); 1549 if (check_class(varset($pref['allow_theme_select'],FALSE), $tempClasses)) 1550 { // User can set own theme 1551 if (isset($_POST['settheme'])) 1552 { 1553 $user_pref['sitetheme'] = ($pref['sitetheme'] == $_POST['sitetheme'] ? "" : $_POST['sitetheme']); 1554 save_prefs('user'); 1555 } 1556 } 1557 elseif (isset($user_pref['sitetheme'])) 1558 { // User obviously no longer allowed his own theme - clear it 1559 unset($user_pref['sitetheme']); 1560 save_prefs('user'); 1561 } 1562 1563 1564 define("USERTHEME", (isset($user_pref['sitetheme']) && file_exists(e_THEME.$user_pref['sitetheme']."/theme.php") ? $user_pref['sitetheme'] : FALSE)); 1565 // global $ADMIN_DIRECTORY, $PLUGINS_DIRECTORY; Don't look very necessary 1566 } 1567 else 1568 { 1569 define("USER", FALSE); 1570 define('USERID', 0); 1571 define("USERTHEME", FALSE); 1572 define("ADMIN", FALSE); 1573 define("CORRUPT_COOKIE", TRUE); 1574 define("USERCLASS", ""); 1575 } 1576 } 1577 1578 define('USERCLASS_LIST', class_list()); 1579 define('e_CLASS_REGEXP', "(^|,)(".str_replace(",", "|", USERCLASS_LIST).")(,|$)"); 1580 1581 if(USER) 1582 { 1583 define('POST_REFERER', md5($currentUser['user_password'].$currentUser['user_lastvisit'].USERCLASS_LIST)); 1584 } 1585 else 1586 { 1587 define('POST_REFERER', ''); 1588 } 1589 if(isset($_POST['__referer']) && $_POST['__referer'] != POST_REFERER) { 1590 header('location:'.e_BASE.'index.php'); 1591 exit; 1592 } 1593 1594 } 1595 1596 $sql->db_Mark_Time('Start: Go online'); 1597 if(isset($pref['track_online']) && $pref['track_online']) { 1598 $e_online->online($pref['track_online'], $pref['flood_protect']); 1599 } 1600 1601 function cookie($name, $value, $expire=0, $path = "/", $domain = "", $secure = 0) { 1602 setcookie($name, $value, $expire, $path, $domain, $secure); 1603 } 1604 1605 // 1606 // Use these to combine isset() and use of the set value. or defined and use of a constant 1607 // i.e. to fix if($pref['foo']) ==> if ( varset($pref['foo']) ) will use the pref, or ''. 1608 // Can set 2nd param to any other default value you like (e.g. false, 0, or whatever) 1609 // $testvalue adds additional test of the value (not just isset()) 1610 // Examples: 1611 // $something = pref; // Bug if pref not set ==> $something = varset(pref); 1612 // $something = isset(pref) ? pref : ""; ==> $something = varset(pref); 1613 // $something = isset(pref) ? pref : default; ==> $something = varset(pref,default); 1614 // $something = isset(pref) && pref ? pref : default; ==> use varsettrue(pref,default) 1615 // 1616 function varset(&$val,$default='') { 1617 if (isset($val)) { 1618 return $val; 1619 } 1620 return $default; 1621 } 1622 function defset($str,$default='') { 1623 if (defined($str)) { 1624 return constant($str); 1625 } 1626 return $default; 1627 } 1628 1629 // 1630 // These variants are like the above, but only return the value if both set AND 'true' 1631 // 1632 function varsettrue(&$val,$default='') { 1633 if (isset($val) && $val) return $val; 1634 return $default; 1635 } 1636 function defsettrue($str,$default='') { 1637 if (defined($str) && constant($str)) return constant($str); 1638 return $default; 1639 } 1640 1641 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// 1642 function message_handler($mode, $message, $line = 0, $file = "") { 1643 e107_require_once(e_HANDLER."message_handler.php"); 1644 show_emessage($mode, $message, $line, $file); 1645 } 1646 1647 // ----------------------------------------------------------------------------- 1648 function table_exists($check) { 1649 if (!$GLOBALS['mySQLtablelist']) { 1650 $tablist=mysql_list_tables($GLOBALS['mySQLdefaultdb']); 1651 while (list($temp) = mysql_fetch_array($tablist)) { 1652 $GLOBALS['mySQLtablelist'][] = $temp; 1653 } 1654 } 1655 1656 $mltable=MPREFIX.strtolower($check); 1657 1658 foreach ($GLOBALS['mySQLtablelist'] as $lang) { 1659 if (strpos($lang, $mltable) !== FALSE) { 1660 return TRUE; 1661 } 1662 } 1663 } 1664 1665 function class_list($uid = '') { 1666 $clist=array(); 1667 1668 if ($uid == '') 1669 { 1670 if (USER === TRUE) 1671 { 1672 if(USERCLASS) 1673 { 1674 $clist=explode(',', USERCLASS); 1675 } 1676 $clist[]=e_UC_MEMBER; 1677 if (ADMIN === TRUE) { 1678 $clist[] = e_UC_ADMIN; 1679 } 1680 if (getperms('0')) { 1681 $clist[] = e_UC_MAINADMIN; 1682 } 1683 } else { 1684 $clist[] = e_UC_GUEST; 1685 } 1686 $clist[]=e_UC_READONLY; 1687 $clist[]=e_UC_PUBLIC; 1688 return implode(',', $clist); 1689 } 1690 } 1691 1692 // --------------------------------------------------------------------------- 1693 function e107_include($fname) { 1694 global $e107_debug; 1695 $ret = ($e107_debug ? include($fname) : @include($fname)); 1696 return $ret; 1697 } 1698 1699 function e107_include_once($fname) { 1700 global $e107_debug; 1701 if(is_readable($fname)){ 1702 $ret = (!$e107_debug)? @include_once($fname) : include_once($fname); 1703 } 1704 return (isset($ret)) ? $ret : ""; 1705 } 1706 1707 function e107_require_once($fname) { 1708 global $e107_debug; 1709 $ret = ($e107_debug ? require_once($fname) : @require_once($fname)); 1710 return $ret; 1711 } 1712 1713 function e107_require($fname) { 1714 global $e107_debug; 1715 $ret = ($e107_debug ? require($fname) : @require($fname)); 1716 return $ret; 1717 } 1718 1719 function include_lan($path, $force = false) 1720 { 1721 if ( ! is_readable($path)) 1722 { 1723 $path = str_replace(e_LANGUAGE, 'English', $path); 1724 } 1725 $ret = ($force) ? e107_include($path) : e107_include_once($path); 1726 return (isset($ret)) ? $ret : ''; 1727 } 1728 1729 if(!function_exists("print_a")) 1730 { 1731 function print_a($var, $return = false) 1732 { 1733 $charset = "utf-8"; 1734 if(defined("CHARSET")) 1735 { 1736 $charset = CHARSET; 1737 } 1738 if(!$return) 1739 { 1740 echo '<pre>'.htmlspecialchars(print_r($var, true), ENT_QUOTES, $charset).'</pre>'; 1741 return true; 1742 } 1743 else 1744 { 1745 return '<pre>'.htmlspecialchars(print_r($var, true), ENT_QUOTES, $charset).'</pre>'; 1746 } 1747 } 1748 } 1749 1750 1751 // Check that all required user fields (including extended fields) are valid. 1752 // Return TRUE if update required 1753 function force_userupdate() 1754 { 1755 global $sql,$pref,$currentUser; 1756 1757 if (e_PAGE == "usersettings.php" || strpos(e_SELF, ADMINDIR) == TRUE || (defined("FORCE_USERUPDATE") && (FORCE_USERUPDATE == FALSE))) 1758 { 1759 return FALSE; 1760 } 1761 1762 $signup_option_names = array("realname", "signature", "image", "timezone", "class"); 1763 1764 foreach($signup_option_names as $key => $value) 1765 { 1766 if ($pref['signup_option_'.$value] == 2 && !$currentUser['user_'.$value]) 1767 { 1768 return TRUE; 1769 } 1770 } 1771 1772 if (!varset($pref['disable_emailcheck'],TRUE) && !trim($currentUser['user_email'])) return TRUE; 1773 1774 if($sql -> db_Select('user_extended_struct', 'user_extended_struct_applicable, user_extended_struct_write, user_extended_struct_name, user_extended_struct_type', 'user_extended_struct_required = 1 AND user_extended_struct_applicable != '.e_UC_NOBODY)) 1775 { 1776 while($row = $sql -> db_Fetch()) 1777 { 1778 if (!check_class($row['user_extended_struct_applicable'])) { continue; } // Must be applicable to this user class 1779 if (!check_class($row['user_extended_struct_write'])) { continue; } // And user must be able to change it 1780 $user_extended_struct_name = "user_{$row['user_extended_struct_name']}"; 1781 if ((!$currentUser[$user_extended_struct_name]) || (($row['user_extended_struct_type'] == 7) && ($currentUser[$user_extended_struct_name] == '0000-00-00'))) 1782 { 1783 return TRUE; 1784 } 1785 } 1786 } 1787 return FALSE; 1788 } 1789 1790 class error_handler { 1791 1792 var $errors; 1793 var $debug = false; 1794 1795 function error_handler() { 1796 // 1797 // This is initialized before the current debug level is known 1798 // 1799 if ((isset($_SERVER['QUERY_STRING']) && strpos($_SERVER['QUERY_STRING'], 'debug=') !== FALSE) || isset($_COOKIE['e107_debug_level'])) { 1800 $this->debug = true; 1801 error_reporting(E_ALL); 1802 } else { 1803 error_reporting(E_ERROR | E_PARSE); 1804 } 1805 } 1806 1807 function handle_error($type, $message, $file, $line, $context) { 1808 $startup_error = (!defined('E107_DEBUG_LEVEL')); // Error before debug system initialized 1809 switch($type) { 1810 case E_NOTICE: 1811 if ($startup_error || E107_DBG_ALLERRORS) { 1812 $error['short'] = "Notice: {$message}, Line {$line} of {$file}<br />\n"; 1813 $trace = debug_backtrace(); 1814 $backtrace[0] = (isset($trace[1]) ? $trace[1] : ""); 1815 $backtrace[1] = (isset($trace[2]) ? $trace[2] : ""); 1816 $error['trace'] = $backtrace; 1817 $this->errors[] = $error; 1818 } 1819 break; 1820 case E_WARNING: 1821 if ($startup_error || E107_DBG_BASIC) { 1822 $error['short'] = "Warning: {$message}, Line {$line} of {$file}<br />\n"; 1823 $trace = debug_backtrace(); 1824 $backtrace[0] = (isset($trace[1]) ? $trace[1] : ""); 1825 $backtrace[1] = (isset($trace[2]) ? $trace[2] : ""); 1826 $error['trace'] = $backtrace; 1827 $this->errors[] = $error; 1828 } 1829 break; 1830 case E_USER_ERROR: 1831 if ($this->debug == true) { 1832 $error['short'] = " Internal Error Message: {$message}, Line {$line} of {$file}<br />\n"; 1833 $trace = debug_backtrace(); 1834 $backtrace[0] = (isset($trace[1]) ? $trace[1] : ""); 1835 $backtrace[1] = (isset($trace[2]) ? $trace[2] : ""); 1836 $error['trace'] = $backtrace; 1837 $this->errors[] = $error; 1838 } 1839 default: 1840 return true; 1841 break; 1842 } 1843 } 1844 1845 function return_errors() { 1846 $index = 0; $colours[0] = "#C1C1C1"; $colours[1] = "#B6B6B6"; 1847 $ret = "" ; 1848 if (E107_DBG_ERRBACKTRACE) 1849 { 1850 foreach ($this->errors as $key => $value) { 1851 $ret .= "\t<tr>\n\t\t<td class='forumheader3' >{$value['short']}</td><td><input class='button' type ='button' style='cursor: hand; cursor: pointer;' size='30' value='Back Trace' onclick=\"expandit('bt_{$key}')\" /></td>\n\t</tr>\n"; 1852 $ret .= "\t<tr>\n<td style='display: none;' colspan='2' id='bt_{$key}'>".print_a($value['trace'], true)."</td></tr>\n"; 1853 if($index == 0) { $index = 1; } else { $index = 0; } 1854 } 1855 } else { 1856 foreach ($this->errors as $key => $value) 1857 { 1858 $ret .= "<tr class='forumheader3'><td>{$value['short']}</td></tr>\n"; 1859 } 1860 } 1861 1862 return ($ret) ? "<table class='fborder'>\n".$ret."</table>" : ""; 1863 } 1864 1865 function trigger_error($information, $level) { 1866 trigger_error($information); 1867 } 1868 } 1869 1870 /** 1871 * Strips slashes from a var if magic_quotes_gqc is enabled 1872 * 1873 * @param mixed $data 1874 * @return mixed 1875 */ 1876 function strip_if_magic($data) { 1877 if (MAGIC_QUOTES_GPC == true) { 1878 return array_stripslashes($data); 1879 } else { 1880 return $data; 1881 } 1882 } 1883 1884 /** 1885 * Strips slashes from a string or an array 1886 * 1887 * @param mixed $value 1888 * @return mixed 1889 */ 1890 function array_stripslashes($data) { 1891 return is_array($data) ? array_map('array_stripslashes', $data) : stripslashes($data); 1892 } 1893 1894 $sql->db_Mark_Time('(After class2)'); 1895 1896 1897 function e107_ini_set($var, $value) 1898 { 1899 if (function_exists('ini_set')) 1900 { 1901 return ini_set($var, $value); 1902 } 1903 return FALSE; 1904 } 1905 1906 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Aug 3 00:19:13 2010 |