1<?php
2/**
3 * Allows users to search the forum based on various criteria.
4 *
5 * @copyright (C) 2008-2012 PunBB, partially based on code (C) 2008-2009 FluxBB.org
6 * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
7 * @package PunBB
8 */
9
10
11if (!defined('FORUM_ROOT'))
12	define('FORUM_ROOT', './');
13require FORUM_ROOT.'include/common.php';
14
15($hook = get_hook('se_start')) ? eval($hook) : null;
16
17// Load the search.php language file
18require FORUM_ROOT.'lang/'.$forum_user['language'].'/search.php';
19
20// Load the necessary search functions
21require FORUM_ROOT.'include/search_functions.php';
22
23
24if ($forum_user['g_read_board'] == '0')
25	message($lang_common['No view']);
26else if ($forum_user['g_search'] == '0')
27	message($lang_search['No search permission']);
28
29
30// If a search_id was supplied
31if (isset($_GET['search_id']))
32{
33	$search_id = intval($_GET['search_id']);
34	if ($search_id < 1)
35		message($lang_common['Bad request']);
36
37	// Generate the query to grab the cached results
38	$query = generate_cached_search_query($search_id, $show_as);
39
40	$url_type = $forum_url['search_results'];
41}
42// We aren't just grabbing a cached search
43else if (isset($_GET['action']))
44{
45	$action = $_GET['action'];
46
47	// Validate action
48	if (!validate_search_action($action))
49		message($lang_common['Bad request']);
50
51	// If it's a regular search (keywords and/or author)
52	if ($action == 'search')
53	{
54		$keywords = (isset($_GET['keywords']) && is_string($_GET['keywords'])) ? forum_trim($_GET['keywords']) : null;
55		$author = (isset($_GET['author']) && is_string($_GET['author'])) ? forum_trim($_GET['author']) : null;
56		$sort_dir = (isset($_GET['sort_dir'])) ? (($_GET['sort_dir'] == 'DESC') ? 'DESC' : 'ASC') : 'DESC';
57		$show_as = (isset($_GET['show_as'])) ? $_GET['show_as'] : 'posts';
58		$sort_by = (isset($_GET['sort_by'])) ? intval($_GET['sort_by']) : null;
59		$search_in = (!isset($_GET['search_in']) || $_GET['search_in'] == 'all') ? 0 : (($_GET['search_in'] == 'message') ? 1 : -1);
60		$forum = (isset($_GET['forum']) && is_array($_GET['forum'])) ? array_map('intval', $_GET['forum']) : array(-1);
61
62		if (preg_match('#^[\*%]+$#', $keywords))
63			$keywords = '';
64
65		if (preg_match('#^[\*%]+$#', $author))
66			$author = '';
67
68		if (!$keywords && !$author)
69			message($lang_search['No terms']);
70
71		// Create a cache of the results and redirect the user to the results
72		create_search_cache($keywords, $author, $search_in, $forum, $show_as, $sort_by, $sort_dir);
73	}
74	// Its not a regular search, so its a quicksearch
75	else
76	{
77		$value = null;
78		// Get any additional variables for quicksearches
79		if ($action == 'show_user_posts' || $action == 'show_user_topics' || $action == 'show_subscriptions' || $action == 'show_forum_subscriptions')
80		{
81			$value = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
82			if ($value < 2)
83				message($lang_common['Bad request']);
84		}
85		else if ($action == 'show_recent')
86			$value = (isset($_GET['value'])) ? intval($_GET['value']) : 86400;
87		else if ($action == 'show_new')
88			$value = (isset($_GET['forum'])) ? intval($_GET['forum']) : -1;
89
90		($hook = get_hook('se_additional_quicksearch_variables')) ? eval($hook) : null;
91
92		$search_id = '';
93
94		// Show as
95		if ($action == 'show_forum_subscriptions')
96			$show_as = 'forums';
97		else
98			$show_as = 'topics';
99
100		// Generate the query for the search
101		$query = generate_action_search_query($action, $value, $search_id, $url_type, $show_as);
102	}
103}
104
105($hook = get_hook('se_pre_search_query')) ? eval($hook) : null;
106
107// We have the query to get the results, lets get them!
108if (isset($query))
109{
110	// No results?
111	if (!$query)
112		no_search_results();
113
114	// Work out the settings for pagination
115	if ($show_as == 'posts')
116		$forum_page['per_page'] = $forum_user['disp_posts'];
117	else if ($show_as == 'topics')
118		$forum_page['per_page'] = $forum_user['disp_topics'];
119	else if ($show_as == 'forums')
120		$forum_page['per_page'] = 0;	// Show all
121
122	// We now have a query that will give us our results in $query, lets get the data!
123	$num_hits = get_search_results($query, $search_set);
124
125	($hook = get_hook('se_post_results_fetched')) ? eval($hook) : null;
126
127	// No search results?
128	if ($num_hits == 0)
129		no_search_results($action);
130
131	//
132	// Output the search results
133	//
134
135	// Setup breadcrumbs and results header and footer
136	$forum_page['crumbs'][] = array($forum_config['o_board_title'], forum_link($forum_url['index']));
137	$action = (isset($action)) ? $action : null;
138	generate_search_crumbs($action);
139
140	// Generate paging links
141	if ($show_as == 'posts' || $show_as == 'topics')
142		$forum_page['page_post']['paging'] = '<p class="paging"><span class="pages">'.$lang_common['Pages'].'</span> '.paginate($forum_page['num_pages'], $forum_page['page'], $url_type, $lang_common['Paging separator'], $search_id).'</p>';
143
144	// Get topic/forum tracking data
145	if (!$forum_user['is_guest'])
146		$tracked_topics = get_tracked_topics();
147
148	// Navigation links for header and page numbering for title/meta description
149	if ($show_as == 'posts' || $show_as == 'topics')
150	{
151		if ($forum_page['page'] < $forum_page['num_pages'])
152		{
153			$forum_page['nav']['last'] = '<link rel="last" href="'.forum_sublink($url_type, $forum_url['page'], $forum_page['num_pages'], $search_id).'" title="'.$lang_common['Page'].' '.$forum_page['num_pages'].'" />';
154			$forum_page['nav']['next'] = '<link rel="next" href="'.forum_sublink($url_type, $forum_url['page'], ($forum_page['page'] + 1), $search_id).'" title="'.$lang_common['Page'].' '.($forum_page['page'] + 1).'" />';
155		}
156		if ($forum_page['page'] > 1)
157		{
158			$forum_page['nav']['prev'] = '<link rel="prev" href="'.forum_sublink($url_type, $forum_url['page'], ($forum_page['page'] - 1), $search_id).'" title="'.$lang_common['Page'].' '.($forum_page['page'] - 1).'" />';
159			$forum_page['nav']['first'] = '<link rel="first" href="'.forum_link($url_type, $search_id).'" title="'.$lang_common['Page'].' 1" />';
160		}
161
162		// Setup main heading
163		if ($forum_page['num_pages'] > 1)
164			$forum_page['main_head_pages'] = sprintf($lang_common['Page info'], $forum_page['page'], $forum_page['num_pages']);
165	}
166
167	// Setup main options header
168	$forum_page['main_title'] = $lang_search['Search options'];
169
170
171	($hook = get_hook('se_results_pre_header_load')) ? eval($hook) : null;
172
173	// Define page type
174	if ($show_as == 'posts')
175		define('FORUM_PAGE', 'searchposts');
176	else if ($show_as == 'topics')
177		define('FORUM_PAGE', 'searchtopics');
178	else
179		define('FORUM_PAGE', 'searchforums');
180
181	require FORUM_ROOT.'header.php';
182
183	// START SUBST - <!-- forum_main -->
184	ob_start();
185
186	($hook = get_hook('se_results_output_start')) ? eval($hook) : null;
187
188	if ($show_as == 'topics')
189	{
190		// Load the forum.php language file
191		require FORUM_ROOT.'lang/'.$forum_user['language'].'/forum.php';
192
193		$forum_page['item_header'] = array();
194		$forum_page['item_header']['subject']['title'] = '<strong class="subject-title">'.$lang_forum['Topics'].'</strong>';
195		$forum_page['item_header']['info']['forum'] = '<strong class="info-forum">'.$lang_forum['Forum'].'</strong>';
196		$forum_page['item_header']['info']['replies'] = '<strong class="info-replies">'.$lang_forum['replies'].'</strong>';
197		$forum_page['item_header']['info']['lastpost'] = '<strong class="info-lastpost">'.$lang_forum['last post'].'</strong>';
198
199		($hook = get_hook('se_results_topics_pre_item_header_output')) ? eval($hook) : null;
200
201?>
202
203	<div class="main-head">
204<?php
205
206	if (!empty($forum_page['main_head_options']))
207		echo "\n\t\t".'<p class="options">'.implode(' ', $forum_page['main_head_options']).'</p>';
208
209?>
210		<h2 class="hn"><span><?php echo $forum_page['items_info'] ?></span></h2>
211	</div>
212	<div class="main-subhead">
213		<p class="item-summary forum-noview"><span><?php printf($lang_forum['Search subtitle'], implode(' ', $forum_page['item_header']['subject']), implode(', ', $forum_page['item_header']['info'])) ?></span></p>
214	</div>
215	<div class="main-content main-forum forum-forums">
216<?php
217
218	}
219	else if ($show_as == 'posts')
220	{
221		// Load the topic.php language file
222		require FORUM_ROOT.'lang/'.$forum_user['language'].'/topic.php';
223
224		// Load parser
225		if (!defined('FORUM_PARSER_LOADED'))
226			require FORUM_ROOT.'include/parser.php';
227?>
228	<div class="main-head">
229<?php
230
231	if (!empty($forum_page['main_head_options']))
232		echo "\n\t\t".'<p class="options">'.implode(' ', $forum_page['main_head_options']).'</p>';
233
234?>
235		<h2 class="hn"><span><?php echo $forum_page['items_info'] ?></span></h2>
236	</div>
237	<div class="main-content main-topic">
238<?php
239	}
240	else if ($show_as == 'forums')
241	{
242		// Load the forum.php language file
243		require FORUM_ROOT.'lang/'.$forum_user['language'].'/index.php';
244
245		$forum_page['cur_category'] = $forum_page['cat_count'] = $forum_page['item_count'] = 0;
246	}
247
248	$forum_page['item_count'] = 0;
249
250	// Finally, lets loop through the results and output them
251	foreach ($search_set as $cur_set)
252	{
253		($hook = get_hook('se_results_loop_start')) ? eval($hook) : null;
254
255		++$forum_page['item_count'];
256
257		if ($forum_config['o_censoring'] == '1')
258			$cur_set['subject'] = censor_words($cur_set['subject']);
259
260		if ($show_as == 'posts')
261		{
262			// Generate the result heading
263			$forum_page['post_ident'] = array();
264			$forum_page['post_ident']['num'] = '<span class="post-num">'.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span>';
265			$forum_page['post_ident']['byline'] = '<span class="post-byline">'.sprintf((($cur_set['pid'] == $cur_set['first_post_id']) ? $lang_topic['Topic byline'] : $lang_topic['Reply byline']), '<strong>'.forum_htmlencode($cur_set['pposter']).'</strong>').'</span>';
266			$forum_page['post_ident']['link'] = '<span class="post-link"><a class="permalink" rel="bookmark" title="'.$lang_topic['Permalink post'].'" href="'.forum_link($forum_url['post'], $cur_set['pid']).'">'.format_time($cur_set['pposted']).'</a></span>';
267
268			($hook = get_hook('se_results_posts_row_pre_item_ident_merge')) ? eval($hook) : null;
269
270			// Generate the topic title
271			$forum_page['item_subject'] = '<a class="permalink" rel="bookmark" title="'.$lang_topic['Permalink topic'].'" href="'.forum_link($forum_url['topic'], array($cur_set['tid'], sef_friendly($cur_set['subject']))).'">'.sprintf((($cur_set['pid'] == $cur_set['first_post_id']) ? $lang_topic['Topic title'] : $lang_topic['Reply title']), forum_htmlencode($cur_set['subject'])).'</a> <small>'.sprintf($lang_topic['Search replies'], forum_number_format($cur_set['num_replies']), '<a href="'.forum_link($forum_url['forum'], array($cur_set['forum_id'], sef_friendly($cur_set['forum_name']))).'">'.forum_htmlencode($cur_set['forum_name']).'</a>').'</small>';
272
273			// Generate author identification
274			$forum_page['user_ident'] = ($cur_set['poster_id'] > 1 && $forum_user['g_view_users'] == '1') ? '<strong class="username"><a title="'.sprintf($lang_search['Go to profile'], forum_htmlencode($cur_set['pposter'])).'" href="'.forum_link($forum_url['user'], $cur_set['poster_id']).'">'.forum_htmlencode($cur_set['pposter']).'</a></strong>' : '<strong class="username">'.forum_htmlencode($cur_set['pposter']).'</strong>';
275
276			// Generate the post actions links
277			$forum_page['post_actions'] = array();
278			$forum_page['post_actions']['forum'] = '<span><a href="'.forum_link($forum_url['forum'], array($cur_set['forum_id'], sef_friendly($cur_set['forum_name']))).'">'.$lang_search['Go to forum'].'<span>: '.forum_htmlencode($cur_set['forum_name']).'</span></a></span>';
279
280			if ($cur_set['pid'] != $cur_set['first_post_id'])
281				$forum_page['post_actions']['topic'] = '<span><a class="permalink" rel="bookmark" title="'.$lang_topic['Permalink topic'].'" href="'.forum_link($forum_url['topic'], array($cur_set['tid'], sef_friendly($cur_set['subject']))).'">'.$lang_search['Go to topic'].'<span>: '.forum_htmlencode($cur_set['subject']).'</span></a></span>';
282
283			$forum_page['post_actions']['post'] = '<span><a class="permalink" rel="bookmark" title="'.$lang_topic['Permalink post'].'" href="'.forum_link($forum_url['post'], $cur_set['pid']).'">'.$lang_search['Go to post'].'<span> '.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span></a></span>';
284
285			$forum_page['message'] = parse_message($cur_set['message'], $cur_set['hide_smilies']);
286
287			// Give the post some class
288			$forum_page['item_status'] = array(
289				'post',
290				(($forum_page['item_count'] % 2 != 0) ? 'odd' : 'even' )
291			);
292
293			if ($forum_page['item_count'] == 1)
294				$forum_page['item_status']['firstpost'] = 'firstpost';
295
296			if (($forum_page['start_from'] + $forum_page['item_count']) == $forum_page['finish_at'])
297				$forum_page['item_status']['lastpost'] = 'lastpost';
298
299			if ($cur_set['pid'] == $cur_set['first_post_id'])
300				$forum_page['item_status']['topicpost'] = 'topicpost';
301
302
303			($hook = get_hook('se_results_posts_row_pre_display')) ? eval($hook) : null;
304
305?>
306	<div class="<?php echo implode(' ', $forum_page['item_status']) ?> resultpost">
307		<div class="posthead">
308			<h3 class="hn post-ident"><?php echo implode(' ', $forum_page['post_ident']) ?></h3>
309			<h4 class="hn post-title"><span><?php echo $forum_page['item_subject'] ?></span></h4>
310		</div>
311		<div class="postbody">
312			<div class="post-entry">
313				<div class="entry-content">
314					<?php echo $forum_page['message'] ?>
315				</div>
316<?php ($hook = get_hook('se_results_posts_row_new_post_entry_data')) ? eval($hook) : null; ?>
317			</div>
318		</div>
319		<div class="postfoot">
320			<div class="post-options">
321				<p class="post-actions"><?php echo implode(' ', $forum_page['post_actions']) ?></p>
322			</div>
323		</div>
324	</div>
325<?php
326
327		}
328		else if ($show_as == 'topics')
329		{
330			// Start from scratch
331			$forum_page['item_subject'] = $forum_page['item_body'] = $forum_page['item_status'] = $forum_page['item_nav'] = $forum_page['item_title'] = $forum_page['item_title_status'] = array();
332
333			// Assemble the Topic heading
334
335			// Should we display the dot or not? :)
336			if (!$forum_user['is_guest'] && $forum_config['o_show_dot'] == '1' && $cur_set['has_posted'] == $forum_user['id'])
337			{
338				$forum_page['item_title']['posted'] = '<span class="posted-mark">'.$lang_forum['You posted indicator'].'</span>';
339				$forum_page['item_status']['posted'] = 'posted';
340			}
341
342			if ($cur_set['sticky'] == '1')
343			{
344				$forum_page['item_title_status']['sticky'] = '<em class="sticky">'.$lang_forum['Sticky'].'</em>';
345				$forum_page['item_status']['sticky'] = 'sticky';
346			}
347
348			if ($cur_set['closed'] != '0')
349			{
350				$forum_page['item_title_status']['closed'] = '<em class="closed">'.$lang_forum['Closed'].'</em>';
351				$forum_page['item_status']['closed'] = 'closed';
352			}
353
354			($hook = get_hook('se_results_topics_row_pre_item_subject_status_merge')) ? eval($hook) : null;
355
356			if (!empty($forum_page['item_title_status']))
357				$forum_page['item_title']['status'] = '<span class="item-status">'.sprintf($lang_forum['Item status'], implode(', ', $forum_page['item_title_status'])).'</span>';
358
359			$forum_page['item_title']['link'] = '<a href="'.forum_link($forum_url['topic'], array($cur_set['tid'], sef_friendly($cur_set['subject']))).'">'.forum_htmlencode($cur_set['subject']).'</a>';
360
361			($hook = get_hook('se_results_topics_row_pre_item_title_merge')) ? eval($hook) : null;
362
363			$forum_page['item_body']['subject']['title'] = '<h3 class="hn"><span class="item-num">'.forum_number_format($forum_page['start_from'] + $forum_page['item_count']).'</span> '.implode(' ', $forum_page['item_title']).'</h3>';
364
365			$forum_page['item_pages'] = ceil(($cur_set['num_replies'] + 1) / $forum_user['disp_posts']);
366
367			if ($forum_page['item_pages'] > 1)
368				$forum_page['item_nav']['pages'] = '<span>'.$lang_forum['Pages'].'&#160;</span>'.paginate($forum_page['item_pages'], -1, $forum_url['topic'], $lang_common['Page separator'], array($cur_set['tid'], sef_friendly($cur_set['subject'])));
369
370			// Does this topic contain posts we haven't read? If so, tag it accordingly.
371			if (!$forum_user['is_guest'] && $cur_set['last_post'] > $forum_user['last_visit'] && (!isset($tracked_topics['topics'][$cur_set['tid']]) || $tracked_topics['topics'][$cur_set['tid']] < $cur_set['last_post']) && (!isset($tracked_topics['forums'][$cur_set['forum_id']]) || $tracked_topics['forums'][$cur_set['forum_id']] < $cur_set['last_post']))
372			{
373				$forum_page['item_nav']['new'] = '<em class="item-newposts"><a href="'.forum_link($forum_url['topic_new_posts'], array($cur_set['tid'], sef_friendly($cur_set['subject']))).'" title="'.$lang_forum['New posts info'].'">'.$lang_forum['New posts'].'</a></em>';
374				$forum_page['item_status']['new'] = 'new';
375			}
376
377			($hook = get_hook('se_results_topics_row_pre_item_nav_merge')) ? eval($hook) : null;
378
379			$forum_page['item_subject']['starter'] = '<span class="item-starter">'.sprintf($lang_forum['Topic starter'], forum_htmlencode($cur_set['poster'])).'</span>';
380
381			if (!empty($forum_page['item_nav']))
382				$forum_page['item_subject']['nav'] = '<span class="item-nav">'.sprintf($lang_forum['Topic navigation'], implode('&#160;&#160;', $forum_page['item_nav'])).'</span>';
383
384			($hook = get_hook('se_results_topics_row_pre_item_subject_merge')) ? eval($hook) : null;
385
386			$forum_page['item_body']['subject']['desc'] = '<p>'.implode(' ', $forum_page['item_subject']).'</p>';
387
388			if (empty($forum_page['item_status']))
389				$forum_page['item_status']['normal'] = 'normal';
390
391			($hook = get_hook('se_results_topics_pre_item_status_merge')) ? eval($hook) : null;
392
393			$forum_page['item_style'] = (($forum_page['item_count'] % 2 != 0) ? ' odd' : ' even').(($forum_page['item_count'] == 1) ? ' main-first-item' : '').((!empty($forum_page['item_status'])) ? ' '.implode(' ', $forum_page['item_status']) : '');
394
395			$forum_page['item_body']['info']['forum'] = '<li class="info-forum"><span class="label">'.$lang_search['Posted in'].'</span><a href="'.forum_link($forum_url['forum'], array($cur_set['forum_id'], sef_friendly($cur_set['forum_name']))).'">'.$cur_set['forum_name'].'</a></li>';
396			$forum_page['item_body']['info']['replies'] = '<li class="info-replies"><strong>'.forum_number_format($cur_set['num_replies']).'</strong> <span class="label">'.(($cur_set['num_replies'] == 1) ? $lang_forum['Reply'] : $lang_forum['Replies']).'</span></li>';
397			$forum_page['item_body']['info']['lastpost'] = '<li class="info-lastpost"><span class="label">'.$lang_forum['Last post'].'</span> <strong><a href="'.forum_link($forum_url['post'], $cur_set['last_post_id']).'">'.format_time($cur_set['last_post']).'</a></strong> <cite>'.sprintf($lang_forum['by poster'], forum_htmlencode($cur_set['last_poster'])).'</cite></li>';
398
399			($hook = get_hook('se_results_topics_row_pre_display')) ? eval($hook) : null;
400
401?>
402		<div class="main-item<?php echo $forum_page['item_style'] ?>">
403			<span class="icon <?php echo implode(' ', $forum_page['item_status']) ?>"><!-- --></span>
404			<div class="item-subject">
405				<?php echo implode("\n\t\t\t\t", $forum_page['item_body']['subject'])."\n" ?>
406			</div>
407			<ul class="item-info">
408				<?php echo implode("\n\t\t\t\t", $forum_page['item_body']['info'])."\n" ?>
409			</ul>
410		</div>
411<?php
412
413		}
414		else if ($show_as == 'forums')
415		{
416			if ($cur_set['cid'] != $forum_page['cur_category'])	// A new category since last iteration?
417			{
418				if ($forum_page['cur_category'] != 0)
419					echo "\t".'</div>'."\n";
420
421				++$forum_page['cat_count'];
422				$forum_page['item_count'] = 1;
423
424				$forum_page['item_header'] = array();
425				$forum_page['item_header']['subject']['title'] = '<strong class="subject-title">'.$lang_index['Forums'].'</strong>';
426				$forum_page['item_header']['info']['topics'] = '<strong class="info-topics">'.$lang_index['topics'].'</strong>';
427				$forum_page['item_header']['info']['post'] = '<strong class="info-posts">'.$lang_index['posts'].'</strong>';
428				$forum_page['item_header']['info']['lastpost'] = '<strong class="info-lastpost">'.$lang_index['last post'].'</strong>';
429
430				($hook = get_hook('se_results_forums_row_pre_cat_head')) ? eval($hook) : null;
431
432				$forum_page['cur_category'] = $cur_set['cid'];
433
434?>
435				<div class="main-head">
436					<h2 class="hn"><span><?php echo forum_htmlencode($cur_set['cat_name']) ?></span></h2>
437				</div>
438				<div class="main-subhead">
439					<p class="item-summary"><span><?php printf($lang_index['Category subtitle'], implode(' ', $forum_page['item_header']['subject']), implode(', ', $forum_page['item_header']['info'])) ?></span></p>
440				</div>
441				<div id="category<?php echo $forum_page['cat_count'] ?>" class="main-content main-category">
442<?php
443			}
444
445			// Reset arrays and globals for each forum
446			$forum_page['item_status'] = $forum_page['item_subject'] = $forum_page['item_body'] = $forum_page['item_title'] = array();
447
448			// Is this a redirect forum?
449			if ($cur_set['redirect_url'] != '')
450			{
451				$forum_page['item_body']['subject']['title'] = '<h3 class="hn"><a class="external" href="'.forum_htmlencode($cur_forum['redirect_url']).'" title="'.sprintf($lang_index['Link to'], forum_htmlencode($cur_forum['redirect_url'])).'"><span>'.forum_htmlencode($cur_set['forum_name']).'</span></a></h3>';
452				$forum_page['item_status']['redirect'] = 'redirect';
453
454				if ($cur_set['forum_desc'] != '')
455					$forum_page['item_subject']['desc'] = $cur_set['forum_desc'];
456
457				$forum_page['item_subject']['redirect'] = '<span>'.$lang_index['External forum'].'</span>';
458
459				($hook = get_hook('se_results_forums_row_redirect_pre_item_subject_merge')) ? eval($hook) : null;
460
461				if (!empty($forum_page['item_subject']))
462					$forum_page['item_body']['subject']['desc'] = '<p>'.implode(' ', $forum_page['item_subject']).'</p>';
463
464				// Forum topic and post count
465				$forum_page['item_body']['info']['topics'] = '<li class="info-topics"><span class="label">'.$lang_index['No topic info'].'</span></li>';
466				$forum_page['item_body']['info']['posts'] = '<li class="info-posts"><span class="label">'.$lang_index['No post info'].'</span></li>';
467				$forum_page['item_body']['info']['lastpost'] = '<li class="info-lastpost"><span class="label">'.$lang_index['No lastpost info'].'</span></li>';
468
469				($hook = get_hook('se_results_forums_row_redirect_pre_display')) ? eval($hook) : null;
470			}
471			else
472			{
473				// Setup the title and link to the forum
474				$forum_page['item_title']['title'] = '<a href="'.forum_link($forum_url['forum'], array($cur_set['fid'], sef_friendly($cur_set['forum_name']))).'"><span>'.forum_htmlencode($cur_set['forum_name']).'</span></a>';
475
476				($hook = get_hook('se_results_forums_row_redirect_pre_item_title_merge')) ? eval($hook) : null;
477
478				$forum_page['item_body']['subject']['title'] = '<h3 class="hn">'.implode(' ', $forum_page['item_title']).'</h3>';
479
480				// Setup the forum description and mod list
481				if ($cur_set['forum_desc'] != '')
482					$forum_page['item_subject']['desc'] = $cur_set['forum_desc'];
483
484				($hook = get_hook('se_results_forums_row_normal_pre_item_subject_merge')) ? eval($hook) : null;
485
486				if (!empty($forum_page['item_subject']))
487					$forum_page['item_body']['subject']['desc'] = '<p>'.implode(' ', $forum_page['item_subject']).'</p>';
488
489				// Setup forum topics, post count and last post
490				$forum_page['item_body']['info']['topics'] = '<li class="info-topics"><strong>'.forum_number_format($cur_set['num_topics']).'</strong> <span class="label">'.(($cur_set['num_topics'] == 1) ? $lang_index['topic'] : $lang_index['topics']).'</span></li>';
491				$forum_page['item_body']['info']['posts'] = '<li class="info-posts"><strong>'.forum_number_format($cur_set['num_posts']).'</strong> <span class="label">'.(($cur_set['num_posts'] == 1) ? $lang_index['post'] : $lang_index['posts']).'</span></li>';
492
493				if ($cur_set['last_post'] != '')
494					$forum_page['item_body']['info']['lastpost'] = '<li class="info-lastpost"><span class="label">'.$lang_index['Last post'].'</span> <strong><a href="'.forum_link($forum_url['post'], $cur_set['last_post_id']).'">'.format_time($cur_set['last_post']).'</a></strong> <cite>'.sprintf($lang_index['Last poster'], forum_htmlencode($cur_set['last_poster'])).'</cite></li>';
495				else
496					$forum_page['item_body']['info']['lastpost'] = '<li class="info-lastpost"><strong>'.$lang_common['Never'].'</strong></li>';
497
498				($hook = get_hook('se_results_forums_row_normal_pre_display')) ? eval($hook) : null;
499			}
500
501			// Generate classes for this forum depending on its status
502			$forum_page['item_style'] = (($forum_page['item_count'] % 2 != 0) ? ' odd' : ' even').(($forum_page['item_count'] == 1) ? ' main-first-item' : '').((!empty($forum_page['item_status'])) ? ' '.implode(' ', $forum_page['item_status']) : '');
503
504			($hook = get_hook('se_results_forums_row_pre_display')) ? eval($hook) : null;
505
506?>
507			<div id="forum<?php echo $cur_set['fid'] ?>" class="main-item<?php echo $forum_page['item_style'] ?>">
508				<span class="icon <?php echo implode(' ', $forum_page['item_status']) ?>"><!-- --></span>
509				<div class="item-subject">
510					<?php echo implode("\n\t\t\t\t", $forum_page['item_body']['subject'])."\n" ?>
511				</div>
512				<ul class="item-info">
513					<?php echo implode("\n\t\t\t\t", $forum_page['item_body']['info'])."\n" ?>
514				</ul>
515			</div>
516<?php
517		}
518	}
519?>
520	</div>
521
522	<div class="main-foot">
523<?php
524
525	if (!empty($forum_page['main_foot_options']))
526		echo "\n\t\t\t".'<p class="options">'.implode(' ', $forum_page['main_foot_options']).'</p>';
527
528?>
529		<h2 class="hn"><span><?php echo $forum_page['items_info'] ?></span></h2>
530	</div>
531<?php
532
533	($hook = get_hook('se_results_end')) ? eval($hook) : null;
534
535	$tpl_temp = forum_trim(ob_get_contents());
536	$tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
537	ob_end_clean();
538	// END SUBST - <!-- forum_main -->
539
540	require FORUM_ROOT.'footer.php';
541}
542
543//
544// Display the search form
545//
546
547// Setup form information
548$forum_page['frm-info'] = array(
549	'keywords'	=> '<li><span>'.$lang_search['Keywords info'].'</span></li>',
550	'refine'	=> '<li><span>'.$lang_search['Refine info'].'</span></li>',
551	'wildcard'	=> '<li><span>'.$lang_search['Wildcard info'].'</span></li>'
552);
553
554if ($forum_config['o_search_all_forums'] == '1' || $forum_user['is_admmod'])
555	$forum_page['frm-info']['forums'] = '<li><span>'.$lang_search['Forum default info'].'</span></li>';
556else
557	$forum_page['frm-info']['forums'] = '<li><span>'.$lang_search['Forum require info'].'</span></li>';
558
559// Setup sort by options
560$forum_page['frm-sort'] = array(
561	'post_time'		=> '<option value="0">'.$lang_search['Sort by post time'].'</option>',
562	'author'		=> '<option value="1">'.$lang_search['Sort by author'].'</option>',
563	'subject'		=> '<option value="2">'.$lang_search['Sort by subject'].'</option>',
564	'forum_name'	=> '<option value="3">'.$lang_search['Sort by forum'].'</option>'
565);
566
567// Setup breadcrumbs
568$forum_page['crumbs'] = array(
569	array($forum_config['o_board_title'], forum_link($forum_url['index'])),
570	$lang_common['Search']
571);
572
573$advanced_search = isset($_GET['advanced']) ? true : false;
574
575// Show link for advanced form
576if (!$advanced_search)
577{
578	$forum_page['main_head_options']['advanced_search'] = '<span'.(empty($forum_page['main_head_options']) ? ' class="first-item"' : '').'><a href="'.forum_link($forum_url['search_advanced']).'">'.$lang_search['Advanced search'].'</a></span>';
579}
580
581// Setup form
582$forum_page['group_count'] = $forum_page['item_count'] = $forum_page['fld_count'] = 0;
583
584($hook = get_hook('se_pre_header_load')) ? eval($hook) : null;
585
586define('FORUM_PAGE', 'search');
587require FORUM_ROOT.'header.php';
588
589// START SUBST - <!-- forum_main -->
590ob_start();
591
592($hook = get_hook('se_main_output_start')) ? eval($hook) : null;
593
594?>
595	<div class="main-head">
596<?php
597
598	if (!empty($forum_page['main_head_options']))
599		echo "\n\t\t".'<p class="options">'.implode(' ', $forum_page['main_head_options']).'</p>';
600
601?>
602		<h2 class="hn"><span><?php echo $lang_search['Search heading'] ?></span></h2>
603	</div>
604	<div class="main-content main-frm">
605<?php if ($advanced_search): ?>
606		<div class="ct-box info-box">
607			<ul class="info-list">
608				<?php echo implode("\n\t\t\t\t", $forum_page['frm-info'])."\n" ?>
609			</ul>
610		</div>
611<?php endif; ?>
612		<form id="afocus" class="frm-form" method="get" accept-charset="utf-8" action="<?php echo forum_link($forum_url['search']) ?>">
613			<div class="hidden">
614				<input type="hidden" name="action" value="search" />
615			</div>
616<?php ($hook = get_hook('se_pre_criteria_fieldset')) ? eval($hook) : null; ?>
617			<fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
618				<legend class="group-legend"><strong><?php echo $lang_search['Search legend'] ?></strong></legend>
619<?php ($hook = get_hook('se_pre_keywords')) ? eval($hook) : null; ?>
620				<div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
621					<div class="sf-box text">
622						<label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_search['Keyword search'] ?></span></label><br />
623						<span class="fld-input"><input type="text" id="fld<?php echo $forum_page['fld_count'] ?>" name="keywords" size="40" maxlength="100" <?php echo ($advanced_search) ? '' : 'required' ?> /></span>
624					</div>
625				</div>
626<?php ($hook = get_hook('se_pre_author')) ? eval($hook) : null; ?>
627<?php if ($advanced_search): ?>
628				<div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
629					<div class="sf-box text">
630						<label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_search['Author search'] ?></span></label><br />
631						<span class="fld-input"><input id="fld<?php echo $forum_page['fld_count'] ?>" type="text" name="author" size="40" maxlength="25" /></span>
632					</div>
633				</div>
634<?php ($hook = get_hook('se_pre_search_in')) ? eval($hook) : null; ?>
635				<div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
636					<div class="sf-box select">
637						<label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_search['Search in'] ?></span></label><br />
638						<span class="fld-input"><select id="fld<?php echo $forum_page['fld_count'] ?>" name="search_in">
639							<option value="all"><?php echo $lang_search['Message and subject'] ?></option>
640							<option value="message"><?php echo $lang_search['Message only'] ?></option>
641							<option value="topic"><?php echo $lang_search['Topic only'] ?></option>
642						</select></span>
643					</div>
644				</div>
645<?php endif; if ((!$advanced_search && ($forum_config['o_search_all_forums'] == '0' && !$forum_user['is_admmod'])) || $advanced_search): ?>
646<?php ($hook = get_hook('se_pre_forum_fieldset')) ? eval($hook) : null; ?>
647				<fieldset class="mf-set set<?php echo ++$forum_page['item_count'] ?>">
648					<legend><span><?php echo $lang_search['Forum search'] ?> <em><?php echo ($forum_config['o_search_all_forums'] == '1' || $forum_user['is_admmod']) ? $lang_search['Forum search default'] : $lang_search['Forum search require'] ?></em></span></legend>
649<?php ($hook = get_hook('se_pre_forum_checklist')) ? eval($hook) : null; ?>
650					<div class="mf-box">
651						<div class="checklist">
652<?php
653
654// Get the list of categories and forums
655$query = array(
656	'SELECT'	=> 'c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.redirect_url',
657	'FROM'		=> 'categories AS c',
658	'JOINS'		=> array(
659		array(
660			'INNER JOIN'	=> 'forums AS f',
661			'ON'			=> 'c.id=f.cat_id'
662		),
663		array(
664			'LEFT JOIN'		=> 'forum_perms AS fp',
665			'ON'			=> '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
666		)
667	),
668	'WHERE'		=> '(fp.read_forum IS NULL OR fp.read_forum=1) AND f.redirect_url IS NULL',
669	'ORDER BY'	=> 'c.disp_position, c.id, f.disp_position'
670);
671
672($hook = get_hook('se_qr_get_cats_and_forums')) ? eval($hook) : null;
673$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
674
675$forums = array();
676while ($cur_forum = $forum_db->fetch_assoc($result))
677{
678	$forums[] = $cur_forum;
679}
680
681if (!empty($forums))
682{
683	$cur_category = 0;
684	foreach ($forums as $cur_forum)
685	{
686		($hook = get_hook('se_forum_loop_start')) ? eval($hook) : null;
687
688		if ($cur_forum['cid'] != $cur_category)	// A new category since last iteration?
689		{
690			if ($cur_category)
691				echo "\t\t\t\t\t\t\t".'</fieldset>'."\n";
692
693			echo "\t\t\t\t\t\t\t".'<fieldset>'."\n\t\t\t\t\t\t\t\t".'<legend><span>'.forum_htmlencode($cur_forum['cat_name']).':</span></legend>'."\n";
694			$cur_category = $cur_forum['cid'];
695		}
696
697		echo "\t\t\t\t\t\t\t\t".'<div class="checklist-item"><span class="fld-input"><input type="checkbox" id="fld'.(++$forum_page['fld_count']).'" name="forum[]" value="'.$cur_forum['fid'].'" /></span> <label for="fld'.$forum_page['fld_count'].'">'.forum_htmlencode($cur_forum['forum_name']).'</label></div>'."\n";
698
699		($hook = get_hook('se_forum_loop_end')) ? eval($hook) : null;
700	}
701
702	echo "\t\t\t\t\t\t\t".'</fieldset>'."\n";
703}
704
705?>
706						</div>
707					</div>
708<?php ($hook = get_hook('se_pre_forum_fieldset_end')) ? eval($hook) : null; ?>
709				</fieldset>
710<?php endif; ?>
711<?php ($hook = get_hook('se_forum_fieldset_end')) ? eval($hook) : null; ?>
712			</fieldset>
713<?php ($hook = get_hook('se_criteria_fieldset_end')) ? eval($hook) : null; ?>
714<?php $forum_page['item_count'] = 0; ?>
715<?php ($hook = get_hook('se_pre_results_fieldset')) ? eval($hook) : null; ?>
716<?php if ($advanced_search): ?>
717			<fieldset class="frm-group group<?php echo ++$forum_page['group_count'] ?>">
718				<legend class="group-legend"><strong><?php echo $lang_search['Results legend'] ?></strong></legend>
719<?php ($hook = get_hook('se_pre_sort_by')) ? eval($hook) : null; ?>
720				<div class="sf-set set<?php echo ++$forum_page['item_count'] ?>">
721					<div class="sf-box select">
722						<label for="fld<?php echo ++$forum_page['fld_count'] ?>"><span><?php echo $lang_search['Sort by'] ?></span></label><br />
723						<span class="fld-input"><select id="fld<?php echo $forum_page['fld_count'] ?>" name="sort_by">
724						<?php echo implode("\n\t\t\t\t\t\t", $forum_page['frm-sort'])."\n" ?>
725						</select></span>
726					</div>
727				</div>
728<?php ($hook = get_hook('se_pre_sort_order_fieldset')) ? eval($hook) : null; ?>
729				<fieldset class="mf-set set<?php echo ++$forum_page['item_count'] ?>">
730					<legend><span><?php echo $lang_search['Sort order'] ?></span></legend>
731<?php ($hook = get_hook('se_pre_sort_order')) ? eval($hook) : null; ?>
732					<div class="mf-box mf-yesno">
733						<div class="mf-item">
734							<span class="fld-input"><input type="radio" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="sort_dir" value="ASC" /></span>
735							<label for="fld<?php echo $forum_page['fld_count'] ?>"><?php echo $lang_search['Ascending'] ?></label>
736						</div>
737						<div class="mf-item">
738							<span class="fld-input"><input type="radio" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="sort_dir" value="DESC" checked="checked" /></span>
739							<label for="fld<?php echo $forum_page['fld_count'] ?>"><?php echo $lang_search['Descending'] ?></label>
740						</div>
741					</div>
742<?php ($hook = get_hook('se_pre_sort_order_fieldset_end')) ? eval($hook) : null; ?>
743				</fieldset>
744<?php ($hook = get_hook('se_pre_display_choices_fieldset')) ? eval($hook) : null; ?>
745				<fieldset class="mf-set set<?php echo ++$forum_page['item_count'] ?>">
746					<legend><span><?php echo $lang_search['Display results'] ?></span></legend>
747<?php ($hook = get_hook('se_pre_display_choices')) ? eval($hook) : null; ?>
748					<div class="mf-box mf-yesno">
749						<div class="mf-item">
750							<span class="fld-input"><input type="radio" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="show_as" value="topics" /></span>
751							<label for="fld<?php echo $forum_page['fld_count'] ?>"><?php echo $lang_search['Show as topics'] ?></label>
752						</div>
753						<div class="mf-item">
754							<span class="fld-input"><input type="radio" id="fld<?php echo ++$forum_page['fld_count'] ?>" name="show_as" value="posts" checked="checked" /></span>
755							<label for="fld<?php echo $forum_page['fld_count'] ?>"><?php echo $lang_search['Show as posts'] ?></label>
756						</div>
757<?php ($hook = get_hook('se_new_display_choices')) ? eval($hook) : null; ?>
758					</div>
759<?php ($hook = get_hook('se_pre_display_choices_fieldset_end')) ? eval($hook) : null; ?>
760				</fieldset>
761<?php ($hook = get_hook('se_pre_results_fieldset_end')) ? eval($hook) : null; ?>
762			</fieldset>
763<?php endif; ($hook = get_hook('se_results_fieldset_end')) ? eval($hook) : null; ?>
764			<div class="frm-buttons">
765				<span class="submit primary"><input type="submit" name="search" value="<?php echo $lang_search['Submit search'] ?>" /></span>
766			</div>
767		</form>
768	</div>
769<?php
770
771($hook = get_hook('se_end')) ? eval($hook) : null;
772
773$tpl_temp = forum_trim(ob_get_contents());
774$tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
775ob_end_clean();
776// END SUBST - <!-- forum_main -->
777
778
779require FORUM_ROOT.'footer.php';
780