diff --git a/phpBB/adm/admin_search.php b/phpBB/adm/admin_search.php
index 4d5e660b64..e427b4bd54 100644
--- a/phpBB/adm/admin_search.php
+++ b/phpBB/adm/admin_search.php
@@ -47,7 +47,7 @@ if (!$auth->acl_get('a_search'))
// Start indexing
if (isset($_POST['start']) || isset($_GET['batchstart']))
{
- $batchsize = 200; // Process this many posts per batch
+ $batchsize = 5000; // Process this many posts per batch
$batchcount = request_var('batchcount', 1);
$batchstart = request_var('batchstart', 0);
$loopcount = 0;
@@ -65,40 +65,11 @@ if (isset($_POST['start']) || isset($_GET['batchstart']))
if ($load > 3)
{
- redirect("admin_search.$phpEx$SID&batchstart=$batchstart&batchcount=$batchcount");
+ redirect("adm/admin_search.$phpEx$SID&batchstart=$batchstart&batchcount=$batchcount", 3);
}
}
}
- /* Try and load stopword and synonym files
- // Do this with the mode "admin" and the fulltext class
- $stopword_array = array();
- $synonym_array = array();
-
- $dir = opendir($phpbb_root_path . 'language/');
- while ($file = readdir($dir))
- {
- if (preg_match('#^lang_#', $file) && !is_file($phpbb_root_path . 'language/' . $file) && !is_link($phpbb_root_path . 'language/' . $file))
- {
- unset($tmp_array);
- $tmp_array = @file($phpbb_root_path . 'language/' . $file . '/search_stopwords.txt');
- if (is_array($tmp_array))
- {
- $stopword_array = array_unique(array_merge($stopword_array, $tmp_array));
- }
-
- unset($tmp_array);
- $tmp_array = @file($phpbb_root_path . 'language/' . $file . '/search_synonyms.txt');
- if (is_array($tmp_array))
- {
- $synonym_array = array_unique(array_merge($synonym_array, $tmp_array));
- }
- }
- }
-
- closedir($dir);
- */
-
if (!$batchstart)
{
// Take board offline
@@ -135,153 +106,26 @@ if (isset($_POST['start']) || isset($_GET['batchstart']))
{
do
{
- $mode = 'admin';
- $fulltext->add($mode, $row['post_id'], $row['post_text'], $row['post_subject']);
- /*$post_id = $row['post_id'];
-
- $search_raw_words = array();
- $search_raw_words['text'] = split_words(clean_words('post', $row['post_text'], $stopword_array, $synonym_array));
- $search_raw_words['title'] = split_words(clean_words('post', $row['post_subject'], $stopword_array, $synonym_array));
-
- $word = array();
- $word_insert_sql = array();
- foreach ($search_raw_words as $word_in => $search_matches)
- {
- $word_insert_sql[$word_in] = '';
- if (!empty($search_matches))
- {
- for ($i = 0; $i < count($search_matches); $i++)
- {
- $search_matches[$i] = trim($search_matches[$i]);
-
- if ($search_matches[$i] != '')
- {
- $word[] = $search_matches[$i];
- $word_insert_sql[$word_in] .= ($word_insert_sql[$word_in] != '') ? ", '" . $search_matches[$i] . "'" : "'" . $search_matches[$i] . "'";
- }
- }
- }
- }
-
- if (count($word))
- {
- $word_text_sql = '';
- $word = array_unique($word);
-
- for($i = 0; $i < count($word); $i++)
- {
- $word_text_sql .= (($word_text_sql != '') ? ', ' : '') . "'" . $db->sql_escape($word[$i]) . "'";
- }
-
- $check_words = array();
- switch(SQL_LAYER)
- {
- case 'postgresql':
- case 'msaccess':
- case 'mssql-odbc':
- case 'oracle':
- case 'db2':
- $sql = "SELECT word_id, word_text
- FROM " . SEARCH_WORD_TABLE . "
- WHERE word_text IN ($word_text_sql)";
- $result = $db->sql_query($sql);
-
- while ($row = $db->sql_fetchrow($result))
- {
- $check_words[$row['word_text']] = $row['word_id'];
- }
- break;
- }
-
- $value_sql = '';
- $match_word = array();
- for ($i = 0; $i < count($word); $i++)
- {
- $new_match = true;
- if (isset($check_words[$word[$i]]))
- {
- $new_match = false;
- }
-
- if ($new_match)
- {
- switch(SQL_LAYER)
- {
- case 'mysql':
- case 'mysql4':
- $value_sql .= (($value_sql != '') ? ', ' : '') . "('" . $db->sql_escape($word[$i]) . "')";
- break;
-
- case 'mssql':
- case 'sqlite':
- $value_sql .= (($value_sql != '') ? ' UNION ALL ' : '') . "SELECT '" . $db->sql_escape($word[$i]) . "'";
- break;
-
- default:
- $sql = 'INSERT INTO ' . SEARCH_WORD_TABLE . " (word_text)
- VALUES ('" . $db->sql_escape($word[$i]) . "')";
- $db->sql_query($sql);
- break;
- }
- }
- }
-
- if ($value_sql != '')
- {
- switch (SQL_LAYER)
- {
- case 'mysql':
- case 'mysql4':
- $sql = 'INSERT IGNORE INTO ' . SEARCH_WORD_TABLE . " (word_text)
- VALUES $value_sql";
- break;
-
- case 'mssql':
- case 'sqlite':
- $sql = 'INSERT INTO ' . SEARCH_WORD_TABLE . " (word_text)
- $value_sql";
- break;
- }
-
- $db->sql_query($sql);
- }
- }
-
- foreach ($word_insert_sql as $word_in => $match_sql)
- {
- $title_match = ($word_in == 'title') ? 1 : 0;
-
- if ($match_sql != '')
- {
- $sql = 'INSERT INTO ' . SEARCH_MATCH_TABLE . " (post_id, word_id, title_match)
- SELECT $post_id, word_id, $title_match
- FROM " . SEARCH_WORD_TABLE . "
- WHERE word_text IN ($match_sql)";
- $db->sql_query($sql);
- }
- }
- */
+ $fulltext->add('admin', $row['post_id'], $row['post_text'], $row['post_subject']);
}
while ($row = $db->sql_fetchrow($result));
}
$db->sql_freeresult($result);
- // Remove common words after the first 2 batches and after every 4th batch after that.
- if ($batchcount % 4 == 3)
- {
-// remove_common('global', $config['common_search']);
- }
-
$batchcount++;
if (($batchstart + $batchsize) < $max_post_id)
{
- redirect("Location: admin_search.$phpEx$SID&batchstart=" . ($batchstart + $batchsize) . "&batchcount=$batch_count");
+ redirect("adm/admin_search.$phpEx$SID&batchstart=" . ($batchstart + $batchsize) . "&batchcount=$batchcount", 3);
}
else
{
set_config('board_disable', 0);
+
+ // search tidy
+ $fulltext->search_tidy();
+
adm_page_header($user->lang['SEARCH_INDEX']);
?>
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index b628e3dd8b..cd3c9c2533 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -46,27 +46,28 @@ class messenger
// Sets an email address to send to
function to($address, $realname = '')
{
- $pos = sizeof($this->addresses['to']);
+ $pos = isset($this->addresses['to']) ? sizeof($this->addresses['to']) : 0;
$this->addresses['to'][$pos]['email'] = trim($address);
$this->addresses['to'][$pos]['name'] = trim($realname);
}
function cc($address, $realname = '')
{
- $pos = sizeof($this->addresses['cc']);
+ $pos = isset($this->addresses['cc']) ? sizeof($this->addresses['cc']) : 0;
$this->addresses['cc'][$pos]['email'] = trim($address);
$this->addresses['cc'][$pos]['name'] = trim($realname);
}
function bcc($address, $realname = '')
{
- $pos = sizeof($this->addresses['bcc']);
+ $pos = isset($this->addresses['bcc']) ? sizeof($this->addresses['bcc']) : 0;
$this->addresses['bcc'][$pos]['email'] = trim($address);
+ $this->addresses['bcc'][$pos]['name'] = trim($realname);
}
function im($address, $realname = '')
{
- $pos = sizeof($this->addresses['im']);
+ $pos = isset($this->addresses['im']) ? sizeof($this->addresses['im']) : 0;
$this->addresses['im'][$pos]['uid'] = trim($address);
$this->addresses['im'][$pos]['name'] = trim($realname);
}
@@ -772,6 +773,7 @@ function smtpmail($addresses, $subject, $message, &$err_msg, $encoding, $headers
// We try to send messages even if a few people do not seem to have valid email addresses, but if no one has, we have to exit here.
if (!$rcpt)
{
+ $user->start();
$err_msg .= '
' . sprintf($user->lang['INVALID_EMAIL_LOG'], htmlspecialchars($mail_to_address));
$smtp->close_session();
return false;
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index 7d4849b4e8..7b87fb83be 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -513,27 +513,6 @@ function decode_message(&$message, $bbcode_uid = '')
return;
}
-// Temp Function - strtolower - borrowed from php.net
-function phpbb_strtolower($string)
-{
- $new_string = '';
-
- for ($i = 0; $i < strlen($string); $i++)
- {
- if (ord(substr($string, $i, 1)) > 0xa0)
- {
- $new_string .= strtolower(substr($string, $i, 2));
- $i++;
- }
- else
- {
- $new_string .= strtolower($string{$i});
- }
- }
-
- return $new_string;
-}
-
// Generate Topic Icons for display
function posting_gen_topic_icons($mode, $icon_id)
{
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index f1470836fd..42ac9fed75 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -111,7 +111,7 @@ class bbcode_firstpass extends bbcode
'url' => array('bbcode_id' => 3, 'regexp' => array('#\[url=?(.*?)?\](.*?)\[/url\]#ise' => "\$this->validate_url('\$1', '\$2')")),
'img' => array('bbcode_id' => 4, 'regexp' => array('#\[img\](https?://)([a-z0-9\-\.,\?!%\*_:;~\\&$@/=\+]+)\[/img\]#i' => '[img:' . $this->bbcode_uid . ']$1$2[/img:' . $this->bbcode_uid . ']')),
'size' => array('bbcode_id' => 5, 'regexp' => array('#\[size=([\-\+]?[1-2]?[0-9])\](.*?)\[/size\]#is' => '[size=$1:' . $this->bbcode_uid . ']$2[/size:' . $this->bbcode_uid . ']')),
- 'color' => array('bbcode_id' => 6, 'regexp' => array('!\[color=(#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]!is' => '[color=$1:' . $this->bbcode_uid . ']$2[/color:' . $this->bbcode_uid . ']')),
+ 'color' => array('bbcode_id' => 6, 'regexp' => array('#\[color=(#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#is' => '[color=$1:' . $this->bbcode_uid . ']$2[/color:' . $this->bbcode_uid . ']')),
'u' => array('bbcode_id' => 7, 'regexp' => array('#\[u\](.*?)\[/u\]#is' => '[u:' . $this->bbcode_uid . ']$1[/u:' . $this->bbcode_uid . ']')),
'list' => array('bbcode_id' => 9, 'regexp' => array('#\[list(=[a-z|0-9|(?:disc|circle|square))]+)?\].*\[/list\]#ise' => "\$this->bbcode_list('\$0')")),
'email' => array('bbcode_id' => 10, 'regexp' => array('#\[email=?(.*?)?\](.*?)\[/email\]#ise' => "\$this->validate_email('\$1', '\$2')")),
@@ -1084,7 +1084,7 @@ class parse_message extends bbcode_firstpass
// Parses a given message and updates/maintains the fulltext tables
class fulltext_search
{
- function split_words($mode, $text, &$stopped_words)
+ function split_words($mode, $text)
{
global $user, $config;
@@ -1099,8 +1099,8 @@ class fulltext_search
if (!$drop_char_match)
{
- $drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!', '*');
- $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '' , ' ', ' ', ' ', ' ', ' ', ' ', ' ');
+ $drop_char_match = array('-', '^', '$', ';', '#', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '\'', '!', '*');
+ $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '' , ' ', ' ', ' ', ' ', ' ');
if ($fp = @fopen($user->lang_path . '/search_stopwords.txt', 'rb'))
{
@@ -1118,42 +1118,50 @@ class fulltext_search
}
$match = array();
+ // Comments for hardcoded bbcode elements (urls, smilies, html)
+ $match[] = '#(.*?)#is';
// New lines, carriage returns
$match[] = "#[\n\r]+#";
// NCRs like etc.
- $match[] = '#&[\#a-z0-9]+?;#i';
- // URL's
- $match[] = '#\b[\w]+:\/\/[a-z0-9\.\-]+(\/[a-z0-9\?\.%_\-\+=&\/]+)?#';
+ $match[] = '#(&|&)[\#a-z0-9]+?;#i';
+ // Do not index code
+ $match[] = '#\[code(=.*)?(\:?[0-9a-z]{5,})\].*?\[\/code(\:?[0-9a-z]{5,})\]#is';
// BBcode
- $match[] = '#\[img:[a-z0-9]{5,}\].*?\[\/img:[a-z0-9]{5,}\]#';
- $match[] = '#\[\/?[a-z\*=\+\-]+(\:?[0-9a-z]+)?:[a-z0-9]{5,}(\:[a-z0-9]+)?=?.*?\]#';
- $match[] = '##is';
- // Sequences < min_search_chars & < max_search_chars
- $match[] = '#\b([\S]{1,' . $config['min_search_chars'] . '}|[\S]{' . $config['max_search_chars'] . ',})\b#is';
+ $match[] = '#\[\/?[a-z\*\+\-]+(=.*)?(\:?[0-9a-z]{5,})\]#';
+ // Sequences > min_search_chars & < max_search_chars
+// $match[] = '#\s([\b]{1,' . $config['min_search_chars'] . '}|[\b]{' . $config['max_search_chars'] . ',})\s#is';
+// $match[] = '#\s((&\#[0-9]+;){1,' . $config['min_search_chars'] . '}|(&\#[0-9]+;){' . $config['max_search_chars'] . ',})\s#is';
+ // Filter out ; and # but not [0-9]+;
+// $match[] = '#(&\#[0-9]+;)|;|\#|';
- $replace = array('', '', '', '', '', '', '');
-
- $text = preg_replace($match, $replace, ' ' . strtolower($text) . ' ');
- $text = str_replace(' and ', ' + ', $text);
- $text = str_replace(' not ', ' - ', $text);
+ $text = preg_replace($match, ' ', ' ' . strtolower(trim($text)) . ' ');
+ $text = str_replace(array(' + ', ' - '), array(' and ', ' not '), $text);
// Filter out non-alphabetical chars
$text = str_replace($drop_char_match, $drop_char_replace, $text);
// Split words
- $text = explode(' ', preg_replace('#\s+#', ' ', $text));
+ $text = explode(' ', preg_replace('#\s+#', ' ', trim($text)));
- if ($stopwords)
+ if (sizeof($stopwords))
{
$stopped_words = array_intersect($text, $stopwords);
$text = array_diff($text, $stopwords);
}
- if ($replace_synonym)
+ if (sizeof($replace_synonym))
{
$text = str_replace($replace_synonym, $match_synonym, $text);
}
-
+
+ foreach ($text as $index => $word)
+ {
+ if (strlen($word) < $config['min_search_chars'] || strlen($word) > $config['max_search_chars'])
+ {
+ unset($text[$index]);
+ }
+ }
+
return $text;
}
@@ -1169,10 +1177,8 @@ class fulltext_search
}
// Split old and new post/subject to obtain array of 'words'
- $stopped_words = array();
- $split_text = $this->split_words('post', $message, $stopped_words);
- $split_title = ($subject) ? $this->split_words('post', $subject, $stopped_words) : array();
- unset($stopped_words);
+ $split_text = $this->split_words('post', $message);
+ $split_title = ($subject) ? $this->split_words('post', $subject) : array();
$words = array();
if ($mode == 'edit')
@@ -1230,7 +1236,6 @@ class fulltext_search
$new_words = array_diff($unique_add_words, array_keys($word_ids));
unset($unique_add_words);
- $db->sql_return_on_error(true);
if (sizeof($new_words))
{
switch (SQL_LAYER)
@@ -1238,7 +1243,7 @@ class fulltext_search
case 'mysql':
case 'mysql4':
$sql = 'INSERT INTO ' . SEARCH_WORD_TABLE . ' (word_text)
- VALUES ' . implode(', ', preg_replace('#^(.*)$#', '(\'$1\')', $new_words));
+ VALUES ' . implode(', ', preg_replace('#^(.*)$#', '(\'$1\')', $new_words));
$db->sql_query($sql);
break;
@@ -1258,7 +1263,6 @@ class fulltext_search
break;
}
}
- $db->sql_return_on_error(false);
unset($new_words);
}
@@ -1343,7 +1347,7 @@ class fulltext_search
$sql_in[] = $row['word_id'];
}
while ($row = $db->sql_fetchrow($result));
-
+
$sql_in = implode(', ', $sql_in);
$sql = 'UPDATE ' . SEARCH_WORD_TABLE . "
@@ -1363,7 +1367,7 @@ class fulltext_search
$sql = 'SELECT w.word_id
FROM ' . SEARCH_WORD_TABLE . ' w
LEFT JOIN ' . SEARCH_MATCH_TABLE . ' m ON w.word_id = m.word_id
- AND m.word_id IS NULL
+ WHERE w.word_common = 0 AND m.word_id IS NULL
GROUP BY m.word_id';
$result = $db->sql_query($sql);
diff --git a/phpBB/includes/ucp/ucp_pm_compose.php b/phpBB/includes/ucp/ucp_pm_compose.php
index 60dd4b33b9..0904238d23 100644
--- a/phpBB/includes/ucp/ucp_pm_compose.php
+++ b/phpBB/includes/ucp/ucp_pm_compose.php
@@ -404,7 +404,7 @@ function compose_pm($id, $mode, $action)
if (strcmp($subject, strtoupper($subject)) == 0 && $subject)
{
- $subject = phpbb_strtolower($subject);
+ $subject = strtolower($subject);
}
$subject = preg_replace('#&(\#[0-9]+;)#', '&\1', $subject);
diff --git a/phpBB/posting.php b/phpBB/posting.php
index fb5b91dde9..343fdf6733 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -498,7 +498,7 @@ if ($submit || $preview || $refresh)
if (strcmp($subject, strtoupper($subject)) == 0 && $subject)
{
- $subject = phpbb_strtolower($subject);
+ $subject = strtolower($subject);
}
$message_parser->message = (isset($_POST['message'])) ? htmlspecialchars(str_replace(array('\\\'', '\\"', '\\0', '\\\\'), array('\'', '"', '\0', '\\'), $_POST['message'])) : '';
diff --git a/phpBB/search.php b/phpBB/search.php
index 8a87809f4b..45ccba3557 100644
--- a/phpBB/search.php
+++ b/phpBB/search.php
@@ -42,7 +42,7 @@ $search_fields = request_var('search_fields', 'all');
$search_child = request_var('search_child', true);
$return_chars = request_var('return_chars', 200);
-$search_forum = request_var('f', 0);
+$search_forum = request_var('search_forum', 0);
$sort_days = request_var('st', 0);
$sort_key = request_var('sk', 't');
@@ -58,10 +58,10 @@ if (!$auth->acl_get('u_search') || !$config['load_search'])
$limit_days = array(0 => $user->lang['ALL_RESULTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 364 => $user->lang['1_YEAR']);
$sort_by_text = array('a' => $user->lang['SORT_AUTHOR'], 't' => $user->lang['SORT_TIME'], 'f' => $user->lang['SORT_FORUM'], 'i' => $user->lang['SORT_TOPIC_TITLE'], 's' => $user->lang['SORT_POST_SUBJECT']);
-$s_limit_days = $s_sort_key = $s_sort_dir = '';
-gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir);
+$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
+gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
-$store_vars = array('sort_by', 'sort_dir', 'show_results', 'return_chars', 'total_match_count');
+$store_vars = array('sort_key', 'sort_dir', 'sort_days', 'show_results', 'return_chars', 'total_match_count');
$current_time = time();
// Check last search time ... if applicable
@@ -136,7 +136,7 @@ if ($search_keywords || $search_author || $search_id)
$sql_author = '';
if ($search_author)
{
- $sql_where = (strstr($search_author, '*')) ? ' LIKE ' : ' = ';
+ $sql_where = (strstr($search_author, '*') !== false) ? ' LIKE ' : ' = ';
$sql = 'SELECT user_id
FROM ' . USERS_TABLE . "
WHERE username $sql_where '" . $db->sql_escape(preg_replace('#\*+#', '%', $search_author)) . "'";
@@ -154,6 +154,8 @@ if ($search_keywords || $search_author || $search_id)
if ($search_id)
{
+ $stopped_words = array();
+
switch ($search_id)
{
case 'egosearch':
@@ -227,6 +229,8 @@ if ($search_keywords || $search_author || $search_id)
break;
default:
+ $search_id = (int) $search_id;
+
$sql = 'SELECT search_array
FROM ' . SEARCH_TABLE . "
WHERE search_id = $search_id
@@ -263,53 +267,52 @@ if ($search_keywords || $search_author || $search_id)
$sql_author = ($sql_author) ? ' AND ' . $sql_author : '';
$split_words = $stopped_words = $smllrg_words = array();
- $drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!');
- $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '' , ' ', ' ', ' ', ' ', ' ', ' ');
+ $drop_char_match = array('-', '^', '$', ';', '#', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '\'', '!', '*');
+ $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '' , ' ', ' ', ' ', ' ', ' ');
if ($fp = @fopen($user->lang_path . '/search_stopwords.txt', 'rb'))
{
- $stopwords = explode("\n", str_replace("\r\n", "\n", trim(fread($fp, filesize($user->lang_path . '/search_stopwords.txt')))));
+ $stopwords = explode("\n", str_replace("\r\n", "\n", fread($fp, filesize($user->lang_path . '/search_stopwords.txt'))));
}
- @fclose($fp);
+ fclose($fp);
if ($fp = @fopen($user->lang_path . '/search_synonyms.txt', 'rb'))
{
- preg_match_all('#^(.*?) (.*?)$#ms', trim(fread($fp, filesize($user->lang_path . '/search_synonyms.txt'))), $match);
- $replace_synonym = $match[1];
- $match_synonym = $match[2];
+ preg_match_all('#^(.*?) (.*?)$#ms', fread($fp, filesize($user->lang_path . '/search_synonyms.txt')), $match);
+ $replace_synonym = &$match[1];
+ $match_synonym = &$match[2];
}
- @fclose($fp);
+ fclose($fp);
$match = array('#\sand\s#i', '#\sor\s#i', '#\snot\s#i', '#\+#', '#-#', '#\|#');
$replace = array(' + ', ' | ', ' - ', ' + ', ' - ', ' | ');
+
$search_keywords = preg_replace($match, $replace, $search_keywords);
$match = array();
+ // Comments for hardcoded bbcode elements (urls, smilies, html)
+ $match[] = '#(.*?)#is';
// New lines, carriage returns
$match[] = "#[\n\r]+#";
// NCRs like etc.
- $match[] = '#&[\#a-z0-9]+?;#i';
- // URL's
- $match[] = '#\b[\w]+:\/\/[a-z0-9\.\-]+(\/[a-z0-9\?\.%_\-\+=&\/]+)?#';
+ $match[] = '#(&|&)[\#a-z0-9]+?;#i';
// BBcode
- $match[] = '#\[img:[a-z0-9]{10,}\].*?\[\/img:[a-z0-9]{10,}\]#';
- $match[] = '#\[\/?url(=.*?)?\]#';
- $match[] = '#\[\/?[a-z\*=\+\-]+(\:?[0-9a-z]+)?:[a-z0-9]{10,}(\:[a-z0-9]+)?=?.*?\]#';
+ $match[] = '#\[\/?[a-z\*\+\-]+(=.*)?(\:?[0-9a-z]{5,})\]#';
// Filter out as above
- $search_keywords = preg_replace($match, ' ', strtolower($search_keywords));
+ $search_keywords = preg_replace($match, ' ', strtolower(trim($search_keywords)));
$search_keywords = str_replace($drop_char_match, $drop_char_replace, $search_keywords);
// Split words
$split_words = explode(' ', preg_replace('#\s+#', ' ', $search_keywords));
- if (!empty($stopwords))
+ if (sizeof($stopwords))
{
$stopped_words = array_intersect($split_words, $stopwords);
$split_words = array_diff($split_words, $stopwords);
}
- if (!empty($replace_synonym))
+ if (sizeof($replace_synonym))
{
$split_words = str_replace($replace_synonym, $match_synonym, $split_words);
}
@@ -371,7 +374,7 @@ if ($search_keywords || $search_author || $search_id)
$result_ary = array();
foreach (array('AND', 'OR', 'NOT') as $bool)
{
- if (is_array($sql_words[$bool]))
+ if (isset($sql_words[$bool]) && is_array($sql_words[$bool]))
{
switch ($bool)
{
@@ -386,7 +389,7 @@ if ($search_keywords || $search_author || $search_id)
$sql_where = (strstr($word, '%')) ? "LIKE $word" : "= $word";
- $sql_and = (sizeof($result_ary['AND'])) ? "AND $field IN (" . implode(', ', $result_ary['AND']) . ')' : '';
+ $sql_and = (isset($result_ary['AND']) && sizeof($result_ary['AND'])) ? "AND $field IN (" . implode(', ', $result_ary['AND']) . ')' : '';
$sql = "SELECT $sql_select
FROM $sql_from" . POSTS_TABLE . ' p, ' . SEARCH_MATCH_TABLE . ' m, ' . SEARCH_WORD_TABLE . " w
@@ -466,27 +469,30 @@ if ($search_keywords || $search_author || $search_id)
break;
}
}
+ else
+ {
+ $sql_words[$bool] = array();
+ }
}
- if (sizeof($result_ary['OR']))
+ if (isset($result_ary['OR']) && sizeof($result_ary['OR']))
{
- $post_id_ary = (sizeof($result_ary['AND'])) ? array_diff($result_ary['AND'], $result_ary['OR']) : $result_ary['OR'];
+ $post_id_ary = (isset($result_ary['AND']) && sizeof($result_ary['AND'])) ? array_diff($result_ary['AND'], $result_ary['OR']) : $result_ary['OR'];
}
else
{
- $post_id_ary = $result_ary['AND'];
+ $post_id_ary = (isset($result_ary['AND'])) ? $result_ary['AND'] : array();
}
- if (sizeof($result_ary['NOT']))
+ if (isset($result_ary['NOT']) && sizeof($result_ary['NOT']))
{
- $post_id_ary = array_diff($post_id_ary, $result_ary['NOT']);
+ $post_id_ary = (sizeof($post_id_ary)) ? array_diff($post_id_ary, $result_ary['NOT']) : array();
}
unset($result_ary);
$post_id_ary = array_unique($post_id_ary);
-
if (!sizeof($post_id_ary))
{
trigger_error($user->lang['NO_SEARCH_RESULTS']);
@@ -542,12 +548,12 @@ if ($search_keywords || $search_author || $search_id)
if ($result = $db->sql_query($sql))
{
$delete_search_ids = array();
- while($row = $db->sql_fetchrow($result))
+ while ($row = $db->sql_fetchrow($result))
{
$delete_search_ids[] = "'" . $db->sql_escape($row['session_id']) . "'";
}
- if (count($delete_search_ids))
+ if (sizeof($delete_search_ids))
{
$sql = 'DELETE FROM ' . SEARCH_TABLE . '
WHERE session_id NOT IN (' . implode(", ", $delete_search_ids) . ')';
@@ -574,14 +580,26 @@ if ($search_keywords || $search_author || $search_id)
srand ((double) microtime() * 1000000);
$search_id = rand();
- $sql = 'INSERT INTO ' . SEARCH_TABLE . " (search_id, session_id, search_time, search_array)
- VALUES($search_id, '" . $db->sql_escape($user->data['session_id']) . "', $current_time, '" . $db->sql_escape($data) . "')";
+ $sql_ary = array(
+ 'search_id' => $search_id,
+ 'session_id' => $user->data['session_id'],
+ 'search_time' => $current_time,
+ 'search_array' => $data
+ );
+
+ $sql = 'INSERT INTO ' . SEARCH_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
unset($data);
}
- // Include the bbcode parser
- include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
+ if ($show_results == 'posts')
+ {
+ include($phpbb_root_path . 'includes/functions_posting.'.$phpEx);
+ }
+ else
+ {
+ include($phpbb_root_path . 'includes/functions_display.'.$phpEx);
+ }
// Look up data ...
$per_page = ($show_results == 'posts') ? $config['posts_per_page'] : $config['topics_per_page'];
@@ -601,15 +619,21 @@ if ($search_keywords || $search_author || $search_id)
$template->assign_vars(array(
'SEARCH_MATCHES' => $l_search_matches,
'SEARCH_WORDS' => $split_words,
- 'IGNORED_WORDS' => ($ignored_words) ? $ignored_words : $user->lang['NO_IGNORE_WORDS'],
- 'PAGINATION' => generate_pagination("search.$phpEx$SID&search_id=$search_id&hilit=$hilit&sk=$sort_key&sd=$sort_dir&st=$sort_days", $total_match_count, $per_page, $start),
- 'PAGE_NUMBER' => on_page($total_match_count, $start),
+ 'IGNORED_WORDS' => ($ignored_words) ? $ignored_words : '',
+ 'PAGINATION' => generate_pagination("search.$phpEx$SID&search_id=$search_id&hilit=$hilit&$u_sort_param", $total_match_count, $per_page, $start),
+ 'PAGE_NUMBER' => on_page($total_match_count, $per_page, $start),
+ 'TOTAL_MATCHES' => $total_match_count,
'S_SELECT_SORT_DIR' => $s_sort_dir,
'S_SELECT_SORT_KEY' => $s_sort_key,
'S_SEARCH_ACTION' => "search.$phpEx$SID&search_id=$search_id",
+ 'S_SHOW_TOPICS' => ($show_results == 'posts') ? false : true,
- 'U_SEARCH_WORDS' => "search.$phpEx$SID&search_keywords=" . urlencode($split_words))
+ 'REPORTED_IMG' => $user->img('icon_reported', 'TOPIC_REPORTED'),
+ 'UNAPPROVED_IMG' => $user->img('icon_unapproved', 'TOPIC_UNAPPROVED'),
+ 'GOTO_PAGE_IMG' => $user->img('icon_post', 'GOTO_PAGE'),
+
+ 'U_SEARCH_WORDS' => "search.$phpEx$SID&show_results=$show_results&search_keywords=" . urlencode($split_words))
);
$u_hilit = urlencode($split_words);
@@ -666,86 +690,61 @@ if ($search_keywords || $search_author || $search_id)
if ($show_results == 'topics')
{
- $last_post_img = "' . $user->img('icon_post_latest', 'VIEW_LATEST_POST') . '';
+ $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
- $topic_author = ($row['topic_poster'] != ANONYMOUS) ? "' : '';
- $topic_author .= ($row['topic_poster'] != ANONYMOUS) ? $row['topic_first_poster_name'] : (($row['topic_first_poster_name'] != '') ? $row['topic_first_poster_name'] : $user->lang['GUEST']);
- $topic_author .= ($row['topic_poster'] != ANONYMOUS) ? '' : '';
+ $folder_img = $folder_alt = $topic_type = '';
+ topic_status($row, $replies, time(), time(), $folder_img, $folder_alt, $topic_type);
- $last_post_author = ($row['topic_last_poster_id'] == ANONYMOUS) ? (($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] . ' ' : $user->lang['GUEST'] . ' ') : "' . $row['topic_last_poster_name'] . '';
+ $tpl_ary = array(
+ 'TOPIC_AUTHOR' => topic_topic_author($row),
+ 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
+ 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
+ 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
+ 'LAST_POST_AUTHOR' => ($row['topic_last_poster_name'] != '') ? $row['topic_last_poster_name'] : $user->lang['GUEST'],
+ 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
+ 'REPLIES' => $replies,
+ 'VIEWS' => $row['topic_views'],
+ 'TOPIC_TYPE' => $topic_type,
- // Topic type/folder
- $topic_type = '';
- if ($row['topic_status'] == ITEM_MOVED)
- {
- $topic_type = $user->lang['VIEW_TOPIC_MOVED'] . ' ';
- $topic_id = $row['topic_moved_id'];
+ 'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'),
+ 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
+ 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? '' : '',
+ 'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', sprintf($user->lang['TOTAL_ATTACHMENTS'], $row['topic_attachment'])) : '',
- $folder_image = 'folder';
- $folder_alt = 'Topic_Moved';
- $newest_post_img = '';
- }
- else
- {
- switch ($row['topic_type'])
- {
- case POST_GLOBAL:
- case POST_ANNOUNCE:
- $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
- $folder = 'folder_announce';
- $folder_new = 'folder_announce_new';
- break;
+ 'S_TOPIC_TYPE' => $row['topic_type'],
+ 'S_USER_POSTED' => (!empty($row['mark_type'])) ? true : false,
- case POST_STICKY:
- $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
- $folder = 'folder_sticky';
- $folder_new = 'folder_sticky_new';
- break;
+ 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_gets('m_', $forum_id)) ? true : false,
+ 'S_TOPIC_UNAPPROVED' => (!$row['topic_approved'] && $auth->acl_gets('m_approve', $forum_id)) ? true : false,
- default:
- if ($replies >= $config['hot_threshold'])
- {
- $folder = 'folder_hot';
- $folder_new = 'folder_hot_new';
- }
- else
- {
- $folder = 'folder';
- $folder_new = 'folder_new';
- }
- break;
- }
- }
-
-
-
- $folder_img = ($unread_topic) ? $folder_new : $folder;
- $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
+ 'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id'] . '#' . $row['topic_last_post_id'],
+ 'U_LAST_POST_AUTHOR'=> ($row['topic_last_poster_id'] != ANONYMOUS && $row['topic_last_poster_id']) ? "memberlist.$phpEx$SID&mode=viewprofile&u={$row['topic_last_poster_id']}" : '',
+ 'U_MCP_REPORT' => "mcp.$phpEx?sid={$user->session_id}&mode=reports&t=$topic_id",
+ 'U_MCP_QUEUE' => "mcp.$phpEx?sid={$user->session_id}&i=queue&mode=approve_details&t=$topic_id"
+ );
}
else
{
- if (in_array($row['poster_id'], $zebra['foe']) && (!$view || $view != 'show' || $post_id != $row['post_id']))
+ if ((isset($zebra['foe']) && in_array($row['poster_id'], $zebra['foe'])) && (!$view || $view != 'show' || $post_id != $row['post_id']))
{
$template->assign_block_vars('searchresults', array(
'S_IGNORE_POST' => true,
- 'L_IGNORE_POST' => sprintf($user->lang['POST_BY_FOE'], $row['username'], "', ''))
+ 'L_IGNORE_POST' => sprintf($user->lang['POST_BY_FOE'], $row['username'], "', ''))
);
continue;
}
-/* if (!empty($censors))
+ if ($row['enable_html'])
{
- $row['post_text'] = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace(\$censors['match'], \$censors['replace'], '\\0')", '>' . $row['post_text'] . '<'), 1, -1));
- }*/
- $row['post_text'] = censor_text($row['post_text']);
-
- if ($row['bbcode_bitfield'])
- {
- $row['post_text'] = preg_replace('#\[\/?.*?:' . $row['bbcode_uid'] . '\]#s', '', $row['post_text']);
+ $row['post_text'] = preg_replace('#(<)([\/]?.*?)(>)#is', "<\\2>", $row['post_text']);
}
+ $row['post_text'] = censor_text($row['post_text']);
+
+ decode_message($row['post_text'], $row['bbcode_uid']);
+
if ($return_chars)
{
$row['post_text'] = (strlen($row['post_text']) < $return_chars + 3) ? $row['post_text'] : substr($row['post_text'], 0, $return_chars) . '...';
@@ -756,42 +755,27 @@ if ($search_keywords || $search_author || $search_id)
$row['post_text'] = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace('#\b(" . $hilit . ")\b#i', '\\\\1', '\\0')", '>' . $row['post_text'] . '<'), 1, -1));
$row['post_text'] = smilie_text($row['post_text']);
+
+ $tpl_ary = array(
+ 'POSTER_NAME' => ($row['poster_id'] == ANONYMOUS) ? ((!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST']) : $row['username'],
+ 'POST_SUBJECT' => censor_text($row['post_subject']),
+ 'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '',
+ 'MESSAGE' => (!empty($row['post_text'])) ? str_replace("\n", '
', $row['post_text']) : ''
+ );
}
- $template->assign_block_vars('searchresults', array(
+ $template->assign_block_vars('searchresults', array_merge($tpl_ary, array(
'FORUM_ID' => $forum_id,
'TOPIC_ID' => $topic_id,
'POST_ID' => ($show_results == 'posts') ? $row['post_id'] : false,
- 'TOPIC_AUTHOR' => $topic_author,
- 'FIRST_POST_TIME' => $user->format_date($row['topic_time'], $config['board_timezone']),
- 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
- 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
- 'LAST_POST_AUTHOR' => $last_post_author,
- 'GOTO_PAGE' => $goto_page,
- 'TOPIC_REPLIES' => ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'],
- 'TOPIC_VIEWS' => $row['topic_views'],
'FORUM_TITLE' => $row['forum_name'],
'TOPIC_TITLE' => censor_text($row['topic_title']),
- 'TOPIC_TYPE' => $topic_type,
-
- 'POSTER_NAME' => ($row['poster_id'] == ANONYMOUS) ? ((!empty($row['post_username'])) ? $row['post_username'] : $user->lang['GUEST']) : $row['username'],
- 'POST_SUBJECT' => censor_text($row['post_subject']),
- 'POST_DATE' => (!empty($row['post_time'])) ? $user->format_date($row['post_time']) : '',
- 'MESSAGE' => (!empty($row['post_text'])) ? str_replace("\n", '
', $row['post_text']) : '',
-
- 'LAST_POST_IMG' => $last_post_img,
- 'NEWEST_POST_IMG' => $newest_post_img,
- 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
- 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? '' : '',
- 'POST_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? '
' : '',
- 'ATTACH_ICON_IMG' => ($auth->acl_gets('f_download', 'u_download', $forum_id) && $row['topic_attachment']) ? $user->img('icon_attach', '') : '',
- 'MINI_POST_IMG' => ($row['post_time'] > $user->data['user_lastvisit'] && $row['post_time'] > $topic_last_read && $user->data['user_id'] != ANONYMOUS) ? $user->img('icon_post_new', $user->lang['NEW_POST']) : $user->img('icon_post', $user->lang['POST']),
'U_VIEW_TOPIC' => $view_topic_url,
'U_VIEW_FORUM' => "viewforum.$phpEx$SID&f=$forum_id",
- 'U_VIEW_POST' => (!empty($row['post_id'])) ? "viewtopic.$phpEx$SID&f=$forum_id&t=" . $row['topic_id'] . '&p=' . $row['post_id'] . '&hilit=' . $u_hilit . '#' . $row['post_id'] : '', )
- );
+ 'U_VIEW_POST' => (!empty($row['post_id'])) ? "viewtopic.$phpEx$SID&f=$forum_id&t=" . $row['topic_id'] . '&p=' . $row['post_id'] . '&hilit=' . $u_hilit . '#' . $row['post_id'] : '')
+ ));
}
$db->sql_freeresult($result);
@@ -799,7 +783,7 @@ if ($search_keywords || $search_author || $search_id)
page_header($user->lang['SEARCH']);
$template->set_filenames(array(
- 'body' => ($show_results == 'posts') ? 'search_results_posts.html' : 'search_results_topics.html')
+ 'body' => 'search_results.html')
);
make_jumpbox('viewforum.'.$phpEx);
@@ -819,6 +803,7 @@ $result = $db->sql_query($sql);
$right = $cat_right = $padding_inc = 0;
$padding = $forum_list = $holding = '';
$pad_store = array('0' => '');
+$search_forums = array();
while ($row = $db->sql_fetchrow($result))
{
if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
@@ -867,7 +852,6 @@ while ($row = $db->sql_fetchrow($result))
$db->sql_freeresult($result);
unset($pad_store);
-
// Number of chars returned
$s_characters = '';
$s_characters .= '';
@@ -886,12 +870,12 @@ $template->assign_vars(array(
'S_FORUM_OPTIONS' => $s_forums,
'S_SELECT_SORT_DIR' => $s_sort_dir,
'S_SELECT_SORT_KEY' => $s_sort_key,
- 'S_SELECT_SORT_DAYS' => $s_limit_days,
- 'S_HIDDEN_FIELDS' => $s_hidden_fields)
+ 'S_SELECT_SORT_DAYS' => $s_limit_days)
);
$sql = 'SELECT search_id, search_time, search_array
- FROM ' . SEARCH_TABLE;
+ FROM ' . SEARCH_TABLE . '
+ ORDER BY search_time DESC';
$result = $db->sql_query($sql);
$i = 0;
diff --git a/phpBB/styles/subSilver/template/search_body.html b/phpBB/styles/subSilver/template/search_body.html
index aacb55c0e6..47e485f021 100644
--- a/phpBB/styles/subSilver/template/search_body.html
+++ b/phpBB/styles/subSilver/template/search_body.html
@@ -58,8 +58,8 @@