📄 search.php
字号:
$forums .= "<option value='{$cdata['forum_id']}'{$selected}> +---- {$cdata['forum_name']}\n";
}
}
}
}
$forums .= "</select>";
$cats .= "</select>";
$this->output = $this->html->form( $forums, $cats );
$this->page_title = $ibforums->lang['search_title'];
$this->nav = array(
$ibforums->lang['search_form']
);
}
function do_search( )
{
global $ibforums;
global $DB;
global $std;
global $HTTP_POST_VARS;
global $print;
if ( 0 < $ibforums->member['g_search_flood'] )
{
$flood_time = time( ) - $ibforums->member['g_search_flood'];
$DB->query( "SELECT id FROM ibf_search_results WHERE (member_id='".$ibforums->member['id']."' OR ip_address='".$ibforums->input['IP_ADDRESS']."') AND search_date > '{$flood_time}'" );
if ( $DB->get_num_rows( ) )
{
$std->error( array(
"LEVEL" => 1,
"MSG" => "search_flood",
"EXTRA" => $ibforums->member['g_search_flood']
) );
}
}
if ( $ibforums->input['namesearch'] != "" )
{
$name_filter = $this->filter_keywords( $ibforums->input['namesearch'], 1 );
}
if ( $ibforums->input['useridsearch'] != "" )
{
$keywords = $this->filter_keywords( $ibforums->input['useridsearch'] );
$this->search_type = "userid";
}
else
{
$keywords = $this->filter_keywords( $ibforums->input['keywords'] );
$this->search_type = "posts";
}
$check_keywords = trim( $keywords );
$check_keywords = str_replace( "%", "", $check_keywords );
if ( ( !$check_keywords || $check_keywords == "" || !isset( $check_keywords ) ) && $ibforums->input['joinname'] == 1 )
{
$std->error( array( "LEVEL" => 1, "MSG" => "no_search_words" ) );
}
if ( $ibforums->input['search_in'] == "titles" )
{
$this->search_in = "titles";
}
$forums = $this->get_searchable_forums( );
if ( $forums == "" )
{
$std->error( array( "LEVEL" => 1, "MSG" => "no_search_forum" ) );
}
foreach ( array( "last_post", "posts", "starter_name", "forum_id" ) as $v )
{
if ( $ibforums->input['sort_key'] == $v )
{
$this->sort_key = $v;
}
}
foreach ( array( 1, 7, 30, 365, 0 ) as $v )
{
if ( $ibforums->input['prune'] == $v )
{
$this->prune = $v;
}
}
if ( $ibforums->input['sort_order'] == "asc" )
{
$this->sort_order = "asc";
}
if ( $ibforums->input['result_type'] == "posts" )
{
$this->result_type = "posts";
}
if ( $ibforums->vars['min_search_word'] < 1 )
{
$ibforums->vars['min_search_word'] = 4;
}
if ( 0 < $this->prune )
{
$gt_lt = $ibforums->input['prune_type'] == "older" ? "<" : ">";
$time = time( ) - $ibforums->input['prune'] * 86400;
$topics_datecut = "t.last_post {$gt_lt} {$time} AND";
$posts_datecut = "p.post_date {$gt_lt} {$time} AND";
}
$name_filter = trim( $name_filter );
$member_string = "";
if ( $name_filter != "" )
{
if ( $ibforums->input['exactname'] == 1 )
{
$sql_query = "SELECT id from ibf_members WHERE lower(name)='".$name_filter."'";
}
else
{
$sql_query = "SELECT id from ibf_members WHERE name like '%".$name_filter."%'";
}
$DB->query( $sql_query );
while ( $row = $DB->fetch_row( ) )
{
$member_string .= "'".$row['id']."',";
}
$member_string = preg_replace( "/,\$/", "", $member_string );
if ( $member_string == "" )
{
$std->error( array( "LEVEL" => 1, "MSG" => "no_name_search_results" ) );
}
$posts_name = " AND p.author_id IN ({$member_string})";
$topics_name = " AND t.starter_id IN ({$member_string})";
}
if ( $ibforums->input['joinname'] == 1 )
{
if ( preg_match( "/ and|or /", $keywords ) )
{
preg_match_all( "/(^|and|or)\\s{1,}(\\S+?)\\s{1,}/", $keywords, $matches );
$title_like = "(";
$post_like = "(";
$i = 0;
for ( ; $i < count( $matches[0] ); ++$i )
{
$boolean = $matches[1][$i];
$word = trim( $matches[2][$i] );
if ( strlen( $word ) < $ibforums->vars['min_search_word'] )
{
$std->error( array(
"LEVEL" => 1,
"MSG" => "search_word_short",
"EXTRA" => $ibforums->vars['min_search_word']
) );
}
if ( $boolean )
{
$boolean = " {$boolean}";
}
$title_like .= "{$boolean} LOWER(t.title) LIKE '%{$word}%' ";
$post_like .= "{$boolean} LOWER(p.post) LIKE '%{$word}%' ";
}
$title_like .= ")";
$post_like .= ")";
}
else
{
if ( strlen( trim( $keywords ) ) < $ibforums->vars['min_search_word'] )
{
$std->error( array(
"LEVEL" => 1,
"MSG" => "search_word_short",
"EXTRA" => $ibforums->vars['min_search_word']
) );
}
$title_like = " LOWER(t.title) LIKE '%".trim( $keywords )."%' ";
$post_like = " LOWER(p.post) LIKE '%".trim( $keywords )."%' ";
}
}
$unique_id = md5( uniqid( microtime( ), 1 ) );
if ( $ibforums->input['joinname'] == 1 )
{
$topics_query = "SELECT t.tid\n\t\t\t\t\t\t\tFROM ibf_topics t\n\t\t\t\t\t\t\tWHERE {$topics_datecut} t.forum_id IN ({$forums})\n\t\t\t\t\t\t\t{$topics_name} AND t.approved=1 AND ({$title_like})";
$posts_query = "SELECT p.pid FROM ibf_posts p "."WHERE {$posts_datecut} p.forum_id IN ({$forums})"." AND p.queued <> 1"." {$posts_name} AND ({$post_like})";
}
else
{
$topics_query = "SELECT t.tid\n\t\t\t\t\t\t\tFROM ibf_topics t\n\t\t\t\t\t\t\tWHERE {$topics_datecut} t.forum_id IN ({$forums})\n\t\t\t\t\t\t\t{$topics_name}";
$posts_query = "SELECT p.pid FROM ibf_posts p "."WHERE {$posts_datecut} p.forum_id IN ({$forums})"." AND p.queued <> 1"." {$posts_name}";
}
$topics = "";
$posts = "";
$DB->query( $topics_query );
$topic_max_hits = $DB->get_num_rows( );
while ( $row = $DB->fetch_row( ) )
{
$topics .= $row['tid'].",";
}
$DB->free_result( );
$DB->query( $posts_query );
$post_max_hits = $DB->get_num_rows( );
while ( $row = $DB->fetch_row( ) )
{
$posts .= $row['pid'].",";
}
$DB->free_result( );
$topics = preg_replace( "/,\$/", "", $topics );
$posts = preg_replace( "/,\$/", "", $posts );
if ( $topics == "" && $posts == "" )
{
$std->error( array( "LEVEL" => 1, "MSG" => "no_search_results" ) );
}
$unique_id = md5( uniqid( microtime( ), 1 ) );
$str = $DB->compile_db_insert_string( array(
"id" => $unique_id,
"search_date" => time( ),
"topic_id" => $topics,
"topic_max" => $topic_max_hits,
"sort_key" => $this->sort_key,
"sort_order" => $this->sort_order,
"member_id" => $ibforums->member['id'],
"ip_address" => $ibforums->input['IP_ADDRESS'],
"post_id" => $posts,
"post_max" => $post_max_hits
) );
$DB->query( "INSERT INTO ibf_search_results ({$str['FIELD_NAMES']}) VALUES ({$str['FIELD_VALUES']})" );
$print->redirect_screen( $ibforums->lang['search_redirect'], "act=Search&CODE=show&searchid={$unique_id}&search_in=".$this->search_in."&result_type=".$this->result_type."&highlite=".urlencode( trim( $keywords ) ) );
exit( );
}
function show_results( )
{
global $ibforums;
global $DB;
global $std;
global $HTTP_POST_VARS;
if ( $read = $std->my_getcookie( "topicsread" ) )
{
$this->read_array = unserialize( stripslashes( $read ) );
}
$this->result_type = $ibforums->input['result_type'];
$this->search_in = $ibforums->input['search_in'];
$t_time = time( ) - 86400;
$DB->query( "DELETE FROM ibf_search_results WHERE search_date < '{$t_time}'" );
$this->unique_id = $ibforums->input['searchid'];
if ( $this->unique_id == "" )
{
$std->error( array( "LEVEL" => 1, "MSG" => "no_search_results" ) );
}
$DB->query( "SELECT * FROM ibf_search_results WHERE id='{$this->unique_id}'" );
$sr = $DB->fetch_row( );
$tmp_topics = $sr['topic_id'];
$topic_max_hits = "";
$tmp_posts = $sr['post_id'];
$post_max_hits = "";
$this->sort_order = $sr['sort_order'];
$this->sort_key = $sr['sort_key'];
$topics = ",";
$posts = ",";
foreach ( explode( ",", $tmp_topics ) as $tid )
{
if ( !preg_match( "/,{$tid},/", $topics ) )
{
$topics .= "{$tid},";
++$topic_max_hits;
}
}
foreach ( explode( ",", $tmp_posts ) as $pid )
{
if ( !preg_match( "/,{$pid},/", $posts ) )
{
$posts .= "{$pid},";
++$post_max_hits;
}
}
$topics = str_replace( ",,", ",", $topics );
$posts = str_replace( ",,", ",", $posts );
if ( $topics == "," && $posts == "," )
{
$std->error( array( "LEVEL" => 1, "MSG" => "no_search_results" ) );
}
$url_words = $this->convert_highlite_words( $ibforums->input['highlite'] );
if ( $this->result_type == "topics" )
{
if ( $this->search_in == "titles" )
{
$this->output .= $this->start_page( $topic_max_hits );
$DB->query( "SELECT t.*, f.id as forum_id, f.name as forum_name\n\t\t\t\t\t\t\tFROM ibf_topics t, ibf_forums f\n\t\t\t\t\t\t\t WHERE t.tid IN(0{$topics}-1) and f.id=t.forum_id\n\t\t\t\t\t\t\t ORDER BY ".$this->sort_key." ".$this->sort_order."\n\t\t\t\t\t\t\tLIMIT ".$this->first.",25" );
}
else
{
if ( $posts != "," )
{
$DB->query( "SELECT topic_id FROM ibf_posts WHERE pid IN(0{$posts}0)" );
while ( $pr = $DB->fetch_row( ) )
{
if ( !preg_match( "/,".$pr['topic_id'].",/", $topics ) )
{
$topics .= $pr['topic_id'].",";
++$topic_max_hits;
}
}
$topics = str_replace( ",,", ",", $topics );
}
$this->output .= $this->start_page( $topic_max_hits );
$DB->query( "SELECT t.*, f.id as forum_id, f.name as forum_name\n\t\t\t\t\t\t\tFROM ibf_topics t\n\t\t\t\t\t\t\t LEFT JOIN ibf_forums f ON (f.id=t.forum_id)\n\t\t\t\t\t\t\t WHERE t.tid IN(0{$topics}0)\n\t\t\t\t\t\t\t ORDER BY t.".$this->sort_key." ".$this->sort_order."\n\t\t\t\t\t\t\tLIMIT ".$this->first.",25" );
}
while ( $row = $DB->fetch_row( ) )
{
$row['keywords'] = $url_words;
$this->output .= $this->html->renderrow( $this->parse_entry( $row ) );
}
$this->output .= $this->html->end( array(
"SHOW_PAGES" => $this->links
) );
}
else
{
require( "./sources/lib/post_parser.php" );
$this->parser = new post_parser( );
if ( $this->search_in == "titles" )
{
$this->output .= $this->start_page( $topic_max_hits, 1 );
$DB->query( "SELECT t.*, p.pid, p.author_id, p.author_name, p.post_date, p.post, f.id as forum_id, f.name as forum_name\n\t\t\t\t FROM ibf_topics t\n\t\t\t\t LEFT JOIN ibf_posts p ON (t.tid=p.topic_id AND p.new_topic=1)\n\t\t\t\t LEFT JOIN ibf_forums f ON (f.id=t.forum_id)\n\t\t\t\t WHERE t.tid IN(0{$topics}-1)\n\t\t\t\t ORDER BY ".$this->sort_key." ".$this->sort_order."\n\t\t\t\t LIMIT ".$this->first.",25" );
}
else
{
if ( $topics != "," )
{
$DB->query( "SELECT pid FROM ibf_posts WHERE topic_id IN(0{$topics}0) AND new_topic=1" );
while ( $pr = $DB->fetch_row( ) )
{
if ( !preg_match( "/,".$pr['pid'].",/", $posts ) )
{
$posts .= $pr['pid'].",";
++$post_max_hits;
}
}
$posts = str_replace( ",,", ",", $posts );
}
$this->output .= $this->start_page( $post_max_hits, 1 );
$DB->query( "SELECT t.*, p.pid, p.author_id, p.author_name, p.post_date, p.post, f.id as forum_id, f.name as forum_name\n\t\t\t\t\t\t\tFROM ibf_posts p\n\t\t\t\t\t\t\t LEFT JOIN ibf_topics t ON (t.tid=p.topic_id)\n\t\t\t\t\t\t\t LEFT JOIN ibf_forums f ON (f.id=p.forum_id)\n\t\t\t\t\t\t\tWHERE p.pid IN(0{$posts}0)\n\t\t\t\t\t\t\tORDER BY ".$this->sort_key." ".$this->sort_order."\n\t\t\t\t\t\t\tLIMIT ".$this->first.",25" );
}
while ( $row = $DB->fetch_row( ) )
{
$row['keywords'] = $url_words;
$row['post_date'] = $std->get_date( $row['post_date'], "LONG" );
$this->output .= $this->html->renderpostrow( $this->parse_entry( $row, 1 ) );
}
$this->output .= $this->html->end_as_post( array(
"SHOW_PAGES" => $this->links
) );
}
$this->page_title = $ibforums->lang['search_results'];
if ( $ibforums->input['nav'] == "lv" )
{
$this->nav = array(
$ibforums->lang['nav_since_lv']
);
}
else if ( $ibforums->input['nav'] == "lt" )
{
$this->nav = array(
$ibforums->lang['nav_lt']
);
}
else
{
$this->nav = array(
"<a href='{$this->base_url}&act=Search'>{$ibforums->lang['search_form']}</a>",
$ibforums->lang['search_title']
);
}
}
function start_page( $amount, $is_post = 0 )
{
global $ibforums;
global $DB;
global $std;
$this->links = $std->build_pagelinks( array(
TOTAL_POSS => $amount,
25,
CUR_ST_VAL => $this->first,
"",
L_MULTI => $ibforums->lang['search_pages'],
BASE_URL => $this->base_url."&act=Search&nav=".$ibforums->input['nav']."&CODE=show&searchid=".$this->unique_id."&search_in=".$this->search_in."&result_type=".$this->result_type."&hl=".$url_words
) );
if ( $is_post == 0 )
{
return $this->html->start( array(
"SHOW_PAGES" => $this->links
) );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -