bb_bozo_recount_topics

The BuddyPress bb bozo recount topics function.

Description

bb_bozo_recount_topics(); 

Usage

  1. if ( !function_exists( 'bb_bozo_recount_topics' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-plugins/bozo.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bb_bozo_recount_topics(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-plugins/bozo.php  
  1. function bb_bozo_recount_topics() { 
  2. global $bbdb; 
  3. global $messages; 
  4. if ( isset($_POST['topic-bozo-posts']) && 1 == $_POST['topic-bozo-posts'] ): 
  5. $old = (array) $bbdb->get_col("SELECT object_id FROM $bbdb->meta WHERE object_type = 'bb_topic' AND meta_key = 'bozos'"); 
  6. $old = array_flip($old); 
  7. $messages[] = __('Counted the number of bozo posts in each topic'); 
  8. if ( $topics = (array) $bbdb->get_col("SELECT topic_id, poster_id, COUNT(post_id) FROM $bbdb->posts WHERE post_status > 1 GROUP BY topic_id, poster_id") ) : 
  9. $unique_topics = array_unique($topics); 
  10. $posters = (array) $bbdb->get_col('', 1); 
  11. $counts = (array) $bbdb->get_col('', 2); 
  12. foreach ($unique_topics as $i): 
  13. $bozos = array(); 
  14. $indices = array_keys($topics, $i); 
  15. foreach ( $indices as $index ) 
  16. $bozos[(int) $posters[$index]] = (int) $counts[$index];  
  17. if ( $bozos ) : 
  18. bb_update_topicmeta( $i, 'bozos', $bozos ); 
  19. unset($indices, $index, $old[$i]); 
  20. endif; 
  21. endforeach; 
  22. unset($topics, $i, $counts, $posters, $bozos); 
  23. endif; 
  24. if ( $old ) : 
  25. $old = join(', ', array_map('intval', array_flip($old))); 
  26. $bbdb->query("DELETE FROM $bbdb->meta WHERE object_type = 'bb_topic' AND object_id IN ($old) AND meta_key = 'bozos'"); 
  27. endif; 
  28. endif;