/** * Pulling BBPress search into a function * * @Param: Search string * @return: An array which contains the BBPress results. * @author: pete kuhn * @version 1.0 **/ function forums_search_results($q) { global $bbdb; $bb_query_form = new BB_Query_Form(); if ($q = stripslashes($q)) { add_filter('bb_recent_search_fields', create_function('$f', 'return $f . ", MAX(post_time) AS post_time";')); add_filter('bb_recent_search_group_by', create_function('', 'return "t.topic_id";')); $bb_query_form->BB_Query_Form('post', array(), array('per_page' => 5, 'post_status' => 0, 'topic_status' => 0, 'post_text' => $q, 'forum_id', 'tag', 'topic_author', 'post_author'), 'bb_recent_search'); $recent = $bb_query_form->results; $bb_query_form->BB_Query_Form('topic', array('search' => $q), array('post_status' => 0, 'topic_status' => 0, 'search', 'forum_id', 'tag', 'topic_author', 'post_author'), 'bb_relevant_search'); $relevant = $bb_query_form->results; $q = $bb_query_form->get('search'); } do_action('do_search', $q); // Cache topics if ($recent) { $topic_ids = array(); foreach ($recent as $bb_post) { $topic_ids[] = (int) $bb_post->topic_id; $bb_post_cache[$bb_post->post_id] = $bb_post; } $topic_ids = join($topic_ids); if ($topics = $bbdb->get_results("SELECT * FROM {$bbdb->topics} WHERE topic_id IN ({$topic_ids})")) { $topics = bb_append_meta($topics, 'topic'); } } return $recent; }
} $bb_query_form = new BB_Query_Form(); if ($q = stripslashes($q)) { $per_page = ceil((int) bb_get_option('page_topics') / 2); /* Recent */ add_filter('bb_recent_search_fields', create_function('$f', 'return $f . ", MAX(post_time) AS post_time";')); add_filter('bb_recent_search_group_by', create_function('', 'return "t.topic_id";')); $bb_query_form->BB_Query_Form('post', array(), array('order_by' => 'p.post_time', 'count' => true, 'per_page' => $per_page, 'post_status' => 0, 'topic_status' => 0, 'post_text' => $q, 'forum_id', 'tag', 'topic_author', 'post_author'), 'bb_recent_search'); $recent = $bb_query_form->results; $recent_count = $recent ? $bb_query_form->found_rows : 0; /* Relevant */ $bb_query_form->BB_Query_Form('topic', array('search' => $q), array('per_page' => $per_page, 'count' => true, 'post_status' => 0, 'topic_status' => 0, 'search', 'forum_id', 'tag', 'topic_author', 'post_author'), 'bb_relevant_search'); $relevant = $bb_query_form->results; $relevant_count = $relevant ? $bb_query_form->found_rows : 0; $search_count = max($recent_count, $relevant_count); $q = $bb_query_form->get('search'); } do_action('do_search', $q); // Cache topics // NOT bbdb::prepared if ($recent) { $topic_ids = array(); foreach ($recent as $bb_post) { $topic_ids[] = (int) $bb_post->topic_id; } $topic_ids = join($topic_ids); if ($topics = $bbdb->get_results("SELECT * FROM {$bbdb->topics} WHERE topic_id IN ({$topic_ids})")) { $topics = bb_append_meta($topics, 'topic'); } } bb_load_template('search.php', array('q', 'recent', 'relevant', 'per_page', 'search_count'), $q);
die(__("Now how'd you get here? And what did you think you'd being doing?")); } //This should never happen. add_filter('get_topic_where', 'bb_no_where'); add_filter('get_topic_link', 'bb_make_link_view_all'); add_filter('post_edit_uri', 'bb_make_link_view_all'); $post_query = new BB_Query_Form('post', array('post_status' => 'normal', 'count' => true, 'per_page' => 20)); $bb_posts =& $post_query->results; $total = $post_query->found_rows; ?> <div class="wrap"> <h2><?php _e('Posts'); $h2_search = $post_query->get('post_text'); $h2_forum = $post_query->get('forum_id'); $h2_tag = $post_query->get('tag_id'); $h2_author = $post_query->get('post_author_id'); $h2_search = $h2_search ? ' ' . sprintf(__('containing “%s”'), esc_html($h2_search)) : ''; $h2_forum = $h2_forum ? ' ' . sprintf(__('in “%s”'), get_forum_name($h2_forum)) : ''; $h2_tag = $h2_tag ? ' ' . sprintf(__('with tag “%s”'), esc_html(bb_get_tag_name($h2_tag))) : ''; $h2_author = $h2_author ? ' ' . sprintf(__('by %s'), esc_html(get_user_name($h2_author))) : ''; if ($ip_available) { $h2_ip = $post_query->get('poster_ip'); $h2_ip = $h2_ip ? ' ' . sprintf(__('from IP address %s'), esc_html($h2_ip)) : ''; } else { $h2_ip = ''; } if ($h2_search || $h2_forum || $h2_tag || $h2_author || $h2_ip) { echo '<span class="subtitle">';
add_filter('topic_last_post_link', 'bb_make_link_view_all'); $topic_query_vars = array('topic_status' => 'normal', 'open' => 'open', 'count' => true, 'per_page' => 20); if (isset($_POST['search']) && $_POST['search']) { $topic_query_vars['post_status'] = 'all'; } elseif (isset($_GET['search']) && $_GET['search']) { $topic_query_vars['post_status'] = 'all'; } $topic_query = new BB_Query_Form('topic', $topic_query_vars); $topics = $topic_query->results; ?> <div class="wrap"> <h2><?php _e('Topics'); $h2_search = $topic_query->get('search'); $h2_forum = $topic_query->get('forum_id'); $h2_tag = $topic_query->get('tag_id'); $h2_author = $topic_query->get('topic_author_id'); $h2_search = $h2_search ? ' ' . sprintf(__('containing “%s”'), esc_html($h2_search)) : ''; $h2_forum = $h2_forum ? ' ' . sprintf(__('in “%s”'), get_forum_name($h2_forum)) : ''; $h2_tag = $h2_tag ? ' ' . sprintf(__('with tag “%s”'), esc_html(bb_get_tag_name($h2_tag))) : ''; $h2_author = $h2_author ? ' ' . sprintf(__('by %s'), esc_html(get_user_name($h2_author))) : ''; if ($h2_search || $h2_forum || $h2_tag || $h2_author) { echo '<span class="subtitle">'; printf(__('%1$s%2$s%3$s%4$s'), $h2_search, $h2_forum, $h2_tag, $h2_author); echo '</span>'; } ?> </h2> <?php