function &query()
 {
     global $bbdb;
     if ($args = func_get_args()) {
         call_user_func_array(array(&$this, 'init'), $args);
     }
     if (!$this->generate_query()) {
         return;
     }
     do_action_ref_array('bb_query', array(&$this));
     $key = md5($this->request);
     if (false === ($cached_ids = wp_cache_get($key, 'bb_query'))) {
         if ('post' == $this->type) {
             $this->results = bb_cache_posts($this->request, $this->query_vars['post_id_only']);
             // This always appends meta
             $_the_id = 'post_id';
             $this->query_vars['append_meta'] = false;
         } else {
             $this->results = $bbdb->get_results($this->request);
             $_the_id = 'topic_id';
         }
         $cached_ids = array();
         if (is_array($this->results)) {
             foreach ($this->results as $object) {
                 $cached_ids[] = $object->{$_the_id};
             }
         }
         wp_cache_set($key, $cached_ids, 'bb_query');
     } else {
         if ('post' == $this->type) {
             $_query_ids = array();
             $_cached_posts = array();
             foreach ($cached_ids as $_cached_id) {
                 if (false !== ($_post = wp_cache_get($_cached_id, 'bb_post'))) {
                     $_cached_posts[$_post->post_id] = $_post;
                 } else {
                     $_query_ids[] = $_cached_id;
                 }
             }
             if (count($_query_ids)) {
                 $_query_ids = join(',', array_map('intval', $_query_ids));
                 $results = $bbdb->get_results("SELECT * FROM {$bbdb->posts} WHERE post_id IN({$_query_ids})");
                 $results = array_merge($results, $_cached_posts);
             } else {
                 $results = $_cached_posts;
             }
             $_the_id = 'post_id';
         } else {
             $_query_ids = array();
             $_cached_topics = array();
             foreach ($cached_ids as $_cached_id) {
                 if (false !== ($_topic = wp_cache_get($_cached_id, 'bb_topic'))) {
                     $_cached_topics[$_topic->topic_id] = $_topic;
                 } else {
                     $_query_ids[] = $_cached_id;
                 }
             }
             if (count($_query_ids)) {
                 $_query_ids = join(',', array_map('intval', $_query_ids));
                 $results = $bbdb->get_results("SELECT * FROM {$bbdb->topics} WHERE topic_id IN({$_query_ids})");
                 $results = array_merge($results, $_cached_topics);
             } else {
                 $results = $_cached_topics;
             }
             $_the_id = 'topic_id';
         }
         $this->results = array();
         $trans = array();
         foreach ($results as $object) {
             $trans[$object->{$_the_id}] = $object;
         }
         foreach ($cached_ids as $cached_id) {
             $this->results[] = $trans[$cached_id];
         }
     }
     $this->count = count($this->results);
     if (false === $this->found_rows && $this->query_vars['count']) {
         // handles FOUND_ROWS() or COUNT(*)
         $this->found_rows = bb_count_last_query($this->request);
     }
     if ('post' == $this->type) {
         if ($this->query_vars['append_meta']) {
             $this->results = bb_append_meta($this->results, 'post');
         }
         if ($this->query_vars['cache_users']) {
             bb_post_author_cache($this->results);
         }
         if ($this->query_vars['cache_topics']) {
             bb_cache_post_topics($this->results);
         }
     } else {
         if ($this->query_vars['append_meta']) {
             $this->results = bb_append_meta($this->results, 'topic');
         }
     }
     return $this->results;
 }
Example #2
0
function bb_cache_last_posts($_topics = false, $author_cache = true)
{
    global $topics, $bbdb;
    if (!$_topics) {
        $_topics =& $topics;
    }
    if (!is_array($_topics)) {
        return false;
    }
    $last_post_ids = array();
    $topic_ids = array();
    foreach ($_topics as $topic) {
        if (is_object($topic)) {
            $last_post_ids[] = (int) $topic->topic_last_post_id;
        } else {
            if (is_numeric($topic) && false !== ($cached_topic = nxt_cache_get($topic, 'bb_topic'))) {
                $last_post_ids[] = (int) $cached_topic->topic_last_post_id;
            } else {
                if (is_numeric($topic)) {
                    $topic_ids[] = (int) $topic;
                }
            }
        }
    }
    if (!empty($last_post_ids)) {
        $_last_post_ids = join(',', $last_post_ids);
        $posts = (array) bb_cache_posts("SELECT post_id FROM {$bbdb->posts} WHERE post_id IN ({$_last_post_ids}) AND post_status = 0", true);
        if ($author_cache) {
            bb_post_author_cache($posts);
        }
    }
    if (!empty($topic_ids)) {
        $_topic_ids = join(',', $topic_ids);
        $posts = (array) bb_cache_posts("SELECT p.post_id FROM {$bbdb->topics} AS t LEFT JOIN {$bbdb->posts} AS p ON ( t.topic_last_post_id = p.post_id ) WHERE t.topic_id IN ({$_topic_ids}) AND p.post_status = 0", true);
        if ($author_cache) {
            bb_post_author_cache($posts);
        }
    }
}
function post_author_cache($posts)
{
    bb_log_deprecated('function', __FUNCTION__, 'bb_post_author_cache');
    return bb_post_author_cache($posts);
}
Example #4
0
}
bb_repermalink();
if (!$topic) {
    bb_die(__('Topic not found.'));
}
if ($view_deleted) {
    add_filter('get_thread_where', create_function('', 'return "p.topic_id = ' . $topic_id . '";'));
    add_filter('get_thread_post_ids', create_function('', 'return "p.topic_id = ' . $topic_id . '";'));
    add_filter('post_edit_uri', 'bb_make_link_view_all');
}
$bb_db_override = false;
do_action('bb_topic.php_pre_db', $topic_id);
if (!$bb_db_override) {
    $posts = get_thread($topic_id, $page);
    $forum = bb_get_forum($topic->forum_id);
    $tags = bb_get_topic_tags($topic_id);
    if ($tags && ($bb_current_id = bb_get_current_user_info('id'))) {
        $user_tags = bb_get_user_tags($topic_id, $bb_current_id);
        $other_tags = bb_get_other_tags($topic_id, $bb_current_id);
        $public_tags = bb_get_public_tags($topic_id);
    } elseif (is_array($tags)) {
        $user_tags = false;
        $other_tags = bb_get_public_tags($topic_id);
        $public_tags =& $other_tags;
    } else {
        $user_tags = $other_tags = $public_tags = false;
    }
    $list_start = ($page - 1) * bb_get_option('page_topics') + 1;
    bb_post_author_cache($posts);
}
bb_load_template('topic.php', array('bb_db_override', 'user_tags', 'other_tags', 'list_start'), $topic_id);