Skip to:
Content

BuddyPress.org

Changeset 5316


Ignore:
Timestamp:
11/09/2011 05:43:09 AM (15 years ago)
Author:
johnjamesjacoby
Message:

Move simple global variable assignments from BP_Core into BuddyPress class as default assignments. Move core component includes into BuddyPress::includes().

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-catchuri.php

    r5314 r5316  
    3030 */
    3131function bp_core_set_uri_globals() {
    32         global $bp, $bp_unfiltered_uri, $bp_unfiltered_uri_offset;
    33         global $current_blog, $wpdb;
    34 
    35         // Create global component, action, and item variables
    36         $bp->current_component = $bp->current_item     = '';
    37         $bp->current_action    = $bp->action_variables = '';
     32        global $bp, $current_blog, $wpdb;
    3833
    3934        // Don't catch URIs on non-root blogs unless multiblog mode is on
     
    121116
    122117        // Keep the unfiltered URI safe
    123         $bp_unfiltered_uri = $bp_uri;
     118        $bp->unfiltered_uri = $bp_uri;
    124119
    125120        // Get slugs of pages into array
     
    223218        // Global the unfiltered offset to use in bp_core_load_template().
    224219        // To avoid PHP warnings in bp_core_load_template(), it must always be >= 0
    225         $bp_unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0;
     220        $bp->unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0;
    226221
    227222        // We have an exact match
     
    315310 */
    316311function bp_core_load_template( $templates ) {
    317         global $post, $bp, $wpdb, $wp_query, $bp_unfiltered_uri, $bp_unfiltered_uri_offset;
     312        global $post, $bp, $wpdb, $wp_query;
    318313
    319314        // Determine if the root object WP page exists for this request (TODO: is there an API function for this?
    320         if ( !empty( $bp_unfiltered_uri_offset ) && !$page_exists = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s", $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) ) )
     315        if ( !empty( $bp->unfiltered_uri_offset ) && !$page_exists = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s", $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) ) )
    321316                return false;
    322317
     
    324319        $object_id = 0;
    325320        foreach ( (array)$bp->pages as $page ) {
    326                 if ( isset( $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) && $page->name == $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) {
     321                if ( isset( $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) && ( $page->name == $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) ) {
    327322                        $object_id = $page->id;
    328323                }
  • trunk/bp-core/bp-core-loader.php

    r5311 r5316  
    11<?php
     2
     3/**
     4 * BuddyPress Core Loader
     5 *
     6 * Core contains the commonly used functions, classes, and API's
     7 *
     8 * @package BuddyPress
     9 * @subpackage Core
     10 */
     11
    212// Exit if accessed directly
    313if ( !defined( 'ABSPATH' ) ) exit;
    414
    5 // Require all of the BuddyPress core libraries
    6 require( BP_PLUGIN_DIR . '/bp-core/bp-core-cache.php'      );
    7 require( BP_PLUGIN_DIR . '/bp-core/bp-core-hooks.php'      );
    8 require( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php'      );
    9 require( BP_PLUGIN_DIR . '/bp-core/bp-core-update.php'     );
    10 require( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php'    );
    11 require( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php'    );
    12 require( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php'    );
    13 require( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php'    );
    14 require( BP_PLUGIN_DIR . '/bp-core/bp-core-template.php'   );
    15 require( BP_PLUGIN_DIR . '/bp-core/bp-core-buddybar.php'   );
    16 require( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php'   );
    17 require( BP_PLUGIN_DIR . '/bp-core/bp-core-component.php'  );
    18 require( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php'  );
    19 require( BP_PLUGIN_DIR . '/bp-core/bp-core-moderation.php' );
    20 
    21 // Load deprecated functions
    22 require( BP_PLUGIN_DIR . '/bp-core/deprecated/1.5.php' );
    23 //require( BP_PLUGIN_DIR . '/bp-core/deprecated/1.6.php' );
    24 
    25 // Load the WP admin bar.
    26 if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
    27         require( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php'  );
    28 
    29 // Move active components from sitemeta, if necessary
    30 // Provides backpat with earlier versions of BP
    31 if ( is_multisite() && $active_components = get_site_option( 'bp-active-components' ) )
    32         bp_update_option( 'bp-active-components', $active_components );
    33 
    3415class BP_Core extends BP_Component {
    3516
     17        /**
     18         * Start the members component creation process
     19         *
     20         * @since BuddyPress (1.5)
     21         *
     22         * @uses BP_Core::bootstrap()
     23         */
    3624        function __construct() {
    3725                parent::start(
     
    4432        }
    4533
     34        /**
     35         * Populate the global data needed before BuddyPress can continue
     36         *
     37         * This involves figuring out the currently required, active, deactive,
     38         * and optional components.
     39         *
     40         * @since BuddyPress (1.5)
     41         *
     42         * @global BuddyPress $bp
     43         */
    4644        private function bootstrap() {
    4745                global $bp;
     
    5856                /** Components ********************************************************/
    5957
     58                // Move active components from sitemeta, if necessary
     59                // Provides backpat with earlier versions of BP
     60                if ( is_multisite() && $active_components = get_site_option( 'bp-active-components' ) )
     61                        bp_update_option( 'bp-active-components', $active_components );
     62
    6063                // Set the included and optional components.
    6164                $bp->optional_components = apply_filters( 'bp_optional_components', array( 'activity', 'blogs', 'forums', 'friends', 'groups', 'messages', 'settings', 'xprofile' ) );
     
    7174                // Pre 1.5 Backwards compatibility
    7275                } elseif ( $deactivated_components = bp_get_option( 'bp-deactivated-components' ) ) {
     76
    7377                        // Trim off namespace and filename
    7478                        foreach ( (array) $deactivated_components as $component => $value )
     
    8993                // Default to all components active
    9094                } else {
     95
    9196                        // Set globals
    9297                        $bp->deactivated_components = array();
     
    116121        }
    117122
     123        /**
     124         * Sets up a majority of the BuddyPress globals that require a minimal
     125         * amount of processing, meaning they cannot be set in the BuddyPress class.
     126         *
     127         * @since BuddyPress (1.5)
     128         *
     129         * @global BuddyPress $bp
     130         */
    118131        function setup_globals() {
    119132                global $bp;
     
    136149                if ( empty( $bp->pages ) )
    137150                        $bp->pages = bp_core_get_directory_pages();
    138 
    139                 /** Admin Bar *********************************************************/
    140 
    141                 // Set the 'My Account' global to prevent debug notices
    142                 $bp->my_account_menu_id = false;
    143 
    144                 /** Component and Action **********************************************/
    145 
    146                 // Used for overriding the 2nd level navigation menu so it can be used to
    147                 // display custom navigation for an item (for example a group)
    148                 $bp->is_single_item = false;
    149 
    150                 // Sets up the array container for the component navigation rendered
    151                 // by bp_get_nav()
    152                 $bp->bp_nav            = array();
    153 
    154                 // Sets up the array container for the component options navigation
    155                 // rendered by bp_get_options_nav()
    156                 $bp->bp_options_nav    = array();
    157 
    158                 // Contains an array of all the active components. The key is the slug,
    159                 // value the internal ID of the component.
    160                 //$bp->active_components = array();
    161151
    162152                /** Basic current user data *******************************************/
     
    194184        }
    195185
     186        /**
     187         * Setup BuddyBar navigation
     188         *
     189         * @since BuddyPress (1.5)
     190         *
     191         * @global BuddyPress $bp
     192         */
    196193        function setup_nav() {
    197194                global $bp;
    198195
    199                 /***
    200                  * If the extended profiles component is disabled, we need to revert to using the
    201                  * built in WordPress profile information
    202                  */
     196                 // If xprofile component is disabled, revert to WordPress profile
    203197                if ( !bp_is_active( 'xprofile' ) ) {
     198
     199                        // Define local variable
     200                        $sub_nav = array();
    204201
    205202                        // Fallback values if xprofile is disabled
     
    226223                                'screen_function' => 'bp_core_catch_profile_uri'
    227224                        );
     225
     226                        parent::setup_nav( $main_nav, $sub_nav );
    228227                }
    229228        }
    230229}
    231230
     231/**
     232 * Setup the BuddyPress Core component
     233 *
     234 * @since BuddyPress (1.6)
     235 *
     236 * @global BuddyPress $bp
     237 */
    232238function bp_setup_core() {
    233239        global $bp;
  • trunk/bp-loader.php

    r5314 r5316  
    7272        public $maintenance_mode = '';
    7373
     74        /**
     75         * @var bool Include deprecated BuddyPress files or not
     76         */
     77        public $load_deprecated = true;
     78
    7479        /** Paths *****************************************************************/
    7580
     
    117122         */
    118123        public $displayed_user = false;
     124
     125        /** Navigation ************************************************************/
     126       
     127        /**
     128         * @var array Primary BuddyPress navigation
     129         */
     130        public $bp_nav = array();
     131
     132        /**
     133         * @var array Secondary BuddyPress navigation to $bp_nav
     134         */
     135        public $bp_options_nav = array();
     136
     137        /** Toolbar ***************************************************************/
     138
     139        /**
     140         * @var string The primary toolbar ID
     141         */
     142        public $my_account_menu_id = '';
     143
     144        /** URI's *****************************************************************/
     145
     146        /**
     147         * @var array The unfiltered URI broken down into chunks
     148         * @see bp_core_set_uri_globals()
     149         */
     150        public $unfiltered_uri = array();
     151
     152        /**
     153         * @var int The current offset of the URI
     154         * @see bp_core_set_uri_globals()
     155         */
     156        public $unfiltered_uri_offset = 0;
     157       
     158        /** Components ************************************************************/
     159
     160        /**
     161         * @var string Name of the current BuddyPress component (primary)
     162         */
     163        public $current_component = '';
     164
     165        /**
     166         * @var string Name of the current BuddyPress item (secondary)
     167         */
     168        public $current_item = '';
     169
     170        /**
     171         * @var string Name of the current BuddyPress action (tertiary)
     172         */
     173        public $current_action = '';
     174
     175        /**
     176         * @var array() Additional navigation elements (supplemental)
     177         */
     178        public $action_variables = array();
     179
     180        /**
     181         * @var bool Displaying custom 2nd level navigation menu (I.E a group)
     182         */
     183        public $is_single_item = false;
    119184
    120185        /** Errors ****************************************************************/
     
    330395                // Other identifiers
    331396                $this->user_id            = apply_filters( 'bp_user_id', 'bp_user' );
    332                 $this->edit_id            = apply_filters( 'bp_edit_id', 'edit'     );
     397                $this->edit_id            = apply_filters( 'bp_edit_id', 'edit'    );
    333398
    334399                /** Users *************************************************************/
     
    386451                        register_theme_directory( $this->themes_dir );
    387452
    388                         // Load core
    389                         require( $this->plugin_dir . '/bp-core/bp-core-loader.php' );
     453                        // Require all of the BuddyPress core libraries
     454                        require( $this->plugin_dir . '/bp-core/bp-core-caps.php'       );
     455                        require( $this->plugin_dir . '/bp-core/bp-core-cache.php'      );
     456                        require( $this->plugin_dir . '/bp-core/bp-core-hooks.php'      );
     457                        require( $this->plugin_dir . '/bp-core/bp-core-cssjs.php'      );
     458                        require( $this->plugin_dir . '/bp-core/bp-core-update.php'     );
     459                        require( $this->plugin_dir . '/bp-core/bp-core-classes.php'    );
     460                        require( $this->plugin_dir . '/bp-core/bp-core-filters.php'    );
     461                        require( $this->plugin_dir . '/bp-core/bp-core-avatars.php'    );
     462                        require( $this->plugin_dir . '/bp-core/bp-core-widgets.php'    );
     463                        require( $this->plugin_dir . '/bp-core/bp-core-template.php'   );
     464                        require( $this->plugin_dir . '/bp-core/bp-core-buddybar.php'   );
     465                        require( $this->plugin_dir . '/bp-core/bp-core-catchuri.php'   );
     466                        require( $this->plugin_dir . '/bp-core/bp-core-component.php'  );
     467                        require( $this->plugin_dir . '/bp-core/bp-core-functions.php'  );
     468                        require( $this->plugin_dir . '/bp-core/bp-core-moderation.php' );
     469                        require( $this->plugin_dir . '/bp-core/bp-core-adminbar.php'   );
     470                        require( $this->plugin_dir . '/bp-core/bp-core-loader.php'     );
     471
     472                        // Skip or load deprecated content
     473                        if ( false === $this->load_deprecated ) {
     474                                require( $this->plugin_dir . '/bp-core/deprecated/1.5.php' );
     475                                require( $this->plugin_dir . '/bp-core/deprecated/1.6.php' );
     476                        }
    390477
    391478                        // Check if an update is required
    392                         if ( (int) $this->db_version_raw < (int) $this->db_version || ( !empty( $this->is_network_activate ) ) ) {
     479                        if ( ( (int) $this->db_version_raw < (int) $this->db_version ) || ( !empty( $this->is_network_activate ) ) ) {
     480
     481                                // BuddyPress needs an update
    393482                                $this->maintenance_mode = 'update';
    394                                 require( $this->plugin_dir . '/bp-core/admin/bp-core-update.php' );
     483
     484                                // Only include core updater if in the admin area
     485                                if ( is_admin() ) {
     486                                        require( $this->plugin_dir . '/bp-core/admin/bp-core-update.php' );
     487                                }
    395488                        }
    396489                }               
Note: See TracChangeset for help on using the changeset viewer.