Fix issues with view posts since last visit, errors on next page, re-introduce external stopword list, examine feasibility of stemmer, tidy ups ...

git-svn-id: file:///svn/phpbb/trunk@2205 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2002-02-25 01:00:48 +00:00
parent b9b87a04fa
commit 508b6d60ef
8 changed files with 674 additions and 661 deletions

View file

@ -0,0 +1,51 @@
<?php
//
// phpBB 2.x auto-generated config file
// Do not change anything in this file!
//
$dbms = "mysql4";
$dbhost = "localhost";
$dbname = "dev_starstreak_net";
$dbuser = "devhttp";
$dbpasswd = "efx2KarizonaD";
$dbhost = "localhost";
$dbname = "phpbb_com";
$dbuser = "devhttp";
$dbpasswd = "efx2KarizonaD";
/*
$dbhost = "localhost";
$dbname = "phpbb_test";
$dbuser = "devhttp";
$dbpasswd = "efx2KarizonaD";
$dbms = "mssql-odbc";
$dbhost = "phpbb_test_mssql_odbc";
$dbname = "";
$dbuser = "devhttp";
$dbpasswd = "efx2KarizonaD";
$dbms = "msaccess";
$dbhost = "phpbb_test_msaccess_odbc";
$dbname = "";
$dbuser = "devhttp";
$dbpasswd = "efx2KarizonaD";
$dbms = "mssql";
$dbhost = "localhost";
$dbname = "phpbb_com";
$dbuser = "devhttp";
$dbpasswd = "efx2KarizonaD";
*/
$table_prefix = "phpbb_";
define('PHPBB_INSTALLED', true);
?>

View file

@ -7,55 +7,41 @@
// Remove or comment the next line (die(".... ) to enable this script. // Remove or comment the next line (die(".... ) to enable this script.
// Do NOT FORGET to either remove this script or disable it after you have used it. // Do NOT FORGET to either remove this script or disable it after you have used it.
// //
die("Please read the first lines of this script for instructions on how to enable it");
// //
// Do not change anything below this line. // Do not change anything below this line.
// //
set_time_limit(0); set_time_limit(0);
$common_percent = 0.4; // Percentage of posts in which a word has to appear to be marked as common
$phpbb_root_path = "../"; $phpbb_root_path = "../";
include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'config.'.$phpEx); include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/constants.'.$phpEx);
include($phpbb_root_path . 'includes/db.'.$phpEx);
include($phpbb_root_path . 'includes/functions.'.$phpEx);
include($phpbb_root_path . 'includes/search.'.$phpEx); include($phpbb_root_path . 'includes/search.'.$phpEx);
$common_percent = 0.4; // Percentage of posts in which a word has to appear to be marked as common
print "<html>\n<body>\n"; print "<html>\n<body>\n";
// //
// Try and load stopword and synonym files // Try and load stopword and synonym files
// //
//$stopword_array = file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_stopwords.txt");
//$synonym_array = file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_synonyms.txt");
// This needs fixing! Shouldn't be hardcoded to English files! // This needs fixing! Shouldn't be hardcoded to English files!
//$stopword_array = file($phpbb_root_path . "language/lang_english/search_stopwords.txt"); $stopword_array = file($phpbb_root_path . "language/lang_english/search_stopwords.txt");
$synonym_array = file($phpbb_root_path . "language/lang_english/search_synonyms.txt"); $synonym_array = file($phpbb_root_path . "language/lang_english/search_synonyms.txt");
/*
for ($j = 0; $j < count($stopword_array); $j++)
{
$filter_word = trim(strtolower($stopword_array[$j]));
$search[] = "/\b" . phpbb_preg_quote($filter_word, "/") . "\b/is";
$replace[] = '';
}
*/
// //
// Fetch a batch of posts_text entries // Fetch a batch of posts_text entries
// //
$sql = "SELECT count(*) as total, max(post_id) as max_post_id $sql = "SELECT COUNT(*) as total, MAX(post_id) as max_post_id
FROM ". POSTS_TEXT_TABLE; FROM ". POSTS_TEXT_TABLE;
if(!$result = $db->sql_query($sql)) if ( !($result = $db->sql_query($sql)) )
{ {
$error = $db->sql_error(); $error = $db->sql_error();
die("Couldn't get maximum post ID :: " . $sql . " :: " . $error['message']); die("Couldn't get maximum post ID :: " . $sql . " :: " . $error['message']);
} }
$max_post_id = $db->sql_fetchrow($result); $max_post_id = $db->sql_fetchrow($result);
$totalposts = $max_post_id['total']; $totalposts = $max_post_id['total'];
$max_post_id = $max_post_id['max_post_id']; $max_post_id = $max_post_id['max_post_id'];
@ -74,15 +60,18 @@ for(;$postcounter <= $max_post_id; $postcounter += $batchsize)
WHERE post_id WHERE post_id
BETWEEN $batchstart BETWEEN $batchstart
AND $batchend"; AND $batchend";
if(!$posts_result = $db->sql_query($sql)) if( !($result = $db->sql_query($sql)) )
{ {
$error = $db->sql_error(); $error = $db->sql_error();
die("Couldn't get post_text :: " . $sql . " :: " . $error['message']); die("Couldn't get post_text :: " . $sql . " :: " . $error['message']);
} }
$rowset = $db->sql_fetchrowset($posts_result); $rowset = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
if( $post_rows = $db->sql_numrows($posts_result) ) $post_rows = count($rowset);
if( $post_rows )
{ {
// $sql = "LOCK TABLES ".POST_TEXT_TABLE." WRITE"; // $sql = "LOCK TABLES ".POST_TEXT_TABLE." WRITE";
@ -92,18 +81,14 @@ for(;$postcounter <= $max_post_id; $postcounter += $batchsize)
// For every post in the batch: // For every post in the batch:
for($post_nr = 0; $post_nr < $post_rows; $post_nr++ ) for($post_nr = 0; $post_nr < $post_rows; $post_nr++ )
{ {
print "."; print ".";
flush(); flush();
$matches = array();
$post_id = $rowset[$post_nr]['post_id']; $post_id = $rowset[$post_nr]['post_id'];
$text = clean_words("post", $rowset[$post_nr]['post_text'], $synonym_array); // Cleaned up post
$text_title = clean_words("post", $rowset[$post_nr]['post_subject'], $synonym_array);
$matches = array(); $matches = array();
$matches['text'] = split_words($text); $matches['text'] = split_words(clean_words("post", $rowset[$post_nr]['post_text'], $stopword_array, $synonym_array));
$matches['title'] = split_words($text_title); $matches['title'] = split_words(clean_words("post", $rowset[$post_nr]['post_subject'], $stopword_array, $synonym_array));
while( list($match_type, $match_ary) = @each($matches) ) while( list($match_type, $match_ary) = @each($matches) )
{ {
@ -190,12 +175,6 @@ for(;$postcounter <= $max_post_id; $postcounter += $batchsize)
// $result = $db->sql_query($sql); // $result = $db->sql_query($sql);
} }
else
{
print "Couldn't get rowcount for number of posts<br>$sql<br>\n";
} // All posts;
$db->sql_freeresult($posts_result);
// Remove common words after the first 2 batches and after every 4th batch after that. // Remove common words after the first 2 batches and after every 4th batch after that.
if( $batchcount % 4 == 3 ) if( $batchcount % 4 == 3 )

View file

@ -19,7 +19,7 @@
* *
***************************************************************************/ ***************************************************************************/
function clean_words($mode, &$entry, &$synonym_list) function clean_words($mode, &$entry, &$stopword_list, &$synonym_list)
{ {
// Weird, $init_match doesn't work with static when double quotes (") are used... // Weird, $init_match doesn't work with static when double quotes (") are used...
static $drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', "'", '|', ',', '@', '_', '?', '%', '-', '~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!'); static $drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', "'", '|', ',', '@', '_', '?', '%', '-', '~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!');
@ -37,16 +37,16 @@ function clean_words($mode, &$entry, &$synonym_list)
if( $mode == "post" ) if( $mode == "post" )
{ {
// HTML entities like &nbsp;
$entry = preg_replace("/\b&[a-z]+;\b/is", " ", $entry);
// Replace line endings by a space // Replace line endings by a space
$entry = preg_replace("/[\n\r]/is", " ", $entry); $entry = preg_replace("/[\n\r]/is", " ", $entry);
// HTML entities like &nbsp;
$entry = preg_replace("/\b&[a-z]+;\b/", " ", $entry);
// Remove URL's // Remove URL's
$entry = preg_replace("/\b[a-z0-9]+:\/\/[a-z0-9\.\-]+(\/[a-z0-9\?\.%_\-\+=&\/]+)?/si", " ", $entry); $entry = preg_replace("/\b[a-z0-9]+:\/\/[a-z0-9\.\-]+(\/[a-z0-9\?\.%_\-\+=&\/]+)?/", " ", $entry);
// Quickly remove BBcode. // Quickly remove BBcode.
$entry = preg_replace("/\[img:[a-z0-9]{10,}\].*?\[\/img:[a-z0-9]{10,}\]/is", " ", $entry); $entry = preg_replace("/\[img:[a-z0-9]{10,}\].*?\[\/img:[a-z0-9]{10,}\]/", " ", $entry);
$entry = preg_replace("/\[\/?url(=.*?)?\]/si", " ", $entry); $entry = preg_replace("/\[\/?url(=.*?)?\]/", " ", $entry);
$entry = preg_replace("/\[\/?[a-z\*=\+\-]+(\:?[0-9a-z]+)?:[a-z0-9]{10,}(\:[a-z0-9]+)?=?.*?\]/si", " ", $entry); $entry = preg_replace("/\[\/?[a-z\*=\+\-]+(\:?[0-9a-z]+)?:[a-z0-9]{10,}(\:[a-z0-9]+)?=?.*?\]/", " ", $entry);
} }
else if( $mode == "search" ) else if( $mode == "search" )
{ {
@ -55,7 +55,7 @@ function clean_words($mode, &$entry, &$synonym_list)
} }
// Replace numbers on their own // Replace numbers on their own
$entry = preg_replace("/\b[0-9]+\b/si", " ", $entry); $entry = preg_replace("/\b[0-9]+\b/", " ", $entry);
// //
// Filter out strange characters like ^, $, &, change "it's" to "its" // Filter out strange characters like ^, $, &, change "it's" to "its"
@ -69,8 +69,21 @@ function clean_words($mode, &$entry, &$synonym_list)
{ {
$entry = str_replace("*", " ", $entry); $entry = str_replace("*", " ", $entry);
// 'words' that consist of <=3 or >=50 characters are removed. // 'words' that consist of <=3 or >=25 characters are removed.
$entry = preg_replace("/\b([a-z0-9]{1,3}|[a-z0-9]{50,})\b/si", " ", $entry); $entry = preg_replace("/\b([a-z0-9]{1,3}|[a-z0-9]{25,})\b/", " ", $entry);
}
if( !empty($stopword_list) )
{
for ($j = 0; $j < count($stopword_list); $j++)
{
$stopword = trim($stopword_list[$j]);
if ( $mode == "post" || ( $stopword != "not" && $stopword != "and" && $stopword != "or" ) )
{
$entry = preg_replace("/\b" . $stopword . "\b/", " ", $entry);
}
}
} }
if( !empty($synonym_list) ) if( !empty($synonym_list) )
@ -78,11 +91,9 @@ function clean_words($mode, &$entry, &$synonym_list)
for ($j = 0; $j < count($synonym_list); $j++) for ($j = 0; $j < count($synonym_list); $j++)
{ {
list($replace_synonym, $match_synonym) = split(" ", trim(strtolower($synonym_list[$j]))); list($replace_synonym, $match_synonym) = split(" ", trim(strtolower($synonym_list[$j])));
if ( $mode == "post" || ( $match_synonym != "not" && $match_synonym != "and" && $match_synonym != "or" ) )
if( ( $match_synonym != "and" && $match_synonym != "or" && $match_synonym != "not" &&
$replace_synonym != "and" && $replace_synonym != "or" && $replace_synonym != "not" ) || $mode == "post" )
{ {
$entry = preg_replace("/\b" . phpbb_preg_quote(trim($match_synonym), "/") . "\b/is", " " . trim($replace_synonym) . " ", $entry); $entry = preg_replace("/\b" . trim($match_synonym) . "\b/", " " . trim($replace_synonym) . " ", $entry);
} }
} }
} }
@ -98,7 +109,7 @@ function split_words(&$entry, $mode = "post")
} }
else else
{ {
preg_match_all("/(\*?[a-z0-9]+\*?)|\b([a-z0-9]+)\b/is", $entry, $split_entries); preg_match_all("/(\*?[a-z0-9]+\*?)|\b([a-z0-9]+)\b/", $entry, $split_entries);
} }
return $split_entries[1]; return $split_entries[1];
@ -108,11 +119,12 @@ function add_search_words($post_id, $post_text, $post_title = "")
{ {
global $db, $phpbb_root_path, $board_config, $lang; global $db, $phpbb_root_path, $board_config, $lang;
$stopwords_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_stopwords.txt");
$synonym_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_synonyms.txt"); $synonym_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_synonyms.txt");
$search_raw_words = array(); $search_raw_words = array();
$search_raw_words['text'] = split_words(clean_words("post", $post_text, $synonym_array)); $search_raw_words['text'] = split_words(clean_words('post', $post_text, $stopword_array, $synonym_array));
$search_raw_words['title'] = split_words(clean_words("post", $post_title, $synonym_array)); $search_raw_words['title'] = split_words(clean_words('post', $post_title, $stopword_array, $synonym_array));
$word = array(); $word = array();
$word_insert_sql = array(); $word_insert_sql = array();
@ -389,4 +401,81 @@ function remove_unmatched_words()
return 0; return 0;
} }
//
// Username search
//
function username_search($search_match, $is_inline_review = 0, $default_list = "")
{
global $db, $board_config, $template, $lang, $images, $theme, $phpEx, $phpbb_root_path;
global $starttime;
$author_list = '';
if ( !empty($search_match) )
{
$username_search = preg_replace("/\*/", "%", trim(strip_tags($search_match)));
$sql = "SELECT username
FROM " . USERS_TABLE . "
WHERE username LIKE '" . str_replace("\'", "''", $username_search) . "'
ORDER BY username";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Couldn't obtain search results", "", __LINE__, __FILE__, $sql);
}
if ( $row = $db->sql_fetchrow($result) )
{
do
{
$author_list .= '<option value="' . $row['username'] . '">' .$row['username'] . '</option>';
}
while ( $row = $db->sql_fetchrow($result) );
}
else
{
$author_list = '<option>' . $lang['No_match']. '</option>';
}
}
if ( !$is_inline_review )
{
$gen_simple_header = TRUE;
$page_title = $lang['Search'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
$template->set_filenames(array(
"search_user_body" => "search_username.tpl")
);
$template->assign_vars(array(
"L_CLOSE_WINDOW" => $lang['Close_window'],
"L_SEARCH_USERNAME" => $lang['Find_username'],
"L_UPDATE_USERNAME" => $lang['Select_username'],
"L_SELECT" => $lang['Select'],
"L_SEARCH" => $lang['Search'],
"L_SEARCH_EXPLAIN" => $lang['Search_author_explain'],
"L_CLOSE_WINDOW" => $lang['Close_window'],
"S_AUTHOR_OPTIONS" => $author_list,
"S_SEARCH_ACTION" => append_sid("search.$phpEx?mode=searchuser"))
);
//
// If we have results then dump them out and enable
// the appropriate switch block
//
if ( !empty($author_list) )
{
$template->assign_block_vars("switch_select_name", array());
}
$template->pparse("search_user_body");
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
}
return($author_list);
}
?> ?>

View file

