search_mysql_ftext.php
来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 879 行 · 第 1/2 页
PHP
879 行
if ( $name_filter != "" AND $this->ipsclass->input['keywords'] != "" ) { $type = 'joined'; } else if ( $name_filter == "" AND $this->ipsclass->input['keywords'] != "" ) { $type= 'postonly'; } else if ( $name_filter != "" AND $this->ipsclass->input['keywords'] == "" ) { $type='nameonly'; } //----------------------------------------- if ( $this->is->mysql_version >= 40010 ) { $boolean = 'IN BOOLEAN MODE'; $keywords = $this->is->filter_ftext_keywords($this->ipsclass->input['keywords']); } else { $keywords = $this->is->filter_keywords($this->ipsclass->input['keywords']); } $check_keywords = trim($keywords); if ( (! $check_keywords) or ($check_keywords == "") or (! isset($check_keywords) ) ) { if ($this->ipsclass->input['namesearch'] == "") { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_words') ); } } else { if ( strlen(trim($keywords)) < $this->ipsclass->vars['min_search_word'] and $type != 'nameonly' ) { if ( $this->is->xml_out ) { print sprintf( $this->ipsclass->lang['xml_char'], $this->ipsclass->vars['min_search_word'] ); exit(); } else { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'search_word_short', 'EXTRA' => $this->ipsclass->vars['min_search_word']) ); } } } //----------------------------------------- // Check for filter abuse.. //----------------------------------------- $tmp = explode( ' ', $keywords ); foreach( $tmp as $t ) { if ( ! $t ) { continue; } $t = preg_replace( "#[\+\-\*\.]#", "", $t ); //----------------------------------------- // Allow abc* but not a*** //----------------------------------------- if ( ( strlen( $t ) < $this->ipsclass->vars['min_search_word'] ) and $type != 'nameonly' ) { if ( $this->is->xml_out ) { print sprintf( $this->ipsclass->lang['xml_char'], $this->ipsclass->vars['min_search_word'] ); exit(); } else { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'search_word_short', 'EXTRA' => $this->ipsclass->vars['min_search_word']) ); } } } //----------------------------------------- if ($this->ipsclass->input['search_in'] == 'titles') { $this->is->search_in = 'titles'; } //----------------------------------------- $forums = $this->is->get_searchable_forums(); //----------------------------------------- // Do we have any forums to search in? //----------------------------------------- if ($forums == "") { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_forum') ); } //----------------------------------------- foreach( array( 'last_post', 'posts', 'starter_name', 'forum_id' ) as $v ) { if ( $this->ipsclass->input['sort_key'] == $v ) { $this->is->sort_key = $v; } } //----------------------------------------- foreach ( array( 1, 7, 30, 60, 90, 180, 365, 0 ) as $v ) { if ($this->ipsclass->input['prune'] == $v) { $this->is->prune = $v; } } //----------------------------------------- if ($this->ipsclass->input['sort_order'] == 'asc') { $this->is->sort_order = 'asc'; } //----------------------------------------- if ($this->ipsclass->input['result_type'] == 'posts') { $this->is->result_type = 'posts'; } if ( $this->ipsclass->vars['min_search_word'] < 1 ) { $this->ipsclass->vars['min_search_word'] = 4; } //----------------------------------------- // Add on the prune days //----------------------------------------- if ($this->is->prune > 0) { $gt_lt = $this->ipsclass->input['prune_type'] == 'older' ? "<" : ">"; $time = time() - ($this->ipsclass->input['prune'] * 86400); if ( $this->is->result_type == 'posts' ) { $topics_datecut = "t.start_date $gt_lt $time AND"; } else { $topics_datecut = "t.last_post $gt_lt $time AND"; } $posts_datecut = "p.post_date $gt_lt $time AND"; } //----------------------------------------- // Only allowed to see their own topics? //----------------------------------------- if ( ! $this->ipsclass->member['g_other_topics'] ) { $name_filter = ""; $posts_name = " AND t.starter_id=".$this->ipsclass->member['id']; $topics_name = " AND t.starter_id=".$this->ipsclass->member['id']; } //----------------------------------------- // Is this a membername search? //----------------------------------------- $name_filter = trim( $name_filter ); $member_string = ""; if ( $name_filter != "" ) { //----------------------------------------- // Get all the possible matches for the supplied name from the DB //----------------------------------------- $name_filter = str_replace( '|', "|", $name_filter ); if ($this->ipsclass->input['exactname'] == 1) { $sql_query = "SELECT id from ibf_members WHERE LOWER(members_display_name)='".$name_filter."'"; } else { $sql_query = "SELECT id from ibf_members WHERE members_display_name like '%".$name_filter."%'"; } $this->ipsclass->DB->query( $sql_query ); while ($row = $this->ipsclass->DB->fetch_row()) { $member_string .= "'".$row['id']."',"; } $member_string = preg_replace( "/,$/", "", $member_string ); // Error out of we matched no members if ($member_string == "") { $this->ipsclass->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 ( $type != 'nameonly' ) { if (strlen(trim($keywords)) < $this->ipsclass->vars['min_search_word']) { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'search_word_short', 'EXTRA' => $this->ipsclass->vars['min_search_word']) ); } } $unique_id = md5(uniqid(microtime(),1)); if ($type != 'nameonly') { if ( ! $this->is->topic_search_only ) { $topics_query = "SELECT t.tid, t.approved, t.forum_id FROM ibf_topics t WHERE $topics_datecut t.forum_id IN ($forums) $topics_name AND t.approved=1 AND MATCH(title) AGAINST ('".trim($keywords)."' $boolean)"; $posts_query = "SELECT p.pid, p.queued, t.approved, t.forum_id FROM ibf_posts p LEFT JOIN ibf_topics t ON ( p.topic_id=t.tid ) WHERE $posts_datecut t.forum_id IN ($forums) AND p.queued=0 $posts_name AND MATCH(post) AGAINST ('".trim($keywords)."' $boolean)"; } else { //----------------------------------------- // Search in topic only //----------------------------------------- $posts_query = "SELECT p.pid, p.queued, t.approved, t.forum_id FROM ibf_posts p LEFT JOIN ibf_topics t ON ( p.topic_id=t.tid ) WHERE p.topic_id={$this->is->topic_id} AND $posts_datecut t.forum_id IN ($forums) AND p.queued=0 $posts_name AND MATCH(post) AGAINST ('".trim($keywords)."' $boolean)"; } } else { $topics_query = "SELECT t.tid, t.approved, t.forum_id FROM ibf_topics t WHERE $topics_datecut t.forum_id IN ($forums) $topics_name AND t.approved=1"; $posts_query = "SELECT p.pid, p.queued, t.approved, t.forum_id FROM ibf_posts p LEFT JOIN ibf_topics t ON ( p.topic_id=t.tid ) WHERE $posts_datecut t.forum_id IN ($forums) AND p.queued=0 $posts_name"; } //print $topics_query."<br />".$posts_query; exit(); //----------------------------------------- // Get the topic ID's to serialize and store into // the database //----------------------------------------- $topics = ""; $posts = ""; $topic_array = array(); $topic_tmp = array(); $post_array = array(); $post_tmp = array(); $t_cnt = 0; $p_cnt = 0; $more = ""; //----------------------------------------- // TID: Get 'em //----------------------------------------- if ( ! $this->is->topic_search_only ) { $this->ipsclass->DB->query($topics_query); while ($row = $this->ipsclass->DB->fetch_row() ) { if( !$row['approved'] ) { if( !$this->ipsclass->member['g_is_supmod'] ) { if( !in_array( $row['forum_id'], $my_invisible_forums_t ) ) { continue; } } } $topic_tmp[ $row['tid'] ] = $row['tid']; } $this->ipsclass->DB->free_result(); } //----------------------------------------- // TID Sort 'em //----------------------------------------- krsort( $topic_tmp ); foreach( $topic_tmp as $id => $tid ) { $t_cnt++; if ( $t_cnt > $this->resultlimit ) { $more = 1; break; } $topic_array[ $tid ] = $tid; } //----------------------------------------- // PID: Get 'em //----------------------------------------- $this->ipsclass->DB->query($posts_query); while ($row = $this->ipsclass->DB->fetch_row() ) { if( $row['queued'] ) { if( !$this->ipsclass->member['g_is_supmod'] ) { if( !in_array( $row['forum_id'], $my_invisible_forums_p ) ) { continue; } } } if( !$row['approved'] ) { if( !$this->ipsclass->member['g_is_supmod'] ) { if( !in_array( $row['forum_id'], $my_invisible_forums_t ) ) { continue; } } } $post_tmp[ $row['pid'] ] = $row['pid']; } $this->ipsclass->DB->free_result(); //----------------------------------------- // PID Sort 'em //----------------------------------------- krsort( $post_tmp ); foreach( $post_tmp as $id => $pid ) { $p_cnt++; if ( $p_cnt > $this->resultlimit ) { $more = 1; break; } $post_array[ $pid ] = $pid; } //----------------------------------------- $topics = implode( ",", $topic_array ); $posts = implode( ",", $post_array ); //----------------------------------------- // Do we have any results? //----------------------------------------- if ($topics == "" and $posts == "") { if ( $this->is->xml_out ) { print sprintf( $this->ipsclass->lang['xml_nomatches'], str_replace( '"', "", $keywords ) ); exit(); } else { $this->output .= $this->ipsclass->compiled_templates['skin_search']->search_error_page($this->ipsclass->input['keywords']); $this->ipsclass->print->add_output( $this->output ); $this->ipsclass->print->do_output( array( 'TITLE' => $this->ipsclass->lang['g_simple_title'], 'JS' => 0, NAV => array( $this->ipsclass->lang['g_simple_title'] ) ) ); } } //----------------------------------------- // If we are still here, return data like a good // boy (or girl). Yes Reg; or girl. // What have the Romans ever done for us? //----------------------------------------- return array( 'topic_id' => $topics, 'post_id' => $posts, 'topic_max' => intval( count( $topic_array ) ), 'post_max' => intval( count( $post_array ) ), 'keywords' => str_replace( '"', "", $keywords ), 'query_cache' => $more, ); } }?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?