PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/buddypress/bp-loader.php

https://bitbucket.org/codemen_iftekhar/codemen
PHP | 487 lines | 157 code | 92 blank | 238 comment | 21 complexity | 86b062beeb9104f3085325d51d4e05bb MD5 | raw file
  1. <?php
  2. /**
  3. * The BuddyPress Plugin
  4. *
  5. * BuddyPress is social networking software with a twist from the creators of WordPress.
  6. *
  7. * @package BuddyPress
  8. * @subpackage Main
  9. */
  10. /**
  11. * Plugin Name: BuddyPress
  12. * Plugin URI: http://buddypress.org
  13. * Description: Social networking in a box. Build a social network for your company, school, sports team or niche community all based on the power and flexibility of WordPress.
  14. * Author: The BuddyPress Community
  15. * Author URI: http://buddypress.org/community/members/
  16. * Version: 1.6.4
  17. * Text Domain: buddypress
  18. * Domain Path: /bp-languages/
  19. */
  20. // Exit if accessed directly
  21. if ( !defined( 'ABSPATH' ) ) exit;
  22. /** Constants *****************************************************************/
  23. if ( !class_exists( 'BuddyPress' ) ) :
  24. /**
  25. * Main BuddyPress Class
  26. *
  27. * Tap tap tap... Is this thing on?
  28. *
  29. * @since BuddyPress (1.6)
  30. */
  31. class BuddyPress {
  32. /**
  33. * Note to Plugin and Theme authors:
  34. *
  35. * Do not directly reference the variables below in your code. Their names
  36. * and locations in the BuddyPress class are subject to change at any time.
  37. *
  38. * Most of them have reference functions located in bp-core-functions.php.
  39. * The ones that don't can be accessed via their respective WordPress API's.
  40. *
  41. * Components are encouraged to store their data in the $bp global rather
  42. * than new globals to keep all BuddyPress data in one place.
  43. */
  44. /** Version ***************************************************************/
  45. /**
  46. * @var string BuddyPress version
  47. */
  48. public $version = '1.6.4';
  49. /**
  50. * @var int Database version of current BuddyPress files
  51. */
  52. public $db_version = 6066;
  53. /**
  54. * @var int Database version raw from database connection
  55. */
  56. public $db_version_raw = 0;
  57. /**
  58. * @var string State of BuddyPress installation
  59. */
  60. public $maintenance_mode = '';
  61. /**
  62. * @var bool Include deprecated BuddyPress files or not
  63. */
  64. public $load_deprecated = true;
  65. /** Root ******************************************************************/
  66. /**
  67. * @var int The root blog ID
  68. */
  69. public $root_blog_id = 1;
  70. /** Paths *****************************************************************/
  71. /**
  72. * The absolute path and filename of this file.
  73. *
  74. * @since BuddyPress (1.6)
  75. * @var string
  76. */
  77. public $file;
  78. /**
  79. * @var string Basename of the BuddyPress plugin directory
  80. */
  81. public $basename = '';
  82. /**
  83. * @var string Absolute path to the BuddyPress plugin directory
  84. */
  85. public $plugin_dir = '';
  86. /**
  87. * @var string Absolute path to the BuddyPress themes directory
  88. */
  89. public $themes_dir = '';
  90. /**
  91. * @var string Absolute path to the BuddyPress language directory
  92. */
  93. public $lang_dir = '';
  94. /** URLs ******************************************************************/
  95. /**
  96. * @var string URL to the BuddyPress plugin directory
  97. */
  98. public $plugin_url = '';
  99. /**
  100. * @var string URL to the BuddyPress themes directory
  101. */
  102. public $themes_url = '';
  103. /** Users *****************************************************************/
  104. /**
  105. * @var object Current user
  106. */
  107. public $current_user = null;
  108. /**
  109. * @var object Displayed user
  110. */
  111. public $displayed_user = null;
  112. /** Navigation ************************************************************/
  113. /**
  114. * @var array Primary BuddyPress navigation
  115. */
  116. public $bp_nav = array();
  117. /**
  118. * @var array Secondary BuddyPress navigation to $bp_nav
  119. */
  120. public $bp_options_nav = array();
  121. /** Toolbar ***************************************************************/
  122. /**
  123. * @var string The primary toolbar ID
  124. */
  125. public $my_account_menu_id = '';
  126. /** URI's *****************************************************************/
  127. /**
  128. * @var array The unfiltered URI broken down into chunks
  129. * @see bp_core_set_uri_globals()
  130. */
  131. public $unfiltered_uri = array();
  132. /**
  133. * @var int The current offset of the URI
  134. * @see bp_core_set_uri_globals()
  135. */
  136. public $unfiltered_uri_offset = 0;
  137. /**
  138. * @var bool Are status headers already sent?
  139. */
  140. public $no_status_set = false;
  141. /**
  142. * @var array The canonical URI stack
  143. * @see bp_redirect_canonical()
  144. * @see bp_core_new_nav_item()
  145. */
  146. public $canonical_stack = array();
  147. /** Components ************************************************************/
  148. /**
  149. * @var string Name of the current BuddyPress component (primary)
  150. */
  151. public $current_component = '';
  152. /**
  153. * @var string Name of the current BuddyPress item (secondary)
  154. */
  155. public $current_item = '';
  156. /**
  157. * @var string Name of the current BuddyPress action (tertiary)
  158. */
  159. public $current_action = '';
  160. /**
  161. * @var array Additional navigation elements (supplemental)
  162. */
  163. public $action_variables = array();
  164. /**
  165. * @var bool Displaying custom 2nd level navigation menu (I.E a group)
  166. */
  167. public $is_single_item = false;
  168. /** Option Overload *******************************************************/
  169. /**
  170. * @var array Optional Overloads default options retrieved from get_option()
  171. */
  172. public $options = array();
  173. /** Functions *************************************************************/
  174. /**
  175. * The main BuddyPress loader
  176. *
  177. * @since BuddyPress (1.6)
  178. *
  179. * @uses BuddyPress::constants() Setup legacy constants
  180. * @uses BuddyPress::setup_globals() Setup globals needed
  181. * @uses BuddyPress::includes() Includ required files
  182. * @uses BuddyPress::setup_actions() Setup hooks and actions
  183. */
  184. public function __construct() {
  185. $this->constants();
  186. $this->setup_globals();
  187. $this->includes();
  188. $this->setup_actions();
  189. }
  190. /**
  191. * Legacy BuddyPress constants
  192. *
  193. * Try to avoid using these. Their values have been moved into variables
  194. * in the $bp global, and have matching functions to get/set their value.
  195. *
  196. * @since BuddyPress (1.6)
  197. *
  198. * @uses is_multisite()
  199. * @uses get_current_site()
  200. * @uses get_current_blog_id()
  201. * @uses plugin_dir_path()
  202. * @uses plugin_dir_url()
  203. */
  204. private function constants() {
  205. // Define the BuddyPress version
  206. if ( !defined( 'BP_VERSION' ) )
  207. define( 'BP_VERSION', $this->version );
  208. // Define the database version
  209. if ( !defined( 'BP_DB_VERSION' ) )
  210. define( 'BP_DB_VERSION', $this->db_version );
  211. // Place your custom code (actions/filters) in a file called
  212. // '/plugins/bp-custom.php' and it will be loaded before anything else.
  213. if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) )
  214. require( WP_PLUGIN_DIR . '/bp-custom.php' );
  215. // Define on which blog ID BuddyPress should run
  216. if ( !defined( 'BP_ROOT_BLOG' ) ) {
  217. // Default to 1
  218. $root_blog_id = 1;
  219. // Root blog is the main site on this network
  220. if ( is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ) {
  221. $current_site = get_current_site();
  222. $root_blog_id = $current_site->blog_id;
  223. // Root blog is every site on this network
  224. } elseif ( is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) ) {
  225. $root_blog_id = get_current_blog_id();
  226. }
  227. define( 'BP_ROOT_BLOG', $root_blog_id );
  228. }
  229. // Path and URL
  230. if ( !defined( 'BP_PLUGIN_DIR' ) )
  231. define( 'BP_PLUGIN_DIR', trailingslashit( WP_PLUGIN_DIR . '/buddypress' ) );
  232. if ( !defined( 'BP_PLUGIN_URL' ) ) {
  233. $plugin_url = plugin_dir_url( __FILE__ );
  234. // If we're using https, update the protocol. Workaround for WP13941, WP15928, WP19037.
  235. if ( is_ssl() )
  236. $plugin_url = str_replace( 'http://', 'https://', $plugin_url );
  237. define( 'BP_PLUGIN_URL', $plugin_url );
  238. }
  239. // The search slug has to be defined nice and early because of the way
  240. // search requests are loaded
  241. //
  242. // @todo Make this better
  243. if ( !defined( 'BP_SEARCH_SLUG' ) )
  244. define( 'BP_SEARCH_SLUG', 'search' );
  245. }
  246. /**
  247. * Component global variables
  248. *
  249. * @since BuddyPress (1.6)
  250. * @access private
  251. *
  252. * @uses plugin_dir_path() To generate BuddyPress plugin path
  253. * @uses plugin_dir_url() To generate BuddyPress plugin url
  254. * @uses apply_filters() Calls various filters
  255. */
  256. private function setup_globals() {
  257. /** Root **************************************************************/
  258. // BuddyPress Root blog ID
  259. $this->root_blog_id = (int) apply_filters( 'bp_get_root_blog_id', BP_ROOT_BLOG );
  260. /** Paths *************************************************************/
  261. // BuddyPress root directory
  262. $this->file = __FILE__;
  263. $this->basename = plugin_basename( $this->file );
  264. $this->plugin_dir = BP_PLUGIN_DIR;
  265. $this->plugin_url = BP_PLUGIN_URL;
  266. // Themes
  267. $this->themes_dir = $this->plugin_dir . 'bp-themes';
  268. $this->themes_url = $this->plugin_url . 'bp-themes';
  269. // Languages
  270. $this->lang_dir = $this->plugin_dir . 'bp-languages';
  271. /** Users *************************************************************/
  272. $this->current_user = new stdClass();
  273. $this->displayed_user = new stdClass();
  274. }
  275. /**
  276. * Include required files
  277. *
  278. * @since BuddyPress (1.6)
  279. * @access private
  280. *
  281. * @uses is_admin() If in WordPress admin, load additional file
  282. */
  283. private function includes() {
  284. // Load the WP abstraction file so BuddyPress can run on all WordPress setups.
  285. require( BP_PLUGIN_DIR . '/bp-core/bp-core-wpabstraction.php' );
  286. // Get the possible DB versions (boy is this gross)
  287. $versions = array();
  288. $versions['1.6-single'] = get_blog_option( $this->root_blog_id, '_bp_db_version' );
  289. // 1.6-single exists, so trust it
  290. if ( !empty( $versions['1.6-single'] ) ) {
  291. $this->db_version_raw = (int) $versions['1.6-single'];
  292. // If no 1.6-single exists, use the max of the others
  293. } else {
  294. $versions['1.2'] = get_site_option( 'bp-core-db-version' );
  295. $versions['1.5-multi'] = get_site_option( 'bp-db-version' );
  296. $versions['1.6-multi'] = get_site_option( '_bp_db_version' );
  297. $versions['1.5-single'] = get_blog_option( $this->root_blog_id, 'bp-db-version' );
  298. // Remove empty array items
  299. $versions = array_filter( $versions );
  300. $this->db_version_raw = (int) ( !empty( $versions ) ) ? (int) max( $versions ) : 0;
  301. }
  302. /** Update/Install ****************************************************/
  303. // This is a new installation
  304. if ( is_admin() ) {
  305. // New installation
  306. if ( empty( $this->db_version_raw ) ) {
  307. $this->maintenance_mode = 'install';
  308. // Update
  309. } elseif ( (int) $this->db_version_raw < (int) $this->db_version ) {
  310. $this->maintenance_mode = 'update';
  311. }
  312. // The installation process requires a few BuddyPress core libraries
  313. if ( !empty( $this->maintenance_mode ) ) {
  314. require( $this->plugin_dir . 'bp-core/bp-core-admin.php' );
  315. require( $this->plugin_dir . 'bp-core/bp-core-functions.php' );
  316. require( $this->plugin_dir . 'bp-core/bp-core-template.php' );
  317. require( $this->plugin_dir . 'bp-core/bp-core-update.php' );
  318. require( $this->plugin_dir . 'bp-core/bp-core-caps.php' );
  319. require( $this->plugin_dir . 'bp-core/bp-core-options.php' );
  320. /**
  321. * Textdomain is usually loaded via the bp_core_loaded action, but
  322. * that action isn't available when BP is in maintenance mode.
  323. */
  324. add_action( 'plugins_loaded', 'bp_core_load_buddypress_textdomain', 9 );
  325. // Load up BuddyPress's admin
  326. add_action( 'plugins_loaded', 'bp_admin' );
  327. }
  328. }
  329. // Not in maintenance mode
  330. if ( empty( $this->maintenance_mode ) ) {
  331. // Require all of the BuddyPress core libraries
  332. require( $this->plugin_dir . 'bp-core/bp-core-actions.php' );
  333. require( $this->plugin_dir . 'bp-core/bp-core-caps.php' );
  334. require( $this->plugin_dir . 'bp-core/bp-core-cache.php' );
  335. require( $this->plugin_dir . 'bp-core/bp-core-cssjs.php' );
  336. require( $this->plugin_dir . 'bp-core/bp-core-update.php' );
  337. require( $this->plugin_dir . 'bp-core/bp-core-options.php' );
  338. require( $this->plugin_dir . 'bp-core/bp-core-classes.php' );
  339. require( $this->plugin_dir . 'bp-core/bp-core-filters.php' );
  340. require( $this->plugin_dir . 'bp-core/bp-core-avatars.php' );
  341. require( $this->plugin_dir . 'bp-core/bp-core-widgets.php' );
  342. require( $this->plugin_dir . 'bp-core/bp-core-template.php' );
  343. require( $this->plugin_dir . 'bp-core/bp-core-adminbar.php' );
  344. require( $this->plugin_dir . 'bp-core/bp-core-buddybar.php' );
  345. require( $this->plugin_dir . 'bp-core/bp-core-catchuri.php' );
  346. require( $this->plugin_dir . 'bp-core/bp-core-component.php' );
  347. require( $this->plugin_dir . 'bp-core/bp-core-functions.php' );
  348. require( $this->plugin_dir . 'bp-core/bp-core-moderation.php' );
  349. require( $this->plugin_dir . 'bp-core/bp-core-loader.php' );
  350. // Skip or load deprecated content
  351. if ( false !== $this->load_deprecated ) {
  352. require( $this->plugin_dir . 'bp-core/deprecated/1.5.php' );
  353. require( $this->plugin_dir . 'bp-core/deprecated/1.6.php' );
  354. }
  355. }
  356. }
  357. /**
  358. * Setup the default hooks and actions
  359. *
  360. * @since BuddyPress (1.6)
  361. * @access private
  362. *
  363. * @uses register_activation_hook() To register the activation hook
  364. * @uses register_deactivation_hook() To register the deactivation hook
  365. * @uses add_action() To add various actions
  366. */
  367. private function setup_actions() {
  368. // Add actions to plugin activation and deactivation hooks
  369. add_action( 'activate_' . $this->basename, 'bp_activation' );
  370. add_action( 'deactivate_' . $this->basename, 'bp_deactivation' );
  371. // If BuddyPress is being deactivated, do not add any actions
  372. if ( bp_is_deactivation( $this->basename ) )
  373. return;
  374. // Array of BuddyPress core actions
  375. $actions = array(
  376. 'setup_current_user', // Setup currently logged in user
  377. 'register_post_types', // Register post types
  378. 'register_post_statuses', // Register post statuses
  379. 'register_taxonomies', // Register taxonomies
  380. 'register_views', // Register the views
  381. 'register_theme_directory', // Register the theme directory
  382. 'load_textdomain', // Load textdomain
  383. 'add_rewrite_tags', // Add rewrite tags
  384. 'generate_rewrite_rules' // Generate rewrite rules
  385. );
  386. // Add the actions
  387. foreach( $actions as $class_action )
  388. add_action( 'bp_' . $class_action, array( $this, $class_action ), 5 );
  389. // Setup the BuddyPress theme directory
  390. register_theme_directory( $this->themes_dir );
  391. }
  392. }
  393. // "And now for something completely different"
  394. $GLOBALS['bp'] = new BuddyPress;
  395. endif;