PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/include/common.php

https://bitbucket.org/gencer/fluxbb
PHP | 199 lines | 117 code | 43 blank | 39 comment | 36 complexity | 17b5826a67d7e2dc52366a968a16255c MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Copyright (C) 2008-2012 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. if (!defined('PUN_ROOT'))
  8. exit('The constant PUN_ROOT must be defined and point to a valid FluxBB installation root directory.');
  9. // Define the version and database revision that this code was written for
  10. define('FORUM_VERSION', '1.5.6');
  11. define('FORUM_DB_REVISION', 21);
  12. define('FORUM_SI_REVISION', 2);
  13. define('FORUM_PARSER_REVISION', 2);
  14. // Block prefetch requests
  15. if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
  16. {
  17. header('HTTP/1.1 403 Prefetching Forbidden');
  18. // Send no-cache headers
  19. header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
  20. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  21. header('Cache-Control: post-check=0, pre-check=0', false);
  22. header('Pragma: no-cache'); // For HTTP/1.0 compatibility
  23. exit;
  24. }
  25. // Attempt to load the configuration file config.php
  26. if (file_exists(PUN_ROOT.'config.php'))
  27. require PUN_ROOT.'config.php';
  28. // 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
  29. if (defined('FORUM'))
  30. define('PUN', FORUM);
  31. // Load the functions script
  32. require PUN_ROOT.'include/functions.php';
  33. // Load UTF-8 functions
  34. require PUN_ROOT.'include/utf8/utf8.php';
  35. // Strip out "bad" UTF-8 characters
  36. forum_remove_bad_characters();
  37. // Reverse the effect of register_globals
  38. forum_unregister_globals();
  39. // If PUN isn't defined, config.php is missing or corrupt
  40. if (!defined('PUN'))
  41. {
  42. header('Location: install.php');
  43. exit;
  44. }
  45. // Record the start time (will be used to calculate the generation time for the page)
  46. $pun_start = get_microtime();
  47. // Make sure PHP reports all errors except E_NOTICE. FluxBB supports E_ALL, but a lot of scripts it may interact with, do not
  48. error_reporting(E_ALL ^ E_NOTICE);
  49. // Force POSIX locale (to prevent functions such as strtolower() from messing up UTF-8 strings)
  50. setlocale(LC_CTYPE, 'C');
  51. // Turn off magic_quotes_runtime
  52. if (get_magic_quotes_runtime())
  53. set_magic_quotes_runtime(0);
  54. // Strip slashes from GET/POST/COOKIE/REQUEST/FILES (if magic_quotes_gpc is enabled)
  55. if (!defined('FORUM_DISABLE_STRIPSLASHES') && get_magic_quotes_gpc())
  56. {
  57. function stripslashes_array($array)
  58. {
  59. return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
  60. }
  61. $_GET = stripslashes_array($_GET);
  62. $_POST = stripslashes_array($_POST);
  63. $_COOKIE = stripslashes_array($_COOKIE);
  64. $_REQUEST = stripslashes_array($_REQUEST);
  65. if (is_array($_FILES))
  66. {
  67. // Don't strip valid slashes from tmp_name path on Windows
  68. foreach ($_FILES AS $key => $value)
  69. $_FILES[$key]['tmp_name'] = str_replace('\\', '\\\\', $value['tmp_name']);
  70. $_FILES = stripslashes_array($_FILES);
  71. }
  72. }
  73. // If a cookie name is not specified in config.php, we use the default (pun_cookie)
  74. if (empty($cookie_name))
  75. $cookie_name = 'pun_cookie';
  76. // If the cache directory is not specified, we use the default setting
  77. if (!defined('FORUM_CACHE_DIR'))
  78. define('FORUM_CACHE_DIR', PUN_ROOT.'cache/');
  79. // Define a few commonly used constants
  80. define('PUN_UNVERIFIED', 0);
  81. define('PUN_ADMIN', 1);
  82. define('PUN_MOD', 2);
  83. define('PUN_GUEST', 3);
  84. define('PUN_MEMBER', 4);
  85. // Load DB abstraction layer and connect
  86. require PUN_ROOT.'include/dblayer/common_db.php';
  87. // Start a transaction
  88. $db->start_transaction();
  89. // Load cached config
  90. if (file_exists(FORUM_CACHE_DIR.'cache_config.php'))
  91. include FORUM_CACHE_DIR.'cache_config.php';
  92. if (!defined('PUN_CONFIG_LOADED'))
  93. {
  94. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  95. require PUN_ROOT.'include/cache.php';
  96. generate_config_cache();
  97. require FORUM_CACHE_DIR.'cache_config.php';
  98. }
  99. // Verify that we are running the proper database schema revision
  100. if (!isset($pun_config['o_database_revision']) || $pun_config['o_database_revision'] < FORUM_DB_REVISION ||
  101. !isset($pun_config['o_searchindex_revision']) || $pun_config['o_searchindex_revision'] < FORUM_SI_REVISION ||
  102. !isset($pun_config['o_parser_revision']) || $pun_config['o_parser_revision'] < FORUM_PARSER_REVISION ||
  103. version_compare($pun_config['o_cur_version'], FORUM_VERSION, '<'))
  104. {
  105. header('Location: db_update.php');
  106. exit;
  107. }
  108. // Enable output buffering
  109. if (!defined('PUN_DISABLE_BUFFERING'))
  110. {
  111. // Should we use gzip output compression?
  112. if ($pun_config['o_gzip'] && extension_loaded('zlib'))
  113. ob_start('ob_gzhandler');
  114. else
  115. ob_start();
  116. }
  117. // Define standard date/time formats
  118. $forum_time_formats = array($pun_config['o_time_format'], 'H:i:s', 'H:i', 'g:i:s a', 'g:i a');
  119. $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');
  120. // Check/update/set cookie and fetch user info
  121. $pun_user = array();
  122. check_cookie($pun_user);
  123. // Attempt to load the common language file
  124. if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/common.php'))
  125. include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
  126. else
  127. error('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name');
  128. // Check if we are to display a maintenance message
  129. if ($pun_config['o_maintenance'] && $pun_user['g_id'] > PUN_ADMIN && !defined('PUN_TURN_OFF_MAINT'))
  130. maintenance_message();
  131. // Load cached bans
  132. if (file_exists(FORUM_CACHE_DIR.'cache_bans.php'))
  133. include FORUM_CACHE_DIR.'cache_bans.php';
  134. if (!defined('PUN_BANS_LOADED'))
  135. {
  136. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  137. require PUN_ROOT.'include/cache.php';
  138. generate_bans_cache();
  139. require FORUM_CACHE_DIR.'cache_bans.php';
  140. }
  141. // Check if current user is banned
  142. check_bans();
  143. // Update online list
  144. update_users_online();
  145. // Check to see if we logged in without a cookie being set
  146. if ($pun_user['is_guest'] && isset($_GET['login']))
  147. message($lang_common['No cookie']);
  148. // The maximum size of a post, in bytes, since the field is now MEDIUMTEXT this allows ~16MB but lets cap at 1MB...
  149. if (!defined('PUN_MAX_POSTSIZE'))
  150. define('PUN_MAX_POSTSIZE', 1048576);
  151. if (!defined('PUN_SEARCH_MIN_WORD'))
  152. define('PUN_SEARCH_MIN_WORD', 3);
  153. if (!defined('PUN_SEARCH_MAX_WORD'))
  154. define('PUN_SEARCH_MAX_WORD', 20);
  155. if (!defined('FORUM_MAX_COOKIE_SIZE'))
  156. define('FORUM_MAX_COOKIE_SIZE', 4048);