Index: branches/rsr.v5.1.dev/web/punbb/include/common.php
===================================================================
--- branches/rsr.v5.1.dev/web/punbb/include/common.php	(revision 1)
+++ branches/rsr.v5.1.dev/web/punbb/include/common.php	(revision 3)
@@ -1,63 +1,75 @@
 <?php
 
-/***********************************************************************
-
-  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
-
-  This file is part of PunBB.
-
-  PunBB is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
-  or (at your option) any later version.
-
-  PunBB is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
-  MA  02111-1307  USA
-
-************************************************************************/
-
-// Activez le mode DEBUG en enlevant // du dÃ©but de la ligne ci-dessous
-//define('PUN_DEBUG', 1);
-
-// Ceci permettra d'afficher en bas de page toutes les requÃªtes exÃ©cutÃ©es
-// N'ACTIVEZ PAS cela sur un environnement de production !
-//define('PUN_SHOW_QUERIES', 1);
+/**
+ * Copyright (C) 2008-2011 FluxBB
+ * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
+ * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
+ */
 
 if (!defined('PUN_ROOT'))
-	exit('La constante PUN_ROOT doit Ãªtre dÃ©finie est doit pointer le repertoire racine d\'une installation fonctionnelle de PunBB.');
+	exit('The constant PUN_ROOT must be defined and point to a valid FluxBB installation root directory.');
 
+// Define the version and database revision that this code was written for
+define('FORUM_VERSION', '1.4.7');
+
+define('FORUM_DB_REVISION', 15);
+define('FORUM_SI_REVISION', 2);
+define('FORUM_PARSER_REVISION', 2);
+
+// Block prefetch requests
+if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
+{
+	header('HTTP/1.1 403 Prefetching Forbidden');
+
+	// Send no-cache headers
+	header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
+	header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
+	header('Cache-Control: post-check=0, pre-check=0', false);
+	header('Pragma: no-cache'); // For HTTP/1.0 compatibility
+
+	exit;
+}
+
+// Attempt to load the configuration file config.php
+if (file_exists(PUN_ROOT.'config.php'))
+	require PUN_ROOT.'config.php';
+
+// If we have the 1.3-legacy constant defined, define the proper 1.4 constant so we don't get an incorrect "need to install" message
+if (defined('FORUM'))
+	define('PUN', FORUM);
 
 // Load the functions script
 require PUN_ROOT.'include/functions.php';
 
+// Load UTF-8 functions
+require PUN_ROOT.'include/utf8/utf8.php';
+
+// Strip out "bad" UTF-8 characters
+forum_remove_bad_characters();
+
 // Reverse the effect of register_globals
-if (@ini_get('register_globals'))
-	unregister_globals();
-
-include PUN_ROOT.'config.php';
+forum_unregister_globals();
 
 // If PUN isn't defined, config.php is missing or corrupt
 if (!defined('PUN'))
-	exit('Le fichier "config.php" n\'existe pas ou est endommagÃ©. Veuillez lancer <a href="install.php">install.php</a> pour installer PunBB.');
-
+{
+	header('Location: install.php');
+	exit;
+}
 
 // Record the start time (will be used to calculate the generation time for the page)
-list($usec, $sec) = explode(' ', microtime());
-$pun_start = ((float)$usec + (float)$sec);
+$pun_start = get_microtime();
 
-// Enable full error, warning and notice reporting
+// Make sure PHP reports all errors except E_NOTICE. FluxBB supports E_ALL, but a lot of scripts it may interact with, do not
 error_reporting(E_ALL ^ E_NOTICE);
 
+// Force POSIX locale (to prevent functions such as strtolower() from messing up UTF-8 strings)
+setlocale(LC_CTYPE, 'C');
+
 // Turn off magic_quotes_runtime
-set_magic_quotes_runtime(0);
+if (get_magic_quotes_runtime())
+	set_magic_quotes_runtime(0);
 
-// Strip slashes from GET/POST/COOKIE (if magic_quotes_gpc is enabled)
+// Strip slashes from GET/POST/COOKIE/REQUEST/FILES (if magic_quotes_gpc is enabled)
 if (get_magic_quotes_gpc())
 {
@@ -70,20 +82,22 @@
 	$_POST = stripslashes_array($_POST);
 	$_COOKIE = stripslashes_array($_COOKIE);
+	$_REQUEST = stripslashes_array($_REQUEST);
+	$_FILES = stripslashes_array($_FILES);
 }
 
-// Seed the random number generator
-mt_srand((double)microtime()*1000000);
+// If a cookie name is not specified in config.php, we use the default (pun_cookie)
+if (empty($cookie_name))
+	$cookie_name = 'pun_cookie';
 
