punbb/include/common.php
author Dan
Wed, 11 Jul 2007 21:01:48 -0400
changeset 0 f9ffdbd96607
child 2 a8a21e1c7afa
permissions -rw-r--r--
Initial population
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     1
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     2
/***********************************************************************
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     3
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     4
  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     5
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     6
  This file is part of PunBB.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     7
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     8
  PunBB is free software; you can redistribute it and/or modify it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     9
  under the terms of the GNU General Public License as published
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    10
  by the Free Software Foundation; either version 2 of the License,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    11
  or (at your option) any later version.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    12
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    13
  PunBB is distributed in the hope that it will be useful, but
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    14
  WITHOUT ANY WARRANTY; without even the implied warranty of
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    16
  GNU General Public License for more details.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    17
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    18
  You should have received a copy of the GNU General Public License
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    19
  along with this program; if not, write to the Free Software
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    20
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    21
  MA  02111-1307  USA
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    22
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    23
************************************************************************/
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    24
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    25
// Enable DEBUG mode by removing // from the following line
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    26
//define('PUN_DEBUG', 1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    27
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    28
// This displays all executed queries in the page footer.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    29
// DO NOT enable this in a production environment!
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    30
//define('PUN_SHOW_QUERIES', 1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    31
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    32
if (!defined('PUN_ROOT'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    33
	exit('The constant PUN_ROOT must be defined and point to a valid PunBB installation root directory.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    34
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    35
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    36
// Load the functions script
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    37
require PUN_ROOT.'include/functions.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    38
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    39
// Reverse the effect of register_globals
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    40
unregister_globals();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    41
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    42
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    43
@include PUN_ROOT.'config.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    44
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    45
// If PUN isn't defined, config.php is missing or corrupt
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    46
if (!defined('PUN'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    47
	exit('The file \'config.php\' doesn\'t exist or is corrupt. Please run <a href="install.php">install.php</a> to install PunBB first.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    48
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    49
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    50
// Record the start time (will be used to calculate the generation time for the page)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    51
list($usec, $sec) = explode(' ', microtime());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    52
$pun_start = ((float)$usec + (float)$sec);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    53
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    54
// Make sure PHP reports all errors except E_NOTICE. PunBB supports E_ALL, but a lot of scripts it may interact with, do not.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    55
error_reporting(E_ALL ^ E_NOTICE);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    56
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    57
// Turn off magic_quotes_runtime
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    58
set_magic_quotes_runtime(0);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    59
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    60
// Strip slashes from GET/POST/COOKIE (if magic_quotes_gpc is enabled)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    61
if (get_magic_quotes_gpc())
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    62
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    63
	function stripslashes_array($array)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    64
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    65
		return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    66
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    67
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    68
	$_GET = stripslashes_array($_GET);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    69
	$_POST = stripslashes_array($_POST);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    70
	$_COOKIE = stripslashes_array($_COOKIE);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    71
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    72
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    73
// Seed the random number generator
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    74
mt_srand((double)microtime()*1000000);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    75
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    76
// If a cookie name is not specified in config.php, we use the default (punbb_cookie)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    77
if (empty($cookie_name))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    78
	$cookie_name = 'punbb_cookie';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    79
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    80
// Define a few commonly used constants
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    81
define('PUN_UNVERIFIED', 32000);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    82
define('PUN_ADMIN', 1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    83
define('PUN_MOD', 2);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    84
define('PUN_GUEST', 3);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    85
define('PUN_MEMBER', 4);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    86
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    87
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    88
// Load DB abstraction layer and connect
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    89
require PUN_ROOT.'include/dblayer/common_db.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    90
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    91
// Start a transaction
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    92
$db->start_transaction();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    93
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    94
// Load cached config
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    95
@include PUN_ROOT.'cache/cache_config.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    96
if (!defined('PUN_CONFIG_LOADED'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    97
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    98
	require PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    99
	generate_config_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   100
	require PUN_ROOT.'cache/cache_config.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   101
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   102
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   103
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   104
// Enable output buffering
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   105
if (!defined('PUN_DISABLE_BUFFERING'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   106
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   107
	// For some very odd reason, "Norton Internet Security" unsets this
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   108
	$_SERVER['HTTP_ACCEPT_ENCODING'] = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : '';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   109
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   110
	// Should we use gzip output compression?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   111
	if ($pun_config['o_gzip'] && extension_loaded('zlib') && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false || strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') !== false))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   112
		ob_start('ob_gzhandler');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   113
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   114
		ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   115
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   116
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   117
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   118
// Check/update/set cookie and fetch user info
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   119
$pun_user = array();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   120
check_cookie($pun_user);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   121
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   122
// Attempt to load the common language file
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   123
@include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   124
if (!isset($lang_common))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   125
	exit('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   126
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   127
// Check if we are to display a maintenance message
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   128
if ($pun_config['o_maintenance'] && $pun_user['g_id'] > PUN_ADMIN && !defined('PUN_TURN_OFF_MAINT'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   129
	maintenance_message();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   130
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   131
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   132
// Load cached bans
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   133
@include PUN_ROOT.'cache/cache_bans.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   134
if (!defined('PUN_BANS_LOADED'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   135
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   136
	require_once PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   137
	generate_bans_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   138
	require PUN_ROOT.'cache/cache_bans.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   139
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   140
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   141
// Check if current user is banned
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   142
check_bans();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   143
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   144
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   145
// Update online list
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   146
update_users_online();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   147