isSpecialUser(S_MODERATOR)){
$show_hidden_posts = true;
} else {
$show_hidden_posts = false;
}
page_head(tr(FORUM_SEARCH));
$search_keywords = post_str("search_keywords", true);
$search_author = post_str("search_author", true);
$search_max_time = post_int("search_max_time");
$search_forum = post_int("search_forum");
$search_sort = post_int("search_sort");
$search_list = explode(" ",$search_keywords);
$min_timestamp = time() - ($search_max_time*3600*24);
$limit = 100;
if ($search_forum==-1){
$forum = "";
} else if ($search_forum) {
$forum = new Forum($search_forum);
}
if ($search_author) $user = newUser($search_author);
$dbhandler = $mainFactory->getDatabaseHandler();
// First search thread titles, if we get a hit there it's almost bound to be relevant
$thread_ids = $dbhandler->searchThreadTitles($search_list, $forum, $user, $min_timestamp, round($limit/7), $search_sort, $show_hidden_posts);
// Display the threads while we search for posts
if ($thread_ids){
echo "
Perform another search
";
echo "Threads found matching your search query:
";
start_forum_table(array(tr(FORUM_TOPIC), tr(FORUM_THREADS), tr(FORUM_POSTS), tr(FORUM_AUTHOR), tr(FORUM_VIEWS), "".tr(FORUM_LAST_POST).""));
foreach ($thread_ids as $key => $thread_id){
$thread = new Thread($thread_id);
if ($thread->isHidden()) continue;
$thread_forum = $thread->getForum();
echo '
'.cleanup_title($thread_forum->getTitle()).' |
'.cleanup_title($thread->getTitle()).' | ';
echo '
'.($thread->getPostCount()+1).' |
'.re_user_links($thread->getOwner()).' |
'.$thread->getViewCount().' |
'.time_diff_str($thread->getLastTimestamp(), time()).' |
';
}
end_table();
echo "
";
}
// Let's see if we can match anything in a post body as well:
$post_ids = $dbhandler->searchPosts($search_list, $forum, $user, $min_timestamp, $limit, $search_sort, $show_hidden_posts);
if ($post_ids){
echo "Posts found matching your search query:
";
start_forum_table(array(tr(FORUM_TOPIC), tr(FORUM_THREADS), tr(FORUM_AUTHOR),"".tr(FORUM_LAST_POST).""));
if ($logged_in_user){
$options = $logged_in_user->getTextTransformSettings();
} else {
$options = new output_options;
}
foreach ($post_ids as $key => $post_id){
$post = new Post($post_id);
$thread = $post->getThread();
if (($show_hidden_posts == false) && ($thread->isHidden())) continue;
if (($show_hidden_posts == false) && ($post->isHidden())) continue;
$options->setHighlightTerms($search_list);
$contents = output_transform($post->getContent(),$options);
$thread_forum = $thread->getForum();
echo '
'.cleanup_title($thread_forum->getTitle()).' |
'.cleanup_title($thread->getTitle()).' |
'.re_user_links($post->getOwner()).' |
'.time_diff_str($post->getTimestamp(), time()).' |
'.substr($contents,0,200).'...
|
|
';
}
end_table();
}
if (!$thread_ids && !$post_ids){
echo "Sorry, couldn't find anything matching your search query. You
can try to broaden your search by using less words (or less specific words).
You can also
try the same search on Google.
";
}
echo "Perform another search
";
page_tail();
exit;
?>