@ -8,30 +8,16 @@ andy andrew
anemia anaemia anemia anaemia
anemic anaemic anemic anaemic
anesthesia anaesthesia anesthesia anaesthesia
anesthesiologist anaesthesiologist
anesthesiololy anaesthesiology
anesthetic anaesthetic
anesthetist anaesthetist
appologize appologise appologize appologise
appologized appologised
appologizing appologising
apr april
archean archaean archean archaean
archeology archaeology archeology archaeology
archeozoic archaeozoic archeozoic archaeozoic
armor armour armor armour
armored armoured
armory armoury
armorment armourment
artic arctic artic arctic
attachment attachement attachment attachement
attachments attachements
attendence attendance attendence attendance
aug august
barbecue barbeque barbecue barbeque
bbq barbeque
behavior behaviour behavior behaviour
behaviorism behaviourism
biassed biased biassed biased
biol biology biol biology
buletin bulletin buletin bulletin
@ -43,18 +29,13 @@ cenozoic caenozoic
center centre center centre
check cheque check cheque
color colour color colour
colored coloured
coloring colouring
colorless colourless
comission commission comission commission
comittee committee comittee committee
commitee committee commitee committee
conceed concede conceed concede
creating createing creating createing
curiculum curriculum curiculum curriculum
dec december
defense defence defense defence
dept department
develope develop develope develop
discription description discription description
dulness dullness dulness dullness
@ -66,7 +47,6 @@ exhorbitant exorbitant
exhuberant exuberant exhuberant exuberant
existance existence existance existence
favorite favourite favorite favourite
feb february
fetus foetus fetus foetus
ficticious fictitious ficticious fictitious
flavor flavour flavor flavour
@ -78,66 +58,43 @@ geneology genealogy
grammer grammar grammer grammar
gray grey gray grey
guerilla guerrilla guerilla guerrilla
gynecological gynaecological
gynecologist gynaecologist
gynecology gynaecology gynecology gynaecology
harbor harbour harbor harbour
heighth height heighth height
hemaglobin haemaglobin hemaglobin haemaglobin
hematin haematin hematin haematin
hematite haematite hematite haematite
hematologist haematologist
hematology haematology hematology haematology
hemophilia haemophilia
hemorrhage haemorrhage
hemorrhoids haemorrhoids
honor honour honor honour
innoculate inoculate innoculate inoculate
installment instalment installment instalment
irrelevent irrelevant irrelevent irrelevant
irrevelant irrelevant irrevelant irrelevant
jan january
jeweler jeweller jeweler jeweller
judgement judgment judgement judgment
jul july
jun june
labeled labelled labeled labelled
labor labour labor labour
laborer labourer laborer labourer
laborers labourers laborers labourers
laboring labouring laboring labouring
lib library
licence license licence license
liesure leisure liesure leisure
liquify liquefy liquify liquefy
maintainance maintenance maintainance maintenance
maintenence maintenance maintenence maintenance
marshal marshall
medieval mediaeval medieval mediaeval
medievalism mediaevalism
medievalist mediaevalist
meg margaret
meter metre meter metre
milage mileage milage mileage
millipede millepede millipede millepede
miscelaneous miscellaneous miscelaneous miscellaneous
morgage mortgage morgage mortgage
noticable noticeable noticable noticeable
nov november
occurence occurrence occurence occurrence
oct october
offense offence offense offence
ommision omission ommision omission
ommission omission ommission omission
optimize optimize optimize optimize
optimizer optimiser
optimizing optimising
optimized optimised
organisation organization
organise organize organise organize
organised organized
organising organizing
organiser organizer
pajamas pyjamas pajamas pyjamas
paleography palaeography paleography palaeography
paleolithic palaeolithic paleolithic palaeolithic
@ -158,7 +115,6 @@ personel personnel
practise practice practise practice
program programme program programme
psych psychology psych psychology
qld queensland
questionaire questionnaire questionaire questionnaire
rarify rarefy rarify rarefy
reccomend recommend reccomend recommend
@ -178,7 +134,6 @@ supersede supercede
suprise surprise suprise surprise
surprize surprise surprize surprise
synchronise synchronize synchronise synchronize
tas tasmania
temperary temporary temperary temporary
theater theatre theater theatre
threshhold threshold threshhold threshold
@ -187,7 +142,6 @@ truely truly
truley truly truley truly
useable usable useable usable
valor valour valor valour
vic victoria
vigor vigour vigor vigour
vol volume vol volume
whack wack whack wack

View file

