common.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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('FORK_VERSION', '0.0.0');
  11. define('FORK_REVISION', 1);
  12. define('FORK_DB_REVISION', 21);
  13. define('FORK_SI_REVISION', 2.1);
  14. define('FORK_PARSER_REVISION', 2);
  15. define('MIN_PHP_VERSION', '5.6.0');
  16. define('MIN_MYSQL_VERSION', '4.1.2');
  17. define('MIN_PGSQL_VERSION', '7.0.0');
  18. define('PUN_SEARCH_MIN_WORD', 3);
  19. define('PUN_SEARCH_MAX_WORD', 20);
  20. // Block prefetch requests
  21. if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
  22. {
  23. header('HTTP/1.1 403 Prefetching Forbidden');
  24. // Send no-cache headers
  25. header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
  26. header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  27. header('Cache-Control: post-check=0, pre-check=0', false);
  28. header('Pragma: no-cache'); // For HTTP/1.0 compatibility
  29. exit;
  30. }
  31. // Record the start time (will be used to calculate the generation time for the page)
  32. $pun_start = microtime(true);
  33. $page_js = array();
  34. // Load the functions script
  35. require PUN_ROOT.'include/functions.php';
  36. // Load addon functionality
  37. require PUN_ROOT.'include/addons.php';
  38. // Force POSIX locale (to prevent functions such as strtolower() from messing up UTF-8 strings)
  39. setlocale(LC_CTYPE, 'C');
  40. require PUN_ROOT . 'app/bootstrap.php';
  41. // The addon manager is responsible for storing the hook listeners and communicating with the addons
  42. $flux_addons = new flux_addon_manager();
  43. // Define a few commonly used constants
  44. define('PUN_UNVERIFIED', 0);
  45. define('PUN_ADMIN', 1);
  46. define('PUN_MOD', 2);
  47. define('PUN_GUEST', 3);
  48. define('PUN_MEMBER', 4);
  49. $db = $container->get('DB');
  50. // Start a transaction
  51. $db->start_transaction();
  52. // Load cached config
  53. if (file_exists($container->getParameter('DIR_CACHE') . 'cache_config.php'))
  54. include $container->getParameter('DIR_CACHE') . 'cache_config.php';
  55. if (!defined('PUN_CONFIG_LOADED'))
  56. {
  57. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  58. require PUN_ROOT.'include/cache.php';
  59. generate_config_cache();
  60. require $container->getParameter('DIR_CACHE') . 'cache_config.php';
  61. }
  62. // Verify that we are running the proper database schema revision
  63. if (empty($pun_config['i_fork_revision']) || $pun_config['i_fork_revision'] < FORK_REVISION) {
  64. header('Location: db_update.php');
  65. exit;
  66. }
  67. // Enable output buffering
  68. if (!defined('PUN_DISABLE_BUFFERING'))
  69. {
  70. // Should we use gzip output compression?
  71. if ($pun_config['o_gzip'] && extension_loaded('zlib'))
  72. ob_start('ob_gzhandler');
  73. else
  74. ob_start();
  75. }
  76. // Define standard date/time formats
  77. $forum_time_formats = array($pun_config['o_time_format'], 'H:i:s', 'H:i', 'g:i:s a', 'g:i a');
  78. $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');
  79. // Check/update/set cookie and fetch user info
  80. $pun_user = array();
  81. check_cookie($pun_user);
  82. // Attempt to load the common language file
  83. if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/common.php'))
  84. include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
  85. else
  86. error('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name');
  87. // Check if we are to display a maintenance message
  88. if ($pun_config['o_maintenance'] && $pun_user['g_id'] > PUN_ADMIN && !defined('PUN_TURN_OFF_MAINT'))
  89. maintenance_message();
  90. // Load cached bans
  91. if (file_exists($container->getParameter('DIR_CACHE') . 'cache_bans.php'))
  92. include $container->getParameter('DIR_CACHE') . 'cache_bans.php';
  93. if (!defined('PUN_BANS_LOADED'))
  94. {
  95. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  96. require PUN_ROOT.'include/cache.php';
  97. generate_bans_cache();
  98. require $container->getParameter('DIR_CACHE') . 'cache_bans.php';
  99. }
  100. // Check if current user is banned
  101. check_bans();
  102. // Update online list
  103. $onl_u = $onl_g = $onl_s = array();
  104. if (!defined('WITT_ENABLE')) // Кто в этой теме - Visman
  105. update_users_online();
  106. // Check to see if we logged in without a cookie being set
  107. if ($pun_user['is_guest'] && $container->get('Request')->isGet('login'))
  108. message($lang_common['No cookie']);
  109. // The maximum size of a post, in characters, not bytes
  110. if (!defined('PUN_MAX_POSTSIZE'))
  111. define('PUN_MAX_POSTSIZE', 65000);
  112. if (!defined('PUN_SEARCH_MIN_WORD'))
  113. define('PUN_SEARCH_MIN_WORD', 3);
  114. if (!defined('PUN_SEARCH_MAX_WORD'))
  115. define('PUN_SEARCH_MAX_WORD', 20);
  116. if (!defined('FORUM_MAX_COOKIE_SIZE'))
  117. define('FORUM_MAX_COOKIE_SIZE', 4048);
  118. // Load cached subforums - Visman
  119. if (file_exists($container->getParameter('DIR_CACHE') . 'cache_subforums_'.$pun_user['g_id'].'.php'))
  120. include $container->getParameter('DIR_CACHE') . 'cache_subforums_'.$pun_user['g_id'].'.php';
  121. if (!isset($sf_array_tree))
  122. {
  123. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  124. require PUN_ROOT.'include/cache.php';
  125. generate_subforums_cache($pun_user['g_id']);
  126. require $container->getParameter('DIR_CACHE') . 'cache_subforums_'.$pun_user['g_id'].'.php';
  127. }