PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/buddypress/bp-core/bp-core-loader.php

https://bitbucket.org/codemen_iftekhar/codemen
PHP | 247 lines | 99 code | 52 blank | 96 comment | 12 complexity | 6e5341897823973e0f6ed90654a6504e MD5 | raw file
  1. <?php
  2. /**
  3. * BuddyPress Core Loader
  4. *
  5. * Core contains the commonly used functions, classes, and API's
  6. *
  7. * @package BuddyPress
  8. * @subpackage Core
  9. */
  10. // Exit if accessed directly
  11. if ( !defined( 'ABSPATH' ) ) exit;
  12. class BP_Core extends BP_Component {
  13. /**
  14. * Start the members component creation process
  15. *
  16. * @since BuddyPress (1.5)
  17. *
  18. * @uses BP_Core::bootstrap()
  19. */
  20. function __construct() {
  21. parent::start(
  22. 'core',
  23. __( 'BuddyPress Core', 'buddypress' )
  24. , BP_PLUGIN_DIR
  25. );
  26. $this->bootstrap();
  27. }
  28. /**
  29. * Populate the global data needed before BuddyPress can continue
  30. *
  31. * This involves figuring out the currently required, active, deactive,
  32. * and optional components.
  33. *
  34. * @since BuddyPress (1.5)
  35. *
  36. * @global BuddyPress $bp
  37. */
  38. private function bootstrap() {
  39. global $bp;
  40. /**
  41. * At this point in the stack, BuddyPress core has been loaded but
  42. * individual components (friends/activity/groups/etc...) have not.
  43. *
  44. * The 'bp_core_loaded' action lets you execute code ahead of the
  45. * other components.
  46. */
  47. do_action( 'bp_core_loaded' );
  48. /** Components ********************************************************/
  49. // Set the included and optional components.
  50. $bp->optional_components = apply_filters( 'bp_optional_components', array( 'activity', 'blogs', 'forums', 'friends', 'groups', 'messages', 'settings', 'xprofile' ) );
  51. // Set the required components
  52. $bp->required_components = apply_filters( 'bp_required_components', array( 'members' ) );
  53. // Get a list of activated components
  54. if ( $active_components = bp_get_option( 'bp-active-components' ) ) {
  55. $bp->active_components = apply_filters( 'bp_active_components', $active_components );
  56. $bp->deactivated_components = apply_filters( 'bp_deactivated_components', array_values( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_keys( $bp->active_components ) ) ) );
  57. // Pre 1.5 Backwards compatibility
  58. } elseif ( $deactivated_components = bp_get_option( 'bp-deactivated-components' ) ) {
  59. // Trim off namespace and filename
  60. foreach ( (array) $deactivated_components as $component => $value )
  61. $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) );
  62. // Set globals
  63. $bp->deactivated_components = apply_filters( 'bp_deactivated_components', $trimmed );
  64. // Setup the active components
  65. $active_components = array_fill_keys( array_diff( array_values( array_merge( $optional_components, $required_components ) ), array_values( $deactivated_components ) ), '1' );
  66. // Set the active component global
  67. $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components );
  68. // Default to all components active
  69. } else {
  70. // Set globals
  71. $bp->deactivated_components = array();
  72. // Setup the active components
  73. $active_components = array_fill_keys( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), '1' );
  74. // Set the active component global
  75. $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components );
  76. }
  77. // Loop through optional components
  78. foreach( $bp->optional_components as $component )
  79. if ( bp_is_active( $component ) && file_exists( BP_PLUGIN_DIR . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) )
  80. include( BP_PLUGIN_DIR . '/bp-' . $component . '/bp-' . $component . '-loader.php' );
  81. // Loop through required components
  82. foreach( $bp->required_components as $component )
  83. if ( file_exists( BP_PLUGIN_DIR . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) )
  84. include( BP_PLUGIN_DIR . '/bp-' . $component . '/bp-' . $component . '-loader.php' );
  85. // Add Core to required components
  86. $bp->required_components[] = 'core';
  87. }
  88. function includes() {
  89. if ( !is_admin() )
  90. return;
  91. $includes = array(
  92. 'admin'
  93. );
  94. parent::includes( $includes );
  95. }
  96. /**
  97. * Sets up a majority of the BuddyPress globals that require a minimal
  98. * amount of processing, meaning they cannot be set in the BuddyPress class.
  99. *
  100. * @since BuddyPress (1.5)
  101. *
  102. * @global BuddyPress $bp
  103. */
  104. function setup_globals() {
  105. global $bp;
  106. /** Database **********************************************************/
  107. // Get the base database prefix
  108. if ( empty( $bp->table_prefix ) )
  109. $bp->table_prefix = bp_core_get_table_prefix();
  110. // The domain for the root of the site where the main blog resides
  111. if ( empty( $bp->root_domain ) )
  112. $bp->root_domain = bp_core_get_root_domain();
  113. // Fetches all of the core BuddyPress settings in one fell swoop
  114. if ( empty( $bp->site_options ) )
  115. $bp->site_options = bp_core_get_root_options();
  116. // The names of the core WordPress pages used to display BuddyPress content
  117. if ( empty( $bp->pages ) )
  118. $bp->pages = bp_core_get_directory_pages();
  119. /** Basic current user data *******************************************/
  120. // Logged in user is the 'current_user'
  121. $current_user = wp_get_current_user();
  122. // The user ID of the user who is currently logged in.
  123. $bp->loggedin_user = new stdClass;
  124. $bp->loggedin_user->id = isset( $current_user->ID ) ? $current_user->ID : 0;
  125. /** Avatars ***********************************************************/
  126. // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar
  127. $bp->grav_default = new stdClass;
  128. $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['avatar_default'] );
  129. $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', $bp->grav_default->user );
  130. $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', $bp->grav_default->user );
  131. // Notifications Table
  132. $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
  133. /**
  134. * Used to determine if user has admin rights on current content. If the
  135. * logged in user is viewing their own profile and wants to delete
  136. * something, is_item_admin is used. This is a generic variable so it
  137. * can be used by other components. It can also be modified, so when
  138. * viewing a group 'is_item_admin' would be 'true' if they are a group
  139. * admin, and 'false' if they are not.
  140. */
  141. bp_update_is_item_admin( bp_user_has_access(), 'core' );
  142. // Is the logged in user is a mod for the current item?
  143. bp_update_is_item_mod( false, 'core' );
  144. do_action( 'bp_core_setup_globals' );
  145. }
  146. /**
  147. * Setup BuddyBar navigation
  148. *
  149. * @since BuddyPress (1.5)
  150. *
  151. * @global BuddyPress $bp
  152. */
  153. function setup_nav() {
  154. global $bp;
  155. // If xprofile component is disabled, revert to WordPress profile
  156. if ( !bp_is_active( 'xprofile' ) ) {
  157. // Define local variable
  158. $sub_nav = array();
  159. // Fallback values if xprofile is disabled
  160. $bp->core->profile->slug = 'profile';
  161. $bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
  162. // Add 'Profile' to the main navigation
  163. $main_nav = array(
  164. 'name' => __( 'Profile', 'buddypress' ),
  165. 'slug' => $bp->core->profile->slug,
  166. 'position' => 20,
  167. 'screen_function' => 'bp_core_catch_profile_uri',
  168. 'default_subnav_slug' => 'public'
  169. );
  170. $profile_link = trailingslashit( bp_loggedin_user_domain() . '/' . $bp->core->profile->slug );
  171. // Add the subnav items to the profile
  172. $sub_nav[] = array(
  173. 'name' => __( 'Public', 'buddypress' ),
  174. 'slug' => 'public',
  175. 'parent_url' => $profile_link,
  176. 'parent_slug' => $bp->core->profile->slug,
  177. 'screen_function' => 'bp_core_catch_profile_uri'
  178. );
  179. parent::setup_nav( $main_nav, $sub_nav );
  180. }
  181. }
  182. }
  183. /**
  184. * Setup the BuddyPress Core component
  185. *
  186. * @since BuddyPress (1.6)
  187. *
  188. * @global BuddyPress $bp
  189. */
  190. function bp_setup_core() {
  191. global $bp;
  192. $bp->core = new BP_Core();
  193. }
  194. add_action( 'bp_setup_components', 'bp_setup_core', 2 );
  195. ?>