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

  1. <?php 
  2. /** 
  3. * Used to setup and fix common variables and include 
  4. * the bbPress and BackPress procedural and class libraries. 
  5. * 
  6. * You should not have to change this file, all configuration 
  7. * should be possible in bb-config.php 
  8. * 
  9. * @package bbPress 
  10. */ 
  11.  
  12.  
  13.  
  14. // Die if called directly 
  15. if ( !defined( 'BB_PATH' ) ) { 
  16. die( 'This file cannot be called directly.' ); 
  17.  
  18. // Set default timezone in PHP 5. 
  19. if ( function_exists( 'date_default_timezone_set' ) ) 
  20. date_default_timezone_set( 'UTC' ); 
  21.  
  22. /** 
  23. * bb_unregister_GLOBALS() - Turn register globals off 
  24. * 
  25. * @access private 
  26. * @return null Will return null if register_globals PHP directive was disabled 
  27. */ 
  28. function bb_unregister_GLOBALS() 
  29. if ( !ini_get( 'register_globals' ) ) { 
  30. return; 
  31.  
  32. if ( isset($_REQUEST['GLOBALS']) ) { 
  33. die( 'GLOBALS overwrite attempt detected' ); 
  34.  
  35. // Variables that shouldn't be unset 
  36. $noUnset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'bb_table_prefix', 'bb' ); 
  37.  
  38. $input = array_merge( $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset( $_SESSION ) && is_array( $_SESSION ) ? $_SESSION : array() ); 
  39. foreach ( $input as $k => $v ) { 
  40. if ( !in_array( $k, $noUnset ) && isset( $GLOBALS[$k] ) ) { 
  41. $GLOBALS[$k] = NULL; 
  42. unset( $GLOBALS[$k] ); 
  43. bb_unregister_GLOBALS(); 
  44.  
  45.  
  46.  
  47. /** 
  48. * Let bbPress know what we are up to at the moment 
  49. */ 
  50.  
  51. /** 
  52. * Whether the current script is in the admin area or not 
  53. */ 
  54. if ( !defined( 'BB_IS_ADMIN' ) ) { 
  55. define( 'BB_IS_ADMIN', false ); 
  56. } elseif ( BB_IS_ADMIN ) { 
  57. $bb_hardcoded = (array) $bb; 
  58.  
  59. /** 
  60. * Whether the current script is part of the installation process or not 
  61. * @since 1.0 
  62. */ 
  63. if ( !defined( 'BB_INSTALLING' ) ) { 
  64. define( 'BB_INSTALLING', false ); 
  65.  
  66. /** 
  67. * Whether to load deprecated routines, constants and functions 
  68. * @since 1.0 
  69. */ 
  70. if ( !defined( 'BB_LOAD_DEPRECATED' ) ) { 
  71. define( 'BB_LOAD_DEPRECATED', true ); 
  72.  
  73.  
  74.  
  75. /** 
  76. * Remove filters and action that have been set by an included WordPress install 
  77. */ 
  78. if ( defined( 'ABSPATH' ) ) { 
  79. $wp_filter = array(); 
  80. $wp_actions = array(); 
  81. $merged_filters = array(); 
  82. $wp_current_filter = array(); 
  83.  
  84.  
  85.  
  86. /** 
  87. * Define include paths and load core BackPress libraries 
  88. */ 
  89.  
  90. /** 
  91. * The full path to the BackPress libraries 
  92. */ 
  93. if ( !defined( 'BACKPRESS_PATH' ) ) { 
  94. define( 'BACKPRESS_PATH', BB_PATH . BB_INC . 'backpress/' ); 
  95.  
  96. // Load logging class 
  97. require_once( BACKPRESS_PATH . 'class.bp-log.php' ); 
  98. $bb_log = new BP_Log(); 
  99. if ( defined( 'BB_LOG_LEVEL' ) ) { 
  100. $bb_log->set_level( BB_LOG_LEVEL ); 
  101. if ( defined( 'BB_LOG_TYPE' ) ) { 
  102. $bb_log->set_type( BB_LOG_TYPE ); 
  103. if ( defined( 'BB_LOG_FILENAME' ) ) { 
  104. $bb_log->set_filename( BB_LOG_FILENAME ); 
  105. $bb_log->notice('Logging started'); 
  106.  
  107. // Load core BackPress functions 
  108. require_once( BACKPRESS_PATH . 'functions.core.php' ); 
  109. require_once( BACKPRESS_PATH . 'functions.compat.php' ); 
  110. require_once( BACKPRESS_PATH . 'functions.formatting.php' ); 
  111.  
  112. // WP_Error 
  113. if ( !class_exists( 'WP_Error' ) ) { 
  114. require_once( BACKPRESS_PATH . 'class.wp-error.php' ); 
  115.  
  116.  
  117.  
  118. /** 
  119. * Set up database parameters based on config and initialise 
  120. */ 
  121.  
  122. /** 
  123. * Define the full path to the database class 
  124. */ 
  125. if ( !defined( 'BB_DATABASE_CLASS_INCLUDE' ) ) { 
  126. define( 'BB_DATABASE_CLASS_INCLUDE', BACKPRESS_PATH . 'class.bpdb-multi.php' ); 
  127.  
  128. /** 
  129. * Define the name of the database class 
  130. */ 
  131. if ( !defined( 'BB_DATABASE_CLASS' ) ) { 
  132. define( 'BB_DATABASE_CLASS', 'BPDB_Multi' ); 
  133.  
  134. if ( in_array( BB_DATABASE_CLASS, array( 'BPDB', 'BPDB_Multi' ) ) ) { 
  135. /** 
  136. * Define BackPress Database errors if not already done - no localisation at this stage 
  137. */ 
  138. if ( !defined( 'BPDB__CONNECT_ERROR_MESSAGE' ) ) { 
  139. define( 'BPDB__CONNECT_ERROR_MESSAGE', 'ERROR: Could not establish a database connection' ); 
  140. if ( !defined( 'BPDB__CONNECT_ERROR_MESSAGE' ) ) { 
  141. define( 'BPDB__SELECT_ERROR_MESSAGE', 'ERROR: Can\'t select database.' ); 
  142. if ( !defined( 'BPDB__ERROR_STRING' ) ) { 
  143. define( 'BPDB__ERROR_STRING', 'ERROR: bbPress database error - "%s" for query "%s" via caller "%s"' ); 
  144. if ( !defined( 'BPDB__ERROR_HTML' ) ) { 
  145. define( 'BPDB__ERROR_HTML', '<div id="error"><p class="bpdberror"><strong>Database error:</strong> [%s]<br /><code>%s</code><br />Caller: %s</p></div>' ); 
  146. if ( !defined( 'BPDB__DB_VERSION_ERROR' ) ) { 
  147. define( 'BPDB__DB_VERSION_ERROR', 'ERROR: bbPress requires MySQL 4.0.0 or higher' ); 
  148. if ( !defined( 'BPDB__PHP_EXTENSION_MISSING' ) ) { 
  149. define( 'BPDB__PHP_EXTENSION_MISSING', 'ERROR: bbPress requires The MySQL PHP extension' ); 
  150.  
  151. // Load the database class 
  152. if ( BB_DATABASE_CLASS_INCLUDE ) { 
  153. require_once( BB_DATABASE_CLASS_INCLUDE ); 
  154.  
  155. // Die if there is no database table prefix 
  156. if ( !$bb_table_prefix ) { 
  157. die( 'You must specify a table prefix in your <code>bb-config.php</code> file.' ); 
  158.  
  159. // Setup the global database connection 
  160. $bbdb_class = BB_DATABASE_CLASS; 
  161. $bbdb = new $bbdb_class( array( 
  162. 'name' => BBDB_NAME,  
  163. 'user' => BBDB_USER,  
  164. 'password' => BBDB_PASSWORD,  
  165. 'host' => BBDB_HOST,  
  166. 'charset' => defined( 'BBDB_CHARSET' ) ? BBDB_CHARSET : false,  
  167. 'collate' => defined( 'BBDB_COLLATE' ) ? BBDB_COLLATE : false 
  168. ) ); 
  169. unset( $bbdb_class ); 
  170.  
  171. /** 
  172. * bbPress tables 
  173. */ 
  174. $bbdb->tables = array( 
  175. 'forums' => false,  
  176. 'meta' => false,  
  177. 'posts' => false,  
  178. 'tagged' => false, // Deprecated 
  179. 'tags' => false, // Deprecated 
  180. 'terms' => false,  
  181. 'term_relationships' => false,  
  182. 'term_taxonomy' => false,  
  183. 'topics' => false,  
  184. 'topicmeta' => false, // Deprecated 
  185. 'users' => false,  
  186. 'usermeta' => false 
  187. ); 
  188.  
  189. // Set the prefix on the tables 
  190. if ( is_wp_error( $bbdb->set_prefix( $bb_table_prefix ) ) ) { 
  191. die( 'Your table prefix may only contain letters, numbers and underscores.' ); 
  192.  
  193. // Set a site id if there isn't one already 
  194. if ( !isset( $bb->site_id ) ) { 
  195. $bb->site_id = 1; 
  196.  
  197.  
  198.  
  199. /** 
  200. * Load core bbPress libraries 
  201. */ 
  202.  
  203. require_once( BB_PATH . BB_INC . 'functions.bb-core.php' ); 
  204. require_once( BB_PATH . BB_INC . 'functions.bb-forums.php' ); 
  205. require_once( BB_PATH . BB_INC . 'functions.bb-topics.php' ); 
  206. require_once( BB_PATH . BB_INC . 'functions.bb-posts.php' ); 
  207. require_once( BB_PATH . BB_INC . 'functions.bb-topic-tags.php' ); 
  208. require_once( BB_PATH . BB_INC . 'functions.bb-users.php' ); 
  209. require_once( BB_PATH . BB_INC . 'functions.bb-meta.php' ); 
  210. require_once( BB_PATH . BB_INC . 'class.bb-query.php' ); 
  211. require_once( BB_PATH . BB_INC . 'class.bb-walker.php' ); 
  212.  
  213.  
  214.  
  215. /** 
  216. * Load API and object handling BackPress libraries 
  217. */ 
  218.  
  219. // Plugin API 
  220. if ( !function_exists( 'add_filter' ) ) { 
  221. require_once( BACKPRESS_PATH . 'functions.plugin-api.php' ); 
  222.  
  223. // Shortcodes API 
  224. if ( !function_exists( 'add_shortcode' ) ) { 
  225. require_once( BACKPRESS_PATH . 'functions.shortcodes.php' ); 
  226. } else { 
  227. remove_all_shortcodes(); 
  228.  
  229.  
  230.  
  231. /** 
  232. * Define the full path to the object cache functions include 
  233. */ 
  234. $_internal_object_cache_functions_include = BACKPRESS_PATH . 'loader.wp-object-cache.php'; 
  235. $_memcached_object_cache_functions_include = BACKPRESS_PATH . 'loader.wp-object-cache-memcached.php'; 
  236. if ( !defined( 'BB_OBJECT_CACHE_FUNCTIONS_INCLUDE' ) ) { 
  237. if ( defined( 'BB_OBJECT_CACHE_TYPE' ) && 'memcached' === BB_OBJECT_CACHE_TYPE ) { 
  238. define( 'BB_OBJECT_CACHE_FUNCTIONS_INCLUDE', $_memcached_object_cache_functions_include ); 
  239. } else { 
  240. define( 'BB_OBJECT_CACHE_FUNCTIONS_INCLUDE', $_internal_object_cache_functions_include ); 
  241.  
  242. // See if a caching class is already loaded (by WordPress) 
  243. if ( function_exists( 'wp_cache_init' ) ) { 
  244. if ( isset( $_wp_using_ext_object_cache ) ) { 
  245. $_bb_using_ext_object_cache = $_wp_using_ext_object_cache; 
  246. } else { 
  247. $_bb_using_ext_object_cache = false; 
  248. } elseif ( BB_OBJECT_CACHE_FUNCTIONS_INCLUDE ) { 
  249. // Load the object cache class 
  250. require_once( BB_OBJECT_CACHE_FUNCTIONS_INCLUDE ); 
  251. if ( BB_OBJECT_CACHE_FUNCTIONS_INCLUDE === $_internal_object_cache_functions_include ) { 
  252. $_bb_using_ext_object_cache = false; 
  253. } else { 
  254. $_bb_using_ext_object_cache = true; 
  255. unset( $_internal_object_cache_functions_include ); 
  256.  
  257. // Instantiate the $wp_object_cache object using wp_cache_init() 
  258. if ( function_exists( 'wp_cache_init' ) ) { 
  259. // Clear WordPress cache if it exists already - maybe should save and re-load? 
  260. unset( $wp_object_cache ); 
  261. wp_cache_init(); 
  262. if ( function_exists( 'wp_cache_add_global_groups' ) ) { 
  263. wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'useremail', 'usernicename' ) ); 
  264.  
  265.  
  266.  
  267. /** 
  268. * Load mapping class for BackPress to store options 
  269. */ 
  270. require_once( BB_PATH . BB_INC . 'class.bp-options.php' ); 
  271. require_once( BACKPRESS_PATH . 'functions.bp-options.php' ); 
  272.  
  273.  
  274.  
  275. /** 
  276. * Load WP_Http class 
  277. */ 
  278. if ( !class_exists( 'WP_Http' ) ) { 
  279. require_once( BACKPRESS_PATH . 'class.wp-http.php' ); 
  280.  
  281.  
  282.  
  283. /** 
  284. * Determine language settings and load i10n libraries as required 
  285. */ 
  286.  
  287. /** 
  288. * The full path to the directory containing language files 
  289. */ 
  290. if ( !defined( 'BB_LANG_DIR' ) ) { 
  291. if ( BB_LOAD_DEPRECATED && defined( 'BBLANGDIR' ) ) { 
  292. // User has set old constant 
  293. bb_log_deprecated( 'constant', 'BBLANGDIR', 'BB_LANG_DIR' ); 
  294. define( 'BB_LANG_DIR', BBLANGDIR ); 
  295. } else { 
  296. define( 'BB_LANG_DIR', BB_PATH . 'my-languages/' ); // absolute path with trailing slash 
  297.  
  298. /** 
  299. * The language in which to display bbPress 
  300. */ 
  301. if ( BB_LOAD_DEPRECATED && !defined( 'BB_LANG' ) && defined( 'BBLANG' ) && '' != BBLANG ) { 
  302. // User has set old constant 
  303. bb_log_deprecated( 'constant', 'BBLANG', 'BB_LANG' ); 
  304. define( 'BB_LANG', BBLANG ); 
  305. if ( !class_exists( 'MO' ) ) { 
  306. require_once( BACKPRESS_PATH . 'pomo/mo.php' ); 
  307.  
  308. // Is WordPress loaded 
  309. if ( !defined( 'BB_IS_WP_LOADED') ) { 
  310. define( 'BB_IS_WP_LOADED', defined( 'DB_NAME' ) ); 
  311.  
  312. // Only load this if WordPress isn't loaded 
  313. if ( !BB_IS_WP_LOADED ) { 
  314. require_once( BACKPRESS_PATH . 'functions.kses.php' ); 
  315. require_once( BB_PATH . BB_INC . 'functions.bb-l10n.php' ); 
  316.  
  317.  
  318.  
  319. /** 
  320. * Routines related to installation 
  321. */ 
  322.  
  323. // Load BB_CHANNELS_INCLUDE if it exists, must be done before the install is completed 
  324. if ( defined( 'BB_CHANNELS_INCLUDE' ) && file_exists( BB_CHANNELS_INCLUDE ) && !is_dir( BB_CHANNELS_INCLUDE ) ) { 
  325. require_once( BB_CHANNELS_INCLUDE ); 
  326.  
  327. // If there is no forum table in the database then redirect to the installer 
  328. if ( !BB_INSTALLING && !bb_is_installed() ) { 
  329. $link = preg_replace( '|(/bb-admin)?/[^/]+?$|', '/', $_SERVER['PHP_SELF'] ) . 'bb-admin/install.php'; 
  330. require_once( BB_PATH . BB_INC . 'functions.bb-pluggable.php' ); 
  331. wp_redirect( $link ); 
  332. die(); 
  333.  
  334. // Setup some variables in the $bb class if they don't exist - some of these are deprecated 
  335. if ( BB_LOAD_DEPRECATED ) { 
  336. foreach ( array( 'use_cache' => false, 'debug' => false ) as $o => $oo ) { 
  337. if ( !isset( $bb->$o ) ) { 
  338. $bb->$o = $oo; 
  339. } else { 
  340. bb_log_deprecated( 'variable', '$bb->' . $o ); 
  341. unset( $o, $oo ); 
  342.  
  343. // Disable plugins during installation 
  344. if ( BB_INSTALLING ) { 
  345. foreach ( array('active_plugins') as $i ) { 
  346. $bb->$i = false; 
  347. unset( $i ); 
  348.  
  349.  
  350.  
  351. /** 
  352. * Load additional bbPress libraries 
  353. */ 
  354.  
  355. require_once( BB_PATH . BB_INC . 'functions.bb-formatting.php' ); 
  356. require_once( BB_PATH . BB_INC . 'functions.bb-template.php' ); 
  357. require_once( BB_PATH . BB_INC . 'functions.bb-capabilities.php' ); 
  358. require_once( BB_PATH . BB_INC . 'class.bb-pingbacks.php' ); 
  359.  
  360.  
  361.  
  362. // Cache options from the database 
  363. if ( !isset( $bb->load_options ) ) { 
  364. $bb->load_options = true; 
  365. if ( $bb->load_options ) { 
  366. $bbdb->suppress_errors(); 
  367. bb_cache_all_options(); 
  368. $bbdb->suppress_errors( false ); 
  369.  
  370. /** 
  371. * Set the URI and derivitaves 
  372. */ 
  373. if ( $bb->uri = bb_get_option( 'uri' ) ) { 
  374. $bb->uri = rtrim( trim( $bb->uri ), " \t\n\r\0\x0B/" ) . '/'; 
  375.  
  376. if ( preg_match( '@^(https?://[^/]+)((?:/.*)*/{1, 1})$@i', $bb->uri, $matches ) ) { 
  377. // Used when setting up cookie domain 
  378. $bb->domain = $matches[1]; 
  379. // Used when setting up cookie paths 
  380. $bb->path = $matches[2]; 
  381. unset( $matches ); 
  382. } elseif ( BB_LOAD_DEPRECATED ) { 
  383. // Backwards compatibility 
  384. // These were never set in the database 
  385. if ( isset( $bb->domain ) ) { 
  386. bb_log_deprecated( 'variable', '$bb->domain', '$bb->uri' ); 
  387. $bb->domain = rtrim( trim( $bb->domain ), " \t\n\r\0\x0B/" ); 
  388. if ( isset( $bb->path ) ) { 
  389. bb_log_deprecated( 'variable', '$bb->path', '$bb->uri' ); 
  390. $bb->path = trim( $bb->path ); 
  391. if ( $bb->path != '/' ) $bb->path = '/' . trim( $bb->path, " \t\n\r\0\x0B/" ) . '/'; 
  392. // We need both to build a uri 
  393. if ( $bb->domain && $bb->path ) { 
  394. $bb->uri = $bb->domain . $bb->path; 
  395.  
  396. // Die if no URI 
  397. if ( !BB_INSTALLING && !$bb->uri ) { 
  398. bb_die( __( 'Could not determine site URI' ) ); 
  399.  
  400. /** 
  401. * BB_FORCE_SSL_USER_FORMS - Whether to force use of ssl on user forms like login, registration and profile editing 
  402. */ 
  403. if ( !defined( 'BB_FORCE_SSL_USER_FORMS' ) ) { 
  404. define( 'BB_FORCE_SSL_USER_FORMS', false ); 
  405. force_ssl_login( BB_FORCE_SSL_USER_FORMS ); 
  406.  
  407. /** 
  408. * BB_FORCE_SSL_ADMIN - Whether to force use of ssl in the admin area 
  409. */ 
  410. if ( !defined( 'BB_FORCE_SSL_ADMIN' ) ) { 
  411. define( 'BB_FORCE_SSL_ADMIN', false ); 
  412. force_ssl_admin( BB_FORCE_SSL_ADMIN ); 
  413.  
  414. // Load default filters 
  415. require_once( BB_PATH . BB_INC . 'defaults.bb-filters.php' ); 
  416.  
  417. // Load default scripts 
  418. require_once( BB_PATH . BB_INC . 'functions.bb-script-loader.php' ); 
  419.  
  420. /** Check if the globals have been sanitized by WordPress or not (else there would be extra slashes while deep integration) */ 
  421. if ( !function_exists( 'wp_magic_quotes' ) ) { 
  422. // Sanitise external input 
  423. $_GET = bb_global_sanitize( $_GET ); 
  424. $_POST = bb_global_sanitize( $_POST ); 
  425. $_COOKIE = bb_global_sanitize( $_COOKIE, false ); 
  426. $_SERVER = bb_global_sanitize( $_SERVER ); 
  427.  
  428.  
  429. /** 
  430. * Define theme and plugin constants 
  431. */ 
  432.  
  433. /** 
  434. * Full path to the location of the core plugins directory 
  435. */ 
  436. define( 'BB_CORE_PLUGIN_DIR', BB_PATH . 'bb-plugins/' ); 
  437.  
  438. /** 
  439. * Full URL of the core plugins directory 
  440. */ 
  441. define( 'BB_CORE_PLUGIN_URL', $bb->uri . 'bb-plugins/' ); 
  442.  
  443. /** 
  444. * Full path to the location of the core themes directory 
  445. */ 
  446. define( 'BB_CORE_THEME_DIR', BB_PATH . 'bb-templates/' ); 
  447.  
  448. /** 
  449. * Full URL of the core themes directory 
  450. */ 
  451. define( 'BB_CORE_THEME_URL', $bb->uri . 'bb-templates/' ); 
  452.  
  453. /** 
  454. * The default theme 
  455. */ 
  456. define( 'BB_DEFAULT_THEME', 'core#kakumei' ); 
  457.  
  458. /** 
  459. * Full path to the location of the default theme directory 
  460. */ 
  461. define( 'BB_DEFAULT_THEME_DIR', BB_CORE_THEME_DIR . 'kakumei/' ); 
  462.  
  463. /** 
  464. * Full URL of the default theme directory 
  465. */ 
  466. define( 'BB_DEFAULT_THEME_URL', BB_CORE_THEME_URL . 'kakumei/' ); 
  467.  
  468. /** 
  469. * Full path to the location of the user plugins directory 
  470. */ 
  471. if ( !defined( 'BB_PLUGIN_DIR' ) ) { 
  472. if ( BB_LOAD_DEPRECATED && defined( 'BBPLUGINDIR' ) ) { 
  473. // User has set old constant 
  474. bb_log_deprecated( 'constant', 'BBPLUGINDIR', 'BB_PLUGIN_DIR' ); 
  475. define( 'BB_PLUGIN_DIR', BBPLUGINDIR ); 
  476. } else { 
  477. define( 'BB_PLUGIN_DIR', BB_PATH . 'my-plugins/' ); 
  478.  
  479. /** 
  480. * Full URL of the user plugins directory 
  481. */ 
  482. if ( !defined( 'BB_PLUGIN_URL' ) ) { 
  483. if ( BB_LOAD_DEPRECATED && defined( 'BBPLUGINURL' ) ) { 
  484. // User has set old constant 
  485. bb_log_deprecated( 'constant', 'BBPLUGINURL', 'BB_PLUGIN_URL' ); 
  486. define( 'BB_PLUGIN_URL', BBPLUGINURL ); 
  487. } else { 
  488. define( 'BB_PLUGIN_URL', $bb->uri . 'my-plugins/' ); 
  489.  
  490. /** 
  491. * Full path to the location of the user themes directory 
  492. */ 
  493. if ( !defined( 'BB_THEME_DIR' ) ) { 
  494. if ( BB_LOAD_DEPRECATED && defined( 'BBTHEMEDIR' ) ) { 
  495. // User has set old constant 
  496. bb_log_deprecated( 'constant', 'BBTHEMEDIR', 'BB_THEME_DIR' ); 
  497. define( 'BB_THEME_DIR', BBTHEMEDIR ); 
  498. } else { 
  499. define( 'BB_THEME_DIR', BB_PATH . 'my-templates/' ); 
  500.  
  501. /** 
  502. * Full URL of the user themes directory 
  503. */ 
  504. if ( !defined( 'BB_THEME_URL' ) ) { 
  505. if ( BB_LOAD_DEPRECATED && defined( 'BBTHEMEURL' ) ) { 
  506. // User has set old constant 
  507. bb_log_deprecated( 'constant', 'BBTHEMEURL', 'BB_THEME_URL' ); 
  508. define( 'BB_THEME_URL', BBTHEMEURL ); 
  509. } else { 
  510. define( 'BB_THEME_URL', $bb->uri . 'my-templates/' ); 
  511.  
  512. /** 
  513. * Look-up arrays provide easier access to arbitrary plugin and theme locations 
  514. */ 
  515. $_default_plugin_locations = array( 
  516. 'core' => array( 
  517. 'dir' => BB_CORE_PLUGIN_DIR,  
  518. 'url' => BB_CORE_PLUGIN_URL,  
  519. 'cap' => 'manage_plugins' 
  520. ),  
  521. 'user' => array( 
  522. 'dir' => BB_PLUGIN_DIR,  
  523. 'url' => BB_PLUGIN_URL,  
  524. 'cap' => 'manage_plugins' 
  525. ); 
  526.  
  527. if ( isset( $bb->plugin_locations ) && is_array( $bb->plugin_locations ) ) { 
  528. $bb->plugin_locations = array_merge( $_default_plugin_locations, $bb->plugin_locations ); 
  529. } else { 
  530. $bb->plugin_locations = $_default_plugin_locations; 
  531.  
  532. // Don't accept a plugin location called "all". Unlikely, but really not desirable. 
  533. if ( isset( $bb->plugin_locations['all'] ) ) { 
  534. unset( $bb->plugin_locations['all'] ); 
  535.  
  536. $_default_theme_locations = array( 
  537. 'core' => array( 
  538. 'dir' => BB_CORE_THEME_DIR,  
  539. 'url' => BB_CORE_THEME_URL,  
  540. 'cap' => 'manage_themes' 
  541. ),  
  542. 'user' => array( 
  543. 'dir' => BB_THEME_DIR,  
  544. 'url' => BB_THEME_URL,  
  545. 'cap' => 'manage_themes' 
  546. ); 
  547.  
  548. if ( isset( $bb->theme_locations ) && is_array( $bb->theme_locations ) ) { 
  549. $bb->theme_locations = array_merge( $_default_theme_locations, $bb->theme_locations ); 
  550. } else { 
  551. $bb->theme_locations = $_default_theme_locations; 
  552.  
  553.  
  554.  
  555. /** 
  556. * Add custom tables if present 
  557. */ 
  558.  
  559. // Resolve the various ways custom user tables might be setup 
  560. bb_set_custom_user_tables(); 
  561.  
  562. // Add custom databases if required 
  563. if ( isset( $bb->custom_databases ) ) { 
  564. foreach ( $bb->custom_databases as $connection => $database ) { 
  565. $bbdb->add_db_server( $connection, $database ); 
  566. unset( $connection, $database ); 
  567.  
  568. // Add custom tables if required 
  569. if ( isset( $bb->custom_tables ) ) { 
  570. $bbdb->tables = array_merge( $bbdb->tables, $bb->custom_tables ); 
  571. if ( is_wp_error( $bbdb->set_prefix( $bbdb->prefix ) ) ) { 
  572. die( __( 'Your user table prefix may only contain letters, numbers and underscores.' ) ); 
  573.  
  574.  
  575.  
  576. /** 
  577. * Sort out cookies so they work with WordPress (if required) 
  578. * Note that database integration is no longer a pre-requisite for cookie integration 
  579. */ 
  580.  
  581. $bb->wp_siteurl = bb_get_option( 'wp_siteurl' ); 
  582. if ( $bb->wp_siteurl ) { 
  583. $bb->wp_siteurl = rtrim( trim( $bb->wp_siteurl ), " \t\n\r\0\x0B/" ); 
  584.  
  585. $bb->wp_home = bb_get_option( 'wp_home' ); 
  586. if ( $bb->wp_home ) { 
  587. $bb->wp_home = rtrim( trim( $bb->wp_home ), " \t\n\r\0\x0B/" ); 
  588.  
  589. $bb->wp_cookies_integrated = false; 
  590. $bb->cookiedomain = bb_get_option( 'cookiedomain' ); 
  591. $bb->cookiepath = bb_get_option( 'cookiepath' ); 
  592. $bb->wordpress_mu_primary_blog_id = bb_get_option( 'wordpress_mu_primary_blog_id' ); 
  593.  
  594. if ( $bb->wp_siteurl && $bb->wp_home ) { 
  595. if ( $bb->cookiedomain ) { 
  596. $bb->wp_cookies_integrated = true; 
  597. } else { 
  598. $cookiedomain = bb_get_common_domains( $bb->uri, $bb->wp_home ); 
  599. if ( bb_match_domains( $bb->uri, $bb->wp_home ) ) { 
  600. if ( $bb->wordpress_mu_primary_blog_id ) { 
  601. $bb->cookiedomain = '.' . $cookiedomain; 
  602. if ( !$bb->cookiepath ) { 
  603. $bb->cookiepath = bb_get_common_paths( $bb->uri, $bb->wp_home ); 
  604. $bb->wp_cookies_integrated = true; 
  605. } elseif ( $cookiedomain && strpos( $cookiedomain, '.' ) !== false ) { 
  606. $bb->cookiedomain = '.' . $cookiedomain; 
  607. if ( !$bb->cookiepath ) { 
  608. $bb->cookiepath = bb_get_common_paths( $bb->uri, $bb->wp_home ); 
  609. $bb->wp_cookies_integrated = true; 
  610. unset( $cookiedomain ); 
  611.  
  612. define( 'BB_HASH', $bb->wp_cookies_integrated ? md5( $bb->wp_siteurl ) : md5( $bb->uri ) ); 
  613.  
  614. if ( BB_LOAD_DEPRECATED ) { 
  615. // Deprecated setting 
  616. $bb->usercookie = bb_get_option( 'usercookie' ); 
  617. if ( !$bb->usercookie ) { 
  618. $bb->usercookie = ( $bb->wp_cookies_integrated ? 'wordpressuser_' : 'bb_user_' ) . BB_HASH; 
  619. } else { 
  620. bb_log_deprecated( 'variable', '$bb->usercookie' ); 
  621.  
  622. // Deprecated setting 
  623. $bb->passcookie = bb_get_option( 'passcookie' ); 
  624. if ( !$bb->passcookie ) { 
  625. $bb->passcookie = ( $bb->wp_cookies_integrated ? 'wordpresspass_' : 'bb_pass_' ) . BB_HASH; 
  626. } else { 
  627. bb_log_deprecated( 'variable', '$bb->passcookie' ); 
  628.  
  629. $bb->authcookie = bb_get_option( 'authcookie' ); 
  630. if ( !$bb->authcookie ) { 
  631. $bb->authcookie = ( $bb->wp_cookies_integrated ? 'wordpress_' : 'bbpress_' ) . BB_HASH; 
  632.  
  633. $bb->secure_auth_cookie = bb_get_option( 'secure_auth_cookie' ); 
  634. if ( !$bb->secure_auth_cookie ) { 
  635. $bb->secure_auth_cookie = ( $bb->wp_cookies_integrated ? 'wordpress_sec_' : 'bbpress_sec_' ) . BB_HASH; 
  636.  
  637. $bb->logged_in_cookie = bb_get_option( 'logged_in_cookie' ); 
  638. if ( !$bb->logged_in_cookie ) { 
  639. $bb->logged_in_cookie = ( $bb->wp_cookies_integrated ? 'wordpress_logged_in_' : 'bbpress_logged_in_' ) . BB_HASH; 
  640.  
  641. // Cookie path was set before integration logic above 
  642. if ( !$bb->cookiepath ) { 
  643. $bb->cookiepath = $bb->wp_cookies_integrated ? preg_replace( '|https?://[^/]+|i', '', $bb->wp_home ) : $bb->path; 
  644. $bb->cookiepath = rtrim( trim( $bb->cookiepath ), " \t\n\r\0\x0B/" ) . '/'; 
  645.  
  646. $bb->admin_cookie_path = bb_get_option( 'admin_cookie_path' ); 
  647. if ( !$bb->admin_cookie_path ) { 
  648. $bb->admin_cookie_path = $bb->path . 'bb-admin'; 
  649. if ( '/' !== $bb->admin_cookie_path = trim( $bb->admin_cookie_path ) ) { 
  650. $bb->admin_cookie_path = rtrim( $bb->admin_cookie_path, " \t\n\r\0\x0B/" ); 
  651.  
  652. if ( BB_LOAD_DEPRECATED ) { 
  653. $_plugin_cookie_paths = bb_get_option( 'plugin_cookie_paths' ); 
  654.  
  655. // Deprecated settings 
  656. if ( $_plugin_cookie_paths ) { 
  657. if ( isset( $_plugin_cookie_paths['core'] ) && $_plugin_cookie_paths['core'] ) { 
  658. $bb->core_plugins_cookie_path = $_plugin_cookie_paths['core']; 
  659. if ( isset( $_plugin_cookie_paths['user'] ) && $_plugin_cookie_paths['user'] ) { 
  660. $bb->user_plugins_cookie_path = $_plugin_cookie_paths['user']; 
  661. } else { 
  662. if ( $bb->core_plugins_cookie_path = bb_get_option( 'core_plugins_cookie_path' ) ) { 
  663. bb_log_deprecated( 'variable', '$bb->core_plugins_cookie_path', '$bb->plugin_cookie_paths[\'core\']' ); 
  664. if ( $bb->user_plugins_cookie_path = bb_get_option( 'user_plugins_cookie_path' ) ) { 
  665. bb_log_deprecated( 'variable', '$bb->core_plugins_cookie_path', '$bb->plugin_cookie_paths[\'user\']' ); 
  666.  
  667. if ( !$bb->core_plugins_cookie_path && isset( $bb->plugin_locations['core']['url'] ) && $bb->plugin_locations['core']['url'] ) { 
  668. $bb->core_plugins_cookie_path = preg_replace( '|https?://[^/]+|i', '', $bb->plugin_locations['core']['url'] ); 
  669. $bb->core_plugins_cookie_path = rtrim( trim( $bb->core_plugins_cookie_path ), " \t\n\r\0\x0B/" ); 
  670.  
  671. if ( !$bb->user_plugins_cookie_path && isset( $bb->plugin_locations['user']['url'] ) && $bb->plugin_locations['user']['url'] ) { 
  672. $bb->user_plugins_cookie_path = preg_replace( '|https?://[^/]+|i', '', $bb->plugin_locations['user']['url'] ); 
  673. $bb->user_plugins_cookie_path = rtrim( trim( $bb->user_plugins_cookie_path ), " \t\n\r\0\x0B/" ); 
  674.  
  675. if ( !$_plugin_cookie_paths ) { 
  676. $bb->plugin_cookie_paths = array(); 
  677. if ( !isset( $_plugin_cookie_paths['core'] ) ) { 
  678. $bb->plugin_cookie_paths['core'] = $bb->core_plugins_cookie_path; 
  679. if ( !isset( $_plugin_cookie_paths['user'] ) ) { 
  680. $bb->plugin_cookie_paths['user'] = $bb->user_plugins_cookie_path; 
  681.  
  682. $bb->sitecookiepath = bb_get_option( 'sitecookiepath' ); 
  683. $_bb_sitecookiepath = $bb->sitecookiepath; 
  684. if ( !$bb->sitecookiepath && $bb->wp_cookies_integrated ) { 
  685. $bb->sitecookiepath = preg_replace( '|https?://[^/]+|i', '', $bb->wp_siteurl ); 
  686. $_bb_sitecookiepath = $bb->sitecookiepath; 
  687. $bb->sitecookiepath = rtrim( trim( $bb->sitecookiepath ), " \t\n\r\0\x0B/" ) . '/'; 
  688.  
  689. $bb->wp_admin_cookie_path = bb_get_option( 'wp_admin_cookie_path' ); 
  690. if ( !$bb->wp_admin_cookie_path && $bb->wp_cookies_integrated ) { 
  691. if ( $bb->wordpress_mu_primary_blog_id ) { 
  692. $bb->wp_admin_cookie_path = $_bb_sitecookiepath; 
  693. } else { 
  694. $bb->wp_admin_cookie_path = $_bb_sitecookiepath . '/wp-admin'; 
  695. if ( '/' !== $bb->wp_admin_cookie_path = trim( $bb->wp_admin_cookie_path ) ) { 
  696. $bb->wp_admin_cookie_path = rtrim( $bb->wp_admin_cookie_path, " \t\n\r\0\x0B/" ); 
  697.  
  698. $bb->wp_plugins_cookie_path = bb_get_option( 'wp_plugins_cookie_path' ); 
  699. if ( !$bb->wp_plugins_cookie_path && $bb->wp_cookies_integrated ) { 
  700. // This is a best guess only, should be manually set to match WP_PLUGIN_URL 
  701. $bb->wp_plugins_cookie_path = $_bb_sitecookiepath . '/wp-content/plugins'; 
  702. if ( '/' !== $bb->wp_plugins_cookie_path = trim( $bb->wp_plugins_cookie_path ) ) { 
  703. $bb->wp_plugins_cookie_path = rtrim( $bb->wp_plugins_cookie_path, " \t\n\r\0\x0B/" ); 
  704. unset( $_bb_sitecookiepath ); 
  705.  
  706. /** 
  707. * Should be exactly the same as the default value of the KEYS in bb-config-sample.php 
  708. * @since 1.0 
  709. */ 
  710. $bb_default_secret_key = 'put your unique phrase here'; 
  711.  
  712.  
  713.  
  714. /** 
  715. * Initialise localisation 
  716. */ 
  717.  
  718. // Load the default text localization domain. 
  719. bb_load_default_textdomain(); 
  720.  
  721. // Pull in locale data after loading text domain. 
  722. require_once( BB_PATH . BB_INC . 'class.bb-locale.php' ); 
  723.  
  724. /** 
  725. * Localisation object 
  726. */ 
  727. $bb_locale = new BB_Locale(); 
  728.  
  729.  
  730.  
  731. /** 
  732. * Remaining BackPress 
  733. */ 
  734.  
  735. // WP_Pass 
  736. if ( !class_exists( 'WP_Pass' ) ) { 
  737. require_once( BACKPRESS_PATH . 'class.wp-pass.php' ); 
  738.  
  739. // WP_Users 
  740. if ( !class_exists( 'WP_Users' ) ) { 
  741. require_once( BACKPRESS_PATH . 'class.wp-users.php' ); 
  742. $wp_users_object = new WP_Users( $bbdb ); 
  743.  
  744. if ( !class_exists( 'BP_Roles' ) ) { 
  745. require_once( BACKPRESS_PATH . 'class.bp-roles.php' ); 
  746.  
  747. /** 
  748. * BP_Roles object 
  749. */ 
  750. $wp_roles = new BP_Roles( $bbdb ); 
  751.  
  752. // BP_User 
  753. if ( !class_exists( 'BP_User' ) ) { 
  754. require_once( BACKPRESS_PATH . 'class.bp-user.php' ); 
  755.  
  756. // WP_Auth 
  757. if ( !class_exists( 'WP_Auth' ) ) { 
  758. require_once( BACKPRESS_PATH . 'class.wp-auth.php' ); 
  759.  
  760. $cookies = array(); 
  761.  
  762. $cookies['logged_in'][] = array( 
  763. 'domain' => $bb->cookiedomain,  
  764. 'path' => $bb->cookiepath,  
  765. 'name' => $bb->logged_in_cookie 
  766. ); 
  767.  
  768. if ( $bb->sitecookiepath && $bb->cookiepath != $bb->sitecookiepath ) { 
  769. $cookies['logged_in'][] = array( 
  770. 'domain' => $bb->cookiedomain,  
  771. 'path' => $bb->sitecookiepath,  
  772. 'name' => $bb->logged_in_cookie 
  773. ); 
  774.  
  775. $cookies['auth'][] = array( 
  776. 'domain' => $bb->cookiedomain,  
  777. 'path' => $bb->admin_cookie_path,  
  778. 'name' => $bb->authcookie 
  779. ); 
  780.  
  781. $cookies['secure_auth'][] = array( 
  782. 'domain' => $bb->cookiedomain,  
  783. 'path' => $bb->admin_cookie_path,  
  784. 'name' => $bb->secure_auth_cookie,  
  785. 'secure' => true 
  786. ); 
  787.  
  788. $_plugin_cookie_paths = bb_get_option( 'plugin_cookie_paths' ); 
  789. foreach ( $bb->plugin_locations as $_name => $_data ) { 
  790. if ( isset( $_data['cookie_path'] ) && !empty( $_data['cookie_path'] ) ) { 
  791. $_cookie_path = $_data['cookie_path']; 
  792. } elseif ( !$_plugin_cookie_paths || !isset( $_plugin_cookie_paths[$_name] ) || !$_plugin_cookie_paths[$_name] ) { 
  793. $_cookie_path = preg_replace( '|https?://[^/]+|i', '', $_data['url'] ); 
  794. } else { 
  795. $_cookie_path = $_plugin_cookie_paths[$_name]; 
  796. if ( '/' !== $_cookie_path = trim( $_cookie_path ) ) { 
  797. $_cookie_path = rtrim( $_cookie_path, " \t\n\r\0\x0B/" ); 
  798.  
  799. if ( !$_cookie_path ) { 
  800. continue; 
  801.  
  802. $_auth = array( 
  803. 'domain' => $bb->cookiedomain,  
  804. 'path' => $_cookie_path,  
  805. 'name' => $bb->authcookie 
  806. ); 
  807.  
  808. if ( !in_array( $_auth, $cookies['auth'] ) ) { 
  809. $cookies['auth'][] = $_auth; 
  810.  
  811. $_secure_auth = array( 
  812. 'domain' => $bb->cookiedomain,  
  813. 'path' => $_cookie_path,  
  814. 'name' => $bb->secure_auth_cookie,  
  815. 'secure' => true 
  816. ); 
  817.  
  818. if ( !in_array( $_secure_auth, $cookies['secure_auth'] ) ) { 
  819. $cookies['secure_auth'][] = $_secure_auth; 
  820. unset( $_plugin_cookie_paths, $_type, $_data, $_cookie_path, $_auth, $_secure_auth ); 
  821.  
  822. if ( $bb->wp_admin_cookie_path ) { 
  823. $cookies['auth'][] = array( 
  824. 'domain' => $bb->cookiedomain,  
  825. 'path' => $bb->wp_admin_cookie_path,  
  826. 'name' => $bb->authcookie 
  827. ); 
  828.  
  829. $cookies['secure_auth'][] = array( 
  830. 'domain' => $bb->cookiedomain,  
  831. 'path' => $bb->wp_admin_cookie_path,  
  832. 'name' => $bb->secure_auth_cookie,  
  833. 'secure' => true 
  834. ); 
  835.  
  836. if ( $bb->wp_plugins_cookie_path ) { 
  837. $cookies['auth'][] = array( 
  838. 'domain' => $bb->cookiedomain,  
  839. 'path' => $bb->wp_plugins_cookie_path,  
  840. 'name' => $bb->authcookie 
  841. ); 
  842.  
  843. $cookies['secure_auth'][] = array( 
  844. 'domain' => $bb->cookiedomain,  
  845. 'path' => $bb->wp_plugins_cookie_path,  
  846. 'name' => $bb->secure_auth_cookie,  
  847. 'secure' => true 
  848. ); 
  849.  
  850. /** 
  851. * The current cookie version 
  852. * 
  853. * Version 1 is for WordPress >= 2.6 and < 2.8 
  854. * Version 2 is for WordPress >= 2.8 
  855. */ 
  856. if ( !defined( 'WP_AUTH_COOKIE_VERSION' ) ) { 
  857. define( 'WP_AUTH_COOKIE_VERSION', 2 ); 
  858.  
  859. /** 
  860. * WP_Auth object 
  861. */ 
  862. $wp_auth_object = new WP_Auth( $bbdb, $wp_users_object, $cookies ); 
  863.  
  864. unset( $cookies ); 
  865.  
  866. /** 
  867. * Current user object 
  868. */ 
  869. $bb_current_user =& $wp_auth_object->current; 
  870.  
  871. // WP_Scripts/WP_Styles 
  872. if ( !class_exists( 'WP_Dependencies' ) ) { 
  873. require_once( BACKPRESS_PATH . 'class.wp-dependencies.php' ); 
  874.  
  875. if ( !class_exists( 'WP_Scripts' ) ) { 
  876. require_once( BACKPRESS_PATH . 'class.wp-scripts.php' ); 
  877. require_once( BACKPRESS_PATH . 'functions.wp-scripts.php' ); 
  878. } else { 
  879. unset( $wp_scripts ); 
  880.  
  881. if ( !class_exists( 'WP_Styles' ) ) { 
  882. require_once( BACKPRESS_PATH . 'class.wp-styles.php' ); 
  883. require_once( BACKPRESS_PATH . 'functions.wp-styles.php' ); 
  884. } else { 
  885. unset( $wp_styles ); 
  886.  
  887.  
  888.  
  889. // WP_Taxonomy 
  890. if ( !class_exists( 'WP_Taxonomy' ) ) { 
  891. require_once( BACKPRESS_PATH . 'class.wp-taxonomy.php' ); 
  892. if ( !class_exists( 'BB_Taxonomy' ) ) { 
  893. require_once( BB_PATH . BB_INC . 'class.bb-taxonomy.php' ); 
  894. if ( !isset( $wp_taxonomy_object ) ) { 
  895. // Clean slate 
  896. $wp_taxonomy_object = new BB_Taxonomy( $bbdb ); 
  897. } elseif ( !is_a( $wp_taxonomy_object, 'BB_Taxonomy' ) ) { 
  898. // exists, but it's not good enough, translate it 
  899.  
  900. // preserve the references 
  901. $tax =& $wp_taxonomy_object->taxonomies; 
  902. $wp_taxonomy_object = new BB_Taxonomy( $bbdb ); 
  903. $wp_taxonomy_object->taxonomies =& $tax; 
  904. unset( $tax ); 
  905.  
  906. $wp_taxonomy_object->register_taxonomy( 'bb_topic_tag', 'bb_topic' ); 
  907.  
  908. $wp_taxonomy_object->register_taxonomy( 'bb_subscribe', 'bb_user' ); 
  909.  
  910. do_action( 'bb_options_loaded' ); 
  911.  
  912.  
  913.  
  914. /** 
  915. * Load deprecated constants and functions 
  916. */ 
  917.  
  918. // Skip loading of deprecated stuff unless specifically requested 
  919. if ( BB_LOAD_DEPRECATED ) { 
  920. /** 
  921. * Define deprecated constants for plugin compatibility 
  922. * $deprecated_constants below is a complete array of old constants and their replacements 
  923. */ 
  924. $deprecated_constants = array( 
  925. 'BBPATH' => 'BB_PATH',  
  926. 'BBINC' => 'BB_INC',  
  927. 'BBLANG' => 'BB_LANG',  
  928. 'BBLANGDIR' => 'BB_LANG_DIR',  
  929. 'BBPLUGINDIR' => 'BB_PLUGIN_DIR',  
  930. 'BBPLUGINURL' => 'BB_PLUGIN_URL',  
  931. 'BBTHEMEDIR' => 'BB_THEME_DIR',  
  932. 'BBTHEMEURL' => 'BB_THEME_URL',  
  933. 'BBHASH' => 'BB_HASH' 
  934. ); 
  935. foreach ( $deprecated_constants as $old => $new ) { 
  936. // only define if new one is defined 
  937. if ( !defined( $old ) && defined( $new ) ) { 
  938. define( $old, constant( $new ) ); 
  939. } elseif ( defined( $old ) ) { 
  940. bb_log_deprecated( 'constant', $old, $new ); 
  941.  
  942. $deprecated_constants = array( 
  943. 'USER_BBDB_NAME' => 'user_bbdb_name',  
  944. 'USER_BBDB_USER' => 'user_bbdb_user',  
  945. 'USER_BBDB_PASSWORD' => 'user_bbdb_password',  
  946. 'USER_BBDB_HOST' => 'user_bbdb_host',  
  947. 'USER_BBDB_CHARSET' => 'user_bbdb_charset',  
  948. 'CUSTOM_USER_TABLE' => 'custom_user_table',  
  949. 'CUSTOM_USER_META_TABLE' => 'custom_user_meta_table',  
  950. ); 
  951. foreach ( $deprecated_constants as $old => $new ) { 
  952. if ( !defined( $old ) ) { 
  953. define( $old, $bb->$new ); 
  954. } else { 
  955. bb_log_deprecated( 'constant', $old, '$bb->' . $new ); 
  956. unset($deprecated_constants, $old, $new); 
  957.  
  958. /** 
  959. * Load deprecated functions 
  960. */ 
  961. require_once( BB_PATH . BB_INC . 'functions.bb-deprecated.php' ); 
  962.  
  963. /** 
  964. * Old cache global object for backwards compatibility 
  965. */ 
  966. $bb_cache = new BB_Cache(); 
  967.  
  968.  
  969.  
  970. /** 
  971. * Load active template functions.php file 
  972. */ 
  973. $template_functions_include = bb_get_active_theme_directory() . 'functions.php'; 
  974. if ( file_exists( $template_functions_include ) ) { 
  975. require_once( $template_functions_include ); 
  976. unset( $template_functions_include ); 
  977.  
  978.  
  979.  
  980. /** 
  981. * Load Plugins 
  982. */ 
  983.  
  984. // Skip plugin loading in "safe" mode 
  985. if ( $bb->plugin_locations && ( !isset( $bb->safemode ) || $bb->safemode !== true ) ) { 
  986. // Autoloaded "underscore" plugins 
  987. foreach ( $bb->plugin_locations as $_name => $_data ) { 
  988. foreach ( bb_glob( $_data['dir'] . '_*.php' ) as $_plugin ) { 
  989. require_once( $_plugin ); 
  990. unset( $_plugin ); 
  991. unset( $_name, $_data ); 
  992. do_action( 'bb_underscore_plugins_loaded' ); 
  993.  
  994. // Normal plugins 
  995. if ( $_plugins = bb_get_option( 'active_plugins' ) ) { 
  996. foreach ( (array) $_plugins as $_plugin ) { 
  997. if ( !preg_match( '/^([a-z0-9_-]+)#((?:[a-z0-9\/\\_-]+.)+)(php)$/i', $_plugin, $_matches ) ) { 
  998. // The plugin entry in the database is invalid 
  999. continue; 
  1000.  
  1001. $_directory = $bb->plugin_locations[$_matches[1]]['dir']; 
  1002. $_plugin = $_matches[2] . $_matches[3]; 
  1003.  
  1004. if ( !$_plugin ) { 
  1005. // Not likely 
  1006. continue; 
  1007.  
  1008. if ( validate_file( $_plugin ) ) { 
  1009. // $plugin has .., :, etc. 
  1010. continue; 
  1011.  
  1012. if ( !file_exists( $_directory . $_plugin ) ) { 
  1013. // The plugin isn't there 
  1014. continue; 
  1015.  
  1016. require_once( $_directory . $_plugin ); 
  1017. unset( $_plugins, $_plugin, $_directory ); 
  1018. do_action( 'bb_plugins_loaded' ); 
  1019.  
  1020. require_once( BB_PATH . BB_INC . 'functions.bb-pluggable.php' ); 
  1021.  
  1022.  
  1023.  
  1024. /** 
  1025. * Reference to $wp_roles 
  1026. */ 
  1027. $bb_roles =& $wp_roles; 
  1028. do_action( 'bb_got_roles' ); 
  1029.  
  1030.  
  1031.  
  1032. /** 
  1033. * Create an API hook to run on shutdown 
  1034. */ 
  1035.  
  1036. function bb_shutdown_action_hook() { 
  1037. do_action( 'bb_shutdown' ); 
  1038. register_shutdown_function( 'bb_shutdown_action_hook' ); 
  1039.  
  1040.  
  1041. /** 
  1042. * Get details of the current user 
  1043. */ 
  1044.  
  1045. bb_current_user(); 
  1046.  
  1047.  
  1048.  
  1049. /** 
  1050. * Initialise CRON 
  1051. */ 
  1052.  
  1053. if ( !function_exists( 'wp_schedule_single_event' ) ) { 
  1054. require_once( BACKPRESS_PATH . 'functions.wp-cron.php' ); 
  1055. if ( ( !defined('DOING_CRON') || !DOING_CRON ) ) { 
  1056. wp_cron(); 
  1057.  
  1058.  
  1059.  
  1060. /** 
  1061. * The currently viewed page number 
  1062. */ 
  1063. $page = bb_get_uri_page(); 
  1064.  
  1065.  
  1066.  
  1067. /** 
  1068. * Initialisation complete API hook 
  1069. */ 
  1070.  
  1071. do_action( 'bb_init' ); 
  1072.  
  1073.  
  1074.  
  1075. /** 
  1076. * Block user if they deserve it 
  1077. */ 
  1078.  
  1079. if ( bb_is_user_logged_in() && bb_has_broken_pass() ) { 
  1080. bb_block_current_user(); 
  1081.  
  1082.  
  1083.  
  1084. /** 
  1085. * Send HTTP headers 
  1086. */ 
  1087.  
  1088. bb_send_headers(); 
.