PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/nacridan/forum/include/common.php

https://gitlab.com/nacridan/Nacridan
PHP | 205 lines | 119 code | 45 blank | 41 comment | 36 complexity | 482b4c553b1c648b14439284c0b7cdfd MD5 | raw file
  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.8');
  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 addon functionality
  34. require PUN_ROOT.'include/addons.php';
  35. // Load UTF-8 functions
  36. require PUN_ROOT.'include/utf8/utf8.php';
  37. // Strip out "bad" UTF-8 characters
  38. forum_remove_bad_characters();
  39. // Reverse the effect of register_globals
  40. forum_unregister_globals();
  41. // If PUN isn't defined, config.php is missing or corrupt
  42. if (!defined('PUN'))
  43. {
  44. header('Location: install.php');
  45. exit;
  46. }
  47. // The addon manager is responsible for storing the hook listeners and communicating with the addons
  48. $flux_addons = new flux_addon_manager();
  49. // Record the start time (will be used to calculate the generation time for the page)
  50. $pun_start = get_microtime();
  51. // Make sure PHP reports all errors except E_NOTICE. FluxBB supports E_ALL, but a lot of scripts it may interact with, do not
  52. error_reporting(E_ALL ^ E_NOTICE);
  53. // Force POSIX locale (to prevent functions such as strtolower() from messing up UTF-8 strings)
  54. setlocale(LC_CTYPE, 'C');
  55. // Turn off magic_quotes_runtime
  56. if (get_magic_quotes_runtime())
  57. set_magic_quotes_runtime(0);
  58. // Strip slashes from GET/POST/COOKIE/REQUEST/FILES (if magic_quotes_gpc is enabled)
  59. if (!defined('FORUM_DISABLE_STRIPSLASHES') && get_magic_quotes_gpc())
  60. {
  61. function stripslashes_array($array)
  62. {
  63. return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
  64. }
  65. $_GET = stripslashes_array($_GET);
  66. $_POST = stripslashes_array($_POST);
  67. $_COOKIE = stripslashes_array($_COOKIE);
  68. $_REQUEST = stripslashes_array($_REQUEST);
  69. if (is_array($_FILES))
  70. {
  71. // Don't strip valid slashes from tmp_name path on Windows
  72. foreach ($_FILES AS $key => $value)
  73. $_FILES[$key]['tmp_name'] = str_replace('\\', '\\\\', $value['tmp_name']);
  74. $_FILES = stripslashes_array($_FILES);
  75. }
  76. }
  77. // If a cookie name is not specified in config.php, we use the default (pun_cookie)
  78. if (empty($cookie_name))
  79. $cookie_name = 'pun_cookie';
  80. // If the cache directory is not specified, we use the default setting
  81. if (!defined('FORUM_CACHE_DIR'))
  82. define('FORUM_CACHE_DIR', PUN_ROOT.'cache/');
  83. // Define a few commonly used constants
  84. define('PUN_UNVERIFIED', 0);
  85. define('PUN_ADMIN', 1);
  86. define('PUN_MOD', 2);
  87. define('PUN_GUEST', 3);
  88. define('PUN_MEMBER', 4);
  89. // Load DB abstraction layer and connect
  90. require PUN_ROOT.'include/dblayer/common_db.php';
  91. // Start a transaction
  92. $db->start_transaction();
  93. // Load cached config
  94. if (file_exists(FORUM_CACHE_DIR.'cache_config.php'))
  95. include FORUM_CACHE_DIR.'cache_config.php';
  96. if (!defined('PUN_CONFIG_LOADED'))
  97. {
  98. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  99. require PUN_ROOT.'include/cache.php';
  100. generate_config_cache();
  101. require FORUM_CACHE_DIR.'cache_config.php';
  102. }
  103. // Verify that we are running the proper database schema revision
  104. if (!isset($pun_config['o_database_revision']) || $pun_config['o_database_revision'] < FORUM_DB_REVISION ||
  105. !isset($pun_config['o_searchindex_revision']) || $pun_config['o_searchindex_revision'] < FORUM_SI_REVISION ||
  106. !isset($pun_config['o_parser_revision']) || $pun_config['o_parser_revision'] < FORUM_PARSER_REVISION ||
  107. version_compare($pun_config['o_cur_version'], FORUM_VERSION, '<'))
  108. {
  109. header('Location: db_update.php');
  110. exit;
  111. }
  112. // Enable output buffering
  113. if (!defined('PUN_DISABLE_BUFFERING'))
  114. {
  115. // Should we use gzip output compression?
  116. if ($pun_config['o_gzip'] && extension_loaded('zlib'))
  117. ob_start('ob_gzhandler');
  118. else
  119. ob_start();
  120. }
  121. // Define standard date/time formats
  122. $forum_time_formats = array($pun_config['o_time_format'], 'H:i:s', 'H:i', 'g:i:s a', 'g:i a');
  123. $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');
  124. // Check/update/set cookie and fetch user info
  125. $pun_user = array();
  126. check_cookie($pun_user);
  127. // Attempt to load the common language file
  128. if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/common.php'))
  129. include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
  130. else
  131. error('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name');
  132. // Check if we are to display a maintenance message
  133. if ($pun_config['o_maintenance'] && $pun_user['g_id'] > PUN_ADMIN && !defined('PUN_TURN_OFF_MAINT'))
  134. maintenance_message();
  135. // Load cached bans
  136. if (file_exists(FORUM_CACHE_DIR.'cache_bans.php'))
  137. include FORUM_CACHE_DIR.'cache_bans.php';
  138. if (!defined('PUN_BANS_LOADED'))
  139. {
  140. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  141. require PUN_ROOT.'include/cache.php';
  142. generate_bans_cache();
  143. require FORUM_CACHE_DIR.'cache_bans.php';
  144. }
  145. // Check if current user is banned
  146. check_bans();
  147. // Update online list
  148. update_users_online();
  149. // Check to see if we logged in without a cookie being set
  150. if ($pun_user['is_guest'] && isset($_GET['login']))
  151. message($lang_common['No cookie']);
  152. // The maximum size of a post, in bytes, since the field is now MEDIUMTEXT this allows ~16MB but lets cap at 1MB...
  153. if (!defined('PUN_MAX_POSTSIZE'))
  154. define('PUN_MAX_POSTSIZE', 1048576);
  155. if (!defined('PUN_SEARCH_MIN_WORD'))
  156. define('PUN_SEARCH_MIN_WORD', 3);
  157. if (!defined('PUN_SEARCH_MAX_WORD'))
  158. define('PUN_SEARCH_MAX_WORD', 20);
  159. if (!defined('FORUM_MAX_COOKIE_SIZE'))
  160. define('FORUM_MAX_COOKIE_SIZE', 4048);