diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 58bcd66ec0..855bdea0f6 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -234,7 +234,12 @@ class acp_search if (method_exists($this->search, 'delete_index')) { // pass a reference to myself so the $search object can make use of save_state() and attributes - $this->search->delete_index($this, $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=delete"); + if ($error = $this->search->delete_index($this, $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=delete")) + { + $this->state = array(''); + $this->save_state(); + trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js()); + } } else { @@ -269,25 +274,23 @@ class acp_search } $this->search->tidy(); - + $this->state = array(''); $this->save_state(); - /** - * @todo remove Javascript - */ - trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action) . ''); + trigger_error($user->lang['SEARCH_INDEX_REMOVED'] . adm_back_link($this->u_action) . $this->close_popup_js()); } else { if (method_exists($this->search, 'create_index')) { // pass a reference to myself so the $search object can make use of save_state() and attributes - $this->search->create_index($this, $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=create"); + if ($error = $this->search->create_index($this, $phpbb_admin_path . "index.$phpEx$SID&i=$id&mode=$mode&action=create")) + { + $this->state = array(''); + $this->save_state(); + trigger_error($error . adm_back_link($this->u_action) . $this->close_popup_js()); + } } else { @@ -319,14 +322,7 @@ class acp_search $this->state = array(''); $this->save_state(); - /** - * @todo remove Javascript - */ - trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action) . ''); + trigger_error($user->lang['SEARCH_INDEX_CREATED'] . adm_back_link($this->u_action) . $this->close_popup_js()); } } @@ -426,6 +422,18 @@ class acp_search adm_page_footer(); } + function close_popup_js() + { + /** + * @todo remove Javascript + */ + return ''; + } + function get_search_types() { global $phpbb_root_path, $phpEx; diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 3ef8fe0b2d..45597376fe 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -40,7 +40,7 @@ class fulltext_mysql extends search_backend } /** - * Checks for correct MySQL version and stores max/min word length in the config + * Checks for correct MySQL version and stores min/max word length in the config */ function init() { @@ -61,13 +61,19 @@ class fulltext_mysql extends search_backend } $result = $db->sql_query('SHOW TABLE STATUS LIKE \'' . POSTS_TABLE . '\''); - $engine = $db->sql_fetchfield('Engine', 0, $result); - if (!$engine) - { - $engine = $db->sql_fetchfield('Type', 0, $result); - } + $info = $db->sql_fetchrow($result); $db->sql_freeresult($result); + $engine = ''; + if (isset($info['Engine'])) + { + $engine = $info['Engine']; + } + else if (isset($info['Type'])) + { + $engine = $info['Type']; + } + if ($engine != 'MyISAM') { return $user->lang['FULLTEXT_MYSQL_NOT_MYISAM']; @@ -160,7 +166,7 @@ class fulltext_mysql extends search_backend } /** - * Turns text into an array of words that can be stored in the word list table + * Turns text into an array of words */ function split_message($text) { @@ -618,9 +624,10 @@ class fulltext_mysql extends search_backend { global $db; - if (strpos(SQL_LAYER, 'mysql') === false) + // Make sure we can actually use MySQL with fulltext indexes + if ($error = $this->init()) { - return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_VERSION']; + return $error; } if (!is_array($this->stats)) @@ -648,9 +655,10 @@ class fulltext_mysql extends search_backend { global $db; - if (strpos(SQL_LAYER, 'mysql') === false) + // Make sure we can actually use MySQL with fulltext indexes + if ($error = $this->init()) { - return $user->lang['FULLTEXT_MYSQL_INCOMPATIBLE_VERSION']; + return $error; } if (!is_array($this->stats)) @@ -706,6 +714,12 @@ class fulltext_mysql extends search_backend { global $db; + if (strpos(SQL_LAYER, 'mysql') === false) + { + $this->stats = array(); + return; + } + $sql = 'SHOW INDEX FROM ' . POSTS_TABLE; $result = $db->sql_query($sql); diff --git a/phpBB/includes/search/fulltext_phpbb.php b/phpBB/includes/search/fulltext_phpbb.php index 6d9a33baaa..b01e70621b 100644 --- a/phpBB/includes/search/fulltext_phpbb.php +++ b/phpBB/includes/search/fulltext_phpbb.php @@ -405,15 +405,15 @@ class fulltext_phpbb extends search_backend if ($sql_in) { - $sql = "SELECT $sql_select, COUNT(DISTINCT m.word_id) as matches + $sql = "SELECT $sql_select, COUNT(DISTINCT m.word_id) as matches, " . $sort_by_sql[$sort_key] . " FROM $sql_from$sql_sort_table" . POSTS_TABLE . ' p, ' . SEARCH_MATCH_TABLE . ' m, ' . SEARCH_WORD_TABLE . " w WHERE w.word_text IN ($sql_in) AND m.word_id = w.word_id AND w.word_common <> 1 AND p.post_id = m.post_id $sql_where_options - GROUP BY $field - ORDER BY $sql_sort"; + GROUP BY $field, " . $sort_by_sql[$sort_key] . ' + ORDER BY ' . $sql_sort; $result = $db->sql_query($sql); if (!($row = $db->sql_fetchrow($result))) @@ -689,8 +689,8 @@ class fulltext_phpbb extends search_backend AND t.topic_id = p.topic_id $sql_sort_join $sql_time - GROUP BY t.topic_id - ORDER BY $sql_sort"; + GROUP BY t.topic_id, " . $sort_by_sql[$sort_key] . ' + ORDER BY ' . $sql_sort; $field = 'topic_id'; } diff --git a/phpBB/search.php b/phpBB/search.php index 6b742d1a08..80ad3dccbe 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -28,10 +28,12 @@ $post_id = request_var('p', 0); $topic_id = request_var('t', 0); $view = request_var('view', ''); +$submit = request_var('submit', false); $keywords = request_var('keywords', ''); $add_keywords = request_var('add_keywords', ''); $author = request_var('author', ''); $show_results = ($topic_id) ? 'posts' : request_var('sr', 'posts'); +$show_results = ($show_results == 'posts') ? 'posts' : 'topics'; $search_terms = request_var('terms', 'all'); $search_fields = request_var('sf', 'all'); $search_child = request_var('sc', true); @@ -76,7 +78,7 @@ $sort_by_text = array('a' => $user->lang['SORT_AUTHOR'], 't' => $user->lang['SOR $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); -if ($keywords || $author || $search_id) +if ($keywords || $author || $search_id || $submit) { // clear arrays $id_ary = array(); @@ -231,6 +233,7 @@ if ($keywords || $author || $search_id) { // default to showing results as posts when performing an author search $show_results = ($topic_id) ? 'posts' : request_var('sr', ($search_id == 'egosearch') ? 'topics' : 'posts'); + $show_results = ($show_results == 'posts') ? 'posts' : 'topics'; } // define some variables needed for retrieving post_id/topic_id information @@ -241,9 +244,6 @@ if ($keywords || $author || $search_id) $sql = $field = ''; if ($search_id) { - // Build sql string for sorting - $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); - switch ($search_id) { // Oh holy Bob, bring us some activity... @@ -252,6 +252,7 @@ if ($keywords || $author || $search_id) $sort_key = 't'; $sort_dir = 'd'; $sort_by_sql['t'] = 't.topic_last_post_time'; + $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); if (!$sort_days) { @@ -262,7 +263,7 @@ if ($keywords || $author || $search_id) $last_post_time = (time() - ($sort_days * 24 * 3600)); - $sql = 'SELECT DISTINCT t.topic_id + $sql = 'SELECT DISTINCT t.topic_last_post_time, t.topic_id FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t WHERE p.post_time > $last_post_time AND t.topic_approved = 1 @@ -275,8 +276,10 @@ if ($keywords || $author || $search_id) case 'unanswered': $show_results = request_var('sr', 'topics'); + $show_results = ($show_results == 'posts') ? 'posts' : 'topics'; $sort_by_sql['t'] = ($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time'; $sort_by_sql['s'] = ($show_results == 'posts') ? 'p.post_subject' : 't.topic_title'; + $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); $sort_join = ($sort_key == 'f') ? FORUMS_TABLE . ' f, ' : ''; $sql_sort = ($sort_key == 'f') ? ' AND f.forum_id = p.forum_id ' . $sql_sort : $sql_sort; @@ -298,7 +301,7 @@ if ($keywords || $author || $search_id) } else { - $sql = "SELECT DISTINCT p.topic_id + $sql = 'SELECT DISTINCT ' . $sort_by_sql[$sort_key] . ", p.topic_id FROM $sort_join" . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t WHERE t.topic_replies = 0 AND p.topic_id = t.topic_id @@ -311,8 +314,10 @@ if ($keywords || $author || $search_id) case 'newposts': $show_results = request_var('sr', 'topics'); + $show_results = ($show_results == 'posts') ? 'posts' : 'topics'; $sort_by_sql['t'] = ($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time'; $sort_by_sql['s'] = ($show_results == 'posts') ? 'p.post_subject' : 't.topic_title'; + $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); $sort_join = ($sort_key == 'f') ? FORUMS_TABLE . ' f, ' : ''; $sql_sort = ($sort_key == 'f') ? ' AND f.forum_id = p.forum_id ' . $sql_sort : $sql_sort; @@ -339,7 +344,7 @@ if ($keywords || $author || $search_id) } else { - $sql = "SELECT DISTINCT p.topic_id + $sql = 'SELECT DISTINCT ' . $sort_by_sql[$sort_key] . ", p.topic_id FROM $sort_join" . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE p.post_time > ' . $user->data['user_lastvisit'] . " AND t.topic_id = p.topic_id @@ -418,7 +423,7 @@ if ($keywords || $author || $search_id) $hilit = htmlspecialchars(implode('|', str_replace(array('+', '-', '|'), '', $search->split_words))); $split_words = (sizeof($search->split_words)) ? htmlspecialchars(implode(' ', $search->split_words)) : ''; $u_hilit = urlencode($split_words); - $u_show_results = ($show_results != 'topic') ? '&sr=' . $show_results : ''; + $u_show_results = ($show_results != 'posts') ? '&sr=' . $show_results : ''; $u_search_forum = implode('&fid%5B%5D=', $search_forum); $u_search = "{$phpbb_root_path}search.$phpEx$SID"; @@ -585,10 +590,10 @@ if ($keywords || $author || $search_id) $view_topic_url = "{$phpbb_root_path}viewtopic.$phpEx$SID&f=$u_forum_id&t=$result_topic_id&hilit=$u_hilit"; + $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; + if ($show_results == 'topics') { - $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; - $folder_img = $folder_alt = $topic_type = ''; topic_status($row, $replies, (isset($topic_tracking_info[$forum_id][$row['topic_id']]) && $row['topic_last_post_time'] > $topic_tracking_info[$forum_id][$row['topic_id']]) ? true : false, $folder_img, $folder_alt, $topic_type); @@ -601,8 +606,6 @@ if ($keywords || $author || $search_id) '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, 'LAST_POST_IMG' => $user->img('icon_post_latest', 'VIEW_LATEST_POST'), @@ -675,6 +678,8 @@ if ($keywords || $author || $search_id) 'FORUM_TITLE' => $row['forum_name'], 'TOPIC_TITLE' => $topic_title, + 'TOPIC_REPLIES' => $replies, + 'TOPIC_VIEWS' => $row['topic_views'], 'U_VIEW_TOPIC' => $view_topic_url, 'U_VIEW_FORUM' => "{$phpbb_root_path}viewforum.$phpEx$SID&f=$forum_id", diff --git a/phpBB/styles/subSilver/template/search_body.html b/phpBB/styles/subSilver/template/search_body.html index 668edef756..61fc707270 100644 --- a/phpBB/styles/subSilver/template/search_body.html +++ b/phpBB/styles/subSilver/template/search_body.html @@ -42,7 +42,7 @@
{searchresults.REPLIES}
{searchresults.VIEWS}
{searchresults.TOPIC_REPLIES}
{searchresults.TOPIC_VIEWS}
{searchresults.LAST_POST_TIME}
{searchresults.LAST_POST_AUTHOR}{searchresults.LAST_POST_AUTHOR}
@@ -132,6 +132,6 @@
-