Skip to:
Content

BuddyPress.org

Ticket #5875: 5875.01.patch

File 5875.01.patch, 1.6 KB (added by r-a-y, 10 years ago)
  • src/bp-activity/bp-activity-functions.php

     
    11931193                'recorded_time'     => bp_core_current_time(), // The GMT time that this activity was recorded
    11941194                'hide_sitewide'     => false,                  // Should this be hidden on the sitewide activity stream?
    11951195                'is_spam'           => false,                  // Is this activity item to be marked as spam?
     1196                'throttle'                      => 0
    11961197        ) );
    11971198
    11981199        // Make sure we are backwards compatible
     
    12041205                $r['type'] = $r['component_action'];
    12051206        }
    12061207
     1208        // Check if a throttle time is required.
     1209        if ( $r['throttle'] > 0 ) {
     1210
     1211                // Throttle to one activity of this type per 2 hours
     1212                $existing = bp_activity_get( array(
     1213                        'max'    => 1,
     1214                        'filter' => array(
     1215                                'user_id' => $r['user_id']
     1216                                'object'  => $r['component'],
     1217                                'action'  => $r['action'],
     1218                        ),
     1219                ) );
     1220
     1221                // Default throttle time is 2 hours. Filter to change (in seconds)
     1222                if ( ! empty( $existing['activities'] ) ) {
     1223                        $throttle_period = apply_filters( 'bp_' . $r['component'] . '_' . $r['action'] . '_activity_throttle_time', HOUR_IN_SECONDS * 2 );
     1224                        $then            = strtotime( $existing['activities'][0]->date_recorded );
     1225                        $now             = strtotime( bp_core_current_time() );
     1226
     1227                        // Bail if throttled
     1228                        if ( ( $now - $then ) < $throttle_period ) {
     1229                                return false;
     1230                        }
     1231                }
     1232        }
     1233
    12071234        // Setup activity to be added
    12081235        $activity                    = new BP_Activity_Activity( $r['id'] );
    12091236        $activity->user_id           = $r['user_id'];