[ PHPXref.com ] [ Generated: Thu Aug 19 03:35:06 2010 ] [ FluxBB 1.4.2 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> search.php (source)

   1  <?php
   2  
   3  /**
   4   * Copyright (C) 2008-2010 FluxBB
   5   * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
   6   * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
   7   */
   8  
   9  // The contents of this file are very much inspired by the file search.php
  10  // from the phpBB Group forum software phpBB2 (http://www.phpbb.com)
  11  
  12  define('PUN_ROOT', './');
  13  require  PUN_ROOT.'include/common.php';
  14  
  15  // Load the search.php language file
  16  require PUN_ROOT.'lang/'.$pun_user['language'].'/search.php';
  17  require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';
  18  
  19  
  20  if ($pun_user['g_read_board'] == '0')
  21      message($lang_common['No view']);
  22  else if ($pun_user['g_search'] == '0')
  23      message($lang_search['No search permission']);
  24  
  25  require  PUN_ROOT.'include/search_idx.php';
  26  
  27  // Figure out what to do :-)
  28  if (isset($_GET['action']) || isset($_GET['search_id']))
  29  {
  30      $action = (isset($_GET['action'])) ? $_GET['action'] : null;
  31      $forum = (isset($_GET['forum'])) ? intval($_GET['forum']) : -1;
  32      $sort_dir = (isset($_GET['sort_dir']) && $_GET['sort_dir'] == 'DESC') ? 'DESC' : 'ASC';
  33  
  34      // If a search_id was supplied
  35      if (isset($_GET['search_id']))
  36      {
  37          $search_id = intval($_GET['search_id']);
  38          if ($search_id < 1)
  39              message($lang_common['Bad request']);
  40      }
  41      // If it's a regular search (keywords and/or author)
  42      else if ($action == 'search')
  43      {
  44          $keywords = (isset($_GET['keywords'])) ? utf8_strtolower(pun_trim($_GET['keywords'])) : null;
  45          $author = (isset($_GET['author'])) ? utf8_strtolower(pun_trim($_GET['author'])) : null;
  46  
  47          if (preg_match('#^[\*%]+$#', $keywords) || (pun_strlen(str_replace(array('*', '%'), '', $keywords)) < PUN_SEARCH_MIN_WORD && !is_cjk($keywords)))
  48              $keywords = '';
  49  
  50          if (preg_match('#^[\*%]+$#', $author) || pun_strlen(str_replace(array('*', '%'), '', $author)) < 2)
  51              $author = '';
  52  
  53          if (!$keywords && !$author)
  54              message($lang_search['No terms']);
  55  
  56          if ($author)
  57              $author = str_replace('*', '%', $author);
  58  
  59          $show_as = (isset($_GET['show_as'])) ? $_GET['show_as'] : 'posts';
  60          $sort_by = (isset($_GET['sort_by'])) ? intval($_GET['sort_by']) : null;
  61          $search_in = (!isset($_GET['search_in']) || $_GET['search_in'] == 'all') ? 0 : (($_GET['search_in'] == 'message') ? 1 : -1);
  62      }
  63      // If it's a user search (by ID)
  64      else if ($action == 'show_user')
  65      {
  66          $user_id = (isset($_GET['user_id'])) ? intval($_GET['user_id']) : 0;
  67          if ($user_id < 2)
  68              message($lang_common['Bad request']);
  69      }
  70      else
  71      {
  72          if ($action != 'show_new' && $action != 'show_24h' && $action != 'show_unanswered' && $action != 'show_subscriptions')
  73              message($lang_common['Bad request']);
  74      }
  75  
  76  
  77      // If a valid search_id was supplied we attempt to fetch the search results from the db
  78      if (isset($search_id))
  79      {
  80          $ident = ($pun_user['is_guest']) ? get_remote_address() : $pun_user['username'];
  81  
  82          $result = $db->query('SELECT search_data FROM '.$db->prefix.'search_cache WHERE id='.$search_id.' AND ident=\''.$db->escape($ident).'\'') or error('Unable to fetch search results', __FILE__, __LINE__, $db->error());
  83          if ($row = $db->fetch_assoc($result))
  84          {
  85              $temp = unserialize($row['search_data']);
  86  
  87              $search_ids = unserialize($temp['search_ids']);
  88              $num_hits = $temp['num_hits'];
  89              $sort_by = $temp['sort_by'];
  90              $sort_dir = $temp['sort_dir'];
  91              $show_as = $temp['show_as'];
  92  
  93              unset($temp);
  94          }
  95          else
  96              message($lang_search['No hits']);
  97      }
  98      else
  99      {
 100          $keyword_results = $author_results = array();
 101  
 102          // Search a specific forum?
 103          $forum_sql = ($forum != -1 || ($forum == -1 && $pun_config['o_search_all_forums'] == '0' && !$pun_user['is_admmod'])) ? ' AND t.forum_id = '.$forum : '';
 104  
 105          if (!empty($author) || !empty($keywords))
 106          {
 107              // Flood protection
 108              if ($pun_user['last_search'] && (time() - $pun_user['last_search']) < $pun_user['g_search_flood'] && (time() - $pun_user['last_search']) >= 0)
 109                  message(sprintf($lang_search['Search flood'], $pun_user['g_search_flood']));
 110  
 111              if (!$pun_user['is_guest'])
 112                  $db->query('UPDATE '.$db->prefix.'users SET last_search='.time().' WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
 113              else
 114                  $db->query('UPDATE '.$db->prefix.'online SET last_search='.time().' WHERE ident=\''.$db->escape(get_remote_address()).'\'' ) or error('Unable to update user', __FILE__, __LINE__, $db->error());
 115  
 116              switch ($sort_by)
 117              {
 118                  case 1:
 119                      $sort_by_sql = ($show_as == 'topics') ? 't.poster' : 'p.poster';
 120                      $sort_type = SORT_STRING;
 121                      break;
 122  
 123                  case 2:
 124                      $sort_by_sql = 't.subject';
 125                      $sort_type = SORT_STRING;
 126                      break;
 127  
 128                  case 3:
 129                      $sort_by_sql = 't.forum_id';
 130                      $sort_type = SORT_NUMERIC;
 131                      break;
 132  
 133                  case 4:
 134                      $sort_by_sql = 't.last_post';
 135                      $sort_type = SORT_NUMERIC;
 136                      break;
 137  
 138                  default:
 139                      $sort_by_sql = ($show_as == 'topics') ? 't.last_post' : 'p.posted';
 140                      $sort_type = SORT_NUMERIC;
 141                      break;
 142              }
 143  
 144              // If it's a search for keywords
 145              if ($keywords)
 146              {
 147                  // split the keywords into words
 148                  $keywords_array = split_words($keywords, false);
 149  
 150                  if (empty($keywords_array))
 151                      message($lang_search['No hits']);
 152  
 153                  // Should we search in message body or topic subject specifically?
 154                  $search_in_cond = ($search_in) ? (($search_in > 0) ? ' AND m.subject_match = 0' : ' AND m.subject_match = 1') : '';
 155  
 156                  $word_count = 0;
 157                  $match_type = 'and';
 158  
 159                  $sort_data = array();
 160                  foreach ($keywords_array as $cur_word)
 161                  {
 162                      switch ($cur_word)
 163                      {
 164                          case 'and':
 165                          case 'or':
 166                          case 'not':
 167                              $match_type = $cur_word;
 168                              break;
 169  
 170                          default:
 171                          {
 172                              if (is_cjk($cur_word))
 173                              {
 174                                  $where_cond = str_replace('*', '%', $cur_word);
 175                                  $where_cond = ($search_in ? (($search_in > 0) ? 'p.message LIKE \'%'.$db->escape($where_cond).'%\'' : 't.subject LIKE \'%'.$db->escape($where_cond).'%\'') : 'p.message LIKE \'%'.$db->escape($where_cond).'%\' OR t.subject LIKE \'%'.$db->escape($where_cond).'%\'');
 176  
 177                                  $result = $db->query('SELECT p.id AS post_id, p.topic_id, '.$sort_by_sql.' AS sort_by FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE ('.$where_cond.') AND (fp.read_forum IS NULL OR fp.read_forum=1)'.$forum_sql, true) or error('Unable to search for posts', __FILE__, __LINE__, $db->error());
 178                              }
 179                              else
 180                                  $result = $db->query('SELECT m.post_id, p.topic_id, '.$sort_by_sql.' AS sort_by FROM '.$db->prefix.'search_words AS w INNER JOIN '.$db->prefix.'search_matches AS m ON m.word_id = w.id INNER JOIN '.$db->prefix.'posts AS p ON p.id=m.post_id INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE w.word LIKE \''.$db->escape(str_replace('*', '%', $cur_word)).'\''.$search_in_cond.' AND (fp.read_forum IS NULL OR fp.read_forum=1)'.$forum_sql, true) or error('Unable to search for posts', __FILE__, __LINE__, $db->error());
 181  
 182                              $row = array();
 183                              while ($temp = $db->fetch_assoc($result))
 184                              {
 185                                  $row[$temp['post_id']] = $temp['topic_id'];
 186  
 187                                  if (!$word_count)
 188                                  {
 189                                      $keyword_results[$temp['post_id']] = $temp['topic_id'];
 190                                      $sort_data[$temp['post_id']] = $temp['sort_by'];
 191                                  }
 192                                  else if ($match_type == 'or')
 193                                  {
 194                                      $keyword_results[$temp['post_id']] = $temp['topic_id'];
 195                                      $sort_data[$temp['post_id']] = $temp['sort_by'];
 196                                  }
 197                                  else if ($match_type == 'not')
 198                                  {
 199                                      unset($keyword_results[$temp['post_id']]);
 200                                      unset($sort_data[$temp['post_id']]);
 201                                  }
 202                              }
 203  
 204                              if ($match_type == 'and' && $word_count)
 205                              {
 206                                  foreach ($keyword_results as $post_id => $topic_id)
 207                                  {
 208                                      if (!isset($row[$post_id]))
 209                                      {
 210                                          unset($keyword_results[$post_id]);
 211                                          unset($sort_data[$post_id]);
 212                                      }
 213                                  }
 214                              }
 215  
 216                              ++$word_count;
 217                              $db->free_result($result);
 218  
 219                              break;
 220                          }
 221                      }
 222                  }
 223  
 224                  // Sort the results - annoyingly array_multisort re-indexes arrays with numeric keys, so we need to split the keys out into a seperate array then combine them again after
 225                  $post_ids = array_keys($keyword_results);
 226                  $topic_ids = array_values($keyword_results);
 227  
 228                  array_multisort(array_values($sort_data), $sort_dir == 'DESC' ? SORT_DESC : SORT_ASC, $sort_type, $post_ids, $topic_ids);
 229  
 230                  // combine the arrays back into a key=>value array (array_combine is PHP5 only unfortunately)
 231                  $num_results = count($keyword_results);
 232                  $keyword_results = array();
 233                  for ($i = 0;$i < $num_results;$i++)
 234                      $keyword_results[$post_ids[$i]] = $topic_ids[$i];
 235  
 236                  unset($sort_data, $post_ids, $topic_ids);
 237              }
 238  
 239              // If it's a search for author name (and that author name isn't Guest)
 240              if ($author && $author != 'guest' && $author != utf8_strtolower($lang_common['Guest']))
 241              {
 242                  switch ($db_type)
 243                  {
 244                      case 'pgsql':
 245                          $result = $db->query('SELECT id FROM '.$db->prefix.'users WHERE username ILIKE \''.$db->escape($author).'\'') or error('Unable to fetch users', __FILE__, __LINE__, $db->error());
 246                          break;
 247  
 248                      default:
 249                          $result = $db->query('SELECT id FROM '.$db->prefix.'users WHERE username LIKE \''.$db->escape($author).'\'') or error('Unable to fetch users', __FILE__, __LINE__, $db->error());
 250                          break;
 251                  }
 252  
 253                  if ($db->num_rows($result))
 254                  {
 255                      $user_ids = array();
 256                      while ($row = $db->fetch_row($result))
 257                          $user_ids[] = $row[0];
 258  
 259                      $result = $db->query('SELECT p.id AS post_id, p.topic_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.poster_id IN('.implode(',', $user_ids).')'.$forum_sql.' ORDER BY '.$sort_by_sql.' '.$sort_dir) or error('Unable to fetch matched posts list', __FILE__, __LINE__, $db->error());
 260                      while ($temp = $db->fetch_assoc($result))
 261                          $author_results[$temp['post_id']] = $temp['topic_id'];
 262  
 263                      $db->free_result($result);
 264                  }
 265              }
 266  
 267              // If we searched for both keywords and author name we want the intersection between the results
 268              if ($author && $keywords)
 269                  $search_ids = array_intersect_assoc($keyword_results, $author_results);
 270              else if ($keywords)
 271                  $search_ids = $keyword_results;
 272              else
 273                  $search_ids = $author_results;
 274  
 275              unset($keyword_results, $author_results);
 276  
 277              if ($show_as == 'topics')
 278                  $search_ids = array_values($search_ids);
 279              else
 280                  $search_ids = array_keys($search_ids);
 281  
 282              $search_ids = array_unique($search_ids);
 283  
 284              $num_hits = count($search_ids);
 285              if (!$num_hits)
 286                  message($lang_search['No hits']);
 287          }
 288          else if ($action == 'show_new' || $action == 'show_24h' || $action == 'show_user' || $action == 'show_subscriptions' || $action == 'show_unanswered')
 289          {
 290              // If it's a search for new posts
 291              if ($action == 'show_new')
 292              {
 293                  if ($pun_user['is_guest'])
 294                      message($lang_common['No permission']);
 295  
 296                  $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.last_post>'.$pun_user['last_visit'].' AND t.moved_to IS NULL'.(isset($_GET['fid']) ? ' AND t.forum_id='.intval($_GET['fid']) : '').' ORDER BY t.last_post DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
 297                  $num_hits = $db->num_rows($result);
 298  
 299                  if (!$num_hits)
 300                      message($lang_search['No new posts']);
 301              }
 302              // If it's a search for todays posts
 303              else if ($action == 'show_24h')
 304              {
 305                  $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.last_post>'.(time() - 86400).' AND t.moved_to IS NULL ORDER BY t.last_post DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
 306                  $num_hits = $db->num_rows($result);
 307  
 308                  if (!$num_hits)
 309                      message($lang_search['No recent posts']);
 310              }
 311              // If it's a search for posts by a specific user ID
 312              else if ($action == 'show_user')
 313              {
 314                  $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.poster_id='.$user_id.' GROUP BY t.id ORDER BY t.last_post DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
 315                  $num_hits = $db->num_rows($result);
 316  
 317                  if (!$num_hits)
 318                      message($lang_search['No user posts']);
 319              }
 320              // If it's a search for subscribed topics
 321              else if ($action == 'show_subscriptions')
 322              {
 323                  if ($pun_user['is_guest'])
 324                      message($lang_common['Bad request']);
 325  
 326                  $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'subscriptions AS s ON (t.id=s.topic_id AND s.user_id='.$pun_user['id'].') LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) ORDER BY t.last_post DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
 327                  $num_hits = $db->num_rows($result);
 328  
 329                  if (!$num_hits)
 330                      message($lang_search['No subscriptions']);
 331              }
 332              // If it's a search for unanswered posts
 333              else
 334              {
 335                  $result = $db->query('SELECT t.id FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.num_replies=0 AND t.moved_to IS NULL ORDER BY t.last_post DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
 336                  $num_hits = $db->num_rows($result);
 337  
 338                  if (!$num_hits)
 339                      message($lang_search['No unanswered']);
 340              }
 341  
 342              // We want to sort things after last post
 343              $sort_by = 4;
 344              $sort_dir = 'DESC';
 345  
 346              $search_ids = array();
 347              while ($row = $db->fetch_row($result))
 348                  $search_ids[] = $row[0];
 349  
 350              $db->free_result($result);
 351  
 352              $show_as = 'topics';
 353          }
 354          else
 355              message($lang_common['Bad request']);
 356  
 357  
 358          // Prune "old" search results
 359          $old_searches = array();
 360          $result = $db->query('SELECT ident FROM '.$db->prefix.'online') or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
 361  
 362          if ($db->num_rows($result))
 363          {
 364              while ($row = $db->fetch_row($result))
 365                  $old_searches[] = '\''.$db->escape($row[0]).'\'';
 366  
 367              $db->query('DELETE FROM '.$db->prefix.'search_cache WHERE ident NOT IN('.implode(',', $old_searches).')') or error('Unable to delete search results', __FILE__, __LINE__, $db->error());
 368          }
 369  
 370          // Fill an array with our results and search properties
 371          $temp = serialize(array(
 372              'search_ids'        => serialize($search_ids),
 373              'num_hits'            => $num_hits,
 374              'sort_by'            => $sort_by,
 375              'sort_dir'            => $sort_dir,
 376              'show_as'            => $show_as,
 377          ));
 378          $search_id = mt_rand(1, 2147483647);
 379  
 380          $ident = ($pun_user['is_guest']) ? get_remote_address() : $pun_user['username'];
 381  
 382          $db->query('INSERT INTO '.$db->prefix.'search_cache (id, ident, search_data) VALUES('.$search_id.', \''.$db->escape($ident).'\', \''.$db->escape($temp).'\')') or error('Unable to insert search results', __FILE__, __LINE__, $db->error());
 383  
 384          if ($action != 'show_new' && $action != 'show_24h')
 385          {
 386              $db->end_transaction();
 387              $db->close();
 388  
 389              // Redirect the user to the cached result page
 390              header('Location: search.php?search_id='.$search_id);
 391              exit;
 392          }
 393      }
 394  
 395  
 396      // Fetch results to display
 397      if (!empty($search_ids))
 398      {
 399          switch ($sort_by)
 400          {
 401              case 1:
 402                  $sort_by_sql = ($show_as == 'topics') ? 't.poster' : 'p.poster';
 403                  break;
 404  
 405              case 2:
 406                  $sort_by_sql = 't.subject';
 407                  break;
 408  
 409              case 3:
 410                  $sort_by_sql = 't.forum_id';
 411                  break;
 412  
 413              case 4:
 414                  $sort_by_sql = 't.last_post';
 415                  break;
 416  
 417              default:
 418                  $sort_by_sql = ($show_as == 'topics') ? 't.last_post' : 'p.posted';
 419                  break;
 420          }
 421  
 422          // Determine the topic or post offset (based on $_GET['p'])
 423          $per_page = ($show_as == 'posts') ? $pun_user['disp_posts'] : $pun_user['disp_topics'];
 424          $num_pages = ceil($num_hits / $per_page);
 425  
 426          $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']);
 427          $start_from = $per_page * ($p - 1);
 428  
 429          // Generate paging links
 430          $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'search.php?search_id='.$search_id);
 431  
 432          // throw away the first $start_from of $search_ids, only keep the top $per_page of $search_ids
 433          $search_ids = array_slice($search_ids, $start_from, $per_page);
 434  
 435          $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_search['Search results']);
 436          define('PUN_ACTIVE_PAGE', 'search');
 437          require  PUN_ROOT.'header.php';
 438  
 439  
 440  ?>
 441  <div class="linkst">
 442      <div class="inbox">
 443          <p class="pagelink"><?php echo $paging_links ?></p>
 444          <div class="clearer"></div>
 445      </div>
 446  </div>
 447  
 448  <?php
 449  
 450          if ($show_as == 'topics')
 451          {
 452              $topic_count = 0;
 453  
 454  ?>
 455  <div id="vf" class="blocktable">
 456      <h2><span><?php echo $lang_search['Search results'] ?></span></h2>
 457      <div class="box">
 458          <div class="inbox">
 459              <table cellspacing="0">
 460              <thead>
 461                  <tr>
 462                      <th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th>
 463                      <th class="tc2" scope="col"><?php echo $lang_common['Forum'] ?></th>
 464                      <th class="tc3" scope="col"><?php echo $lang_common['Replies'] ?></th>
 465                      <th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th>
 466                  </tr>
 467              </thead>
 468              <tbody>
 469  <?php
 470  
 471          }
 472          else if ($show_as == 'posts')
 473          {
 474              require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
 475  
 476              require  PUN_ROOT.'include/parser.php';
 477  
 478              $post_count = 0;
 479          }
 480  
 481          // Get topic/forum tracking data
 482          if (!$pun_user['is_guest'])
 483              $tracked_topics = get_tracked_topics();
 484  
 485          if ($show_as == 'posts')
 486              $result = $db->query('SELECT p.id AS pid, p.poster AS pposter, p.posted AS pposted, p.poster_id, p.message, p.hide_smilies, t.id AS tid, t.poster, t.subject, t.first_post_id, t.last_post, t.last_post_id, t.last_poster, t.num_replies, t.forum_id, f.forum_name FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE p.id IN('.implode(',', $search_ids).') ORDER BY '.$sort_by_sql.' '.$sort_dir) or error('Unable to fetch search results', __FILE__, __LINE__, $db->error());
 487          else
 488              $result = $db->query('SELECT t.id AS tid, t.poster, t.subject, t.last_post, t.last_post_id, t.last_poster, t.num_replies, t.closed, t.sticky, t.forum_id, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.id IN('.implode(',', $search_ids).') ORDER BY '.$sort_by_sql.' '.$sort_dir) or error('Unable to fetch search results', __FILE__, __LINE__, $db->error());
 489  
 490          while ($cur_search = $db->fetch_assoc($result))
 491          {
 492              $forum = '<a href="viewforum.php?id='.$cur_search['forum_id'].'">'.pun_htmlspecialchars($cur_search['forum_name']).'</a>';
 493  
 494              if ($pun_config['o_censoring'] == '1')
 495                  $cur_search['subject'] = censor_words($cur_search['subject']);
 496  
 497              if ($show_as == 'posts')
 498              {
 499                  ++$post_count;
 500                  $icon_type = 'icon';
 501  
 502                  if (!$pun_user['is_guest'] && $cur_search['last_post'] > $pun_user['last_visit'] && (!isset($tracked_topics['topics'][$cur_search['tid']]) || $tracked_topics['topics'][$cur_search['tid']] < $cur_search['last_post']) && (!isset($tracked_topics['forums'][$cur_search['forum_id']]) || $tracked_topics['forums'][$cur_search['forum_id']] < $cur_search['last_post']))
 503                  {
 504                      $item_status = 'inew';
 505                      $icon_type = 'icon icon-new';
 506                      $icon_text = $lang_topic['New icon'];
 507                  }
 508                  else
 509                  {
 510                      $item_status = '';
 511                      $icon_text = '<!-- -->';
 512                  }
 513  
 514                  if ($pun_config['o_censoring'] == '1')
 515                      $cur_search['message'] = censor_words($cur_search['message']);
 516  
 517                  $message = parse_message($cur_search['message'], $cur_search['hide_smilies']);
 518                  $pposter = pun_htmlspecialchars($cur_search['pposter']);
 519  
 520                  if ($cur_search['poster_id'] > 1)
 521                  {
 522                      if ($pun_user['g_view_users'] == '1')
 523                          $pposter = '<strong><a href="profile.php?id='.$cur_search['poster_id'].'">'.$pposter.'</a></strong>';
 524                      else
 525                          $pposter = '<strong>'.$pposter.'</strong>';
 526                  }
 527  
 528  
 529  ?>
 530  <div class="blockpost<?php echo ($post_count % 2 == 0) ? ' roweven' : ' rowodd' ?><?php if ($cur_search['pid'] == $cur_search['first_post_id']) echo ' firstpost' ?><?php if ($post_count == 1) echo ' blockpost1' ?><?php if ($item_status != '') echo ' '.$item_status ?>">
 531      <h2><span><span class="conr">#<?php echo ($start_from + $post_count) ?></span> <span><?php if ($cur_search['pid'] != $cur_search['first_post_id']) echo $lang_topic['Re'].' ' ?><?php echo $forum ?></span> <span>»&#160;<a href="viewtopic.php?id=<?php echo $cur_search['tid'] ?>"><?php echo pun_htmlspecialchars($cur_search['subject']) ?></a></span> <span>»&#160;<a href="viewtopic.php?pid=<?php echo $cur_search['pid'].'#p'.$cur_search['pid'] ?>"><?php echo format_time($cur_search['pposted']) ?></a></span></span></h2>
 532      <div class="box">
 533          <div class="inbox">
 534              <div class="postbody">
 535                  <div class="postleft">
 536                      <dl>
 537                          <dt><?php echo $pposter ?></dt>
 538                          <dd><span><?php echo $lang_topic['Replies'].' '.forum_number_format($cur_search['num_replies']) ?></span></dd>
 539                          <dd><div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo $icon_text ?></div></div></dd>
 540                      </dl>
 541                  </div>
 542                  <div class="postright">
 543                      <div class="postmsg">
 544                          <?php echo $message."\n" ?>
 545                      </div>
 546                  </div>
 547                  <div class="clearer"></div>
 548              </div>
 549          </div>
 550          <div class="inbox">
 551              <div class="postfoot clearb">
 552                  <div class="postfootright">
 553                      <ul>
 554                          <li><span><a href="viewtopic.php?id=<?php echo $cur_search['tid'] ?>"><?php echo $lang_search['Go to topic'] ?></a></span></li>
 555                          <li><span><a href="viewtopic.php?pid=<?php echo $cur_search['pid'].'#p'.$cur_search['pid'] ?>"><?php echo $lang_search['Go to post'] ?></a></span></li>
 556                      </ul>
 557                  </div>
 558              </div>
 559          </div>
 560      </div>
 561  </div>
 562  <?php
 563  
 564              }
 565              else
 566              {
 567                  ++$topic_count;
 568                  $status_text = array();
 569                  $item_status = ($topic_count % 2 == 0) ? 'roweven' : 'rowodd';
 570                  $icon_type = 'icon';
 571  
 572                  $subject = '<a href="viewtopic.php?id='.$cur_search['tid'].'">'.pun_htmlspecialchars($cur_search['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_search['poster']).'</span>';
 573  
 574                  if ($cur_search['sticky'] == '1')
 575                  {
 576                      $item_status .= ' isticky';
 577                      $status_text[] = '<span class="stickytext">'.$lang_forum['Sticky'].'</span>';
 578                  }
 579  
 580                  if ($cur_search['closed'] != '0')
 581                  {
 582                      $status_text[] = '<span class="closedtext">'.$lang_forum['Closed'].'</span>';
 583                      $item_status .= ' iclosed';
 584                  }
 585  
 586                  if (!$pun_user['is_guest'] && $cur_search['last_post'] > $pun_user['last_visit'] && (!isset($tracked_topics['topics'][$cur_search['tid']]) || $tracked_topics['topics'][$cur_search['tid']] < $cur_search['last_post']) && (!isset($tracked_topics['forums'][$cur_search['forum_id']]) || $tracked_topics['forums'][$cur_search['forum_id']] < $cur_search['last_post']))
 587                  {
 588                      $item_status .= ' inew';
 589                      $icon_type = 'icon icon-new';
 590                      $subject = '<strong>'.$subject.'</strong>';
 591                      $subject_new_posts = '<span class="newtext">[ <a href="viewtopic.php?id='.$cur_search['tid'].'&amp;action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a> ]</span>';
 592                  }
 593                  else
 594                      $subject_new_posts = null;
 595  
 596                  // Insert the status text before the subject
 597                  $subject = implode(' ', $status_text).' '.$subject;
 598  
 599                  $num_pages_topic = ceil(($cur_search['num_replies'] + 1) / $pun_user['disp_posts']);
 600  
 601                  if ($num_pages_topic > 1)
 602                      $subject_multipage = '<span class="pagestext">[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_search['tid']).' ]</span>';
 603                  else
 604                      $subject_multipage = null;
 605  
 606                  // Should we show the "New posts" and/or the multipage links?
 607                  if (!empty($subject_new_posts) || !empty($subject_multipage))
 608                  {
 609                      $subject .= !empty($subject_new_posts) ? ' '.$subject_new_posts : '';
 610                      $subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
 611                  }
 612  
 613  ?>
 614                  <tr class="<?php echo $item_status ?>">
 615                      <td class="tcl">
 616                          <div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo forum_number_format($topic_count + $start_from) ?></div></div>
 617                          <div class="tclcon">
 618                              <div>
 619                                  <?php echo $subject."\n" ?>
 620                              </div>
 621                          </div>
 622                      </td>
 623                      <td class="tc2"><?php echo $forum ?></td>
 624                      <td class="tc3"><?php echo forum_number_format($cur_search['num_replies']) ?></td>
 625                      <td class="tcr"><?php echo '<a href="viewtopic.php?pid='.$cur_search['last_post_id'].'#p'.$cur_search['last_post_id'].'">'.format_time($cur_search['last_post']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_search['last_poster']) ?></span></td>
 626                  </tr>
 627  <?php
 628  
 629              }
 630          }
 631  
 632          if ($show_as == 'topics')
 633              echo "\t\t\t".'</tbody>'."\n\t\t\t".'</table>'."\n\t\t".'</div>'."\n\t".'</div>'."\n".'</div>'."\n\n";
 634  
 635  ?>
 636  <div class="<?php echo ($show_as == 'topics') ? 'linksb' : 'postlinksb'; ?>">
 637      <div class="inbox">
 638          <p class="pagelink"><?php echo $paging_links ?></p>
 639          <div class="clearer"></div>
 640      </div>
 641  </div>
 642  <?php
 643  
 644          $footer_style = 'search';
 645          require  PUN_ROOT.'footer.php';
 646      }
 647      else
 648          message($lang_search['No hits']);
 649  }
 650  
 651  
 652  $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_search['Search']);
 653  $focus_element = array('search', 'keywords');
 654  define('PUN_ACTIVE_PAGE', 'search');
 655  require  PUN_ROOT.'header.php';
 656  
 657  ?>
 658  <div id="searchform" class="blockform">
 659      <h2><span><?php echo $lang_search['Search'] ?></span></h2>
 660      <div class="box">
 661          <form id="search" method="get" action="search.php">
 662              <div class="inform">
 663                  <fieldset>
 664                      <legend><?php echo $lang_search['Search criteria legend'] ?></legend>
 665                      <div class="infldset">
 666                          <input type="hidden" name="action" value="search" />
 667                          <label class="conl"><?php echo $lang_search['Keyword search'] ?><br /><input type="text" name="keywords" size="40" maxlength="100" /><br /></label>
 668                          <label class="conl"><?php echo $lang_search['Author search'] ?><br /><input id="author" type="text" name="author" size="25" maxlength="25" /><br /></label>
 669                          <p class="clearb"><?php echo $lang_search['Search info'] ?></p>
 670                      </div>
 671                  </fieldset>
 672              </div>
 673              <div class="inform">
 674                  <fieldset>
 675                      <legend><?php echo $lang_search['Search in legend'] ?></legend>
 676                      <div class="infldset">
 677                          <label class="conl"><?php echo $lang_search['Forum search']."\n" ?>
 678                          <br /><select id="forum" name="forum">
 679  <?php
 680  
 681  if ($pun_config['o_search_all_forums'] == '1' || $pun_user['is_admmod'])
 682      echo "\t\t\t\t\t\t\t".'<option value="-1">'.$lang_search['All forums'].'</option>'."\n";
 683  
 684  $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.redirect_url FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
 685  
 686  $cur_category = 0;
 687  while ($cur_forum = $db->fetch_assoc($result))
 688  {
 689      if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
 690      {
 691          if ($cur_category)
 692              echo "\t\t\t\t\t\t\t".'</optgroup>'."\n";
 693  
 694          echo "\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($cur_forum['cat_name']).'">'."\n";
 695          $cur_category = $cur_forum['cid'];
 696      }
 697  
 698      echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_forum['fid'].'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</option>'."\n";
 699  }
 700  
 701  ?>
 702                              </optgroup>
 703                          </select>
 704                          <br /></label>
 705                          <label class="conl"><?php echo $lang_search['Search in']."\n" ?>
 706                          <br /><select id="search_in" name="search_in">
 707                              <option value="all"><?php echo $lang_search['Message and subject'] ?></option>
 708                              <option value="message"><?php echo $lang_search['Message only'] ?></option>
 709                              <option value="topic"><?php echo $lang_search['Topic only'] ?></option>
 710                          </select>
 711                          <br /></label>
 712                          <p class="clearb"><?php echo $lang_search['Search in info'] ?></p>
 713                      </div>
 714                  </fieldset>
 715              </div>
 716              <div class="inform">
 717                  <fieldset>
 718                      <legend><?php echo $lang_search['Search results legend'] ?></legend>
 719                      <div class="infldset">
 720                          <label class="conl"><?php echo $lang_search['Sort by']."\n" ?>
 721                          <br /><select name="sort_by">
 722                              <option value="0"><?php echo $lang_search['Sort by post time'] ?></option>
 723                              <option value="1"><?php echo $lang_search['Sort by author'] ?></option>
 724                              <option value="2"><?php echo $lang_search['Sort by subject'] ?></option>
 725                              <option value="3"><?php echo $lang_search['Sort by forum'] ?></option>
 726                          </select>
 727                          <br /></label>
 728                          <label class="conl"><?php echo $lang_search['Sort order']."\n" ?>
 729                          <br /><select name="sort_dir">
 730                              <option value="DESC"><?php echo $lang_search['Descending'] ?></option>
 731                              <option value="ASC"><?php echo $lang_search['Ascending'] ?></option>
 732                          </select>
 733                          <br /></label>
 734                          <label class="conl"><?php echo $lang_search['Show as']."\n" ?>
 735                          <br /><select name="show_as">
 736                              <option value="topics"><?php echo $lang_search['Show as topics'] ?></option>
 737                              <option value="posts"><?php echo $lang_search['Show as posts'] ?></option>
 738                          </select>
 739                          <br /></label>
 740                          <p class="clearb"><?php echo $lang_search['Search results info'] ?></p>
 741                      </div>
 742                  </fieldset>
 743              </div>
 744              <p class="buttons"><input type="submit" name="search" value="<?php echo $lang_common['Submit'] ?>" accesskey="s" /></p>
 745          </form>
 746      </div>
 747  </div>
 748  <?php
 749  
 750  require  PUN_ROOT.'footer.php';


[ Powered by PHPXref - Served by Debian GNU/Linux ]