[ Index ]

PHP Cross Reference of MyBB 1.4.13

title

Body

[close]

/ -> search.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.4
   4   * Copyright © 2008 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybboard.net
   7   * License: http://www.mybboard.net/about/license
   8   *
   9   * $Id: search.php 4505 2009-11-13 15:59:56Z Tomm $
  10   */
  11  
  12  
  13  define("IN_MYBB", 1);
  14  define("IGNORE_CLEAN_VARS", "sid");
  15  define('THIS_SCRIPT', 'search.php');
  16  
  17  $templatelist = "search,forumdisplay_thread_gotounread,search_results_threads_thread,search_results_threads,search_results_posts,search_results_posts_post";
  18  $templatelist .= ",multipage_nextpage,multipage_page_current,multipage_page,multipage_start,multipage_end,multipage,forumdisplay_thread_multipage_more,forumdisplay_thread_multipage_page,forumdisplay_thread_multipage";
  19  $templatelist .= ",search_results_posts_inlinecheck,search_results_posts_nocheck,search_results_threads_inlinecheck,search_results_threads_nocheck,search_results_inlinemodcol,search_results_posts_inlinemoderation_custom_tool,search_results_posts_inlinemoderation_custom,search_results_posts_inlinemoderation,search_results_threads_inlinemoderation_custom_tool,search_results_threads_inlinemoderation_custom,search_results_threads_inlinemoderation,search_orderarrow";
  20  require_once  "./global.php";
  21  require_once  MYBB_ROOT."inc/functions_post.php";
  22  require_once  MYBB_ROOT."inc/functions_search.php";
  23  require_once  MYBB_ROOT."inc/class_parser.php";
  24  $parser = new postParser;
  25  
  26  // Load global language phrases
  27  $lang->load("search");
  28  
  29  add_breadcrumb($lang->nav_search, "search.php");
  30  
  31  switch($mybb->input['action'])
  32  {
  33      case "results":
  34          add_breadcrumb($lang->nav_results);
  35          break;
  36      default:
  37          break;
  38  }
  39  
  40  if($mybb->usergroup['cansearch'] == 0)
  41  {
  42      error_no_permission();
  43  }
  44  
  45  $now = TIME_NOW;
  46  $mybb->input['keywords'] = trim($mybb->input['keywords']);
  47  
  48  $limitsql = "";
  49  if(intval($mybb->settings['searchhardlimit']) > 0)
  50  {
  51      $limitsql = "ORDER BY t.dateline DESC LIMIT ".intval($mybb->settings['searchhardlimit']);
  52  }
  53  
  54  if($mybb->input['action'] == "results")
  55  {
  56      $sid = $db->escape_string($mybb->input['sid']);
  57      $query = $db->simple_select("searchlog", "*", "sid='$sid'");
  58      $search = $db->fetch_array($query);
  59  
  60      if(!$search['sid'])
  61      {
  62          error($lang->error_invalidsearch);
  63      }
  64  
  65      $plugins->run_hooks("search_results_start");
  66  
  67      // Decide on our sorting fields and sorting order.
  68      $order = my_strtolower(htmlspecialchars($mybb->input['order']));
  69      $sortby = my_strtolower(htmlspecialchars($mybb->input['sortby']));
  70  
  71      switch($sortby)
  72      {
  73          case "replies":
  74              $sortfield = "t.replies";
  75              break;
  76          case "views":
  77              $sortfield = "t.views";
  78              break;
  79          case "subject":
  80              if($search['resulttype'] == "threads")
  81              {
  82                  $sortfield = "t.subject";
  83              }
  84              else
  85              {
  86                  $sortfield = "p.subject";
  87              }
  88              break;
  89          case "forum":
  90              $sortfield = "t.fid";
  91              break;
  92          case "starter":
  93              if($search['resulttype'] == "threads")
  94              {
  95                  $sortfield = "t.username";
  96              }
  97              else
  98              {
  99                  $sortfield = "p.username";
 100              }
 101              break;
 102          case "lastpost":
 103          default:
 104              if($search['resulttype'] == "threads")
 105              {
 106                  $sortfield = "t.lastpost";
 107                  $sortby = "lastpost";
 108              }
 109              else
 110              {
 111                  $sortfield = "p.dateline";
 112                  $sortby = "dateline";
 113              }
 114              break;
 115      }
 116      
 117      if($order != "asc")
 118      {
 119          $order = "desc";
 120          $oppsortnext = "asc";
 121          $oppsort = $lang->asc;
 122      }
 123      else
 124      {
 125          $oppsortnext = "desc";
 126          $oppsort = $lang->desc;        
 127      }
 128      
 129      if(!$mybb->settings['threadsperpage'])
 130      {
 131          $mybb->settings['threadsperpage'] = 20;
 132      }
 133  
 134      // Work out pagination, which page we're at, as well as the limits.
 135      $perpage = $mybb->settings['threadsperpage'];
 136      $page = intval($mybb->input['page']);
 137      if($page > 0)
 138      {
 139          $start = ($page-1) * $perpage;
 140      }
 141      else
 142      {
 143          $start = 0;
 144          $page = 1;
 145      }
 146      $end = $start + $perpage;
 147      $lower = $start+1;
 148      $upper = $end;
 149      
 150      // Work out if we have terms to highlight
 151      $highlight = "";
 152      if($search['keywords'])
 153      {
 154          if($mybb->settings['seourls'] == "yes" || ($mybb->settings['seourls'] == "auto" && $_SERVER['SEO_SUPPORT'] == 1))
 155          {
 156              $highlight = "?highlight=".urlencode($search['keywords']);
 157          }
 158          else
 159          {
 160              $highlight = "&amp;highlight=".urlencode($search['keywords']);
 161          }
 162      }
 163  
 164      $sorturl = "search.php?action=results&amp;sid={$sid}";
 165      $thread_url = "";
 166      $post_url = "";
 167      
 168      eval("\$orderarrow['$sortby'] = \"".$templates->get("search_orderarrow")."\";");
 169  
 170      // Read some caches we will be using
 171      $forumcache = $cache->read("forums");
 172      $icon_cache = $cache->read("posticons");
 173  
 174      $threads = array();
 175  
 176      if($mybb->user['uid'] == 0)
 177      {
 178          // Build a forum cache.
 179          $query = $db->query("
 180              SELECT fid
 181              FROM ".TABLE_PREFIX."forums
 182              WHERE active != 0
 183              ORDER BY pid, disporder
 184          ");
 185          
 186          $forumsread = unserialize($mybb->cookies['mybb']['forumread']);
 187      }
 188      else
 189      {
 190          // Build a forum cache.
 191          $query = $db->query("
 192              SELECT f.fid, fr.dateline AS lastread
 193              FROM ".TABLE_PREFIX."forums f
 194              LEFT JOIN ".TABLE_PREFIX."forumsread fr ON (fr.fid=f.fid AND fr.uid='{$mybb->user['uid']}')
 195              WHERE f.active != 0
 196              ORDER BY pid, disporder
 197          ");
 198      }
 199      while($forum = $db->fetch_array($query))
 200      {
 201          if($mybb->user['uid'] == 0)
 202          {
 203              if($forumsread[$forum['fid']])
 204              {
 205                  $forum['lastread'] = $forumsread[$forum['fid']];
 206              }
 207          }
 208          $readforums[$forum['fid']] = $forum['lastread'];
 209      }
 210      $fpermissions = forum_permissions();
 211      
 212      // Inline Mod Column for moderators
 213      $inlinemodcol = $inlinecookie = '';
 214      $is_mod = $is_supermod = false;
 215      if($mybb->usergroup['issupermod'])
 216      {
 217          $is_supermod = true;
 218      }
 219      if($is_supermod || is_moderator())
 220      {
 221          eval("\$inlinemodcol = \"".$templates->get("search_results_inlinemodcol")."\";");
 222          $inlinecookie = "inlinemod_search".$sid;
 223          $inlinecount = 0;
 224          $is_mod = true;
 225          $return_url = 'search.php?'.htmlspecialchars_uni($_SERVER['QUERY_STRING']);
 226      }
 227  
 228      // Show search results as 'threads'
 229      if($search['resulttype'] == "threads")
 230      {
 231          $threadcount = 0;
 232          
 233          // Moderators can view unapproved threads
 234          $query = $db->simple_select("moderators", "fid", "uid='{$mybb->user['uid']}'");
 235          if($mybb->usergroup['issupermod'] == 1)
 236          {
 237              // Super moderators (and admins)
 238              $unapproved_where = "t.visible>-1";
 239          }
 240          elseif($db->num_rows($query))
 241          {
 242              // Normal moderators
 243              $moderated_forums = '0';
 244              while($forum = $db->fetch_array($query))
 245              {
 246                  $moderated_forums .= ','.$forum['fid'];
 247              }
 248              $unapproved_where = "(t.visible>0 OR (t.visible=0 AND t.fid IN ({$moderated_forums})))";
 249          }
 250          else
 251          {
 252              // Normal users
 253              $unapproved_where = 't.visible>0';
 254          }
 255          
 256          // If we have saved WHERE conditions, execute them
 257          if($search['querycache'] != "")
 258          {
 259              $where_conditions = $search['querycache'];
 260              $query = $db->simple_select("threads t", "t.tid", $where_conditions. " AND {$unapproved_where} AND t.closed NOT LIKE 'moved|%' {$limitsql}");
 261              while($thread = $db->fetch_array($query))
 262              {
 263                  $threads[$thread['tid']] = $thread['tid'];
 264                  $threadcount++;
 265              }
 266              // Build our list of threads.
 267              if($threadcount > 0)
 268              {
 269                  $search['threads'] = implode(",", $threads);
 270              }
 271              // No results.
 272              else
 273              {
 274                  error($lang->error_nosearchresults);
 275              }
 276              $where_conditions = "t.tid IN (".$search['threads'].")";
 277          }
 278          // This search doesn't use a query cache, results stored in search table.
 279          else
 280          {
 281              $where_conditions = "t.tid IN (".$search['threads'].")";
 282              $query = $db->simple_select("threads t", "COUNT(t.tid) AS resultcount", $where_conditions. " AND {$unapproved_where} AND t.closed NOT LIKE 'moved|%' {$limitsql}");
 283              $count = $db->fetch_array($query);
 284  
 285              if(!$count['resultcount'])
 286              {
 287                  error($lang->error_nosearchresults);
 288              }
 289              $threadcount = $count['resultcount'];
 290          }
 291          // Begin selecting matching threads, cache them.
 292          $sqlarray = array(
 293              'order_by' => $sortfield,
 294              'order_dir' => $order,
 295              'limit_start' => $start,
 296              'limit' => $perpage
 297          );
 298          $query = $db->query("
 299              SELECT t.*, u.username AS userusername
 300              FROM ".TABLE_PREFIX."threads t
 301              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
 302              WHERE $where_conditions AND {$unapproved_where} AND t.closed NOT LIKE 'moved|%'
 303              ORDER BY $sortfield $order
 304              LIMIT $start, $perpage
 305          ");
 306          $thread_cache = array();
 307          while($thread = $db->fetch_array($query))
 308          {
 309              $thread_cache[$thread['tid']] = $thread;
 310          }
 311          $thread_ids = implode(",", array_keys($thread_cache));
 312  
 313  
 314          // Fetch dot icons if enabled
 315          if($mybb->settings['dotfolders'] != 0 && $mybb->user['uid'] && $thread_cache)
 316          {
 317              $query = $db->simple_select("posts", "DISTINCT tid,uid", "uid='".$mybb->user['uid']."' AND tid IN(".$thread_ids.")"); // Why are we querying the posts table?
 318              while($post = $db->fetch_array($query))
 319              {
 320                  $thread_cache[$post['tid']]['dot_icon'] = 1;
 321              }
 322          }
 323  
 324          // Fetch the read threads.
 325          if($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0)
 326          {
 327              $query = $db->simple_select("threadsread", "tid,dateline", "uid='".$mybb->user['uid']."' AND tid IN(".$thread_ids.")");
 328              while($readthread = $db->fetch_array($query))
 329              {
 330                  $thread_cache[$readthread['tid']]['lastread'] = $readthread['dateline'];
 331              }
 332          }
 333  
 334          foreach($thread_cache as $thread)
 335          {
 336              $bgcolor = alt_trow();
 337              $folder = '';
 338              $prefix = '';
 339              
 340              // Unapproved colour
 341              if(!$thread['visible'])
 342              {
 343                  $bgcolor = 'trow_shaded';
 344              }
 345  
 346              if($thread['userusername'])
 347              {
 348                  $thread['username'] = $thread['userusername'];
 349              }
 350              $thread['profilelink'] = build_profile_link($thread['username'], $thread['uid']);
 351  
 352              $thread['subject'] = $parser->parse_badwords($thread['subject']);
 353              $thread['subject'] = htmlspecialchars_uni($thread['subject']);
 354  
 355              if($icon_cache[$thread['icon']])
 356              {
 357                  $posticon = $icon_cache[$thread['icon']];
 358                  $icon = "<img src=\"".$posticon['path']."\" alt=\"".$posticon['name']."\" />";
 359              }
 360              else
 361              {
 362                  $icon = "&nbsp;";
 363              }
 364              if($thread['poll'])
 365              {
 366                  $prefix = $lang->poll_prefix;
 367              }
 368                  
 369              // Determine the folder
 370              $folder = '';
 371              $folder_label = '';
 372              if($thread['dot_icon'])
 373              {
 374                  $folder = "dot_";
 375                  $folder_label .= $lang->icon_dot;
 376              }
 377              $gotounread = '';
 378              $isnew = 0;
 379              $donenew = 0;
 380              $last_read = 0;
 381              
 382              if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'])
 383              {
 384                  $forum_read = $readforums[$thread['fid']];
 385              
 386                  $read_cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
 387                  if($forum_read == 0 || $forum_read < $read_cutoff)
 388                  {
 389                      $forum_read = $read_cutoff;
 390                  }
 391              }
 392              else
 393              {
 394                  $forum_read = $forumsread[$thread['fid']];
 395              }
 396              
 397              if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $thread['lastpost'] > $forum_read)
 398              {
 399                  if($thread['lastread'])
 400                  {
 401                      $last_read = $thread['lastread'];
 402                  }
 403                  else
 404                  {
 405                      $last_read = $read_cutoff;
 406                  }
 407              }
 408              else
 409              {
 410                  $last_read = my_get_array_cookie("threadread", $thread['tid']);
 411              }
 412      
 413              if($forum_read > $last_read)
 414              {
 415                  $last_read = $forum_read;
 416              }
 417  
 418              if($thread['lastpost'] > $last_read && $last_read)
 419              {
 420                  $folder .= "new";
 421                  $new_class = "subject_new";
 422                  $folder_label .= $lang->icon_new;
 423                  $thread['newpostlink'] = get_thread_link($thread['tid'], 0, "newpost").$highlight;
 424                  eval("\$gotounread = \"".$templates->get("forumdisplay_thread_gotounread")."\";");
 425                  $unreadpost = 1;
 426              }
 427              else
 428              {
 429                  $new_class = '';
 430                  $folder_label .= $lang->icon_no_new;
 431              }
 432  
 433              if($thread['replies'] >= $mybb->settings['hottopic'] || $thread['views'] >= $mybb->settings['hottopicviews'])
 434              {
 435                  $folder .= "hot";
 436                  $folder_label .= $lang->icon_hot;
 437              }
 438              if($thread['closed'] == 1)
 439              {
 440                  $folder .= "lock";
 441                  $folder_label .= $lang->icon_lock;
 442              }
 443              $folder .= "folder";
 444              
 445              if(!$mybb->settings['postsperpage'])
 446              {
 447                  $mybb->settings['postperpage'] = 20;
 448              }
 449  
 450              $thread['pages'] = 0;
 451              $thread['multipage'] = '';
 452              $threadpages = '';
 453              $morelink = '';
 454              $thread['posts'] = $thread['replies'] + 1;
 455              if($thread['posts'] > $mybb->settings['postsperpage'])
 456              {
 457                  $thread['pages'] = $thread['posts'] / $mybb->settings['postsperpage'];
 458                  $thread['pages'] = ceil($thread['pages']);
 459                  if($thread['pages'] > 4)
 460                  {
 461                      $pagesstop = 4;
 462                      $page_link = get_thread_link($thread['tid'], $thread['pages']).$highlight;
 463                      eval("\$morelink = \"".$templates->get("forumdisplay_thread_multipage_more")."\";");
 464                  }
 465                  else
 466                  {
 467                      $pagesstop = $thread['pages'];
 468                  }
 469                  for($i = 1; $i <= $pagesstop; ++$i)
 470                  {
 471                      $page_link = get_thread_link($thread['tid'], $i).$highlight;
 472                      eval("\$threadpages .= \"".$templates->get("forumdisplay_thread_multipage_page")."\";");
 473                  }
 474                  eval("\$thread['multipage'] = \"".$templates->get("forumdisplay_thread_multipage")."\";");
 475              }
 476              else
 477              {
 478                  $threadpages = '';
 479                  $morelink = '';
 480                  $thread['multipage'] = '';
 481              }
 482              $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
 483              $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
 484              $lastposter = $thread['lastposter'];
 485              $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
 486              $lastposteruid = $thread['lastposteruid'];
 487              $thread_link = get_thread_link($thread['tid']);
 488  
 489              // Don't link to guest's profiles (they have no profile).
 490              if($lastposteruid == 0)
 491              {
 492                  $lastposterlink = $lastposter;
 493              }
 494              else
 495              {
 496                  $lastposterlink = build_profile_link($lastposter, $lastposteruid);
 497              }
 498  
 499              $thread['replies'] = my_number_format($thread['replies']);
 500              $thread['views'] = my_number_format($thread['views']);
 501  
 502              if($forumcache[$thread['fid']])
 503              {
 504                  $thread['forumlink'] = "<a href=\"".get_forum_link($thread['fid'])."\">".$forumcache[$thread['fid']]['name']."</a>";
 505              }
 506              else
 507              {
 508                  $thread['forumlink'] = "";
 509              }
 510  
 511              // If this user is the author of the thread and it is not closed or they are a moderator, they can edit
 512              if(($thread['uid'] == $mybb->user['uid'] && $thread['closed'] != 1 && $mybb->user['uid'] != 0 && $fpermissions[$thread['fid']]['caneditposts'] == 1) || is_moderator($fid, "caneditposts"))
 513              {
 514                  $inline_edit_class = "subject_editable";
 515              }
 516              else
 517              {
 518                  $inline_edit_class = "";
 519              }
 520              $load_inline_edit_js = 1;
 521  
 522              // If this thread has 1 or more attachments show the papperclip
 523              if($thread['attachmentcount'] > 0)
 524              {
 525                  if($thread['attachmentcount'] > 1)
 526                  {
 527                      $attachment_count = $lang->sprintf($lang->attachment_count_multiple, $thread['attachmentcount']);
 528                  }
 529                  else
 530                  {
 531                      $attachment_count = $lang->attachment_count;
 532                  }
 533  
 534                  eval("\$attachment_count = \"".$templates->get("forumdisplay_thread_attachment_count")."\";");
 535              }
 536              else
 537              {
 538                  $attachment_count = '';
 539              }
 540  
 541              $inline_edit_tid = $thread['tid'];
 542              
 543              // Inline thread moderation
 544              $inline_mod_checkbox = '';
 545              if($is_supermod || is_moderator($thread['fid']))
 546              {
 547                  eval("\$inline_mod_checkbox = \"".$templates->get("search_results_threads_inlinecheck")."\";");
 548              }
 549              elseif($is_mod)
 550              {
 551                  eval("\$inline_mod_checkbox = \"".$templates->get("search_results_threads_nocheck")."\";");
 552              }
 553  
 554              $plugins->run_hooks("search_results_thread");
 555              eval("\$results .= \"".$templates->get("search_results_threads_thread")."\";");
 556          }
 557          if(!$results)
 558          {
 559              error($lang->error_nosearchresults);
 560          }
 561          else
 562          {
 563              if($load_inline_edit_js == 1)
 564              {
 565                  eval("\$inline_edit_js = \"".$templates->get("forumdisplay_threadlist_inlineedit_js")."\";");
 566              }
 567          }
 568          $multipage = multipage($threadcount, $perpage, $page, "search.php?action=results&amp;sid=$sid&amp;sortby=$sortby&amp;order=$order&amp;uid=".$mybb->input['uid']);
 569          if($upper > $threadcount)
 570          {
 571              $upper = $threadcount;
 572          }
 573          
 574          // Inline Thread Moderation Options
 575          if($is_mod)
 576          {
 577              $customthreadtools = '';
 578              switch($db->type)
 579              {
 580                  case "pgsql":
 581                  case "sqlite3":
 582                  case "sqlite2":
 583                      $query = $db->simple_select("modtools", "tid, name", "type='t' AND (','||forums||',' LIKE '%,-1,%' OR forums='')");
 584                      break;
 585                  default:
 586                      $query = $db->simple_select("modtools", "tid, name", "type='t' AND (CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='')");
 587              }
 588              
 589              while($tool = $db->fetch_array($query))
 590              {
 591                  eval("\$customthreadtools .= \"".$templates->get("search_results_threads_inlinemoderation_custom_tool")."\";");
 592              }
 593              // Build inline moderation dropdown
 594              if(!empty($customthreadtools))
 595              {
 596                  eval("\$customthreadtools = \"".$templates->get("search_results_threads_inlinemoderation_custom")."\";");
 597              }
 598              eval("\$inlinemod = \"".$templates->get("search_results_threads_inlinemoderation")."\";");
 599          }
 600          
 601          eval("\$searchresults = \"".$templates->get("search_results_threads")."\";");
 602          $plugins->run_hooks("search_results_end");
 603          output_page($searchresults);
 604      }
 605      else // Displaying results as posts
 606      {
 607          if(!$search['posts'])
 608          {
 609              error($lang->error_nosearchresults);
 610          }
 611          
 612          $postcount = 0;
 613          
 614          // Moderators can view unapproved threads
 615          $query = $db->simple_select("moderators", "fid", "uid='{$mybb->user['uid']}'");
 616          if($mybb->usergroup['issupermod'] == 1)
 617          {
 618              // Super moderators (and admins)
 619              $p_unapproved_where = "visible >= 0";
 620              $t_unapproved_where = "visible < 0";
 621          }
 622          elseif($db->num_rows($query))
 623          {
 624              // Normal moderators
 625              $moderated_forums = '0';
 626              while($forum = $db->fetch_array($query))
 627              {
 628                  $moderated_forums .= ','.$forum['fid'];
 629                  $test_moderated_forums[$forum['fid']] = $forum['fid'];
 630              }
 631              $p_unapproved_where = "visible >= 0";
 632              $t_unapproved_where = "visible < 0 AND fid NOT IN ({$moderated_forums})";
 633          }
 634          else
 635          {
 636              // Normal users
 637              $p_unapproved_where = 'visible=1';
 638              $t_unapproved_where = 'visible < 1';
 639          }
 640  
 641          $post_cache_options = array();
 642          if(intval($mybb->settings['searchhardlimit']) > 0)
 643          {
 644              $post_cache_options['limit'] = intval($mybb->settings['searchhardlimit']);
 645          }
 646          if(strpos($sortfield, 'p.') !== false)
 647          {
 648              $post_cache_options['order_by'] = str_replace('p.', '', $sortfield);
 649              $post_cache_options['order_dir'] = $order;
 650          }
 651  
 652          $tids = array();
 653          $pids = array();
 654          // Make sure the posts we're viewing we have permission to view.
 655          $query = $db->simple_select("posts", "pid, tid", "pid IN(".$db->escape_string($search['posts']).") AND {$p_unapproved_where}", $post_cache_options);
 656          while($post = $db->fetch_array($query))
 657          {
 658              $pids[$post['pid']] = $post['tid'];
 659              $tids[$post['tid']][$post['pid']] = $post['pid'];
 660          }
 661          
 662          if(!empty($pids))
 663          {
 664              $temp_pids = array();
 665              
 666              // Check the thread records as well. If we don't have permissions, remove them from the listing.
 667              $query = $db->simple_select("threads", "tid", "tid IN(".$db->escape_string(implode(',', $pids)).") AND ({$t_unapproved_where} OR closed LIKE 'moved|%')");
 668              while($thread = $db->fetch_array($query))
 669              {
 670                  if(array_key_exists($thread['tid'], $tids) != false)
 671                  {
 672                      $temp_pids = $tids[$thread['tid']];
 673                      foreach($temp_pids as $pid)
 674                      {
 675                          unset($pids[$pid]);
 676                          unset($tids[$thread['tid']]);
 677                      }
 678                  }
 679              }            
 680              unset($temp_pids);
 681          }
 682          
 683          // Declare our post count
 684          $postcount = count($pids);
 685          
 686          if(!$postcount)
 687          {
 688              error($lang->error_nosearchresults);
 689          }
 690          
 691          // And now we have our sanatized post list
 692          $search['posts'] = implode(',', array_keys($pids));
 693          
 694          $tids = implode(",", array_keys($tids));
 695          
 696          // Read threads
 697          if($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0)
 698          {
 699              $query = $db->simple_select("threadsread", "tid, dateline", "uid='".$mybb->user['uid']."' AND tid IN(".$db->escape_string($tids).")");
 700              while($readthread = $db->fetch_array($query))
 701              {
 702                  $readthreads[$readthread['tid']] = $readthread['dateline'];
 703              }
 704          }
 705  
 706          $dot_icon = array();
 707          if($mybb->settings['dotfolders'] != 0 && $mybb->user['uid'] != 0)
 708          {
 709              $query = $db->simple_select("posts", "DISTINCT tid,uid", "uid='".$mybb->user['uid']."' AND tid IN(".$db->escape_string($tids).")");
 710              while($post = $db->fetch_array($query))
 711              {
 712                  $dot_icon[$post['tid']] = true;
 713              }
 714          }
 715  
 716          $query = $db->query("
 717              SELECT p.*, u.username AS userusername, t.subject AS thread_subject, t.replies AS thread_replies, t.views AS thread_views, t.lastpost AS thread_lastpost, t.closed AS thread_closed
 718              FROM ".TABLE_PREFIX."posts p
 719              LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
 720              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 721              WHERE p.pid IN (".$db->escape_string($search['posts']).")
 722              ORDER BY $sortfield $order
 723              LIMIT $start, $perpage
 724          ");
 725          while($post = $db->fetch_array($query))
 726          {
 727              $bgcolor = alt_trow();
 728              if(!$post['visible'])
 729              {
 730                  $bgcolor = 'trow_shaded';
 731              }
 732              if($post['userusername'])
 733              {
 734                  $post['username'] = $post['userusername'];
 735              }
 736              $post['profilelink'] = build_profile_link($post['username'], $post['uid']);
 737              $post['subject'] = $parser->parse_badwords($post['subject']);
 738              $post['thread_subject'] = $parser->parse_badwords($post['thread_subject']);
 739              $post['thread_subject'] = htmlspecialchars_uni($post['thread_subject']);
 740  
 741              if($icon_cache[$post['icon']])
 742              {
 743                  $posticon = $icon_cache[$post['icon']];
 744                  $icon = "<img src=\"".$posticon['path']."\" alt=\"".$posticon['name']."\" />";
 745              }
 746              else
 747              {
 748                  $icon = "&nbsp;";
 749              }
 750  
 751              if($forumcache[$thread['fid']])
 752              {
 753                  $post['forumlink'] = "<a href=\"".get_forum_link($post['fid'])."\">".$forumcache[$post['fid']]['name']."</a>";
 754              }
 755              else
 756              {
 757                  $post['forumlink'] = "";
 758              }
 759              // Determine the folder
 760              $folder = '';
 761              $folder_label = '';
 762              $gotounread = '';
 763              $isnew = 0;
 764              $donenew = 0;
 765              $last_read = 0;
 766              $post['thread_lastread'] = $readthreads[$post['tid']];
 767              if($mybb->settings['threadreadcut'] > 0 && $mybb->user['uid'] && $post['thread_lastpost'] > $forumread)
 768              {
 769                  $cutoff = TIME_NOW-$mybb->settings['threadreadcut']*60*60*24;
 770                  if($post['thread_lastpost'] > $cutoff)
 771                  {
 772                      if($post['thread_lastread'])
 773                      {
 774                          $last_read = $post['thread_lastread'];
 775                      }
 776                      else
 777                      {
 778                          $last_read = 1;
 779                      }
 780                  }
 781              }
 782  
 783              if($dot_icon[$post['tid']])
 784              {
 785                  $folder = "dot_";
 786                  $folder_label .= $lang->icon_dot;
 787              }
 788  
 789              if(!$last_read)
 790              {
 791                  $readcookie = $threadread = my_get_array_cookie("threadread", $post['tid']);
 792                  if($readcookie > $forumread)
 793                  {
 794                      $last_read = $readcookie;
 795                  }
 796                  elseif($forumread > $mybb->user['lastvisit'])
 797                  {
 798                      $last_read = $forumread;
 799                  }
 800                  else
 801                  {
 802                      $last_read = $mybb->user['lastvisit'];
 803                  }
 804              }
 805  
 806              if($post['thread_lastpost'] > $last_read && $last_read)
 807              {
 808                  $folder .= "new";
 809                  $folder_label .= $lang->icon_new;
 810                  eval("\$gotounread = \"".$templates->get("forumdisplay_thread_gotounread")."\";");
 811                  $unreadpost = 1;
 812              }
 813              else
 814              {
 815                  $folder_label .= $lang->icon_no_new;
 816              }
 817  
 818              if($post['thread_replies'] >= $mybb->settings['hottopic'] || $post['thread_views'] >= $mybb->settings['hottopicviews'])
 819              {
 820                  $folder .= "hot";
 821                  $folder_label .= $lang->icon_hot;
 822              }
 823              if($thread['thread_closed'] == 1)
 824              {
 825                  $folder .= "lock";
 826                  $folder_label .= $lang->icon_lock;
 827              }
 828              $folder .= "folder";
 829  
 830              $post['thread_replies'] = my_number_format($post['thread_replies']);
 831              $post['thread_views'] = my_number_format($post['thread_views']);
 832  
 833              if($forumcache[$post['fid']])
 834              {
 835                  $post['forumlink'] = "<a href=\"".get_forum_link($post['fid'])."\">".$forumcache[$post['fid']]['name']."</a>";
 836              }
 837              else
 838              {
 839                  $post['forumlink'] = "";
 840              }
 841  
 842              if(!$post['subject'])
 843              {
 844                  $post['subject'] = $post['message'];
 845              }
 846              if(my_strlen($post['subject']) > 50)
 847              {
 848                  $post['subject'] = htmlspecialchars_uni(my_substr($post['subject'], 0, 50)."...");
 849              }
 850              else
 851              {
 852                  $post['subject'] = htmlspecialchars_uni($post['subject']);
 853              }
 854              // What we do here is parse the post using our post parser, then strip the tags from it
 855              $parser_options = array(
 856                  'allow_html' => 0,
 857                  'allow_mycode' => 1,
 858                  'allow_smilies' => 0,
 859                  'allow_imgcode' => 0,
 860                  'filter_badwords' => 1
 861              );
 862              $post['message'] = strip_tags($parser->parse_message($post['message'], $parser_options));
 863              if(my_strlen($post['message']) > 200)
 864              {
 865                  $prev = my_substr($post['message'], 0, 200)."...";
 866              }
 867              else
 868              {
 869                  $prev = $post['message'];
 870              }
 871              $posted = my_date($mybb->settings['dateformat'], $post['dateline']).", ".my_date($mybb->settings['timeformat'], $post['dateline']);
 872              
 873              $thread_url = get_thread_link($post['tid']);
 874              $post_url = get_post_link($post['pid'], $post['tid']);
 875              
 876              // Inline post moderation
 877              $inline_mod_checkbox = '';
 878              if($is_supermod || is_moderator($post['fid']))
 879              {
 880                  eval("\$inline_mod_checkbox = \"".$templates->get("search_results_posts_inlinecheck")."\";");
 881              }
 882              elseif($is_mod)
 883              {
 884                  eval("\$inline_mod_checkbox = \"".$templates->get("search_results_posts_nocheck")."\";");
 885              }
 886  
 887              $plugins->run_hooks("search_results_post");
 888              eval("\$results .= \"".$templates->get("search_results_posts_post")."\";");
 889          }
 890          if(!$results)
 891          {
 892              error($lang->error_nosearchresults);
 893          }
 894          $multipage = multipage($postcount, $perpage, $page, "search.php?action=results&amp;sid=$sid&amp;sortby=$sortby&amp;order=$order&amp;uid=".$mybb->input['uid']);
 895          if($upper > $postcount)
 896          {
 897              $upper = $postcount;
 898          }
 899          
 900          // Inline Post Moderation Options
 901          if($is_mod)
 902          {
 903              $customthreadtools = $customposttools = '';
 904              switch($db->type)
 905              {
 906                  case "pgsql":
 907                  case "sqlite3":
 908                  case "sqlite2":
 909                      $query = $db->simple_select("modtools", "tid, name, type", "type='p' AND (','||forums||',' LIKE '%,-1,%' OR forums='')");
 910                      break;
 911                  default:
 912                      $query = $db->simple_select("modtools", "tid, name, type", "type='p' AND (CONCAT(',',forums,',') LIKE '%,-1,%' OR forums='')");
 913              }
 914              
 915              while($tool = $db->fetch_array($query))
 916              {
 917                  eval("\$customposttools .= \"".$templates->get("search_results_posts_inlinemoderation_custom_tool")."\";");
 918              }
 919              // Build inline moderation dropdown
 920              if(!empty($customposttools))
 921              {
 922                  eval("\$customposttools = \"".$templates->get("search_results_posts_inlinemoderation_custom")."\";");
 923              }
 924              eval("\$inlinemod = \"".$templates->get("search_results_posts_inlinemoderation")."\";");
 925          }
 926  
 927          eval("\$searchresults = \"".$templates->get("search_results_posts")."\";");
 928          $plugins->run_hooks("search_results_end");
 929          output_page($searchresults);
 930      }
 931  }
 932  elseif($mybb->input['action'] == "findguest")
 933  {
 934      $where_sql = "uid='0'";
 935  
 936      $unsearchforums = get_unsearchable_forums();
 937      if($unsearchforums)
 938      {
 939          $where_sql .= " AND fid NOT IN ($unsearchforums)";
 940      }
 941      $inactiveforums = get_inactive_forums();
 942      if($inactiveforums)
 943      {
 944          $where_sql .= " AND fid NOT IN ($inactiveforums)";
 945      }
 946      
 947      $options = array(
 948          'order_by' => 'dateline',
 949          'order_dir' => 'desc'
 950      );
 951  
 952      // Do we have a hard search limit?
 953      if($mybb->settings['searchhardlimit'] > 0)
 954      {
 955          $options['limit'] = intval($mybb->settings['searchhardlimit']);
 956      }
 957  
 958      $pids = '';
 959      $comma = '';
 960      $query = $db->simple_select("posts", "pid", "{$where_sql}", $options);
 961      while($pid = $db->fetch_field($query, "pid"))
 962      {
 963              $pids .= $comma.$pid;
 964              $comma = ',';
 965      }
 966      
 967      $tids = '';
 968      $comma = '';
 969      $query = $db->simple_select("threads", "tid", $where_sql);
 970      while($tid = $db->fetch_field($query, "tid"))
 971      {
 972              $tids .= $comma.$tid;
 973              $comma = ',';
 974      }
 975  
 976      $sid = md5(uniqid(microtime(), 1));
 977      $searcharray = array(
 978          "sid" => $db->escape_string($sid),
 979          "uid" => $mybb->user['uid'],
 980          "dateline" => TIME_NOW,
 981          "ipaddress" => $db->escape_string($session->ipaddress),
 982          "threads" => $db->escape_string($tids),
 983          "posts" => $db->escape_string($pids),
 984          "resulttype" => "posts",
 985          "querycache" => '',
 986          "keywords" => ''
 987      );
 988      $plugins->run_hooks("search_do_search_process");
 989      $db->insert_query("searchlog", $searcharray);
 990      redirect("search.php?action=results&sid=".$sid, $lang->redirect_searchresults);
 991  }
 992  elseif($mybb->input['action'] == "finduser")
 993  {
 994      $where_sql = "uid='".intval($mybb->input['uid'])."'";
 995      
 996      $unsearchforums = get_unsearchable_forums();
 997      if($unsearchforums)
 998      {
 999          $where_sql .= " AND fid NOT IN ($unsearchforums)";
1000      }
1001      $inactiveforums = get_inactive_forums();
1002      if($inactiveforums)
1003      {
1004          $where_sql .= " AND fid NOT IN ($inactiveforums)";
1005      }
1006  
1007      $options = array(
1008          'order_by' => 'dateline',
1009          'order_dir' => 'desc'
1010      );
1011  
1012      // Do we have a hard search limit?
1013      if($mybb->settings['searchhardlimit'] > 0)
1014      {
1015          $options['limit'] = intval($mybb->settings['searchhardlimit']);
1016      }
1017  
1018      $pids = '';
1019      $comma = '';
1020      $query = $db->simple_select("posts", "pid", "{$where_sql}", $options);
1021      while($pid = $db->fetch_field($query, "pid"))
1022      {
1023              $pids .= $comma.$pid;
1024              $comma = ',';
1025      }
1026      
1027      $tids = '';
1028      $comma = '';
1029      $query = $db->simple_select("threads", "tid", $where_sql);
1030      while($tid = $db->fetch_field($query, "tid"))
1031      {
1032              $tids .= $comma.$tid;
1033              $comma = ',';
1034      }
1035  
1036      $sid = md5(uniqid(microtime(), 1));
1037      $searcharray = array(
1038          "sid" => $db->escape_string($sid),
1039          "uid" => $mybb->user['uid'],
1040          "dateline" => TIME_NOW,
1041          "ipaddress" => $db->escape_string($session->ipaddress),
1042          "threads" => $db->escape_string($tids),
1043          "posts" => $db->escape_string($pids),
1044          "resulttype" => "posts",
1045          "querycache" => '',
1046          "keywords" => ''
1047      );
1048      $plugins->run_hooks("search_do_search_process");
1049      $db->insert_query("searchlog", $searcharray);
1050      redirect("search.php?action=results&sid=".$sid, $lang->redirect_searchresults);
1051  }
1052  elseif($mybb->input['action'] == "finduserthreads")
1053  {
1054      $where_sql = "t.uid='".intval($mybb->input['uid'])."'";
1055  
1056      $unsearchforums = get_unsearchable_forums();
1057      if($unsearchforums)
1058      {
1059          $where_sql .= " AND t.fid NOT IN ($unsearchforums)";
1060      }
1061      $inactiveforums = get_inactive_forums();
1062      if($inactiveforums)
1063      {
1064          $where_sql .= " AND t.fid NOT IN ($inactiveforums)";
1065      }
1066  
1067      $sid = md5(uniqid(microtime(), 1));
1068      $searcharray = array(
1069          "sid" => $db->escape_string($sid),
1070          "uid" => $mybb->user['uid'],
1071          "dateline" => TIME_NOW,
1072          "ipaddress" => $db->escape_string($session->ipaddress),
1073          "threads" => '',
1074          "posts" => '',
1075          "resulttype" => "threads",
1076          "querycache" => $db->escape_string($where_sql),
1077          "keywords" => ''
1078      );
1079      $plugins->run_hooks("search_do_search_process");
1080      $db->insert_query("searchlog", $searcharray);
1081      redirect("search.php?action=results&sid=".$sid, $lang->redirect_searchresults);
1082  }
1083  elseif($mybb->input['action'] == "getnew")
1084  {
1085      
1086      $where_sql = "t.lastpost >= '".$mybb->user['lastvisit']."'";
1087  
1088      if($mybb->input['fid'])
1089      {
1090          $where_sql .= " AND t.fid='".intval($mybb->input['fid'])."'";
1091      }
1092      else if($mybb->input['fids'])
1093      {
1094          $fids = explode(',', $mybb->input['fids']);
1095          foreach($fids as $key => $fid)
1096          {
1097              $fids[$key] = intval($fid);
1098          }
1099          
1100          if(!empty($fids))
1101          {
1102              $where_sql .= " AND t.fid IN (".implode(',', $fids).")";
1103          }
1104      }
1105      
1106      $unsearchforums = get_unsearchable_forums();
1107      if($unsearchforums)
1108      {
1109          $where_sql .= " AND t.fid NOT IN ($unsearchforums)";
1110      }
1111      $inactiveforums = get_inactive_forums();
1112      if($inactiveforums)
1113      {
1114          $where_sql .= " AND t.fid NOT IN ($inactiveforums)";
1115      }
1116  
1117      $sid = md5(uniqid(microtime(), 1));
1118      $searcharray = array(
1119          "sid" => $db->escape_string($sid),
1120          "uid" => $mybb->user['uid'],
1121          "dateline" => TIME_NOW,
1122          "ipaddress" => $db->escape_string($session->ipaddress),
1123          "threads" => '',
1124          "posts" => '',
1125          "resulttype" => "threads",
1126          "querycache" => $db->escape_string($where_sql),
1127          "keywords" => ''
1128      );
1129  
1130      $plugins->run_hooks("search_do_search_process");
1131      $db->insert_query("searchlog", $searcharray);
1132      redirect("search.php?action=results&sid=".$sid, $lang->redirect_searchresults);
1133  }
1134  elseif($mybb->input['action'] == "getdaily")
1135  {
1136      if($mybb->input['days'] < 1)
1137      {
1138          $days = 1;
1139      }
1140      else
1141      {
1142          $days = intval($mybb->input['days']);
1143      }
1144      $datecut = TIME_NOW-(86400*$days);
1145  
1146      $where_sql = "t.lastpost >='".$datecut."'";
1147  
1148      if($mybb->input['fid'])
1149      {
1150          $where_sql .= " AND t.fid='".intval($mybb->input['fid'])."'";
1151      }
1152      else if($mybb->input['fids'])
1153      {
1154          $fids = explode(',', $mybb->input['fids']);
1155          foreach($fids as $key => $fid)
1156          {
1157              $fids[$key] = intval($fid);
1158          }
1159          
1160          if(!empty($fids))
1161          {
1162              $where_sql .= " AND t.fid IN (".implode(',', $fids).")";
1163          }
1164      }
1165      
1166      $unsearchforums = get_unsearchable_forums();
1167      if($unsearchforums)
1168      {
1169          $where_sql .= " AND t.fid NOT IN ($unsearchforums)";
1170      }
1171      $inactiveforums = get_inactive_forums();
1172      if($inactiveforums)
1173      {
1174          $where_sql .= " AND t.fid NOT IN ($inactiveforums)";
1175      }
1176  
1177  
1178      $sid = md5(uniqid(microtime(), 1));
1179      $searcharray = array(
1180          "sid" => $db->escape_string($sid),
1181          "uid" => $mybb->user['uid'],
1182          "dateline" => TIME_NOW,
1183          "ipaddress" => $db->escape_string($session->ipaddress),
1184          "threads" => '',
1185          "posts" => '',
1186          "resulttype" => "threads",
1187          "querycache" => $db->escape_string($where_sql),
1188          "keywords" => ''
1189      );
1190  
1191      $plugins->run_hooks("search_do_search_process");
1192      $db->insert_query("searchlog", $searcharray);
1193      redirect("search.php?action=results&sid=".$sid, $lang->redirect_searchresults);
1194  }
1195  elseif($mybb->input['action'] == "do_search" && $mybb->request_method == "post")
1196  {
1197      $plugins->run_hooks("search_do_search_start");
1198  
1199      // Check if search flood checking is enabled and user is not admin
1200      if($mybb->settings['searchfloodtime'] > 0 && $mybb->usergroup['cancp'] != 1)
1201      {
1202          // Fetch the time this user last searched
1203          if($mybb->user['uid'])
1204          {
1205              $conditions = "uid='{$mybb->user['uid']}'";
1206          }
1207          else
1208          {
1209              $conditions = "uid='0' AND ipaddress='".$db->escape_string($session->ipaddress)."'";
1210          }
1211          $timecut = TIME_NOW-$mybb->settings['searchfloodtime'];
1212          $query = $db->simple_select("searchlog", "*", "$conditions AND dateline > '$timecut'", array('order_by' => "dateline", 'order_dir' => "DESC"));
1213          $last_search = $db->fetch_array($query);
1214          // Users last search was within the flood time, show the error
1215          if($last_search['sid'])
1216          {
1217              $remaining_time = $mybb->settings['searchfloodtime']-(TIME_NOW-$last_search['dateline']);
1218              if($remaining_time == 1)
1219              {
1220                  $lang->error_searchflooding = $lang->sprintf($lang->error_searchflooding_1, $mybb->settings['searchfloodtime']);
1221              }
1222              else
1223              {
1224                  $lang->error_searchflooding = $lang->sprintf($lang->error_searchflooding, $mybb->settings['searchfloodtime'], $remaining_time);
1225              }
1226              error($lang->error_searchflooding);
1227          }
1228      }
1229      if($mybb->input['showresults'] == "threads")
1230      {
1231          $resulttype = "threads";
1232      }
1233      else
1234      {
1235          $resulttype = "posts";
1236      }
1237  
1238      $search_data = array(
1239          "keywords" => $mybb->input['keywords'],
1240          "author" => $mybb->input['author'],
1241          "postthread" => $mybb->input['postthread'],
1242          "matchusername" => $mybb->input['matchusername'],
1243          "postdate" => $mybb->input['postdate'],
1244          "pddir" => $mybb->input['pddir'],
1245          "forums" => $mybb->input['forums'],
1246          "findthreadst" => $mybb->input['findthreadst'],
1247          "numreplies" => $mybb->input['numreplies']
1248      );
1249  
1250      if($db->can_search == true)
1251      {
1252          if($mybb->settings['searchtype'] == "fulltext" && $db->supports_fulltext_boolean("posts") && $db->is_fulltext("posts"))
1253          {
1254              $search_results = perform_search_mysql_ft($search_data);
1255          }
1256          else
1257          {
1258              $search_results = perform_search_mysql($search_data);
1259          }
1260      }
1261      else
1262      {
1263          error($lang->error_no_search_support);
1264      }
1265      $sid = md5(uniqid(microtime(), 1));
1266      $searcharray = array(
1267          "sid" => $db->escape_string($sid),
1268          "uid" => $mybb->user['uid'],
1269          "dateline" => $now,
1270          "ipaddress" => $db->escape_string($session->ipaddress),
1271          "threads" => $search_results['threads'],
1272          "posts" => $search_results['posts'],
1273          "resulttype" => $resulttype,
1274          "querycache" => $search_results['querycache'],
1275          "keywords" => $db->escape_string($mybb->input['keywords']),
1276      );
1277      $plugins->run_hooks("search_do_search_process");
1278  
1279      $db->insert_query("searchlog", $searcharray);
1280  
1281      if(my_strtolower($mybb->input['sortordr']) == "asc" || my_strtolower($mybb->input['sortordr'] == "desc"))
1282      {
1283          $sortorder = $mybb->input['sortordr'];
1284      }
1285      else
1286      {
1287          $sortorder = "desc";
1288      }
1289      $sortby = htmlspecialchars($mybb->input['sortby']);
1290      $plugins->run_hooks("search_do_search_end");
1291      redirect("search.php?action=results&sid=".$sid."&sortby=".$sortby."&order=".$sortorder, $lang->redirect_searchresults);
1292  }
1293  else if($mybb->input['action'] == "thread")
1294  {
1295      // Fetch thread info
1296      $thread = get_thread($mybb->input['tid']);
1297      if(!$thread['tid'] || (($thread['visible'] == 0 && !is_moderator($thread['fid'])) || $thread['visible'] < 0))
1298      {
1299          error($lang->error_invalidthread);
1300      }
1301  
1302      // Get forum info
1303      $forum = get_forum($thread['fid']);
1304      if(!$forum)
1305      {
1306          error($lang->error_invalidforum);
1307      }
1308  
1309      $forum_permissions = forum_permissions($forum['fid']);
1310  
1311      if($forum['open'] == 0 || $forum['type'] != "f")
1312      {
1313          error($lang->error_closedinvalidforum);
1314      }
1315      if($forum_permissions['canview'] == 0 || $forum_permissions['canviewthreads'] != 1)
1316      {
1317          error_no_permission();
1318      }
1319  
1320      $plugins->run_hooks("search_thread_start");
1321  
1322      // Check if search flood checking is enabled and user is not admin
1323      if($mybb->settings['searchfloodtime'] > 0 && $mybb->usergroup['cancp'] != 1)
1324      {
1325          // Fetch the time this user last searched
1326          if($mybb->user['uid'])
1327          {
1328              $conditions = "uid='{$mybb->user['uid']}'";
1329          }
1330          else
1331          {
1332              $conditions = "uid='0' AND ipaddress='".$db->escape_string($session->ipaddress)."'";
1333          }
1334          $timecut = TIME_NOW-$mybb->settings['searchfloodtime'];
1335          $query = $db->simple_select("searchlog", "*", "$conditions AND dateline > '$timecut'", array('order_by' => "dateline", 'order_dir' => "DESC"));
1336          $last_search = $db->fetch_array($query);
1337  
1338          // We shouldn't show remaining time if time is 0 or under.
1339          $remaining_time = $mybb->settings['searchfloodtime']-(TIME_NOW-$last_search['dateline']);
1340          // Users last search was within the flood time, show the error.
1341          if($last_search['sid'] && $remaining_time > 0)
1342          {
1343              if($remaining_time == 1)
1344              {
1345                  $lang->error_searchflooding = $lang->sprintf($lang->error_searchflooding_1, $mybb->settings['searchfloodtime']);
1346              }
1347              else
1348              {
1349                  $lang->error_searchflooding = $lang->sprintf($lang->error_searchflooding, $mybb->settings['searchfloodtime'], $remaining_time);
1350              }
1351              error($lang->error_searchflooding);
1352          }
1353      }
1354  
1355      $search_data = array(
1356          "keywords" => $mybb->input['keywords'],
1357          "postthread" => 1,
1358          "tid" => $mybb->input['tid']
1359      );
1360  
1361      if($db->can_search == true)
1362      {
1363          if($mybb->settings['searchtype'] == "fulltext" && $db->supports_fulltext_boolean("posts") && $db->is_fulltext("posts"))
1364          {
1365              $search_results = perform_search_mysql_ft($search_data);
1366          }
1367          else
1368          {
1369              $search_results = perform_search_mysql($search_data);
1370          }
1371      }
1372      else
1373      {
1374          error($lang->error_no_search_support);
1375      }
1376      $sid = md5(uniqid(microtime(), 1));
1377      $searcharray = array(
1378          "sid" => $db->escape_string($sid),
1379          "uid" => $mybb->user['uid'],
1380          "dateline" => $now,
1381          "ipaddress" => $db->escape_string($session->ipaddress),
1382          "threads" => $search_results['threads'],
1383          "posts" => $search_results['posts'],
1384          "resulttype" => 'posts',
1385          "querycache" => $search_results['querycache'],
1386          "keywords" => $db->escape_string($mybb->input['keywords'])
1387      );
1388      $plugins->run_hooks("search_thread_process");
1389  
1390      $db->insert_query("searchlog", $searcharray);
1391  
1392      $plugins->run_hooks("search_do_search_end");
1393      redirect("search.php?action=results&sid=".$sid, $lang->redirect_searchresults);
1394  }
1395  else
1396  {
1397      $plugins->run_hooks("search_start");
1398      $srchlist = make_searchable_forums("", $fid);
1399      eval("\$search = \"".$templates->get("search")."\";");
1400      $plugins->run_hooks("search_end");
1401      output_page($search);
1402  }
1403  
1404  ?>


Generated: Mon Apr 19 19:52:21 2010 Cross-referenced by PHPXref 0.7