diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2004-10-19 19:26:58 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2004-10-19 19:26:58 +0000 |
commit | c091164d7ed991e75ec4b9ef7f5b0fd25b46438e (patch) | |
tree | a3dd063dcb659db6f6c2bc0cb81d240e38f23dd1 /phpBB/includes | |
parent | 028c05a9a6977287380398119633ff789d23a49d (diff) | |
download | forums-c091164d7ed991e75ec4b9ef7f5b0fd25b46438e.tar forums-c091164d7ed991e75ec4b9ef7f5b0fd25b46438e.tar.gz forums-c091164d7ed991e75ec4b9ef7f5b0fd25b46438e.tar.bz2 forums-c091164d7ed991e75ec4b9ef7f5b0fd25b46438e.tar.xz forums-c091164d7ed991e75ec4b9ef7f5b0fd25b46438e.zip |
- search updates
git-svn-id: file:///svn/phpbb/trunk@5003 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/functions_messenger.php | 10 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 21 | ||||
-rw-r--r-- | phpBB/includes/message_parser.php | 64 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_pm_compose.php | 2 |
4 files changed, 41 insertions, 56 deletions
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 .= '<br /><br />' . 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); |