Skip to:
Content

BuddyPress.org

Ticket #2084: 2084-1.diff

File 2084-1.diff, 4.9 KB (added by boonebgorges, 14 years ago)
  • bp-activity.php

     
    524524}
    525525
    526526/**
     527 * bp_activity_total_mentions_for_user()
     528 *
     529 * Reduces new mention count for mentioned users when activity items are deleted
     530 *
     531 * @package BuddyPress Activity
     532 * @since 1.3
     533 *
     534 * @param $activity_id The unique id for the activity item
     535 */
     536function bp_activity_total_mentions_for_user( $user_id = false ) {
     537        global $bp;
     538
     539        if ( !$user_id )
     540                $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
     541
     542        if ( !$count = wp_cache_get( 'bp_total_mentions_for_user_' . $user_id, 'bp' ) ) {
     543                $count = BP_Activity_Activity::total_mention_count( $user_id );
     544                wp_cache_set( 'bp_total_mentions_for_user_' . $user_id, $count, 'bp' );
     545        }
     546
     547        return $count;
     548}
     549
     550/**
    527551 * bp_activity_reduce_mention_count()
    528552 *
    529553 * Reduces new mention count for mentioned users when activity items are deleted
  • bp-themes/bp-default/activity/index.php

     
    4747
    4848                                                <?php do_action( 'bp_before_activity_type_tab_mentions' ) ?>
    4949
    50                                                 <li id="activity-mentions"><a href="<?php echo bp_loggedin_user_domain() . BP_ACTIVITY_SLUG . '/mentions/' ?>" title="<?php _e( 'Activity that I have been mentioned in.', 'buddypress' ) ?>"><?php printf( __( '@%s Mentions', 'buddypress' ), bp_get_loggedin_user_username() ) ?><?php if ( bp_get_total_mention_count_for_user( bp_loggedin_user_id() ) ) : ?> <strong><?php printf( __( '(%s new)', 'buddypress' ), bp_get_total_mention_count_for_user( bp_loggedin_user_id() ) ) ?></strong><?php endif; ?></a></li>
    51 
     50                                                <?php if ( bp_get_total_mention_count_for_user( bp_loggedin_user_id() ) ) : ?>
     51                                                        <li id="activity-mentions"><a href="<?php echo bp_loggedin_user_domain() . BP_ACTIVITY_SLUG . '/mentions/' ?>" title="<?php _e( 'Activity that I have been mentioned in.', 'buddypress' ) ?>"><?php printf( __( '@%s Mentions', 'buddypress' ), bp_get_loggedin_user_username() ) ?><?php if ( bp_get_new_mention_count_for_user( bp_loggedin_user_id() ) ) : ?> <strong><?php printf( __( '(%s new)', 'buddypress' ), bp_get_new_mention_count_for_user( bp_loggedin_user_id() ) ) ?></strong><?php endif; ?></a></li>
     52                                                <?php endif; ?>
    5253                                        <?php endif; ?>
    5354
    5455                                        <?php do_action( 'bp_activity_type_tabs' ) ?>
  • bp-activity/bp-activity-templatetags.php

     
    952952                return apply_filters( 'bp_get_total_favorite_count_for_user', bp_activity_total_favorites_for_user( $user_id ) );
    953953        }
    954954
     955function bp_new_mention_count_for_user( $user_id = false ) {
     956        echo bp_get_new_favorite_count_for_user( $user_id );
     957}
     958        function bp_get_new_mention_count_for_user( $user_id = false ) {
     959                return apply_filters( 'bp_get_new_mention_count_for_user', get_user_meta( $user_id, 'bp_new_mention_count', true ) );
     960        }
     961
    955962function bp_total_mention_count_for_user( $user_id = false ) {
    956963        echo bp_get_total_favorite_count_for_user( $user_id );
    957964}
    958965        function bp_get_total_mention_count_for_user( $user_id = false ) {
    959                 return apply_filters( 'bp_get_total_mention_count_for_user', get_user_meta( $user_id, 'bp_new_mention_count', true ) );
     966                return apply_filters( 'bp_get_total_mention_count_for_user', bp_activity_total_mentions_for_user( $user_id ) );
    960967        }
    961968
    962969function bp_send_public_message_link() {
  • bp-activity/bp-activity-classes.php

     
    530530
    531531                return count( maybe_unserialize( $favorite_activity_entries ) );
    532532        }
     533       
     534        function total_mention_count( $user_id ) {
     535                global $bp, $wpdb;
     536               
     537                $user_nicename = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_nicename : $bp->loggedin_user->userdata->user_nicename;
     538                $user_login = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
     539                $search_terms = '@' . bp_core_get_username( $user_id, $user_nicename, $user_login ) . '<'; // Start search at @ symbol and stop search at closing tag delimiter.
     540               
     541                $search_terms = $wpdb->escape( $search_terms );
     542                $where_sql = "a.content LIKE '%%" . like_escape( $search_terms ) . "%%'";
     543               
     544                $total_mentions = $wpdb->get_var( $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a WHERE {$where_sql}" ) );               
     545               
     546                return $total_mentions;
     547        }
    533548
    534549        function check_exists_by_content( $content ) {
    535550                global $wpdb, $bp;