Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/06/2009 03:07:48 AM (17 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/bp-core-templatetags.php

    r958 r1021  
    44 * TEMPLATE TAG
    55 *
    6  * Uses the $bp['bp_nav'] global to render out the navigation within a BuddyPress install.
     6 * Uses the $bp->bp_nav global to render out the navigation within a BuddyPress install.
    77 * Each component adds to this navigation array within its own [component_name]_setup_nav() function.
    88 *
     
    2020   
    2121    /* Sort the nav by key as the array has been put together in different locations */
    22     $bp['bp_nav'] = bp_core_sort_nav_items( $bp['bp_nav'] );
     22    $bp->bp_nav = bp_core_sort_nav_items( $bp->bp_nav );
    2323
    2424    /* Loop through each navigation item */
    25     foreach( (array) $bp['bp_nav'] as $nav_item ) {
     25    foreach( (array) $bp->bp_nav as $nav_item ) {
    2626        /* If the current component matches the nav item id, then add a highlight CSS class. */
    27         if ( $bp['current_component'] == $nav_item['css_id'] ) {
     27        if ( $bp->current_component == $nav_item['css_id'] ) {
    2828            $selected = ' class="current"';
    2929        } else {
     
    3131        }
    3232       
    33         /* If we are viewing another person (current_userid does not equal loggedin_userid)
     33        /* If we are viewing another person (current_userid does not equal loggedin_user->id)
    3434           then check to see if the two users are friends. if they are, add a highlight CSS class
    3535           to the friends nav item if it exists. */
    36         if ( !bp_is_home() && $bp['current_userid'] ) {
     36        if ( !bp_is_home() && $bp->displayed_user->id ) {
    3737            if ( function_exists('friends_install') ) {
    38                 if ( friends_check_friendship( $bp['loggedin_userid'], $bp['current_userid'] ) && $nav_item['css_id'] == $bp['friends']['slug'] ) {
     38                if ( friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id ) && $nav_item['css_id'] == $bp->friends->slug ) {
    3939                    $selected = ' class="current"';
    4040                } else {
     
    6060 * TEMPLATE TAG
    6161 *
    62  * Uses the $bp['bp_options_nav'] global to render out the sub navigation for the current component.
     62 * Uses the $bp->bp_options_nav global to render out the sub navigation for the current component.
    6363 * Each component adds to its sub navigation array within its own [component_name]_setup_nav() function.
    6464 *
     
    7878    /* Only render this navigation when the logged in user is looking at one of their own pages. */
    7979    if ( bp_is_home() || $is_single_group ) {
    80         if ( count( $bp['bp_options_nav'][$bp['current_component']] ) < 1 )
     80        if ( count( $bp->bp_options_nav[$bp->current_component] ) < 1 )
    8181            return false;
    8282   
    8383        /* Loop through each navigation item */
    84         foreach ( $bp['bp_options_nav'][$bp['current_component']] as $slug => $values ) {
     84        foreach ( $bp->bp_options_nav[$bp->current_component] as $slug => $values ) {
    8585            $title = $values['name'];
    8686            $link = $values['link'];
     
    8888           
    8989            /* If the current action or an action variable matches the nav item id, then add a highlight CSS class. */
    90             if ( $slug == $bp['current_action'] || in_array( $slug, $bp['action_variables'] ) ) {
     90            if ( $slug == $bp->current_action || in_array( $slug, $bp->action_variables ) ) {
    9191                $selected = ' class="current"';
    9292            } else {
     
    9898        }
    9999    } else {
    100         if ( !$bp['bp_users_nav'] )
     100        if ( !$bp->bp_users_nav )
    101101            return false;
    102102
     
    109109 * TEMPLATE TAG
    110110 *
    111  * Uses the $bp['bp_users_nav'] global to render out the user navigation when viewing another user other than
     111 * Uses the $bp->bp_users_nav global to render out the user navigation when viewing another user other than
    112112 * yourself.
    113113 *
     
    119119
    120120    /* Sort the nav by key as the array has been put together in different locations */
    121     $bp['bp_users_nav'] = bp_core_sort_nav_items( $bp['bp_users_nav'] );
    122 
    123     foreach ( $bp['bp_users_nav'] as $user_nav_item ) {
    124         if ( $bp['current_component'] == $user_nav_item['css_id'] ) {
     121    $bp->bp_users_nav = bp_core_sort_nav_items( $bp->bp_users_nav );
     122
     123    foreach ( $bp->bp_users_nav as $user_nav_item ) {   
     124        if ( $bp->current_component == $user_nav_item['css_id'] ) {
    125125            $selected = ' class="current"';
    126126        } else {
     
    145145    global $bp;
    146146   
    147     if ( $bp['bp_options_avatar'] == '' )
     147    if ( empty( $bp->bp_options_avatar ) )
    148148        return false;
    149149   
     
    164164    global $bp;
    165165
    166     echo apply_filters( 'bp_get_options_avatar', $bp['bp_options_avatar'] );
     166    echo apply_filters( 'bp_get_options_avatar', $bp->bp_options_avatar );
    167167}
    168168
     
    170170    global $bp;
    171171   
    172     if ( $bp['bp_options_title'] == '' )
    173         $bp['bp_options_title'] = __('Options', 'buddypress');
    174    
    175     echo apply_filters( 'bp_get_options_avatar', $bp['bp_options_title'] );
     172    if ( empty( $bp->bp_options_title ) )
     173        $bp->bp_options_title = __( 'Options', 'buddypress' );
     174   
     175    echo apply_filters( 'bp_get_options_avatar', $bp->bp_options_title );
    176176}
    177177
     
    200200   
    201201    if ( $width && $height )
    202         echo apply_filters( 'bp_loggedinuser_avatar', bp_core_get_avatar( $bp['loggedin_userid'], 2, $width, $height ) );
     202        echo apply_filters( 'bp_loggedinuser_avatar', bp_core_get_avatar( $bp->loggedin_user->id, 2, $width, $height ) );
    203203    else
    204         echo apply_filters( 'bp_loggedinuser_avatar', bp_core_get_avatar( $bp['loggedin_userid'], 2 ) );
     204        echo apply_filters( 'bp_loggedinuser_avatar', bp_core_get_avatar( $bp->loggedin_user->id, 2 ) );
    205205}
    206206
     
    209209   
    210210    if ( $width && $height )
    211         echo apply_filters( 'bp_get_options_avatar', bp_core_get_avatar( $bp['loggedin_userid'], 1, $width, $height ) );
     211        echo apply_filters( 'bp_get_options_avatar', bp_core_get_avatar( $bp->loggedin_user->id, 1, $width, $height ) );
    212212    else
    213         echo apply_filters( 'bp_get_options_avatar', bp_core_get_avatar( $bp['loggedin_userid'], 1 ) );
     213        echo apply_filters( 'bp_get_options_avatar', bp_core_get_avatar( $bp->loggedin_user->id, 1 ) );
    214214}
    215215
     
    219219
    220220function bp_is_home() {
    221     global $bp, $current_blog, $doing_admin_bar;
    222    
    223     if ( is_user_logged_in() && $bp['loggedin_userid'] == $bp['current_userid'] )
     221    global $bp;
     222   
     223    if ( is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
    224224        return true;
    225225       
     
    231231   
    232232    if ( !$user_id )
    233         $user_id = $bp['current_userid'];
     233        $user_id = $bp->displayed_user->id;
    234234   
    235235    if ( function_exists('xprofile_install') ) {
    236         // First check the usermeta table for a easily fetchable value
    237         //$data = get_usermeta( $user_id, 'bp_display_name' );
    238 
    239         //if ( $data == '' ) {
    240             $data = bp_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id );
    241 
    242             if ( empty($data) ) {
    243                 $ud = get_userdata($user_id);
    244                 $data = $ud->display_name;
    245             } else {
    246                 $data = ucfirst($data);
    247             }
    248            
    249             // store this in usermeta for less expensive fetching.
    250         //  update_usermeta( $user_id, 'bp_display_name', $data );
    251         //}
     236        $data = bp_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id );
     237
     238        if ( empty($data) ) {
     239            $ud = get_userdata($user_id);
     240            $data = $ud->display_name;
     241        } else {
     242            $data = ucfirst($data);
     243        }
    252244    } else {
    253245        $ud = get_userdata($user_id);
     
    265257   
    266258    if ( !$user_id )
    267         $user_id = $bp['current_userid'];
     259        $user_id = $bp->displayed_user->id;
    268260   
    269261    $last_activity = bp_core_get_last_activity( get_usermeta( $user_id, 'last_activity' ), __('active %s ago', 'buddypress') );
     
    277269function bp_the_avatar() {
    278270    global $bp;
    279     echo apply_filters( 'bp_the_avatar', bp_core_get_avatar( $bp['current_userid'], 2 ) );
     271    echo apply_filters( 'bp_the_avatar', bp_core_get_avatar( $bp->displayed_user->id, 2 ) );
    280272}
    281273
    282274function bp_the_avatar_thumbnail() {
    283275    global $bp;
    284     echo apply_filters( 'bp_the_avatar_thumbnail', bp_core_get_avatar( $bp['current_userid'], 1 ) );
     276    echo apply_filters( 'bp_the_avatar_thumbnail', bp_core_get_avatar( $bp->displayed_user->id, 1 ) );
    285277}
    286278
     
    288280    global $bp;
    289281   
    290     echo apply_filters( 'bp_the_avatar_thumbnail', $bp['current_domain'] );
     282    echo apply_filters( 'bp_the_avatar_thumbnail', $bp->displayed_user->domain );
    291283}
    292284
     
    322314        $youtext = ucfirst($youtext);
    323315   
    324     if ( $bp['current_userid'] == $bp['loggedin_userid'] ) {
     316    if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
    325317        if ( $echo )
    326318            echo apply_filters( 'bp_word_or_name', $youtext );
     
    328320            return apply_filters( 'bp_word_or_name', $youtext );
    329321    } else {
    330         $nametext = sprintf($nametext, $bp['current_fullname']);
     322        $nametext = sprintf( $nametext, $bp->displayed_user->fullname );
    331323        if ( $echo )
    332324            echo apply_filters( 'bp_word_or_name', $nametext );
     
    342334        $yourtext = ucfirst($yourtext);
    343335   
    344     if ( $bp['current_userid'] == $bp['loggedin_userid'] ) {
     336    if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
    345337        if ( $echo )
    346338            echo apply_filters( 'bp_your_or_their', $yourtext );
     
    358350    global $bp, $current_user;
    359351   
    360     if ( $link = bp_core_get_userlink( $bp['loggedin_userid'] ) ) {
     352    if ( $link = bp_core_get_userlink( $bp->loggedin_user->id ) ) {
    361353        echo apply_filters( 'bp_loggedinuser_link', $link );
    362354    } else {
    363         $ud = get_userdata($current_user->ID);
     355        $ud = get_userdata($displayed_user->id);
    364356        echo apply_filters( 'bp_loggedinuser_link', $ud->user_login );
    365357    }
     
    374366    global $bp, $is_member_page;
    375367   
    376     if ( $bp['current_component'] == NEWS_SLUG )
    377         return true;
    378        
    379     if ( !$is_member_page && !in_array( $bp['current_component'], $bp['root_components'] ) )
    380         return true;
    381    
     368    if ( $bp->current_component == HOME_BLOG_SLUG )
     369        return true;
     370
     371    if ( !$is_member_page && !in_array( $bp->current_component, $bp->root_components ) )
     372        return true;
     373       
    382374    return false;
    383375}
     
    386378    global $bp;
    387379   
    388     if ( $bp['current_fullname'] != '' ) {
    389         echo apply_filters( 'bp_page_title', strip_tags( $bp['current_fullname'] . ' &raquo; ' . ucwords($bp['current_component']) . ' &raquo; ' . $bp['bp_options_nav'][$bp['current_component']][$bp['current_action']]['name'] ) );
    390     } else {
    391         echo apply_filters( 'bp_page_title', strip_tags( ucwords($bp['current_component']) . ' &raquo; ' . ucwords($bp['bp_options_title']) . ' &raquo; ' . ucwords($bp['current_action']) ) );
     380    if ( !empty( $bp->displayed_user->fullname ) ) {
     381        echo apply_filters( 'bp_page_title', strip_tags( $bp->displayed_user->fullname . ' &raquo; ' . ucwords( $bp->current_component ) . ' &raquo; ' . $bp->bp_options_nav[$bp->current_component][$bp->current_action]['name'] ) );
     382    } else {
     383        echo apply_filters( 'bp_page_title', strip_tags( ucwords( $bp->current_component ) . ' &raquo; ' . ucwords( $bp->bp_options_title ) . ' &raquo; ' . ucwords( $bp->current_action ) ) );
    392384    }
    393385}
     
    401393    global $bp;
    402394
    403     if ( $bp['current_userid'] )
     395    if ( $bp->displayed_user->id )
    404396        return false;
    405397
    406     if ( $page == $bp['current_component'] || $page == 'home' && $bp['current_component'] == $bp['default_component'] )
     398    if ( $page == $bp->current_component || $page == 'home' && $bp->current_component == $bp->default_component )
    407399        return true;
    408400   
     
    422414    if ( bp_has_custom_signup_page() ) {
    423415        if ( $echo )
    424             echo $bp['root_domain'] . '/' . REGISTER_SLUG;
    425         else
    426             return $bp['root_domain'] . '/' . REGISTER_SLUG;
    427     } else {
    428         if ( $echo )
    429             echo $bp['root_domain'] . '/wp-signup.php';
    430         else
    431             return $bp['root_domain'] . '/wp-signup.php';
     416            echo $bp->root_domain . '/' . REGISTER_SLUG;
     417        else
     418            return $bp->root_domain . '/' . REGISTER_SLUG;
     419    } else {
     420        if ( $echo )
     421            echo $bp->root_domain . '/wp-signup.php';
     422        else
     423            return $bp->root_domain . '/wp-signup.php';
    432424    }
    433425}
     
    528520   
    529521    if ( function_exists('friends_install') ) {
    530         if ( friends_check_friendship( $bp['loggedin_userid'], $bp['current_userid'] ) )
     522        if ( friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id ) )
    531523            return true;
    532524        else
     
    540532    global $bp;
    541533?>
    542     <li<?php if(bp_is_page('home')) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php _e( 'Home', 'buddypress' ) ?></a></li>
    543     <li<?php if(bp_is_page(HOME_BLOG_SLUG)) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo HOME_BLOG_SLUG ?>" title="<?php _e( 'Blog', 'buddypress' ) ?>"><?php _e( 'Blog', 'buddypress' ) ?></a></li>
    544     <li<?php if(bp_is_page(MEMBERS_SLUG)) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo MEMBERS_SLUG ?>" title="<?php _e( 'Members', 'buddypress' ) ?>"><?php _e( 'Members', 'buddypress' ) ?></a></li>
    545    
    546     <?php if ( function_exists('groups_install') ) { ?>
    547         <li<?php if(bp_is_page($bp['groups']['slug'])) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo $bp['groups']['slug'] ?>" title="<?php _e( 'Groups', 'buddypress' ) ?>"><?php _e( 'Groups', 'buddypress' ) ?></a></li>
     534    <li<?php if ( bp_is_page( 'home' ) ) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php _e( 'Home', 'buddypress' ) ?></a></li>
     535    <li<?php if ( bp_is_page( HOME_BLOG_SLUG ) ) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo HOME_BLOG_SLUG ?>" title="<?php _e( 'Blog', 'buddypress' ) ?>"><?php _e( 'Blog', 'buddypress' ) ?></a></li>
     536    <li<?php if ( bp_is_page( MEMBERS_SLUG ) ) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo MEMBERS_SLUG ?>" title="<?php _e( 'Members', 'buddypress' ) ?>"><?php _e( 'Members', 'buddypress' ) ?></a></li>
     537   
     538    <?php if ( function_exists( 'groups_install' ) ) { ?>
     539        <li<?php if ( bp_is_page( $bp->groups->slug ) ) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo $bp->groups->slug ?>" title="<?php _e( 'Groups', 'buddypress' ) ?>"><?php _e( 'Groups', 'buddypress' ) ?></a></li>
    548540    <?php } ?>
    549541   
    550     <?php if ( function_exists('bp_blogs_install') ) { ?>
    551         <li<?php if(bp_is_page($bp['blogs']['slug'])) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo $bp['blogs']['slug'] ?>" title="<?php _e( 'Blogs', 'buddypress' ) ?>"><?php _e( 'Blogs', 'buddypress' ) ?></a></li>
     542    <?php if ( function_exists( 'bp_blogs_install' ) ) { ?>
     543        <li<?php if ( bp_is_page( $bp->blogs->slug ) ) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo $bp->blogs->slug ?>" title="<?php _e( 'Blogs', 'buddypress' ) ?>"><?php _e( 'Blogs', 'buddypress' ) ?></a></li>
    552544    <?php } ?>
    553545<?php
     
    568560function bp_current_user_id() {
    569561    global $bp;
    570     return apply_filters( 'bp_current_user_id', $bp['current_userid'] );
     562    return apply_filters( 'bp_current_user_id', $bp->displayed_user->id );
    571563}
    572564
    573565function bp_user_fullname() {
    574566    global $bp;
    575     echo apply_filters( 'bp_user_fullname', $bp['current_fullname'] );
     567    echo apply_filters( 'bp_user_fullname', $bp->displayed_user->fullname );
    576568}
    577569
Note: See TracChangeset for help on using the changeset viewer.