bb_bozo_recount_topics
The BuddyPress bb bozo recount topics function.
Description
bb_bozo_recount_topics();
Usage
if ( !function_exists( 'bb_bozo_recount_topics' ) ) { require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-plugins/bozo.php'; } // NOTICE! Understand what this does before running. $result = bb_bozo_recount_topics();
Defined (1)
The function is defined in the following location(s).
- /bp-forums/bbpress/bb-plugins/bozo.php
- function bb_bozo_recount_topics() {
- global $bbdb;
- global $messages;
- if ( isset($_POST['topic-bozo-posts']) && 1 == $_POST['topic-bozo-posts'] ):
- $old = (array) $bbdb->get_col("SELECT object_id FROM $bbdb->meta WHERE object_type = 'bb_topic' AND meta_key = 'bozos'");
- $old = array_flip($old);
- $messages[] = __('Counted the number of bozo posts in each topic');
- 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") ) :
- $unique_topics = array_unique($topics);
- $posters = (array) $bbdb->get_col('', 1);
- $counts = (array) $bbdb->get_col('', 2);
- foreach ($unique_topics as $i):
- $bozos = array();
- $indices = array_keys($topics, $i);
- foreach ( $indices as $index )
- $bozos[(int) $posters[$index]] = (int) $counts[$index];
- if ( $bozos ) :
- bb_update_topicmeta( $i, 'bozos', $bozos );
- unset($indices, $index, $old[$i]);
- endif;
- endforeach;
- unset($topics, $i, $counts, $posters, $bozos);
- endif;
- if ( $old ) :
- $old = join(', ', array_map('intval', array_flip($old)));
- $bbdb->query("DELETE FROM $bbdb->meta WHERE object_type = 'bb_topic' AND object_id IN ($old) AND meta_key = 'bozos'");
- endif;
- endif;
- }