/bp-forums/bbpress/bb-load.php

  1. <?php 
  2. /** 
  3. * Initialises the most fundamental parts of bbPress 
  4. * 
  5. * You should not have to change this file, all configuration 
  6. * should be possible in bb-config.php 
  7. * 
  8. * @package bbPress 
  9. */ 
  10.  
  11.  
  12.  
  13. /** 
  14. * Low level reasons to die 
  15. */ 
  16.  
  17. // Die if PHP is not new enough 
  18. if ( version_compare( PHP_VERSION, '4.3', '<' ) ) { 
  19. die( sprintf( 'Your server is running PHP version %s but bbPress requires at least 4.3', PHP_VERSION ) ); 
  20.  
  21.  
  22.  
  23. // Modify error reporting levels to exclude PHP notices 
  24. error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING); 
  25.  
  26.  
  27. /** 
  28. * bb_timer_start() - PHP 4 standard microtime start capture 
  29. * 
  30. * @access private 
  31. * @global int $bb_timestart Seconds and Microseconds added together from when function is called 
  32. * @return bool Always returns true 
  33. */ 
  34. function bb_timer_start() 
  35. global $bb_timestart; 
  36. $mtime = explode( ' ', microtime() ); 
  37. $bb_timestart = $mtime[1] + $mtime[0]; 
  38. return true; 
  39. bb_timer_start(); 
  40.  
  41.  
  42.  
  43. // Server detection 
  44.  
  45. /** 
  46. * Whether the server software is Apache or something else 
  47. * @global bool $is_apache 
  48. */ 
  49. $is_apache = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false); 
  50.  
  51. /** 
  52. * Whether the server software is IIS or something else 
  53. * @global bool $is_IIS 
  54. */ 
  55. $is_IIS = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) !== false || strpos( $_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer' ) !== false ); 
  56.  
  57. /** 
  58. * Whether the server software is IIS 7.X 
  59. * @global bool $is_iis7 
  60. */ 
  61. $is_iis7 = ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7.' ) !== false ); 
  62.  
  63.  
  64.  
  65. /** 
  66. * Stabilise $_SERVER variables in various PHP environments 
  67. */ 
  68.  
  69. // Fix for IIS, which doesn't set REQUEST_URI 
  70. if ( empty( $_SERVER['REQUEST_URI'] ) ) { 
  71.  
  72. // IIS Mod-Rewrite 
  73. if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) { 
  74. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL']; 
  75. // IIS Isapi_Rewrite 
  76. else if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { 
  77. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; 
  78. else 
  79. // Use ORIG_PATH_INFO if there is no PATH_INFO 
  80. if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) ) 
  81. $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']; 
  82.  
  83. // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice) 
  84. if ( isset($_SERVER['PATH_INFO']) ) { 
  85. if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) 
  86. $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']; 
  87. else 
  88. $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']; 
  89.  
  90. // Append the query string if it exists and isn't null 
  91. if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { 
  92. $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; 
  93.  
  94. // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests 
  95. if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) ) 
  96. $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED']; 
  97.  
  98. // Fix for Dreamhost and other PHP as CGI hosts 
  99. if (strpos($_SERVER['SCRIPT_NAME'], 'php.cgi') !== false) 
  100. unset($_SERVER['PATH_INFO']); 
  101.  
  102. // Fix empty PHP_SELF 
  103. $PHP_SELF = $_SERVER['PHP_SELF']; 
  104. if ( empty($PHP_SELF) ) 
  105. $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/", '', $_SERVER["REQUEST_URI"]); 
  106.  
  107.  
  108.  
  109. /** 
  110. * bbPress logging level constants - same as constants from BP_Log class 
  111. */ 
  112. define( 'BB_LOG_NONE', 0 ); 
  113. define( 'BB_LOG_FAIL', 1 ); 
  114. define( 'BB_LOG_ERROR', 2 ); 
  115. define( 'BB_LOG_WARNING', 4 ); 
  116. define( 'BB_LOG_NOTICE', 8 ); 
  117. define( 'BB_LOG_DEBUG', 16 ); 
  118.  
  119. /** 
  120. * Combination of all errors (excluding none and debug) 
  121. */ 
  122. define( 'BB_LOG_ALL', BB_LOG_FAIL + BB_LOG_ERROR + BB_LOG_WARNING + BB_LOG_NOTICE ); 
  123.  
  124. /** 
  125. * Define temporary $_bb_path as this files directory, then check for the special BB_PATH config file 
  126. * which allows override of BB_PATH, but only outside of core files 
  127. */ 
  128. $_bb_path = dirname( __FILE__ ) . '/'; 
  129. $_bb_config_path = dirname( $_bb_path ) . '/bb-config-path.php'; 
  130. if ( file_exists( $_bb_config_path ) ) { 
  131. include_once( $_bb_config_path ); 
  132. if ( !defined( 'BB_PATH' ) ) { 
  133. define( 'BB_PATH', $_bb_path ); 
  134. unset( $_bb_path, $_bb_config_path ); 
  135.  
  136. /** 
  137. * The bbPress includes path relative to BB_PATH 
  138. */ 
  139. define( 'BB_INC', 'bb-includes/' ); 
  140.  
  141. // Initialise $bb object 
  142. $bb = new StdClass(); 
  143.  
  144. if ( file_exists( BB_PATH . 'bb-config.php') ) { 
  145.  
  146. // The config file resides in BB_PATH 
  147. require_once( BB_PATH . 'bb-config.php'); 
  148.  
  149. // Load bb-settings.php 
  150. require_once( BB_PATH . 'bb-settings.php' ); 
  151.  
  152. } elseif ( file_exists( dirname( BB_PATH ) . '/bb-config.php') ) { 
  153.  
  154. // The config file resides one level below BB_PATH 
  155. require_once( dirname( BB_PATH ) . '/bb-config.php' ); 
  156.  
  157. // Load bb-settings.php 
  158. require_once( BB_PATH . 'bb-settings.php' ); 
  159.  
  160. } elseif ( !defined( 'BB_INSTALLING' ) || !BB_INSTALLING ) { 
  161.  
  162. // The config file doesn't exist and we aren't on the installation page 
  163.  
  164. // Cut to the chase, go to the installer and use it to deal with errors 
  165. $install_uri = preg_replace( '|(/bb-admin)?/[^/]+?$|', '/', $_SERVER['PHP_SELF'] ) . 'bb-admin/install.php'; 
  166. header( 'Location: ' . $install_uri ); 
  167. die(); 
  168.  
  169.  
  170. if ( isset( $_GET['doit'] ) && 'bb-subscribe' == $_GET['doit'] ) 
  171. require( BB_PATH . 'bb-includes/action.subscribe.php' ); 
.