Beehive PHP Cross Reference Discussion Forums

Source: /lsearch.php - 272 lines - 11986 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*======================================================================
   4  Copyright Project Beehive Forum 2002
   5  
   6  This file is part of Beehive Forum.
   7  
   8  Beehive Forum is free software; you can redistribute it and/or modify
   9  it under the terms of the GNU General Public License as published by
  10  the Free Software Foundation; either version 3 of the License, or
  11  (at your option) any later version.
  12  
  13  Beehive Forum is distributed in the hope that it will be useful,
  14  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  GNU General Public License for more details.
  17  
  18  You should have received a copy of the GNU General Public License
  19  along with Beehive; if not, write to the Free Software
  20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  21  USA
  22  ======================================================================*/
  23  
  24  // Bootstrap
  25  require_once  'lboot.php';
  26  
  27  // Required includes
  28  require_once  BH_INCLUDE_PATH . 'constants.inc.php';
  29  require_once  BH_INCLUDE_PATH . 'fixhtml.inc.php';
  30  require_once  BH_INCLUDE_PATH . 'form.inc.php';
  31  require_once  BH_INCLUDE_PATH . 'format.inc.php';
  32  require_once  BH_INCLUDE_PATH . 'forum.inc.php';
  33  require_once  BH_INCLUDE_PATH . 'header.inc.php';
  34  require_once  BH_INCLUDE_PATH . 'html.inc.php';
  35  require_once  BH_INCLUDE_PATH . 'light.inc.php';
  36  require_once  BH_INCLUDE_PATH . 'messages.inc.php';
  37  require_once  BH_INCLUDE_PATH . 'poll.inc.php';
  38  require_once  BH_INCLUDE_PATH . 'search.inc.php';
  39  require_once  BH_INCLUDE_PATH . 'session.inc.php';
  40  require_once  BH_INCLUDE_PATH . 'thread.inc.php';
  41  require_once  BH_INCLUDE_PATH . 'threads.inc.php';
  42  require_once  BH_INCLUDE_PATH . 'word_filter.inc.php';
  43  // End Required includes
  44  
  45  // Check we're logged in correctly
  46  if (!session::logged_in()) {
  47      html_guest_error();
  48  }
  49  
  50  if (isset($_POST['fid']) && is_numeric($_POST['fid'])) {
  51      $search_folder_fid = $_POST['fid'];
  52  } else {
  53      $search_folder_fid = 0;
  54  }
  55  
  56  $search_date_from_array = array(
  57      SEARCH_FROM_TODAY => gettext("Today"),
  58      SEARCH_FROM_YESTERDAY => gettext("Yesterday"),
  59      SEARCH_FROM_DAYBEFORE => gettext("Day before yesterday"),
  60      SEARCH_FROM_ONE_WEEK_AGO => sprintf(gettext("%s week ago"), 1),
  61      SEARCH_FROM_TWO_WEEKS_AGO => sprintf(gettext("%s weeks ago"), 2),
  62      SEARCH_FROM_THREE_WEEKS_AGO => sprintf(gettext("%s weeks ago"), 3),
  63      SEARCH_FROM_ONE_MONTH_AGO => sprintf(gettext("%s month ago"), 1),
  64      SEARCH_FROM_TWO_MONTHS_AGO => sprintf(gettext("%s months ago"), 2),
  65      SEARCH_FROM_THREE_MONTHS_AGO => sprintf(gettext("%s months ago"), 3),
  66      SEARCH_FROM_SIX_MONTHS_AGO => sprintf(gettext("%s months ago"), 6),
  67      SEARCH_FROM_ONE_YEAR_AGO => sprintf(gettext("%s year ago"), 1),
  68      SEARCH_FROM_BEGINNING_OF_TIME => gettext("Beginning of time")
  69  );
  70  
  71  $search_date_to_array = array(
  72      SEARCH_TO_NOW => gettext("Now"),
  73      SEARCH_TO_TODAY => gettext("Today"),
  74      SEARCH_TO_YESTERDAY => gettext("Yesterday"),
  75      SEARCH_TO_DAYBEFORE => gettext("Day before yesterday"),
  76      SEARCH_TO_ONE_WEEK_AGO => sprintf(gettext("%s week ago"), 1),
  77      SEARCH_TO_TWO_WEEKS_AGO => sprintf(gettext("%s weeks ago"), 2),
  78      SEARCH_TO_THREE_WEEKS_AGO => sprintf(gettext("%s weeks ago"), 3),
  79      SEARCH_TO_ONE_MONTH_AGO => sprintf(gettext("%s month ago"), 1),
  80      SEARCH_TO_TWO_MONTHS_AGO => sprintf(gettext("%s months ago"), 2),
  81      SEARCH_TO_THREE_MONTHS_AGO => sprintf(gettext("%s months ago"), 3),
  82      SEARCH_TO_SIX_MONTHS_AGO => sprintf(gettext("%s months ago"), 6),
  83      SEARCH_TO_ONE_YEAR_AGO => sprintf(gettext("%s year ago"), 1)
  84  );
  85  
  86  if (!$folder_dropdown = light_folder_search_dropdown($search_folder_fid)) {
  87      html_draw_error(gettext("There are no folders available."));
  88  }
  89  
  90  $min_length = 4;
  91  $max_length = 84;
  92  
  93  search_get_word_lengths($min_length, $max_length);
  94  
  95  if (isset($_POST) && sizeof($_POST) > 0) {
  96  
  97      $page = 1;
  98  
  99      $search_arguments = array(
 100          'user_include' => SEARCH_FILTER_USER_POSTS,
 101      );
 102  
 103      $search_no_matches = false;
 104  
 105      if (isset($_POST['search_string']) && strlen(trim($_POST['search_string'])) > 0) {
 106          $search_arguments['search_string'] = trim($_POST['search_string']);
 107      }
 108  
 109      if (isset($_POST['username']) && strlen(trim($_POST['username'])) > 0) {
 110          $search_arguments['username'] = trim($_POST['username']);
 111      }
 112  
 113      if (isset($_POST['user_include']) && is_numeric($_POST['user_include'])) {
 114          $search_arguments['user_include'] = $_POST['user_include'];
 115      }
 116  
 117      if (isset($_POST['fid']) && is_numeric($_POST['fid'])) {
 118          $search_arguments['fid'] = $_POST['fid'];
 119      }
 120  
 121      if (isset($_POST['date_from']) && is_numeric($_POST['date_from'])) {
 122          $search_arguments['date_from'] = $_POST['date_from'];
 123      }
 124  
 125      if (isset($_POST['date_to']) && is_numeric($_POST['date_to'])) {
 126          $search_arguments['date_to'] = $_POST['date_to'];
 127      }
 128  
 129      $error = SEARCH_NO_ERROR;
 130  
 131      if (!($search_success = search_execute($search_arguments, $error))) {
 132  
 133          switch ($error) {
 134  
 135              case SEARCH_NO_MATCHES:
 136  
 137                  $search_no_matches = true;
 138                  $valid = false;
 139  
 140                  break;
 141  
 142              case SEARCH_USER_NOT_FOUND:
 143  
 144                  $error_msg_array[] = gettext("The username you specified in the to or from field was not found.");
 145                  $valid = false;
 146  
 147                  break;
 148  
 149              case SEARCH_FREQUENCY_TOO_GREAT:
 150  
 151                  $search_limit_count = forum_get_setting('search_limit_count', 'is_numeric', 1);
 152                  $search_limit_time = forum_get_setting('search_limit_time', 'is_numeric', 30);
 153                  $error_msg_array[] = sprintf(gettext("You can only perform %d search(es) every %s seconds."), $search_limit_count, $search_limit_time);
 154                  break;
 155  
 156              case SEARCH_SPHINX_UNAVAILABLE:
 157  
 158                  $error_msg_array[] = gettext("Search is currently unavailable. Please try again later.");
 159                  break;
 160          }
 161  
 162      } else {
 163  
 164          header_redirect("lsearch.php?webtag=$webtag&page=1");
 165          exit;
 166      }
 167  
 168  } else if (isset($_GET['page']) && is_numeric($_GET['page'])) {
 169  
 170      $page = $_GET['page'];
 171  
 172      if (($search_results_array = search_fetch_results($page)) !== false) {
 173  
 174          light_html_draw_top();
 175  
 176          light_thread_list_draw_top(SEARCH_RESULTS);
 177  
 178          if ($page > 1) {
 179              echo "<div class=\"search_pagination\"><a href=\"lsearch.php?webtag=$webtag&amp;page=", ($page - 1), "\">", gettext("Previous 20 results"), "</a></div>\n";
 180          } else {
 181              echo "<div class=\"search_pagination\">", gettext("Found"), ": {$search_results_array['result_count']} ", gettext("matches"), "</div>\n";
 182          }
 183  
 184          echo "<ol start=\"", (($page * 20) - 20) + 1, "\">\n";
 185  
 186          foreach ($search_results_array['result_array'] as $search_result) {
 187  
 188              if (($message = messages_get($search_result['TID'], $search_result['PID'], 1)) !== false) {
 189  
 190                  if (($thread_data = thread_get($search_result['TID'])) !== false) {
 191  
 192                      $message['TITLE'] = trim($thread_data['TITLE']);
 193  
 194                      // Fetch the messaage content, strip the signature and remove HTML.
 195                      $message['CONTENT'] = message_get_content($search_result['TID'], $search_result['PID']);
 196                      $message['CONTENT'] = message_apply_formatting($message['CONTENT'], true);
 197                      $message['CONTENT'] = trim(strip_tags($message['CONTENT']));
 198  
 199                      // Limit thread title to 20 characters.
 200                      if (mb_strlen($message['TITLE']) > 20) {
 201                          $message['TITLE'] = word_filter_add_ob_tags(mb_substr($message['TITLE'], 0, 20), true) . "&hellip;";
 202                      } else {
 203                          $message['TITLE'] = word_filter_add_ob_tags($message['TITLE'], true);
 204                      }
 205  
 206                      // Limit displayed post content to 35 characters
 207                      if (mb_strlen($message['CONTENT']) > 70) {
 208                          $message['CONTENT'] = word_filter_add_ob_tags(fix_html(mb_substr($message['CONTENT'], 0, 70)), true) . "&hellip;";
 209                      } else {
 210                          $message['CONTENT'] = word_filter_add_ob_tags($message['CONTENT'], true);
 211                      }
 212  
 213                      if ((thread_is_poll($search_result['TID']) && $search_result['PID'] == 1) || strlen($message['CONTENT']) < 1) {
 214  
 215                          echo "  <li><p><a href=\"lmessages.php?webtag=$webtag&amp;msg={$search_result['TID']}.{$search_result['PID']}&amp;hightlight=yes\"><b>{$message['TITLE']}</b></a><br />";
 216                          echo "<span class=\"smalltext\"><b>", gettext("From"), ":</b> ", word_filter_add_ob_tags(format_user_name($search_result['FROM_LOGON'], $search_result['FROM_NICKNAME']), true), ", ", format_time($search_result['CREATED']), "</span></p></li>\n";
 217  
 218                      } else {
 219  
 220                          echo "  <li><p><a href=\"lmessages.php?webtag=$webtag&amp;msg={$search_result['TID']}.{$search_result['PID']}&amp;highlight=yes\"><b>{$message['TITLE']}</b></a><br />";
 221                          echo "{$message['CONTENT']}<br /><span class=\"smalltext\"><b>", gettext("From"), ":</b> ", word_filter_add_ob_tags(format_user_name($search_result['FROM_LOGON'], $search_result['FROM_NICKNAME']), true), ", ", format_time($search_result['CREATED']), "</span></p></li>\n";
 222                      }
 223                  }
 224              }
 225          }
 226  
 227          echo "</ol>\n";
 228  
 229          if (ceil($search_results_array['result_count'] / 20) > $page) {
 230              echo "<div class=\"search_pagination\"><a href=\"lsearch.php?webtag=$webtag&amp;page=", ($page + 1), "\">", gettext("Next 20 results"), "</a></div>\n";
 231          }
 232  
 233      } else {
 234  
 235          light_html_draw_top();
 236  
 237          light_thread_list_draw_top(SEARCH_RESULTS);
 238  
 239          echo "<img src=\"", html_style_image('search.png'), "\" alt=\"", gettext("matches"), "\" title=\"", gettext("matches"), "\" />&nbsp;", gettext("Found"), ": 0 ", gettext("matches"), "<br /><br />\n";
 240      }
 241  
 242      light_html_draw_bottom();
 243      exit;
 244  }
 245  
 246  light_html_draw_top();
 247  
 248  if (isset($error_msg_array) && sizeof($error_msg_array) > 0) {
 249  
 250      light_html_display_error_array($error_msg_array);
 251  
 252  } else if (isset($search_no_matches) && $search_no_matches == true) {
 253  
 254      light_html_display_error_msg(gettext("Search Returned No Results"));
 255  }
 256  
 257  echo "<form accept-charset=\"utf-8\" id=\"search_form\" method=\"post\" action=\"lsearch.php\" target=\"_self\">\n";
 258  echo form_input_hidden('webtag', htmlentities_array($webtag)), "\n";
 259  echo "<div class=\"search\">\n";
 260  echo "<h3>", gettext("Search discussions"), "</h3>\n";
 261  echo "<div class=\"search_inner\">\n";
 262  echo "<div class=\"search_keywords\">", gettext("Keywords"), ":", light_form_input_text("search_string", (isset($search_arguments['search_string']) ? htmlentities_array($search_arguments['search_string']) : ''), 30), "</div>\n";
 263  echo "<div class=\"search_user\">", gettext("Username (optional)"), ":", light_form_input_text("username", (isset($search_arguments['username']) ? htmlentities_array($search_arguments['username']) : ''), 30), "</div>\n";
 264  echo "<div class=\"search_folder\">", gettext("Folder(s)"), ":", $folder_dropdown, "</div>\n";
 265  echo "<div class=\"search_date\">", gettext("Posted From"), ":", light_form_dropdown_array("date_from", $search_date_from_array, (isset($search_arguments['date_from']) && in_array($search_arguments['date_from'], array_keys($search_date_from_array)) ? $search_arguments['date_from'] : SEARCH_FROM_ONE_MONTH_AGO)), "</div>\n";
 266  echo "<div class=\"search_date\">", gettext("Posted to"), ":", light_form_dropdown_array("date_to", $search_date_to_array, (isset($search_arguments['date_to']) && in_array($search_arguments['date_to'], array_keys($search_date_from_array)) ? $search_arguments['date_to'] : SEARCH_TO_TODAY)), "</div>\n";
 267  echo "<div class=\"search_buttons\">", light_form_submit("search_submit", gettext("Find")), "</div>";
 268  echo "</div>";
 269  echo "</div>";
 270  echo "</form>";
 271  
 272  light_html_draw_bottom();

title

Description

title

Description

title

Description

title

title

Body