Ticket #5397: 5397.02.patch
| File 5397.02.patch, 6.4 KB (added by , 11 years ago) |
|---|
-
src/bp-activity/bp-activity-classes.php
diff --git src/bp-activity/bp-activity-classes.php src/bp-activity/bp-activity-classes.php index 66605fb..fbeb9a4 100644
class BP_Activity_Activity { 1340 1340 1341 1341 return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) ); 1342 1342 } 1343 1344 /** 1345 * Get activities count detailled by types 1346 * 1347 * @param int $user_id The ID of the user. 1348 * @return array the stats 1349 */ 1350 public static function get_count_by_type( $user_id = '' ) { 1351 global $wpdb; 1352 1353 $activity_stats = array(); 1354 $total_activity = 0; 1355 1356 if ( empty( $user_id ) ) { 1357 return $activity_stats; 1358 } 1359 1360 $activity_table = buddypress()->activity->table_name; 1361 1362 $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 ); 1363 1364 foreach ( $activity_stats as $activity_type ) { 1365 $total_activity += absint( $activity_type->sub_total ); 1366 } 1367 1368 return array( 'types' => $activity_stats, 'total' => $total_activity ); 1369 } 1343 1370 } 1344 1371 1345 1372 /** -
src/bp-activity/bp-activity-functions.php
diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php index 980aa5e..46342d2 100644
function bp_activity_do_heartbeat() { 1952 1952 1953 1953 return $retval; 1954 1954 } 1955 1956 /** 1957 * Builds Activity stats by types 1958 * 1959 * If no types are set, defaults to total activities 1960 * 1961 * @since BuddyPress (?) 1962 * 1963 * @param integer $user_id 1964 * @param boolean $hide_empty should we display empty types ? 1965 * @param array $types list of available types 1966 * @return array activity stats 1967 */ 1968 function bp_activity_get_count_by_type( $user_id = 0, $hide_empty = false, $types = array() ) { 1969 $activity_stats = BP_Activity_Activity::get_count_by_type( $user_id ); 1970 1971 // no activity returns 0 1972 if ( empty( $activity_stats ) ) { 1973 return array( 'total' => 0 ); 1974 } 1975 1976 // no types retuns total of activities 1977 if ( empty( $types ) ) { 1978 unset( $activity_stats['types'] ); 1979 return $activity_stats; 1980 } 1981 1982 $types_stats_ordered = array(); 1983 1984 // fill the array with 0 value for each type 1985 if( empty( $hide_empty ) ) { 1986 $types_stats_ordered = array_fill_keys( array_keys( $types ), 0 ); 1987 } 1988 1989 // fill the type the user added activities in 1990 foreach( $types as $key => $type ) { 1991 if( ! empty( $activity_stats['types'][ $key ] ) ) { 1992 $types_stats_ordered[ $key ] = $activity_stats['types'][ $key ]->sub_total; 1993 } 1994 } 1995 1996 // Most used type first 1997 arsort( $types_stats_ordered ); 1998 1999 // keep only types the user added activities in 2000 if( ! empty( $hide_empty ) ) { 2001 $types = array_intersect_key( $types, $types_stats_ordered ); 2002 } 2003 2004 // We need to merge "human" description for types 2005 $activity_stats['types'] = array_merge_recursive( $types_stats_ordered, $types ); 2006 2007 return $activity_stats; 2008 } -
src/bp-activity/bp-activity-template.php
diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php index cd0c279..3667592 100644
function bp_activity_show_filters( $context = '' ) { 3497 3497 3498 3498 return apply_filters( 'bp_get_activity_show_filters', $output, $filters, $context ); 3499 3499 } 3500 3501 /** Stats **********************************************************************/ 3502 3503 /** 3504 * Display the number of activities by type in user's profile. 3505 * 3506 * @since BuddyPress (?) 3507 * 3508 * @param array $args before|after|user_id 3509 * @uses bp_activity_get_profile_stats() to get the stats 3510 */ 3511 function bp_activity_profile_stats( $args = '' ) { 3512 echo bp_activity_get_profile_stats( $args ); 3513 } 3514 add_action( 'bp_members_admin_user_stats', 'bp_activity_profile_stats', 10, 1 ); 3515 3516 /** 3517 * Return the number of activities by type in user's profile. 3518 * 3519 * @since BuddyPress (?) 3520 * 3521 * @param array $args before|after|user_id|types|hide_empty 3522 * @return string HTML for stats output. 3523 */ 3524 function bp_activity_get_profile_stats( $args = '' ) { 3525 3526 // Parse the args 3527 $r = bp_parse_args( $args, array( 3528 'before' => '<li class="bp-activity-profile-stats">', 3529 'after' => '</li>', 3530 'user_id' => bp_displayed_user_id(), 3531 'types' => bp_activity_get_types(), 3532 'hide_empty' => true, 3533 'output' => '' 3534 ), 'activity_get_profile_stats' ); 3535 3536 // Allow completely overloaded output 3537 if ( empty( $r['output'] ) ) { 3538 3539 // Only proceed if a user ID was passed 3540 if ( ! empty( $r['user_id'] ) ) { 3541 3542 // Get the user activities count by type 3543 $activity_stats = bp_activity_get_count_by_type( $r['user_id'], $r['hide_empty'], $r['types'] ); 3544 $total_activities = absint( $activity_stats['total'] ); 3545 3546 $r['output'] = $r['before'] . sprintf( _n( '%s activity', '%s activities', $total_activities, 'buddypress' ), '<strong>'. $total_activities .'</strong>' ); 3547 3548 // If types exist, show some detailed output 3549 if ( ! empty( $activity_stats['types'] ) ) { 3550 $r['output'] .= '<ol>'; 3551 3552 foreach ( $activity_stats['types'] as $type ) { 3553 $r['output'] .= '<li>' . esc_html( $type[1] ) . ': ' . absint( $type[0] ) .'</li>'; 3554 } 3555 3556 $r['output'] .= '</ol>'; 3557 } 3558 3559 $r['output'] .= $r['after']; 3560 } 3561 } 3562 3563 // Filter and return 3564 return apply_filters( 'bp_activity_get_profile_stats', $r['output'], $r ); 3565 } -
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;