Ticket #5397: 5397.03.patch
| File 5397.03.patch, 7.4 KB (added by , 11 years ago) |
|---|
-
src/bp-activity/bp-activity-cache.php
diff --git src/bp-activity/bp-activity-cache.php src/bp-activity/bp-activity-cache.php index 36d8805..bf4040e 100644
function bp_activity_update_meta_cache( $activity_ids = false ) { 43 43 */ 44 44 function bp_activity_clear_cache_for_activity( $activity ) { 45 45 wp_cache_delete( $activity->id, 'bp_activity' ); 46 wp_cache_delete( $activity->user_id, 'bp_activity_user_stats' ); 46 47 } 47 48 add_action( 'bp_activity_after_save', 'bp_activity_clear_cache_for_activity' ); 48 49 -
src/bp-activity/bp-activity-classes.php
diff --git src/bp-activity/bp-activity-classes.php src/bp-activity/bp-activity-classes.php index 90aa677..2fcdc5a 100644
class BP_Activity_Activity { 1498 1498 1499 1499 return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) ); 1500 1500 } 1501 1502 /** 1503 * Get activities count detailled by types 1504 * 1505 * @param int $user_id The ID of the user. 1506 * @return array the stats 1507 */ 1508 public static function get_count_by_type( $user_id = '' ) { 1509 global $wpdb; 1510 1511 $activity_stats = array(); 1512 $total_activity = 0; 1513 1514 if ( empty( $user_id ) ) { 1515 return $activity_stats; 1516 } 1517 1518 $stats = wp_cache_get( $user_id, 'bp_activity_user_stats' ); 1519 1520 if ( ! empty( $stats ) ) { 1521 return $stats; 1522 } 1523 1524 $activity_table = buddypress()->activity->table_name; 1525 1526 $activity_stats = $wpdb->get_results( $wpdb->prepare( "SELECT type, COUNT(*) as sub_total FROM {$activity_table} WHERE user_id = %d AND type != 'last_activity' GROUP BY type ORDER BY type ASC", $user_id ), OBJECT_K ); 1527 1528 foreach ( $activity_stats as $activity_type ) { 1529 $total_activity += absint( $activity_type->sub_total ); 1530 } 1531 1532 $stats = array( 'types' => $activity_stats, 'total' => $total_activity ); 1533 1534 // Set user stats cache 1535 wp_cache_set( $user_id, $stats, 'bp_activity_user_stats' ); 1536 1537 return $stats; 1538 } 1501 1539 } 1502 1540 1503 1541 /** -
src/bp-activity/bp-activity-functions.php
diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php index 5689c34..efe80af 100644
function bp_activity_delete( $args = '' ) { 2234 2234 } 2235 2235 } 2236 2236 2237 // Clear user stats cache 2238 wp_cache_delete( $user_id, 'bp_activity_user_stats' ); 2239 2237 2240 /** 2238 2241 * Fires after the activity item has been deleted. 2239 2242 * … … function bp_activity_do_heartbeat() { 2874 2877 2875 2878 return $retval; 2876 2879 } 2880 2881 /** 2882 * Builds Activity stats by types 2883 * 2884 * If no types are set, defaults to total activities 2885 * 2886 * @since BuddyPress (?) 2887 * 2888 * @param integer $user_id 2889 * @param boolean $hide_empty should we display empty types ? 2890 * @param array $types list of available types 2891 * @return array activity stats 2892 */ 2893 function bp_activity_get_count_by_type( $user_id = 0, $hide_empty = false, $types = array() ) { 2894 $activity_stats = BP_Activity_Activity::get_count_by_type( $user_id ); 2895 2896 // no activity returns 0 2897 if ( empty( $activity_stats ) ) { 2898 return array( 'total' => 0 ); 2899 } 2900 2901 // no types retuns total of activities 2902 if ( empty( $types ) ) { 2903 unset( $activity_stats['types'] ); 2904 return $activity_stats; 2905 } 2906 2907 $types_stats_ordered = array(); 2908 2909 // fill the array with 0 value for each type 2910 if( empty( $hide_empty ) ) { 2911 $types_stats_ordered = array_fill_keys( array_keys( $types ), 0 ); 2912 } 2913 2914 // fill the type the user added activities in 2915 foreach( $types as $key => $type ) { 2916 if( ! empty( $activity_stats['types'][ $key ] ) ) { 2917 $types_stats_ordered[ $key ] = $activity_stats['types'][ $key ]->sub_total; 2918 } 2919 } 2920 2921 // Most used type first 2922 arsort( $types_stats_ordered ); 2923 2924 // keep only types the user added activities in 2925 if( ! empty( $hide_empty ) ) { 2926 $types = array_intersect_key( $types, $types_stats_ordered ); 2927 } 2928 2929 // We need to merge "human" description for types 2930 $activity_stats['types'] = array_merge_recursive( $types_stats_ordered, $types ); 2931 2932 return $activity_stats; 2933 } -
src/bp-activity/bp-activity-template.php
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php index d33d1f3..720df1d 100644
function bp_activity_show_filters( $context = '' ) { 4423 4423 */ 4424 4424 return apply_filters( 'bp_get_activity_show_filters', $output, $filters, $context ); 4425 4425 } 4426 4427 /** Stats **********************************************************************/ 4428 4429 /** 4430 * Display the number of activities by type in user's profile. 4431 * 4432 * @since BuddyPress (?) 4433 * 4434 * @param array $args before|after|user_id 4435 * @uses bp_activity_get_profile_stats() to get the stats 4436 */ 4437 function bp_activity_profile_stats( $args = '' ) { 4438 echo bp_activity_get_profile_stats( $args ); 4439 } 4440 add_action( 'bp_members_admin_user_stats', 'bp_activity_profile_stats', 10, 1 ); 4441 4442 /** 4443 * Return the number of activities by type in user's profile. 4444 * 4445 * @since BuddyPress (?) 4446 * 4447 * @param array $args before|after|user_id|types|hide_empty 4448 * @return string HTML for stats output. 4449 */ 4450 function bp_activity_get_profile_stats( $args = '' ) { 4451 4452 // Parse the args 4453 $r = bp_parse_args( $args, array( 4454 'before' => '<li class="bp-activity-profile-stats">', 4455 'after' => '</li>', 4456 'user_id' => bp_displayed_user_id(), 4457 'types' => bp_activity_get_types(), 4458 'hide_empty' => true, 4459 'output' => '' 4460 ), 'activity_get_profile_stats' ); 4461 4462 // Allow completely overloaded output 4463 if ( empty( $r['output'] ) ) { 4464 4465 // Only proceed if a user ID was passed 4466 if ( ! empty( $r['user_id'] ) ) { 4467 4468 // Get the user activities count by type 4469 $activity_stats = bp_activity_get_count_by_type( $r['user_id'], $r['hide_empty'], $r['types'] ); 4470 $total_activities = absint( $activity_stats['total'] ); 4471 4472 $r['output'] = $r['before'] . sprintf( _n( '%s activity', '%s activities', $total_activities, 'buddypress' ), '<strong>'. $total_activities .'</strong>' ); 4473 4474 // If types exist, show some detailed output 4475 if ( ! empty( $activity_stats['types'] ) ) { 4476 $r['output'] .= '<ol>'; 4477 4478 foreach ( $activity_stats['types'] as $type ) { 4479 $r['output'] .= '<li>' . esc_html( $type[1] ) . ': ' . absint( $type[0] ) .'</li>'; 4480 } 4481 4482 $r['output'] .= '</ol>'; 4483 } 4484 4485 $r['output'] .= $r['after']; 4486 } 4487 } 4488 4489 // Filter and return 4490 return apply_filters( 'bp_activity_get_profile_stats', $r['output'], $r ); 4491 } -
src/bp-members/admin/css/admin.css
diff --git src/bp-members/admin/css/admin.css src/bp-members/admin/css/admin.css index e4599f7..a6ba29c 100644
div#community-profile-page li.bp-members-profile-stats:before, 25 25 div#community-profile-page li.bp-friends-profile-stats:before, 26 26 div#community-profile-page li.bp-groups-profile-stats:before, 27 27 div#community-profile-page li.bp-blogs-profile-stats:before, 28 div#community-profile-page li.bp-activity-profile-stats:before, 28 29 div#community-profile-page a.bp-xprofile-avatar-user-admin:before { 29 30 font: normal 20px/1 'dashicons'; 30 31 speak: none; … … div#community-profile-page a.bp-xprofile-avatar-user-admin:before { 60 61 content:"\f182"; 61 62 } 62 63 64 div#community-profile-page li.bp-activity-profile-stats:before { 65 content:"\f452"; 66 } 67 68 div#community-profile-page li.bp-activity-profile-stats ol li { 69 font-size:80%; 70 margin-bottom:0; 71 } 72 63 73 div#community-profile-page div#bp_xprofile_user_admin_avatar div.avatar { 64 74 width:150px; 65 75 margin:0 auto;