2006-06-16 23:53:56 +00:00
< ? php
2008-08-05 22:43:14 +00:00
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
2007-11-12 20:57:15 +00:00
// search for posts or a thread.
// Takes input from forum_search.php
2006-06-16 23:53:56 +00:00
2007-11-12 20:57:15 +00:00
require_once ( '../inc/time.inc' );
require_once ( '../inc/text_transform.inc' );
2006-06-16 23:53:56 +00:00
require_once ( '../inc/forum.inc' );
2011-02-09 22:11:34 +00:00
check_get_args ( array ());
2007-11-15 22:51:05 +00:00
// Searches for the keywords in the $keyword_list array in thread titles.
// Optionally filters by forum, user, time, or hidden if specified.
//
function search_thread_titles (
$keyword_list , $forum = " " , $user = " " , $time = " " , $limit = 200 ,
$sort_style = CREATE_TIME_NEW , $show_hidden = false
){
$search_string = " % " ;
foreach ( $keyword_list as $key => $word ) {
$search_string .= mysql_escape_string ( $word ) . " % " ;
}
$query = " title like ' " . $search_string . " ' " ;
2008-09-07 07:40:56 +00:00
if ( $forum && $forum != " all " ) {
$query .= " and forum = $forum->id " ;
2007-11-15 22:51:05 +00:00
}
2008-09-07 07:40:56 +00:00
if ( $user && $user != " all " ) {
$query .= " and owner = $user->id " ;
2007-11-15 22:51:05 +00:00
}
2008-09-07 07:40:56 +00:00
if ( $time && $user != " all " ) {
$query .= " and timestamp > $time " ;
2007-11-15 22:51:05 +00:00
}
2008-09-09 14:59:50 +00:00
if ( ! $show_hidden ) {
2008-09-07 07:40:56 +00:00
$query .= " and thread.hidden = 0 " ;
2007-11-15 22:51:05 +00:00
}
switch ( $sort_style ) {
case MODIFIED_NEW :
$query .= ' ORDER BY timestamp DESC' ;
break ;
case VIEWS_MOST :
$query .= ' ORDER BY views DESC' ;
break ;
case REPLIES_MOST :
$query .= ' ORDER BY replies DESC' ;
break ;
case CREATE_TIME_NEW :
$query .= ' ORDER by create_time desc' ;
break ;
case CREATE_TIME_OLD :
$query .= ' ORDER by create_time asc' ;
break ;
case 'score' :
$query .= ' ORDER by score desc' ;
break ;
default :
$query .= ' ORDER BY timestamp DESC' ;
break ;
}
2008-09-07 07:40:56 +00:00
$query .= " limit $limit " ;
2007-11-15 22:51:05 +00:00
return BoincThread :: enum ( $query );
}
// Searches for the keywords in the $keyword_list array in post bodies.
// optionally filters by forum, time, hidden, or user if specified.
//
function search_post_content (
2008-01-19 13:25:47 +00:00
$keyword_list , $forum , $user , $time , $limit , $sort_style , $show_hidden
2007-11-15 22:51:05 +00:00
){
2010-11-25 05:54:09 +00:00
$db = BoincDb :: get ();
2007-11-15 22:51:05 +00:00
$search_string = " % " ;
foreach ( $keyword_list as $key => $word ){
2011-08-28 21:27:52 +00:00
$search_string .= BoincDb :: escape_string ( $word ) . " % " ;
2011-08-25 22:12:48 +00:00
}
2007-11-15 22:51:05 +00:00
$optional_join = " " ;
2008-01-19 13:25:47 +00:00
// if looking in a single forum, need to join w/ thread table
// because that's where the link to forum is
//
if ( $forum ) {
2010-11-25 05:54:09 +00:00
$optional_join = " LEFT JOIN " . $db -> db_name . " .thread ON post.thread = thread.id " ;
2007-11-15 22:51:05 +00:00
}
2010-11-25 05:54:09 +00:00
$query = " select post.* from " . $db -> db_name . " .post " . $optional_join . " where content like ' " . $search_string . " ' " ;
2008-01-19 13:25:47 +00:00
if ( $forum ) {
$query .= " and forum = $forum->id " ;
2007-11-15 22:51:05 +00:00
}
2008-01-19 13:25:47 +00:00
if ( $user ) {
$query .= " and post.user = $user->id " ;
2007-11-15 22:51:05 +00:00
}
2008-01-19 13:25:47 +00:00
if ( $time ) {
$query .= " and post.timestamp > $time " ;
2007-11-15 22:51:05 +00:00
}
2008-01-19 13:25:47 +00:00
if ( ! $show_hidden ) {
2007-11-15 22:51:05 +00:00
$query .= " AND post.hidden = 0 " ;
}
switch ( $sort_style ) {
case VIEWS_MOST :
$query .= ' ORDER BY views DESC' ;
break ;
case CREATE_TIME_NEW :
$query .= ' ORDER by post.timestamp desc' ;
break ;
case CREATE_TIME_OLD :
$query .= ' ORDER by post.timestamp asc' ;
break ;
case POST_SCORE :
$query .= ' ORDER by post.score desc' ;
break ;
default :
$query .= ' ORDER BY post.timestamp DESC' ;
break ;
}
2008-01-19 13:25:47 +00:00
$query .= " limit $limit " ;
2007-11-15 22:51:05 +00:00
return BoincPost :: enum_general ( $query );
}
2007-11-12 20:57:15 +00:00
$logged_in_user = get_logged_in_user ( false );
BoincForumPrefs :: lookup ( $logged_in_user );
if ( $logged_in_user && $logged_in_user -> prefs -> privilege ( S_MODERATOR )){
2007-09-12 15:02:39 +00:00
$show_hidden_posts = true ;
} else {
$show_hidden_posts = false ;
}
2006-06-16 23:53:56 +00:00
2007-11-20 19:23:26 +00:00
page_head ( tra ( " Forum search results " ));
2006-06-16 23:53:56 +00:00
$search_keywords = post_str ( " search_keywords " , true );
2008-09-07 07:40:56 +00:00
$search_author = post_int ( " search_author " , true );
2006-06-16 23:53:56 +00:00
$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 ){
2008-01-19 13:25:47 +00:00
$forum = null ;
2006-06-16 23:53:56 +00:00
} else if ( $search_forum ) {
2007-11-12 20:57:15 +00:00
$forum = BoincForum :: lookup_id ( $search_forum );
2006-06-16 23:53:56 +00:00
}
2007-10-30 23:34:26 +00:00
$user = null ;
2007-11-12 20:57:15 +00:00
if ( $search_author ) {
$user = BoincUser :: lookup_id ( $search_author );
}
2006-06-16 23:53:56 +00:00
2007-11-15 00:27:02 +00:00
// First search thread titles; if we get a hit there it's probably relevant
2007-11-12 20:57:15 +00:00
//
$threads = search_thread_titles ( $search_list , $forum , $user , $min_timestamp , round ( $limit / 7 ), $search_sort , $show_hidden_posts );
2006-06-16 23:53:56 +00:00
// Display the threads while we search for posts
2007-11-12 20:57:15 +00:00
if ( count ( $threads )){
2010-11-03 21:48:39 +00:00
echo " <span class=title> " . tra ( " Thread titles matching your query: " ) . " </span> " ;
2007-11-22 04:13:59 +00:00
show_thread_and_context_header ();
2008-08-07 20:43:52 +00:00
$i = 0 ;
2007-11-12 20:57:15 +00:00
foreach ( $threads as $thread ){
if ( $thread -> hidden ) continue ;
2008-08-07 20:43:52 +00:00
show_thread_and_context ( $thread , $logged_in_user , $i ++ );
2006-06-16 23:53:56 +00:00
}
end_table ();
echo " <br /><br /> " ;
}
2007-11-12 20:57:15 +00:00
2007-11-15 00:27:02 +00:00
// Look in a post content as well
2007-11-12 20:57:15 +00:00
//
2007-11-15 00:27:02 +00:00
$posts = search_post_content (
2007-11-12 20:57:15 +00:00
$search_list , $forum , $user , $min_timestamp , $limit , $search_sort ,
$show_hidden_posts
);
2006-06-16 23:53:56 +00:00
2007-11-12 20:57:15 +00:00
if ( count ( $posts )){
2010-11-03 21:48:39 +00:00
echo " <span class=title> " . tra ( " Messages matching your query: " ) . " </span> " ;
2007-11-20 19:23:26 +00:00
start_table ();
$n = 1 ;
$options = get_output_options ( $logged_in_user );
$options -> setHighlightTerms ( $search_list );
foreach ( $posts as $post ) {
2007-11-12 20:57:15 +00:00
$thread = BoincThread :: lookup_id ( $post -> thread );
2007-11-20 19:23:26 +00:00
if ( ! $thread ) continue ;
$forum = BoincForum :: lookup_id ( $thread -> forum );
if ( ! $forum ) continue ;
2007-11-25 04:47:54 +00:00
if ( ! is_forum_visible_to_user ( $forum , $logged_in_user )) continue ;
2007-11-20 19:23:26 +00:00
2008-01-11 23:11:07 +00:00
if ( ! $show_hidden_posts ) {
if ( $thread -> hidden ) continue ;
if ( $post -> hidden ) continue ;
}
2007-11-20 19:23:26 +00:00
show_post_and_context ( $post , $thread , $forum , $options , $n );
$n ++ ;
2006-06-16 23:53:56 +00:00
}
end_table ();
}
2007-11-12 20:57:15 +00:00
if ( ! count ( $thread ) && ! count ( $posts )){
2011-08-25 22:12:48 +00:00
echo " <p> " . tra ( " Sorry, couldn't find anything matching your search query. You can try to broaden your search by using less words (or less specific words). " ) . " </p>
< p > "
. tra ( " You can also %1try the same search on Google.%2 " ,
" <a href= \" http://www.google.com/search?domains= " . URL_BASE . " &sitesearch= " . URL_BASE . " /forum_thread.php&q= " . htmlentities ( $search_keywords ) . " \" > " ,
" </a> " )
. " </p> " ;
2006-06-16 23:53:56 +00:00
}
2011-08-25 22:12:48 +00:00
echo " <p><a href= \" forum_search.php \" > " . tra ( " Perform another search " ) . " </a></p> " ;
2006-06-16 23:53:56 +00:00
page_tail ();
2007-11-12 20:57:15 +00:00
$cvs_version_tracker [] = " \$ Id $ " ; //Generated automatically - do not edit
2006-06-16 23:53:56 +00:00
?>