Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

[Plugin: WP-Blacklister] [FEATURE REQUEST]

By: a guest on Apr 5th, 2012  |  syntax: PHP  |  size: 1.25 KB  |  views: 34  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }