PHP-Nuke PHP Cross Reference Web Portal Systems

Source: /modules/Forums/search.php - 1444 lines - 45894 bytes - Summary - Text - Print

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

title

Description

title

Description

title

Description

title

title

Body