Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/27/2011 03:57:16 PM (16 years ago)
Author:
johnjamesjacoby
Message:

Break BuddyBar parts up into their individual components and out of bp-core.

File:
1 edited

Legend:

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

    r3951 r3952  
    11<?php
    2 
    32
    43/**
     
    294293
    295294function bp_core_admin_bar() {
    296         global $bp, $wpdb, $current_blog;
     295        global $bp;
    297296
    298297        if ( defined( 'BP_DISABLE_ADMIN_BAR' ) )
     
    324323        global $bp;
    325324
    326         echo '<a href="' . $bp->root_domain . '" id="admin-bar-logo">' . get_blog_option( BP_ROOT_BLOG, 'blogname') . '</a>';
     325        echo '<a href="' . $bp->root_domain . '" id="admin-bar-logo">' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '</a>';
    327326}
    328327
     
    350349
    351350        echo '<li id="bp-adminbar-account-menu"><a href="' . bp_loggedin_user_domain() . '">';
    352 
    353351        echo __( 'My Account', 'buddypress' ) . '</a>';
    354352        echo '<ul>';
     
    398396}
    399397
    400 // *** "My Blogs" Menu ********
    401 function bp_adminbar_blogs_menu() {
    402         global $bp;
    403 
    404         if ( !is_user_logged_in() || !bp_is_active( 'blogs' ) )
    405                 return false;
    406 
    407         if ( !is_multisite() )
    408                 return false;
    409 
    410         if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', 'bp' ) ) {
    411                 $blogs = bp_blogs_get_blogs_for_user( $bp->loggedin_user->id, true );
    412                 wp_cache_set( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', $blogs, 'bp' );
    413         }
    414 
    415         $counter = 0;
    416         if ( is_array( $blogs['blogs'] ) && (int)$blogs['count'] ) {
    417 
    418                 echo '<li id="bp-adminbar-blogs-menu"><a href="' . trailingslashit( $bp->loggedin_user->domain . $bp->blogs->slug ) . '">';
    419 
    420                 _e( 'My Blogs', 'buddypress' );
    421 
    422                 echo '</a>';
    423                 echo '<ul>';
    424 
    425                 foreach ( (array)$blogs['blogs'] as $blog ) {
    426                         $alt      = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
    427                         $site_url = esc_attr( $blog->siteurl );
    428 
    429                         echo '<li' . $alt . '>';
    430                         echo '<a href="' . $site_url . '">' . esc_html( $blog->name ) . '</a>';
    431                         echo '<ul>';
    432                         echo '<li class="alt"><a href="' . $site_url . 'wp-admin/">' . __( 'Dashboard', 'buddypress' ) . '</a></li>';
    433                         echo '<li><a href="' . $site_url . 'wp-admin/post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>';
    434                         echo '<li class="alt"><a href="' . $site_url . 'wp-admin/edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>';
    435                         echo '<li><a href="' . $site_url . 'wp-admin/edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>';
    436                         echo '</ul>';
    437 
    438                         do_action( 'bp_adminbar_blog_items', $blog );
    439 
    440                         echo '</li>';
    441                         $counter++;
    442                 }
    443 
    444                 $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
    445 
    446                 if ( bp_blog_signup_enabled() ) {
    447                         echo '<li' . $alt . '>';
    448                         echo '<a href="' . $bp->root_domain . '/' . $bp->blogs->root_slug . '/create/">' . __( 'Create a Blog!', 'buddypress' ) . '</a>';
    449                         echo '</li>';
    450                 }
    451 
    452                 echo '</ul>';
    453                 echo '</li>';
    454         }
    455 }
    456 
    457398function bp_adminbar_thisblog_menu() {
    458399        if ( current_user_can( 'edit_posts' ) ) {
    459400                echo '<li id="bp-adminbar-thisblog-menu"><a href="' . admin_url() . '">';
    460 
    461401                _e( 'Dashboard', 'buddypress' );
    462 
    463402                echo '</a>';
    464403                echo '<ul>';
     
    475414}
    476415
    477 // **** "Notifications" Menu *********
    478 function bp_adminbar_notifications_menu() {
    479         global $bp;
    480 
    481         if ( !is_user_logged_in() )
    482                 return false;
    483 
    484         echo '<li id="bp-adminbar-notifications-menu"><a href="' . $bp->loggedin_user->domain . '">';
    485         _e( 'Notifications', 'buddypress' );
    486 
    487         if ( $notifications = bp_members_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?>
    488                 <span><?php echo count( $notifications ) ?></span>
    489         <?php
    490         }
    491 
    492         echo '</a>';
    493         echo '<ul>';
    494 
    495         if ( $notifications ) {
    496                 $counter = 0;
    497                 for ( $i = 0; $i < count($notifications); $i++ ) {
    498                         $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?>
    499 
    500                         <li<?php echo $alt ?>><?php echo $notifications[$i] ?></li>
    501 
    502                         <?php $counter++;
    503                 }
    504         } else { ?>
    505 
    506                 <li><a href="<?php echo $bp->loggedin_user->domain ?>"><?php _e( 'No new notifications.', 'buddypress' ); ?></a></li>
    507 
    508         <?php
    509         }
    510 
    511         echo '</ul>';
    512         echo '</li>';
    513 }
    514 
    515 // **** "Blog Authors" Menu (visible when not logged in) ********
    516 function bp_adminbar_authors_menu() {
    517         global $bp, $current_blog, $wpdb;
    518 
    519         // Only for multisite
    520         if ( !is_multisite() )
    521                 return false;
    522 
    523         // Hide on root blog
    524         if ( $current_blog->blog_id == BP_ROOT_BLOG || !bp_is_active( 'blogs' ) )
    525                 return false;
    526 
    527         $blog_prefix = $wpdb->get_blog_prefix( $current_blog->blog_id );
    528         $authors     = $wpdb->get_results( "SELECT user_id, user_login, user_nicename, display_name, user_email, meta_value as caps FROM $wpdb->users u, $wpdb->usermeta um WHERE u.ID = um.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY um.user_id" );
    529 
    530         if ( !empty( $authors ) ) {
    531                 // This is a blog, render a menu with links to all authors
    532                 echo '<li id="bp-adminbar-authors-menu"><a href="/">';
    533                 _e('Blog Authors', 'buddypress');
    534                 echo '</a>';
    535 
    536                 echo '<ul class="author-list">';
    537                 foreach( (array)$authors as $author ) {
    538                         $caps = maybe_unserialize( $author->caps );
    539                         if ( isset( $caps['subscriber'] ) || isset( $caps['contributor'] ) ) continue;
    540 
    541                         echo '<li>';
    542                         echo '<a href="' . bp_core_get_user_domain( $author->user_id, $author->user_nicename, $author->user_login ) . '">';
    543                         echo bp_core_fetch_avatar( array( 'item_id' => $author->user_id, 'email' => $author->user_email, 'width' => 15, 'height' => 15 ) ) ;
    544                         echo ' ' . $author->display_name . '</a>';
    545                         echo '<div class="admin-bar-clear"></div>';
    546                         echo '</li>';
    547                 }
    548                 echo '</ul>';
    549                 echo '</li>';
    550         }
    551 }
    552416
    553417// **** "Random" Menu (visible when not logged in) ********
     
    558422                <a href="#"><?php _e( 'Visit', 'buddypress' ) ?></a>
    559423                <ul class="random-list">
    560                         <li><a href="<?php echo $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/?random-member' ?>"><?php _e( 'Random Member', 'buddypress' ) ?></a></li>
     424                        <li><a href="<?php echo trailingslashit( $bp->root_domain . '/' . $bp->members->root_slug ) . '?random-member' ?>"><?php _e( 'Random Member', 'buddypress' ) ?></a></li>
    561425
    562426                        <?php if ( bp_is_active( 'groups' ) ) : ?>
    563427
    564                                 <li class="alt"><a href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/?random-group' ?>"><?php _e( 'Random Group', 'buddypress' ) ?></a></li>
     428                                <li class="alt"><a href="<?php echo trailingslashit( $bp->root_domain . '/' . $bp->groups->root_slug ) . '?random-group' ?>"><?php _e( 'Random Group', 'buddypress' ) ?></a></li>
    565429
    566430                        <?php endif; ?>
    567431
    568                         <?php if ( bp_is_active( 'blogs' ) && is_multisite() ) : ?>
    569 
    570                                 <li><a href="<?php echo $bp->root_domain . '/' . $bp->blogs->slug . '/?random-blog' ?>"><?php _e( 'Random Blog', 'buddypress' ) ?></a></li>
     432                        <?php if ( is_multisite() && bp_is_active( 'blogs' ) ) : ?>
     433
     434                                <li><a href="<?php echo trailingslashit( $bp->root_domain . '/' . $bp->blogs->root_slug ) . '?random-blog' ?>"><?php _e( 'Random Blog', 'buddypress' ) ?></a></li>
    571435
    572436                        <?php endif; ?>
     
    594458                add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu',         2   );
    595459                add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu',       4   );
    596                 add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu',         6   );
    597460                add_action( 'bp_adminbar_menus', 'bp_adminbar_thisblog_menu',      6   );
    598                 add_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8   );
    599                 add_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu',       12  );
    600461                add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu',        100 );
    601462
Note: See TracChangeset for help on using the changeset viewer.