Advertisement
Guest User

[Plugin: WP-Blacklister] [FEATURE REQUEST]

a guest
Apr 5th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. function aggComments( $spam_comments, $index_type, $remove_duplicates = 1, $hard_sort = 1, $display_counts = 1 ) {
  2.     $return_array = array();
  3.     foreach( $spam_comments as $spam_comment ) // for each spam comment
  4.         array_push( $return_array, trim( $spam_comment->$index_type ) ); // slice its data into new array
  5.     if( $display_counts ) {
  6.         $return_array_with_counts = array_count_values( $return_array );
  7.         $return_array = $ip_or_email = $count = array();
  8.         foreach( $return_array_with_counts as $key => $value ){
  9.             $ip_or_email[] = $key;
  10.             $count[] = $value;
  11.         }
  12.         array_multisort( $count, SORT_DESC, $ip_or_email, SORT_ASC, $return_array_with_counts ); //STABLE SORT THAT MAINTAINS THE ORIGINAL ORDER FOR ELEMENTS THAT HAVE EQUAL COUNTS
  13.         foreach( $return_array_with_counts as $key => $value )
  14.             if(!empty($key)) //SKIP ANY BLANK EMAIL ADDRESSES/URLS
  15.                 array_push( $return_array, $key . ' (' . $value . ')' );
  16.         return $return_array;
  17.     }
  18.     if( $remove_duplicates ) $return_array = array_flip( array_flip( array_reverse( $return_array, true ) ) ); // faster dedupe
  19.     if( $hard_sort ) sort( $return_array ); // hard (rekey) sort
  20.     return $return_array;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement