Skip to:
Content

BuddyPress.org

Ticket #5397: 5397.diff

File 5397.diff, 12.4 KB (added by imath, 8 years ago)
  • bp-activity/bp-activity-classes.php

     
    12011201
    12021202                return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) );
    12031203        }
     1204
     1205        /**
     1206         * Get activities count detailled by types
     1207         *
     1208         * @param int $user_id The ID of the user.
     1209         * @return array the stats
     1210         */
     1211        public static function get_count_by_type( $user_id = '' ) {
     1212                global $wpdb;
     1213
     1214                $activity_stats = array();
     1215                $total_activity = 0;
     1216
     1217                if ( empty( $user_id ) )
     1218                        return $activity_stats;
     1219
     1220                $activity_table = buddypress()->activity->table_name;
     1221
     1222                $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 );
     1223               
     1224                foreach ( $activity_stats as $activity_type ) {
     1225                        $total_activity += absint( $activity_type->sub_total );
     1226                }
     1227
     1228                return array( 'types' => $activity_stats, 'total' => $total_activity );
     1229        }
    12041230}
    12051231
    12061232/**
  • bp-activity/bp-activity-functions.php

     
    18121812function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
    18131813        bp_activity_update_meta( $id, $cachekey, $cache );
    18141814}
     1815
     1816/**
     1817 * Builds Activity stats by types
     1818 *
     1819 * If no types are set, defaults to total activities
     1820 *
     1821 * @since BuddyPress (?)
     1822 *
     1823 * @param  integer $user_id
     1824 * @param  boolean $hide_empty should we display empty types ?
     1825 * @param  array $types list of available types
     1826 * @return array activity stats
     1827 */
     1828function bp_activity_get_count_by_type( $user_id = 0, $hide_empty = false, $types = array() ) {
     1829        $activity_stats = BP_Activity_Activity::get_count_by_type( $user_id );
     1830
     1831        // no activity returns 0
     1832        if ( empty( $activity_stats ) )
     1833                return array( 'total' => 0 );
     1834
     1835        // no types retuns total of activities
     1836        if ( empty( $types ) ) {
     1837                unset( $activity_stats['types'] );
     1838                return $activity_stats;
     1839        }
     1840
     1841        $types_stats_ordered = array();
     1842
     1843        // fill the array with 0 value for each type
     1844        if( empty( $hide_empty ) )
     1845                $types_stats_ordered = array_fill_keys( array_keys( $types ), 0 );
     1846
     1847        // fill the type the user added activities in
     1848        foreach( $types as $key => $type ) {
     1849                if( ! empty( $activity_stats['types'][ $key ] ) ) {
     1850                        $types_stats_ordered[ $key ] = $activity_stats['types'][ $key ]->sub_total;
     1851                }
     1852        }
     1853
     1854        // Most used type first
     1855        arsort( $types_stats_ordered );
     1856       
     1857        // keep only types the user added activities in
     1858        if( ! empty( $hide_empty ) )
     1859                $types = array_intersect_key( $types, $types_stats_ordered );
     1860
     1861        // We need to merge "human" description for types
     1862        $activity_stats['types'] = array_merge_recursive( $types_stats_ordered, $types );
     1863       
     1864        return $activity_stats;
     1865}
  • bp-activity/bp-activity-template.php

     
    32653265<?php
    32663266}
    32673267add_action( 'bp_head', 'bp_activity_sitewide_feed' );
     3268
     3269
     3270/** Stats **********************************************************************/
     3271
     3272/**
     3273 * Display the number of activities by type in user's profile.
     3274 *
     3275 * @since BuddyPress (?)
     3276 *
     3277 * @param array $args before|after|user_id
     3278 * @uses bp_activity_get_profile_stats() to get the stats
     3279 */
     3280function bp_activity_profile_stats( $args = '' ) {
     3281        echo bp_activity_get_profile_stats( $args );
     3282}
     3283add_action( 'bp_members_admin_user_stats', 'bp_activity_profile_stats', 10, 1 );
     3284
     3285/**
     3286 * Return the number of activities by type in user's profile.
     3287 *
     3288 * @since BuddyPress (?)
     3289 *
     3290 * @param array $args before|after|user_id|types|hide_empty
     3291 * @return string HTML for stats output.
     3292 */
     3293function bp_activity_get_profile_stats( $args = '' ) {
     3294
     3295        // Parse the args
     3296        $r = bp_parse_args( $args, array(
     3297                'before'     => '<li class="bp-activity-profile-stats">',
     3298                'after'      => '</li>',
     3299                'user_id'    => bp_displayed_user_id(),
     3300                'types'      => bp_activity_get_types(),
     3301                'hide_empty' => true,
     3302                'output'     => ''
     3303        ), 'activity_get_profile_stats' );
     3304
     3305        // Allow completely overloaded output
     3306        if ( empty( $r['output'] ) ) {
     3307
     3308                // Only proceed if a user ID was passed
     3309                if ( ! empty( $r['user_id'] ) ) {
     3310
     3311                        // Get the user activities count by type
     3312                        $activity_stats = bp_activity_get_count_by_type( $r['user_id'], $r['hide_empty'], $r['types'] );
     3313                        $total_activities = absint( $activity_stats['total'] );
     3314
     3315                        $r['output'] = $r['before'] . sprintf( _n( '%s activity', '%s activities', $total_activities, 'buddypress' ), '<strong>'. $total_activities .'</strong>' );
     3316
     3317                        // If types exist, show some detailed output
     3318                        if ( ! empty( $activity_stats['types'] ) ) {
     3319                                $r['output'] .= '<ol>';
     3320
     3321                                foreach ( $activity_stats['types'] as $type ) {
     3322                                        $r['output'] .= '<li>' . esc_html( $type[1] ) . ': ' . absint( $type[0] ) .'</li>';
     3323                                }
     3324
     3325                                $r['output'] .= '</ol>';
     3326                        }
     3327
     3328                        $r['output'] .= $r['after'];
     3329                }
     3330        }
     3331
     3332        // Filter and return
     3333        return apply_filters( 'bp_activity_get_profile_stats', $r['output'], $r );
     3334}
  • bp-members/admin/css/admin.css

     
    6060div#community-profile-page li.bp-friends-profile-stats:before,
    6161div#community-profile-page li.bp-groups-profile-stats:before,
    6262div#community-profile-page li.bp-blogs-profile-stats:before,
     63div#community-profile-page li.bp-activity-profile-stats:before,
    6364div#community-profile-page a.bp-xprofile-avatar-user-admin:before {
    6465        font-family: 'dashicons';
    6566        font-size: 18px;
     
    8384        content: "\f120";
    8485}
    8586
     87div#community-profile-page li.bp-activity-profile-stats:before {
     88        content:"\f452";
     89}
     90
     91div#community-profile-page li.bp-activity-profile-stats ol li {
     92        font-size:80%;
     93        margin-bottom:0;
     94}
     95
    8696div#community-profile-page a.bp-xprofile-avatar-user-admin:before {
    8797        content:"\f182";
    8898}
  • bp-members/admin/css/admin.min.css

     
    1 div#profile-page.wrap form#your-profile{position:relative}div#profile-page.wrap form#your-profile h3:first-of-type{margin-top:6em}div#profile-page.wrap form#your-profile ul#profile-nav{position:absolute;top:-6em;border-bottom:solid 1px #ccc;width:100%}div#community-profile-page h2:first-of-type{margin-bottom:1em}div#community-profile-page h2.profile-section{border-bottom:dotted 1px #ccc}div#community-profile-page ul#profile-nav{border-bottom:solid 1px #ccc;width:100%;margin-top:1em;margin-bottom:1em;padding:1em 0;padding-bottom:0;height:2.4em}div#community-profile-page ul#profile-nav li,form#your-profile ul#profile-nav li{margin-left:.4em;float:left;font-weight:700;font-size:15px;line-height:24px}div#community-profile-page ul#profile-nav li a,form#your-profile ul#profile-nav li a{text-decoration:none;color:#888}div#community-profile-page ul#profile-nav li a:hover,div#community-profile-page ul#profile-nav li.nav-tab-active a,form#your-profile ul#profile-nav li a:hover,form#your-profile ul#profile-nav li.nav-tab-active a{text-decoration:none;color:#000}div#community-profile-page a.bp-xprofile-avatar-user-admin:before,div#community-profile-page li.bp-blogs-profile-stats:before,div#community-profile-page li.bp-friends-profile-stats:before,div#community-profile-page li.bp-groups-profile-stats:before,div#community-profile-page li.bp-members-profile-stats:before{font-family:dashicons;font-size:18px;vertical-align:bottom;margin-right:5px}div#community-profile-page li.bp-members-profile-stats:before{content:"\f130"}div#community-profile-page li.bp-friends-profile-stats:before{content:"\f454"}div#community-profile-page li.bp-groups-profile-stats:before{content:"\f456"}div#community-profile-page li.bp-blogs-profile-stats:before{content:"\f120"}div#community-profile-page a.bp-xprofile-avatar-user-admin:before{content:"\f182"}div#community-profile-page div#bp_xprofile_user_admin_avatar div.avatar{width:150px;margin:0 auto}div#community-profile-page div#bp_xprofile_user_admin_avatar a{display:block;margin:1em 0;text-decoration:none;color:#888}div#community-profile-page p.not-activated{margin:1em 1em 0;color:red}div#community-profile-page .form-table td.admin-field-visibility-td{padding:5px 5px 15px}div#community-profile-page .form-table tr.admin-field-visibility-tr{border-bottom:dotted 1px #ccc}div#community-profile-page .form-table tr.admin-field-visibility-tr:last-child{border:0}div#community-profile-page .field-visibility-settings legend,div#community-profile-page .field-visibility-settings-notoggle{font-size:14px;font-style:italic;color:#666}div#community-profile-page .field-visibility-settings ul{margin:0;font-size:13px}div#community-profile-page .field-visibility-settings ul li{display:inline-block;margin-right:1em}div#community-profile-page .form-table td.admin-field-checkbox label,div#community-profile-page .form-table td.admin-field-radio label{display:block}
    2  No newline at end of file
     1div#profile-page.wrap form#your-profile{position:relative}div#profile-page.wrap form#your-profile h3:first-of-type{margin-top:6em}div#profile-page.wrap form#your-profile ul#profile-nav{position:absolute;top:-6em;border-bottom:solid 1px #ccc;width:100%}div#community-profile-page h2:first-of-type{margin-bottom:1em}div#community-profile-page h2.profile-section{border-bottom:dotted 1px #ccc}div#community-profile-page ul#profile-nav{border-bottom:solid 1px #ccc;width:100%;margin-top:1em;margin-bottom:1em;padding:1em 0;padding-bottom:0;height:2.4em}div#community-profile-page ul#profile-nav li,form#your-profile ul#profile-nav li{margin-left:.4em;float:left;font-weight:700;font-size:15px;line-height:24px}div#community-profile-page ul#profile-nav li a,form#your-profile ul#profile-nav li a{text-decoration:none;color:#888}div#community-profile-page ul#profile-nav li a:hover,div#community-profile-page ul#profile-nav li.nav-tab-active a,form#your-profile ul#profile-nav li a:hover,form#your-profile ul#profile-nav li.nav-tab-active a{text-decoration:none;color:#000}div#community-profile-page a.bp-xprofile-avatar-user-admin:before,div#community-profile-page li.bp-activity-profile-stats:before,div#community-profile-page li.bp-blogs-profile-stats:before,div#community-profile-page li.bp-friends-profile-stats:before,div#community-profile-page li.bp-groups-profile-stats:before,div#community-profile-page li.bp-members-profile-stats:before{font-family:dashicons;font-size:18px;vertical-align:bottom;margin-right:5px}div#community-profile-page li.bp-members-profile-stats:before{content:"\f130"}div#community-profile-page li.bp-friends-profile-stats:before{content:"\f454"}div#community-profile-page li.bp-groups-profile-stats:before{content:"\f456"}div#community-profile-page li.bp-blogs-profile-stats:before{content:"\f120"}div#community-profile-page li.bp-activity-profile-stats:before{content:"\f452"}div#community-profile-page li.bp-activity-profile-stats ol li{font-size:80%;margin-bottom:0}div#community-profile-page a.bp-xprofile-avatar-user-admin:before{content:"\f182"}div#community-profile-page div#bp_xprofile_user_admin_avatar div.avatar{width:150px;margin:0 auto}div#community-profile-page div#bp_xprofile_user_admin_avatar a{display:block;margin:1em 0;text-decoration:none;color:#888}div#community-profile-page p.not-activated{margin:1em 1em 0;color:red}div#community-profile-page .form-table td.admin-field-visibility-td{padding:5px 5px 15px}div#community-profile-page .form-table tr.admin-field-visibility-tr{border-bottom:dotted 1px #ccc}div#community-profile-page .form-table tr.admin-field-visibility-tr:last-child{border:0}div#community-profile-page .field-visibility-settings legend,div#community-profile-page .field-visibility-settings-notoggle{font-size:14px;font-style:italic;color:#666}div#community-profile-page .field-visibility-settings ul{margin:0;font-size:13px}div#community-profile-page .field-visibility-settings ul li{display:inline-block;margin-right:1em}div#community-profile-page .form-table td.admin-field-checkbox label,div#community-profile-page .form-table td.admin-field-radio label{display:block}
     2 No newline at end of file