diff --git a/phpBB/index.php b/phpBB/index.php index 7df8938510..ce92725707 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -205,8 +205,10 @@ if($total_categories = $db->sql_numrows($q_categories)) "USERS_BROWSING" => $users_browsing, "L_FORUM_LOCKED" => $lang['Forum_is_locked'], - "L_MARK_FORUMS_READ" => $lang['Mark_all_forums'], + "L_MARK_FORUMS_READ" => $lang['Mark_all_forums'], + "L_SEARCH_NEW" => $lang['Search_new'], + "U_SEARCH_NEW" => append_sid("search.$phpEx?search_id=newposts"), "U_MARK_READ" => append_sid("index.$phpEx?mark=forums"), "U_NEWEST_USER_PROFILE" => append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$newest_uid")) ); diff --git a/phpBB/language/lang_english.php b/phpBB/language/lang_english.php index 1ac21588f6..ea18d29ffc 100755 --- a/phpBB/language/lang_english.php +++ b/phpBB/language/lang_english.php @@ -39,6 +39,8 @@ // $lang['Forum'] = "Forum"; $lang['Forums'] = "Forums"; +$lang['Category'] = "Category"; +$lang['Categories'] = "Categories"; $lang['Topic'] = "Topic"; $lang['Topics'] = "Topics"; $lang['Reply'] = "Reply"; @@ -527,15 +529,25 @@ $lang['View_Information'] = "View Information"; // // Search // +$lang['Search_query'] = "Search Query"; +$lang['Search_options'] = "Search Options"; +$lang['Search_keywords'] = "Search for Keywords"; +$lang['Search_keywords_explain'] = "You can use AND to define words which must be in the results, OR to define words which may be in the result and NOT to define words which should not be in the result. Use * as a wildcard for partial matches. To define a phrase enclose it within """; +$lang['Search_author'] = "Search for Author"; +$lang['Search_author_explain'] = "Use * as a wildcard for partial matches"; $lang['Search_for_any'] = "Search for any terms or use query as entered"; $lang['Search_for_all'] = "Search for all terms"; $lang['Search_author'] = "Search for Author"; -$lang['Limit_chars'] = "Limit charaters returned to"; +$lang['Return_first'] = "Return first"; // followed by xxx characters +$lang['characters'] = "characters"; +$lang['Search_previous'] = "Search previous"; // followed by days, weeks, months, year, all $lang['Sort_by'] = "Sort by"; $lang['Sort_Ascending'] = "Sort Ascending"; $lang['Sort_Decending'] = "Sort Descending"; +$lang['Display_results'] = "Display results as"; $lang['All'] = "All"; - +$lang['No_search_match'] = "No topics or posts met your search criteria"; +$lang['Search_new'] = "View posts since last visit"; // // Topic Admin <= Should be blank for now // diff --git a/phpBB/profile.php b/phpBB/profile.php index 53710a0ea6..543bea9d45 100644 --- a/phpBB/profile.php +++ b/phpBB/profile.php @@ -251,8 +251,8 @@ if(isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode'])) $yim_img = ($members[$i]['user_yim']) ? "\""" : " "; - $search_img = "\"""; - $search = "" . $lang['Search_user_posts'] . ""; + $search_img = "\"""; + $search = "" . $lang['Search_user_posts'] . ""; $www_img = ($profiledata['user_website']) ? "\""" : " "; diff --git a/phpBB/search.php b/phpBB/search.php index 9dee9959a4..7f082fa702 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -30,11 +30,9 @@ $phpbb_root_path = "./"; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); +include($phpbb_root_path . 'includes/bbcode.'.$phpEx); -$pagetype = "search"; -$page_title = "Search Forums"; - -// +// ----------------------- // Page specific functions // function gensearch_sql($searchstring, $override_all = 0) @@ -65,22 +63,16 @@ function gensearch_sql($searchstring, $override_all = 0) for($i = 0; $i < count($words); $i++) { // - // First see if we've got a single - // word enclosed in quotes. If so remove + // First see if we've got a single word enclosed in quotes. If so remove // quotes and store word // - // Next see if we've got an opening quote - // if we do then we assume a phrase is being - // entered so store first word (if any) - // and set $phrase to true + // Next see if we've got an opening quote if we do then we assume a phrase is + // being entered so store first word (if any) and set $phrase to true // - // Next check if we've got a closing quote - // if so end phrase input + // Next check if we've got a closing quote if so end phrase input // - // Finally store any other word (checking - // to see if phrase is true (if so store word - // in the same array position as previous - // word matches) + // Finally store any other word (checking to see if phrase is true (if so + // store word in the same array position as previous word matches) // if(preg_match("/^([\+\-]*)\"(.*?)\"/", $words[$i], $word)) { @@ -201,16 +193,9 @@ function gensearch_sql($searchstring, $override_all = 0) $searchstring .= " AND "; } $findword = $searchlistandtype["AND"][$j]; - $is_phrase_word = $searchlist_isphrase["AND"][$j]; - if($is_phrase_word) - { - $searchstring .= " ( pt.post_text LIKE '% $findword %' OR pt.post_text LIKE '$findword %' OR pt.post_text LIKE '% $findword' OR pt.post_text LIKE '$findword' )"; - } - else - { - $searchstring .= "pt.post_text LIKE '%$findword%'"; - } - } + + $searchstring .= " ( pt.post_text LIKE '% $findword %')"; + }// OR pt.post_text LIKE '$findword %' OR pt.post_text LIKE '% $findword' } elseif($binsearchtype[$i] == "OR" && count($searchlistandtype["OR"])) { @@ -225,16 +210,9 @@ function gensearch_sql($searchstring, $override_all = 0) $searchstring .= " OR "; } $findword = $searchlistandtype["OR"][$j]; - $is_phrase_word = $searchlist_isphrase["OR"][$j]; - if($is_phrase_word) - { - $searchstring .= " ( pt.post_text LIKE '% $findword %' OR pt.post_text LIKE '$findword %' OR pt.post_text LIKE '% $findword' OR pt.post_text LIKE '$findword' )"; - } - else - { - $searchstring .= "pt.post_text LIKE '%$findword%'"; - } - } + + $searchstring .= " ( pt.post_text LIKE '% $findword %' )"; + }// OR pt.post_text LIKE '$findword %' OR pt.post_text LIKE '% $findword' } elseif($binsearchtype[$i] == "NOT" && count($searchlistandtype["NOT"])) { @@ -249,16 +227,9 @@ function gensearch_sql($searchstring, $override_all = 0) $searchstring .= " AND "; } $findword = $searchlistandtype["NOT"][$j]; - $is_phrase_word = $searchlist_isphrase["NOT"][$j]; - if($is_phrase_word) - { - $searchstring .= " ( pt.post_text NOT LIKE '% $findword %' AND pt.post_text NOT LIKE '$findword %' AND pt.post_text NOT LIKE '% $findword' AND pt.post_text NOT LIKE '$findword' ) "; - } - else - { - $searchstring .= "pt.post_text NOT LIKE '%$findword%'"; - } - } + + $searchstring .= " ( pt.post_text NOT LIKE '% $findword %' AND pt.post_text NOT LIKE '$findword %' AND pt.post_text NOT LIKE '% $findword' AND pt.post_text NOT LIKE '$findword' ) "; + }// } } } @@ -295,12 +266,7 @@ function gensearch_sql($searchstring, $override_all = 0) } // // End of functions defns -// - - -// -// Start of page proper -// +// ---------------------- // // Start session management @@ -311,17 +277,95 @@ init_userprefs($userdata); // End session management // -$start = (isset($HTTP_GET_VARS['start'])) ? $HTTP_GET_VARS['start'] : 0; +// +// Define initial vars +// +if( isset($HTTP_POST_VARS['search_keywords']) || isset($HTTP_GET_VARS['search_keywords']) ) +{ + $query_keywords = ( isset($HTTP_POST_VARS['search_keywords']) ) ? $HTTP_POST_VARS['search_keywords'] : $HTTP_GET_VARS['search_keywords']; +} +else +{ + $query_keywords = ""; +} -$querystring = (isset($HTTP_POST_VARS['querystring'])) ? $HTTP_POST_VARS['querystring'] : ( (!empty($HTTP_GET_VARS['q'])) ? $HTTP_GET_VARS['q'] : "" ); -$authorstring = (isset($HTTP_POST_VARS['authorstring'])) ? $HTTP_POST_VARS['authorstring'] : ( (!empty($HTTP_GET_VARS['a'])) ? $HTTP_GET_VARS['a'] : "" ); +if( isset($HTTP_POST_VARS['search_author']) || isset($HTTP_GET_VARS['search_author']) ) +{ + $query_author = ( isset($HTTP_POST_VARS['search_author']) ) ? $HTTP_POST_VARS['search_author'] : $HTTP_GET_VARS['search_author']; +} +else +{ + $query_author = ""; +} -$return_chars = ($HTTP_POST_VARS['charsreqd'] != "all") ? $HTTP_POST_VARS['charsreqd'] : -1; -$return_chars = (isset($HTTP_GET_VARS['c'])) ? ( ($HTTP_GET_VARS['c'] != "all") ? $HTTP_GET_VARS['c'] : -1 ) : $return_chars; -$searchall = ($HTTP_POST_VARS['addterms'] == "all") ? 1 : ( ($HTTP_GET_VARS['m'] == "all") ? 1 : 0 ); -$searchforum = (isset($HTTP_POST_VARS['searchforum'])) ? $HTTP_POST_VARS['searchforum'] : $HTTP_GET_VARS['f'] ; -$sortby = (isset($HTTP_POST_VARS['sortby'])) ? $HTTP_POST_VARS['sortby'] : $HTTP_GET_VARS['b']; -$sortby_dir = (isset($HTTP_POST_VARS['sortdir'])) ? $HTTP_POST_VARS['sortdir'] : $HTTP_GET_VARS['d']; +$search_id = ( isset($HTTP_GET_VARS['search_id']) ) ? $HTTP_GET_VARS['search_id'] : ""; + +if( isset($HTTP_POST_VARS['addterms']) ) +{ + $search_all_terms = ( $HTTP_POST_VARS['addterms'] == "all" ) ? 1 : 0; +} +else if( isset($HTTP_GET_VARS['addterms']) ) +{ + $search_all_terms = ( $HTTP_GET_VARS['addterms'] == "all" ) ? 1 : 0; +} +else +{ + $search_all_terms = 0; +} + +if( isset($HTTP_POST_VARS['charsreqd']) || isset($HTTP_GET_VARS['charsreqd']) ) +{ + $return_chars = ( isset($HTTP_POST_VARS['charsreqd']) ) ? $HTTP_POST_VARS['charsreqd'] : $HTTP_GET_VARS['charsreqd']; + if( $return_chars == "all" ) + { + $return_chars = -1; + } +} +else +{ + $return_chars = 200; +} + +$search_cat = ( isset($HTTP_POST_VARS['searchcat']) ) ? $HTTP_POST_VARS['searchcat'] : ""; +$search_forum = ( isset($HTTP_POST_VARS['searchforum']) ) ? $HTTP_POST_VARS['searchforum'] : ""; + +if( isset($HTTP_POST_VARS['sortby']) || isset($HTTP_GET_VARS['sortby']) ) +{ + $sortby = (isset($HTTP_POST_VARS['sortby'])) ? $HTTP_POST_VARS['sortby'] : $HTTP_GET_VARS['sortby']; +} +else +{ + $sortby = 0; +} + +if( isset($HTTP_POST_VARS['sortdir']) || isset($HTTP_GET_VARS['sortdir']) ) +{ + $sortby_dir = (isset($HTTP_POST_VARS['sortdir'])) ? $HTTP_POST_VARS['sortdir'] : $HTTP_GET_VARS['sortdir']; +} +else +{ + $sortby_dir = "DESC"; +} + +if( isset($HTTP_POST_VARS['showresults']) || isset($HTTP_GET_VARS['showresults']) ) +{ + $show_results = (isset($HTTP_POST_VARS['showresults'])) ? $HTTP_POST_VARS['showresults'] : $HTTP_GET_VARS['showresults']; +} +else +{ + $show_results = "posts"; +} + +if(!empty($HTTP_POST_VARS['resultdays']) ) +{ + $search_time = time() - ( $HTTP_POST_VARS['resultdays'] * 86400 ); +} +else +{ + $search_time = 0; +} + +$start = ( isset($HTTP_GET_VARS['start']) ) ? $HTTP_GET_VARS['start'] : 0; // // Define some globally used data @@ -329,248 +373,696 @@ $sortby_dir = (isset($HTTP_POST_VARS['sortdir'])) ? $HTTP_POST_VARS['sortdir'] : $sortby_types = array("Post Time", "Post Subject", "Topic Title", "Author Name", "Forum"); $sortby_sql = array("p.post_time", "pt.post_subject", "t.topic_title", "u.username", "f.forum_id"); -if((isset($HTTP_POST_VARS['dosearch']) || isset($HTTP_GET_VARS['dosearch'])) && (!empty($querystring) || !empty($authorstring))) +// +// Begin core code +// +if( $query_keywords != "" || $query_author != "" || $search_id ) { - // - // Limit to search to accessible - // forums - // - $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); - - // - // Start building appropriate SQL query - // - $sql = "SELECT pt.post_text, pt.post_subject, p.forum_id, p.post_id, p.topic_id, p.post_time, f.forum_name, t.topic_title, t.topic_replies, t.topic_views, u.username, u.user_id - FROM ".FORUMS_TABLE." f, ".TOPICS_TABLE." t, ".USERS_TABLE." u, ".POSTS_TEXT_TABLE." pt, ".POSTS_TABLE." p "; - - // - // If user is logged in then we'll - // check to see which (if any) private - // forums they are allowed to view and - // include them in the search. - // - // If not logged in we explicitly prevent - // searching of private forums - // - - if($querystring != "" || $authorstring != "") + if( $query_keywords != "" || $query_author != "" || $search_id == "newposts" ) { - $search_sql = ""; - if($querystring != "") + if( $search_id == "newposts" ) { - $searchdata = gensearch_sql($querystring, $searchall); - $search_sql = $searchdata[0]; + $show_results = "topics"; + $search_time = $userdata['session_last_visit']; + $sortby = 0; + $sortby_dir = "DESC"; } - if($authorstring != "") + // + // Limit to search to accessible + // forums + // + $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); + + // + // Start building appropriate SQL query + // + $sql_fields = ( $show_results == "posts") ? "pt.post_text, pt.post_subject, p.*, f.forum_name, t.*, u.username, u.user_id, u.user_sig" : "f.forum_id, f.forum_name, t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username" ; + + $sql_from = ( $show_results == "posts") ? FORUMS_TABLE . " f, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt " : FORUMS_TABLE . " f, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt, " . USERS_TABLE . " u2"; + + $sql_where = ( $show_results == "posts") ? "pt.post_id = p.post_id AND f.forum_id = p.forum_id AND p.topic_id = t.topic_id AND p.poster_id = u.user_id" : "pt.post_id = p.post_id AND f.forum_id = p.forum_id AND t.topic_id = p.topic_id AND u.user_id = t.topic_poster AND p.poster_id = u2.user_id"; + + $sql = "SELECT $sql_fields + FROM $sql_from "; + + // + // If user is logged in then we'll + // check to see which (if any) private + // forums they are allowed to view and + // include them in the search. + // + // If not logged in we explicitly prevent + // searching of private forums + // + + if( $query_keywords != "" || $query_author != "" || $search_id == "newposts" ) { - $search_sql = preg_replace("/\(\)/", "", $search_sql); - $authorstring = $authorstring; - $search_sql .= ($search_sql == "") ? "(u.username LIKE '%$authorstring%')" : " AND (u.username LIKE '%$authorstring%')"; - } - - if(!ereg("\([ ]*\)",$search_sql)) - { - $sql .= "WHERE $search_sql - AND (pt.post_id = p.post_id) - AND (f.forum_id = p.forum_id) - AND (p.topic_id = t.topic_id) - AND (p.poster_id = u.user_id)"; - - if($searchforum != "all") + $search_sql = ""; + if($query_keywords != "") { - $sql .= ($is_auth_ary[$searchforum]['auth_read']) ? " AND (f.forum_id = '$searchforum')" : ""; + $searchdata = gensearch_sql($query_keywords, $search_all_terms); + $search_sql = $searchdata[0]; } - while(list($key, $value) = each($is_auth_ary)) + if($query_author != "") { - if(!$value['auth_read']) + $search_sql = preg_replace("/\(\)/", "", $search_sql); + $search_sql .= ($search_sql == "") ? "u.username LIKE '%$query_author%'" : " AND (u.username LIKE '%$query_author%')"; + } + + if( !ereg("\([ ]*\)", $search_sql) || $search_id == "newposts" ) + { + $sql .= ( $search_id == "newposts" ) ? "WHERE $sql_where" : "WHERE $search_sql AND $sql_where"; + + if( $search_forum != "all" ) { - $sql .= " AND (f.forum_id <> $key )"; - } - } - - $sql .= " ORDER BY ".$sortby_sql[$sortby]." $sortby_dir"; - - $result = $db->sql_query($sql); - if(!$result) - { - message_die(QUERY_ERROR, "Couldn't obtain search results", __LINE__, __FILE__); - } - $searchset = $db->sql_fetchrowset($result); - - if(count($searchset)) - { - // - // Output header - // - include($phpbb_root_path . 'includes/page_header.'.$phpEx); - - $template->set_filenames(array( - "body" => "search_results_body.tpl", - "jumpbox" => "jumpbox.tpl") - ); - $jumpbox = make_jumpbox(); - $template->assign_vars(array( - "JUMPBOX_LIST" => $jumpbox, - "SELECT_NAME" => POST_FORUM_URL) - ); - $template->assign_var_from_handle("JUMPBOX", "jumpbox"); - - $template->assign_vars(array( - "SEARCH_MATCHES" => count($searchset), - - "L_TOPIC" => $lang['Topic']) - ); - - for($j = 1; $j < count($searchdata); $j++) - { - $search_string[] = "'(".preg_quote($searchdata[$j], "'").")'i"; - $replace_string[] = "\\1"; + $sql .= ( $is_auth_ary[$searchforum]['auth_read'] ) ? " AND f.forum_id = '$searchforum'" : ""; } - for($i = $start; $i < min($start + $board_config['posts_per_page'], count($searchset)); $i++) + while(list($key, $value) = each($is_auth_ary)) { - $forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=" . $searchset[$i]['forum_id']); - $topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $searchset[$i]['topic_id']); - $poster_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $searchset[$i]['user_id']); - $post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=".$searchset[$i]['post_id']."#".$searchset[$i]['post_id']); - - $post_date = create_date($board_config['default_dateformat'], $searchset[$i]['post_time'], $board_config['board_timezone']); - - $message = $searchset[$i]['post_text']; - - if($return_chars != 0 ) + if( !$value['auth_read'] ) { - if($return_chars != -1) + $sql .= " AND f.forum_id <> $key "; + } + } + + if( $search_time ) + { + $sql .= " AND p.post_time >= $search_time "; + } + + if( $show_results != "posts") + { + $sql .= " GROUP BY t.topic_id "; + } + + $sql .= " ORDER BY " . $sortby_sql[$sortby] . " $sortby_dir"; + + if( !$result = $db->sql_query($sql) ) + { + message_die(GENERAL_ERROR, "Couldn't obtain search results", "", __LINE__, __FILE__, $sql); + } + $searchset = $db->sql_fetchrowset($result); + + // + // Clean up search results table + // + $sql = "SELECT session_id + FROM " . SESSIONS_TABLE; + if( $result = $db->sql_query($sql) ) + { + $delete_search_id_sql = ""; + while( $row = $db->sql_fetchrow($result) ) + { + if( $delete_search_id_sql != "" ) { - $message = (strlen($message) > $return_chars) ? substr($message, 0, $return_chars) . " ..." : $message; - } - - $message = strip_tags($message); - // - // Remove BBCode - // - $message = preg_replace("/\[.*\]/", "", $message); - - $message = str_replace("\n", "
", $message); - if(count($searchdata) > 1) - { - $message = preg_replace($search_string, $replace_string, $message); + $delete_search_id_sql .= ", "; + } + $delete_search_id_sql .= "'" . $row['session_id'] . "'"; + } + + if( $delete_search_id_sql != "" ) + { + $sql = "DELETE FROM phpbb_search_results + WHERE session_id NOT IN ($delete_search_id_sql)"; + if( !$result = $db->sql_query($sql) ) + { + message_die(GENERAL_ERROR, "Couldn't delete old search id sessions", "", __LINE__, __FILE__, $sql); + } + } + } + + // + // Store new result data + // + if( count($searchset) ) + { + $search_results = ""; + for($i = 0; $i < count($searchset); $i++) + { + if( $show_results == "posts") + { + $search_results .= ($search_results != "") ? ", " . $searchset[$i]['post_id'] : $searchset[$i]['post_id']; + } + else + { + $search_results .= ($search_results != "") ? ", " . $searchset[$i]['topic_id'] : $searchset[$i]['topic_id']; + } + } + + // + // Combine both results and search data (apart from original query) + // so we can serialize it and place it in the DB + // + $store_search_data = array(); + $store_search_data['results'] = $search_results; + $store_search_data['data'] = $searchdata; + $store_search_data['data'][0] = ""; + + $result_array = serialize($store_search_data); + unset($store_search_data); + unset($search_results); + + mt_srand ((double) microtime() * 1000000); + $search_id = mt_rand(); + + $sql = "UPDATE phpbb_search_results + SET search_id = $search_id, search_array = '$result_array' + WHERE session_id = '" . $userdata['session_id'] . "'"; + $result = $db->sql_query($sql); + if( !$result || !$db->sql_affectedrows() ) + { + $sql = "INSERT INTO phpbb_search_results (search_id, session_id, search_array) + VALUES($search_id, '" . $userdata['session_id'] . "', '$result_array')"; + if( !$result = $db->sql_query($sql) ) + { + message_die(GENERAL_ERROR, "Couldn't insert search results", "", __LINE__, __FILE__, $sql); + } + } + } + else + { + message_die(GENERAL_MESSAGE, $lang['No_search_match']); + } + } + } + } + else + { + $search_id = $HTTP_GET_VARS['search_id']; + + $sql = "SELECT search_array + FROM phpbb_search_results + WHERE search_id = '$search_id' + AND session_id = '". $userdata['session_id'] . "'"; + if( !$result = $db->sql_query($sql) ) + { + message_die(GENERAL_ERROR, "Couldn't obtain search results", "", __LINE__, __FILE__, $sql); + } + + if( $db->sql_numrows($result) ) + { + $row = $db->sql_fetchrow($result); + + $row = unserialize($row['search_array']); + $search_results = $row['results']; + $searchdata = $row['data']; + + if( $show_results == "posts") + { + $sql = "SELECT pt.post_text, pt.post_subject, p.*, f.forum_name, t.*, u.username, u.user_id, u.user_sig + FROM " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt + WHERE pt.post_id = p.post_id + AND f.forum_id = p.forum_id + AND p.topic_id = t.topic_id + AND p.poster_id = u.user_id + AND p.post_id IN ($search_results)"; + } + else + { + $sql = "SELECT t.*, f.forum_id, f.forum_name, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username + FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f, " . USERS_TABLE . " u, " . USERS_TABLE . " u2, " . POSTS_TABLE . " p + WHERE t.topic_id IN ($search_results) + AND f.forum_id = t.forum_id + AND u.user_id = t.topic_poster + AND p.post_id = t.topic_last_post_id + AND p.poster_id = u2.user_id"; + } + + $sql .= " ORDER BY " . $sortby_sql[$sortby] . " $sortby_dir"; + + if( !$result = $db->sql_query($sql) ) + { + message_die(GENERAL_ERROR, "Couldn't obtain search results", "", __LINE__, __FILE__, $sql); + } + + $searchset = $db->sql_fetchrowset($result); + } + else + { + header("Location: " . append_sid("search.$phpEx")); + } + } + + if( count($searchset) ) + { + + // + // Output header + // + $page_title = $lang['Search']; + include($phpbb_root_path . 'includes/page_header.'.$phpEx); + + // + // Define censored word matches + // + $orig_word = array(); + $replacement_word = array(); + obtain_word_list($orig_word, $replacement_word); + + if( $showresults == "posts" ) + { + $template->set_filenames(array( + "body" => "search_results_posts.tpl", + "jumpbox" => "jumpbox.tpl") + ); + } + else + { + $template->set_filenames(array( + "body" => "search_results_topics.tpl", + "jumpbox" => "jumpbox.tpl") + ); + } + + $jumpbox = make_jumpbox(); + $template->assign_vars(array( + "L_GO" => $lang['Go'], + "L_JUMP_TO" => $lang['Jump_to'], + "L_SELECT_FORUM" => $lang['Select_forum'], + + "S_JUMPBOX_LIST" => $jumpbox, + "S_JUMPBOX_ACTION" => append_sid("viewforum.$phpEx")) + ); + $template->assign_var_from_handle("JUMPBOX", "jumpbox"); + + $template->assign_vars(array( + "SEARCH_MATCHES" => count($searchset), + + "L_TOPIC" => $lang['Topic']) + ); + + for($j = 1; $j < count($searchdata); $j++) + { + $search_string[] = "'(" . preg_quote($searchdata[$j], "'") . ")'i"; + $replace_string[] = "\\1"; + } + + for($i = $start; $i < min($start + $board_config['posts_per_page'], count($searchset)); $i++) + { + $forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=" . $searchset[$i]['forum_id']); + $topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $searchset[$i]['topic_id']); + $poster_url = append_sid("profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $searchset[$i]['user_id']); + $post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . "=".$searchset[$i]['post_id']."#".$searchset[$i]['post_id']); + + $post_date = create_date($board_config['default_dateformat'], $searchset[$i]['post_time'], $board_config['board_timezone']); + + $message = $searchset[$i]['post_text']; + + if( $showresults == "posts" ) + { + if($return_chars != 0 ) + { + if($return_chars != -1) + { + $message = (strlen($message) > $return_chars) ? substr($message, 0, $return_chars) . " ..." : $message; + } + + // + // If the board has HTML off but the post has HTML + // on then we process it, else leave it alone + // + if( $return_chars != -1 ) + { + if( $searchset[$i]['enable_html'] ) + { + $message = preg_replace("#(<)([\/]?.*?)(>)#is", "<\\2>", $message); } + $message = preg_replace("/\:[0-9a-z\:]+\]/si", "]", $message); } else { - $message = ""; + $bbcode_uid = $searchset[$i]['bbcode_uid']; + $user_sig = $searchset[$i]['user_sig']; + + if( !$board_config['allow_html'] ) + { + if( $user_sig != "" && $searchset[$i]['enable_sig'] ) + { + $user_sig = preg_replace("#(<)([\/]?.*?)(>)#is", "<\\2>", $user_sig); + } + + if( $searchset[$i]['enable_html'] ) + { + $message = preg_replace("#(<)([\/]?.*?)(>)#is", "<\\2>", $message); + } + } + + if( $board_config['allow_bbcode'] && $bbcode_uid != "" ) + { + if( $user_sig != "" && $searchset[$i]['enable_sig'] ) + { + $sig_uid = make_bbcode_uid(); + $user_sig = bbencode_first_pass($user_sig, $sig_uid); + $user_sig = bbencode_second_pass($user_sig, $sig_uid); + } + + $message = bbencode_second_pass($message, $bbcode_uid); + } + else if( !$board_config['allow_bbcode'] && $bbcode_uid != "" ) + { + $message = preg_replace("/\:[0-9a-z\:]+\]/si", "]", $message); + } + + $message = make_clickable($message); + + if( $searchset[$i]['enable_sig'] ) + { + $message .= "

_________________
" . make_clickable($user_sig); + } } - $template->assign_block_vars("searchresults", array( - "TOPIC_TITLE" => $searchset[$i]['topic_title'], - "FORUM_NAME" => $searchset[$i]['forum_name'], - "POST_SUBJECT" => $searchset[$i]['post_subject'], - "POST_DATE" => $post_date, - "POSTER_NAME" => $searchset[$i]['username'], - "TOPIC_REPLIES" => $searchset[$i]['topic_replies'], - "TOPIC_VIEWS" => $searchset[$i]['topic_views'], - "MESSAGE" => $message, + if( count($orig_word) ) + { + $topic_title = preg_replace($orig_word, $replacement_word, $searchset[$i]['topic_title']); + $post_subject = ( $searchset[$i]['post_subject'] != "" ) ? preg_replace($orig_word, $replacement_word, $searchset[$i]['post_subject']) : $topic_title; - "U_POST" => $post_url, - "U_TOPIC" => $topic_url, - "U_FORUM" => $forum_url, - "U_USER_PROFILE" => $poster_url - )); + $message = preg_replace($orig_word, $replacement_word, $message); + } + if($board_config['allow_smilies'] && $searchset[$i]['enable_smilies']) + { + $message = smilies_pass($message); + } + + $message = str_replace("\n", "
", $message); + + if( count($searchdata) > 1 ) + { + $message = preg_replace($search_string, $replace_string, $message); + } } - $base_url = "search.php?q=" . urlencode($querystring) . "&a=" . urlencode($authorstring) . "&c=$return_chars&m=$searchall&f=$searchforum&b=" . urlencode($sortby) . "&dosearch=1"; + $template->assign_block_vars("searchresults", array( + "TOPIC_TITLE" => $topic_title, + "FORUM_NAME" => $searchset[$i]['forum_name'], + "POST_SUBJECT" => $post_subject, + "POST_DATE" => $post_date, + "POSTER_NAME" => $searchset[$i]['username'], + "TOPIC_REPLIES" => $searchset[$i]['topic_replies'], + "TOPIC_VIEWS" => $searchset[$i]['topic_views'], + "MESSAGE" => $message, - $template->assign_vars(array( - "PAGINATION" => generate_pagination($base_url, count($searchset), $board_config['posts_per_page'], $start), - "ON_PAGE" => (floor($start/$board_config['posts_per_page'])+1), - "TOTAL_PAGES" => ceil((count($searchset))/$board_config['posts_per_page']), - - "L_OF" => $lang['of'], - "L_PAGE" => $lang['Page'], - "L_GOTO_PAGE" => $lang['Goto_page']) + "U_POST" => $post_url, + "U_TOPIC" => $topic_url, + "U_FORUM" => $forum_url, + "U_USER_PROFILE" => $poster_url) ); + } + else + { + $message = ""; - $template->pparse("body"); + if( count($orig_word) ) + { + $topic_title = preg_replace($orig_word, $replacement_word, $searchset[$i]['topic_title']); + } - include($phpbb_root_path . 'includes/page_tail.'.$phpEx); + $topic_type = $searchset[$i]['topic_type']; + + if($topic_type == POST_ANNOUNCE) + { + $topic_type = $lang['Topic_Announcement'] . " "; + } + else if($topic_type == POST_STICKY) + { + $topic_type = $lang['Topic_Sticky'] . " "; + } + else + { + $topic_type = ""; + } + + if( $searchset[$i]['topic_vote'] ) + { + $topic_type .= $lang['Topic_Poll'] . " "; + } + + $forum_id = $searchset[$i]['forum_id']; + $topic_id = $searchset[$i]['topic_id']; + + $replies = $searchset[$i]['topic_replies']; + + if($replies > $board_config['posts_per_page']) + { + $goto_page = "   (\""" . $lang['Goto_page'] . ": "; + + $times = 1; + for($j = 0; $j < $replies + 1; $j += $board_config['posts_per_page']) + { + if($times > 4) + { + if( $j + $board_config['posts_per_page'] >= $replies + 1 ) + { + $goto_page .= " ... $times"; + } + } + else + { + if($times != 1) + { + $goto_page .= ", "; + } + $goto_page .= "$times"; + } + $times++; + } + $goto_page .= ")"; + } + else + { + $goto_page = ""; + } + + if($searchset[$i]['topic_status'] == TOPIC_LOCKED) + { + $folder_image = "\"""; + } + else if($searchset[$i]['topic_status'] == TOPIC_MOVED) + { + $topic_type = $lang['Topic_Moved'] . " "; + $topic_id = $searchset[$i]['topic_moved_id']; + } + else + { + if($searchset[$i]['topic_type'] == POST_ANNOUNCE) + { + $folder = $images['folder_announce']; + $folder_new = $images['folder_announce_new']; + } + else if($searchset[$i]['topic_type'] == POST_STICKY) + { + $folder = $images['folder_sticky']; + $folder_new = $images['folder_sticky_new']; + } + else + { + if($replies >= $board_config['hot_threshold']) + { + $folder = $images['folder_hot']; + $folder_new = $images['folder_new_hot']; + } + else + { + $folder = $images['folder']; + $folder_new = $images['folder_new']; + } + } + + if( empty($HTTP_COOKIE_VARS['phpbb2_' . $forum_id . '_' . $topic_id]) && $searchset[$i]['post_time'] > $userdata['session_last_visit'] ) + { + $folder_image = "\"""; + } + else + { + if( isset($HTTP_COOKIE_VARS['phpbb2_' . $forum_id . '_' . $topic_id]) ) + { + $folder_image = ($HTTP_COOKIE_VARS['phpbb2_' . $forum_id . '_' . $topic_id] < $searchset[$i]['post_time'] ) ? "\""" : "\"""; + } + else + { + $folder_image = "\"""; + } + } + } + + $topic_poster = $searchset[$i]['username']; + + $last_post_time = create_date($board_config['default_dateformat'], $searchset[$i]['post_time'], $board_config['board_timezone']); + + if($searchset[$i]['id2'] == ANONYMOUS && $searchset[$i]['post_username'] != '') + { + $last_post_user = $searchset[$i]['post_username']; + } + else + { + $last_post_user = $searchset[$i]['user2']; + } + + $last_post = $last_post_time . "
" . $lang['by'] . " "; + $last_post .= "" . $last_post_user . " "; + $last_post .= "\"""; + + $views = $searchset[$i]['topic_views']; + + $template->assign_block_vars("searchresults", array( + "FORUM_NAME" => $searchset[$i]['forum_name'], + "FORUM_ID" => $forum_id, + "TOPIC_ID" => $topic_id, + "FOLDER" => $folder_image, + "TOPIC_POSTER" => $topic_poster, + "GOTO_PAGE" => $goto_page, + "REPLIES" => $replies, + "TOPIC_TITLE" => $topic_title, + "TOPIC_TYPE" => $topic_type, + "VIEWS" => $views, + "LAST_POST" => $last_post, + + "U_VIEW_FORUM" => $forum_url, + "U_VIEW_TOPIC" => $topic_url, + "U_TOPIC_POSTER_PROFILE" => $topic_poster_profile_url) + ); } } + + $base_url = "search.$phpEx?search_id=$search_id&showresults=" . $show_results . "&sortby=" . $sortby . "&sortdir=" . $sortby_dir . "&charsreqd=" . $return_chars; + + $template->assign_vars(array( + "PAGINATION" => generate_pagination($base_url, count($searchset), $board_config['posts_per_page'], $start), + "ON_PAGE" => (floor($start/$board_config['posts_per_page'])+1), + "TOTAL_PAGES" => ceil((count($searchset))/$board_config['posts_per_page']), + + "L_OF" => $lang['of'], + "L_PAGE" => $lang['Page'], + "L_GOTO_PAGE" => $lang['Goto_page']) + ); + + $template->pparse("body"); + + include($phpbb_root_path . 'includes/page_tail.'.$phpEx); } } // -// This will be replaced by -// an auth function return of -// all accessible forums ... I think +// Search forum // -$sql = "SELECT forum_name, forum_id - FROM " . FORUMS_TABLE . " - ORDER BY cat_id, forum_order"; +$sql = "SELECT c.cat_title, c.cat_id, f.forum_name, f.forum_id + FROM " . CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f + WHERE f.cat_id = c.cat_id + ORDER BY c.cat_id, f.forum_order"; $result = $db->sql_query($sql); if(!$result) { - message_die(QUERY_ERROR, "Couldn't obtain forum_name/forum_id", __LINE__, __FILE__); + message_die(GENERAL_ERROR, "Couldn't obtain forum_name/forum_id", "", __LINE__, __FILE__, $sql); } $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); -$s_forums = ""; +$s_forums = ""; while($row = $db->sql_fetchrow($result)) { if($is_auth_ary[$row['forum_id']]['auth_read']) { - $s_forums .= ""; + $s_forums .= ""; + if(empty($list_cat[$row['cat_id']])) + { + $list_cat[$row['cat_id']] = $row['cat_title']; + } } } -$s_characters = ""; +// +// Category to search +// +$s_categories = ""; +while( list($cat_id, $cat_title) = each($list_cat)) +{ + $s_categories .= ""; +} + +// +// Number of chars returned +// +$s_characters = ""; $s_characters .= ""; $s_characters .= ""; $s_characters .= ""; + for($i = 100; $i < 1100 ; $i += 100) { - $s_characters .= ""; + $selected = ($i == 200) ? "selected=\"selected\"" : ""; + $s_characters .= ""; } +// +// Sorting +// $s_sortby = ""; for($i = 0; $i < count($sortby_types); $i++) { - $s_sortby .= ""; + $s_sortby .= ""; } +// +// Search time +// +$previous_days = array(0, 1, 7, 14, 30, 90, 180, 364); +$previous_days_text = array($lang['All'], "1 " . $lang['Day'], "7 " . $lang['Days'], "2 " . $lang['Weeks'], "1 " . $lang['Month'], "3 ". $lang['Months'], "6 " . $lang['Months'], "1 " . $lang['Year']); + +$s_time = ""; + +$page_title = $lang['Search']; include($phpbb_root_path . 'includes/page_header.'.$phpEx); $template->set_filenames(array( "body" => "search_body.tpl", "jumpbox" => "jumpbox.tpl") ); + $jumpbox = make_jumpbox(); $template->assign_vars(array( - "JUMPBOX_LIST" => $jumpbox, - "SELECT_NAME" => POST_FORUM_URL) + "L_GO" => $lang['Go'], + "L_JUMP_TO" => $lang['Jump_to'], + "L_SELECT_FORUM" => $lang['Select_forum'], + + "S_JUMPBOX_LIST" => $jumpbox, + "S_JUMPBOX_ACTION" => append_sid("viewforum.$phpEx")) ); $template->assign_var_from_handle("JUMPBOX", "jumpbox"); -$s_hidden_fields = ""; - $template->assign_vars(array( + "L_SEARCH_QUERY" => $lang['Search_query'], + "L_SEARCH_OPTIONS" => $lang['Search_options'], + "L_SEARCH_KEYWORDS" => $lang['Search_keywords'], + "L_SEARCH_KEYWORDS_EXPLAIN" => $lang['Search_keywords_explain'], + "L_SEARCH_AUTHOR" => $lang['Search_author'], + "L_SEARCH_AUTHOR_EXPLAIN" => $lang['Search_author_explain'], "L_SEARCH_ANY_TERMS" => $lang['Search_for_any'], "L_SEARCH_ALL_TERMS" => $lang['Search_for_all'], - "L_SEARCH_AUTHOR" => $lang['Search_author'], - "L_LIMIT_CHARACTERS" => $lang['Limit_chars'], + "L_CATEGORY" => $lang['Category'], + "L_RETURN_FIRST" => $lang['Return_first'], + "L_CHARACTERS" => $lang['characters'], "L_SORT_BY" => $lang['Sort_by'], "L_SORT_ASCENDING" => $lang['Sort_Ascending'], - "L_SORT_DECENDING" => $lang['Sort_Decending'], + "L_SORT_DESCENDING" => $lang['Sort_Decending'], + "L_SEARCH_PREVIOUS" => $lang['Search_previous'], + "L_DISPLAY_RESULTS" => $lang['Display_results'], "S_SEARCH_ACTION" => append_sid("search.$phpEx"), "S_CHARACTER_OPTIONS" => $s_characters, - "S_FORUM_OPTIONS" => $s_forums, + "S_FORUM_OPTIONS" => $s_forums, + "S_CATEGORY_OPTIONS" => $s_categories, + "S_TIME_OPTIONS" => $s_time, "S_SORT_OPTIONS" => $s_sortby, "S_HIDDEN_FIELDS" => $s_hidden_fields) ); diff --git a/phpBB/templates/PSO/index_body.tpl b/phpBB/templates/PSO/index_body.tpl index ab00dea929..8a67312b15 100644 --- a/phpBB/templates/PSO/index_body.tpl +++ b/phpBB/templates/PSO/index_body.tpl @@ -2,6 +2,7 @@ +
{SITENAME} {L_INDEX}{L_SEARCH_NEW}
@@ -26,7 +27,7 @@ {catrow.forumrow.FORUM_NAME}
{catrow.forumrow.FORUM_DESC} {catrow.forumrow.TOPICS} {catrow.forumrow.POSTS} - {catrow.forumrow.LAST_POST} + {catrow.forumrow.LAST_POST} {catrow.forumrow.MODERATORS} diff --git a/phpBB/templates/PSO/search_body.tpl b/phpBB/templates/PSO/search_body.tpl index b71f2c7607..5e2bab929c 100644 --- a/phpBB/templates/PSO/search_body.tpl +++ b/phpBB/templates/PSO/search_body.tpl @@ -1,45 +1,54 @@ -
+
- + -
{SITENAME} {L_INDEX}{SITENAME} {L_INDEX}
+ -
- - +
+
+ + - -
- + - - + + - - + + - - + - - + + + + - - + + + + - + + + + + + +
 {L_SEARCH} {L_SEARCH_QUERY}
Search query: 
{L_SEARCH_ANY_TERMS}
{L_SEARCH_ALL_TERMS}
{L_SEARCH_KEYWORDS}:
{L_SEARCH_KEYWORDS_EXPLAIN}

{L_SEARCH_ANY_TERMS}
{L_SEARCH_ALL_TERMS}
{L_SEARCH_AUTHOR}: {L_SEARCH_AUTHOR}:
{L_SEARCH_AUTHOR_EXPLAIN}
{L_FORUM}: {L_SEARCH_OPTIONS}
{L_LIMIT_CHARACTERS}: {L_FORUM}: {L_RETURN_FIRST} {L_CHARACTERS}
{L_SORT_BY}:    {L_SORT_ASCENDING}    {L_SORT_DECENDING} {L_CATEGORY}: {L_SORT_BY}: 
 {L_SORT_ASCENDING}    {L_SORT_DESCENDING} 
{S_HIDDEN_FIELDS}{L_DISPLAY_RESULTS}:  {L_POSTS}    {L_TOPICS} {L_SEARCH_PREVIOUS}: {S_TIME_OPTIONS}
{S_HIDDEN_FIELDS}
+
-
+
- + -
{S_TIMEZONE}{S_TIMEZONE} {JUMPBOX}
\ No newline at end of file + diff --git a/phpBB/templates/PSO/search_results_posts.tpl b/phpBB/templates/PSO/search_results_posts.tpl new file mode 100644 index 0000000000..2e1337397c --- /dev/null +++ b/phpBB/templates/PSO/search_results_posts.tpl @@ -0,0 +1,72 @@ + + + + +
{SITENAME} {L_INDEX}
+ + + + + +
+ + + +
 {L_SEARCH} - {SEARCH_MATCHES} Matches 
+ +
+ + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
 {L_FORUM}: {searchresults.FORUM_NAME}
+ + + +
{searchresults.POSTER_NAME}

{L_REPLIES}: {searchresults.TOPIC_REPLIES}
{L_VIEWS}: {searchresults.TOPIC_VIEWS}
+ + + +
{L_TOPIC}: {searchresults.TOPIC_TITLE}
+ + + + + + +
Post image icon{L_POSTED}: {searchresults.POST_DATE}     Post Subject: {searchresults.POST_SUBJECT}
{searchresults.MESSAGE}

+ + + + +
 {L_PAGE} {ON_PAGE} {L_OF} {TOTAL_PAGES} {PAGINATION}
+ +
+ +
+ + + + +
{S_TIMEZONE}{JUMPBOX}
\ No newline at end of file diff --git a/phpBB/templates/PSO/search_results_topics.tpl b/phpBB/templates/PSO/search_results_topics.tpl new file mode 100644 index 0000000000..f63f825066 --- /dev/null +++ b/phpBB/templates/PSO/search_results_topics.tpl @@ -0,0 +1,58 @@ + + + + + +
{SITENAME} {L_INDEX}
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 {L_SEARCH} - {SEARCH_MATCHES} Matches 
  {L_FORUM}  {L_TOPICS}  {L_REPLIES}  {L_AUTHOR}  {L_VIEWS}  {L_LASTPOST} 
 {searchresults.FOLDER}  {searchresults.FORUM_NAME} {searchresults.TOPIC_TYPE}{searchresults.TOPIC_TITLE} {searchresults.GOTO_PAGE}{searchresults.REPLIES}{searchresults.TOPIC_POSTER}{searchresults.VIEWS}{searchresults.LAST_POST}
{L_NO_TOPICS}
+ + + + +
   {L_PAGE} {ON_PAGE} {L_OF} {TOTAL_PAGES} {PAGINATION} 
+ +
+ + + + + + +
{S_TIMEZONE}{JUMPBOX}
\ No newline at end of file