Exemple #1
0
     $messages[] = $message[1];
 }
 if (!empty($_POST['topics-replied'])) {
     $message = bb_recount_user_topics_replied();
     $messages[] = $message[1];
 }
 if (!empty($_POST['topic-tag-count'])) {
     $message = bb_recount_topic_tags();
     $messages[] = $message[1];
 }
 if (!empty($_POST['tags-tag-count'])) {
     $message = bb_recount_tag_topics();
     $messages[] = $message[1];
 }
 if (!empty($_POST['tags-delete-empty'])) {
     $message = bb_recount_tag_delete_empty();
     $messages[] = $message[1];
 }
 if (!empty($_POST['clean-favorites'])) {
     $message = bb_recount_clean_favorites();
     $messages[] = $message[1];
 }
 bb_recount_list();
 foreach ((array) $recount_list as $item) {
     if (isset($item[2]) && isset($_POST[$item[0]]) && 1 == $_POST[$item[0]] && is_callable($item[2])) {
         $message = call_user_func($item[2]);
         if (is_array($message)) {
             $messages[] = $message[1];
         } else {
             $messages[] = $message;
         }
function bb_recount_tag_topics()
{
    global $bbdb;
    $statement = __('Counting the number of topics in each topic tag… %s');
    $result = __('Failed!');
    // Delete empty tags
    $delete = bb_recount_tag_delete_empty();
    if ($delete[0] > 0) {
        $result = __('Could not delete empty tags.');
        return array(1, sprintf($statement, $result));
    }
    // Get all tags
    $sql_terms = "SELECT\n\t\t`{$bbdb->term_taxonomy}`.`term_taxonomy_id`,\n\t\t`{$bbdb->term_relationships}`.`object_id`\n\tFROM `{$bbdb->term_relationships}`\n\tJOIN `{$bbdb->term_taxonomy}`\n\t\tON `{$bbdb->term_taxonomy}`.`term_taxonomy_id` = `{$bbdb->term_relationships}`.`term_taxonomy_id`\n\tWHERE\n\t\t`{$bbdb->term_taxonomy}`.`taxonomy` = 'bb_topic_tag'\n\tORDER BY\n\t\t`{$bbdb->term_taxonomy}`.`term_taxonomy_id`,\n\t\t`{$bbdb->term_relationships}`.`object_id`;";
    $terms = $bbdb->get_results($sql_terms);
    if (is_nxt_error($terms) || !is_array($terms)) {
        return array(2, sprintf($statement, $result));
    }
    if (empty($terms)) {
        $result = __('No topic tags found.');
        return array(3, sprintf($statement, $result));
    }
    // Count the topics in each tag
    $tags = array();
    foreach ($terms as $term) {
        if (!isset($tags[$term->term_taxonomy_id])) {
            $tags[$term->term_taxonomy_id] = 1;
        } else {
            $tags[$term->term_taxonomy_id]++;
        }
    }
    if (empty($tags)) {
        return array(4, sprintf($statement, $result));
    }
    // Build the values to insert into the SQL statement
    $values = array();
    foreach ($tags as $term_taxonomy_id => $count) {
        $values[] = '(' . $term_taxonomy_id . ', ' . $count . ')';
    }
    if (empty($values)) {
        return array(5, sprintf($statement, $result));
    }
    // Update the terms with the new tag counts
    $values = array_chunk($values, 10000);
    foreach ($values as $chunk) {
        $sql = "INSERT INTO `{$bbdb->term_taxonomy}` (`term_taxonomy_id`, `count`) VALUES " . implode(", ", $chunk) . " ON DUPLICATE KEY UPDATE `count` = VALUES(`count`);";
        if (is_nxt_error($bbdb->query($sql))) {
            return array(6, sprintf($statement, $result));
        }
    }
    if ($return_boolean) {
        return true;
    }
    $result = __('Complete!');
    return array(0, sprintf($statement, $result));
}