Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/25/2011 08:58:56 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Rename new 'bp-users' component to 'bp-members' for consistency through-out project.
Core, Messages, and Friends Components now use the BP_Component class.
Split Friends and Messages components into smaller files.
Change references to 'profile' to 'xprofile' through-out project for consistency.
Introduce 'bp_actions' and 'bp_screens' standard hooks to replace the usage of 'wp' through-out project.
Move component loader sequence into bp-core-bootstrap.php,
Move old root_component action into 1.3 deprecated file.

File:
1 edited

Legend:

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

    r3829 r3917  
    11<?php
    22
    3 // Load the files containing functions that we globally will need.
    4 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-hooks.php'      );
    5 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php'      );
    6 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php'    );
    7 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php'    );
    8 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php'    );
    9 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php'    );
    10 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-template.php'   );
    11 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-buddybar.php'   );
    12 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php'   );
    13 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-component.php'  );
    14 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php'  );
     3// Require all of the BuddyPress core libraries
     4require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-component.php'  );
     5require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php'  );
     6require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-hooks.php'  );
     7require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php'  );
     8require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php'  );
     9require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php'  );
     10require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php'  );
     11require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php'  );
     12require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-template.php'  );
     13require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-buddybar.php'  );
     14require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php'  );
    1515
    16 // Do we load deprecated functions?
     16// Load deprecated functions
    1717if ( !defined( 'BP_SKIP_DEPRECATED' ) )
    18     require ( BP_PLUGIN_DIR . '/bp-core/deprecated/1.3.php' );
     18    require_once( BP_PLUGIN_DIR . '/bp-core/deprecated/1.3.php' );
    1919
    20 // If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar.
     20// Load the WP admin bar.
    2121if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
    22     require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
     22    require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
    2323
    2424/** "And now for something completely different" ******************************/
    2525
    26 /**
    27  * Sets up default global BuddyPress configuration settings and stores
    28  * them in a $bp variable.
    29  *
    30  * @package BuddyPress Core Core
    31  * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    32  * @uses bp_core_get_user_domain() Returns the domain for a user
    33  */
    34 function bp_core_setup_globals() {
    35     global $bp;
    36     //global $current_action, $current_blog;
    37     global $bp_pages;
    38     //global $action_variables;
     26class BP_Core extends BP_Component {
    3927
    40     // Get the base database prefix
    41     $bp->table_prefix = bp_core_get_table_prefix();
    42 
    43     // The domain for the root of the site where the main blog resides
    44     $bp->root_domain  = bp_core_get_root_domain();
    45 
    46     // The names of the core WordPress pages used to display BuddyPress content
    47     $bp->pages        = $bp_pages;
    48 
    49     /** Component and Action **************************************************/
    50 
    51     // Used for overriding the 2nd level navigation menu so it can be used to
    52     // display custom navigation for an item (for example a group)
    53     $bp->is_single_item = false;
    54 
    55     // The default component to use if none are set and someone
    56     // visits: http://domain.com/members/andy
    57     if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) {
    58         if ( isset( $bp->pages->activity ) )
    59             $bp->default_component = $bp->activity->id;
    60         else
    61             $bp->default_component = $bp->profile->id;
    62     } else {
    63         $bp->default_component     = BP_DEFAULT_COMPONENT;
     28    function BP_Core() {
     29        parent::start(
     30            '_core',
     31            __( 'BuddyPress Core', 'buddypress' )
     32            , BP_PLUGIN_DIR
     33        );
    6434    }
    6535
    66     // Fetches all of the core BuddyPress settings in one fell swoop
    67     $bp->site_options = bp_core_get_site_options();
     36    function _setup_globals() {
     37        global $bp, $bp_pages;
    6838
    69     // Sets up the array container for the component navigation rendered
    70     // by bp_get_nav()
    71     $bp->bp_nav            = array();
     39        // Setup the BuddyPress theme directory
     40        register_theme_directory( WP_PLUGIN_DIR . '/buddypress/bp-themes' );
    7241
    73     // Sets up the array container for the component options navigation
    74     // rendered by bp_get_options_nav()
    75     $bp->bp_options_nav    = array();
     42        // Get the base database prefix
     43        $bp->table_prefix = bp_core_get_table_prefix();
    7644
    77     // Contains an array of all the active components. The key is the slug,
    78     // value the internal ID of the component.
    79     $bp->active_components = array();
     45        // The domain for the root of the site where the main blog resides
     46        $bp->root_domain  = bp_core_get_root_domain();
    8047
    81     /** Avatars ***************************************************************/
     48        // The names of the core WordPress pages used to display BuddyPress content
     49        $bp->pages        = $bp_pages;
    8250
    83     // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar
    84     $bp->grav_default->user  = apply_filters( 'bp_user_gravatar_default',  $bp->site_options['avatar_default'] );
    85     $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', $bp->grav_default->user );
    86     $bp->grav_default->blog  = apply_filters( 'bp_blog_gravatar_default',  $bp->grav_default->user );
     51        /** Component and Action **************************************************/
    8752
    88     // Notifications Table
    89     $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
     53        // Used for overriding the 2nd level navigation menu so it can be used to
     54        // display custom navigation for an item (for example a group)
     55        $bp->is_single_item = false;
    9056
    91     do_action( 'bp_core_setup_globals' );
    92 }
    93 add_action( 'bp_setup_globals', 'bp_core_setup_globals', 1 );
     57        // The default component to use if none are set and someone
     58        // visits: http://domain.com/members/andy
     59        if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) {
     60            if ( isset( $bp->pages->activity ) )
     61                $bp->default_component = $bp->activity->id;
     62            else
     63                $bp->default_component = $bp->profile->id;
     64        } else {
     65            $bp->default_component     = BP_DEFAULT_COMPONENT;
     66        }
    9467
    95 /**
    96  * Sets up the profile navigation item if the Xprofile component is not installed.
    97  *
    98  * @package BuddyPress Core
    99  * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
    100  * @uses bp_core_new_nav_item() Adds a navigation item to the top level buddypress navigation
    101  * @uses bp_core_new_subnav_item() Adds a sub navigation item to a nav item
    102  * @uses bp_is_my_profile() Returns true if the current user being viewed is equal the logged in user
    103  * @uses bp_core_fetch_avatar() Returns the either the thumb or full avatar URL for the user_id passed
    104  */
    105 function bp_core_setup_nav() {
    106     global $bp;
     68        // Fetches all of the core BuddyPress settings in one fell swoop
     69        $bp->site_options = bp_core_get_site_options();
    10770
    108     /***
    109      * If the extended profiles component is disabled, we need to revert to using the
    110      * built in WordPress profile information
    111      */
    112     if ( !bp_is_active( 'profile' ) ) {
     71        // Sets up the array container for the component navigation rendered
     72        // by bp_get_nav()
     73        $bp->bp_nav            = array();
    11374
    114         // Fallback values if xprofile is disabled
    115         $bp->core->profile->slug = 'profile';
    116         $bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
     75        // Sets up the array container for the component options navigation
     76        // rendered by bp_get_options_nav()
     77        $bp->bp_options_nav    = array();
    11778
    118         // Add 'Profile' to the main navigation
    119         bp_core_new_nav_item( array(
    120             'name'                => __( 'Profile', 'buddypress' ),
    121             'slug'                => $bp->core->profile->slug,
    122             'position'            => 20,
    123             'screen_function'     => 'bp_core_catch_profile_uri',
    124             'default_subnav_slug' => 'public'
    125         ) );
     79        // Contains an array of all the active components. The key is the slug,
     80        // value the internal ID of the component.
     81        $bp->active_components = array();
    12682
    127         $profile_link = trailingslashit( $bp->loggedin_user->domain . '/' . $bp->core->profile->slug );
     83        /** Basic current user data ***********************************************/
    12884
    129         // Add the subnav items to the profile
    130         bp_core_new_subnav_item( array(
    131             'name'            => __( 'Public', 'buddypress' ),
    132             'slug'            => 'public',
    133             'parent_url'      => $profile_link,
    134             'parent_slug'     => $bp->core->profile->slug,
    135             'screen_function' => 'bp_core_catch_profile_uri'
    136         ) );
     85        // Logged in user is the 'current_user'
     86        $current_user            = wp_get_current_user();
    13787
    138         // Looking at a profile
    139         if ( 'profile' == $bp->current_component ) {
    140             if ( bp_is_my_profile() ) {
    141                 $bp->bp_options_title = __( 'My Profile', 'buddypress' );
    142             } else {
    143                 $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    144                     'item_id' => $bp->displayed_user->id,
    145                     'type'    => 'thumb'
    146                 ) );
    147                 $bp->bp_options_title  = $bp->displayed_user->fullname;
    148             }
     88        // The user ID of the user who is currently logged in.
     89        $bp->loggedin_user->id   = $current_user->ID;
     90
     91        /** Avatars ***************************************************************/
     92
     93        // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar
     94        $bp->grav_default->user  = apply_filters( 'bp_user_gravatar_default',  $bp->site_options['avatar_default'] );
     95        $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', $bp->grav_default->user );
     96        $bp->grav_default->blog  = apply_filters( 'bp_blog_gravatar_default',  $bp->grav_default->user );
     97
     98        // Notifications Table
     99        $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
     100
     101        do_action( 'bp_core_setup_globals' );
     102    }
     103
     104    function _setup_nav() {
     105        global $bp;
     106
     107        /***
     108         * If the extended profiles component is disabled, we need to revert to using the
     109         * built in WordPress profile information
     110         */
     111        if ( !bp_is_active( 'xprofile' ) ) {
     112
     113            // Fallback values if xprofile is disabled
     114            $bp->core->profile->slug = 'profile';
     115            $bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
     116
     117            // Add 'Profile' to the main navigation
     118            $main_nav = array(
     119                'name'                => __( 'Profile', 'buddypress' ),
     120                'slug'                => $bp->core->profile->slug,
     121                'position'            => 20,
     122                'screen_function'     => 'bp_core_catch_profile_uri',
     123                'default_subnav_slug' => 'public'
     124            );
     125
     126            $profile_link = trailingslashit( $bp->loggedin_user->domain . '/' . $bp->core->profile->slug );
     127
     128            // Add the subnav items to the profile
     129            $sub_nav[] = array(
     130                'name'            => __( 'Public', 'buddypress' ),
     131                'slug'            => 'public',
     132                'parent_url'      => $profile_link,
     133                'parent_slug'     => $bp->core->profile->slug,
     134                'screen_function' => 'bp_core_catch_profile_uri'
     135            );
    149136        }
    150137    }
    151138}
    152 add_action( 'bp_setup_nav', 'bp_core_setup_nav' );
    153 
     139$bp->core = new BP_Core();
    154140
    155141?>
Note: See TracChangeset for help on using the changeset viewer.