PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/include/common.php

https://github.com/Dratone/EveBB
PHP | 269 lines | 154 code | 59 blank | 56 comment | 48 complexity | 948e3f2c304c2d682d67603f0a880303 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Copyright (C) 2008-2010 FluxBB
  4. * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
  5. * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  6. */
  7. session_start();
  8. if (!defined('PUN_ROOT'))
  9. exit('The constant PUN_ROOT must be defined and point to a valid FluxBB installation root directory.');
  10. // Define the version and database revision that this code was written for
  11. define('FORUM_VERSION', '1.4.5');
  12. define('EVE_BB_VERSION', '1.1.14');
  13. //Functions for EvE-BB
  14. define('EVE_ENABLED', 1);
  15. require(PUN_ROOT.'include/eve_functions.php');
  16. define('FORUM_DB_REVISION', 12);
  17. define('FORUM_SI_REVISION', 2);
  18. define('FORUM_PARSER_REVISION', 2);
  19. // Block prefetch requests
  20. if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
  21. {
  22. header('HTTP/1.1 403 Prefetching Forbidden');
  23. // Send no-cache headers
  24. header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
  25. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  26. header('Cache-Control: post-check=0, pre-check=0', false);
  27. header('Pragma: no-cache'); // For HTTP/1.0 compatibility
  28. exit;
  29. } //End if.
  30. // Attempt to load the configuration file config.php
  31. if (file_exists(PUN_ROOT.'config.php'))
  32. require PUN_ROOT.'config.php';
  33. // 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
  34. if (defined('FORUM'))
  35. define('PUN', FORUM);
  36. // Load the functions script
  37. require PUN_ROOT.'include/functions.php';
  38. // Load UTF-8 functions
  39. require PUN_ROOT.'include/utf8/utf8.php';
  40. // Strip out "bad" UTF-8 characters
  41. forum_remove_bad_characters();
  42. // Reverse the effect of register_globals
  43. forum_unregister_globals();
  44. // If PUN isn't defined, config.php is missing or corrupt
  45. if (!defined('PUN'))
  46. {
  47. header('Location: install.php');
  48. exit;
  49. }
  50. // Record the start time (will be used to calculate the generation time for the page)
  51. $pun_start = get_microtime();
  52. // Make sure PHP reports all errors except E_NOTICE. FluxBB supports E_ALL, but a lot of scripts it may interact with, do not
  53. error_reporting(E_ALL ^ E_NOTICE);
  54. // Force POSIX locale (to prevent functions such as strtolower() from messing up UTF-8 strings)
  55. setlocale(LC_CTYPE, 'C');
  56. // Turn off magic_quotes_runtime
  57. if (get_magic_quotes_runtime())
  58. set_magic_quotes_runtime(0);
  59. // Strip slashes from GET/POST/COOKIE (if magic_quotes_gpc is enabled)
  60. if (get_magic_quotes_gpc())
  61. {
  62. function stripslashes_array($array)
  63. {
  64. return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
  65. }
  66. $_GET = stripslashes_array($_GET);
  67. $_POST = stripslashes_array($_POST);
  68. $_COOKIE = stripslashes_array($_COOKIE);
  69. $_REQUEST = stripslashes_array($_REQUEST);
  70. }
  71. // If a cookie name is not specified in config.php, we use the default (pun_cookie)
  72. if (empty($cookie_name))
  73. $cookie_name = 'pun_cookie';
  74. // If the cache directory is not specified, we use the default setting
  75. if (!defined('FORUM_CACHE_DIR'))
  76. define('FORUM_CACHE_DIR', PUN_ROOT.'cache/');
  77. // Define a few commonly used constants
  78. define('PUN_UNVERIFIED', 0);
  79. define('PUN_ADMIN', 1);
  80. define('PUN_MOD', 2);
  81. define('PUN_GUEST', 3);
  82. define('PUN_MEMBER', 4);
  83. // Load DB abstraction layer and connect
  84. require PUN_ROOT.'include/dblayer/common_db.php';
  85. // Start a transaction
  86. $db->start_transaction();
  87. // Load cached config
  88. if (file_exists(FORUM_CACHE_DIR.'cache_config.php'))
  89. include FORUM_CACHE_DIR.'cache_config.php';
  90. if (!defined('PUN_CONFIG_LOADED'))
  91. {
  92. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  93. require PUN_ROOT.'include/cache.php';
  94. generate_config_cache();
  95. require FORUM_CACHE_DIR.'cache_config.php';
  96. }
  97. //Debugging is now based out of the admin options.
  98. if ($pun_config['o_enable_debug'] == 1) {
  99. //The lock file is made by the options, if it doesn't exist, someone has deleted it.
  100. if (file_exists(FORUM_CACHE_DIR.'debug.lock')) {
  101. define('PUN_DEBUG', 1);
  102. } else {
  103. //Turn it off fully, just to be sure.
  104. $pun_config['o_enable_debug'] = 0;
  105. $db->query('UPDATE '.$db->prefix.'config SET conf_value=0 WHERE conf_name=\'o_enable_debug\'');
  106. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  107. require PUN_ROOT.'include/cache.php';
  108. generate_config_cache();
  109. } //End if - else.
  110. } //End if.
  111. //define('PUN_SHOW_QUERIES', 1);
  112. //define('PUN_SHOW_REQUESTS', 1);
  113. //Set the session length.
  114. //This is not something I'd like anyone tampering with unless they are aware of the kind of issues it could bring.
  115. //Anyone comfortable with editing the session length should be OK with editing this file.
  116. $pun_config['session_length'] = 4*60*60;
  117. // Verify that we are running the proper database schema revision
  118. if (!isset($pun_config['o_database_revision']) || $pun_config['o_database_revision'] < FORUM_DB_REVISION ||
  119. !isset($pun_config['o_searchindex_revision']) || $pun_config['o_searchindex_revision'] < FORUM_SI_REVISION ||
  120. !isset($pun_config['o_parser_revision']) || $pun_config['o_parser_revision'] < FORUM_PARSER_REVISION ||
  121. version_compare($pun_config['o_cur_version'], FORUM_VERSION, '<'))
  122. {
  123. header('Location: db_update.php');
  124. exit;
  125. }
  126. // Enable output buffering
  127. if (!defined('PUN_DISABLE_BUFFERING'))
  128. {
  129. // Should we use gzip output compression?
  130. if ($pun_config['o_gzip'] && extension_loaded('zlib'))
  131. ob_start('ob_gzhandler');
  132. else
  133. ob_start();
  134. }
  135. // Define standard date/time formats
  136. $forum_time_formats = array($pun_config['o_time_format'], 'H:i:s', 'H:i', 'g:i:s a', 'g:i a');
  137. $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');
  138. // Check/update/set cookie and fetch user info
  139. $pun_user = array();
  140. check_cookie($pun_user);
  141. // Attempt to load the common language file
  142. if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/common.php')) {
  143. include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
  144. /*********** EVE-BB ***********/
  145. include PUN_ROOT.'lang/'.$pun_user['language'].'/eve_bb.php';
  146. /*********** EVE-BB ***********/
  147. } else {
  148. error('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name');
  149. } //End if - else.
  150. // Check if we are to display a maintenance message
  151. if ($pun_config['o_maintenance'] && $pun_user['g_id'] > PUN_ADMIN && !defined('PUN_TURN_OFF_MAINT'))
  152. maintenance_message();
  153. // Load cached bans
  154. if (file_exists(FORUM_CACHE_DIR.'cache_bans.php'))
  155. include FORUM_CACHE_DIR.'cache_bans.php';
  156. if (!defined('PUN_BANS_LOADED'))
  157. {
  158. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  159. require PUN_ROOT.'include/cache.php';
  160. generate_bans_cache();
  161. require FORUM_CACHE_DIR.'cache_bans.php';
  162. }
  163. // Check if current user is banned
  164. check_bans();
  165. // Check to see if we logged in without a cookie being set
  166. if ($pun_user['is_guest'] && isset($_GET['login']))
  167. message($lang_common['No cookie']);
  168. // The maximum size of a post, in bytes, since the field is now MEDIUMTEXT this allows ~16MB but lets cap at 1MB...
  169. if (!defined('PUN_MAX_POSTSIZE'))
  170. define('PUN_MAX_POSTSIZE', 1048576);
  171. if (!defined('PUN_SEARCH_MIN_WORD'))
  172. define('PUN_SEARCH_MIN_WORD', 3);
  173. if (!defined('PUN_SEARCH_MAX_WORD'))
  174. define('PUN_SEARCH_MAX_WORD', 20);
  175. if (!defined('FORUM_MAX_COOKIE_SIZE'))
  176. define('FORUM_MAX_COOKIE_SIZE', 4048);
  177. /*********** EVE-BB ***********/
  178. //Define this ONLY if you want automated testing to be allowed on your server.
  179. //define('EVEBB_AUTO_DEBUG', 1);
  180. //Determine if we can/should use cURL where possible.
  181. if (extension_loaded('curl') && $pun_config['o_use_fopen'] != '1') {
  182. define('EVEBB_CURL', 1);
  183. } //End if.
  184. require(PUN_ROOT.'include/request.php');
  185. $pun_request = new Request();
  186. //See if they are allowed to have their own style.
  187. if ($pun_config['o_allow_style'] != '1') {
  188. $pun_user['style'] = $pun_config['o_default_style'];
  189. } //End if.
  190. //We now make our hooks so we can run tasks via plugins.
  191. $_HOOKS = array(
  192. 'rules' => array(),
  193. 'startup' => array(),
  194. 'users' => array(),
  195. 'api' => array(),
  196. );
  197. include(PUN_ROOT.'include/hook_classes.php');
  198. //Now lets load the hook files...
  199. $dir = scandir(PUN_ROOT.'plugins/hooks');
  200. foreach ($dir as $d) {
  201. if (strlen($d) < 5) {
  202. continue;
  203. } //End if.
  204. if (substr($d, -3) != "php") {
  205. continue;
  206. } //End if.
  207. require(PUN_ROOT.'plugins/hooks/'.$d);
  208. } //End foreach().
  209. task_runner(); //Run our updating tasks, skip it if possible to avoid load.
  210. /*********** EVE-BB ***********/