@ -29,7 +29,7 @@ include($phpbb_root_path . 'includes/search.'.$phpEx);
// //
// Start session management // Start session management
// //
$userdata = session_pagestart($user_ip, PAGE_SEARCH, $board_config['session_length']); $userdata = session_pagestart($user_ip, PAGE_SEARCH);
init_userprefs($userdata); init_userprefs($userdata);
// //
// End session management // End session management
@ -44,68 +44,68 @@ if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
} }
else else
{ {
$mode = ""; $mode = '';
} }
if( isset($HTTP_POST_VARS['search_keywords']) || isset($HTTP_GET_VARS['search_keywords']) ) 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']; $search_keywords = ( isset($HTTP_POST_VARS['search_keywords']) ) ? $HTTP_POST_VARS['search_keywords'] : $HTTP_GET_VARS['search_keywords'];
} }
else else
{ {
$query_keywords = ""; $search_keywords = '';
} }
if( isset($HTTP_POST_VARS['search_author']) || isset($HTTP_GET_VARS['search_author'])) 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']; $search_author = ( isset($HTTP_POST_VARS['search_author']) ) ? $HTTP_POST_VARS['search_author'] : $HTTP_GET_VARS['search_author'];
} }
else else
{ {
$query_author = ""; $search_author = '';
} }
$search_id = ( isset($HTTP_GET_VARS['search_id']) ) ? $HTTP_GET_VARS['search_id'] : ""; $search_id = ( isset($HTTP_GET_VARS['search_id']) ) ? $HTTP_GET_VARS['search_id'] : "";
$show_results = ( isset($HTTP_POST_VARS['showresults']) ) ? $HTTP_POST_VARS['showresults'] : "posts"; $show_results = ( isset($HTTP_POST_VARS['show_results']) ) ? $HTTP_POST_VARS['show_results'] : "posts";
if( isset($HTTP_POST_VARS['addterms']) ) if( isset($HTTP_POST_VARS['search_terms']) )
{ {
$search_all_terms = ( $HTTP_POST_VARS['addterms'] == "all" ) ? 1 : 0; $search_terms = ( $HTTP_POST_VARS['search_terms'] == "all" ) ? 1 : 0;
} }
else else
{ {
$search_all_terms = 0; $search_terms = 0;
} }
if( isset($HTTP_POST_VARS['searchfields']) ) if( isset($HTTP_POST_VARS['search_fields']) )
{ {
$search_msg_title = ( $HTTP_POST_VARS['searchfields'] == "all" ) ? 1 : 0; $search_fields = ( $HTTP_POST_VARS['search_fields'] == "all" ) ? 1 : 0;
} }
else else
{ {
$search_msg_title = 0; $search_fields = 0;
} }
$return_chars = ( isset($HTTP_POST_VARS['charsreqd']) ) ? intval($HTTP_POST_VARS['charsreqd']) : 200; $return_chars = ( isset($HTTP_POST_VARS['return_chars']) ) ? intval($HTTP_POST_VARS['return_chars']) : 200;
$search_cat = ( isset($HTTP_POST_VARS['searchcat']) ) ? intval($HTTP_POST_VARS['searchcat']) : -1; $search_cat = ( isset($HTTP_POST_VARS['search_cat']) ) ? intval($HTTP_POST_VARS['search_cat']) : -1;
$search_forum = ( isset($HTTP_POST_VARS['searchforum']) ) ? intval($HTTP_POST_VARS['searchforum']) : -1; $search_forum = ( isset($HTTP_POST_VARS['search_forum']) ) ? intval($HTTP_POST_VARS['search_forum']) : -1;
$sortby = ( isset($HTTP_POST_VARS['sortby']) ) ? intval($HTTP_POST_VARS['sortby']) : 0; $sort_by = ( isset($HTTP_POST_VARS['sort_by']) ) ? intval($HTTP_POST_VARS['sort_by']) : 0;
if( isset($HTTP_POST_VARS['sortdir']) ) if( isset($HTTP_POST_VARS['sort_dir']) )
{ {
$sortby_dir = ( $HTTP_POST_VARS['sortdir'] == "DESC" ) ? "DESC" : "ASC"; $sort_dir = ( $HTTP_POST_VARS['sort_dir'] == "DESC" ) ? "DESC" : "ASC";
} }
else else
{ {
$sortby_dir = "DESC"; $sort_dir = "DESC";
} }
if(!empty($HTTP_POST_VARS['resultdays']) ) if(!empty($HTTP_POST_VARS['search_time']) )
{ {
$search_time = time() - ( intval($HTTP_POST_VARS['resultdays']) * 86400 ); $search_time = time() - ( intval($HTTP_POST_VARS['search_time']) * 86400 );
} }
else else
{ {
@ -117,13 +117,13 @@ $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) :
// //
// Define some globally used data // Define some globally used data
// //
$sortby_types = array($lang['Sort_Time'], $lang['Sort_Post_Subject'], $lang['Sort_Topic_Title'], $lang['Sort_Author'], $lang['Sort_Forum']); $sort_by_types = array($lang['Sort_Time'], $lang['Sort_Post_Subject'], $lang['Sort_Topic_Title'], $lang['Sort_Author'], $lang['Sort_Forum']);
$sortby_sql = array("p.post_time", "pt.post_subject", "t.topic_title", "u.username", "f.forum_id"); $sort_by_sql = array("p.post_time", "pt.post_subject", "t.topic_title", "u.username", "f.forum_id");
// //
// Begin core code // Begin core code
// //
if( $mode == "searchuser" ) if( $mode == 'searchuser' )
{ {
// //
// This handles the simple windowed user search // This handles the simple windowed user search
@ -143,16 +143,20 @@ if( $mode == "searchuser" )
exit; exit;
} }
else if( $query_keywords != "" || $query_author != "" || $search_id ) else if( $search_keywords != '' || $search_author != '' || $search_id )
{ {
$store_vars = array('search_results', 'total_match_count', 'split_search', 'sort_by', 'sort_dir', 'show_results', 'return_chars');
// //
// Cycle through options ... // Cycle through options ...
// //
if( $search_id == "newposts" || $search_id == "egosearch" || ( $query_author != "" && $query_keywords == "" ) ) if ( $search_id == 'newposts' || $search_id == 'egosearch' || $search_id == 'unanswered' || $search_keywords != '' || $search_author != '' )
{ {
if( $search_id == "newposts" ) if ( $search_id == 'newposts' || $search_id == 'egosearch' || ( $search_author != '' && $search_keywords == '' ) )
{ {
if( $userdata['session_logged_in'] ) if ( $search_id == 'newposts' )
{
if ( $userdata['session_logged_in'] )
{ {
$sql = "SELECT post_id $sql = "SELECT post_id
FROM " . POSTS_TABLE . " FROM " . POSTS_TABLE . "
@ -160,47 +164,56 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
} }
else else
{ {
message_die(GENERAL_MESSAGE, $lang['No_search_match']); header("Location: login.$phpEx?redirect=search&search_id=newposts");
exit;
} }
$show_results = "topics"; $show_results = "topics";
$sortby = 0; $sort_by = 0;
$sortby_dir = "DESC"; $sort_dir = "DESC";
} }
else if( $search_id == "egosearch" ) else if ( $search_id == 'egosearch' )
{
if ( $userdata['session_logged_in'] )
{ {
$sql = "SELECT post_id $sql = "SELECT post_id
FROM " . POSTS_TABLE . " FROM " . POSTS_TABLE . "
WHERE poster_id = " . $userdata['user_id']; WHERE poster_id = " . $userdata['user_id'];;
$show_results = "topics";
$sortby = 0;
$sortby_dir = "DESC";
} }
else else
{ {
$query_author = str_replace("*", "%", trim($query_author)); header("Location: login.$phpEx?redirect=search&search_id=egosearch");
exit;
}
$show_results = "topics";
$sort_by = 0;
$sort_dir = "DESC";
}
else
{
$search_author = str_replace("*", "%", trim($search_author));
$sql = "SELECT user_id $sql = "SELECT user_id
FROM " . USERS_TABLE . " FROM " . USERS_TABLE . "
WHERE username LIKE '" . str_replace("\'", "''", $query_author) . "'"; WHERE username LIKE '" . str_replace("\'", "''", $search_author) . "'";
$result = $db->sql_query($sql); if ( !($result = $db->sql_query($sql)) )
if( !$result )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain list of matching users (searching for: $query_author)", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain list of matching users (searching for: $search_author)", "", __LINE__, __FILE__, $sql);
}
if( $db->sql_numrows($result) == 0 )
{
message_die(GENERAL_MESSAGE, $lang['No_search_match']);
} }
while( $row = $db->sql_fetchrow($result) ) $matching_userids = '';
if ( $row = $db->sql_fetchrow($result) )
{ {
if( $matching_userids != "" ) do
{ {
$matching_userids .= ", "; $matching_userids .= ( ( $matching_userids != '' ) ? ', ' : '' ) . $row['user_id'];
} }
$matching_userids .= $row['user_id']; while( $row = $db->sql_fetchrow($result) );
}
else
{
message_die(GENERAL_MESSAGE, $lang['No_search_match']);
} }
$sql = "SELECT post_id $sql = "SELECT post_id
@ -208,8 +221,7 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
WHERE poster_id IN ($matching_userids)"; WHERE poster_id IN ($matching_userids)";
} }
$result = $db->sql_query($sql); if ( !($result = $db->sql_query($sql)) )
if( !$result )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain matched posts list", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain matched posts list", "", __LINE__, __FILE__, $sql);
} }
@ -219,46 +231,46 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
{ {
$search_ids[] = $row['post_id']; $search_ids[] = $row['post_id'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
$total_match_count = count($search_ids); $total_match_count = count($search_ids);
} }
else if( $query_keywords != "" ) else if ( $search_keywords != '' )
{ {
$stopword_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_stopwords.txt");
$synonym_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_synonyms.txt"); $synonym_array = @file($phpbb_root_path . "language/lang_" . $board_config['default_lang'] . "/search_synonyms.txt");
$split_search = array(); $split_search = array();
$cleaned_search = clean_words("search", stripslashes($query_keywords), $synonym_array); $cleaned_search = clean_words("search", stripslashes($search_keywords), $stopword_array, $synonym_array);
$split_search = split_words($cleaned_search, "search"); $split_search = split_words($cleaned_search, "search");
$search_msg_only = ( !$search_msg_title ) ? "AND m.title_match = 0" : ""; $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : "";
$word_count = 0; $word_count = 0;
$current_match_type = "and"; $current_match_type = 'and';
$word_match = array(); $word_match = array();
$result_list = array(); $result_list = array();
for($i = 0; $i < count($split_search); $i++) for($i = 0; $i < count($split_search); $i++)
{ {
if( $split_search[$i] == "and" ) switch ( $split_search[$i] )
{ {
$current_match_type = "and"; case 'and':
} $current_match_type = 'and';
else if( $split_search[$i] == "or" ) break;
{
$current_match_type = "or"; case 'or':
} $current_match_type = 'or';
else if( $split_search[$i] == "not" ) break;
{
$current_match_type = "not"; case 'not':
} $current_match_type = 'not';
else break;
{
if( !empty($search_all_terms) ) default:
if( !empty($search_terms) )
{ {
$current_match_type = "and"; $current_match_type = "and";
} }
@ -271,8 +283,7 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
AND m.word_id = w.word_id AND m.word_id = w.word_id
AND w.word_common <> 1 AND w.word_common <> 1
$search_msg_only"; $search_msg_only";
$result = $db->sql_query($sql); if ( !($result = $db->sql_query($sql)) )
if( !$result )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain matched posts list", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain matched posts list", "", __LINE__, __FILE__, $sql);
} }
@ -280,31 +291,30 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
$row = array(); $row = array();
while( $temp_row = $db->sql_fetchrow($result) ) while( $temp_row = $db->sql_fetchrow($result) )
{ {
$row['' . $temp_row['post_id'] . ''] = 1; $row[$temp_row['post_id']] = 1;
if( !$word_count ) if ( !$word_count )
{ {
$result_list['' . $temp_row['post_id'] . ''] = 1; $result_list[$temp_row['post_id']] = 1;
} }
else if( $current_match_type == "or" ) else if ( $current_match_type == "or" )
{ {
$result_list['' . $temp_row['post_id'] . ''] = 1; $result_list[$temp_row['post_id']] = 1;
} }
else if( $current_match_type == "not" ) else if ( $current_match_type == "not" )
{ {
$result_list['' . $temp_row['post_id'] . ''] = 0; $result_list[$temp_row['post_id']] = 0;
} }
} }
if( $current_match_type == "and" && $word_count ) if ( $current_match_type == "and" && $word_count )
{ {
@reset($result_list); @reset($result_list);
while( list($post_id, $match_count) = @each($result_list) )
while( list($post_id, $match_count) = each($result_list) )
{ {
if( !$row['' . $post_id . ''] ) if ( !$row[$post_id] )
{ {
$result_list['' . $post_id . ''] = 0; $result_list[$post_id] = 0;
} }
} }
} }
@ -312,7 +322,6 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
$word_count++; $word_count++;
$db->sql_freeresult($result); $db->sql_freeresult($result);
} }
} }
@ -321,7 +330,7 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
$search_ids = array(); $search_ids = array();
while( list($post_id, $matches) = each($result_list) ) while( list($post_id, $matches) = each($result_list) )
{ {
if( $matches ) if ( $matches )
{ {
$search_ids[] = $post_id; $search_ids[] = $post_id;
} }
@ -338,11 +347,11 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
// If not logged in we explicitly prevent searching of private forums // If not logged in we explicitly prevent searching of private forums
// //
$auth_sql = ""; $auth_sql = "";
if( $search_forum != -1 ) if ( $search_forum != -1 )
{ {
$is_auth = auth(AUTH_READ, $search_forum, $userdata); $is_auth = auth(AUTH_READ, $search_forum, $userdata);
if( !$is_auth['auth_read'] ) if ( !$is_auth['auth_read'] )
{ {
message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']); message_die(GENERAL_MESSAGE, $lang['No_searchable_forums']);
} }
@ -353,7 +362,7 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
{ {
$is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
if( $search_cat != -1 ) if ( $search_cat != -1 )
{ {
$auth_sql = "f.cat_id = $search_cat"; $auth_sql = "f.cat_id = $search_cat";
} }
@ -361,17 +370,13 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
$ignore_forum_sql = ""; $ignore_forum_sql = "";
while( list($key, $value) = each($is_auth_ary) ) while( list($key, $value) = each($is_auth_ary) )
{ {
if( !$value['auth_read'] ) if ( !$value['auth_read'] )
{ {
if( $ignore_forum_sql != "" ) $ignore_forum_sql .= ( ( $ignore_forum_sql != "" ) ? ", " : "" ) . $key;
{
$ignore_forum_sql .= ", ";
}
$ignore_forum_sql .= $key;
} }
} }
if( $ignore_forum_sql != "" ) if ( $ignore_forum_sql != "" )
{ {
$auth_sql .= ( $auth_sql != "" ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) "; $auth_sql .= ( $auth_sql != "" ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) ";
} }
@ -380,23 +385,23 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
// //
// Author name search // Author name search
// //
if( $query_author != "" ) if ( $search_author != "" )
{ {
$query_author = str_replace("*", "%", trim(str_replace("\'", "''", $query_author))); $search_author = str_replace("*", "%", trim(str_replace("\'", "''", $search_author)));
} }
if( $total_match_count ) if ( $total_match_count )
{ {
if( $show_results == "topics" ) if ( $show_results == "topics" )
{ {
$where_sql = ""; $where_sql = "";
if( $search_time ) if ( $search_time )
{ {
$where_sql .= ( $query_author == "" && $auth_sql == "" ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time "; $where_sql .= ( $search_author == "" && $auth_sql == "" ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time ";
} }
if( $query_author == "" && $auth_sql == "" ) if ( $search_author == "" && $auth_sql == "" )
{ {
$sql = "SELECT topic_id $sql = "SELECT topic_id
FROM " . POSTS_TABLE . " FROM " . POSTS_TABLE . "
@ -408,13 +413,13 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
{ {
$from_sql = POSTS_TABLE . " p"; $from_sql = POSTS_TABLE . " p";
if( $query_author != "" ) if ( $search_author != '' )
{ {
$from_sql .= ", " . USERS_TABLE . " u"; $from_sql .= ", " . USERS_TABLE . " u";
$where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$query_author' "; $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author' ";
} }
if( $auth_sql != "" ) if ( $auth_sql != '' )
{ {
$from_sql .= ", " . FORUMS_TABLE . " f"; $from_sql .= ", " . FORUMS_TABLE . " f";
$where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql"; $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
@ -427,8 +432,7 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
GROUP BY p.topic_id"; GROUP BY p.topic_id";
} }
$result = $db->sql_query($sql); if ( !($result = $db->sql_query($sql)) )
if( !$result )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain topic ids", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain topic ids", "", __LINE__, __FILE__, $sql);
} }
@ -438,39 +442,37 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
{ {
$search_ids[] = $row['topic_id']; $search_ids[] = $row['topic_id'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
$total_match_count = count($search_ids); $total_match_count = sizeof($search_ids);
} }
else if( $query_author != "" || $search_time || $auth_sql != "" ) else if ( $search_author != '' || $search_time || $auth_sql != '' )
{ {
$where_sql = ( $query_author == "" && $auth_sql == "" ) ? "post_id IN (" . implode(", ", $search_ids) . ")" : "p.post_id IN (" . implode(", ", $search_ids) . ")"; $where_sql = ( $search_author == "" && $auth_sql == "" ) ? "post_id IN (" . implode(", ", $search_ids) . ")" : "p.post_id IN (" . implode(", ", $search_ids) . ")";
$from_sql = ( $query_author == "" && $auth_sql == "" ) ? POSTS_TABLE : POSTS_TABLE . " p"; $from_sql = ( $search_author == "" && $auth_sql == "" ) ? POSTS_TABLE : POSTS_TABLE . " p";
if( $search_time ) if ( $search_time )
{ {
$where_sql .= ( $query_author == "" && $auth_sql == "" ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time"; $where_sql .= ( $search_author == "" && $auth_sql == "" ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time";
} }
if( $auth_sql != "" ) if ( $auth_sql != '' )
{ {
$from_sql .= ", " . FORUMS_TABLE . " f"; $from_sql .= ", " . FORUMS_TABLE . " f";
$where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql"; $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
} }
if( $query_author != "" ) if ( $search_author != '' )
{ {
$from_sql .= ", " . USERS_TABLE . " u"; $from_sql .= ", " . USERS_TABLE . " u";
$where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$query_author'"; $where_sql .= " AND u.user_id = p.poster_id AND u.username LIKE '$search_author'";
} }
$sql = "SELECT p.post_id $sql = "SELECT p.post_id
FROM $from_sql FROM $from_sql
WHERE $where_sql"; WHERE $where_sql";
$result = $db->sql_query($sql); if ( !($result = $db->sql_query($sql)) )
if( !$result )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain post ids", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain post ids", "", __LINE__, __FILE__, $sql);
} }
@ -486,10 +488,9 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
$total_match_count = count($search_ids); $total_match_count = count($search_ids);
} }
} }
else if( $search_id == "unanswered" ) else if ( $search_id == 'unanswered' )
{ {
if ( $auth_sql != "" )
if($auth_sql != "")
{ {
$sql = "SELECT t.topic_id, f.forum_id $sql = "SELECT t.topic_id, f.forum_id
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
@ -506,9 +507,7 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
AND topic_moved_id = 0"; AND topic_moved_id = 0";
} }
if ( !($result = $db->sql_query($sql)) )
$result = $db->sql_query($sql);
if( !$result )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain post ids", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain post ids", "", __LINE__, __FILE__, $sql);
} }
@ -518,7 +517,6 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
{ {
$search_ids[] = $row['topic_id']; $search_ids[] = $row['topic_id'];
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
$total_match_count = count($search_ids); $total_match_count = count($search_ids);
@ -527,22 +525,21 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
// Basic requirements // Basic requirements
// //
$show_results = "topics"; $show_results = "topics";
$sortby = 0; $sort_by = 0;
$sortby_dir = "DESC"; $sort_dir = "DESC";
}
else
{
message_die(GENERAL_MESSAGE, $lang['No_search_match']);
} }
// //
// Finish building query (for all combinations) // Finish building query (for all combinations)
// and run it ... // and run it ...
// //
if( $total_match_count )
{
//
// Clean up search results table
//
$sql = "SELECT session_id $sql = "SELECT session_id
FROM " . SESSIONS_TABLE; FROM " . SESSIONS_TABLE;
if( $result = $db->sql_query($sql) ) if ( $result = $db->sql_query($sql) )
{ {
$delete_search_ids = array(); $delete_search_ids = array();
while( $row = $db->sql_fetchrow($result) ) while( $row = $db->sql_fetchrow($result) )
@ -550,11 +547,11 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
$delete_search_ids[] = "'" . $row['session_id'] . "'"; $delete_search_ids[] = "'" . $row['session_id'] . "'";
} }
if( count($delete_search_ids) ) if ( count($delete_search_ids) )
{ {
$sql = "DELETE FROM " . SEARCH_TABLE . " $sql = "DELETE FROM " . SEARCH_TABLE . "
WHERE session_id NOT IN (" . implode(", ", $delete_search_ids) . ")"; WHERE session_id NOT IN (" . implode(", ", $delete_search_ids) . ")";
if( !$result = $db->sql_query($sql) ) if ( !$result = $db->sql_query($sql) )
{ {
message_die(GENERAL_ERROR, "Couldn't delete old search id sessions", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't delete old search id sessions", "", __LINE__, __FILE__, $sql);
} }
@ -564,8 +561,6 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
// //
// Store new result data // Store new result data
// //
if( $total_match_count )
{
$search_results = implode(", ", $search_ids); $search_results = implode(", ", $search_ids);
$per_page = ( $show_results == "posts" ) ? $board_config['posts_per_page'] : $board_config['topics_per_page']; $per_page = ( $show_results == "posts" ) ? $board_config['posts_per_page'] : $board_config['topics_per_page'];
@ -574,15 +569,10 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
// so we can serialize it and place it in the DB // so we can serialize it and place it in the DB
// //
$store_search_data = array(); $store_search_data = array();
$store_search_data['results'] = $search_results; for($i = 0; $i < count($store_vars); $i++)
$store_search_data['match_count'] = $total_match_count; {
$store_search_data[$store_vars[$i]] = $$store_vars[$i];
$store_search_data['word_array'] = $split_search; }
$store_search_data['sort_by'] = $sortby;
$store_search_data['sortby_dir'] = $sortby_dir;
$store_search_data['show_results'] = $show_results;
$store_search_data['return_chars'] = $return_chars;
$result_array = serialize($store_search_data); $result_array = serialize($store_search_data);
unset($store_search_data); unset($store_search_data);
@ -593,12 +583,11 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
$sql = "UPDATE " . SEARCH_TABLE . " $sql = "UPDATE " . SEARCH_TABLE . "
SET search_id = $search_id, search_array = '$result_array' SET search_id = $search_id, search_array = '$result_array'
WHERE session_id = '" . $userdata['session_id'] . "'"; WHERE session_id = '" . $userdata['session_id'] . "'";
$result = $db->sql_query($sql); if ( !($result = $db->sql_query($sql)) || !$db->sql_affectedrows() )
if( !$result || !$db->sql_affectedrows() )
{ {
$sql = "INSERT INTO " . SEARCH_TABLE . " (search_id, session_id, search_array) $sql = "INSERT INTO " . SEARCH_TABLE . " (search_id, session_id, search_array)
VALUES($search_id, '" . $userdata['session_id'] . "', '" . str_replace("\'", "''", $result_array) . "')"; VALUES($search_id, '" . $userdata['session_id'] . "', '" . str_replace("\'", "''", $result_array) . "')";
if( !$result = $db->sql_query($sql) ) if ( !($result = $db->sql_query($sql)) )
{ {
message_die(GENERAL_ERROR, "Couldn't insert search results", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't insert search results", "", __LINE__, __FILE__, $sql);
} }
@ -606,18 +595,11 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
} }
else else
{ {
message_die(GENERAL_MESSAGE, $lang['No_search_match']);
}
}
else if( isset($HTTP_GET_VARS['search_id']) )
{
$search_id = intval($HTTP_GET_VARS['search_id']);
$sql = "SELECT search_array $sql = "SELECT search_array
FROM " . SEARCH_TABLE . " FROM " . SEARCH_TABLE . "
WHERE search_id = $search_id WHERE search_id = $search_id
AND session_id = '". $userdata['session_id'] . "'"; AND session_id = '". $userdata['session_id'] . "'";
if( !$result = $db->sql_query($sql) ) if( !($result = $db->sql_query($sql)) )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain search results", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain search results", "", __LINE__, __FILE__, $sql);
} }
@ -625,32 +607,19 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
if( $row = $db->sql_fetchrow($result) ) if( $row = $db->sql_fetchrow($result) )
{ {
$search_data = unserialize($row['search_array']); $search_data = unserialize($row['search_array']);
unset($row); for($i = 0; $i < count($store_vars); $i++)
$search_results = $search_data['results'];
$total_match_count = $search_data['match_count'];
$split_search = $search_data['word_array'];
$sortby = $search_data['sort_by'];
$sortby_dir = $search_data['sortby_dir'];
$show_results = $search_data['show_results'];
$return_chars = $search_data['return_chars'];
}
else
{ {
header("Location: " . append_sid("search.$phpEx", true)); $$store_vars[$i] = $search_data[$store_vars[$i]];
} }
} }
else
{
message_die(GENERAL_MESSAGE, $lang['No_search_match']);
} }
if( $search_results != "" ) //
// Look up data ...
//
if ( $search_results != "" )
{ {
if( $show_results == "posts" ) if ( $show_results == "posts" )
{ {
$sql = "SELECT pt.post_text, pt.bbcode_uid, pt.post_subject, p.*, f.forum_id, f.forum_name, t.*, u.username, u.user_id, u.user_sig, u.user_sig_bbcode_uid $sql = "SELECT pt.post_text, pt.bbcode_uid, pt.post_subject, p.*, f.forum_id, f.forum_name, t.*, u.username, u.user_id, u.user_sig, u.user_sig_bbcode_uid
FROM " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt FROM " . FORUMS_TABLE . " f, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt
@ -673,9 +642,9 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
$per_page = ( $show_results == "posts" ) ? $board_config['posts_per_page'] : $board_config['topics_per_page']; $per_page = ( $show_results == "posts" ) ? $board_config['posts_per_page'] : $board_config['topics_per_page'];
$sql .= " ORDER BY " . $sortby_sql[$sortby] . " $sortby_dir LIMIT $start, " . $per_page; $sql .= " ORDER BY " . $sort_by_sql[$sort_by] . " $sort_dir LIMIT $start, " . $per_page;
if( !$result = $db->sql_query($sql) ) if ( !$result = $db->sql_query($sql) )
{ {
message_die(GENERAL_ERROR, "Couldn't obtain search results", "", __LINE__, __FILE__, $sql); message_die(GENERAL_ERROR, "Couldn't obtain search results", "", __LINE__, __FILE__, $sql);
} }
@ -701,7 +670,7 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
$page_title = $lang['Search']; $page_title = $lang['Search'];
include($phpbb_root_path . 'includes/page_header.'.$phpEx); include($phpbb_root_path . 'includes/page_header.'.$phpEx);
if( $show_results == "posts" ) if ( $show_results == "posts" )
{ {
$template->set_filenames(array( $template->set_filenames(array(
"body" => "search_results_posts.tpl", "body" => "search_results_posts.tpl",
@ -931,7 +900,7 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
if( $replies > $board_config['topics_per_page'] ) if( $replies > $board_config['topics_per_page'] )
{ {
$goto_page = "[ <img src=\"" . $images['icon_gotopost'] . "\" alt=\"" . $lang['Goto_page'] . "\" />" . $lang['Goto_page'] . ": "; $goto_page = '[ <img src="' . $images['icon_gotopost'] . '" alt="' . $lang['Goto_page'] . '" title="' . $lang['Goto_page'] . '" />' . $lang['Goto_page'] . ': ';
$times = 1; $times = 1;
for($j = 0; $j < $replies + 1; $j += $board_config['posts_per_page']) for($j = 0; $j < $replies + 1; $j += $board_config['posts_per_page'])
@ -942,7 +911,7 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
{ {
if( $j + $board_config['topics_per_page'] >= $replies + 1 ) if( $j + $board_config['topics_per_page'] >= $replies + 1 )
{ {
$goto_page .= " ... <a href=\"$base_url\">$times</a>"; $goto_page .= ' ... <a href="' . $base_url . '">' . $times . '</a>';
} }
} }
else else
@ -952,16 +921,16 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
$goto_page .= ", "; $goto_page .= ", ";
} }
$goto_page .= "<a href=\"$base_url\">$times</a>"; $goto_page .= '<a href="' . $base_url . '">' . $times . '</a>';
} }
$times++; $times++;
} }
$goto_page .= " ]"; $goto_page .= ' ]';
} }
else else
{ {
$goto_page = ""; $goto_page = '';
} }
if( $searchset[$i]['topic_status'] == TOPIC_MOVED ) if( $searchset[$i]['topic_status'] == TOPIC_MOVED )
@ -1014,15 +983,15 @@ else if( $query_keywords != "" || $query_author != "" || $search_id )
if( !empty($tracking_topics['' . $topic_id . '']) ) if( !empty($tracking_topics['' . $topic_id . '']) )
{ {
if( $tracking_topics['' . $topic_id . ''] > $searchset[$i]['post_time'] ) if( $tracking_topics[$topic_id] > $searchset[$i]['post_time'] )
{ {
$unread_topics = false; $unread_topics = false;
} }
} }
if( !empty($tracking_forums['' . $forum_id . '']) ) if( !empty($tracking_forums[$forum_id]) )
{ {
if( $tracking_forums['' . $forum_id . ''] > $searchset[$i]['post_time'] ) if( $tracking_forums[$forum_id] > $searchset[$i]['post_time'] )
{ {
$unread_topics = false; $unread_topics = false;
} }
@ -1176,24 +1145,24 @@ else
// //
// Number of chars returned // Number of chars returned
// //
$s_characters = "<option value=\"-1\">" . $lang['All_available'] . "</option>"; $s_characters = '<option value="-1">' . $lang['All_available'] . '</option>';
$s_characters .= "<option value=\"0\">0</option>"; $s_characters .= '<option value="0">0</option>';
$s_characters .= "<option value=\"25\">25</option>"; $s_characters .= '<option value="25">25</option>';
$s_characters .= "<option value=\"50\">50</option>"; $s_characters .= '<option value="50">50</option>';
for($i = 100; $i < 1100 ; $i += 100) for($i = 100; $i < 1100 ; $i += 100)
{ {
$selected = ( $i == 200 ) ? "selected=\"selected\"" : ""; $selected = ( $i == 200 ) ? ' selected="selected"' : '';
$s_characters .= "<option value=\"$i\"$selected>$i</option>"; $s_characters .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
} }
// //
// Sorting // Sorting
// //
$s_sortby = ""; $s_sort_by = "";
for($i = 0; $i < count($sortby_types); $i++) for($i = 0; $i < count($sort_by_types); $i++)
{ {
$s_sortby .= "<option value=\"$i\">" . $sortby_types[$i] . "</option>"; $s_sort_by .= '<option value="' . $i . '">' . $sort_by_types[$i] . '</option>';
} }
// //
@ -1256,7 +1225,7 @@ $template->assign_vars(array(
"S_FORUM_OPTIONS" => $s_forums, "S_FORUM_OPTIONS" => $s_forums,
"S_CATEGORY_OPTIONS" => $s_categories, "S_CATEGORY_OPTIONS" => $s_categories,
"S_TIME_OPTIONS" => $s_time, "S_TIME_OPTIONS" => $s_time,
"S_SORT_OPTIONS" => $s_sortby, "S_SORT_OPTIONS" => $s_sort_by,
"S_HIDDEN_FIELDS" => $s_hidden_fields) "S_HIDDEN_FIELDS" => $s_hidden_fields)
); );

View file

@ -26,7 +26,7 @@
<span class="postdetails">{L_REPLIES}: <b>{searchresults.TOPIC_REPLIES}</b><br /> <span class="postdetails">{L_REPLIES}: <b>{searchresults.TOPIC_REPLIES}</b><br />
{L_VIEWS}: <b>{searchresults.TOPIC_VIEWS}</b></span><br /> {L_VIEWS}: <b>{searchresults.TOPIC_VIEWS}</b></span><br />
</td> </td>
<td valign="top" class="row1"> <img src="templates/subSilver/images/icon_minipost.gif" alt="Post image icon"><span class="postdetails">{L_FORUM}:&nbsp;<b><a href="{U_FORUM}" class="postdetails">{searchresults.FORUM_NAME}</a></b>&nbsp;&nbsp;&nbsp;{L_POSTED}: <td valign="top" class="row1"> <span class="postdetails">{L_FORUM}:&nbsp;<b><a href="{U_FORUM}" class="postdetails">{searchresults.FORUM_NAME}</a></b>&nbsp;&nbsp;&nbsp;{L_POSTED}:
{searchresults.POST_DATE}&nbsp;&nbsp;&nbsp;Subject: <b><a href="{searchresults.U_POST}">{searchresults.POST_SUBJECT}</a></b></span></td> {searchresults.POST_DATE}&nbsp;&nbsp;&nbsp;Subject: <b><a href="{searchresults.U_POST}">{searchresults.POST_SUBJECT}</a></b></span></td>
</tr> </tr>
<tr> <tr>

View file

@ -57,7 +57,7 @@
<table width="98%" cellspacing="2" border="0" align="center"> <table width="98%" cellspacing="2" border="0" align="center">
<tr> <tr>
<td><span class="gensmall"><b>{S_TIMEZONE}</b></span></td> <td valign="top"><span class="gensmall"><b>{S_TIMEZONE}</b></span></td>
<td align="right">{JUMPBOX}</td> <td align="right">{JUMPBOX}</td>
</tr> </tr>
</table> </table>

View file

@ -1,84 +1,55 @@
<form action="{S_SEARCH_ACTION}" method="POST">
<table width="100%" cellspacing="2" cellpadding="2" border="0" align="center"> <form action="{S_SEARCH_ACTION}" method="POST"><table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
<tr> <tr>
<td align="left"><span class="nav"><a href="{U_INDEX}" class="nav">{L_INDEX}</a></span></td> <td align="left"><span class="nav"><a href="{U_INDEX}" class="nav">{L_INDEX}</a></span></td>
</tr> </tr>
</table> </table>
<table border="0" cellpadding="4" cellspacing="1" width="100%" class="forumline">
<table class="forumline" width="100%" cellpadding="4" cellspacing="1" border="0">
<tr> <tr>
<th class="thHead" colspan="4" height="25">{L_SEARCH_QUERY}</th> <th class="thHead" colspan="4" height="25">{L_SEARCH_QUERY}</th>
</tr> </tr>
<tr> <tr>
<td class="row1" colspan="2" width="50%"><span class="gen">{L_SEARCH_KEYWORDS}:</span><br /> <td class="row1" colspan="2" width="50%"><span class="gen">{L_SEARCH_KEYWORDS}:</span><br /><span class="gensmall">{L_SEARCH_KEYWORDS_EXPLAIN}</span></td>
<span class="gensmall">{L_SEARCH_KEYWORDS_EXPLAIN}</span></td> <td class="row2" colspan="2" valign="top"><span class="genmed"><input type="text" style="width: 300px" class="post" name="search_keywords" size="30" /><br /><input type="radio" name="search_terms" value="any" checked="checked" /> {L_SEARCH_ANY_TERMS}<br /><input type="radio" name="search_terms" value="all" /> {L_SEARCH_ALL_TERMS}</span></td>
<td class="row2" colspan="2" valign="top"><span class="genmed">
<input type="text" style="width: 300px" class="post" name="search_keywords" size="30" />
<br />
<input type="radio" name="addterms" value="any" checked="checked" /> {L_SEARCH_ANY_TERMS}<br />
<input type="radio" name="addterms" value="all" /> {L_SEARCH_ALL_TERMS}</span></td>
</tr> </tr>
<tr> <tr>
<td class="row1" colspan="2"><span class="gen">{L_SEARCH_AUTHOR}:</span><br /> <td class="row1" colspan="2"><span class="gen">{L_SEARCH_AUTHOR}:</span><br /><span class="gensmall">{L_SEARCH_AUTHOR_EXPLAIN}</span></td>
<span class="gensmall">{L_SEARCH_AUTHOR_EXPLAIN}</span></td> <td class="row2" colspan="2" valign="middle"><span class="genmed"><input type="text" style="width: 300px" class="post" name="search_author" size="30" /></span></td>
<td class="row2" colspan="2" valign="middle"><span class="genmed">
<input type="text" style="width: 300px" class="post" name="search_author" size="30" />
</span> </td>
</tr> </tr>
<tr> <tr>
<th class="thHead" colspan="4" height="25">{L_SEARCH_OPTIONS}</th> <th class="thHead" colspan="4" height="25">{L_SEARCH_OPTIONS}</th>
</tr> </tr>
<tr> <tr>
<td class="row1" align="right"><span class="gen">{L_FORUM}:&nbsp;</span></td> <td class="row1" align="right"><span class="gen">{L_FORUM}:&nbsp;</span></td>
<td class="row2"><span class="genmed"> <td class="row2"><span class="genmed"><select class="post" name="search_forum">{S_FORUM_OPTIONS}</select></span></td>
<select class="post" name="searchforum">{S_FORUM_OPTIONS}
</select>
</span></td>
<td class="row1" align="right" nowrap="nowrap"><span class="gen">{L_SEARCH_PREVIOUS}:&nbsp;</span></td> <td class="row1" align="right" nowrap="nowrap"><span class="gen">{L_SEARCH_PREVIOUS}:&nbsp;</span></td>
<td class="row2" valign="middle"><span class="genmed"><select class="post" name="resultdays">{S_TIME_OPTIONS}</select> <td class="row2" valign="middle"><span class="genmed"><select class="post" name="search_time">{S_TIME_OPTIONS}</select><br /><input type="radio" name="search_fields" value="all" checked="checked" /> {L_SEARCH_MESSAGE_TITLE}<br /><input type="radio" name="search_fields" value="msgonly" /> {L_SEARCH_MESSAGE_ONLY}</span></td>
<br />
<input type="radio" name="searchfields" value="all" checked="checked" /> {L_SEARCH_MESSAGE_TITLE}<br />
<input type="radio" name="searchfields" value="msgonly" /> {L_SEARCH_MESSAGE_ONLY}</span></td>
</tr> </tr>
<tr> <tr>
<td class="row1" align="right"><span class="gen">{L_CATEGORY}:&nbsp;</span></td> <td class="row1" align="right"><span class="gen">{L_CATEGORY}:&nbsp;</span></td>
<td class="row2"><span class="genmed"> <td class="row2"><span class="genmed"><select class="post" name="search_cat">{S_CATEGORY_OPTIONS}
<select class="post" name="searchcat">{S_CATEGORY_OPTIONS} </select></span></td>
</select>
</span></td>
<td class="row1" align="right"><span class="gen">{L_SORT_BY}:&nbsp;</span></td> <td class="row1" align="right"><span class="gen">{L_SORT_BY}:&nbsp;</span></td>
<td class="row2" valign="middle" nowrap="nowrap"><span class="genmed"> <td class="row2" valign="middle" nowrap="nowrap"><span class="genmed"><select class="post" name="sort_by">{S_SORT_OPTIONS}</select><br /><input type="radio" name="sort_dir" value="ASC" /> {L_SORT_ASCENDING}<br /><input type="radio" name="sort_dir" value="DESC" checked /> {L_SORT_DESCENDING}</span>&nbsp;</td>
<select class="post" name="sortby">{S_SORT_OPTIONS}</select>
<br />
<input type="radio" name="sortdir" value="ASC" />
{L_SORT_ASCENDING}<br />
<input type="radio" name="sortdir" value="DESC" checked />
{L_SORT_DESCENDING}</span>&nbsp;</td>
</tr> </tr>
<tr> <tr>
<td class="row1" align="right" nowrap="nowrap"><span class="gen">{L_DISPLAY_RESULTS}:&nbsp;</span></td> <td class="row1" align="right" nowrap="nowrap"><span class="gen">{L_DISPLAY_RESULTS}:&nbsp;</span></td>
<td class="row2" nowrap="nowrap"> <td class="row2" nowrap="nowrap"><input type="radio" name="show_results" value="posts" /><span class="genmed">{L_POSTS}<input type="radio" name="show_results" value="topics" checked="checked" />{L_TOPICS}</span></td>
<input type="radio" name="showresults" value="posts" />
<span class="genmed">{L_POSTS}
<input type="radio" name="showresults" value="topics" checked="checked" />
{L_TOPICS}</span></td>
<td class="row1" align="right"><span class="gen">{L_RETURN_FIRST}</span></td> <td class="row1" align="right"><span class="gen">{L_RETURN_FIRST}</span></td>
<td class="row2"><span class="genmed"> <td class="row2"><span class="genmed"><select class="post" name="return_chars">{S_CHARACTER_OPTIONS}</select> {L_CHARACTERS}</span></td>
<select class="post" name="charsreqd">{S_CHARACTER_OPTIONS}
</select>
{L_CHARACTERS}</span></td>
</tr> </tr>
<tr> <tr>
<td class="catBottom" colspan="4" align="center" height="28">{S_HIDDEN_FIELDS} <td class="catBottom" colspan="4" align="center" height="28">{S_HIDDEN_FIELDS}<input class="liteoption" type="submit" value="{L_SEARCH}" /></td>
<input class="liteoption" type="submit" value="{L_SEARCH}" />
</td>
</tr> </tr>
</table> </table>
<table width="100%" cellspacing="2" border="0" align="center" cellpadding="2">
<table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
<tr> <tr>
<td align="right" valign="middle"><span class="gensmall">{S_TIMEZONE}</span></td> <td align="right" valign="middle"><span class="gensmall">{S_TIMEZONE}</span></td>
</tr> </tr>
</table> </table></form>
</form>
<table width="100%" border="0"> <table width="100%" border="0">
<tr> <tr>
<td align="right" valign="top">{JUMPBOX}</td> <td align="right" valign="top">{JUMPBOX}</td>