punbb/include/common.php
changeset 7 98bbc533541c
equal deleted inserted replaced
6:5e1f1e916419 7:98bbc533541c
       
     1 <?php
       
     2 /***********************************************************************
       
     3 
       
     4   Copyright (C) 2002-2008  PunBB.org
       
     5 
       
     6   This file is part of PunBB.
       
     7 
       
     8   PunBB is free software; you can redistribute it and/or modify it
       
     9   under the terms of the GNU General Public License as published
       
    10   by the Free Software Foundation; either version 2 of the License,
       
    11   or (at your option) any later version.
       
    12 
       
    13   PunBB is distributed in the hope that it will be useful, but
       
    14   WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16   GNU General Public License for more details.
       
    17 
       
    18   You should have received a copy of the GNU General Public License
       
    19   along with this program; if not, write to the Free Software
       
    20   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
       
    21   MA  02111-1307  USA
       
    22 
       
    23 ************************************************************************/
       
    24 
       
    25 
       
    26 if (!defined('PUN_ROOT'))
       
    27 	exit('The constant PUN_ROOT must be defined and point to a valid PunBB installation root directory.');
       
    28 
       
    29 if (!defined('PUN_ESSENTIALS_LOADED'))
       
    30 	require PUN_ROOT.'include/essentials.php';
       
    31 
       
    32 // Turn off magic_quotes_runtime
       
    33 set_magic_quotes_runtime(0);
       
    34 
       
    35 // Strip slashes from GET/POST/COOKIE (if magic_quotes_gpc is enabled)
       
    36 if (get_magic_quotes_gpc())
       
    37 {
       
    38 	function stripslashes_array($array)
       
    39 	{
       
    40 		return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
       
    41 	}
       
    42 
       
    43 	$_GET = stripslashes_array($_GET);
       
    44 	$_POST = stripslashes_array($_POST);
       
    45 	$_COOKIE = stripslashes_array($_COOKIE);
       
    46 }
       
    47 
       
    48 // If a cookie name is not specified in config.php, we use the default (punbb_cookie)
       
    49 if (empty($cookie_name))
       
    50 	$cookie_name = 'punbb_cookie';
       
    51 
       
    52 // Define a few commonly used constants
       
    53 define('PUN_UNVERIFIED', 0);
       
    54 define('PUN_ADMIN', 1);
       
    55 define('PUN_GUEST', 2);
       
    56 define('PUN_MEMBER', 3);
       
    57 
       
    58 // Enable output buffering
       
    59 if (!defined('PUN_DISABLE_BUFFERING'))
       
    60 {
       
    61 	// For some very odd reason, "Norton Internet Security" unsets this
       
    62 	$_SERVER['HTTP_ACCEPT_ENCODING'] = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : '';
       
    63 
       
    64 	// Should we use gzip output compression?
       
    65 	if ($pun_config['o_gzip'] && extension_loaded('zlib') && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false || strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') !== false))
       
    66 		ob_start('ob_gzhandler');
       
    67 	else
       
    68 		ob_start();
       
    69 }
       
    70 
       
    71 // Setup base URL (added for Enano)
       
    72 global $paths;
       
    73 $base_url = contentPath . $paths->nslist['Special'] . 'Forum';
       
    74 
       
    75 // Define standard date/time formats
       
    76 $pun_time_formats = array($pun_config['o_time_format'], 'H:i:s', 'H:i', 'g:i:s a', 'g:i a');
       
    77 $pun_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');
       
    78 
       
    79 // Create pun_page array
       
    80 $pun_page = array();
       
    81 
       
    82 // Login and fetch user info
       
    83 $pun_user = array();
       
    84 cookie_login($pun_user);
       
    85 
       
    86 // Attempt to load the common language file
       
    87 if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/common.php'))
       
    88 	include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
       
    89 else
       
    90 	error('There is no valid language pack \''.htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name.');
       
    91 
       
    92 // Check if we are to display a maintenance message
       
    93 if ($pun_config['o_maintenance'] && $pun_user['g_id'] > PUN_ADMIN && !defined('PUN_TURN_OFF_MAINT'))
       
    94 	maintenance_message();
       
    95 
       
    96 // Setup the URL rewriting scheme
       
    97 if (file_exists(PUN_ROOT.'include/url/'.$pun_config['o_sef'].'.php'))
       
    98 	require PUN_ROOT.'include/url/'.$pun_config['o_sef'].'.php';
       
    99 else
       
   100 	require PUN_ROOT.'include/url/Default.php';
       
   101 
       
   102 
       
   103 // Load cached updates info
       
   104 if ($session->user_level >= USER_LEVEL_ADMIN)
       
   105 {
       
   106 	if (file_exists(PUN_CACHE_DIR.'cache_updates.php'))
       
   107 		include PUN_CACHE_DIR.'cache_updates.php';
       
   108 
       
   109 	// Regenerate cache only if automatic updates are enabled and if the cache is more than 12 hours old
       
   110 	if ($pun_config['o_check_for_updates'] == '1' && (!defined('PUN_UPDATES_LOADED') || $pun_updates['cached'] < (time() - 43200)))
       
   111 	{
       
   112 		require_once PUN_ROOT.'include/cache.php';
       
   113 		generate_updates_cache();
       
   114 		require PUN_CACHE_DIR.'cache_updates.php';
       
   115 	}
       
   116 }
       
   117 
       
   118 
       
   119 // Load cached bans
       
   120 if (file_exists(PUN_CACHE_DIR.'cache_bans.php'))
       
   121 	include PUN_CACHE_DIR.'cache_bans.php';
       
   122 
       
   123 if (!defined('PUN_BANS_LOADED'))
       
   124 {
       
   125 	require_once PUN_ROOT.'include/cache.php';
       
   126 	generate_bans_cache();
       
   127 	require PUN_CACHE_DIR.'cache_bans.php';
       
   128 }
       
   129 
       
   130 // Check if current user is banned
       
   131 check_bans();
       
   132 
       
   133 
       
   134 // Update online list
       
   135 update_users_online();
       
   136 
       
   137 // Check to see if we logged in without a cookie being set
       
   138 if ($pun_user['is_guest'] && isset($_GET['login']))
       
   139 	message($lang_common['No cookie']);
       
   140 
       
   141 // If we're an administrator or moderator, make sure the CSRF token in $_POST is valid (token in post.php is dealt with in post.php)
       
   142 if (!empty($_POST) && $pun_user['is_admmod'] && (isset($_POST['confirm_cancel']) || (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== generate_form_token(get_current_url()))) && basename($_SERVER['PHP_SELF']) != 'post.php')
       
   143 	csrf_confirm_form();
       
   144 
       
   145 // A good place to add common functions for your extension
       
   146 ($hook = get_hook('co_common')) ? eval($hook) : null;