[1] | 1 | <?php |
---|
| 2 | |
---|
[3] | 3 | /** |
---|
| 4 | * Copyright (C) 2008-2011 FluxBB |
---|
| 5 | * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB |
---|
| 6 | * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher |
---|
| 7 | */ |
---|
[1] | 8 | |
---|
| 9 | // The contents of this file are very much inspired by the file search.php |
---|
[3] | 10 | // from the phpBB Group forum software phpBB2 (http://www.phpbb.com) |
---|
[1] | 11 | |
---|
[3] | 12 | define('PUN_ROOT', dirname(__FILE__).'/'); |
---|
[1] | 13 | require PUN_ROOT.'include/common.php'; |
---|
| 14 | |
---|
| 15 | // Load the search.php language file |
---|
| 16 | require PUN_ROOT.'lang/'.$pun_user['language'].'/search.php'; |
---|
[3] | 17 | require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php'; |
---|
[1] | 18 | |
---|
| 19 | |
---|
| 20 | if ($pun_user['g_read_board'] == '0') |
---|
| 21 | message($lang_common['No view']); |
---|
| 22 | else if ($pun_user['g_search'] == '0') |
---|
| 23 | message($lang_search['No search permission']); |
---|
| 24 | |
---|
[3] | 25 | require PUN_ROOT.'include/search_idx.php'; |
---|
[1] | 26 | |
---|
| 27 | // Figure out what to do :-) |
---|
| 28 | if (isset($_GET['action']) || isset($_GET['search_id'])) |
---|
| 29 | { |
---|
| 30 | $action = (isset($_GET['action'])) ? $_GET['action'] : null; |
---|
[3] | 31 | $forums = isset($_GET['forums']) ? (is_array($_GET['forums']) ? $_GET['forums'] : explode(',', $_GET['forums'])) : (isset($_GET['forum']) ? array($_GET['forum']) : array()); |
---|
| 32 | $sort_dir = (isset($_GET['sort_dir']) && $_GET['sort_dir'] == 'DESC') ? 'DESC' : 'ASC'; |
---|
[1] | 33 | |
---|
[3] | 34 | $forums = array_map('intval', $forums); |
---|
| 35 | |
---|
| 36 | // Allow the old action names for backwards compatibility reasons |
---|
| 37 | if ($action == 'show_user') |
---|
| 38 | $action = 'show_user_posts'; |
---|
| 39 | else if ($action == 'show_24h') |
---|
| 40 | $action = 'show_recent'; |
---|
| 41 | |
---|
[1] | 42 | // If a search_id was supplied |
---|
| 43 | if (isset($_GET['search_id'])) |
---|
| 44 | { |
---|
| 45 | $search_id = intval($_GET['search_id']); |
---|
| 46 | if ($search_id < 1) |
---|
| 47 | message($lang_common['Bad request']); |
---|
| 48 | } |
---|
| 49 | // If it's a regular search (keywords and/or author) |
---|
| 50 | else if ($action == 'search') |
---|
| 51 | { |
---|
[3] | 52 | $keywords = (isset($_GET['keywords'])) ? utf8_strtolower(pun_trim($_GET['keywords'])) : null; |
---|
| 53 | $author = (isset($_GET['author'])) ? utf8_strtolower(pun_trim($_GET['author'])) : null; |
---|
| 54 | |
---|
| 55 | if (preg_match('%^[\*\%]+$%', $keywords) || (pun_strlen(str_replace(array('*', '%'), '', $keywords)) < PUN_SEARCH_MIN_WORD && !is_cjk($keywords))) |
---|
[1] | 56 | $keywords = ''; |
---|
| 57 | |
---|
[3] | 58 | if (preg_match('%^[\*\%]+$%', $author) || pun_strlen(str_replace(array('*', '%'), '', $author)) < 2) |
---|
[1] | 59 | $author = ''; |
---|
| 60 | |
---|
| 61 | if (!$keywords && !$author) |
---|
| 62 | message($lang_search['No terms']); |
---|
| 63 | |
---|
| 64 | if ($author) |
---|
| 65 | $author = str_replace('*', '%', $author); |
---|
| 66 | |
---|
[3] | 67 | $show_as = (isset($_GET['show_as']) && $_GET['show_as'] == 'topics') ? 'topics' : 'posts'; |
---|
| 68 | $sort_by = (isset($_GET['sort_by'])) ? intval($_GET['sort_by']) : 0; |
---|
| 69 | $search_in = (!isset($_GET['search_in']) || $_GET['search_in'] == '0') ? 0 : (($_GET['search_in'] == '1') ? 1 : -1); |
---|
[1] | 70 | } |
---|
[3] | 71 | // If it's a user search (by ID) |
---|
| 72 | else if ($action == 'show_user_posts' || $action == 'show_user_topics' || $action == 'show_subscriptions') |
---|
[1] | 73 | { |
---|
[3] | 74 | $user_id = (isset($_GET['user_id'])) ? intval($_GET['user_id']) : $pun_user['id']; |
---|
[1] | 75 | if ($user_id < 2) |
---|
| 76 | message($lang_common['Bad request']); |
---|
[3] | 77 | |
---|
| 78 | // Subscribed topics can only be viewed by admins, moderators and the users themselves |
---|
| 79 | if ($action == 'show_subscriptions' && !$pun_user['is_admmod'] && $user_id != $pun_user['id']) |
---|
| 80 | message($lang_common['No permission']); |
---|
[1] | 81 | } |
---|
[3] | 82 | else if ($action == 'show_recent') |
---|
| 83 | $interval = isset($_GET['value']) ? intval($_GET['value']) : 86400; |
---|
| 84 | else if ($action == 'show_replies') |
---|
[1] | 85 | { |
---|
[3] | 86 | if ($pun_user['is_guest']) |
---|
[1] | 87 | message($lang_common['Bad request']); |
---|
| 88 | } |
---|
[3] | 89 | else if ($action != 'show_new' && $action != 'show_unanswered') |
---|
| 90 | message($lang_common['Bad request']); |
---|
[1] | 91 | |
---|
| 92 | |
---|
| 93 | // If a valid search_id was supplied we attempt to fetch the search results from the db |
---|
| 94 | if (isset($search_id)) |
---|
| 95 | { |
---|
| 96 | $ident = ($pun_user['is_guest']) ? get_remote_address() : $pun_user['username']; |
---|
| 97 | |
---|
[3] | 98 | $result = $db->query('SELECT search_data FROM '.$db->prefix.'search_cache WHERE id='.$search_id.' AND ident=\''.$db->escape($ident).'\'') or error('Unable to fetch search results', __FILE__, __LINE__, $db->error()); |
---|
[1] | 99 | if ($row = $db->fetch_assoc($result)) |
---|
| 100 | { |
---|
| 101 | $temp = unserialize($row['search_data']); |
---|
| 102 | |
---|
[3] | 103 | $search_ids = unserialize($temp['search_ids']); |
---|
[1] | 104 | $num_hits = $temp['num_hits']; |
---|
| 105 | $sort_by = $temp['sort_by']; |
---|
| 106 | $sort_dir = $temp['sort_dir']; |
---|
| 107 | $show_as = $temp['show_as']; |
---|
[3] | 108 | $search_type = $temp['search_type']; |
---|
[1] | 109 | |
---|
| 110 | unset($temp); |
---|
| 111 | } |
---|
| 112 | else |
---|
| 113 | message($lang_search['No hits']); |
---|
| 114 | } |
---|
| 115 | else |
---|
| 116 | { |
---|
| 117 | $keyword_results = $author_results = array(); |
---|
| 118 | |
---|
| 119 | // Search a specific forum? |
---|
[3] | 120 | $forum_sql = (!empty($forums) || (empty($forums) && $pun_config['o_search_all_forums'] == '0' && !$pun_user['is_admmod'])) ? ' AND t.forum_id IN ('.implode(',', $forums).')' : ''; |
---|
[1] | 121 | |
---|
| 122 | if (!empty($author) || !empty($keywords)) |
---|
| 123 | { |
---|
[3] | 124 | // Flood protection |
---|
| 125 | if ($pun_user['last_search'] && (time() - $pun_user['last_search']) < $pun_user['g_search_flood'] && (time() - $pun_user['last_search']) >= 0) |
---|
| 126 | message(sprintf($lang_search['Search flood'], $pun_user['g_search_flood'])); |
---|
| 127 | |
---|
| 128 | if (!$pun_user['is_guest']) |
---|
| 129 | $db->query('UPDATE '.$db->prefix.'users SET last_search='.time().' WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error()); |
---|
| 130 | else |
---|
| 131 | $db->query('UPDATE '.$db->prefix.'online SET last_search='.time().' WHERE ident=\''.$db->escape(get_remote_address()).'\'' ) or error('Unable to update user', __FILE__, __LINE__, $db->error()); |
---|
| 132 | |
---|
| 133 | switch ($sort_by) |
---|
[1] | 134 | { |
---|
[3] | 135 | case 1: |
---|
| 136 | $sort_by_sql = ($show_as == 'topics') ? 't.poster' : 'p.poster'; |
---|
| 137 | $sort_type = SORT_STRING; |
---|
| 138 | break; |
---|
[1] | 139 | |
---|
[3] | 140 | case 2: |
---|
| 141 | $sort_by_sql = 't.subject'; |
---|
| 142 | $sort_type = SORT_STRING; |
---|
| 143 | break; |
---|
[1] | 144 | |
---|
[3] | 145 | case 3: |
---|
| 146 | $sort_by_sql = 't.forum_id'; |
---|
| 147 | $sort_type = SORT_NUMERIC; |
---|
| 148 | break; |
---|
[1] | 149 | |
---|
[3] | 150 | case 4: |
---|
| 151 | $sort_by_sql = 't.last_post'; |
---|
| 152 | $sort_type = SORT_NUMERIC; |
---|
| 153 | break; |
---|
[1] | 154 | |
---|
[3] | 155 | default: |
---|
| 156 | $sort_by_sql = ($show_as == 'topics') ? 't.last_post' : 'p.posted'; |
---|
| 157 | $sort_type = SORT_NUMERIC; |
---|
| 158 | break; |
---|
| 159 | } |
---|
[1] | 160 | |
---|
[3] | 161 | // If it's a search for keywords |
---|
| 162 | if ($keywords) |
---|
| 163 | { |
---|
| 164 | // split the keywords into words |
---|
| 165 | $keywords_array = split_words($keywords, false); |
---|
[1] | 166 | |
---|
[3] | 167 | if (empty($keywords_array)) |
---|
| 168 | message($lang_search['No hits']); |
---|
[1] | 169 | |
---|
[3] | 170 | // Should we search in message body or topic subject specifically? |
---|
| 171 | $search_in_cond = ($search_in) ? (($search_in > 0) ? ' AND m.subject_match = 0' : ' AND m.subject_match = 1') : ''; |
---|
[1] | 172 | |
---|
| 173 | $word_count = 0; |
---|
| 174 | $match_type = 'and'; |
---|
[3] | 175 | |
---|
| 176 | $sort_data = array(); |
---|
| 177 | foreach ($keywords_array as $cur_word) |
---|
[1] | 178 | { |
---|
| 179 | switch ($cur_word) |
---|
| 180 | { |
---|
| 181 | case 'and': |
---|
| 182 | case 'or': |
---|
| 183 | case 'not': |
---|
| 184 | $match_type = $cur_word; |
---|
| 185 | break; |
---|
| 186 | |
---|
| 187 | default: |
---|
| 188 | { |
---|
[3] | 189 | if (is_cjk($cur_word)) |
---|
[1] | 190 | { |
---|
[3] | 191 | $where_cond = str_replace('*', '%', $cur_word); |
---|
| 192 | $where_cond = ($search_in ? (($search_in > 0) ? 'p.message LIKE \'%'.$db->escape($where_cond).'%\'' : 't.subject LIKE \'%'.$db->escape($where_cond).'%\'') : 'p.message LIKE \'%'.$db->escape($where_cond).'%\' OR t.subject LIKE \'%'.$db->escape($where_cond).'%\''); |
---|
[1] | 193 | |
---|
[3] | 194 | $result = $db->query('SELECT p.id AS post_id, p.topic_id, '.$sort_by_sql.' AS sort_by FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE ('.$where_cond.') AND (fp.read_forum IS NULL OR fp.read_forum=1)'.$forum_sql, true) or error('Unable to search for posts', __FILE__, __LINE__, $db->error()); |
---|
[1] | 195 | } |
---|
| 196 | else |
---|
[3] | 197 | $result = $db->query('SELECT m.post_id, p.topic_id, '.$sort_by_sql.' AS sort_by FROM '.$db->prefix.'search_words AS w INNER JOIN '.$db->prefix.'search_matches AS m ON m.word_id = w.id INNER JOIN '.$db->prefix.'posts AS p ON p.id=m.post_id INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE w.word LIKE \''.$db->escape(str_replace('*', '%', $cur_word)).'\''.$search_in_cond.' AND (fp.read_forum IS NULL OR fp.read_forum=1)'.$forum_sql, true) or error('Unable to search for posts', __FILE__, __LINE__, $db->error()); |
---|
[1] | 198 | |
---|
| 199 | $row = array(); |
---|
[3] | 200 | while ($temp = $db->fetch_assoc($result)) |
---|
[1] | 201 | { |
---|
[3] | 202 | $row[$temp['post_id']] = $temp['topic_id']; |
---|
[1] | 203 | |
---|
| 204 | if (!$word_count) |
---|
[3] | 205 | { |
---|
| 206 | $keyword_results[$temp['post_id']] = $temp['topic_id']; |
---|
| 207 | $sort_data[$temp['post_id']] = $temp['sort_by']; |
---|
| 208 | } |
---|
[1] | 209 | else if ($match_type == 'or') |
---|
[3] | 210 | { |
---|
| 211 | $keyword_results[$temp['post_id']] = $temp['topic_id']; |
---|
| 212 | $sort_data[$temp['post_id']] = $temp['sort_by']; |
---|
| 213 | } |
---|
[1] | 214 | else if ($match_type == 'not') |
---|
[3] | 215 | { |
---|
| 216 | unset($keyword_results[$temp['post_id']]); |
---|
| 217 | unset($sort_data[$temp['post_id']]); |
---|
| 218 | } |
---|
[1] | 219 | } |
---|
| 220 | |
---|
| 221 | if ($match_type == 'and' && $word_count) |
---|
| 222 | { |
---|
[3] | 223 | foreach ($keyword_results as $post_id => $topic_id) |
---|
[1] | 224 | { |
---|
| 225 | if (!isset($row[$post_id])) |
---|
[3] | 226 | { |
---|
| 227 | unset($keyword_results[$post_id]); |
---|
| 228 | unset($sort_data[$post_id]); |
---|
| 229 | } |
---|
[1] | 230 | } |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | ++$word_count; |
---|
| 234 | $db->free_result($result); |
---|
| 235 | |
---|
| 236 | break; |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | |
---|
[3] | 241 | // Sort the results - annoyingly array_multisort re-indexes arrays with numeric keys, so we need to split the keys out into a seperate array then combine them again after |
---|
| 242 | $post_ids = array_keys($keyword_results); |
---|
| 243 | $topic_ids = array_values($keyword_results); |
---|
[1] | 244 | |
---|
[3] | 245 | array_multisort(array_values($sort_data), $sort_dir == 'DESC' ? SORT_DESC : SORT_ASC, $sort_type, $post_ids, $topic_ids); |
---|
| 246 | |
---|
| 247 | // combine the arrays back into a key=>value array (array_combine is PHP5 only unfortunately) |
---|
| 248 | $num_results = count($keyword_results); |
---|
| 249 | $keyword_results = array(); |
---|
| 250 | for ($i = 0;$i < $num_results;$i++) |
---|
| 251 | $keyword_results[$post_ids[$i]] = $topic_ids[$i]; |
---|
| 252 | |
---|
| 253 | unset($sort_data, $post_ids, $topic_ids); |
---|
[1] | 254 | } |
---|
| 255 | |
---|
| 256 | // If it's a search for author name (and that author name isn't Guest) |
---|
[3] | 257 | if ($author && $author != 'guest' && $author != utf8_strtolower($lang_common['Guest'])) |
---|
[1] | 258 | { |
---|
| 259 | switch ($db_type) |
---|
| 260 | { |
---|
| 261 | case 'pgsql': |
---|
[3] | 262 | $result = $db->query('SELECT id FROM '.$db->prefix.'users WHERE username ILIKE \''.$db->escape($author).'\'') or error('Unable to fetch users', __FILE__, __LINE__, $db->error()); |
---|
[1] | 263 | break; |
---|
| 264 | |
---|
| 265 | default: |
---|
[3] | 266 | $result = $db->query('SELECT id FROM '.$db->prefix.'users WHERE username LIKE \''.$db->escape($author).'\'') or error('Unable to fetch users', __FILE__, __LINE__, $db->error()); |
---|
[1] | 267 | break; |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | if ($db->num_rows($result)) |
---|
| 271 | { |
---|
[3] | 272 | $user_ids = array(); |
---|
[1] | 273 | while ($row = $db->fetch_row($result)) |
---|
[3] | 274 | $user_ids[] = $row[0]; |
---|
[1] | 275 | |
---|
[3] | 276 | $result = $db->query('SELECT p.id AS post_id, p.topic_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.poster_id IN('.implode(',', $user_ids).')'.$forum_sql.' ORDER BY '.$sort_by_sql.' '.$sort_dir) or error('Unable to fetch matched posts list', __FILE__, __LINE__, $db->error()); |
---|
| 277 | while ($temp = $db->fetch_assoc($result)) |
---|
| 278 | $author_results[$temp['post_id']] = $temp['topic_id']; |
---|
[1] | 279 | |
---|
| 280 | $db->free_result($result); |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | |
---|
[3] | 284 | // If we searched for both keywords and author name we want the intersection between the results |
---|
[1] | 285 | if ($author && $keywords) |
---|
| 286 | { |
---|
[3] | 287 | $search_ids = array_intersect_assoc($keyword_results, $author_results); |
---|
| 288 | $search_type = array('both', array($keywords, pun_trim($_GET['author'])), implode(',', $forums), $search_in); |
---|
[1] | 289 | } |
---|
| 290 | else if ($keywords) |
---|
[3] | 291 | { |
---|
[1] | 292 | $search_ids = $keyword_results; |
---|
[3] | 293 | $search_type = array('keywords', $keywords, implode(',', $forums), $search_in); |
---|
| 294 | } |
---|
[1] | 295 | else |
---|
[3] | 296 | { |
---|
[1] | 297 | $search_ids = $author_results; |
---|
[3] | 298 | $search_type = array('author', pun_trim($_GET['author']), implode(',', $forums), $search_in); |
---|
| 299 | } |
---|
[1] | 300 | |
---|
[3] | 301 | unset($keyword_results, $author_results); |
---|
[1] | 302 | |
---|
| 303 | if ($show_as == 'topics') |
---|
[3] | 304 | $search_ids = array_values($search_ids); |
---|
[1] | 305 | else |
---|
[3] | 306 | $search_ids = array_keys($search_ids); |
---|
[1] | 307 | |
---|
[3] | 308 | $search_ids = array_unique($search_ids); |
---|
[1] | 309 | |
---|
[3] | 310 | $num_hits = count($search_ids); |
---|
| 311 | if (!$num_hits) |
---|
| 312 | message($lang_search['No hits']); |
---|
[1] | 313 | } |
---|
[3] | 314 | else if ($action == 'show_new' || $action == 'show_recent' || $action == 'show_replies' || $action == 'show_user_posts' || $action == 'show_user_topics' || $action == 'show_subscriptions' || $action == 'show_unanswered') |
---|
[1] | 315 | { |
---|
[3] | 316 | $search_type = array('action', $action); |
---|
| 317 | $show_as = 'topics'; |
---|
| 318 | // We want to sort things after last post |
---|
| 319 | $sort_by = 0; |
---|
| 320 | $sort_dir = 'DESC'; |
---|
| 321 | |
---|
| 322 | // If it's a search for new posts since last visit |
---|
[1] | 323 | if ($action == 'show_new') |
---|
| 324 | { |
---|
| 325 | if ($pun_user['is_guest']) |
---|
| 326 | message($lang_common['No permission']); |
---|
| 327 | |
---|
[3] | 328 | $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.last_post>'.$pun_user['last_visit'].' AND t.moved_to IS NULL'.(isset($_GET['fid']) ? ' AND t.forum_id='.intval($_GET['fid']) : '').' ORDER BY t.last_post DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error()); |
---|
[1] | 329 | $num_hits = $db->num_rows($result); |
---|
| 330 | |
---|
| 331 | if (!$num_hits) |
---|
| 332 | message($lang_search['No new posts']); |
---|
| 333 | } |
---|
[3] | 334 | // If it's a search for recent posts (in a certain time interval) |
---|
| 335 | else if ($action == 'show_recent') |
---|
[1] | 336 | { |
---|
[3] | 337 | $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.last_post>'.(time() - $interval).' AND t.moved_to IS NULL'.(isset($_GET['fid']) ? ' AND t.forum_id='.intval($_GET['fid']) : '').' ORDER BY t.last_post DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error()); |
---|
[1] | 338 | $num_hits = $db->num_rows($result); |
---|
| 339 | |
---|
| 340 | if (!$num_hits) |
---|
| 341 | message($lang_search['No recent posts']); |
---|
| 342 | } |
---|
[3] | 343 | // If it's a search for topics in which the user has posted |
---|
| 344 | else if ($action == 'show_replies') |
---|
| 345 | { |
---|
| 346 | $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.poster_id='.$pun_user['id'].' GROUP BY t.id'.($db_type == 'pgsql' ? ', t.last_post' : '').' ORDER BY t.last_post DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error()); |
---|
| 347 | $num_hits = $db->num_rows($result); |
---|
| 348 | |
---|
| 349 | if (!$num_hits) |
---|
| 350 | message($lang_search['No user posts']); |
---|
| 351 | } |
---|
[1] | 352 | // If it's a search for posts by a specific user ID |
---|
[3] | 353 | else if ($action == 'show_user_posts') |
---|
[1] | 354 | { |
---|
[3] | 355 | $show_as = 'posts'; |
---|
| 356 | |
---|
| 357 | $result = $db->query('SELECT p.id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON p.topic_id=t.id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.poster_id='.$user_id.' ORDER BY p.posted DESC') or error('Unable to fetch user posts', __FILE__, __LINE__, $db->error()); |
---|
[1] | 358 | $num_hits = $db->num_rows($result); |
---|
| 359 | |
---|
| 360 | if (!$num_hits) |
---|
| 361 | message($lang_search['No user posts']); |
---|
[3] | 362 | |
---|
| 363 | // Pass on the user ID so that we can later know whos posts we're searching for |
---|
| 364 | $search_type[2] = $user_id; |
---|
[1] | 365 | } |
---|
[3] | 366 | // If it's a search for topics by a specific user ID |
---|
| 367 | else if ($action == 'show_user_topics') |
---|
| 368 | { |
---|
| 369 | $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON t.first_post_id=p.id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.poster_id='.$user_id.' ORDER BY t.last_post DESC') or error('Unable to fetch user topics', __FILE__, __LINE__, $db->error()); |
---|
| 370 | $num_hits = $db->num_rows($result); |
---|
| 371 | |
---|
| 372 | if (!$num_hits) |
---|
| 373 | message($lang_search['No user topics']); |
---|
| 374 | |
---|
| 375 | // Pass on the user ID so that we can later know whos topics we're searching for |
---|
| 376 | $search_type[2] = $user_id; |
---|
| 377 | } |
---|
[1] | 378 | // If it's a search for subscribed topics |
---|
| 379 | else if ($action == 'show_subscriptions') |
---|
| 380 | { |
---|
| 381 | if ($pun_user['is_guest']) |
---|
| 382 | message($lang_common['Bad request']); |
---|
| 383 | |
---|
[3] | 384 | $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'topic_subscriptions AS s ON (t.id=s.topic_id AND s.user_id='.$user_id.') LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) ORDER BY t.last_post DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error()); |
---|
[1] | 385 | $num_hits = $db->num_rows($result); |
---|
| 386 | |
---|
| 387 | if (!$num_hits) |
---|
| 388 | message($lang_search['No subscriptions']); |
---|
[3] | 389 | |
---|
| 390 | // Pass on user ID so that we can later know whose subscriptions we're searching for |
---|
| 391 | $search_type[2] = $user_id; |
---|
[1] | 392 | } |
---|
| 393 | // If it's a search for unanswered posts |
---|
| 394 | else |
---|
| 395 | { |
---|
[3] | 396 | $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.num_replies=0 AND t.moved_to IS NULL ORDER BY t.last_post DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error()); |
---|
[1] | 397 | $num_hits = $db->num_rows($result); |
---|
| 398 | |
---|
| 399 | if (!$num_hits) |
---|
| 400 | message($lang_search['No unanswered']); |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | $search_ids = array(); |
---|
| 404 | while ($row = $db->fetch_row($result)) |
---|
| 405 | $search_ids[] = $row[0]; |
---|
| 406 | |
---|
| 407 | $db->free_result($result); |
---|
| 408 | } |
---|
| 409 | else |
---|
| 410 | message($lang_common['Bad request']); |
---|
| 411 | |
---|
| 412 | |
---|
| 413 | // Prune "old" search results |
---|
| 414 | $old_searches = array(); |
---|
[3] | 415 | $result = $db->query('SELECT ident FROM '.$db->prefix.'online') or error('Unable to fetch online list', __FILE__, __LINE__, $db->error()); |
---|
[1] | 416 | |
---|
| 417 | if ($db->num_rows($result)) |
---|
| 418 | { |
---|
| 419 | while ($row = $db->fetch_row($result)) |
---|
| 420 | $old_searches[] = '\''.$db->escape($row[0]).'\''; |
---|
| 421 | |
---|
[3] | 422 | $db->query('DELETE FROM '.$db->prefix.'search_cache WHERE ident NOT IN('.implode(',', $old_searches).')') or error('Unable to delete search results', __FILE__, __LINE__, $db->error()); |
---|
[1] | 423 | } |
---|
| 424 | |
---|
| 425 | // Fill an array with our results and search properties |
---|
[3] | 426 | $temp = serialize(array( |
---|
| 427 | 'search_ids' => serialize($search_ids), |
---|
| 428 | 'num_hits' => $num_hits, |
---|
| 429 | 'sort_by' => $sort_by, |
---|
| 430 | 'sort_dir' => $sort_dir, |
---|
| 431 | 'show_as' => $show_as, |
---|
| 432 | 'search_type' => $search_type |
---|
| 433 | )); |
---|
[1] | 434 | $search_id = mt_rand(1, 2147483647); |
---|
| 435 | |
---|
| 436 | $ident = ($pun_user['is_guest']) ? get_remote_address() : $pun_user['username']; |
---|
| 437 | |
---|
[3] | 438 | $db->query('INSERT INTO '.$db->prefix.'search_cache (id, ident, search_data) VALUES('.$search_id.', \''.$db->escape($ident).'\', \''.$db->escape($temp).'\')') or error('Unable to insert search results', __FILE__, __LINE__, $db->error()); |
---|
[1] | 439 | |
---|
[3] | 440 | if ($search_type[0] != 'action') |
---|
[1] | 441 | { |
---|
| 442 | $db->end_transaction(); |
---|
| 443 | $db->close(); |
---|
| 444 | |
---|
| 445 | // Redirect the user to the cached result page |
---|
| 446 | header('Location: search.php?search_id='.$search_id); |
---|
| 447 | exit; |
---|
| 448 | } |
---|
| 449 | } |
---|
| 450 | |
---|
[3] | 451 | $forum_actions = array(); |
---|
[1] | 452 | |
---|
[3] | 453 | // If we're on the new posts search, display a "mark all as read" link |
---|
| 454 | if (!$pun_user['is_guest'] && $search_type[0] == 'action' && $search_type[1] == 'show_new') |
---|
| 455 | $forum_actions[] = '<a href="misc.php?action=markread">'.$lang_common['Mark all as read'].'</a>'; |
---|
| 456 | |
---|
[1] | 457 | // Fetch results to display |
---|
[3] | 458 | if (!empty($search_ids)) |
---|
[1] | 459 | { |
---|
| 460 | switch ($sort_by) |
---|
| 461 | { |
---|
| 462 | case 1: |
---|
| 463 | $sort_by_sql = ($show_as == 'topics') ? 't.poster' : 'p.poster'; |
---|
| 464 | break; |
---|
| 465 | |
---|
| 466 | case 2: |
---|
| 467 | $sort_by_sql = 't.subject'; |
---|
| 468 | break; |
---|
| 469 | |
---|
| 470 | case 3: |
---|
| 471 | $sort_by_sql = 't.forum_id'; |
---|
| 472 | break; |
---|
| 473 | |
---|
| 474 | default: |
---|
[3] | 475 | $sort_by_sql = ($show_as == 'topics') ? 't.last_post' : 'p.posted'; |
---|
[1] | 476 | break; |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | // Determine the topic or post offset (based on $_GET['p']) |
---|
| 480 | $per_page = ($show_as == 'posts') ? $pun_user['disp_posts'] : $pun_user['disp_topics']; |
---|
| 481 | $num_pages = ceil($num_hits / $per_page); |
---|
| 482 | |
---|
[3] | 483 | $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']); |
---|
[1] | 484 | $start_from = $per_page * ($p - 1); |
---|
| 485 | |
---|
| 486 | // Generate paging links |
---|
[3] | 487 | $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'search.php?search_id='.$search_id); |
---|
[1] | 488 | |
---|
[3] | 489 | // throw away the first $start_from of $search_ids, only keep the top $per_page of $search_ids |
---|
| 490 | $search_ids = array_slice($search_ids, $start_from, $per_page); |
---|
[1] | 491 | |
---|
[3] | 492 | // Run the query and fetch the results |
---|
| 493 | if ($show_as == 'posts') |
---|
| 494 | $result = $db->query('SELECT p.id AS pid, p.poster AS pposter, p.posted AS pposted, p.poster_id, p.message, p.hide_smilies, t.id AS tid, t.poster, t.subject, t.first_post_id, t.last_post, t.last_post_id, t.last_poster, t.num_replies, t.forum_id, f.forum_name FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE p.id IN('.implode(',', $search_ids).') ORDER BY '.$sort_by_sql.' '.$sort_dir) or error('Unable to fetch search results', __FILE__, __LINE__, $db->error()); |
---|
| 495 | else |
---|
| 496 | $result = $db->query('SELECT t.id AS tid, t.poster, t.subject, t.last_post, t.last_post_id, t.last_poster, t.num_replies, t.closed, t.sticky, t.forum_id, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.id IN('.implode(',', $search_ids).') ORDER BY '.$sort_by_sql.' '.$sort_dir) or error('Unable to fetch search results', __FILE__, __LINE__, $db->error()); |
---|
[1] | 497 | |
---|
| 498 | $search_set = array(); |
---|
| 499 | while ($row = $db->fetch_assoc($result)) |
---|
| 500 | $search_set[] = $row; |
---|
| 501 | |
---|
[3] | 502 | $crumbs_text = array(); |
---|
| 503 | $crumbs_text['show_as'] = $lang_search['Search']; |
---|
[1] | 504 | |
---|
[3] | 505 | if ($search_type[0] == 'action') |
---|
| 506 | { |
---|
| 507 | if ($search_type[1] == 'show_user_topics') |
---|
| 508 | $crumbs_text['search_type'] = '<a href="search.php?action=show_user_topics&user_id='.$search_type[2].'">'.sprintf($lang_search['Quick search show_user_topics'], pun_htmlspecialchars($search_set[0]['poster'])).'</a>'; |
---|
| 509 | else if ($search_type[1] == 'show_user_posts') |
---|
| 510 | $crumbs_text['search_type'] = '<a href="search.php?action=show_user_posts&user_id='.$search_type[2].'">'.sprintf($lang_search['Quick search show_user_posts'], pun_htmlspecialchars($search_set[0]['pposter'])).'</a>'; |
---|
| 511 | else if ($search_type[1] == 'show_subscriptions') |
---|
| 512 | { |
---|
| 513 | // Fetch username of subscriber |
---|
| 514 | $subscriber_id = $search_type[2]; |
---|
| 515 | $result = $db->query('SELECT username FROM '.$db->prefix.'users WHERE id='.$subscriber_id) or error('Unable to fetch username of subscriber', __FILE__, __LINE__, $db->error()); |
---|
| 516 | |
---|
| 517 | if ($db->num_rows($result)) |
---|
| 518 | $subscriber_name = $db->result($result); |
---|
| 519 | else |
---|
| 520 | message($lang_common['Bad request']); |
---|
| 521 | |
---|
| 522 | $crumbs_text['search_type'] = '<a href="search.php?action=show_subscriptions&user_id='.$subscriber_id.'">'.sprintf($lang_search['Quick search show_subscriptions'], pun_htmlspecialchars($subscriber_name)).'</a>'; |
---|
| 523 | } |
---|
| 524 | else |
---|
| 525 | $crumbs_text['search_type'] = '<a href="search.php?action='.$search_type[1].'">'.$lang_search['Quick search '.$search_type[1]].'</a>'; |
---|
| 526 | } |
---|
| 527 | else |
---|
| 528 | { |
---|
| 529 | $keywords = $author = ''; |
---|
| 530 | |
---|
| 531 | if ($search_type[0] == 'both') |
---|
| 532 | { |
---|
| 533 | list ($keywords, $author) = $search_type[1]; |
---|
| 534 | $crumbs_text['search_type'] = sprintf($lang_search['By both show as '.$show_as], pun_htmlspecialchars($keywords), pun_htmlspecialchars($author)); |
---|
| 535 | } |
---|
| 536 | else if ($search_type[0] == 'keywords') |
---|
| 537 | { |
---|
| 538 | $keywords = $search_type[1]; |
---|
| 539 | $crumbs_text['search_type'] = sprintf($lang_search['By keywords show as '.$show_as], pun_htmlspecialchars($keywords)); |
---|
| 540 | } |
---|
| 541 | else if ($search_type[0] == 'author') |
---|
| 542 | { |
---|
| 543 | $author = $search_type[1]; |
---|
| 544 | $crumbs_text['search_type'] = sprintf($lang_search['By user show as '.$show_as], pun_htmlspecialchars($author)); |
---|
| 545 | } |
---|
| 546 | |
---|
| 547 | $crumbs_text['search_type'] = '<a href="search.php?action=search&keywords='.urlencode($keywords).'&author='.urlencode($author).'&forums='.$search_type[2].'&search_in='.$search_type[3].'&sort_by='.$sort_by.'&sort_dir='.$sort_dir.'&show_as='.$show_as.'">'.$crumbs_text['search_type'].'</a>'; |
---|
| 548 | } |
---|
| 549 | |
---|
| 550 | $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_search['Search results']); |
---|
| 551 | define('PUN_ACTIVE_PAGE', 'search'); |
---|
[1] | 552 | require PUN_ROOT.'header.php'; |
---|
| 553 | |
---|
| 554 | ?> |
---|
| 555 | <div class="linkst"> |
---|
[3] | 556 | <div class="inbox crumbsplus"> |
---|
| 557 | <ul class="crumbs"> |
---|
| 558 | <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li> |
---|
| 559 | <li><span>» </span><a href="search.php"><?php echo $crumbs_text['show_as'] ?></a></li> |
---|
| 560 | <li><span>» </span><strong><?php echo $crumbs_text['search_type'] ?></strong></li> |
---|
| 561 | </ul> |
---|
| 562 | <div class="pagepost"> |
---|
| 563 | <p class="pagelink"><?php echo $paging_links ?></p> |
---|
| 564 | </div> |
---|
| 565 | <div class="clearer"></div> |
---|
[1] | 566 | </div> |
---|
| 567 | </div> |
---|
| 568 | |
---|
| 569 | <?php |
---|
| 570 | |
---|
| 571 | if ($show_as == 'topics') |
---|
| 572 | { |
---|
[3] | 573 | $topic_count = 0; |
---|
[1] | 574 | |
---|
| 575 | ?> |
---|
| 576 | <div id="vf" class="blocktable"> |
---|
[3] | 577 | <h2><span><?php echo $lang_search['Search results'] ?></span></h2> |
---|
[1] | 578 | <div class="box"> |
---|
| 579 | <div class="inbox"> |
---|
| 580 | <table cellspacing="0"> |
---|
| 581 | <thead> |
---|
| 582 | <tr> |
---|
[3] | 583 | <th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th> |
---|
[1] | 584 | <th class="tc2" scope="col"><?php echo $lang_common['Forum'] ?></th> |
---|
| 585 | <th class="tc3" scope="col"><?php echo $lang_common['Replies'] ?></th> |
---|
| 586 | <th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th> |
---|
| 587 | </tr> |
---|
| 588 | </thead> |
---|
| 589 | <tbody> |
---|
| 590 | <?php |
---|
| 591 | |
---|
| 592 | } |
---|
[3] | 593 | else if ($show_as == 'posts') |
---|
| 594 | { |
---|
| 595 | require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php'; |
---|
[1] | 596 | |
---|
[3] | 597 | require PUN_ROOT.'include/parser.php'; |
---|
[1] | 598 | |
---|
[3] | 599 | $post_count = 0; |
---|
| 600 | } |
---|
[1] | 601 | |
---|
[3] | 602 | // Get topic/forum tracking data |
---|
| 603 | if (!$pun_user['is_guest']) |
---|
| 604 | $tracked_topics = get_tracked_topics(); |
---|
| 605 | |
---|
| 606 | foreach ($search_set as $cur_search) |
---|
[1] | 607 | { |
---|
[3] | 608 | $forum = '<a href="viewforum.php?id='.$cur_search['forum_id'].'">'.pun_htmlspecialchars($cur_search['forum_name']).'</a>'; |
---|
[1] | 609 | |
---|
| 610 | if ($pun_config['o_censoring'] == '1') |
---|
[3] | 611 | $cur_search['subject'] = censor_words($cur_search['subject']); |
---|
[1] | 612 | |
---|
| 613 | if ($show_as == 'posts') |
---|
| 614 | { |
---|
[3] | 615 | ++$post_count; |
---|
| 616 | $icon_type = 'icon'; |
---|
[1] | 617 | |
---|
[3] | 618 | if (!$pun_user['is_guest'] && $cur_search['last_post'] > $pun_user['last_visit'] && (!isset($tracked_topics['topics'][$cur_search['tid']]) || $tracked_topics['topics'][$cur_search['tid']] < $cur_search['last_post']) && (!isset($tracked_topics['forums'][$cur_search['forum_id']]) || $tracked_topics['forums'][$cur_search['forum_id']] < $cur_search['last_post'])) |
---|
| 619 | { |
---|
| 620 | $item_status = 'inew'; |
---|
| 621 | $icon_type = 'icon icon-new'; |
---|
| 622 | $icon_text = $lang_topic['New icon']; |
---|
| 623 | } |
---|
| 624 | else |
---|
| 625 | { |
---|
| 626 | $item_status = ''; |
---|
| 627 | $icon_text = '<!-- -->'; |
---|
| 628 | } |
---|
[1] | 629 | |
---|
| 630 | if ($pun_config['o_censoring'] == '1') |
---|
[3] | 631 | $cur_search['message'] = censor_words($cur_search['message']); |
---|
[1] | 632 | |
---|
[3] | 633 | $message = parse_message($cur_search['message'], $cur_search['hide_smilies']); |
---|
| 634 | $pposter = pun_htmlspecialchars($cur_search['pposter']); |
---|
[1] | 635 | |
---|
[3] | 636 | if ($cur_search['poster_id'] > 1) |
---|
| 637 | { |
---|
| 638 | if ($pun_user['g_view_users'] == '1') |
---|
| 639 | $pposter = '<strong><a href="profile.php?id='.$cur_search['poster_id'].'">'.$pposter.'</a></strong>'; |
---|
| 640 | else |
---|
| 641 | $pposter = '<strong>'.$pposter.'</strong>'; |
---|
| 642 | } |
---|
[1] | 643 | |
---|
| 644 | |
---|
| 645 | ?> |
---|
[3] | 646 | <div class="blockpost<?php echo ($post_count % 2 == 0) ? ' roweven' : ' rowodd' ?><?php if ($cur_search['pid'] == $cur_search['first_post_id']) echo ' firstpost' ?><?php if ($post_count == 1) echo ' blockpost1' ?><?php if ($item_status != '') echo ' '.$item_status ?>"> |
---|
| 647 | <h2><span><span class="conr">#<?php echo ($start_from + $post_count) ?></span> <span><?php if ($cur_search['pid'] != $cur_search['first_post_id']) echo $lang_topic['Re'].' ' ?><?php echo $forum ?></span> <span>» <a href="viewtopic.php?id=<?php echo $cur_search['tid'] ?>"><?php echo pun_htmlspecialchars($cur_search['subject']) ?></a></span> <span>» <a href="viewtopic.php?pid=<?php echo $cur_search['pid'].'#p'.$cur_search['pid'] ?>"><?php echo format_time($cur_search['pposted']) ?></a></span></span></h2> |
---|
[1] | 648 | <div class="box"> |
---|
| 649 | <div class="inbox"> |
---|
[3] | 650 | <div class="postbody"> |
---|
| 651 | <div class="postleft"> |
---|
| 652 | <dl> |
---|
| 653 | <dt><?php echo $pposter ?></dt> |
---|
| 654 | <?php if ($cur_search['pid'] == $cur_search['first_post_id']) : ?> <dd><span><?php echo $lang_topic['Replies'].' '.forum_number_format($cur_search['num_replies']) ?></span></dd> |
---|
| 655 | <?php endif; ?> |
---|
| 656 | <dd><div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo $icon_text ?></div></div></dd> |
---|
| 657 | </dl> |
---|
| 658 | </div> |
---|
| 659 | <div class="postright"> |
---|
| 660 | <div class="postmsg"> |
---|
| 661 | <?php echo $message."\n" ?> |
---|
| 662 | </div> |
---|
| 663 | </div> |
---|
| 664 | <div class="clearer"></div> |
---|
[1] | 665 | </div> |
---|
[3] | 666 | </div> |
---|
| 667 | <div class="inbox"> |
---|
| 668 | <div class="postfoot clearb"> |
---|
| 669 | <div class="postfootright"> |
---|
| 670 | <ul> |
---|
| 671 | <li><span><a href="viewtopic.php?id=<?php echo $cur_search['tid'] ?>"><?php echo $lang_search['Go to topic'] ?></a></span></li> |
---|
| 672 | <li><span><a href="viewtopic.php?pid=<?php echo $cur_search['pid'].'#p'.$cur_search['pid'] ?>"><?php echo $lang_search['Go to post'] ?></a></span></li> |
---|
| 673 | </ul> |
---|
[1] | 674 | </div> |
---|
| 675 | </div> |
---|
| 676 | </div> |
---|
| 677 | </div> |
---|
| 678 | </div> |
---|
| 679 | <?php |
---|
| 680 | |
---|
| 681 | } |
---|
| 682 | else |
---|
| 683 | { |
---|
[3] | 684 | ++$topic_count; |
---|
| 685 | $status_text = array(); |
---|
| 686 | $item_status = ($topic_count % 2 == 0) ? 'roweven' : 'rowodd'; |
---|
[1] | 687 | $icon_type = 'icon'; |
---|
| 688 | |
---|
[3] | 689 | $subject = '<a href="viewtopic.php?id='.$cur_search['tid'].'">'.pun_htmlspecialchars($cur_search['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_search['poster']).'</span>'; |
---|
[1] | 690 | |
---|
[3] | 691 | if ($cur_search['sticky'] == '1') |
---|
| 692 | { |
---|
| 693 | $item_status .= ' isticky'; |
---|
| 694 | $status_text[] = '<span class="stickytext">'.$lang_forum['Sticky'].'</span>'; |
---|
| 695 | } |
---|
[1] | 696 | |
---|
[3] | 697 | if ($cur_search['closed'] != '0') |
---|
[1] | 698 | { |
---|
[3] | 699 | $status_text[] = '<span class="closedtext">'.$lang_forum['Closed'].'</span>'; |
---|
| 700 | $item_status .= ' iclosed'; |
---|
[1] | 701 | } |
---|
| 702 | |
---|
[3] | 703 | if (!$pun_user['is_guest'] && $cur_search['last_post'] > $pun_user['last_visit'] && (!isset($tracked_topics['topics'][$cur_search['tid']]) || $tracked_topics['topics'][$cur_search['tid']] < $cur_search['last_post']) && (!isset($tracked_topics['forums'][$cur_search['forum_id']]) || $tracked_topics['forums'][$cur_search['forum_id']] < $cur_search['last_post'])) |
---|
[1] | 704 | { |
---|
| 705 | $item_status .= ' inew'; |
---|
[3] | 706 | $icon_type = 'icon icon-new'; |
---|
[1] | 707 | $subject = '<strong>'.$subject.'</strong>'; |
---|
[3] | 708 | $subject_new_posts = '<span class="newtext">[ <a href="viewtopic.php?id='.$cur_search['tid'].'&action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a> ]</span>'; |
---|
[1] | 709 | } |
---|
| 710 | else |
---|
| 711 | $subject_new_posts = null; |
---|
| 712 | |
---|
[3] | 713 | // Insert the status text before the subject |
---|
| 714 | $subject = implode(' ', $status_text).' '.$subject; |
---|
[1] | 715 | |
---|
[3] | 716 | $num_pages_topic = ceil(($cur_search['num_replies'] + 1) / $pun_user['disp_posts']); |
---|
| 717 | |
---|
[1] | 718 | if ($num_pages_topic > 1) |
---|
[3] | 719 | $subject_multipage = '<span class="pagestext">[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_search['tid']).' ]</span>'; |
---|
[1] | 720 | else |
---|
| 721 | $subject_multipage = null; |
---|
| 722 | |
---|
| 723 | // Should we show the "New posts" and/or the multipage links? |
---|
| 724 | if (!empty($subject_new_posts) || !empty($subject_multipage)) |
---|
| 725 | { |
---|
[3] | 726 | $subject .= !empty($subject_new_posts) ? ' '.$subject_new_posts : ''; |
---|
[1] | 727 | $subject .= !empty($subject_multipage) ? ' '.$subject_multipage : ''; |
---|
| 728 | } |
---|
| 729 | |
---|
| 730 | ?> |
---|
[3] | 731 | <tr class="<?php echo $item_status ?>"> |
---|
[1] | 732 | <td class="tcl"> |
---|
[3] | 733 | <div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo forum_number_format($topic_count + $start_from) ?></div></div> |
---|
| 734 | <div class="tclcon"> |
---|
| 735 | <div> |
---|
[1] | 736 | <?php echo $subject."\n" ?> |
---|
| 737 | </div> |
---|
| 738 | </div> |
---|
| 739 | </td> |
---|
| 740 | <td class="tc2"><?php echo $forum ?></td> |
---|
[3] | 741 | <td class="tc3"><?php echo forum_number_format($cur_search['num_replies']) ?></td> |
---|
| 742 | <td class="tcr"><?php echo '<a href="viewtopic.php?pid='.$cur_search['last_post_id'].'#p'.$cur_search['last_post_id'].'">'.format_time($cur_search['last_post']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_search['last_poster']) ?></span></td> |
---|
[1] | 743 | </tr> |
---|
| 744 | <?php |
---|
| 745 | |
---|
| 746 | } |
---|
| 747 | } |
---|
| 748 | |
---|
| 749 | if ($show_as == 'topics') |
---|
| 750 | echo "\t\t\t".'</tbody>'."\n\t\t\t".'</table>'."\n\t\t".'</div>'."\n\t".'</div>'."\n".'</div>'."\n\n"; |
---|
| 751 | |
---|
| 752 | ?> |
---|
| 753 | <div class="<?php echo ($show_as == 'topics') ? 'linksb' : 'postlinksb'; ?>"> |
---|
[3] | 754 | <div class="inbox crumbsplus"> |
---|
| 755 | <div class="pagepost"> |
---|
| 756 | <p class="pagelink"><?php echo $paging_links ?></p> |
---|
| 757 | </div> |
---|
| 758 | <ul class="crumbs"> |
---|
| 759 | <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li> |
---|
| 760 | <li><span>» </span><a href="search.php"><?php echo $crumbs_text['show_as'] ?></a></li> |
---|
| 761 | <li><span>» </span><strong><?php echo $crumbs_text['search_type'] ?></strong></li> |
---|
| 762 | </ul> |
---|
| 763 | <?php echo (!empty($forum_actions) ? "\t\t".'<p class="subscribelink clearb">'.implode(' - ', $forum_actions).'</p>'."\n" : '') ?> |
---|
| 764 | <div class="clearer"></div> |
---|
[1] | 765 | </div> |
---|
| 766 | </div> |
---|
| 767 | <?php |
---|
| 768 | |
---|
| 769 | require PUN_ROOT.'footer.php'; |
---|
| 770 | } |
---|
| 771 | else |
---|
| 772 | message($lang_search['No hits']); |
---|
| 773 | } |
---|
| 774 | |
---|
| 775 | |
---|
[3] | 776 | $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_search['Search']); |
---|
[1] | 777 | $focus_element = array('search', 'keywords'); |
---|
[3] | 778 | define('PUN_ACTIVE_PAGE', 'search'); |
---|
[1] | 779 | require PUN_ROOT.'header.php'; |
---|
| 780 | |
---|
| 781 | ?> |
---|
| 782 | <div id="searchform" class="blockform"> |
---|
| 783 | <h2><span><?php echo $lang_search['Search'] ?></span></h2> |
---|
| 784 | <div class="box"> |
---|
| 785 | <form id="search" method="get" action="search.php"> |
---|
| 786 | <div class="inform"> |
---|
| 787 | <fieldset> |
---|
| 788 | <legend><?php echo $lang_search['Search criteria legend'] ?></legend> |
---|
| 789 | <div class="infldset"> |
---|
| 790 | <input type="hidden" name="action" value="search" /> |
---|
| 791 | <label class="conl"><?php echo $lang_search['Keyword search'] ?><br /><input type="text" name="keywords" size="40" maxlength="100" /><br /></label> |
---|
| 792 | <label class="conl"><?php echo $lang_search['Author search'] ?><br /><input id="author" type="text" name="author" size="25" maxlength="25" /><br /></label> |
---|
| 793 | <p class="clearb"><?php echo $lang_search['Search info'] ?></p> |
---|
| 794 | </div> |
---|
| 795 | </fieldset> |
---|
| 796 | </div> |
---|
| 797 | <div class="inform"> |
---|
| 798 | <fieldset> |
---|
| 799 | <legend><?php echo $lang_search['Search in legend'] ?></legend> |
---|
| 800 | <div class="infldset"> |
---|
| 801 | <?php |
---|
| 802 | |
---|
[3] | 803 | $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.redirect_url FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error()); |
---|
[1] | 804 | |
---|
[3] | 805 | // We either show a list of forums of which multiple can be selected |
---|
| 806 | if ($pun_config['o_search_all_forums'] == '1' || $pun_user['is_admmod']) |
---|
| 807 | { |
---|
| 808 | echo "\t\t\t\t\t\t".'<div class="conl multiselect">'.$lang_search['Forum search']."\n"; |
---|
| 809 | echo "\t\t\t\t\t\t".'<br />'."\n"; |
---|
| 810 | echo "\t\t\t\t\t\t".'<div class="checklist">'."\n"; |
---|
[1] | 811 | |
---|
[3] | 812 | $cur_category = 0; |
---|
| 813 | while ($cur_forum = $db->fetch_assoc($result)) |
---|
| 814 | { |
---|
| 815 | if ($cur_forum['cid'] != $cur_category) // A new category since last iteration? |
---|
| 816 | { |
---|
| 817 | if ($cur_category) |
---|
| 818 | echo "\t\t\t\t\t\t\t".'</fieldset>'."\n"; |
---|
| 819 | |
---|
| 820 | echo "\t\t\t\t\t\t\t".'<fieldset><legend><span>'.pun_htmlspecialchars($cur_forum['cat_name']).'</span></legend>'."\n"; |
---|
| 821 | $cur_category = $cur_forum['cid']; |
---|
| 822 | } |
---|
| 823 | |
---|
| 824 | echo "\t\t\t\t\t\t\t\t".'<div class="checklist-item"><span class="fld-input"><input type="checkbox" name="forums[]" id="forum-'.$cur_forum['fid'].'" value="'.$cur_forum['fid'].'" /></span> <label for="forum-'.$cur_forum['fid'].'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</label></div>'."\n"; |
---|
| 825 | } |
---|
| 826 | |
---|
| 827 | echo "\t\t\t\t\t\t\t".'</fieldset>'."\n"; |
---|
| 828 | echo "\t\t\t\t\t\t".'</div>'."\n"; |
---|
| 829 | echo "\t\t\t\t\t\t".'</div>'."\n"; |
---|
| 830 | } |
---|
| 831 | // ... or a simple select list for one forum only |
---|
| 832 | else |
---|
[1] | 833 | { |
---|
[3] | 834 | echo "\t\t\t\t\t\t".'<label class="conl">'.$lang_search['Forum search']."\n"; |
---|
| 835 | echo "\t\t\t\t\t\t".'<br />'."\n"; |
---|
| 836 | echo "\t\t\t\t\t\t".'<select id="forum" name="forum">'."\n"; |
---|
| 837 | |
---|
| 838 | $cur_category = 0; |
---|
| 839 | while ($cur_forum = $db->fetch_assoc($result)) |
---|
[1] | 840 | { |
---|
[3] | 841 | if ($cur_forum['cid'] != $cur_category) // A new category since last iteration? |
---|
| 842 | { |
---|
| 843 | if ($cur_category) |
---|
| 844 | echo "\t\t\t\t\t\t\t".'</optgroup>'."\n"; |
---|
[1] | 845 | |
---|
[3] | 846 | echo "\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($cur_forum['cat_name']).'">'."\n"; |
---|
| 847 | $cur_category = $cur_forum['cid']; |
---|
| 848 | } |
---|
| 849 | |
---|
| 850 | echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_forum['fid'].'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</option>'."\n"; |
---|
[1] | 851 | } |
---|
| 852 | |
---|
[3] | 853 | echo "\t\t\t\t\t\t\t".'</optgroup>'."\n"; |
---|
| 854 | echo "\t\t\t\t\t\t".'</select>'."\n"; |
---|
| 855 | echo "\t\t\t\t\t\t".'<br /></label>'."\n"; |
---|
[1] | 856 | } |
---|
| 857 | |
---|
| 858 | ?> |
---|
[3] | 859 | <label class="conl"><?php echo $lang_search['Search in']."\n" ?> |
---|
[1] | 860 | <br /><select id="search_in" name="search_in"> |
---|
[3] | 861 | <option value="0"><?php echo $lang_search['Message and subject'] ?></option> |
---|
| 862 | <option value="1"><?php echo $lang_search['Message only'] ?></option> |
---|
| 863 | <option value="-1"><?php echo $lang_search['Topic only'] ?></option> |
---|
[1] | 864 | </select> |
---|
| 865 | <br /></label> |
---|
[3] | 866 | <p class="clearl"><?php echo $lang_search['Search in info'] ?></p> |
---|
| 867 | <?php echo ($pun_config['o_search_all_forums'] == '1' || $pun_user['is_admmod'] ? '<p>'.$lang_search['Search multiple forums info'].'</p>' : '') ?> |
---|
[1] | 868 | </div> |
---|
| 869 | </fieldset> |
---|
| 870 | </div> |
---|
| 871 | <div class="inform"> |
---|
| 872 | <fieldset> |
---|
| 873 | <legend><?php echo $lang_search['Search results legend'] ?></legend> |
---|
| 874 | <div class="infldset"> |
---|
[3] | 875 | <label class="conl"><?php echo $lang_search['Sort by']."\n" ?> |
---|
[1] | 876 | <br /><select name="sort_by"> |
---|
| 877 | <option value="0"><?php echo $lang_search['Sort by post time'] ?></option> |
---|
| 878 | <option value="1"><?php echo $lang_search['Sort by author'] ?></option> |
---|
| 879 | <option value="2"><?php echo $lang_search['Sort by subject'] ?></option> |
---|
| 880 | <option value="3"><?php echo $lang_search['Sort by forum'] ?></option> |
---|
| 881 | </select> |
---|
| 882 | <br /></label> |
---|
[3] | 883 | <label class="conl"><?php echo $lang_search['Sort order']."\n" ?> |
---|
[1] | 884 | <br /><select name="sort_dir"> |
---|
| 885 | <option value="DESC"><?php echo $lang_search['Descending'] ?></option> |
---|
| 886 | <option value="ASC"><?php echo $lang_search['Ascending'] ?></option> |
---|
| 887 | </select> |
---|
| 888 | <br /></label> |
---|
[3] | 889 | <label class="conl"><?php echo $lang_search['Show as']."\n" ?> |
---|
[1] | 890 | <br /><select name="show_as"> |
---|
| 891 | <option value="topics"><?php echo $lang_search['Show as topics'] ?></option> |
---|
| 892 | <option value="posts"><?php echo $lang_search['Show as posts'] ?></option> |
---|
| 893 | </select> |
---|
| 894 | <br /></label> |
---|
| 895 | <p class="clearb"><?php echo $lang_search['Search results info'] ?></p> |
---|
| 896 | </div> |
---|
| 897 | </fieldset> |
---|
| 898 | </div> |
---|
[3] | 899 | <p class="buttons"><input type="submit" name="search" value="<?php echo $lang_common['Submit'] ?>" accesskey="s" /></p> |
---|
[1] | 900 | </form> |
---|
| 901 | </div> |
---|
| 902 | </div> |
---|
| 903 | <?php |
---|
| 904 | |
---|
| 905 | require PUN_ROOT.'footer.php'; |
---|