-// If a cookie name is not specified in config.php, we use the default (punbb_cookie)
-if (empty($cookie_name))
-	$cookie_name = 'punbb_cookie';
+// If the cache directory is not specified, we use the default setting
+if (!defined('FORUM_CACHE_DIR'))
+	define('FORUM_CACHE_DIR', PUN_ROOT.'cache/');
 
 // Define a few commonly used constants
-define('PUN_UNVERIFIED', 32000);
+define('PUN_UNVERIFIED', 0);
 define('PUN_ADMIN', 1);
 define('PUN_MOD', 2);
 define('PUN_GUEST', 3);
 define('PUN_MEMBER', 4);
-
 
 // Load DB abstraction layer and connect
@@ -94,21 +108,31 @@
 
 // Load cached config
-@include PUN_ROOT.'cache/cache_config.php';
+if (file_exists(FORUM_CACHE_DIR.'cache_config.php'))
+	include FORUM_CACHE_DIR.'cache_config.php';
+
 if (!defined('PUN_CONFIG_LOADED'))
 {
-	require PUN_ROOT.'include/cache.php';
+	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
+		require PUN_ROOT.'include/cache.php';
+
 	generate_config_cache();
-	require PUN_ROOT.'cache/cache_config.php';
+	require FORUM_CACHE_DIR.'cache_config.php';
 }
 
+// Verify that we are running the proper database schema revision
+if (!isset($pun_config['o_database_revision']) || $pun_config['o_database_revision'] < FORUM_DB_REVISION ||
+	!isset($pun_config['o_searchindex_revision']) || $pun_config['o_searchindex_revision'] < FORUM_SI_REVISION ||
+	!isset($pun_config['o_parser_revision']) || $pun_config['o_parser_revision'] < FORUM_PARSER_REVISION ||
+	version_compare($pun_config['o_cur_version'], FORUM_VERSION, '<'))
+{
+	header('Location: db_update.php');
+	exit;
+}
 
 // Enable output buffering
 if (!defined('PUN_DISABLE_BUFFERING'))
 {
-	// For some very odd reason, "Norton Internet Security" unsets this
-	$_SERVER['HTTP_ACCEPT_ENCODING'] = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : '';
-
 	// Should we use gzip output compression?
-	if ($pun_config['o_gzip'] && extension_loaded('zlib') && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false || strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') !== false))
+	if ($pun_config['o_gzip'] && extension_loaded('zlib'))
 		ob_start('ob_gzhandler');
 	else
@@ -116,4 +140,7 @@
 }
 
+// Define standard date/time formats
+$forum_time_formats = array($pun_config['o_time_format'], 'H:i:s', 'H:i', 'g:i:s a', 'g:i a');
+$forum_date_formats = array($pun_config['o_date_format'], 'Y-m-d', 'Y-d-m', 'd-m-Y', 'm-d-Y', 'M j Y', 'jS M Y');
 
 // Check/update/set cookie and fetch user info
@@ -122,7 +149,8 @@
 
 // Attempt to load the common language file
-@include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
-if (!isset($lang_common))
-	exit('Il n\'y a pas de pack de langue \''.pun_htmlspecialchars($pun_user['language']).'\' d\'installÃ©. Veuillez rÃ©-installer une langue de ce nom.');
+if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/common.php'))
+	include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
+else
+	error('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name');
 
 // Check if we are to display a maintenance message
@@ -130,12 +158,15 @@
 	maintenance_message();
 
+// Load cached bans
+if (file_exists(FORUM_CACHE_DIR.'cache_bans.php'))
+	include FORUM_CACHE_DIR.'cache_bans.php';
 
-// Load cached bans
-@include PUN_ROOT.'cache/cache_bans.php';
 if (!defined('PUN_BANS_LOADED'))
 {
-	require_once PUN_ROOT.'include/cache.php';
+	if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
+		require PUN_ROOT.'include/cache.php';
+
 	generate_bans_cache();
-	require PUN_ROOT.'cache/cache_bans.php';
+	require FORUM_CACHE_DIR.'cache_bans.php';
 }
 
@@ -146,3 +177,17 @@
 update_users_online();
 
-?>
+// Check to see if we logged in without a cookie being set
+if ($pun_user['is_guest'] && isset($_GET['login']))
+	message($lang_common['No cookie']);
+
+// The maximum size of a post, in bytes, since the field is now MEDIUMTEXT this allows ~16MB but lets cap at 1MB...
+if (!defined('PUN_MAX_POSTSIZE'))
+	define('PUN_MAX_POSTSIZE', 1048576);
+
+if (!defined('PUN_SEARCH_MIN_WORD'))
+	define('PUN_SEARCH_MIN_WORD', 3);
+if (!defined('PUN_SEARCH_MAX_WORD'))
+	define('PUN_SEARCH_MAX_WORD', 20);
+
+if (!defined('FORUM_MAX_COOKIE_SIZE'))
+	define('FORUM_MAX_COOKIE_SIZE', 4048);
