Changeset 702 for trunk/forum/search.php
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/search.php
r400 r702 3 3 * 4 4 * @package phpBB3 5 * @version $Id : search.php 9040 2008-11-01 19:00:50Z naderman$5 * @version $Id$ 6 6 * @copyright (c) 2005 phpBB Group 7 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License … … 48 48 $search_forum = request_var('fid', array(0)); 49 49 50 // We put login boxes for the case if search_id is egosearch or unreadposts 51 // because a guest should be able to log in even if guests search is not permitted 52 53 // Egosearch is an author search 54 if ($search_id == 'egosearch') 55 { 56 $author_id = $user->data['user_id']; 57 58 if ($user->data['user_id'] == ANONYMOUS) 59 { 60 login_box('', $user->lang['LOGIN_EXPLAIN_EGOSEARCH']); 61 } 62 } 63 64 // Search for unread posts needs user to be logged in if topics tracking for guests is disabled 65 if ($search_id == 'unreadposts' && !$config['load_anon_lastread'] && !$user->data['is_registered']) 66 { 67 login_box('', $user->lang['LOGIN_EXPLAIN_UNREADSEARCH']); 68 } 69 50 70 // Is user able to search? Has search been disabled? 51 71 if (!$auth->acl_get('u_search') || !$auth->acl_getf_global('f_search') || !$config['load_search']) … … 85 105 $id_ary = array(); 86 106 87 // egosearch is an author search88 if ($search_id == 'egosearch')89 {90 $author_id = $user->data['user_id'];91 92 if ($user->data['user_id'] == ANONYMOUS)93 {94 login_box('', $user->lang['LOGIN_EXPLAIN_EGOSEARCH']);95 }96 }97 98 107 // If we are looking for authors get their ids 99 108 $author_id_ary = array(); 109 $sql_author_match = ''; 100 110 if ($author_id) 101 111 { … … 114 124 FROM ' . USERS_TABLE . " 115 125 WHERE $sql_where 116 AND user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';126 AND user_type <> " . USER_IGNORE; 117 127 $result = $db->sql_query_limit($sql, 100); 118 128 … … 122 132 } 123 133 $db->sql_freeresult($result); 134 135 $sql_where = (strpos($author, '*') !== false) ? ' post_username ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($author))) : " post_username = '" . $db->sql_escape(utf8_clean_string($author)) . "'"; 136 137 $sql = 'SELECT 1 as guest_post 138 FROM ' . POSTS_TABLE . " 139 WHERE $sql_where 140 AND poster_id = " . ANONYMOUS; 141 $result = $db->sql_query_limit($sql, 1); 142 $found_guest_post = $db->sql_fetchfield('guest_post'); 143 $db->sql_freeresult($result); 144 145 if ($found_guest_post) 146 { 147 $author_id_ary[] = ANONYMOUS; 148 $sql_author_match = (strpos($author, '*') !== false) ? ' ' . $db->sql_like_expression(str_replace('*', $db->any_char, utf8_clean_string($author))) : " = '" . $db->sql_escape(utf8_clean_string($author)) . "'"; 149 } 124 150 125 151 if (!sizeof($author_id_ary)) … … 156 182 $not_in_fid = (sizeof($ex_fid_ary)) ? 'WHERE ' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . " OR (f.forum_password <> '' AND fa.user_id <> " . (int) $user->data['user_id'] . ')' : ""; 157 183 158 $sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, f a.user_id184 $sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, f.forum_flags, fa.user_id 159 185 FROM ' . FORUMS_TABLE . ' f 160 186 LEFT JOIN ' . FORUMS_ACCESS_TABLE . " fa ON (fa.forum_id = f.forum_id … … 169 195 { 170 196 if ($row['forum_password'] && $row['user_id'] != $user->data['user_id']) 197 { 198 $ex_fid_ary[] = (int) $row['forum_id']; 199 continue; 200 } 201 202 // Exclude forums from active topics 203 if (!($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) && ($search_id == 'active_topics')) 171 204 { 172 205 $ex_fid_ary[] = (int) $row['forum_id']; … … 308 341 $last_post_time = ''; 309 342 } 310 311 343 312 344 if ($sort_key == 'a') … … 342 374 break; 343 375 376 case 'unreadposts': 377 $l_search_title = $user->lang['SEARCH_UNREAD']; 378 // force sorting 379 $show_results = 'topics'; 380 $sort_key = 't'; 381 $sort_by_sql['t'] = 't.topic_last_post_time'; 382 $sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC'); 383 384 $sql_where = 'AND t.topic_moved_id = 0 385 ' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . ' 386 ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : ''); 387 388 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); 389 $s_sort_key = $s_sort_dir = $u_sort_param = $s_limit_days = ''; 390 391 $unread_list = array(); 392 $unread_list = get_unread_topics($user->data['user_id'], $sql_where, $sql_sort); 393 394 if (!empty($unread_list)) 395 { 396 $sql = 'SELECT t.topic_id 397 FROM ' . TOPICS_TABLE . ' t 398 WHERE ' . $db->sql_in_set('t.topic_id', array_keys($unread_list)) . " 399 $sql_sort"; 400 $field = 'topic_id'; 401 } 402 break; 403 344 404 case 'newposts': 345 405 $l_search_title = $user->lang['SEARCH_NEW']; … … 373 433 ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . " 374 434 $sql_sort"; 435 /* 436 [Fix] queued replies missing from "view new posts" (Bug #42705 - Patch by Paul) 437 - Creates temporary table, query is far from optimized 438 439 $sql = 'SELECT t.topic_id 440 FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p 441 WHERE p.post_time > ' . $user->data['user_lastvisit'] . ' 442 AND t.topic_id = p.topic_id 443 AND t.topic_moved_id = 0 444 ' . $m_approve_fid_sql . ' 445 ' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . " 446 GROUP BY t.topic_id 447 $sql_sort"; 448 */ 375 449 $field = 'topic_id'; 376 450 } … … 396 470 while ($row = $db->sql_fetchrow($result)) 397 471 { 398 $id_ary[] = $row[$field];472 $id_ary[] = (int) $row[$field]; 399 473 } 400 474 $db->sql_freeresult($result); … … 416 490 if (!empty($search->search_query)) 417 491 { 418 $total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $ id_ary, $start, $per_page);492 $total_match_count = $search->keyword_search($show_results, $search_fields, $search_terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page); 419 493 } 420 494 else if (sizeof($author_id_ary)) 421 495 { 422 496 $firstpost_only = ($search_fields === 'firstpost' || $search_fields == 'titleonly') ? true : false; 423 $total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $ id_ary, $start, $per_page);497 $total_match_count = $search->author_search($show_results, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_id_ary, $sql_author_match, $id_ary, $start, $per_page); 424 498 } 425 499 … … 471 545 472 546 $u_hilit = urlencode(htmlspecialchars_decode(str_replace('|', ' ', $hilit))); 473 $u_show_results = ($show_results != 'posts') ? '&sr=' . $show_results : '';547 $u_show_results = '&sr=' . $show_results; 474 548 $u_search_forum = implode('&fid%5B%5D=', $search_forum); 475 549 476 550 $u_search = append_sid("{$phpbb_root_path}search.$phpEx", $u_sort_param . $u_show_results); 477 551 $u_search .= ($search_id) ? '&search_id=' . $search_id : ''; 478 $u_search .= ($u_hilit) ? '&keywords=' . urlencode(htmlspecialchars_decode($ search->search_query)) : '';552 $u_search .= ($u_hilit) ? '&keywords=' . urlencode(htmlspecialchars_decode($keywords)) : ''; 479 553 $u_search .= ($search_terms != 'all') ? '&terms=' . $search_terms : ''; 480 554 $u_search .= ($topic_id) ? '&t=' . $topic_id : ''; … … 582 656 while ($row = $db->sql_fetchrow($result)) 583 657 { 658 $row['forum_id'] = (int) $row['forum_id']; 659 $row['topic_id'] = (int) $row['topic_id']; 660 584 661 if ($row['topic_status'] == ITEM_MOVED) 585 662 { … … 768 845 } 769 846 770 $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$u_forum_id&t=$result_topic_id" . (($u_hilit) ? "&hilit=$u_hilit" : '')); 847 $view_topic_url_params = "f=$u_forum_id&t=$result_topic_id" . (($u_hilit) ? "&hilit=$u_hilit" : ''); 848 $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params); 771 849 772 850 $replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies']; … … 826 904 'S_POSTS_UNAPPROVED' => $posts_unapproved, 827 905 828 'U_LAST_POST' => $view_topic_url . '&p=' . $row['topic_last_post_id']. '#p' . $row['topic_last_post_id'],906 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], 829 907 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 830 908 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), 831 'U_NEWEST_POST' => $view_topic_url . '&view=unread#unread',909 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&view=unread') . '#unread', 832 910 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=reports&t=' . $result_topic_id, true, $user->session_id), 833 911 'U_MCP_QUEUE' => $u_mcp_queue, … … 930 1008 page_footer(); 931 1009 } 932 933 1010 934 1011 // Search forum
Note:
See TracChangeset
for help on using the changeset viewer.