search.php
来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 1,763 行 · 第 1/4 页
PHP
1,763 行
<?php/*+--------------------------------------------------------------------------| Invision Power Board v2.1.6| =============================================| by Matthew Mecham| (c) 2001 - 2005 Invision Power Services, Inc.| http://www.invisionpower.com| =============================================| Web: http://www.invisionboard.com| Time: Thu, 04 May 2006 17:39:49 GMT| Release: b415613eeb952a2741ff6d53e0266428| Licence Info: http://www.invisionboard.com/?license+---------------------------------------------------------------------------| > $Date: 2006-01-05 11:02:13 +0000 (Thu, 05 Jan 2006) $| > $Revision: 114 $| > $Author: matt $+---------------------------------------------------------------------------|| > Searching procedures| > Module written by Matt Mecham| > Date started: 24th February 2002|| > Module Version Number: 1.1.0| > DBA Checked: Thu 20 May 2004| > Quality Checked: Wed 15 Sept. 2004+--------------------------------------------------------------------------*/if ( ! defined( 'IN_IPB' ) ){ print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files."; exit();}class search { var $output = ""; var $page_title = ""; var $nav = array(); var $html = ""; var $first = 0; var $search_type = 'posts'; var $sort_order = 'desc'; var $sort_key = 'last_post'; var $search_in = 'posts'; var $prune = '0'; var $st_time = array(); var $end_time = array(); var $st_stamp = ""; var $end_stamp = ""; var $result_type = "topics"; var $parser = ""; var $load_lib = 'search_mysql_man'; var $lib = ""; var $mysql_version = ""; var $true_version = ""; // max number of results var $resultlimit = 1000; var $xml_out = 0; /*-------------------------------------------------------------------------*/ // Auto run /*-------------------------------------------------------------------------*/ function auto_run() { //----------------------------------------- // Check //----------------------------------------- if (! $this->ipsclass->vars['allow_search']) { $this->ipsclass->Error( array( LEVEL => 1, MSG => 'search_off') ); } if ($this->ipsclass->member['g_use_search'] != 1) { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_permission' ) ); } if ( $read = $this->ipsclass->my_getcookie('topicsread') ) { $this->read_array = $this->ipsclass->clean_int_array( unserialize(stripslashes($read)) ); } //----------------------------------------- // Using XML? //----------------------------------------- $this->xml_out = intval( $_REQUEST['xml'] ); //----------------------------------------- // Forum jump //----------------------------------------- $this->ipsclass->forum_jump = $this->ipsclass->build_forum_jump(); //----------------------------------------- // Get the SQL version. //----------------------------------------- $this->ipsclass->DB->sql_get_version(); $this->true_version = $this->ipsclass->DB->true_version; $this->mysql_version = $this->ipsclass->DB->mysql_version; //----------------------------------------- // Sort out the required search library //----------------------------------------- $method = isset($this->ipsclass->vars['search_sql_method']) ? $this->ipsclass->vars['search_sql_method'] : 'man'; $sql = isset($this->ipsclass->vars['sql_driver']) ? $this->ipsclass->vars['sql_driver'] : 'mysql'; $this->load_lib = 'search_'.strtolower($sql).'_'.$method.'.php'; require ( ROOT_PATH."sources/lib/".$this->load_lib ); //----------------------------------------- // Require the HTML and language modules //----------------------------------------- $this->ipsclass->load_language('lang_search'); $this->ipsclass->load_language('lang_forum' ); $this->ipsclass->load_template('skin_search'); $this->base_url = $this->ipsclass->base_url; //----------------------------------------- // Suck in libby //----------------------------------------- $this->lib = new search_lib($this); $this->lib->ipsclass =& $this->ipsclass; $this->first = intval($this->ipsclass->input['st']); //----------------------------------------- // What to do? //----------------------------------------- if (! isset($this->ipsclass->member['g_use_search']) ) { $this->ipsclass->Error( array( LEVEL => 1, MSG => 'cant_use_feature') ); } switch($this->ipsclass->input['CODE']) { case '01': $this->do_search(); break; case 'getnew': $this->get_new_posts(); break; case 'show': $this->show_results(); break; case 'getreplied': $this->get_replies(); break; case 'lastten': $this->get_last_ten(); break; case 'getalluser': $this->get_all_user(); break; case 'simpleresults': $this->show_simple_results(); break; case 'explain': $this->show_boolean_explain(); break; case 'searchtopic': $this->search_topic(); break; case 'gettopicsuser': $this->get_topics_user(); break; case 'getactive': $this->ipsclass->input['active'] = 1; $this->get_new_posts(); break; default: $this->show_form(); break; } // If we have any HTML to print, do so... $this->ipsclass->print->add_output("$this->output"); $this->ipsclass->print->do_output( array( 'TITLE' => $this->page_title, 'JS' => 0, NAV => $this->nav ) ); } /*-------------------------------------------------------------------------*/ // Do simple search /*-------------------------------------------------------------------------*/ function show_simple_results() { $result = $this->lib->do_simple_search(); } /*-------------------------------------------------------------------------*/ // Search topic /*-------------------------------------------------------------------------*/ function search_topic() { $this->topic_id = intval($this->ipsclass->input['topic']); $this->topic_search_only = 1; $this->result_type = 'posts'; $this->search_type = 'posts'; $this->search_in = 'posts'; $this->do_search(); } /*-------------------------------------------------------------------------*/ // Get all posts by a member /*-------------------------------------------------------------------------*/ function get_topics_user() { //----------------------------------------- // Do we have flood control enabled? //----------------------------------------- if ($this->ipsclass->member['g_search_flood'] > 0) { $flood_time = time() - $this->ipsclass->member['g_search_flood']; //----------------------------------------- // Get any old search results.. //----------------------------------------- $this->ipsclass->DB->simple_construct( array( 'select' => 'id', 'from' => 'search_results', 'where' => "(member_id='".$this->ipsclass->member['id']."' OR ip_address='".$this->ipsclass->input['IP_ADDRESS']."') AND search_date > '$flood_time'" ) ); $this->ipsclass->DB->simple_exec(); if ( $this->ipsclass->DB->get_num_rows() ) { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'search_flood', 'EXTRA' => $this->ipsclass->member['g_search_flood']) ); } } $this->ipsclass->input['forums'] = 'all'; $forums = $this->get_searchable_forums(); $mid = intval($this->ipsclass->input['mid']); //----------------------------------------- // Do we have any forums to search in? //----------------------------------------- if ($forums == "") { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_forum') ); } if ($mid == "") { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) ); } //----------------------------------------- // Get the topic ID's to serialize and store into // the database //----------------------------------------- $this->ipsclass->DB->simple_construct( array( 'select' => 'count(*) as count', 'from' => 'topics t', 'where' => "t.approved=1 AND t.forum_id IN($forums) AND t.starter_id=$mid" ) ); $this->ipsclass->DB->simple_exec(); $row = $this->ipsclass->DB->fetch_row(); $results = intval($row['count']); //----------------------------------------- // Do we have any results? //----------------------------------------- if ( ! $results ) { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) ); } //----------------------------------------- // Cache query //----------------------------------------- $this->ipsclass->DB->simple_construct( array( 'select' => 't.*, t.title as topic_title', 'from' => 'topics t', 'where' => "t.approved=1 AND t.forum_id IN($forums) AND t.starter_id=$mid", 'order' => "t.last_post DESC" ) ); $query_to_cache = $this->ipsclass->DB->cur_query; $this->ipsclass->DB->flush_query(); //----------------------------------------- // If we are still here, store the data into the database... //----------------------------------------- $unique_id = md5(uniqid(microtime(),1)); $this->ipsclass->DB->do_insert( 'search_results', array ( 'id' => $unique_id, 'search_date' => time(), 'post_max' => $results, 'sort_key' => $this->sort_key, 'sort_order' => $this->sort_order, 'member_id' => $this->ipsclass->member['id'], 'ip_address' => $this->ipsclass->input['IP_ADDRESS'], 'query_cache' => $query_to_cache ) ); $this->ipsclass->boink_it( $this->ipsclass->base_url."act=Search&nav=au&CODE=show&searchid=$unique_id&search_in=topics&result_type=topics" ); } /*-------------------------------------------------------------------------*/ // Get all posts by a member /*-------------------------------------------------------------------------*/ function get_all_user() { //----------------------------------------- // Do we have flood control enabled? //----------------------------------------- if ($this->ipsclass->member['g_search_flood'] > 0) { $flood_time = time() - $this->ipsclass->member['g_search_flood']; // Get any old search results.. $this->ipsclass->DB->simple_construct( array( 'select' => 'id', 'from' => 'search_results', 'where' => "(member_id='".$this->ipsclass->member['id']."' OR ip_address='".$this->ipsclass->input['IP_ADDRESS']."') AND search_date > '$flood_time'" ) ); $this->ipsclass->DB->simple_exec(); if ( $this->ipsclass->DB->get_num_rows() ) { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'search_flood', 'EXTRA' => $this->ipsclass->member['g_search_flood']) ); } } $this->ipsclass->input['forums'] = 'all'; $forums = $this->get_searchable_forums(); $mid = intval($this->ipsclass->input['mid']); //----------------------------------------- // Do we have any forums to search in? //----------------------------------------- if ($forums == "") { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_forum') ); } if ($mid == "") { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) ); } //----------------------------------------- // Get the topic ID's to serialize and store into // the database //----------------------------------------- $this->ipsclass->DB->cache_add_query( 'search_get_all_user_count', array( 'mid' => $mid, 'forums' => $forums ) ); $this->ipsclass->DB->cache_exec_query(); $row = $this->ipsclass->DB->fetch_row(); $results = intval($row['count']); //----------------------------------------- // Do we have any results? //----------------------------------------- if ( ! $results ) { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) ); } //----------------------------------------- // Cache query //----------------------------------------- $this->ipsclass->DB->cache_add_query( 'search_get_all_user_query', array( 'mid' => $mid, 'forums' => $forums ) ); $query_to_cache = $this->ipsclass->DB->cur_query; $this->ipsclass->DB->flush_query(); //----------------------------------------- // If we are still here, store the data into the database... //----------------------------------------- $unique_id = md5(uniqid(microtime(),1)); $this->ipsclass->DB->do_insert( 'search_results', array ( 'id' => $unique_id, 'search_date' => time(), 'post_max' => $results, 'sort_key' => $this->sort_key, 'sort_order' => $this->sort_order, 'member_id' => $this->ipsclass->member['id'], 'ip_address' => $this->ipsclass->input['IP_ADDRESS'], 'query_cache' => $query_to_cache ) ); $this->ipsclass->boink_it( $this->ipsclass->base_url."act=Search&nav=au&CODE=show&searchid=$unique_id&search_in=posts&result_type=posts" ); } /*-------------------------------------------------------------------------*/ // Get new posts /*-------------------------------------------------------------------------*/ function get_new_posts() { if ( ! $this->ipsclass->member['id'] and ! $this->ipsclass->input['active'] ) { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) ); } //----------------------------------------- // Do we have flood control enabled? //----------------------------------------- if ($this->ipsclass->member['g_search_flood'] > 0) { $flood_time = time() - $this->ipsclass->member['g_search_flood'];
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?