| [ PHPXref.com ] | [ Generated: Tue Jul 29 09:36:16 2008 ] | [ Phorum 5.2.8 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 //////////////////////////////////////////////////////////////////////////////// 3 // // 4 // Copyright (C) 2008 Phorum Development Team // 5 // http://www.phorum.org // 6 // // 7 // This program is free software. You can redistribute it and/or modify // 8 // it under the terms of either the current Phorum License (viewable at // 9 // phorum.org) or the Phorum License that was distributed with this file // 10 // // 11 // This program is distributed in the hope that it will be useful, // 12 // but WITHOUT ANY WARRANTY, without even the implied warranty of // 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // 14 // // 15 // You should have received a copy of the Phorum License // 16 // along with this program. // 17 // // 18 //////////////////////////////////////////////////////////////////////////////// 19 20 // Check that this file is not loaded directly. 21 if ( basename( __FILE__ ) == basename( $_SERVER["PHP_SELF"] ) ) exit(); 22 23 24 // ---------------------------------------------------------------------- 25 // Initialize variables and constants and load required libraries 26 // ---------------------------------------------------------------------- 27 28 // the Phorum version 29 define( "PHORUM", "5.2.8" ); 30 31 // our database schema version in format of year-month-day-serial 32 define( "PHORUM_SCHEMA_VERSION", "2007031400" ); 33 34 // our database patch level in format of year-month-day-serial 35 define( "PHORUM_SCHEMA_PATCHLEVEL", "2008062500" ); 36 37 // The required version of the Phorum PHP extension. This version is updated 38 // if internal changes of Phorum require the extension library to be upgraded 39 // for compatibility. We follow PHP's schema of using the date at which an 40 // important internal change was done as the extension's version number. 41 // This version number should match the one in the php_phorum.h header file 42 // for the module. 43 define( "PHORUM_EXTENSION_VERSION", "20070522" ); 44 45 // Initialize the global $PHORUM variable, which holds all Phorum data. 46 global $PHORUM; 47 $PHORUM = array 48 ( 49 // The DATA member holds the template variables. 50 'DATA' => array( 51 'GET_VARS' => array(), 52 'POST_VARS' => '' 53 ), 54 55 // The TMP member hold template {DEFINE ..} definitions, temporary 56 // arrays and such in template code. 57 'TMP' => array(), 58 59 // Query arguments. 60 'args' => array(), 61 62 // The active forum id. 63 'forum_id' => 0 64 ); 65 66 // Load all constants from ./include/constants.php 67 require_once ( "./include/constants.php" ); 68 69 // Load the API code that is required for all pages. 70 require_once ("./include/api/base.php"); 71 require_once ("./include/api/user.php"); 72 73 74 // ---------------------------------------------------------------------- 75 // Load the database layer and setup a connection 76 // ---------------------------------------------------------------------- 77 78 // Get the database settings. It is possible to override the database 79 // settings by defining a global variable $PHORUM_ALT_DBCONFIG which 80 // overrides $PHORUM["DBCONFIG"] (from include/db/config.php). This is 81 // only allowed if "PHORUM_WRAPPER" is defined and if the alternative 82 // configuration wasn't passed as a request parameter (which could 83 // set $PHORUM_ALT_DBCONFIG if register_globals is enabled for PHP). 84 if (empty( $GLOBALS["PHORUM_ALT_DBCONFIG"] ) || $GLOBALS["PHORUM_ALT_DBCONFIG"]==$_REQUEST["PHORUM_ALT_DBCONFIG"] || !defined("PHORUM_WRAPPER")) { 85 86 // Backup display_errors setting. 87 $orig = ini_get("display_errors"); 88 @ini_set("display_errors", 0); 89 90 // Use output buffering so we don't get header errors if there's 91 // some additional output in the database config file (e.g. a UTF-8 92 // byte order marker). 93 ob_start(); 94 95 // Load configuration. 96 if (! include_once( "./include/db/config.php" )) { 97 print '<html><head><title>Phorum error</title></head><body>'; 98 print '<h2>Phorum database configuration error</h2>'; 99 100 // No database configuration found. 101 if (!file_exists("./include/db/config.php")) { ?> 102 Phorum has been installed on this server, but the configuration<br/> 103 for the database connection has not yet been made. Please read<br/> 104 <a href="docs/install.txt">docs/install.txt</a> for installation 105 instructions. <?php 106 } else { 107 $fp = fopen("./include/db/config.php", "r"); 108 // Unable to read the configuration file. 109 if (!$fp) { ?> 110 A database configuration file was found in 111 ./include/db/config.php,<br/>but Phorum was unable to read it. 112 Please check the file permissions<br/>for this file. <?php 113 // Unknown error. 114 } else { 115 fclose($fp); ?> 116 A database configuration file was found in 117 ./include/dbconfig.php,<br/>but it could not be loaded. 118 It possibly contains one or more errors.<br/>Please check 119 your configuration file. <?php 120 } 121 } 122 123 print '</body></html>'; 124 exit(1); 125 } 126 127 // Clean up the output buffer. 128 ob_end_clean(); 129 130 // Restore original display_errors setting. 131 @ini_set("display_errors", $orig); 132 } else { 133 $PHORUM["DBCONFIG"] = $GLOBALS["PHORUM_ALT_DBCONFIG"]; 134 } 135 136 // Backward compatbility: the "mysqli" layer was merged with the "mysql" 137 // layer, but people might still be using "mysqli" as their configured 138 // database type. 139 if ($PHORUM["DBCONFIG"]["type"] == "mysqli" && 140 !file_exists("./include/db/mysqli.php")) { 141 $PHORUM["DBCONFIG"]["type"] = "mysql"; 142 } 143 144 // Load the database layer. 145 $PHORUM['DBCONFIG']['type'] = basename($PHORUM['DBCONFIG']['type']); 146 require_once( "./include/db/{$PHORUM['DBCONFIG']['type']}.php" ); 147 148 // Try to setup a connection to the database. 149 if(!phorum_db_check_connection()){ 150 if(isset($PHORUM["DBCONFIG"]["down_page"])){ 151 phorum_redirect_by_url($PHORUM["DBCONFIG"]["down_page"]); 152 exit(); 153 } else { 154 echo "The database connection failed. Please check your database configuration in include/db/config.php. If the configuration is okay, check if the database server is running."; 155 exit(); 156 } 157 } 158 159 160 // ---------------------------------------------------------------------- 161 // Load and process the Phorum settings 162 // ---------------------------------------------------------------------- 163 164 // Load the Phorum settings from the database. 165 phorum_db_load_settings(); 166 167 // For command line scripts, disable caching. 168 // The command line user is often different from the web server 169 // user, possibly causing permission problems on the cache. 170 if (defined('PHORUM_SCRIPT')) 171 { 172 $PHORUM['cache_banlists'] = 0; 173 $PHORUM['cache_css'] = 0; 174 $PHORUM['cache_javascript'] = 0; 175 $PHORUM['cache_layer'] = 0; 176 $PHORUM['cache_messages'] = 0; 177 $PHORUM['cache_newflags'] = 0; 178 $PHORUM['cache_rss'] = 0; 179 $PHORUM['cache_users'] = 0; 180 } 181 182 // If we have no private key for signing data, generate one now, 183 // but only if it's not a fresh install. 184 if ( isset($PHORUM['internal_version']) && $PHORUM['internal_version'] >= PHORUM_SCHEMA_VERSION && (!isset($PHORUM["private_key"]) || empty($PHORUM["private_key"]))) { 185 $chars = "0123456789!@#$%&abcdefghijklmnopqr". 186 "stuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 187 $private_key = ""; 188 for ($i = 0; $i<40; $i++) { 189 $private_key .= substr($chars, rand(0, strlen($chars)-1), 1); 190 } 191 $PHORUM["private_key"] = $private_key; 192 phorum_db_update_settings(array("private_key" => $PHORUM["private_key"])); 193 } 194 195 // Determine the caching layer to load. 196 if(!isset($PHORUM['cache_layer']) || empty($PHORUM['cache_layer'])) { 197 $PHORUM['cache_layer'] = 'file'; 198 } else { 199 // Safeguard for wrongly selected cache-layers. 200 // Falling back to file-layer if descriptive functions aren't existing. 201 if($PHORUM['cache_layer'] == 'memcached' && !function_exists('memcache_connect')) { 202 $PHORUM['cache_layer'] = 'file'; 203 } elseif($PHORUM['cache_layer'] == 'apc' && !function_exists('apc_fetch')) { 204 $PHORUM['cache_layer'] = 'file'; 205 } 206 } 207 208 // Load the caching-layer. You can specify a different one in the settings. 209 // One caching layer *needs* to be loaded. 210 $PHORUM['cache_layer'] = basename($PHORUM['cache_layer']); 211 require_once( "./include/cache/$PHORUM[cache_layer].php" ); 212 213 // Try to load the Phorum PHP extension, if has been enabled in the admin. 214 // As a precaution, never load it from the admin code (so the extension 215 // support can be disabled at all time if something unexpected happens). 216 if (!defined('PHORUM_ADMIN') && !empty($PHORUM["php_phorum_extension"])) 217 { 218 // Load the extension library. 219 if (! extension_loaded('phorum')) { 220 @dl('phorum.so'); 221 } 222 223 // Check if the version of the PHP extension matches the 224 // one required by the Phorum installation. 225 if (extension_loaded('phorum')) { 226 $ext_ver = phorum_ext_version(); 227 if ($ext_ver != PHORUM_EXTENSION_VERSION) { 228 // The version does not match. Disable the extension support. 229 phorum_db_update_settings(array("php_phorum_extension" => 0)); 230 print "<html><head><title>Phorum Extension Error</title></head><body>"; 231 print "<h1>Phorum Extension Error</h1>" . 232 "The Phorum PHP extension was loaded, but its version<br/>" . 233 "does not match the Phorum version. Therefore, the<br/>" . 234 "extension has now be disabled. Reload this page to continue."; 235 print "</body></html>"; 236 exit(0); 237 } 238 } 239 } 240 241 // Setup phorum_get_url(): this function is used for generating all Phorum 242 // related URL's. It is loaded conditionally, to make it possible to override 243 // it from the phorum PHP extension. 244 if (!function_exists('phorum_get_url')) { 245 require_once ("./include/phorum_get_url.php"); 246 } 247 248 // Setup the template path and http path. These are put in a variable to give 249 // module authors a chance to override them. This can be especially useful 250 // for distibuting a module that contains a full Phorum template as well. 251 $PHORUM['template_path'] = './templates'; 252 $PHORUM['template_http_path'] = $PHORUM['http_path'].'/templates'; 253 254 // ---------------------------------------------------------------------- 255 // Parse and handle request data 256 // ---------------------------------------------------------------------- 257 258 // Thanks a lot for magic quotes :-/ 259 // In PHP6, magic quotes are (finally) removed, so we have to check for 260 // the get_magic_quotes_gpc() function here. The "@" is for suppressing 261 // deprecation warnings that are spawned by PHP 5.3 and higher when 262 // using the get_magic_quotes_gpc() function. 263 if ( function_exists('get_magic_quotes_gpc') && 264 @get_magic_quotes_gpc() && count( $_REQUEST ) ) { 265 foreach( $_POST as $key => $value ) { 266 if ( !is_array( $value ) ) 267 $_POST[$key] = stripslashes( $value ); 268 else 269 $_POST[$key] = phorum_recursive_stripslashes( $value ); 270 } 271 foreach( $_GET as $key => $value ) { 272 if ( !is_array( $value ) ) 273 $_GET[$key] = stripslashes( $value ); 274 else 275 $_GET[$key] = phorum_recursive_stripslashes( $value ); 276 } 277 } 278 279 /* 280 * [hook] 281 * parse_request 282 * 283 * [description] 284 * This hook gives modules a chance to tweak the request environment, 285 * before Phorum parses and handles the request data. For tweaking the 286 * request environment, some of the options are: 287 * <ul> 288 * <li> 289 * Changing the value of <literal>$_REQUEST["forum_id"]</literal> 290 * to override the used forum_id. 291 * </li> 292 * <li> 293 * Changing the value of <literal>$_SERVER["QUERY_STRING"]</literal> 294 * or setting the global override variable 295 * <literal>$PHORUM_CUSTOM_QUERY_STRING</literal> to feed Phorum a 296 * different query string than the one provided by the webserver. 297 * </li> 298 * </ul> 299 * Tweaking the request data should result in data that Phorum can handle. 300 * 301 * [category] 302 * Request initialization 303 * 304 * [when] 305 * Right before Phorum runs the request parsing code in 306 * <filename>common.php</filename>. 307 * 308 * [input] 309 * No input. 310 * 311 * [output] 312 * No output. 313 * 314 * [example] 315 * <hookcode> 316 * function phorum_mod_foo_parse_request() 317 * { 318 * // Override the query string. 319 * global $PHORUM_CUSTOM_QUERY_STRING 320 * $PHORUM_CUSTOM_QUERY_STRING = "1,some,phorum,query=string"; 321 * 322 * // Override the forum_id. 323 * $_SERVER['forum_id'] = "1234"; 324 * } 325 * </hookcode> 326 */ 327 if (isset($PHORUM["hooks"]["parse_request"])) { 328 phorum_hook("parse_request"); 329 } 330 331 // Get the forum id if set using a request parameter. 332 if ( isset( $_REQUEST["forum_id"] ) && is_numeric( $_REQUEST["forum_id"] ) ) { 333 $PHORUM["forum_id"] = $_REQUEST["forum_id"]; 334 } 335 336 // Look for and parse the QUERY_STRING. 337 // This only applies to URLs that we create using phorum_get_url(). 338 // Scripts using data originating from standard HTML forms (e.g. search) 339 // will have to use $_GET or $_POST. 340 if (!defined("PHORUM_ADMIN") && (isset($_SERVER["QUERY_STRING"]) || isset($GLOBALS["PHORUM_CUSTOM_QUERY_STRING"]))) 341 { 342 $Q_STR = empty( $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"] ) 343 ? $_SERVER["QUERY_STRING"] 344 : $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"]; 345 346 // ignore stuff past a # 347 if ( strstr( $Q_STR, "#" ) ) list( $Q_STR, $other ) = explode( "#", $Q_STR, 2 ); 348 349 // explode it on comma 350 $PHORUM["args"] = $Q_STR == '' ? array() : explode( ",", $Q_STR ); 351 352 // check for any assigned values 353 if ( strstr( $Q_STR, "=" ) ) { 354 foreach( $PHORUM["args"] as $key => $arg ) { 355 356 // if an arg has an = create an element in args 357 // with left part as key and right part as value 358 if ( strstr( $arg, "=" ) ) { 359 list( $var, $value ) = explode( "=", $arg, 2 ); 360 // get rid of the numbered arg, it is useless. 361 unset( $PHORUM["args"][$key] ); 362 // add the named arg 363 // TODO: Why is urldecode() used here? IMO this can be omitted. 364 $PHORUM["args"][$var] = urldecode( $value ); 365 } 366 } 367 } 368 369 // Handle path info based URLs for the file script. 370 if (phorum_page == 'file' && 371 !empty($_SERVER['PATH_INFO']) && 372 preg_match('!^/(download/)?(\d+)/(\d+)/!', $_SERVER['PATH_INFO'], $m)) 373 { 374 $PHORUM['args']['file'] = $m[3]; 375 $PHORUM['args'][0] = $PHORUM['forum_id'] = $m[2]; 376 $PHORUM['args']['download'] = empty($m[1]) ? 0 : 1; 377 } 378 379 // set forum_id if not set already by a forum_id request parameter 380 if ( empty( $PHORUM["forum_id"] ) && isset( $PHORUM["args"][0] ) ) { 381 $PHORUM["forum_id"] = ( int )$PHORUM["args"][0]; 382 } 383 } 384 385 // set the forum_id to 0 if not set by now. 386 if ( empty( $PHORUM["forum_id"] ) ) $PHORUM["forum_id"] = 0; 387 388 /* 389 * [hook] 390 * common_pre 391 * 392 * [description] 393 * This hook can be used for overriding settings that were loaded and 394 * setup at the start of the <filename>common.php</filename> script. 395 * If you want to dynamically assign and tweak certain settings, then 396 * this is the designated hook to use for that.<sbr/> 397 * <sbr/> 398 * Because the hook was put after the request parsing phase, you can 399 * make use of the request data that is stored in the global variables 400 * <literal>$PHORUM['forum_id']</literal> and 401 * <literal>$PHORUM['args']</literal>. 402 * 403 * [category] 404 * Request initialization 405 * 406 * [when] 407 * Right after loading the settings from the database and parsing the 408 * request, but before making descisions on user, language and template. 409 * 410 * [input] 411 * No input. 412 * 413 * [output] 414 * No output. 415 * 416 * [example] 417 * <hookcode> 418 * function phorum_mod_foo_common_pre() 419 * { 420 * global $PHORUM; 421 * 422 * // If we are in the forum with id = 10, we set the administrator 423 * // email information to a different value than the one configured 424 * // in the general settings. 425 * if ($PHORUM["forum_id"] == 10) 426 * { 427 * $PHORUM["system_email_from_name"] = "John Doe"; 428 * $PHORUM["system_email_from_address"] = "John.Doe@example.com"; 429 * } 430 * } 431 * </hookcode> 432 */ 433 if (isset($PHORUM["hooks"]["common_pre"])) { 434 phorum_hook("common_pre", ""); 435 } 436 437 // ---------------------------------------------------------------------- 438 // Setup data for standard (not admin) pages 439 // ---------------------------------------------------------------------- 440 441 // TODO: Do we ever need this in admin? If not, it can go inside the block. 442 // stick some stuff from the settings into the DATA member 443 $PHORUM["DATA"]["TITLE"] = ( isset( $PHORUM["title"] ) ) ? $PHORUM["title"] : ""; 444 $PHORUM["DATA"]["DESCRIPTION"] = ( isset( $PHORUM["description"] ) ) ? $PHORUM["description"] : ""; 445 $PHORUM["DATA"]["HTML_TITLE"] = ( !empty( $PHORUM["html_title"] ) ) ? $PHORUM["html_title"] : $PHORUM["DATA"]["TITLE"]; 446 $PHORUM["DATA"]["HEAD_TAGS"] = ( isset( $PHORUM["head_tags"] ) ) ? $PHORUM["head_tags"] : ""; 447 $PHORUM["DATA"]["FORUM_ID"] = $PHORUM["forum_id"]; 448 449 if ( !defined( "PHORUM_ADMIN" ) ) { 450 451 // if the Phorum is disabled, display a message. 452 if(isset($PHORUM["status"]) && $PHORUM["status"]==PHORUM_MASTER_STATUS_DISABLED){ 453 if(!empty($PHORUM["disabled_url"])){ 454 header("Location: ".$PHORUM["disabled_url"]); 455 exit(); 456 } else { 457 echo "This Phorum is currently disabled. Please contact the web site owner at ".$PHORUM['system_email_from_address']." for more information.\n"; 458 exit(); 459 } 460 } 461 462 // checking for upgrade or new install 463 if ( !isset( $PHORUM['internal_version'] ) ) { 464 echo "<html><head><title>Phorum error</title></head><body>No Phorum settings were found. Either this is a brand new installation of Phorum or there is a problem with your database server. If this is a new install, please <a href=\"admin.php\">go to the admin page</a> to complete the installation. If not, check your database server.</body></html>"; 465 exit(); 466 } elseif ( $PHORUM['internal_version'] < PHORUM_SCHEMA_VERSION || 467 !isset($PHORUM['internal_patchlevel']) || 468 $PHORUM['internal_patchlevel'] < PHORUM_SCHEMA_PATCHLEVEL ) { 469 if(isset($PHORUM["DBCONFIG"]["upgrade_page"])){ 470 phorum_redirect_by_url($PHORUM["DBCONFIG"]["upgrade_page"]); 471 exit(); 472 } 473 echo "<html><head><title>Upgrade notification</title></head><body>It looks like you have installed a new version of Phorum.<br/>Please visit the admin page to complete the upgrade!</body></html>"; 474 exit(); 475 } 476 477 // load the forum's settings 478 if(!empty($PHORUM["forum_id"])){ 479 480 $forum_settings = phorum_db_get_forums( $PHORUM["forum_id"] ); 481 482 if ( !isset($forum_settings[$PHORUM["forum_id"]]) ) 483 { 484 /* 485 * [hook] 486 * common_no_forum 487 * 488 * [description] 489 * This hook is called in case a forum_id is requested for 490 * an unknown or inaccessible forum. It can be used for 491 * doing things like logging the bad requests or fully 492 * overriding Phorum's default behavior for these cases 493 * (which is redirecting the user back to the index page). 494 * 495 * [category] 496 * Request initialization 497 * 498 * [when] 499 * In <filename>common.php</filename>, right after detecting 500 * that a requested forum does not exist or is inaccessible 501 * and right before redirecting the user back to the Phorum 502 * index page. 503 * 504 * [input] 505 * No input. 506 * 507 * [output] 508 * No output. 509 * 510 * [example] 511 * <hookcode> 512 * function phorum_mod_foo_common_no_forum() 513 * { 514 * // Return a 404 Not found error instead of redirecting 515 * // the user back to the index. 516 * header("HTTP/1.0 404 Not Found"); 517 * print "<html><head>\n"; 518 * print " <title>404 - Not Found</title>\n"; 519 * print "</head><body>"; 520 * print " <h1>404 - Forum Not Found</h1>"; 521 * print "</body></html>"; 522 * exit(); 523 * } 524 * </hookcode> 525 */ 526 if (isset($PHORUM["hooks"]["common_no_forum"])) { 527 phorum_hook("common_no_forum", ""); 528 } 529 530 phorum_redirect_by_url( phorum_get_url( PHORUM_INDEX_URL ) ); 531 exit(); 532 } 533 534 $PHORUM = array_merge( $PHORUM, $forum_settings[$PHORUM["forum_id"]] ); 535 536 } elseif(isset($PHORUM["forum_id"]) && $PHORUM["forum_id"]==0){ 537 538 $PHORUM = array_merge( $PHORUM, $PHORUM["default_forum_options"] ); 539 540 // some hard settings are needed if we are looking at forum_id 0 541 $PHORUM['vroot']=0; 542 $PHORUM['parent_id']=0; 543 $PHORUM['active']=1; 544 $PHORUM['folder_flag']=1; 545 $PHORUM['cache_version']=0; 546 547 } 548 549 550 // handling vroots 551 if(!empty($PHORUM['vroot'])) { 552 $vroot_folders = phorum_db_get_forums($PHORUM['vroot']); 553 554 $PHORUM["title"] = $vroot_folders[$PHORUM['vroot']]['name']; 555 $PHORUM["DATA"]["TITLE"] = $PHORUM["title"]; 556 $PHORUM["DATA"]["HTML_TITLE"] = $PHORUM["title"]; 557 558 if($PHORUM['vroot'] == $PHORUM['forum_id']) { 559 // unset the forum-name if we are in the vroot-index 560 // otherwise the NAME and TITLE would be the same and still shown twice 561 unset($PHORUM['name']); 562 } 563 } 564 565 // stick some stuff from the settings into the DATA member 566 $PHORUM["DATA"]["NAME"] = ( isset( $PHORUM["name"] ) ) ? $PHORUM["name"] : ""; 567 $PHORUM["DATA"]["HTML_DESCRIPTION"] = ( isset( $PHORUM["description"] ) ) ? preg_replace("!\s+!", " ", $PHORUM["description"]) : ""; 568 $PHORUM["DATA"]["DESCRIPTION"] = strip_tags($PHORUM["DATA"]["HTML_DESCRIPTION"]); 569 // clean up some more stuff in the description without html 570 $search_arr = array('\'','"'); 571 $replace_arr = array('',''); 572 $PHORUM["DATA"]["DESCRIPTION"]=str_replace($search_arr,$replace_arr,$PHORUM["DATA"]["DESCRIPTION"]); 573 574 $PHORUM["DATA"]["ENABLE_PM"] = ( isset( $PHORUM["enable_pm"] ) ) ? $PHORUM["enable_pm"] : ""; 575 if ( !empty( $PHORUM["DATA"]["HTML_TITLE"] ) && !empty( $PHORUM["DATA"]["NAME"] ) ) { 576 $PHORUM["DATA"]["HTML_TITLE"] .= PHORUM_SEPARATOR; 577 } 578 $PHORUM["DATA"]["HTML_TITLE"] .= $PHORUM["DATA"]["NAME"]; 579 580 // Try to restore a user session. 581 if (phorum_api_user_session_restore(PHORUM_FORUM_SESSION)) 582 { 583 // if the user has overridden thread settings, change it here. 584 if ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) { 585 if ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_ON ) { 586 $PHORUM["threaded_list"] = true; 587 } elseif ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_OFF ) { 588 $PHORUM["threaded_list"] = false; 589 } 590 if ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_ON ) { 591 $PHORUM["threaded_read"] = 1; 592 } elseif ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_OFF ) { 593 $PHORUM["threaded_read"] = 0; 594 } elseif ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_HYBRID ) { 595 $PHORUM["threaded_read"] = 2; 596 } 597 } 598 599 // check if the user has new private messages 600 if (!empty($PHORUM["enable_new_pm_count"]) && 601 !empty($PHORUM["enable_pm"])) { 602 $PHORUM['user']['new_private_messages'] = 603 phorum_db_pm_checknew($PHORUM['user']['user_id']); 604 } 605 } 606 607 /* 608 * [hook] 609 * common_post_user 610 * 611 * [description] 612 * This hook gives modules a chance to override Phorum variables 613 * and settings, after the active user has been loaded. The settings 614 * for the active forum are also loaded before this hook is called, 615 * therefore this hook can be used for overriding general settings, 616 * forum settings and user settings. 617 * 618 * [category] 619 * Request initialization 620 * 621 * [when] 622 * Right after loading the data for the active user in 623 * <filename>common.php</filename>, but before deciding on the 624 * language and template to use. 625 * 626 * [input] 627 * No input. 628 * 629 * [output] 630 * No output. 631 * 632 * [example] 633 * <hookcode> 634 * function phorum_mod_foo_common_post_user() 635 * { 636 * global $PHORUM; 637 * 638 * // Switch the read mode for admin users to threaded. 639 * if ($PHORUM['user']['user_id'] && $PHORUM['user']['admin']) { 640 * $PHORUM['threaded_read'] = PHORUM_THREADED_ON; 641 * } 642 * 643 * // Disable "float_to_top" for anonymous users. 644 * if (!$PHORUM['user']['user_id']) { 645 * $PHORUM['float_to_top'] = 0; 646 * } 647 * } 648 * </hookcode> 649 */ 650 if (isset($PHORUM["hooks"]["common_post_user"])) { 651 phorum_hook("common_post_user", ""); 652 } 653 654 // only do those parts if the forum is not set to fixed view 655 if ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) { 656 657 // check for a template being passed on the url 658 // only use valid template names 659 if(!empty( $PHORUM["args"]["template"] ) ) { 660 $template = basename( $PHORUM["args"]["template"] ); 661 if ($template != '..') { 662 $PHORUM["template"] = $template; 663 } 664 } 665 666 // get the language file 667 if(isset( $PHORUM['user']['user_language'] ) && !empty($PHORUM['user']['user_language']) ) { 668 $PHORUM['language'] = $PHORUM['user']['user_language']; 669 } 670 671 if( isset( $PHORUM['user']['user_template'] ) && !empty($PHORUM['user']['user_template']) && 672 (!isset( $PHORUM["user_template"] ) || !empty($PHORUM['user_template'])) 673 ) { 674 $PHORUM['template'] = $PHORUM['user']['user_template']; 675 } 676 677 } 678 679 if ( !isset( $PHORUM["language"] ) || empty( $PHORUM["language"] ) || !file_exists( "./include/lang/$PHORUM[language].php" ) ) 680 $PHORUM["language"] = $PHORUM["default_forum_options"]["language"]; 681 if ( !file_exists("./include/lang/$PHORUM[language].php") ) { 682 $PHORUM["language"] = PHORUM_DEFAULT_LANGUAGE; 683 } 684 685 // Use output buffering so we don't get header errors if there's 686 // some additional output in the upcoming included files (e.g. UTF-8 687 // byte order markers). 688 ob_start(); 689 690 // Not loaded if we are running an external or scheduled script