root/phpBB2/search.php

Revision 331, 43.1 kB (checked in by Nafania, 1 year ago)

фича - похожие торренты

Line 
1 <?php
2 /***************************************************************************</span>
3 <span class="code-comment"> *                search.php
4  *                -------------------
5  *   begin        : Saturday, Feb 13, 2001
6  *   copyright        : (C) 2001 The phpBB Group
7  *   email        : support@phpbb.com
8  *
9  *   $Id: search.php,v 1.72.2.17 2005/09/14 18:14:30 acydburn Exp $
10  *
11  *
12  ***************************************************************************/
13
14 /***************************************************************************
15  *
16  *   This program is free software; you can redistribute it and/or modify
17  *   it under the terms of the GNU General Public License as published by
18  *   the Free Software Foundation; either version 2 of the License, or
19  *   (at your option) any later version.
20  *
21  ***************************************************************************/
22
23 if ( !defined('IN_PHPBB2_BRIDGE') ) {</span>
24 <span class="code-keyword">    trigger_error('Invalid access');
25 }
26
27 define('IN_PHPBB', true);
28 $root_path = './';</span>
29 <span class="code-lang">include($root_path . 'extension.inc');
30 include($root_path . 'phpBB2/includes/bbcode.'.$phpEx);
31 include($root_path . 'phpBB2/includes/functions_search.'.$phpEx);
32 include($root_path . 'include/bbcode/bbcode.lib.php');
33
34 //</span>
35 <span class="code-comment">// Start session management
36 //
37 $userdata = session_pagestart($user_ip);
38 init_userprefs($userdata);
39 //</span>
40 <span class="code-comment">// End session management
41 //
42
43 /* */
44 $bb_code = new bbcode;
45 /* */</span>
46 <span class="code-comment">
47 //
48 // Define initial vars
49 //
50 $mode = request_var('mode', '');
51 $search_keywords = request_var('search_keywords', '');
52 $search_author = phpbb_clean_username(request_var('search_author', ''));
53 $search_id = request_var('search_id', '');
54 $show_results = request_var('show_results', 'posts');
55 $show_results = ($show_results == 'topics') ? 'topics' : 'posts';
56 $return_chars = request_var('return_chars', 200);
57 $search_cat = request_var('search_cat', -1);
58 $search_forum = request_var('search_forum', -1);
59 $sort_by = request_var('sort_by', 0);
60
61 $search_terms = request_var('search_terms', '');
62 $search_terms = ( $search_terms == 'all' ? 1 : 0 );
63
64 $search_fields = request_var('search_fields', '');
65 $search_fields = ( $search_fields == 'all' ? 1 : 0 );
66
67 $sort_dir = request_var('sort_dir', '');
68 $sort_dir = ( $sort_dir == 'ASC' ? 'ASC' : 'DESC' );
69
70 $search_time = request_var('search_time', 0);
71 $search_time = ( $search_time ? time() - $search_time * 86400 : 0 );
72
73 $topic_days = $search_time;
74
75 $start = request_var('start', 0);
76
77 $sort_by_types = array($lang['sort_time'], $lang['sort_post_subject'], $lang['sort_topic_title'], $lang['sort_author'], $lang['sort_forum']);
78
79 $split_search = array();
80
81 //</span>
82 <span class="code-comment">// Begin core code
83 //
84 if ( $mode == 'searchuser' )</span>
85 <span class="code-keyword">{
86     $search_username = request_var('search_username', '');
87     username_search($search_username);
88     gc();
89 }
90 else if ( $search_keywords != '' || $search_author != '' || $search_id )
91 {
92     $store_vars = array('search_results', 'total_match_count', 'split_search', 'sort_by', 'sort_dir', 'show_results', 'return_chars');
93     $search_results = '';
94     // Topic search MOD
95     $tid = request_var('topic_id', 0);
96     // Topic search MOD
97
98     //
99     // Search ID Limiter, decrease this value if you experience further timeout problems with searching forums
100     $limiter = 5000;
101     $current_time = time();
102     $total_match_count = 0;
103
104     //
105     // Cycle through options ...
106     //
107     if ( $search_id == 'newposts' || $search_id == 'egosearch' || $search_id == 'unanswered' || $search_keywords != '' || $search_author != '' )
108     {
109         //
110         // Flood control
111         //
112         $where_sql = ($userdata['uid'] == ANONYMOUS) ? "se.session_ip = '$user_ip'" : 'se.session_user_id = ' . $userdata['uid'];
113         $sql = 'SELECT MAX(sr.search_time) AS last_search_time
114                 FROM ' . SEARCH_TABLE . ' sr, ' . SESSIONS_TABLE . " se
115                 WHERE sr.session_id = se.session_id
116                 AND $where_sql";
117         $result = $db->sql_query($sql);
118         if ( $row = $db->sql_fetchrow($result) ) {
119             if ( $row['last_search_time'] > 0 && ($current_time - $row['last_search_time']) < $config['search_flood_interval'] ) {
120                 $wait_time = intval($config['search_flood_interval']) - ($current_time - intval($row['last_search_time']));
121                 trigger_error(sprintf($lang['search_flood_error'], $wait_time));
122             }
123         }
124
125         if ( $search_id == 'newposts' || $search_id == 'egosearch' || ( $search_author != '' && $search_keywords == '' )  )
126         {
127             if ( $search_id == 'newposts' )
128             {
129
130                 loggedinorreturn();
131
132                 $topic_ids = get_unread_topics();
133
134                 if ( sizeof($topic_ids) ) {
135                     $topic_ids = array_keys($topic_ids);
136                     $sql = 'SELECT post_id FROM ' . POSTS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
137                 }
138                 else {
139                     $sql = false;
140                 }
141
142                 $show_results = 'topics';
143                 $sort_by = 0;
144                 $sort_dir = 'DESC';
145             }
146             else if ( $search_id == 'egosearch' )
147             {
148                 loggedinorreturn();
149
150                 $sql = "SELECT post_id FROM " . POSTS_TABLE . " WHERE poster_id = " . $userdata['uid'];
151
152                 $show_results = 'topics';
153                 $sort_by = 0;
154                 $sort_dir = 'DESC';
155             }
156             else
157             {
158                 $search_author = str_replace('*', '%', trim($search_author));
159
160                 if( ( strpos($search_author, '%') !== false ) && ( utf_strlen(str_replace('%', '', $search_author)) < $config['search_min_chars'] ) )
161                 {
162                     $search_author = '';
163                 }
164
165                 $sql = "SELECT uid FROM " . USERS_TABLE . " WHERE name LIKE '" . $db->sql_escape($search_author) . "'";
166                 $result = $db->sql_query($sql);
167
168                 $matching_userids = '';
169                 if ( $row = $db->sql_fetchrow($result) )
170                 {
171                     do
172                     {
173                         $matching_userids .= ( ( $matching_userids != '' ) ? ', ' : '' ) . $row['uid'];
174                     }
175                     while( $row = $db->sql_fetchrow($result) );
176                 }
177                 else
178                 {
179                     trigger_error($lang['no_search_match']);
180                 }
181
182                 $sql = "SELECT post_id FROM " . POSTS_TABLE . " WHERE poster_id IN ($matching_userids)";
183
184                 if ($search_time)
185                 {
186                     $sql .= " AND post_time >= " . $search_time;
187                 }
188             }
189
190             $result = $db->sql_query($sql);
191
192             $search_ids = array();
193             while( $row = $db->sql_fetchrow($result) )
194             {
195                 $search_ids[] = $row['post_id'];
196             }
197
198             $db->sql_freeresult($result);
199
200             $total_match_count = sizeof($search_ids);
201
202         }
203         else if ( $search_keywords != '' )
204         {
205             $stopword_array = @file($root_path . 'languages/lang_' . $config['default_lang'] . '/search_stopwords.txt');
206             $synonym_array = @file($root_path . 'languages/lang_' . $config['default_lang'] . '/search_synonyms.txt');
207
208             $stripped_keywords = ( STRIP ? stripslashes($search_keywords) : $search_keywords );
209             $split_search = split_words(clean_words('search', $stripped_keywords, $stopword_array, $synonym_array), 'search');
210             unset($stripped_keywords);
211
212             $search_msg_only = ( !$search_fields ) ? "AND m.title_match = 0" : '';
213
214             $word_count = 0;
215             $current_match_type = 'or';
216
217             $word_match = array();
218             $result_list = array();
219
220             for($i = 0; $i < sizeof($split_search); $i++)
221             {
222                 if ( utf_strlen(str_replace(array('*', '%'), '', trim($split_search[$i]))) < $config['search_min_chars'] )
223                 {
224                     $split_search[$i] = '';
225                     continue;
226                 }
227
228                 switch ( $split_search[$i] )
229                 {
230                     case 'and':
231                         $current_match_type = 'and';
232                         break;
233
234                     case 'or':
235                         $current_match_type = 'or';
236                         break;
237
238                     case 'not':
239                         $current_match_type = 'not';
240                         break;
241
242                     default:
243                         if ( !empty($search_terms) )
244                         {
245                             $current_match_type = 'and';
246                         }
247
248                         $match_word = str_replace('*', '%', $split_search[$i]);
249                         $sql = "SELECT m.post_id
250                                 FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
251                                 WHERE w.word_text LIKE '$match_word'
252                                     AND m.word_id = w.word_id
253                                     AND w.word_common <> 1
254                                     $search_msg_only";
255                         $result = $db->sql_query($sql);
256
257                         $row = array();
258                         while( $temp_row = $db->sql_fetchrow($result) )
259                         {
260                             $row[$temp_row['post_id']] = 1;
261
262                             if ( !$word_count )
263                             {
264                                 $result_list[$temp_row['post_id']] = 1;
265                             }
266                             else if ( $current_match_type == 'or' )
267                             {
268                                 $result_list[$temp_row['post_id']] = 1;
269                             }
270                             else if ( $current_match_type == 'not' )
271                             {
272                                 $result_list[$temp_row['post_id']] = 0;
273                             }
274                         }
275
276                         if ( $current_match_type == 'and' && $word_count )
277                         {
278                             @reset($result_list);
279                             while( list($post_id, $match_count) = @each($result_list) )
280                             {
281                                 if ( !$row[$post_id] )
282                                 {
283                                     $result_list[$post_id] = 0;
284                                 }
285                             }
286                         }
287
288                         $word_count++;
289
290                         $db->sql_freeresult($result);
291                     }
292             }
293
294             @reset($result_list);
295
296             $search_ids = array();
297             while( list($post_id, $matches) = each($result_list) )
298             {
299                 if ( $matches )
300                 {
301
302                     // Topic Search MOD
303                     if($tid)
304                     {
305                         $sql = "SELECT post_id
306                             FROM " . POSTS_TABLE . "
307                             WHERE topic_id = '$tid'";
308                         $result = $db->sql_query($sql);
309                         while( $test = $db->sql_fetchrow($result) )
310                         {
311                             if($test['post_id'] == $post_id)
312                             {
313                                 $search_ids[] = $post_id;
314                             }
315                         }
316                         $show_results = 'posts';
317                     }
318                     else
319                     { // End Topic Search MOD
320
321                     $search_ids[] = $post_id;
322                     // Topic Search MOD
323                     }
324                     // End Topic search MOD
325                 }
326             }
327
328             unset($result_list);
329             $total_match_count = sizeof($search_ids);
330         }
331
332         //
333         // If user is logged in then we'll check to see which (if any) private
334         // forums they are allowed to view and include them in the search.
335         //
336         // If not logged in we explicitly prevent searching of private forums
337         //
338         $auth_sql = '';
339         if ( $search_forum != -1 )
340         {
341             $is_auth = auth(AUTH_READ, $search_forum, $userdata);
342
343             if ( !$is_auth['auth_read'] )
344             {
345                 trigger_error($lang['no_searchable_forums']);
346                 return;
347             }
348
349             $auth_sql = "f.forum_id = $search_forum";
350         }
351         else
352         {
353             $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
354
355             if ( $search_cat != -1 )
356             {
357                 $auth_sql = "f.cat_id = $search_cat";
358             }
359
360             $ignore_forum_sql = '';
361             while( list($key, $value) = each($is_auth_ary) )
362             {
363                 if ( !$value['auth_read'] )
364                 {
365                     $ignore_forum_sql .= ( ( $ignore_forum_sql != '' ) ? ', ' : '' ) . $key;
366                 }
367             }
368
369             if ( $ignore_forum_sql != '' )
370             {
371                 $auth_sql .= ( $auth_sql != '' ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) ";
372             }
373         }
374
375         //
376         // Author name search
377         //
378         if ( $search_author != '' )
379         {
380             $search_author = str_replace('*', '%', trim($search_author));
381
382             if( ( strpos($search_author, '%') !== false ) && ( utf_strlen(str_replace('%', '', $search_author)) < $config['search_min_chars'] ) )
383             {
384                 $search_author = '';
385             }
386         }
387
388         if ( $total_match_count )
389         {
390             if ( $show_results == 'topics' )
391             {
392                 //
393                 // This one is a beast, try to seperate it a bit (workaround for connection timeouts)
394                 //
395                 $search_id_chunks = array();
396                 $count = 0;
397                 $chunk = 0;
398
399                 if (sizeof($search_ids) > $limiter)
400                 {
401                     for ($i = 0; $i < sizeof($search_ids); $i++)
402                     {
403                         if ($count == $limiter)
404                         {
405                             $chunk++;
406                             $count = 0;
407                         }
408
409                         $search_id_chunks[$chunk][$count] = $search_ids[$i];
410                         $count++;
411                     }
412                 }
413                 else
414                 {
415                     $search_id_chunks[0] = $search_ids;
416                 }
417
418                 $search_ids = array();
419
420                 for ($i = 0; $i < sizeof($search_id_chunks); $i++)
421                 {
422                     $where_sql = '';
423
424                     if ( $search_time )
425                     {
426                         $where_sql .= ( $search_author == '' && $auth_sql == ''  ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time ";
427                     }
428
429                     if ( $search_author == '' && $auth_sql == '' )
430                     {
431                         $sql = "SELECT topic_id
432                             FROM " . POSTS_TABLE . "
433                             WHERE post_id IN (" . implode(", ", $search_id_chunks[$i]) . ")
434                             $where_sql
435                             GROUP BY topic_id";
436                     }
437                     else
438                     {
439                         $from_sql = POSTS_TABLE . " p";
440
441                         if ( $search_author != '' )
442                         {
443                             $from_sql .= ", " . USERS_TABLE . " u";
444                             $where_sql .= " AND u.uid = p.poster_id AND u.name LIKE '$search_author' ";
445                         }
446
447                         if ( $auth_sql != '' )
448                         {
449                             $from_sql .= ", " . FORUMS_TABLE . " f";
450                             $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
451                         }
452
453                         $sql = "SELECT p.topic_id
454                             FROM $from_sql
455                             WHERE p.post_id IN (" . implode(", ", $search_id_chunks[$i]) . ")
456                                 $where_sql
457                             GROUP BY p.topic_id";
458                     }
459
460                     $result = $db->sql_query($sql);
461
462                     while ($row = $db->sql_fetchrow($result))
463                     {
464                         $search_ids[] = $row['topic_id'];
465                     }
466                     $db->sql_freeresult($result);
467                 }
468
469                 $total_match_count = sizeof($search_ids);
470
471             }
472             else if ( $search_author != '' || $search_time || $auth_sql != '' )
473             {
474                 $search_id_chunks = array();
475                 $count = 0;
476                 $chunk = 0;
477
478                 if (count($search_ids) > $limiter)
479                 {
480                     for ($i = 0; $i < count($search_ids); $i++)
481                     {
482                         if ($count == $limiter)
483                         {
484                             $chunk++;
485                             $count = 0;
486                         }
487
488                         $search_id_chunks[$chunk][$count] = $search_ids[$i];
489                         $count++;
490                     }
491                 }
492                 else
493                 {
494                     $search_id_chunks[0] = $search_ids;
495                 }
496
497                 $search_ids = array();
498
499                 for ($i = 0; $i < count($search_id_chunks); $i++)
500                 {
501                     $where_sql = ( $search_author == '' && $auth_sql == '' ) ? 'post_id IN (' . implode(', ', $search_id_chunks[$i]) . ')' : 'p.post_id IN (' . implode(', ', $search_id_chunks[$i]) . ')';
502                     $select_sql = ( $search_author == '' && $auth_sql == '' ) ? 'post_id' : 'p.post_id';
503                     $from_sql = (  $search_author == '' && $auth_sql == '' ) ? POSTS_TABLE : POSTS_TABLE . ' p';
504
505                     if ( $search_time )
506                     {
507                         $where_sql .= ( $search_author == '' && $auth_sql == '' ) ? " AND post_time >= $search_time " : " AND p.post_time >= $search_time";
508                     }
509
510                     if ( $auth_sql != '' )
511                     {
512                         $from_sql .= ", " . FORUMS_TABLE . " f";
513                         $where_sql .= " AND f.forum_id = p.forum_id AND $auth_sql";
514                     }
515
516                     if ( $search_author != '' )
517                     {
518                         $from_sql .= ", " . USERS_TABLE . " u";
519                         $where_sql .= " AND u.uid = p.poster_id AND u.name LIKE '$search_author'";
520                     }
521
522                     $sql = "SELECT " . $select_sql . "
523                         FROM $from_sql
524                         WHERE $where_sql";
525                     $result = $db->sql_query($sql);
526
527                     while( $row = $db->sql_fetchrow($result) )
528                     {
529                         $search_ids[] = $row['post_id'];
530                     }
531                     $db->sql_freeresult($result);
532                 }
533
534                 $total_match_count = count($search_ids);
535             }
536         }
537         else if ( $search_id == 'unanswered' )
538         {
539             if ( $auth_sql != '' )
540             {
541                 $sql = "SELECT t.topic_id, f.forum_id
542                     FROM " . TOPICS_TABLE . "  t, " . FORUMS_TABLE . " f
543                     WHERE t.topic_replies = 0
544                         AND t.forum_id = f.forum_id
545                         AND t.topic_moved_id = 0
546                         AND $auth_sql";
547             }
548             else
549             {
550                 $sql = "SELECT topic_id
551                     FROM " . TOPICS_TABLE . "
552                     WHERE topic_replies = 0
553                         AND topic_moved_id = 0";
554             }
555
556             $result = $db->sql_query($sql);
557
558             $search_ids = array();
559             while( $row = $db->sql_fetchrow($result) )
560             {
561                 $search_ids[] = $row['topic_id'];
562             }
563             $db->sql_freeresult($result);
564
565             $total_match_count = count($search_ids);
566
567             //
568             // Basic requirements
569             //
570             $show_results = 'topics';
571             $sort_by = 0;
572             $sort_dir = 'DESC';
573         }
574         else
575         {
576             trigger_error($lang['no_search_match']);
577             return;
578         }
579
580         //
581         // Store new result data
582         //
583         $search_results = implode(', ', $search_ids);
584         $per_page = ( $show_results == 'posts' ) ? $config['posts_per_page'] : $config['topics_per_page'];
585
586         //
587         // Combine both results and search data (apart from original query)
588         // so we can serialize it and place it in the DB
589         //
590         $store_search_data = array();
591
592         //
593         // Limit the character length (and with this the results displayed at all following pages) to prevent
594         // truncated result arrays. Normally, search results above 12000 are affected.
595         // - to include or not to include
596         /*
597         $max_result_length = 60000;
598         if (utf_strlen($search_results) > $max_result_length)
599         {
600             $search_results = substr($search_results, 0, $max_result_length);
601             $search_results = substr($search_results, 0, strrpos($search_results, ','));
602             $total_match_count = count(explode(', ', $search_results));
603         }
604         */
605
606         for($i = 0; $i < sizeof($store_vars); $i++)
607         {
608             $store_search_data[$store_vars[$i]] = $$store_vars[$i];
609         }
610
611         $result_array = serialize($store_search_data);
612         unset($store_search_data);
613
614         $search_id = md5(dss_rand());
615
616         $sql = "UPDATE " . SEARCH_TABLE . "
617             SET search_id = '" . $db->sql_escape($search_id) . "', search_time = $current_time, search_array = '" . $db->sql_escape($result_array) . "'
618             WHERE session_id = '" . $userdata['session_id'] . "'";
619         if ( !($result = $db->sql_query($sql)) || !$db->sql_affectedrows() )
620         {
621             $sql = "INSERT INTO " . SEARCH_TABLE . " (search_id, session_id, search_time, search_array)
622                 VALUES('" . $db->sql_escape($search_id) . "', '" . $userdata['session_id'] . "', $current_time, '" . $db->sql_escape($result_array) . "')";
623             $result = $db->sql_query($sql);
624         }
625     }
626     else
627     {
628         $search_id = intval($search_id);
629         if ( $search_id )
630         {
631             $sql = "SELECT search_array
632                 FROM " . SEARCH_TABLE . "
633                 WHERE search_id = '" . $db->sql_escape($search_id) . "'
634                     AND session_id = '". $userdata['session_id'] . "'";
635             $result = $db->sql_query($sql);
636
637             if ( $row = $db->sql_fetchrow($result) )
638             {
639                 $search_data = unserialize($row['search_array']);
640                 for($i = 0; $i < sizeof($store_vars); $i++)
641                 {
642                     $$store_vars[$i] = $search_data[$store_vars[$i]];
643                 }
644             }
645         }
646     }
647     //
648     // Look up data ...
649     //
650     if ( $search_results != '' )
651     {
652         if ( $show_results == 'posts' )
653         {
654             $sql = "SELECT pt.post_text, pt.post_subject, p.*, f.forum_id, f.forum_name, t.*, u.name AS username, u.uid, c.cat_id, c.cat_title, f2.forum_id AS p_forum_id, f2.forum_name AS p_forum_name
655                 FROM " . FORUMS_TABLE . " f LEFT JOIN " . FORUMS_TABLE . " f2 ON ( f.forum_parent = f2.forum_id ),
656     " . FORUM_CATEGORIES_TABLE . " c, " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TEXT_TABLE . " pt
657                 WHERE p.post_id IN ($search_results)
658                     AND pt.post_id = p.post_id
659                     AND f.forum_id = p.forum_id
660                     AND p.topic_id = t.topic_id
661                     AND p.poster_id = u.uid
662     AND f.cat_id = c.cat_id";
663         }
664         else
665         {
666             $sql = "SELECT t.*, f.forum_id, f.forum_name, u.name AS username, u.uid, u2.name as user2, u2.uid as id2, p.post_username, p2.post_username AS post_username2, p2.post_time, c.cat_id, c.cat_title, f2.forum_id AS p_forum_id, f2.forum_name AS p_forum_name
667                 FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f LEFT JOIN " . FORUMS_TABLE . " f2 ON ( f.forum_parent = f2.forum_id )," . FORUM_CATEGORIES_TABLE . " c, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
668                 WHERE t.topic_id IN ($search_results)
669                     AND t.topic_poster = u.uid
670                     AND f.forum_id = t.forum_id
671                     AND p.post_id = t.topic_first_post_id
672                     AND p2.post_id = t.topic_last_post_id
673                     AND u2.uid = p2.poster_id
674     AND f.cat_id = c.cat_id";
675         }
676
677         $per_page = ( $show_results == 'posts' ) ? $config['posts_per_page'] : $config['topics_per_page'];
678
679     /*if ($userdata['session_logged_in'])
680     {
681     if ($config['load_db_track'] && $author_id !== $userdata['uid'])
682     {
683     $sql_from .= ' LEFT JOIN ' . TOPICS_POSTED_TABLE . ' tp ON (tp.user_id = ' . $userdata['uid'] . '
684     AND t.topic_id = tp.topic_id)';
685     $sql_select .= ', tp.topic_posted';
686     }
687
688     if ($config['load_db_lastread'])
689     {
690     $sql_from .= ' LEFT JOIN ' . TOPICS_TRACK_TABLE . ' tt ON (tt.user_id = ' . $userdata['uid'] . '
691     AND t.topic_id = tt.topic_id)
692     LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $userdata['uid'] . '
693     AND ft.forum_id = f.forum_id)';
694     $sql_select .= ', tt.mark_time, ft.mark_time as f_mark_time';
695     }
696     }
697
698     if ($config['load_anon_lastread'] || ($userdata['session_logged_in'] && !$config['load_db_lastread']))
699     {*/
700     $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
701     $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
702     //}
703     $topic_tracking_info = array();
704
705         $sql .= " ORDER BY ";
706         switch ( $sort_by )
707         {
708             case 1:
709                 $sql .= ( $show_results == 'posts' ) ? 'pt.post_subject' : 't.topic_title';
710                 break;
711             case 2:
712                 $sql .= 't.topic_title';
713                 break;
714             case 3:
715                 $sql .= 'u.name';
716                 break;
717             case 4:
718                 $sql .= 'f.forum_id';
719                 break;
720             default:
721                 $sql .= ( $show_results == 'posts' ) ? 'p.post_time' : 'p2.post_time';
722                 break;
723         }
724
725         $sql .= ' ' . $sort_dir . ' LIMIT ' . $start . ', ' . $per_page;
726
727         $result = $db->sql_query($sql);
728
729         $searchset = array();
730         $forums = array();
731         while( $row = $db->sql_fetchrow($result) )
732         {
733             $searchset[] = $row;
734
735     $forums[$row['forum_id']]['topic_list'][] = $row['topic_id'];
736         }
737
738     foreach ($forums as $forum_id => $forum)
739     {
740     /*if ($userdata['session_logged_in'] && $config['load_db_lastread'])
741     {
742     $topic_tracking_info[$forum_id] = get_topic_tracking($forum_id, $forum['topic_list'], $forum['rowset'], array($forum_id => $forum['mark_time']), ($forum_id) ? false : $forum['topic_list']);
743     }
744     else if ($config['load_anon_lastread'] || $userdata['session_logged_in'])
745     {*/
746     $topic_tracking_info[$forum_id] = get_complete_topic_tracking($forum_id, $forum['topic_list'], ($forum_id) ? false : $forum['topic_list']);
747
748     if (!$userdata['session_logged_in'])
749     {
750     $userdata['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['onlinesince']) : 0;
751     }
752     //}
753     }
754     unset($forums);
755
756         $db->sql_freeresult($result);
757
758         //
759         // Define censored word matches
760         //
761         $orig_word = array();
762         $replacement_word = array();
763         $cache->obtain_word_list($orig_word, $replacement_word);
764
765         //
766         // Output header
767         //
768         stdhead($lang['forums'] . ' :: ' . $lang['search'], false);
769
770         if ( $show_results == 'posts' )
771         {
772             // Topic search MOD
773             if( !$tid )
774             {
775                 // End Topic search MOD
776                 $template->set_filenames(array(
777                     'body' => 'forum/search_results_posts.tpl')
778                 );
779             // Topic search MOD
780             }
781             else
782             {
783                 $template->set_filenames(array(
784                     'body' => 'forum/topic_search_results.tpl')
785                 );
786             }
787             // End Topic search MOD
788         }
789         else
790         {
791             $template->set_filenames(array(
792                 'body' => 'forum/search_results_topics.tpl')
793             );
794         }
795         //make_jumpbox('viewforum.'.$phpEx);
796         make_jumpbox('phpbb2.php?page=viewforum');
797
798         $l_search_matches = ( $total_match_count == 1 ) ? sprintf($lang['found_search_match'], $total_match_count) : sprintf($lang['found_search_matches'], $total_match_count);
799
800         $template->assign_vars(array(
801             'L_SEARCH_MATCHES' => $l_search_matches)
802         );
803
804         $highlight_active = '';
805         $highlight_match = array();
806         for($j = 0; $j < sizeof($split_search); $j++ )
807         {
808             $split_word = $split_search[$j];
809
810             if ( $split_word != 'and' && $split_word != 'or' && $split_word != 'not' )
811             {
812                 $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $split_word) . ')\b#is';
813                 $highlight_active .= " " . $split_word;
814
815                 for ($k = 0; $k < sizeof($synonym_array); $k++)
816                 {
817                     list($replace_synonym, $match_synonym) = split(' ', trim(utf_strtolower($synonym_array[$k])));
818
819                     if ( $replace_synonym == $split_word )
820                     {
821                         $highlight_match[] = '#\b(' . str_replace("*", "([\w]+)?", $replace_synonym) . ')\b#is';
822                         $highlight_active .= ' ' . $match_synonym;
823                     }
824                 }
825             }
826         }
827
828         $highlight_active = urlencode(trim($highlight_active));
829
830         for($i = 0; $i < sizeof($searchset); $i++)
831         {
832
833             $topic_title = $searchset[$i]['topic_title'];
834
835             $forum_id = $searchset[$i]['forum_id'];
836             $topic_id = $searchset[$i]['topic_id'];
837
838     // www.phpBB-SEO.com SEO TOOLKIT BEGIN
839     $seo->set_url($searchset[$i]['cat_id'], $searchset[$i]['cat_title'], $seo->seo_static['forum_cat']);
840
841     if ( !empty($searchset[$i]['p_forum_id']) ) {
842     $seo->set_parent($searchset[$i]['p_forum_id'], $seo->seo_static['forum'], $searchset[$i]['cat_id'], $seo->seo_static['forum_cat']);
843     $seo->set_url($searchset[$i]['p_forum_name'], $searchset[$i]['p_forum_id'], $seo->seo_static['forum']);
844     $seo->set_parent($forum_id, $seo->seo_static['forum'], $searchset[$i]['p_forum_id'], $seo->seo_static['forum']);
845     }
846     else {
847     $seo->set_parent($forum_id, $seo->seo_static['forum'], $searchset[$i]['cat_id'], $seo->seo_static['forum_cat']);
848     }
849     $seo->set_url($searchset[$i]['forum_name'], $forum_id, $seo->seo_static['forum']);
850
851     $seo->set_parent($topic_id, $seo->seo_static['topic'], $forum_id, $seo->seo_static['forum']);
852     $seo->set_url($topic_title, $topic_id, $seo->seo_static['topic']);
853
854     if ( $show_results != 'posts' ) {
855
856     $seo->set_user_url($searchset[$i]['username'], $searchset[$i]['uid']);
857     $seo->set_user_url($searchset[$i]['user2'], $searchset[$i]['id2']);
858     }
859     // www.phpBB-SEO.com SEO TOOLKIT END
860
861             //$forum_url = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . '=' . $searchset[$i]['forum_id']);
862             $forum_url = append_sid($root_path . "phpbb2.php?page=viewforum&amp;" . POST_FORUM_URL . '=' . $searchset[$i]['forum_id']);
863             //$topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . '=' . $searchset[$i]['topic_id'] . "&amp;highlight=$highlight_active");
864             $topic_url = append_sid($root_path . "phpbb2.php?page=viewtopic&amp;" . POST_TOPIC_URL . '=' . $searchset[$i]['topic_id'] . "&amp;highlight=$highlight_active");
865             //$post_url = append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $searchset[$i]['post_id'] . "&amp;highlight=$highlight_active") . '#' . $searchset[$i]['post_id'];
866
867             $post_date = create_date($searchset[$i]['post_time']);
868
869             if ( $show_results == 'posts' )
870             {
871                     $message = $searchset[$i]['post_text'];
872                     $post_url = append_sid($root_path . "phpbb2.php?page=viewtopic&amp;" . POST_POST_URL . '=' . $searchset[$i]['post_id'] . "&amp;highlight=$highlight_active") . '#' . $searchset[$i]['post_id'];
873
874                 if ( isset($return_chars) )
875                 {
876
877                     //
878                     // If the board has HTML off but the post has HTML
879                     // on then we process it, else leave it alone
880                     //
881                     if ( $return_chars != -1 )
882                     {
883                         $message = strip_tags($message);
884                         $message = preg_replace('/\[url\]|\[\/url\]/si', '', $message);
885                         $message = ( utf_strlen($message) > $return_chars ) ? substr($message, 0, $return_chars) . ' ...' : $message;
886                     }
887                     else
888                     {
889                         if ( !$config['allow_html'] )
890                         {
891                             if ( $searchset[$i]['enable_html'] )
892                             {
893                                 $message = preg_replace('#(<)([\/]?.*?)(>)#is', '&lt;\\2&gt;', $message);
894                             }
895                         }
896
897         $bb_code->parse($message);
898         $message = $bb_code->get_html();
899
900                         if ( $highlight_active )
901                         {
902                             if ( preg_match('/<.*>/', $message) )
903                             {
904                                 $message = preg_replace($highlight_match, '<!-- #sh -->\1<!-- #eh -->', $message);
905
906                                 $end_html = 0;
907                                 $start_html = 1;
908                                 $temp_message = '';
909                                 $message = ' ' . $message . ' ';
910
911                                 while( $start_html = strpos($message, '<', $start_html) )
912                                 {
913                                     $grab_length = $start_html - $end_html - 1;
914                                     $temp_message .= substr($message, $end_html + 1, $grab_length);
915
916                                     if ( $end_html = strpos($message, '>', $start_html) )
917                                     {
918                                         $length = $end_html - $start_html + 1;
919                                         $hold_string = substr($message, $start_html, $length);
920
921                                         if ( strrpos(' ' . $hold_string, '<') != 1 )
922                                         {
923                                             $end_html = $start_html + 1;
924                                             $end_counter = 1;
925
926                                             while ( $end_counter && $end_html < utf_strlen($message) )
927                                             {
928                                                 if ( substr($message, $end_html, 1) == '>' )
929                                                 {
930                                                     $end_counter--;
931                                                 }
932                                                 else if ( substr($message, $end_html, 1) == '<' )
933                                                 {
934                                                     $end_counter++;
935                                                 }
936
937                                                 $end_html++;
938                                             }
939
940                                             $length = $end_html - $start_html + 1;
941                                             $hold_string = substr($message, $start_html, $length);
942                                             $hold_string = str_replace('<!-- #sh -->', '', $hold_string);
943                                             $hold_string = str_replace('<!-- #eh -->', '', $hold_string);
944                                         }
945                                         else if ( $hold_string == '<!-- #sh -->' )
946                                         {
947                                             $hold_string = str_replace('<!-- #sh -->', '<span style="color:#' . $theme['fontcolor3'] . '"><b>', $hold_string);
948                                         }
949                                         else if ( $hold_string == '<!-- #eh -->' )
950                                         {
951                                             $hold_string = str_replace('<!-- #eh -->', '</b></span>', $hold_string);
952                                         }
953
954                                         $temp_message .= $hold_string;
955
956                                         $start_html += $length;
957                                     }
958                                     else
959                                     {
960                                         $start_html = utf_strlen($message);
961                                     }
962                                 }
963
964                                 $grab_length = utf_strlen($message) - $end_html - 1;
965                                 $temp_message .= substr($message, $end_html + 1, $grab_length);
966
967                                 $message = trim($temp_message);
968                             }
969                             else
970                             {
971                                 $message = preg_replace($highlight_match, '<span style="color:#' . $theme['fontcolor3'] . '"><b>\1</b></span>', $message);
972                             }
973                         }
974                     }
975
976                     $topic_title = censor_text($topic_title);
977                     $post_subject = ( $searchset[$i]['post_subject'] != '' ) ? censor_text($searchset[$i]['post_subject']) : $topic_title;
978                     $message = censor_text($message);
979
980                     $message = str_replace("\n", '<br />', $message);
981
982                 }
983
984                 $poster = ( $searchset[$i]['uid'] != ANONYMOUS ) ? '<a href="' . append_sid($root_path . "userdetails.php?id=" . $searchset[$i]['uid']) . '">' : '';
985                 $poster .= ( $searchset[$i]['uid'] != ANONYMOUS ) ? $searchset[$i]['username'] : ( ( $searchset[$i]['post_username'] != "" ) ? $searchset[$i]['post_username'] : $lang['guest'] );
986                 $poster .= ( $searchset[$i]['uid'] != ANONYMOUS ) ? '</a>' : '';
987
988                 /*if ( $userdata['session_logged_in'] && $searchset[$i]['post_time'] > $userdata['user_lastvisit'] )
989                 {
990                     $topic_last_read = 0;
991                     if ( !empty($tracking_topics[$topic_id]) && !empty($tracking_forums[$forum_id]) )
992                     {
993                         $topic_last_read = ( $tracking_topics[$topic_id] > $tracking_forums[$forum_id] ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
994                     }
995                     else if ( !empty($tracking_topics[$topic_id]) || !empty($tracking_forums[$forum_id]) )
996                     {
997                         $topic_last_read = ( !empty($tracking_topics[$topic_id]) ) ? $tracking_topics[$topic_id] : $tracking_forums[$forum_id];
998                     }
999
1000                     if ( $searchset[$i]['post_time'] > $topic_last_read )
1001                     {
1002                         $mini_post_img = $images['icon_minipost_new'];
1003                         $mini_post_alt = $lang['new_post'];
1004                     }
1005                     else
1006                     {
1007                         $mini_post_img = $images['icon_minipost'];
1008                         $mini_post_alt = $lang['post'];
1009                     }
1010                 }
1011                 else
1012                 {
1013                     $mini_post_img = $images['icon_minipost'];
1014                     $mini_post_alt = $lang['post'];
1015                 }*/
1016
1017                 $unread_topic = (isset($topic_tracking_info[$forum_id][$topic_id]) && $searchset[$i]['post_time'] > $topic_tracking_info[$forum_id][$topic_id]) ? true : false;
1018
1019                 if ( $unread_topic )
1020                     {
1021                         $mini_post_img = $images['icon_minipost_new'];
1022                         $mini_post_alt = $lang['new_post'];
1023                     }
1024                     else
1025                     {
1026                         $mini_post_img = $images['icon_minipost'];
1027                         $mini_post_alt = $lang['post'];
1028                     }
1029
1030                 $template->assign_block_vars("searchresults", array(
1031                     'TOPIC_TITLE' => $topic_title,
1032                     'FORUM_NAME' => $searchset[$i]['forum_name'],
1033                     'POST_SUBJECT' => $post_subject,
1034                     'POST_DATE' => $post_date,
1035                     'POSTER_NAME' => $poster,
1036                     'TOPIC_REPLIES' => $searchset[$i]['topic_replies'],
1037                     'TOPIC_VIEWS' => $searchset[$i]['topic_views'],
1038                     'MESSAGE' => $message,
1039                     'MINI_POST_IMG' => $mini_post_img,
1040
1041                     'L_MINI_POST_ALT' => $mini_post_alt,
1042
1043                     'U_POST' => $post_url,
1044                     'U_TOPIC' => $topic_url,
1045                     'U_FORUM' => $forum_url)
1046                 );
1047             }
1048             else
1049             {
1050                 $message = '';
1051
1052                 if ( count($orig_word) )
1053                 {
1054                     $topic_title = preg_replace($orig_word, $replacement_word, $searchset[$i]['topic_title']);
1055                 }
1056
1057                 $topic_type = $searchset[$i]['topic_type'];
1058
1059                 if ($topic_type == POST_ANNOUNCE)
1060                 {
1061                     $topic_type = $lang['topic_announcement'] . ' ';
1062                 }
1063                 else if ($topic_type == POST_STICKY)
1064                 {
1065                     $topic_type = $lang['topic_sticky'] . ' ';
1066                 }
1067                 else
1068                 {
1069                     $topic_type = '';
1070                 }
1071
1072                 if ( $searchset[$i]['topic_vote'] )
1073                 {
1074                     $topic_type .= $lang['topic_poll'] . ' ';
1075                 }
1076
1077                 $views = $searchset[$i]['topic_views'];
1078                 $replies = $searchset[$i]['topic_replies'];
1079
1080                 if ( ( $replies + 1 ) > $config['posts_per_page'] )
1081                 {
1082                     $total_pages = ceil( ( $replies + 1 ) / $config['posts_per_page'] );
1083                     //$goto_page = ' [ <img src="' . $images['icon_gotopost'] . '" alt="' . $lang['goto_page'] . '" title="' . $lang['goto_page'] . '" />' . $lang['goto_page'] . ': ';
1084                     $goto_page = ' [ <img src="' . $images['icon_gotopost'] . '" alt="' . $lang['goto_page'] . '" title="' . $lang['goto_page'] . '" />' . $lang['goto_page'] . ': ';
1085
1086                     $times = 1;
1087                     for($j = 0; $j < $replies + 1; $j += $config['posts_per_page'])
1088                     {
1089                         //$goto_page .= '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $topic_id . "&amp;start=$j") . '">' . $times . '</a>';
1090                         $goto_page .= '<a href="' . append_sid($root_path . "phpbb2.php?page=viewtopic&amp;" . POST_TOPIC_URL . "=" . $topic_id . "&amp;start=$j") . '">' . $times . '</a>';
1091                         if ( $times == 1 && $total_pages > 4 )
1092                         {
1093                             $goto_page .= ' ... ';
1094                             $times = $total_pages - 3;
1095                             $j += ( $total_pages - 4 ) * $config['posts_per_page'];
1096                         }
1097                         else if ( $times < $total_pages )
1098                         {
1099                             $goto_page .= ', ';
1100                         }
1101                         $times++;
1102                     }
1103                     $goto_page .= ' ] ';
1104                 }
1105                 else
1106                 {
1107                     $goto_page = '';
1108                 }
1109
1110                 if ( $searchset[$i]['topic_status'] == TOPIC_MOVED )
1111                 {
1112                     $topic_type = $lang['topic_moved'] . ' ';
1113                     $topic_id = $searchset[$i]['topic_moved_id'];
1114
1115                     //$folder_image = '<img src="' . $images['folder'] . '" alt="' . $lang['no_new_posts'] . '" />';
1116                     $folder_image = '<img src="' . $images['folder'] . '" alt="' . $lang['no_new_posts'] . '" />';
1117                     $newest_post_img = '';
1118                 }
1119                 else
1120                 {
1121                     if ( $searchset[$i]['topic_status'] == TOPIC_LOCKED )
1122                     {
1123                         $folder = $images['folder_locked'];
1124                         $folder_new = $images['folder_locked_new'];
1125                     }
1126                     else if ( $searchset[$i]['topic_type'] == POST_ANNOUNCE )
1127                     {
1128                         $folder = $images['folder_announce'];
1129                         $folder_new = $images['folder_announce_new'];
1130                     }
1131                     else if ( $searchset[$i]['topic_type'] == POST_STICKY )
1132                     {
1133                         $folder = $images['folder_sticky'];
1134                         $folder_new = $images['folder_sticky_new'];
1135                     }
1136                     else
1137                     {
1138                         if ( $replies >= $config['hot_threshold'] )
1139                         {
1140                             $folder = $images['folder_hot'];
1141                             $folder_new = $images['folder_hot_new'];
1142                         }
1143                         else
1144                         {
1145                             $folder = $images['folder'];
1146                             $folder_new = $images['folder_new'];
1147                         }
1148                     }
1149
1150                     /*if ( $userdata['session_logged_in'] )
1151                     {
1152                         if ( $searchset[$i]['post_time'] > $userdata['user_lastvisit'] )
1153                         {
1154                             if ( !empty($tracking_topics) || !empty($tracking_forums) || isset($_COOKIE[$config['cookie_name'] . '_f_all']) )
1155                             {
1156
1157                                 $unread_topics = true;
1158
1159                                 if ( !empty($tracking_topics[$topic_id]) )
1160                                 {
1161                                     if ( $tracking_topics[$topic_id] > $searchset[$i]['post_time'] )
1162                                     {
1163                                         $unread_topics = false;
1164                                     }
1165                                 }
1166
1167                                 if ( !empty($tracking_forums[$forum_id]) )
1168                                 {
1169                                     if ( $tracking_forums[$forum_id] > $searchset[$i]['post_time'] )
1170                                     {
1171                                         $unread_topics = false;
1172                                     }
1173                                 }
1174
1175                                 if ( isset($_COOKIE[$config['cookie_name'] . '_f_all']) )
1176                                 {
1177                                     if ( $_COOKIE[$config['cookie_name'] . '_f_all'] > $searchset[$i]['post_time'] )
1178                                     {
1179                                         $unread_topics = false;
1180                                     }
1181                                 }*/
1182
1183                                 $unread_topics = (isset($topic_tracking_info[$forum_id][$topic_id]) && $searchset[$i]['post_time'] > $topic_tracking_info[$forum_id][$topic_id]) ? true : false;
1184
1185                                 if ( $unread_topics )
1186                                 {
1187                                     $folder_image = $folder_new;
1188                                     $folder_alt = $lang['new_posts'];
1189
1190                                     //$newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['view_newest_post'] . '" title="' . $lang['view_newest_post'] . '" border="0" /></a> ';
1191                                     $newest_post_img = '<a href="' . append_sid($root_path . "phpbb2.php?page=viewtopic&amp;" . POST_TOPIC_URL . "=$topic_id&amp;view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['view_newest_post'] . '" title="' . $lang['view_newest_post'] . '" border="0" /></a> ';
1192                                 }
1193                                 else
1194                                 {
1195                                     $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['topic_locked'] : $lang['no_new_posts'];
1196
1197                                     $folder_image = $folder;
1198                                     $folder_alt = $folder_alt;
1199                                     $newest_post_img = '';
1200                                 }
1201
1202                             /*}
1203                             else if ( $searchset[$i]['post_time'] > $userdata['user_lastvisit'] )
1204                             {
1205                                 $folder_image = $folder_new;
1206                                 $folder_alt = $lang['new_posts'];
1207
1208                                 //$newest_post_img = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['view_newest_post'] . '" title="' . $lang['view_newest_post'] . '" border="0" /></a> ';
1209                                 $newest_post_img = '<a href="' . append_sid($root_path . "phpbb2.php?page=viewtopic&amp;" . POST_TOPIC_URL . "=$topic_id&amp;view=newest") . '"><img src="' . $images['icon_newest_reply'] . '" alt="' . $lang['view_newest_post'] . '" title="' . $lang['view_newest_post'] . '" border="0" /></a> ';
1210                             }
1211                             else
1212                             {
1213                                 $folder_image = $folder;
1214                                 $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['topic_locked'] : $lang['no_new_posts'];
1215                                 $newest_post_img = '';
1216                             }
1217                         }
1218                         else
1219                         {
1220                             $folder_image = $folder;
1221                             $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['topic_locked'] : $lang['no_new_posts'];
1222                             $newest_post_img = '';
1223                         }
1224                     }
1225                     else
1226                     {
1227                         $folder_image = $folder;
1228                         $folder_alt = ( $searchset[$i]['topic_status'] == TOPIC_LOCKED ) ? $lang['topic_locked'] : $lang['no_new_posts'];
1229                         $newest_post_img = '';
1230                     }*/
1231                 }
1232
1233
1234                 $topic_author = ( $searchset[$i]['uid'] != ANONYMOUS ) ? '<a href="' . append_sid($root_path . "userdetails.php?id=" . $searchset[$i]['uid']) . '">' : '';
1235                 $topic_author .= ( $searchset[$i]['uid'] != ANONYMOUS ) ? $searchset[$i]['username'] : ( ( $searchset[$i]['post_username'] != '' ) ? $searchset[$i]['post_username'] : $lang['guest'] );
1236
1237                 $topic_author .= ( $searchset[$i]['uid'] != ANONYMOUS ) ? '</a>' : '';
1238
1239                 $first_post_time = create_date($searchset[$i]['topic_time']);
1240
1241                 $last_post_time = create_date($searchset[$i]['post_time']);
1242
1243                 $last_post_author = ( $searchset[$i]['id2'] == ANONYMOUS ) ? ( ($searchset[$i]['post_username2'] != '' ) ? $searchset[$i]['post_username2'] . ' ' : $lang['guest'] . ' ' ) : '<a href="' . append_sid($root_path . "userdetails.php?id="  . $searchset[$i]['id2']) . '">' . $searchset[$i]['user2'] . '</a>';
1244
1245                 $last_post_url = '<a href="' . append_sid($root_path . "phpbb2.php?page=viewtopic&amp;"  . POST_POST_URL . '=' . $searchset[$i]['topic_last_post_id']) . '#' . $searchset[$i]['topic_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" alt="' . $lang['view_latest_post'] . '" title="' . $lang['view_latest_post'] . '" border="0" /></a>';
1246
1247                 $template->assign_block_vars('searchresults', array(
1248                     'FORUM_NAME' => $searchset[$i]['forum_name'],
1249                     'FORUM_ID' => $forum_id,
1250                     'TOPIC_ID' => $topic_id,
1251                     'FOLDER' => $folder_image,
1252                     'NEWEST_POST_IMG' => $newest_post_img,
1253                     'TOPIC_FOLDER_IMG' => $folder_image,
1254                     'GOTO_PAGE' => $goto_page,
1255                     'REPLIES' => $replies,
1256                     'TOPIC_TITLE' => $topic_title,
1257                     'TOPIC_TYPE' => $topic_type,
1258                     'VIEWS' => $views,
1259                     'TOPIC_AUTHOR' => $topic_author,
1260                     'FIRST_POST_TIME' => $first_post_time,
1261                     'LAST_POST_TIME' => $last_post_time,
1262                     'LAST_POST_AUTHOR' => $last_post_author,
1263                     'LAST_POST_IMG' => $last_post_url,
1264
1265                     'L_TOPIC_FOLDER_ALT' => $folder_alt,
1266
1267                     'U_VIEW_FORUM' => $forum_url,
1268                     'U_VIEW_TOPIC' => $topic_url)
1269                 );
1270             }
1271         }
1272         // Topic search MOD
1273         if( !$tid )
1274         {
1275         // End Topic search MOD
1276             $base_url = "phpbb2.php?page=search&amp;search_id=$search_id&amp;search_author=$search_author";
1277         // Topic search MOD
1278         }
1279         else
1280         {
1281             $base_url = "phpbb2.php?page=search&amp;search_id=$search_id&amp;topic_id=$tid";
1282         }
1283         // End Topic search MOD
1284
1285         $template->assign_vars(array(
1286             'PAGINATION' => generate_pagination($root_path . $base_url, $total_match_count, $per_page, $start),
1287             'PAGE_NUMBER' => sprintf($lang['page_of'], ( floor( $start / $per_page ) + 1 ), ceil( $total_match_count / $per_page )),
1288         ));
1289         return;
1290     }
1291     else
1292     {
1293         trigger_error($lang['no_search_match']);
1294         return;
1295     }
1296 }
1297
1298 //</span>
1299 <span class="code-comment">// Search forum
1300 //
1301 $sql = "SELECT c.cat_title, c.cat_id, f.forum_name, f.forum_id, f.forum_parent</span>
1302 <span class="code-lang">    FROM " . FORUM_CATEGORIES_TABLE . " c, " . FORUMS_TABLE . " f
1303     WHERE f.cat_id = c.cat_id
1304     ORDER BY c.cat_order, f.forum_order";
1305 $result = $db->sql_query($sql);
1306 $is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata);
1307
1308 $s_forums = '';
1309 $list = array();</span>
1310 <span class="code-lang">while( $row = $db->sql_fetchrow($result) )
1311 {
1312     if ( $is_auth_ary[$row['forum_id']]['auth_read'] )
1313     {
1314         $list[] = $row;
1315     }
1316 }
1317
1318 for( $i = 0; $i < count($list); $i++ )
1319 {
1320     if( !$list[$i]['forum_parent'] )
1321     {
1322     $row = $list[$i];
1323         $s_forums .= '<option value="' . $row['forum_id'] . '">' . $row['forum_name'] . '</option>';
1324         if ( empty($list_cat[$row['cat_id']]) )
1325         {
1326             $list_cat[$row['cat_id']] = $row['cat_title'];
1327         }
1328         $parent_id = $row['forum_id'];
1329     for( $j = 0; $j < count($list); $j++ )
1330     {
1331     if( $list[$j]['forum_parent'] == $parent_id )
1332     {
1333     $row = $list[$j];
1334     $s_forums .= '<option value="' . $row['forum_id'] . '">-- ' . $row['forum_name'] . '</option>';
1335     }
1336     }
1337     }
1338 }
1339
1340 if ( $s_forums != '' )
1341 {
1342     $s_forums = '<option value="-1">' . $lang['all_available'] . '</option>' . $s_forums;
1343
1344     //
1345     // Category to search
1346     //
1347     $s_categories = '<option value="-1">' . $lang['all_available'] . '</option>';
1348     while( list($cat_id, $cat_title) = @each($list_cat))
1349     {
1350         $s_categories .= '<option value="' . $cat_id . '">' . $cat_title . '</option>';
1351     }
1352 }
1353 else
1354 {
1355     trigger_error($lang['no_searchable_forums']);
1356     return;
1357 }
1358
1359 //</span>
1360 <span class="code-comment">// Number of chars returned
1361 //
1362 $s_characters = '<option value="-1">' . $lang['all_available'] . '</option>';
1363 $s_characters .= '<option value="0">0</option>';
1364 $s_characters .= '<option value="25">25</option>';
1365 $s_characters .= '<option value="50">50</option>';</span>
1366 <span class="code-lang">
1367 for($i = 100; $i < 1100 ; $i += 100)
1368 {
1369     $selected = ( $i == 200 ) ? ' selected="selected"' : '';
1370     $s_characters .= '<option value="' . $i . '"' . $selected . '>' . $i . '</option>';
1371 }
1372
1373 //</span>
1374 <span class="code-comment">// Sorting
1375 //
1376 $s_sort_by = "";</span>
1377 <span class="code-lang">for($i = 0; $i < count($sort_by_types); $i++)
1378 {
1379     $s_sort_by .= '<option value="' . $i . '">' . $sort_by_types[$i] . '</option>';
1380 }
1381
1382 //</span>
1383 <span class="code-comment">// Search time
1384 //
1385 $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
1386 $previous_days_text = array($lang['all_posts'], $lang['1_day'], $lang['7_days'], $lang['2_weeks'], $lang['1_month'], $lang['3_months'], $lang['6_months'], $lang['1_year']);
1387
1388 $s_time = '';</span>
1389 <span class="code-lang">for($i = 0; $i < count($previous_days); $i++)
1390 {
1391     $selected = ( $topic_days == $previous_days[$i] ) ? ' selected="selected"' : '';
1392     $s_time .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
1393 }
1394
1395 //</span>
1396 <span class="code-comment">// Output the basic page
1397 //
1398 stdhead($lang['forums'] . ' :: ' . $lang['search'], false);
1399
1400 $template->set_filenames(array(</span>
1401 <span class="code-lang">    'body' => 'forum/search_body.tpl')
1402 );
1403 //make_jumpbox('viewforum.'.$phpEx);
1404 make_jumpbox('phpbb2.php?page=viewforum');
1405
1406 $template->assign_vars(array(</span>
1407 <span class="code-lang">    'L_SEARCH_ANY_TERMS' => $lang['search_for_any'],
1408     'L_SEARCH_ALL_TERMS' => $lang['search_for_all'],
1409     'L_SEARCH_MESSAGE_ONLY' => $lang['search_msg_only'],
1410     'L_SEARCH_MESSAGE_TITLE' => $lang['search_title_msg'],
1411     'L_CHARACTERS' => $lang['characters_posts'],
1412
1413     //'S_SEARCH_ACTION' => append_sid("search.$phpEx?mode=results"),
1414     'S_SEARCH_ACTION' => append_sid($root_path . 'phpbb2.php?page=search&amp;mode=results'),
1415     'S_CHARACTER_OPTIONS' => $s_characters,
1416     'S_FORUM_OPTIONS' => $s_forums,
1417     'S_CATEGORY_OPTIONS' => $s_categories,
1418     'S_TIME_OPTIONS' => $s_time,
1419     'S_SORT_OPTIONS' => $s_sort_by,
1420     'S_HIDDEN_FIELDS' => '')
1421 );
1422
1423 return;
1424
1425 ?>
Note: See TracBrowser for help on using the browser.