Skip to:
Content

Changeset 1021 for trunk/bp-core.php


Ignore:
Timestamp:
02/06/09 03:07:48 (5 years ago)
Author:
apeatling
Message:

Converted $bp as an array to $bp as an object. See this post for more info: http://buddypress.org/forums/topic.php?id=1125

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core.php

    r1017 r1021  
    5555require_once( 'bp-core/bp-core-activation.php' ); 
    5656 
    57 /* Define the slug for member pages and the members directory (e.g. example.com/[members] ) */ 
     57/* Define the slug for member pages and the members directory (e.g. domain.com/[members] ) */ 
    5858define( 'MEMBERS_SLUG', apply_filters( 'bp_members_slug', 'members' ) ); 
    5959 
     
    9191    global $bp, $wpdb; 
    9292    global $current_user, $current_component, $current_action, $current_blog; 
    93     global $current_userid; 
     93    global $displayed_user_id; 
    9494    global $action_variables; 
    9595 
    9696    /* The domain for the root of the site where the main blog resides */    
    97     $bp['root_domain'] = bp_core_get_root_domain(); 
     97    $bp->root_domain = bp_core_get_root_domain(); 
    9898     
    9999    /* The user ID of the user who is currently logged in. */ 
    100     $bp['loggedin_userid'] = $current_user->ID; 
     100    $bp->loggedin_user->id = $current_user->ID; 
     101 
     102    /* The domain for the user currently logged in. eg: http://domain.com/members/andy */ 
     103    $bp->loggedin_user->domain = bp_core_get_user_domain($current_user->ID); 
    101104     
    102105    /* The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php */ 
    103     $bp['current_userid'] = $current_userid; 
    104      
    105     /* The domain for the user currently logged in. eg: http://example.com/members/andy */ 
    106     $bp['loggedin_domain'] = bp_core_get_user_domain($current_user->ID); 
    107      
    108     /* The domain for the user currently being viewed */ 
    109     $bp['current_domain'] = bp_core_get_user_domain($current_userid); 
    110      
    111     /* The component being used eg: http://andy.example.com/ [profile] */ 
    112     $bp['current_component'] = $current_component; // type: string 
    113      
    114     /* The current action for the component eg: http://andy.example.com/profile/ [edit] */ 
    115     $bp['current_action'] = $current_action; // type: string 
    116      
    117     /* The action variables for the current action eg: http://andy.example.com/profile/edit/ [group] / [6] */ 
    118     $bp['action_variables'] = $action_variables; // type: array 
    119      
    120     /* Only used where a component has a sub item, e.g. groups: http://andy.example.com/groups/ [my-group] / home - manipulated in the actual component not in catch uri code.*/ 
    121     $bp['current_item'] = ''; // type: string 
    122  
    123     /* The default component to use if none are set and someone visits: http://andy.example.com/ */ 
    124     $bp['default_component'] = 'profile'; 
     106    $bp->displayed_user->id = $displayed_user_id; 
     107     
     108    /* The domain for the user currently being displayed */ 
     109    $bp->displayed_user->domain = bp_core_get_user_domain($displayed_user_id); 
     110     
     111    /* The component being used eg: http://andy.domain.com/ [profile] */ 
     112    $bp->current_component = $current_component; // type: string 
     113     
     114    /* The current action for the component eg: http://andy.domain.com/profile/ [edit] */ 
     115    $bp->current_action = $current_action; // type: string 
     116     
     117    /* The action variables for the current action eg: http://andy.domain.com/profile/edit/ [group] / [6] */ 
     118    $bp->action_variables = $action_variables; // type: array 
     119     
     120    /* Only used where a component has a sub item, e.g. groups: http://andy.domain.com/groups/ [my-group] / home - manipulated in the actual component not in catch uri code.*/ 
     121    $bp->current_item = ''; // type: string 
     122 
     123    /* The default component to use if none are set and someone visits: http://andy.domain.com/ */ 
     124    $bp->default_component = 'profile'; 
    125125     
    126126    /* Sets up the array container for the component navigation rendered by bp_get_nav() */ 
    127     $bp['bp_nav'] = array(); 
     127    $bp->bp_nav = array(); 
    128128 
    129129    /* Sets up the array container for the user navigation rendered by bp_get_user_nav() */ 
    130     $bp['bp_users_nav'] = array(); 
     130    $bp->bp_users_nav = array(); 
    131131     
    132132    /* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */ 
    133     $bp['bp_options_nav'] = array(); 
     133    $bp->bp_options_nav = array(); 
    134134     
    135135    /* Sets up container used for the title of the current component option and rendered by bp_get_options_title() */ 
    136     $bp['bp_options_title'] = ''; 
     136    $bp->bp_options_title = ''; 
    137137     
    138138    /* Sets up container used for the avatar of the current component being viewed. Rendered by bp_get_options_avatar() */ 
    139     $bp['bp_options_avatar'] = ''; 
     139    $bp->bp_options_avatar = ''; 
    140140 
    141141    /* Fetch the full name for the logged in and current user */ 
    142     $bp['loggedin_fullname'] = bp_core_global_user_fullname( $bp['loggedin_userid'] ); 
    143     $bp['current_fullname'] = bp_core_global_user_fullname( $bp['current_userid'] ); 
     142    $bp->loggedin_user->fullname = bp_core_global_user_fullname( $bp->loggedin_user->id ); 
     143    $bp->displayed_user->fullname = bp_core_global_user_fullname( $bp->displayed_user->id ); 
    144144 
    145145    /* Used to determine if user has admin rights on current content. If the logged in user is viewing 
     
    147147       generic variable so it can be used in other components. It can also be modified, so when viewing a group 
    148148       'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */ 
    149     $bp['is_item_admin'] = bp_is_home(); 
     149    $bp->is_item_admin = bp_is_home(); 
    150150     
    151151    /* Used to determine if the logged in user is a moderator for the current content. */ 
    152     $bp['is_item_mod'] = false; 
    153      
    154     $bp['core'] = array( 
    155         'image_base' => site_url( MUPLUGINDIR . '/bp-core/images' ), 
    156         'table_name_notifications' => $wpdb->base_prefix . 'bp_notifications' 
    157     ); 
     152    $bp->is_item_mod = false; 
     153     
     154    $bp->core->image_base = site_url( MUPLUGINDIR . '/bp-core/images' ); 
     155    $bp->core->table_name_notifications = $wpdb->base_prefix . 'bp_notifications'; 
    158156     
    159157    /* Used to print version numbers in the footer for reference */ 
    160     $bp['version_numbers']['core'] = BP_CORE_VERSION; 
    161      
    162     if ( !$bp['current_component'] ) 
    163         $bp['current_component'] = $bp['default_component']; 
     158    $bp->version_numbers = new stdClass; 
     159    $bp->version_numbers->core = BP_CORE_VERSION; 
     160     
     161    if ( !$bp->current_component ) 
     162        $bp->current_component = $bp->default_component; 
    164163} 
    165164add_action( 'wp', 'bp_core_setup_globals', 1 ); 
     
    193192        $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 
    194193     
    195     $sql[] = "CREATE TABLE ". $bp['core']['table_name_notifications'] ." ( 
     194    $sql[] = "CREATE TABLE $bp->core->table_name_notifications ( 
    196195                id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, 
    197196                user_id int(11) NOT NULL, 
    198197                item_id int(11) NOT NULL, 
    199                 secondary_item_id int(11) NOT NULL, 
     198                secondary_item_id int(11), 
    200199                component_name varchar(75) NOT NULL, 
    201200                component_action varchar(75) NOT NULL, 
     
    218217    // dbDelta won't change character sets, so we need to do this seperately. 
    219218    // This will only be in here pre v1.0 
    220     $wpdb->query( $wpdb->prepare( "ALTER TABLE " . $bp['core']['table_name_notifications'] . " DEFAULT CHARACTER SET %s", $wpdb->charset ) ); 
     219    $wpdb->query( $wpdb->prepare( "ALTER TABLE $bp->core->table_name_notifications DEFAULT CHARACTER SET %s", $wpdb->charset ) ); 
    221220     
    222221    update_site_option( 'bp-core-db-version', BP_CORE_DB_VERSION ); 
     
    241240    if ( is_site_admin() ) { 
    242241        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */ 
    243         if ( ( $wpdb->get_var("SHOW TABLES LIKE '%" . $bp['core']['table_name_notifications'] . "%'") == false ) || ( get_site_option('bp-core-db-version') < BP_CORE_DB_VERSION )  ) 
     242        if ( ( $wpdb->get_var("show tables like '%{$bp->core->table_name_notifications}%'") == false ) || ( get_site_option('bp-core-db-version') < BP_CORE_DB_VERSION )  ) 
    244243            bp_core_install(); 
    245244    } 
     
    263262    if ( is_site_admin() ) { 
    264263        /* Add the administration tab under the "Site Admin" tab for site administrators */ 
    265         add_submenu_page( 'wpmu-admin.php', __('BuddyPress', 'buddypress'), __('BuddyPress', 'buddypress'), 1, 'bp_core_admin_settings', 'bp_core_admin_settings' ); 
     264        add_submenu_page( 'wpmu-admin.php', __("BuddyPress", 'buddypress'), __("BuddyPress", 'buddypress'), 1, "bp_core_admin_settings", "bp_core_admin_settings" ); 
    266265    } 
    267266} 
     
    272271 * 
    273272 * Checks to see if a component's URL should be in the root, not under a member page: 
    274  * eg: http://example.com/groups/the-group NOT http://example.com/members/andy/groups/the-group 
     273 * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group 
    275274 *  
    276275 * @package BuddyPress Core 
     
    280279    global $bp; 
    281280 
    282     return in_array( $component_name, $bp['root_components'] ); 
     281    return in_array( $component_name, $bp->root_components ); 
    283282} 
    284283 
     
    304303        bp_core_add_nav_default( 'profile', 'bp_core_catch_profile_uri', 'public' ); 
    305304 
    306         $profile_link = $bp['loggedin_domain'] . '/profile/'; 
     305        $profile_link = $bp->loggedin_user->domain . '/profile/'; 
    307306 
    308307        /* Add the subnav items to the profile */ 
    309308        bp_core_add_subnav_item( 'profile', 'public', __('Public', 'buddypress'), $profile_link, 'xprofile_screen_display_profile' ); 
    310309 
    311         if ( $bp['current_component'] == 'profile' ) { 
     310        if ( $bp->current_component == 'profile' ) { 
    312311            if ( bp_is_home() ) { 
    313                 $bp['bp_options_title'] = __('My Profile', 'buddypress'); 
     312                $bp->bp_options_title = __('My Profile', 'buddypress'); 
    314313            } else { 
    315                 $bp['bp_options_avatar'] = bp_core_get_avatar( $bp['current_userid'], 1 ); 
    316                 $bp['bp_options_title'] = $bp['current_fullname'];  
     314                $bp->bp_options_avatar = bp_core_get_avatar( $bp->displayed_user->id, 1 ); 
     315                $bp->bp_options_title = $bp->displayed_user->fullname;  
    317316            } 
    318317        } 
     
    326325 * 
    327326 * Returns the domain for the passed user: 
    328  * e.g. http://example.com/members/andy/ 
     327 * e.g. http://domain.com/members/andy/ 
    329328 *  
    330329 * @package BuddyPress Core 
     
    338337    if ( !$user_id ) return; 
    339338     
    340     $ud = get_userdata( $user_id ); 
    341      
    342     return $bp['root_domain'] . '/' . MEMBERS_SLUG . '/' . $ud->user_login . '/'; 
     339    $ud = get_userdata($user_id); 
     340     
     341    return $bp->root_domain . '/' . MEMBERS_SLUG . '/' . $ud->user_login . '/'; 
    343342} 
    344343 
     
    347346 * 
    348347 * Returns the domain for the root blog. 
    349  * eg: http://example.com/ OR https://example.com 
     348 * eg: http://domain.com/ OR https://domain.com 
    350349 *  
    351350 * @package BuddyPress Core 
     
    364363 
    365364/** 
    366  * bp_core_get_current_userid() 
    367  * 
    368  * Returns the user id for the user that is currently being viewed. 
    369  * eg: http://andy.example.com/ or http://example.com/andy/ 
     365 * bp_core_get_displayed_userid() 
     366 * 
     367 * Returns the user id for the user that is currently being displayed. 
     368 * eg: http://andy.domain.com/ or http://domain.com/andy/ 
    370369 *  
    371370 * @package BuddyPress Core 
    372371 * @global $current_blog WordPress global containing information and settings for the current blog being viewed. 
    373372 * @uses bp_core_get_userid_from_user_login() Returns the user id for the username passed 
    374  * @return $current_userid The user id for the user that is currently being viewed, return zero if this is not a user home and just a normal blog. 
    375  */ 
    376 function bp_core_get_current_userid( $user_login ) { 
     373 * @return The user id for the user that is currently being displayed, return zero if this is not a user home and just a normal blog. 
     374 */ 
     375function bp_core_get_displayed_userid( $user_login ) { 
    377376    return bp_core_get_userid_from_user_login( $user_login ); 
    378377} 
     
    395394    global $bp; 
    396395     
    397     $nav_key = count($bp['bp_nav']) + 1; 
    398     $user_nav_key = count($bp['bp_users_nav']) + 1; 
     396    $nav_key = count($bp->bp_nav) + 1; 
     397    $user_nav_key = count($bp->bp_users_nav) + 1; 
    399398     
    400399    if ( !$css_id ) 
    401400        $css_id = $slug; 
    402401 
    403     $bp['bp_nav'][$nav_key] = array( 
     402    $bp->bp_nav[$nav_key] = array( 
    404403        'name'   => $name,  
    405         'link'   => $bp['loggedin_domain'] . $slug, 
     404        'link'   => $bp->loggedin_user->domain . $slug, 
    406405        'css_id' => $css_id 
    407406    ); 
    408407     
    409408    if ( $add_to_usernav ) { 
    410         $bp['bp_users_nav'][$user_nav_key] = array( 
     409        $bp->bp_users_nav[$user_nav_key] = array( 
    411410            'name'   => $name,  
    412             'link'   => $bp['current_domain'] . $slug, 
     411            'link'   => $bp->displayed_user->domain . $slug, 
    413412            'css_id' => $css_id 
    414413        ); 
     
    441440        $css_id = $slug; 
    442441 
    443     $bp['bp_options_nav'][$parent_id][$slug] = array( 
     442    $bp->bp_options_nav[$parent_id][$slug] = array( 
    444443        'name' => $name, 
    445444        'link' => $link . $slug, 
     
    447446    ); 
    448447     
    449     if ( function_exists($function) && $user_has_access && $bp['current_action'] == $slug && $bp['current_component'] == $parent_id ) 
     448    if ( function_exists($function) && $user_has_access && $bp->current_action == $slug && $bp->current_component == $parent_id ) 
    450449        add_action( 'wp', $function, 3 ); 
    451450} 
     
    464463    global $bp; 
    465464 
    466     unset($bp['bp_options_nav'][$parent_id]); 
     465    unset($bp->bp_options_nav[$parent_id]); 
    467466} 
    468467 
     
    489488        return false; 
    490489 
    491     if ( $bp['current_component'] == $parent_id && !$bp['current_action'] ) { 
     490    if ( $bp->current_component == $parent_id && !$bp->current_action ) { 
    492491        if ( function_exists($function) ) { 
    493492            add_action( 'wp', $function, 3 ); 
     
    495494         
    496495        if ( $slug ) 
    497             $bp['current_action'] = $slug; 
     496            $bp->current_action = $slug; 
    498497    } 
    499498} 
     
    522521 * bp_core_add_root_component() 
    523522 * 
    524  * Adds a component to the $bp['root_components'] global. 
     523 * Adds a component to the $bp->root_components global. 
    525524 * Any component that runs in the "root" of an install should be added. 
    526525 * The "root" as in, it can or always runs outside of the /members/username/ path. 
    527526 * 
    528527 * Example of a root component: 
    529  *  Groups: http://example.com/groups/group-name 
    530  *          http://community.example.com/groups/group-name 
    531  *          http://example.com/wpmu/groups/group-name 
     528 *  Groups: http://domain.com/groups/group-name 
     529 *          http://community.domain.com/groups/group-name 
     530 *          http://domain.com/wpmu/groups/group-name 
    532531 * 
    533532 * Example of a component that is NOT a root component: 
    534  *  Friends: http://example.com/members/andy/friends 
    535  *           http://community.example.com/members/andy/friends 
    536  *           http://example.com/wpmu/members/andy/friends 
     533 *  Friends: http://domain.com/members/andy/friends 
     534 *           http://community.domain.com/members/andy/friends 
     535 *           http://domain.com/wpmu/members/andy/friends 
    537536 *  
    538537 * @package BuddyPress Core 
     
    543542    global $bp; 
    544543 
    545     $bp['root_components'][] = $slug; 
     544    $bp->root_components[] = $slug; 
    546545} 
    547546 
     
    560559    global $bp, $wpdb; 
    561560     
    562     if ( $bp['current_component'] == MEMBERS_SLUG && isset( $_GET['random'] ) ) { 
     561    if ( $bp->current_component == MEMBERS_SLUG && isset( $_GET['random'] ) ) { 
    563562        $user = BP_Core_User::get_random_users(1); 
    564563 
    565564        $ud = get_userdata( $user['users'][0]->user_id ); 
    566         bp_core_redirect( $bp['root_domain'] . '/' . MEMBERS_SLUG . '/' . $ud->user_login ); 
     565        bp_core_redirect( $bp->root_domain . '/' . MEMBERS_SLUG . '/' . $ud->user_login ); 
    567566    } 
    568567} 
     
    647646    $ud = get_userdata($uid); 
    648647         
    649     return $bp['root_domain'] . '/' . MEMBERS_SLUG . '/' . $ud->user_login . '/'; 
     648    return $bp->root_domain . '/' . MEMBERS_SLUG . '/' . $ud->user_login . '/'; 
    650649} 
    651650 
     
    670669 * 
    671670 * Returns a HTML formatted link for a user with the user's full name as the link text. 
    672  * eg: <a href="http://andy.example.com/">Andy Peatling</a> 
     671 * eg: <a href="http://andy.domain.com/">Andy Peatling</a> 
    673672 * Optional parameters will return just the name, or just the URL, or disable "You" text when 
    674673 * user matches the logged in user.  
     
    980979    global $bp; 
    981980     
    982     if ( !is_user_logged_in() || !get_usermeta( $bp['loggedin_userid'], 'last_activity') ) 
     981    if ( !is_user_logged_in() ) 
    983982        return false; 
    984983     
    985     if ( time() >= strtotime('+5 minutes', get_usermeta( $bp['loggedin_userid'], 'last_activity') ) || get_usermeta( $bp['loggedin_userid'], 'last_activity') == '' ) { 
     984    if ( time() >= strtotime( '+5 minutes', get_usermeta( $bp->loggedin_user->id, 'last_activity' ) ) || '' == get_usermeta( $bp->loggedin_user->id, 'last_activity' ) ) { 
    986985        // Updated last site activity for this user. 
    987         update_usermeta( $bp['loggedin_userid'], 'last_activity', time() ); 
     986        update_usermeta( $bp->loggedin_user->id, 'last_activity', time() ); 
    988987    } 
    989988} 
     
    10031002 */ 
    10041003function bp_core_get_last_activity( $last_activity_date, $string ) { 
    1005     if ( !$last_activity_date || $last_activity_date == '' ) { 
     1004    if ( !$last_activity_date || empty( $last_activity_date ) ) { 
    10061005        $last_active = __('not recently active', 'buddypress'); 
    10071006    } else { 
     
    10321031     
    10331032    if ( !$user_id ) 
    1034         $user_id = $bp['current_userid']; 
     1033        $user_id = $bp->displayed_user->id; 
    10351034     
    10361035    return $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM $wpdb->posts WHERE post_author = %d AND post_status = 'publish' AND post_type = 'post'", $user_id ) ); 
     
    11031102    foreach ( (array)$nav_array as $key => $value ) { 
    11041103        switch ( $nav_array[$key]['css_id'] ) { 
    1105             case $bp['activity']['slug']: 
     1104            case $bp->activity->slug: 
    11061105                $new_nav[0] = $nav_array[$key]; 
    11071106                unset($nav_array[$key]); 
    11081107            break; 
    1109             case $bp['profile']['slug']: 
     1108            case $bp->profile->slug: 
    11101109                $new_nav[1] = $nav_array[$key]; 
    11111110                unset($nav_array[$key]); 
     
    11151114                unset($nav_array[$key]); 
    11161115            break; 
    1117             case $bp['blogs']['slug']: 
     1116            case $bp->blogs->slug: 
    11181117                $new_nav[2] = $nav_array[$key]; 
    11191118                unset($nav_array[$key]); 
    11201119            break; 
    1121             case $bp['wire']['slug']: 
     1120            case $bp->wire->slug: 
    11221121                $new_nav[3] = $nav_array[$key]; 
    11231122                unset($nav_array[$key]); 
    11241123            break; 
    1125             case $bp['messages']['slug']: 
     1124            case $bp->messages->slug: 
    11261125                $new_nav[4] = $nav_array[$key]; 
    11271126                unset($nav_array[$key]); 
    11281127            break; 
    1129             case $bp['friends']['slug']: 
     1128            case $bp->friends->slug: 
    11301129                $new_nav[5] = $nav_array[$key]; 
    11311130                unset($nav_array[$key]); 
    11321131            break; 
    1133             case $bp['groups']['slug']: 
     1132            case $bp->groups->slug: 
    11341133                $new_nav[6] = $nav_array[$key]; 
    11351134                unset($nav_array[$key]); 
    11361135            break; 
    1137             case $bp['photos']['slug']: 
     1136            case $bp->photos->slug: 
    11381137                $new_nav[7] = $nav_array[$key]; 
    11391138                unset($nav_array[$key]); 
    11401139            break; 
    1141             case $bp['account']['slug']: 
     1140            case $bp->account->slug: 
    11421141                $new_nav[8] = $nav_array[$key]; 
    11431142                unset($nav_array[$key]); 
     
    11971196     
    11981197    $current = maybe_unserialize( get_site_option( 'illegal_names' ) ); 
    1199     $bp_illegal_names = $bp['root_components']; 
     1198    $bp_illegal_names = $bp->root_components; 
    12001199     
    12011200    if ( is_array( $current ) ) { 
     
    12521251    require_once( ABSPATH . '/wp-admin/includes/user.php' ); 
    12531252 
    1254     return wpmu_delete_user( $bp['loggedin_userid'] ); 
     1253    return wpmu_delete_user( $bp->loggedin_user->id ); 
    12551254} 
    12561255 
     
    12581257    global $bp; 
    12591258     
    1260     if ( $bp['current_component'] == SEARCH_SLUG ) { 
     1259    if ( $bp->current_component == SEARCH_SLUG ) { 
    12611260        $search_terms = $_POST['search-terms']; 
    12621261        $search_which = $_POST['search-which']; 
     
    13031302    global $bp; 
    13041303     
    1305     foreach ( $bp['version_numbers'] as $name => $version ) { 
     1304    foreach ( $bp->version_numbers as $name => $version ) { 
    13061305        echo ucwords($name) . ': <b>' . $version . '</b> / '; 
    13071306    } 
Note: See TracChangeset for help on using the changeset viewer.