NoPaste

phpBB-Update f?r Titel-Suche

von Imhotep

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

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN