Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/25/2009 04:01:43 PM (15 years ago)
Author:
apeatling
Message:

Removed blogs, groups and members directory from the home theme into the BuddyPress member theme. The directories now have their own templates and theme based CSS and provide much easier editing.

Moved the $bp global setup to a higher priority action - from the 'wp' action to the 'plugins_loaded' action. This stops occurrences where the $bp global was not defined yet.

File:
1 edited

Legend:

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

    r1243 r1250  
    454454
    455455function bp_page_title() {
    456     global $bp;
    457    
    458     if ( !empty( $bp->displayed_user->fullname ) ) {
    459         echo apply_filters( 'bp_page_title', strip_tags( $bp->displayed_user->fullname . ' » ' . ucwords( $bp->current_component ) . ' » ' . $bp->bp_options_nav[$bp->current_component][$bp->current_action]['name'] ) );
     456    global $bp, $post, $wp_query;
     457   
     458    //var_dump($wp_query);
     459
     460    if ( is_home() && bp_is_page( 'home' ) ) {
     461        $title = __( 'Home', 'buddypress' );
     462    } else if ( bp_is_blog_page() ) {
     463        if ( is_single() ) {
     464            $title = __( 'Blog — ' . $post->post_title, 'buddypress' );
     465        } else if ( is_category() ) {
     466            $title = __( 'Blog — Categories — ' . ucwords( $wp_query->query_vars['category_name'] ), 'buddypress' );               
     467        } else if ( is_tag() ) {
     468            $title = __( 'Blog — Tags — ' . ucwords( $wp_query->query_vars['tag'] ), 'buddypress' );               
     469        } else {
     470            $title = __( 'Blog', 'buddypress' );
     471        }
     472    } else if ( !empty( $bp->displayed_user->fullname ) ) {
     473        $title = strip_tags( $bp->displayed_user->fullname . ' — ' . ucwords( $bp->current_component ) . ' — ' . $bp->bp_options_nav[$bp->current_component][$bp->current_action]['name'] );
     474    } else if ( $bp->is_single_item ) {
     475        $title = ucwords( $bp->current_component ) . ' — ' . $bp->bp_options_title;
    460476    } else {
    461         echo apply_filters( 'bp_page_title', strip_tags( ucwords( $bp->current_component ) . ' » ' . ucwords( $bp->bp_options_title ) . ' » ' . ucwords( $bp->current_action ) ) );
    462     }
     477        if ( $bp->is_directory ) {
     478            if ( !$bp->current_component )
     479                $title = __( 'Members Directory', 'buddypress' );
     480            else
     481                $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( $bp->current_component ) );
     482        }       
     483    }
     484   
     485    echo apply_filters( 'bp_page_title', get_blog_option( 1, 'blogname' ) . ' — ' . $title, $title );
     486   
    463487}
    464488
     
    473497    if ( $bp->displayed_user->id || $bp->is_single_item )
    474498        return false;
    475 
    476     if ( $page == $bp->current_component || $page == 'home' && $bp->current_component == $bp->default_component )
     499   
     500    if ( $page == $bp->current_component || ( is_home() && $page == 'home' && $bp->current_component == $bp->default_component ) || ( $page == MEMBERS_SLUG && !$bp->current_component ) )
    477501        return true;
    478502   
     
    647671}
    648672
     673function bp_get_optionsbar( $hide_on_directory = true ) {
     674    global $bp;
     675   
     676    if ( $hide_on_directory && $bp->is_directory )
     677        return false;
     678   
     679    include_once( TEMPLATEPATH . '/userbar.php' );
     680}
     681
     682function bp_get_userbar( $hide_on_directory = true ) {
     683    global $bp;
     684   
     685    if ( $hide_on_directory && $bp->is_directory )
     686        return false;
     687   
     688    include_once( TEMPLATEPATH . '/optionsbar.php' );
     689}
     690
     691function bp_is_directory() {
     692    global $bp;
     693   
     694    return $bp->is_directory;
     695}
     696
     697
     698/*** CUSTOM LOOP TEMPLATE CLASSES *******************/
     699
     700class BP_Core_Members_Template {
     701    var $current_member = -1;
     702    var $member_count;
     703    var $members;
     704    var $member;
     705
     706    var $in_the_loop;
     707
     708    var $pag_page;
     709    var $pag_num;
     710    var $pag_links;
     711    var $total_member_count;
     712   
     713    function bp_core_members_template( $type, $per_page, $max ) {
     714        global $bp, $bp_the_member_query;
     715
     716        $this->pag_page = isset( $_REQUEST['page'] ) ? intval( $_REQUEST['page'] ) : 1;
     717        $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
     718               
     719        if ( isset( $_REQUEST['s'] ) && '' != $_REQUEST['s'] && $type != 'random' ) {
     720            $this->members = BP_Core_User::search_users( $_REQUEST['s'], $this->pag_num, $this->pag_page );
     721        } else if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) {
     722            $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
     723        } else {
     724            switch ( $type ) {
     725                case 'random':
     726                    $this->members = BP_Core_User::get_random_users( $this->pag_num, $this->pag_page );
     727                    break;
     728               
     729                case 'newest':
     730                    $this->members = BP_Core_User::get_newest_users( $this->pag_num, $this->pag_page );
     731                    break;
     732
     733                case 'popular':
     734                    $this->members = BP_Core_User::get_popular_users( $this->pag_num, $this->pag_page );
     735                    break; 
     736
     737                case 'online':
     738                    $this->members = BP_Core_User::get_online_users( $this->pag_num, $this->pag_page );
     739                    break; 
     740               
     741                case 'active': default:
     742                    $this->members = BP_Core_User::get_active_users( $this->pag_num, $this->pag_page );
     743                    break;                 
     744            }
     745        }
     746       
     747        if ( !$max )
     748            $this->total_member_count = (int)$this->members['total'];
     749        else
     750            $this->total_member_count = (int)$max;
     751
     752        $this->members = $this->members['users'];
     753        $this->member_count = count($this->members);
     754
     755        $this->pag_links = paginate_links( array(
     756            'base' => add_query_arg( 'page', '%#%' ),
     757            'format' => '',
     758            'total' => ceil( (int) $this->total_member_count / (int) $this->pag_num ),
     759            'current' => (int) $this->pag_page,
     760            'prev_text' => '«',
     761            'next_text' => '»',
     762            'mid_size' => 1
     763        ));     
     764    }
     765   
     766    function has_members() {
     767        if ( $this->member_count )
     768            return true;
     769       
     770        return false;
     771    }
     772   
     773    function next_member() {
     774        $this->current_member++;
     775        $this->member = $this->members[$this->current_member];
     776       
     777        return $this->member;
     778    }
     779   
     780    function rewind_members() {
     781        $this->current_member = -1;
     782        if ( $this->member_count > 0 ) {
     783            $this->member = $this->members[0];
     784        }
     785    }
     786   
     787    function site_members() {
     788        if ( $this->current_member + 1 < $this->member_count ) {
     789            return true;
     790        } elseif ( $this->current_member + 1 == $this->member_count ) {
     791            do_action('loop_end');
     792            // Do some cleaning up after the loop
     793            $this->rewind_members();
     794        }
     795
     796        $this->in_the_loop = false;
     797        return false;
     798    }
     799   
     800    function the_member() {
     801        global $member, $bp;
     802
     803        $this->in_the_loop = true;
     804        $this->member = $this->next_member();
     805        $user_id = $this->member->user_id;
     806
     807        if ( !$this->member = wp_cache_get( 'bp_user_' . $user_id, 'bp' ) ) {
     808            $this->member = new BP_Core_User( $user_id );
     809            wp_cache_set( 'bp_user_' . $user_id, $this->member, 'bp' );
     810        }
     811       
     812        if ( 0 == $this->current_member ) // loop has just started
     813            do_action('loop_start');
     814    }
     815}
     816
     817function bp_rewind_site_members() {
     818    global $site_members_template;
     819   
     820    return $site_members_template->rewind_members();
     821}
     822
     823function bp_has_site_members( $args = '' ) {
     824    global $bp, $site_members_template;
     825
     826    $defaults = array(
     827        'type' => 'active',
     828        'per_page' => 10,
     829        'max' => false
     830    );
     831
     832    $r = wp_parse_args( $args, $defaults );
     833    extract( $r, EXTR_SKIP );
     834
     835    // type: active ( default ) | random | newest | popular | online
     836   
     837    if ( $max ) {
     838        if ( $per_page > $max )
     839            $per_page = $max;
     840    }
     841   
     842    $site_members_template = new BP_Core_Members_Template( $type, $per_page, $max );
     843   
     844    return $site_members_template->has_members();
     845}
     846
     847function bp_the_site_member() {
     848    global $site_members_template;
     849    return $site_members_template->the_member();
     850}
     851
     852function bp_site_members() {
     853    global $site_members_template;
     854    return $site_members_template->site_members();
     855}
     856
     857function bp_site_members_pagination_count() {
     858    global $bp, $site_members_template;
     859   
     860    $from_num = intval( ( $site_members_template->pag_page - 1 ) * $site_members_template->pag_num ) + 1;
     861    $to_num = ( $from_num + ( $site_members_template->pag_num - 1 ) > $site_members_template->total_member_count ) ? $site_members_template->total_member_count : $from_num + ( $site_members_template->pag_num - 1) ;
     862
     863    echo sprintf( __( 'Viewing member %d to %d (of %d members)', 'buddypress' ), $from_num, $to_num, $site_members_template->total_member_count ); ?> &nbsp;
     864    <img id="ajax-loader-members" src="<?php echo $bp->core->image_base ?>/ajax-loader.gif" height="7" alt="<?php _e( "Loading", "buddypress" ) ?>" style="display: none;" /><?php
     865}
     866
     867function bp_site_members_pagination_links() {
     868    global $site_members_template;
     869    echo $site_members_template->pag_links;
     870}
     871
     872function bp_the_site_member_avatar() {
     873    global $site_members_template;
     874   
     875    echo $site_members_template->member->avatar_thumb;
     876}
     877
     878function bp_the_site_member_link() {
     879    global $site_members_template;
     880   
     881    echo $site_members_template->member->user_url;
     882}
     883
     884function bp_the_site_member_name() {
     885    global $site_members_template;
     886   
     887    echo $site_members_template->member->fullname;
     888}
     889
     890function bp_the_site_member_last_active() {
     891    global $site_members_template;
     892
     893    echo $site_members_template->member->last_active;
     894}
     895
     896function bp_the_site_member_add_friend_button() {
     897    global $site_members_template;
     898   
     899    if ( function_exists( 'bp_add_friend_button' ) ) {
     900        echo bp_add_friend_button( $site_members_template->member->id );
     901    }
     902}
     903
     904function bp_the_site_member_total_friend_count() {
     905    global $site_members_template;
     906   
     907    if ( !(int) $site_members_template->member->total_friends )
     908        return false;
     909   
     910    if ( 1 == (int) $site_members_template->member->total_friends )
     911        printf( __( '%d friend', 'buddypress' ), (int) $site_members_template->member->total_friends );
     912    else
     913        printf( __( '%d friends', 'buddypress' ), (int) $site_members_template->member->total_friends );       
     914}
     915
     916function bp_the_site_member_random_profile_data() {
     917    global $site_members_template;
     918
     919    if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?>
     920        <?php $random_data = xprofile_get_random_profile_data( $site_members_template->member->id, true ); ?>
     921            <strong><?php echo $random_data[0]->name ?></strong>
     922            <?php echo $random_data[0]->value ?>
     923    <?php }
     924}
     925
     926function bp_the_site_member_hidden_fields() {
     927    if ( isset( $_GET['s'] ) ) {
     928        echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ) . '" name="search_terms" />';
     929    }
     930
     931    if ( isset( $_POST['letter'] ) ) {
     932        echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
     933    }
     934
     935    if ( isset( $_POST['members_search'] ) ) {
     936        echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['members_search'] ) . '" name="search_terms" />';
     937    }
     938}
     939
     940function bp_directory_members_search_form() {
     941    global $bp; ?>
     942    <form action="<?php echo $bp->root_domain . '/' . MEMBERS_SLUG  . '/search/' ?>" method="post" id="search-members-form">
     943        <label><input type="text" name="members_search" id="members_search" value="<?php if ( isset( $_GET['s'] ) ) { echo attribute_escape( $_GET['s'] ); } else { _e( 'Search anything...', 'buddypress' ); } ?>"  onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
     944        <input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
     945    </form>
     946<?php
     947}
     948
     949
    649950/* Template functions for fetching globals, without querying the DB again
    650951   also means we dont have to use the $bp variable in the template (looks messy) */
     
    654955    return apply_filters( 'bp_current_user_id', $bp->displayed_user->id );
    655956}
     957    function bp_displayed_user_id() {
     958        return bp_current_user_id();
     959    }
     960
     961function bp_loggedin_user_id() {
     962    global $bp;
     963    return apply_filters( 'bp_loggedin_user_id', $bp->loggedin_user->id );
     964}
     965
     966function bp_displayed_user_domain() {
     967    global $bp;
     968    return apply_filters( 'bp_displayed_user_domain', $bp->displayed_user->domain );
     969}
     970
     971function bp_loggedin_user_domain() {
     972    global $bp;
     973    return apply_filters( 'bp_loggedin_user_domain', $bp->loggedin_user->domain );
     974}
    656975
    657976function bp_user_fullname() {
     
    659978    echo apply_filters( 'bp_user_fullname', $bp->displayed_user->fullname );
    660979}
    661 
    662 
     980    function bp_displayed_user_fullname() {
     981        return bp_user_fullname();
     982    }
     983
     984function bp_loggedin_user_fullname() {
     985    global $bp;
     986    echo apply_filters( 'bp_loggedin_user_fullname', $bp->loggedin_user->fullname );   
     987}
    663988
    664989?>
Note: See TracChangeset for help on using the changeset viewer.