adopted md5sum
[archlinuxdevstack.git] / fluxbb / search.php
blob985d2f7e1a7398f3280cbfd6f31aebb9c97b0ff0
1 <?php
2 /***********************************************************************
4 Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org)
6 This file is part of PunBB.
8 PunBB is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PunBB is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 MA 02111-1307 USA
23 ************************************************************************/
26 // The contents of this file are very much inspired by the file search.php
27 // from the phpBB Group forum software phpBB2 (http://www.phpbb.com).
30 define('PUN_ROOT', './');
31 require PUN_ROOT.'include/common.php';
34 // Load the search.php language file
35 require PUN_ROOT.'lang/'.$pun_user['language'].'/search.php';
36 require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';
39 if ($pun_user['g_read_board'] == '0')
40 message($lang_common['No view']);
41 else if ($pun_user['g_search'] == '0')
42 message($lang_search['No search permission']);
45 // Detect two byte character sets
46 $multibyte = (isset($lang_common['lang_multibyte']) && $lang_common['lang_multibyte']) ? true : false;
49 // Figure out what to do :-)
50 if (isset($_GET['action']) || isset($_GET['search_id']))
52 $action = (isset($_GET['action'])) ? $_GET['action'] : null;
53 $forum = (isset($_GET['forum'])) ? intval($_GET['forum']) : -1;
54 $sort_dir = (isset($_GET['sort_dir'])) ? (($_GET['sort_dir'] == 'DESC') ? 'DESC' : 'ASC') : 'DESC';
55 if (isset($search_id)) unset($search_id);
57 // If a search_id was supplied
58 if (isset($_GET['search_id']))
60 $search_id = intval($_GET['search_id']);
61 if ($search_id < 1)
62 message($lang_common['Bad request']);
64 // If it's a regular search (keywords and/or author)
65 else if ($action == 'search')
67 $keywords = (isset($_GET['keywords'])) ? strtolower(trim($_GET['keywords'])) : null;
68 $author = (isset($_GET['author'])) ? strtolower(trim($_GET['author'])) : null;
70 if (preg_match('#^[\*%]+$#', $keywords) || strlen(str_replace(array('*', '%'), '', $keywords)) < 3)
71 $keywords = '';
73 if (preg_match('#^[\*%]+$#', $author) || strlen(str_replace(array('*', '%'), '', $author)) < 3)
74 $author = '';
76 if (!$keywords && !$author)
77 message($lang_search['No terms']);
79 if ($author)
80 $author = str_replace('*', '%', $author);
82 $show_as = (isset($_GET['show_as'])) ? $_GET['show_as'] : 'posts';
83 $sort_by = (isset($_GET['sort_by'])) ? intval($_GET['sort_by']) : null;
84 $search_in = (!isset($_GET['search_in']) || $_GET['search_in'] == 'all') ? 0 : (($_GET['search_in'] == 'message') ? 1 : -1);
86 // If it's a user search (by id)
87 else if ($action == 'show_user')
89 $user_id = intval($_GET['user_id']);
90 if ($user_id < 2)
91 message($lang_common['Bad request']);
93 else
95 if ($action != 'show_new' && $action != 'show_24h' && $action != 'show_unanswered' && $action != 'show_subscriptions')
96 message($lang_common['Bad request']);
100 // If a valid search_id was supplied we attempt to fetch the search results from the db
101 if (isset($search_id))
103 $ident = ($pun_user['is_guest']) ? get_remote_address() : $pun_user['username'];
105 $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());
106 if ($row = $db->fetch_assoc($result))
108 $temp = unserialize($row['search_data']);
110 $search_results = $temp['search_results'];
111 $num_hits = $temp['num_hits'];
112 $sort_by = $temp['sort_by'];
113 $sort_dir = $temp['sort_dir'];
114 $show_as = $temp['show_as'];
116 unset($temp);
118 else
119 message($lang_search['No hits']);
121 else
123 $keyword_results = $author_results = array();
125 // Search a specific forum?
126 $forum_sql = ($forum != -1 || ($forum == -1 && $pun_config['o_search_all_forums'] == '0' && $pun_user['g_id'] >= PUN_GUEST)) ? ' AND t.forum_id = '.$forum : '';
128 if (!empty($author) || !empty($keywords))
130 // If it's a search for keywords
131 if ($keywords)
133 $stopwords = (array)@file(PUN_ROOT.'lang/'.$pun_user['language'].'/stopwords.txt');
134 $stopwords = array_map('trim', $stopwords);
136 // Are we searching for multibyte charset text?
137 if ($multibyte)
139 // Strip out excessive whitespace
140 $keywords = trim(preg_replace('#\s+#', ' ', $keywords));
142 $keywords_array = explode(' ', $keywords);
144 else
146 // Filter out non-alphabetical chars
147 $noise_match = array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!', 'ยค');
148 $noise_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '' , ' ', ' ', ' ', ' ', ' ', ' ', ' ');
149 $keywords = str_replace($noise_match, $noise_replace, $keywords);
151 // Strip out excessive whitespace
152 $keywords = trim(preg_replace('#\s+#', ' ', $keywords));
154 // Fill an array with all the words
155 $keywords_array = explode(' ', $keywords);
157 if (empty($keywords_array))
158 message($lang_search['No hits']);
160 while (list($i, $word) = @each($keywords_array))
162 $num_chars = pun_strlen($word);
164 if ($word !== 'or' && ($num_chars < 3 || $num_chars > 20 || in_array($word, $stopwords)))
165 unset($keywords_array[$i]);
168 // Should we search in message body or topic subject specifically?
169 $search_in_cond = ($search_in) ? (($search_in > 0) ? ' AND m.subject_match = 0' : ' AND m.subject_match = 1') : '';
172 $word_count = 0;
173 $match_type = 'and';
174 $result_list = array();
175 @reset($keywords_array);
176 while (list(, $cur_word) = @each($keywords_array))
178 switch ($cur_word)
180 case 'and':
181 case 'or':
182 case 'not':
183 $match_type = $cur_word;
184 break;
186 default:
188 // Are we searching for multibyte charset text?
189 if ($multibyte)
191 $cur_word = $db->escape('%'.str_replace('*', '', $cur_word).'%');
192 $cur_word_like = ($db_type == 'pgsql') ? 'ILIKE \''.$cur_word.'\'' : 'LIKE \''.$cur_word.'\'';
194 if ($search_in > 0)
195 $sql = 'SELECT id FROM '.$db->prefix.'posts WHERE message '.$cur_word_like;
196 else if ($search_in < 0)
197 $sql = 'SELECT p.id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id WHERE t.subject '.$cur_word_like.' GROUP BY p.id, t.id';
198 else
199 $sql = 'SELECT p.id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id WHERE p.message '.$cur_word_like.' OR t.subject '.$cur_word_like.' GROUP BY p.id, t.id';
201 else
203 $cur_word = $db->escape(str_replace('*', '%', $cur_word));
204 $sql = 'SELECT m.post_id FROM '.$db->prefix.'search_words AS w INNER JOIN '.$db->prefix.'search_matches AS m ON m.word_id = w.id WHERE w.word LIKE \''.$cur_word.'\''.$search_in_cond;
207 $result = $db->query($sql, true) or error('Unable to search for posts', __FILE__, __LINE__, $db->error());
209 $row = array();
210 while ($temp = $db->fetch_row($result))
212 $row[$temp[0]] = 1;
214 if (!$word_count)
215 $result_list[$temp[0]] = 1;
216 else if ($match_type == 'or')
217 $result_list[$temp[0]] = 1;
218 else if ($match_type == 'not')
219 $result_list[$temp[0]] = 0;
222 if ($match_type == 'and' && $word_count)
224 @reset($result_list);
225 while (list($post_id,) = @each($result_list))
227 if (!isset($row[$post_id]))
228 $result_list[$post_id] = 0;
232 ++$word_count;
233 $db->free_result($result);
235 break;
240 @reset($result_list);
241 while (list($post_id, $matches) = @each($result_list))
243 if ($matches)
244 $keyword_results[] = $post_id;
247 unset($result_list);
250 // If it's a search for author name (and that author name isn't Guest)
251 if ($author && strcasecmp($author, 'Guest') && strcasecmp($author, $lang_common['Guest']))
253 switch ($db_type)
255 case 'pgsql':
256 $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());
257 break;
259 default:
260 $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());
261 break;
264 if ($db->num_rows($result))
266 $user_ids = '';
267 while ($row = $db->fetch_row($result))
268 $user_ids .= (($user_ids != '') ? ',' : '').$row[0];
270 $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE poster_id IN('.$user_ids.')') or error('Unable to fetch matched posts list', __FILE__, __LINE__, $db->error());
272 $search_ids = array();
273 while ($row = $db->fetch_row($result))
274 $author_results[] = $row[0];
276 $db->free_result($result);
281 if ($author && $keywords)
283 // If we searched for both keywords and author name we want the intersection between the results
284 $search_ids = array_intersect($keyword_results, $author_results);
285 unset($keyword_results, $author_results);
287 else if ($keywords)
288 $search_ids = $keyword_results;
289 else
290 $search_ids = $author_results;
292 $num_hits = count($search_ids);
293 if (!$num_hits)
294 message($lang_search['No hits']);
297 if ($show_as == 'topics')
299 $result = $db->query('SELECT t.id 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 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 p.id IN('.implode(',', $search_ids).')'.$forum_sql.' GROUP BY t.id', true) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
301 $search_ids = array();
302 while ($row = $db->fetch_row($result))
303 $search_ids[] = $row[0];
305 $db->free_result($result);
307 $num_hits = count($search_ids);
309 else
311 $result = $db->query('SELECT p.id 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 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 p.id IN('.implode(',', $search_ids).')'.$forum_sql, true) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
313 $search_ids = array();
314 while ($row = $db->fetch_row($result))
315 $search_ids[] = $row[0];
317 $db->free_result($result);
319 $num_hits = count($search_ids);
322 else if ($action == 'show_new' || $action == 'show_24h' || $action == 'show_user' || $action == 'show_subscriptions' || $action == 'show_unanswered')
324 // If it's a search for new posts
325 if ($action == 'show_new')
327 if ($pun_user['is_guest'])
328 message($lang_common['No permission']);
330 $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_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 t.last_post>'.$pun_user['last_visit'].' AND t.moved_to IS NULL') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
331 $num_hits = $db->num_rows($result);
333 if (!$num_hits)
334 message($lang_search['No new posts']);
336 // If it's a search for todays posts
337 else if ($action == 'show_24h')
339 $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_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 t.last_post>'.(time() - 86400).' AND t.moved_to IS NULL') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
340 $num_hits = $db->num_rows($result);
342 if (!$num_hits)
343 message($lang_search['No recent posts']);
345 // If it's a search for posts by a specific user ID
346 else if ($action == 'show_user')
348 $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 INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_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 p.poster_id='.$user_id.' GROUP BY t.id') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
349 $num_hits = $db->num_rows($result);
351 if (!$num_hits)
352 message($lang_search['No user posts']);
354 // If it's a search for subscribed topics
355 else if ($action == 'show_subscriptions')
357 if ($pun_user['is_guest'])
358 message($lang_common['Bad request']);
360 $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'subscriptions AS s ON (t.id=s.topic_id AND s.user_id='.$pun_user['id'].') INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_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)') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
361 $num_hits = $db->num_rows($result);
363 if (!$num_hits)
364 message($lang_search['No subscriptions']);
366 // If it's a search for unanswered posts
367 else
369 $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_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 t.num_replies=0 AND t.moved_to IS NULL') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
370 $num_hits = $db->num_rows($result);
372 if (!$num_hits)
373 message($lang_search['No unanswered']);
376 // We want to sort things after last post
377 $sort_by = 4;
379 $search_ids = array();
380 while ($row = $db->fetch_row($result))
381 $search_ids[] = $row[0];
383 $db->free_result($result);
385 $show_as = 'topics';
387 else
388 message($lang_common['Bad request']);
391 // Prune "old" search results
392 $old_searches = array();
393 $result = $db->query('SELECT ident FROM '.$db->prefix.'online') or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
395 if ($db->num_rows($result))
397 while ($row = $db->fetch_row($result))
398 $old_searches[] = '\''.$db->escape($row[0]).'\'';
400 $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());
403 // Final search results
404 $search_results = implode(',', $search_ids);
406 // Fill an array with our results and search properties
407 $temp['search_results'] = $search_results;
408 $temp['num_hits'] = $num_hits;
409 $temp['sort_by'] = $sort_by;
410 $temp['sort_dir'] = $sort_dir;
411 $temp['show_as'] = $show_as;
412 $temp = serialize($temp);
413 $search_id = mt_rand(1, 2147483647);
415 $ident = ($pun_user['is_guest']) ? get_remote_address() : $pun_user['username'];
417 $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());
419 if ($action != 'show_new' && $action != 'show_24h')
421 $db->end_transaction();
422 $db->close();
424 // Redirect the user to the cached result page
425 header('Location: search.php?search_id='.$search_id);
426 exit;
431 // Fetch results to display
432 if ($search_results != '')
434 switch ($sort_by)
436 case 1:
437 $sort_by_sql = ($show_as == 'topics') ? 't.poster' : 'p.poster';
438 break;
440 case 2:
441 $sort_by_sql = 't.subject';
442 break;
444 case 3:
445 $sort_by_sql = 't.forum_id';
446 break;
448 case 4:
449 $sort_by_sql = 't.last_post';
450 break;
452 default:
453 $sort_by_sql = ($show_as == 'topics') ? 't.posted' : 'p.posted';
454 break;
457 if ($show_as == 'posts')
459 $substr_sql = ($db_type != 'sqlite') ? 'SUBSTRING' : 'SUBSTR';
460 $sql = 'SELECT p.id AS pid, p.poster AS pposter, p.posted AS pposted, p.poster_id, '.$substr_sql.'(p.message, 1, 1000) AS message, t.id AS tid, t.poster, t.subject, t.last_post, t.last_post_id, t.last_poster, t.num_replies, t.forum_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id WHERE p.id IN('.$search_results.') ORDER BY '.$sort_by_sql;
462 else
463 $sql = '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 FROM '.$db->prefix.'topics AS t WHERE t.id IN('.$search_results.') ORDER BY '.$sort_by_sql;
465 // Determine the topic or post offset (based on $_GET['p'])
466 $per_page = ($show_as == 'posts') ? $pun_user['disp_posts'] : $pun_user['disp_topics'];
467 $num_pages = ceil($num_hits / $per_page);
469 $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
470 $start_from = $per_page * ($p - 1);
472 // Generate paging links
473 $paging_links = $lang_common['Pages'].': '.paginate($num_pages, $p, 'search.php?search_id='.$search_id);
476 $sql .= ' '.$sort_dir.' LIMIT '.$start_from.', '.$per_page;
478 $result = $db->query($sql) or error('Unable to fetch search results', __FILE__, __LINE__, $db->error());
480 $search_set = array();
481 while ($row = $db->fetch_assoc($result))
482 $search_set[] = $row;
484 $db->free_result($result);
486 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_search['Search results'];
487 require PUN_ROOT.'header.php';
491 <div class="linkst">
492 <div class="inbox">
493 <p class="pagelink"><?php echo $paging_links ?></p>
494 </div>
495 </div>
497 <?php
499 // Set background switching on for show as posts
500 $bg_switch = true;
502 if ($show_as == 'topics')
506 <div id="vf" class="blocktable">
507 <h2><span><?php echo $lang_search['Search results']; ?></span></h2>
508 <div class="box">
509 <div class="inbox">
510 <table cellspacing="0">
511 <thead>
512 <tr>
513 <th class="tcl" scope="col"><?php echo $lang_common['Topic']; ?></th>
514 <th class="tc2" scope="col"><?php echo $lang_common['Forum'] ?></th>
515 <th class="tc3" scope="col"><?php echo $lang_common['Replies'] ?></th>
516 <th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th>
517 </tr>
518 </thead>
519 <tbody>
520 <?php
524 // Fetch the list of forums
525 $result = $db->query('SELECT id, forum_name FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
527 $forum_list = array();
528 while ($forum_list[] = $db->fetch_row($result));
530 // Finally, lets loop through the results and output them
531 $count_search_set = count($search_set);
532 for ($i = 0; $i < $count_search_set; ++$i)
534 @reset($forum_list);
535 while (list(, $temp) = @each($forum_list))
537 if ($temp[0] == $search_set[$i]['forum_id'])
538 $forum = '<a href="viewforum.php?id='.$temp[0].'">'.pun_htmlspecialchars($temp[1]).'</a>';
541 if ($pun_config['o_censoring'] == '1')
542 $search_set[$i]['subject'] = censor_words($search_set[$i]['subject']);
545 if ($show_as == 'posts')
547 $icon = '<div class="icon"><div class="nosize">'.$lang_common['Normal icon'].'</div></div>'."\n";
548 $subject = '<a href="viewtopic.php?id='.$search_set[$i]['tid'].'">'.pun_htmlspecialchars($search_set[$i]['subject']).'</a>';
550 if (!$pun_user['is_guest'] && $search_set[$i]['last_post'] > $pun_user['last_visit'])
551 $icon = '<div class="icon inew"><div class="nosize">'.$lang_common['New icon'].'</div></div>'."\n";
554 if ($pun_config['o_censoring'] == '1')
555 $search_set[$i]['message'] = censor_words($search_set[$i]['message']);
557 $message = str_replace("\n", '<br />', pun_htmlspecialchars($search_set[$i]['message']));
558 $pposter = pun_htmlspecialchars($search_set[$i]['pposter']);
560 if ($search_set[$i]['poster_id'] > 1)
561 $pposter = '<strong><a href="profile.php?id='.$search_set[$i]['poster_id'].'">'.$pposter.'</a></strong>';
563 if (pun_strlen($message) >= 1000)
564 $message .= ' &hellip;';
566 $vtpost1 = ($i == 0) ? ' vtp1' : '';
568 // Switch the background color for every message.
569 $bg_switch = ($bg_switch) ? $bg_switch = false : $bg_switch = true;
570 $vtbg = ($bg_switch) ? ' rowodd' : ' roweven';
574 <div class="blockpost searchposts<?php echo $vtbg ?>">
575 <h2><?php echo $forum ?>&nbsp;&raquo;&nbsp;<?php echo $subject ?>&nbsp;&raquo;&nbsp;<a href="viewtopic.php?pid=<?php echo $search_set[$i]['pid'].'#p'.$search_set[$i]['pid'] ?>"><?php echo format_time($search_set[$i]['pposted']) ?></a></h2>
576 <div class="box">
577 <div class="inbox">
578 <div class="postleft">
579 <dl>
580 <dt><?php echo $pposter ?></dt>
581 <dd>Replies: <?php echo $search_set[$i]['num_replies'] ?></dd>
582 <dd><?php echo $icon; ?></dd>
583 <dd><p class="clearb"><a href="viewtopic.php?pid=<?php echo $search_set[$i]['pid'].'#p'.$search_set[$i]['pid'] ?>"><?php echo $lang_search['Go to post'] ?></a></p></dd>
584 </dl>
585 </div>
586 <div class="postright">
587 <div class="postmsg">
588 <p><?php echo $message ?></p>
589 </div>
590 </div>
591 <div class="clearer"></div>
592 </div>
593 </div>
594 </div>
595 <?php
598 else
600 $icon = '<div class="icon"><div class="nosize">'.$lang_common['Normal icon'].'</div></div>'."\n";
602 $icon_text = $lang_common['Normal icon'];
603 $item_status = '';
604 $icon_type = 'icon';
607 $subject = '<a href="viewtopic.php?id='.$search_set[$i]['tid'].'">'.pun_htmlspecialchars($search_set[$i]['subject']).'</a> <span class="byuser">'.$lang_common['by'].'&nbsp;'.pun_htmlspecialchars($search_set[$i]['poster']).'</span>';
609 if ($search_set[$i]['closed'] != '0')
611 $icon_text = $lang_common['Closed icon'];
612 $item_status = 'iclosed';
615 if (!$pun_user['is_guest'] && $search_set[$i]['last_post'] > $pun_user['last_visit'])
617 $icon_text .= ' '.$lang_common['New icon'];
618 $item_status .= ' inew';
619 $icon_type = 'icon inew';
620 $subject = '<strong>'.$subject.'</strong>';
621 $subject_new_posts = '<span class="newtext">[&nbsp;<a href="viewtopic.php?id='.$search_set[$i]['tid'].'&amp;action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a>&nbsp;]</span>';
623 else
624 $subject_new_posts = null;
626 if ($search_set[$i]['sticky'] == '1')
628 $subject = '<span class="stickytext">'.$lang_forum['Sticky'].': </span>'.$subject;
629 $item_status .= ' isticky';
630 $icon_text .= ' '.$lang_forum['Sticky'];
633 $num_pages_topic = ceil(($search_set[$i]['num_replies'] + 1) / $pun_user['disp_posts']);
635 if ($num_pages_topic > 1)
636 $subject_multipage = '[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$search_set[$i]['tid']).' ]';
637 else
638 $subject_multipage = null;
640 // Should we show the "New posts" and/or the multipage links?
641 if (!empty($subject_new_posts) || !empty($subject_multipage))
643 $subject .= '&nbsp; '.(!empty($subject_new_posts) ? $subject_new_posts : '');
644 $subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
648 <tr<?php if ($item_status != '') echo ' class="'.trim($item_status).'"'; ?>>
649 <td class="tcl">
650 <div class="intd">
651 <div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo trim($icon_text) ?></div></div>
652 <div class="tclcon">
653 <?php echo $subject."\n" ?>
654 </div>
655 </div>
656 </td>
657 <td class="tc2"><?php echo $forum ?></td>
658 <td class="tc3"><?php echo $search_set[$i]['num_replies'] ?></td>
659 <td class="tcr"><?php echo '<a href="viewtopic.php?pid='.$search_set[$i]['last_post_id'].'#p'.$search_set[$i]['last_post_id'].'">'.format_time($search_set[$i]['last_post']).'</a> '.$lang_common['by'].'&nbsp;'.pun_htmlspecialchars($search_set[$i]['last_poster']) ?></td>
660 </tr>
661 <?php
666 if ($show_as == 'topics')
667 echo "\t\t\t".'</tbody>'."\n\t\t\t".'</table>'."\n\t\t".'</div>'."\n\t".'</div>'."\n".'</div>'."\n\n";
670 <div class="<?php echo ($show_as == 'topics') ? 'linksb' : 'postlinksb'; ?>">
671 <div class="inbox">
672 <p class="pagelink"><?php echo $paging_links ?></p>
673 </div>
674 </div>
675 <?php
677 $footer_style = 'search';
678 require PUN_ROOT.'footer.php';
680 else
681 message($lang_search['No hits']);
685 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_search['Search'];
686 $focus_element = array('search', 'keywords');
687 require PUN_ROOT.'header.php';
690 <div id="searchform" class="blockform">
691 <h2><span><?php echo $lang_search['Search'] ?></span></h2>
692 <div class="box">
693 <form id="search" method="get" action="search.php">
694 <div class="inform">
695 <fieldset>
696 <legend><?php echo $lang_search['Search criteria legend'] ?></legend>
697 <div class="infldset">
698 <input type="hidden" name="action" value="search" />
699 <label class="conl"><?php echo $lang_search['Keyword search'] ?><br /><input type="text" name="keywords" size="40" maxlength="100" /><br /></label>
700 <label class="conl"><?php echo $lang_search['Author search'] ?><br /><input id="author" type="text" name="author" size="25" maxlength="25" /><br /></label>
701 <p class="clearb"><?php echo $lang_search['Search info'] ?></p>
702 </div>
703 </fieldset>
704 </div>
705 <div class="inform">
706 <fieldset>
707 <legend><?php echo $lang_search['Search in legend'] ?></legend>
708 <div class="infldset">
709 <label class="conl"><?php echo $lang_search['Forum search'] ?>
710 <br /><select id="forum" name="forum">
711 <?php
713 if ($pun_config['o_search_all_forums'] == '1' || $pun_user['g_id'] < PUN_GUEST)
714 echo "\t\t\t\t\t\t\t".'<option value="-1">'.$lang_search['All forums'].'</option>'."\n";
716 $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());
718 $cur_category = 0;
719 while ($cur_forum = $db->fetch_assoc($result))
721 if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
723 if ($cur_category)
724 echo "\t\t\t\t\t\t\t".'</optgroup>'."\n";
726 echo "\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($cur_forum['cat_name']).'">'."\n";
727 $cur_category = $cur_forum['cid'];
730 echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_forum['fid'].'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</option>'."\n";
734 </optgroup>
735 </select>
736 <br /></label>
737 <label class="conl"><?php echo $lang_search['Search in'] ?>
738 <br /><select id="search_in" name="search_in">
739 <option value="all"><?php echo $lang_search['Message and subject'] ?></option>
740 <option value="message"><?php echo $lang_search['Message only'] ?></option>
741 <option value="topic"><?php echo $lang_search['Topic only'] ?></option>
742 </select>
743 <br /></label>
744 <p class="clearb"><?php echo $lang_search['Search in info'] ?></p>
745 </div>
746 </fieldset>
747 </div>
748 <div class="inform">
749 <fieldset>
750 <legend><?php echo $lang_search['Search results legend'] ?></legend>
751 <div class="infldset">
752 <label class="conl"><?php echo $lang_search['Sort by'] ?>
753 <br /><select name="sort_by">
754 <option value="0"><?php echo $lang_search['Sort by post time'] ?></option>
755 <option value="1"><?php echo $lang_search['Sort by author'] ?></option>
756 <option value="2"><?php echo $lang_search['Sort by subject'] ?></option>
757 <option value="3"><?php echo $lang_search['Sort by forum'] ?></option>
758 </select>
759 <br /></label>
760 <label class="conl"><?php echo $lang_search['Sort order'] ?>
761 <br /><select name="sort_dir">
762 <option value="DESC"><?php echo $lang_search['Descending'] ?></option>
763 <option value="ASC"><?php echo $lang_search['Ascending'] ?></option>
764 </select>
765 <br /></label>
766 <label class="conl"><?php echo $lang_search['Show as'] ?>
767 <br /><select name="show_as">
768 <option value="topics"><?php echo $lang_search['Show as topics'] ?></option>
769 <option value="posts"><?php echo $lang_search['Show as posts'] ?></option>
770 </select>
771 <br /></label>
772 <p class="clearb"><?php echo $lang_search['Search results info'] ?></p>
773 </div>
774 </fieldset>
775 </div>
776 <p><input type="submit" name="search" value="<?php echo $lang_common['Submit'] ?>" accesskey="s" /></p>
777 </form>
778 </div>
779 </div>
780 <?php
782 require PUN_ROOT.'footer.php';