diff --git a/phpBB/admin/admin_forumauth.php b/phpBB/admin/admin_forumauth.php
index 70f046a8d6..d0b8f9b395 100644
--- a/phpBB/admin/admin_forumauth.php
+++ b/phpBB/admin/admin_forumauth.php
@@ -100,15 +100,13 @@ if( isset($HTTP_POST_VARS['submit']) )
if(!empty($forum_id))
{
- $sql = "UPDATE " . FORUMS_TABLE . " SET ";
-
if(isset($HTTP_POST_VARS['simpleauth']))
{
$simple_ary = $simple_auth_ary[$HTTP_POST_VARS['simpleauth']];
for($i = 0; $i < count($simple_ary); $i++)
{
- $sql .= ( ( $i < count($simple_ary) - 1 ) ? ', ' : '' ) . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i];
+ $sql .= ( ( $sql != '' ) ? ', ' : '' ) . $forum_auth_fields[$i] . ' = ' . $simple_ary[$i];
}
$sql .= " WHERE forum_id = $forum_id";
@@ -127,22 +125,21 @@ if( isset($HTTP_POST_VARS['submit']) )
}
}
- $sql .= ( ( $i < count($forum_auth_fields) - 1 ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value;
+ $sql .= ( ( $sql != '' ) ? ', ' : '' ) .$forum_auth_fields[$i] . ' = ' . $value;
}
- $sql .= " WHERE forum_id = $forum_id";
-
+ $sql = "UPDATE " . FORUMS_TABLE . " SET $sql WHERE forum_id = $forum_id";
}
if ( $sql != '' )
{
if ( !$db->sql_query($sql) )
{
- message_die(GENERAL_ERROR, "Couldn't update auth table!", "", __LINE__, __FILE__, $sql);
+ message_die(GENERAL_ERROR, 'Could not update auth table', '', __LINE__, __FILE__, $sql);
}
}
- $forum_sql = "";
+ $forum_sql = '';
$adv = 0;
}
diff --git a/phpBB/includes/auth.php b/phpBB/includes/auth.php
index 91ef800b4f..2140615aae 100644
--- a/phpBB/includes/auth.php
+++ b/phpBB/includes/auth.php
@@ -158,18 +158,18 @@ function auth($type, $forum_id, $userdata, $f_access = '')
if ( $row = $db->sql_fetchrow($result) )
{
- if ( $forum_id != AUTH_LIST_ALL)
+ do
{
- $u_access[] = $row;
- }
- else
- {
- do
+ if ( $forum_id != AUTH_LIST_ALL)
+ {
+ $u_access[] = $row;
+ }
+ else
{
$u_access[$row['forum_id']][] = $row;
}
- while( $row = $db->sql_fetchrow($result) );
}
+ while( $row = $db->sql_fetchrow($result) );
}
}
diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php
index 6f9ded1c51..2eac393be3 100644
--- a/phpBB/includes/bbcode.php
+++ b/phpBB/includes/bbcode.php
@@ -606,7 +606,7 @@ function make_clickable($text)
// matches an "xxxx://yyyy" URL at the start of a line, or after a space.
// xxxx can only be alpha characters.
// yyyy is anything up to the first space, newline, or comma.
- $ret = preg_replace("#([\n ])([a-z]+?)://([^,\t <\n\r]+)#i", "\\1\\2://\\3", $ret);
+ $ret = preg_replace("#([\n ])([a-z]+?)://([^\t <\n\r]+)#i", "\\1\\2://\\3", $ret);
// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
// Must contain at least 2 dots. xxxx contains either alphanum, or "-"
@@ -614,7 +614,7 @@ function make_clickable($text)
// zzzz is optional.. will contain everything up to the first space, newline, or comma.
// This is slightly restrictive - it's not going to match stuff like "forums.foo.com"
// This is to keep it from getting annoying and matching stuff that's not meant to be a link.
- $ret = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^,\t <\n\r]*)?)#i", "\\1www.\\2.\\3\\4", $ret);
+ $ret = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^\t <\n\r]*)?)#i", "\\1www.\\2.\\3\\4", $ret);
// matches an email@domain type address at the start of a line, or after a space.
// Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
diff --git a/phpBB/includes/functions_post.php b/phpBB/includes/functions_post.php
index f5af0a167f..9c77d25316 100644
--- a/phpBB/includes/functions_post.php
+++ b/phpBB/includes/functions_post.php
@@ -397,7 +397,7 @@ function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_i
$topic_update_sql .= "topic_replies = topic_replies - 1";
- $sql = "SELECT MAX(post_id) AS post_id
+ $sql = "SELECT MAX(post_id) AS last_post_id
FROM " . POSTS_TABLE . "
WHERE topic_id = $topic_id";
if ( !($db->sql_query($sql)) )
@@ -407,13 +407,13 @@ function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_i
if ( $row = $db->sql_fetchrow($result) )
{
- $topic_update_sql .= ', topic_last_post_id = ' . $row['post_id'];
+ $topic_update_sql .= ', topic_last_post_id = ' . $row['last_post_id'];
}
}
if ( $post_data['last_topic'] )
{
- $sql = "SELECT MAX(post_id) AS post_id
+ $sql = "SELECT MAX(post_id) AS last_post_id
FROM " . POSTS_TABLE . "
WHERE forum_id = $forum_id";
if ( !($db->sql_query($sql)) )
@@ -423,13 +423,13 @@ function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_i
if ( $row = $db->sql_fetchrow($result) )
{
- $forum_update_sql .= ( $row['post_id'] ) ? ', forum_last_post_id = ' . $row['post_id'] : ', forum_last_post_id = 0';
+ $forum_update_sql .= ( $row['last_post_id'] ) ? ', forum_last_post_id = ' . $row['last_post_id'] : ', forum_last_post_id = 0';
}
}
}
else if ( $post_data['first_post'] )
{
- $sql = "SELECT MIN(post_id) AS post_id
+ $sql = "SELECT MIN(post_id) AS first_post_id
FROM " . POSTS_TABLE . "
WHERE topic_id = $topic_id";
if ( !($db->sql_query($sql)) )
@@ -439,7 +439,7 @@ function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_i
if ( $row = $db->sql_fetchrow($result) )
{
- $topic_update_sql .= 'topic_replies = topic_replies - 1, topic_first_post_id = ' . $row['post_id'];
+ $topic_update_sql .= 'topic_replies = topic_replies - 1, topic_first_post_id = ' . $row['first_post_id'];
}
}
else
@@ -517,13 +517,6 @@ function delete_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
}
- $sql = "DELETE FROM " . SEARCH_MATCH_TABLE . "
- WHERE post_id = $post_id";
- if ( !($db->sql_query($sql)) )
- {
- message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
- }
-
$topic_update_sql .= 'topic_replies = topic_replies - 1';
if ( $post_data['last_post'] )
{
@@ -546,12 +539,14 @@ function delete_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
}
}
}
+
+ remove_search_post($post_id);
}
if( $mode == 'poll_delete' || ( $mode == 'delete' && $post_data['first_post'] && $post_data['last_post'] ) && $post_data['has_poll'] && $post_data['edit_poll'] )
{
$sql = "DELETE FROM " . VOTE_DESC_TABLE . "
- WHERE vote_id = $poll_id";
+ WHERE topic_id = $topic_id";
if ( !($db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in deleting poll', '', __LINE__, __FILE__, $sql);
@@ -572,7 +567,6 @@ function delete_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
}
}
- remove_search_post($post_id);
//
// Ok we set variables above that were intended to update the topics table
// so let's go ahead and use it already :)
diff --git a/phpBB/includes/functions_search.php b/phpBB/includes/functions_search.php
index f0ffbbcfdb..ab58a7f414 100644
--- a/phpBB/includes/functions_search.php
+++ b/phpBB/includes/functions_search.php
@@ -21,9 +21,8 @@
function clean_words($mode, &$entry, &$stopword_list, &$synonym_list)
{
- // Weird, $init_match doesn't work with static when double quotes (") are used...
static $drop_char_match = array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '-', '~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!');
- static $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ', ' ', ' ');
+ static $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ', ' ', ' ');
$entry = ' ' . strip_tags(strtolower($entry)) . ' ';
@@ -42,13 +41,10 @@ function clean_words($mode, &$entry, &$stopword_list, &$synonym_list)
}
else if ( $mode == 'search' )
{
- $entry = str_replace('+', ' and ', $entry);
- $entry = str_replace('-', ' not ', $entry);
+ $entry = str_replace(' +', ' and ', $entry);
+ $entry = str_replace(' -', ' not ', $entry);
}
- // Replace numbers on their own
- $entry = preg_replace('/\b[0-9]+\b/', ' ', $entry);
-
//
// Filter out strange characters like ^, $, &, change "it's" to "its"
//
@@ -61,8 +57,8 @@ function clean_words($mode, &$entry, &$stopword_list, &$synonym_list)
{
$entry = str_replace('*', ' ', $entry);
- // 'words' that consist of <=3 or >=25 characters are removed.
- $entry = preg_replace('/\b([a-z0-9]{1,3}|[a-z0-9]{20,})\b/',' ', $entry);
+ // 'words' that consist of <=3 or >=20 characters are removed.
+ $entry = preg_replace('/\b([a-z0-9]{1,3}|[a-z0-9]{21,})\b/',' ', $entry);
}
if ( !empty($stopword_list) )
@@ -95,14 +91,8 @@ function clean_words($mode, &$entry, &$stopword_list, &$synonym_list)
function split_words(&$entry, $mode = 'post')
{
- if ( $mode == 'post' )
- {
- preg_match_all("/\b(\w[\w']*\w+|\w+?)\b/", $entry, $split_entries);
- }
- else
- {
- preg_match_all('/(\*?[à-ÿa-z0-9]+\*?)|\b([à-ÿa-z0-9]+)\b/', $entry, $split_entries);
- }
+ $rex = ( $mode == 'post' ) ? "/\b(\w[\w']*\w+|\w+?)\b/" : '/(\*?[à-ÿa-z0-9]+\*?)|\b([à-ÿa-z0-9]+)\b/';
+ preg_match_all($rex, $entry, $split_entries);
return $split_entries[1];
}
diff --git a/phpBB/search.php b/phpBB/search.php
index 46e811be37..23677fcdef 100644
--- a/phpBB/search.php
+++ b/phpBB/search.php
@@ -117,6 +117,11 @@ $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) :
$sort_by_types = array($lang['Sort_Time'], $lang['Sort_Post_Subject'], $lang['Sort_Topic_Title'], $lang['Sort_Author'], $lang['Sort_Forum']);
+//
+// encoding match for workaround
+//
+$multibyte_charset = 'utf-8, big5, shift_jis, euc-kr, gb2312';
+
//
// Begin core code
//
@@ -235,10 +240,9 @@ else if ( $search_keywords != '' || $search_author != '' || $search_id )
$synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/search_synonyms.txt');
$split_search = array();
- $cleaned_search = clean_words('search', stripslashes($search_keywords), $stopword_array, $synonym_array);
- $split_search = split_words($cleaned_search, 'search');
+ $split_search = ( !strstr($multibyte_charset, $lang['ENCODING']) ) ? split_words(clean_words('search', stripslashes($search_keywords), $stopword_array, $synonym_array), 'search') : split(' ', $search_keywords);
- $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : '';
+ $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : ( ( strstr($multibyte_charset, $lang['ENCODING']) ) ? '' : '' );
$word_count = 0;
$current_match_type = 'or';
@@ -268,14 +272,25 @@ else if ( $search_keywords != '' || $search_author != '' || $search_id )
$current_match_type = 'and';
}
- $match_word = str_replace('*', '%', $split_search[$i]);
-
- $sql = "SELECT m.post_id
- FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
- WHERE w.word_text LIKE '$match_word'
- AND m.word_id = w.word_id
- AND w.word_common <> 1
+ if ( !strstr($multibyte_charset, $lang['ENCODING']) )
+ {
+ $match_word = str_replace('*', '%', $split_search[$i]);
+ $sql = "SELECT m.post_id
+ FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
+ WHERE w.word_text LIKE '$match_word'
+ AND m.word_id = w.word_id
+ AND w.word_common <> 1
+ $search_msg_only";
+ }
+ else
+ {
+ $match_word = addslashes('%' . str_replace('*', '', $split_search[$i]) . '%');
+ $search_msg_only = ( $search_fields ) ? "OR post_subject LIKE '$match_word'" : '';
+ $sql = "SELECT post_id
+ FROM " . POSTS_TEXT_TABLE . "
+ WHERE post_text LIKE '$match_word'
$search_msg_only";
+ }
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index 86a8e0a554..f6dec6853b 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -140,9 +140,9 @@ $join_sql_table = ( !isset($post_id) ) ? '' : ", " . POSTS_TABLE . " p, " . POST
$join_sql = ( !isset($post_id) ) ? "t.topic_id = $topic_id" : "p.post_id = $post_id AND t.topic_id = p.topic_id AND p2.topic_id = p.topic_id AND p2.post_id <= $post_id";
$count_sql = ( !isset($post_id) ) ? '' : ", COUNT(p2.post_id) AS prev_posts";
-$order_sql = ( !isset($post_id) ) ? '' : "GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments ORDER BY p.post_id ASC";
+$order_sql = ( !isset($post_id) ) ? '' : "GROUP BY p.post_id, t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments ORDER BY p.post_id ASC";
-$sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments" . $count_sql . "
+$sql = "SELECT t.topic_id, t.topic_title, t.topic_status, t.topic_replies, t.topic_time, t.topic_type, t.topic_vote, t.topic_last_post_id, f.forum_name, f.forum_status, f.forum_id, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_sticky, f.auth_announce, f.auth_pollcreate, f.auth_vote, f.auth_attachments" . $count_sql . "
FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f" . $join_sql_table . "
WHERE $join_sql
AND f.forum_id = t.forum_id
@@ -152,12 +152,12 @@ if ( !($result = $db->sql_query($sql)) )
message_die(GENERAL_ERROR, "Could not obtain topic information", '', __LINE__, __FILE__, $sql);
}
-if ( !($forum_row = $db->sql_fetchrow($result)) )
+if ( !($forum_topic_data = $db->sql_fetchrow($result)) )
{
message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
}
-$forum_id = $forum_row['forum_id'];
+$forum_id = $forum_topic_data['forum_id'];
//
// Start session management
@@ -172,7 +172,7 @@ init_userprefs($userdata);
// Start auth check
//
$is_auth = array();
-$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_row);
+$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_topic_data);
if( !$is_auth['auth_view'] || !$is_auth['auth_read'] )
{
@@ -192,14 +192,14 @@ if( !$is_auth['auth_view'] || !$is_auth['auth_read'] )
// End auth check
//
-$forum_name = $forum_row['forum_name'];
-$topic_title = $forum_row['topic_title'];
-$topic_id = $forum_row['topic_id'];
-$topic_time = $forum_row['topic_time'];
+$forum_name = $forum_topic_data['forum_name'];
+$topic_title = $forum_topic_data['topic_title'];
+$topic_id = $forum_topic_data['topic_id'];
+$topic_time = $forum_topic_data['topic_time'];
if ( !empty($post_id) )
{
- $start = floor(($forum_row['prev_posts'] - 1) / $board_config['posts_per_page']) * $board_config['posts_per_page'];
+ $start = floor(($forum_topic_data['prev_posts'] - 1) / $board_config['posts_per_page']) * $board_config['posts_per_page'];
}
//
@@ -342,7 +342,7 @@ if( !empty($HTTP_POST_VARS['postdays']) || !empty($HTTP_GET_VARS['postdays']) )
}
else
{
- $total_replies = $forum_row['topic_replies'] + 1;
+ $total_replies = $forum_topic_data['topic_replies'] + 1;
$limit_posts_time = '';
$post_days = 0;
@@ -499,10 +499,10 @@ $nav_links['up'] = array(
'title' => $forum_name
);
-$reply_img = ( $forum_row['forum_status'] == FORUM_LOCKED || $forum_row['topic_status'] == TOPIC_LOCKED ) ? $images['reply_locked'] : $images['reply_new'];
-$reply_alt = ( $forum_row['forum_status'] == FORUM_LOCKED || $forum_row['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['Reply_to_topic'];
-$post_img = ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $images['post_locked'] : $images['post_new'];
-$post_alt = ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'];
+$reply_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $images['reply_locked'] : $images['reply_new'];
+$reply_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED || $forum_topic_data['topic_status'] == TOPIC_LOCKED ) ? $lang['Topic_locked'] : $lang['Reply_to_topic'];
+$post_img = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $images['post_locked'] : $images['post_new'];
+$post_alt = ( $forum_topic_data['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'];
//
// Set a cookie for this topic
@@ -567,7 +567,7 @@ if ( $is_auth['auth_mod'] )
$topic_mod .= '
';
- $topic_mod .= ( $forum_row['topic_status'] == TOPIC_UNLOCKED ) ? '
' : '
';
+ $topic_mod .= ( $forum_topic_data['topic_status'] == TOPIC_UNLOCKED ) ? '
' : '
';
$topic_mod .= '
';
}
@@ -646,7 +646,7 @@ $template->assign_vars(array(
//
// Does this topic contain a poll?
//
-if ( !empty($forum_row['topic_vote']) )
+if ( !empty($forum_topic_data['topic_vote']) )
{
$sql = "SELECT vd.vote_id, vd.vote_text, vd.vote_start, vd.vote_length, vr.vote_option_id, vr.vote_option_text, vr.vote_result
FROM " . VOTE_DESC_TABLE . " vd, " . VOTE_RESULTS_TABLE . " vr
@@ -689,7 +689,7 @@ if ( !empty($forum_row['topic_vote']) )
$poll_expired = ( $vote_info[0]['vote_length'] ) ? ( ( $vote_info[0]['vote_start'] + $vote_info[0]['vote_length'] < time() ) ? TRUE : 0 ) : 0;
- if ( $user_voted || $view_result || $poll_expired || !$is_auth['auth_vote'] || $forum_row['topic_status'] == TOPIC_LOCKED )
+ if ( $user_voted || $view_result || $poll_expired || !$is_auth['auth_vote'] || $forum_topic_data['topic_status'] == TOPIC_LOCKED )
{
$template->set_filenames(array(
'pollbox' => 'viewtopic_poll_result.tpl')
@@ -987,7 +987,7 @@ for($i = 0; $i < $total_posts; $i++)
$ip_img = '';
$ip = '';
- if ( $userdata['user_id'] == $poster_id && $is_auth['auth_delete'] && $i == $total_replies - 1 )
+ if ( $userdata['user_id'] == $poster_id && $is_auth['auth_delete'] && $forum_topic_data['topic_last_post_id'] == $postrow[$i]['post_id'] )
{
$temp_url = append_sid("posting.$phpEx?mode=delete&" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
$delpost_img = '
';