search.php

来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 1,763 行 · 第 1/4 页

PHP
1,763 行
字号
																   'sort_order'  => $this->sort_order,																   'member_id'   => $this->ipsclass->member['id'],																   'ip_address'  => $this->ipsclass->input['IP_ADDRESS'],																   'post_id'     => $result['post_id'],																   'post_max'    => $result['post_max'],																   'query_cache' => $result['query_cache'],													   )        );				if ( $this->xml_out )		{			$result['post_max'] = $result['post_max'] < 1 ? 1 : $result['post_max'];						print sprintf( $this->ipsclass->lang['xml_matches'], preg_replace( "#^[\+\-]#", "", $result['keywords'] ), $result['post_max'], $this->ipsclass->base_url.$url );			exit();		}		else		{			$this->ipsclass->print->redirect_screen( $this->ipsclass->lang['search_redirect'] , $url );		}	}		/*-------------------------------------------------------------------------*/	// Show Results	// Shows the results of the search	/*-------------------------------------------------------------------------*/		function show_results()	{		$this->cached_query   = 0;		$this->cached_matches = 0;	       	//-----------------------------------------       	// Grab forums lib       	//-----------------------------------------       	       	require_once( ROOT_PATH."sources/action_public/forums.php" );       	$this->forums = new forums();       	$this->forums->ipsclass =& $this->ipsclass;       	$this->forums->init();       	       	//-----------------------------------------       	// Start...       	//-----------------------------------------		        $this->result_type  = $this->ipsclass->input['result_type'];        $this->search_in    = $this->ipsclass->input['search_in'];				//-----------------------------------------		// We have a search ID, so lets get the parsed results.		//-----------------------------------------				$this->unique_id = $this->ipsclass->input['searchid'];				if ($this->unique_id == "")		{			$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) );		}				$this->ipsclass->DB->simple_construct( array( 'select' => '*',									  				  'from'   => 'search_results',									  				  'where'  => "id='{$this->unique_id}'" ) );		$this->ipsclass->DB->simple_exec();				$sr = $this->ipsclass->DB->fetch_row();				$this->sort_order   = $sr['sort_order'];		$this->sort_key     = $sr['sort_key'];		$this->more_results = $sr['query_cache'] == 1 ? 1 : 0;				//-----------------------------------------		// Cached query or PID/TID list?		// query_cache == 1 if more than 300 results		//-----------------------------------------				if ( $sr['query_cache'] and $sr['query_cache'] != 1 )		{			$this->cached_query   = $sr['query_cache'];			$this->cached_matches = $sr['post_max'];						$this->ipsclass->DB->cur_query = $this->cached_query;			$this->ipsclass->DB->simple_limit_with_check($this->first, "25");			$this->cached_query = $this->ipsclass->DB->cur_query;			$this->ipsclass->DB->flush_query();		}		else		{			$topics         = $sr['topic_id'];			$topic_max_hits = $sr['topic_max'];			$posts          = $sr['post_id'];			$post_max_hits  = $sr['post_max'];						//-----------------------------------------			// Build array			//-----------------------------------------						$topic_array = array();			$post_array  = array();						if ( $topics )			{				foreach( explode( ",", $topics ) as $t )				{					$topic_array[ $t ] = $t;				}			}						if ( $posts )			{				foreach( explode( ",", $posts ) as $t )				{					$post_array[ $t ] = $t;				}			}						//-----------------------------------------			// Anything left to show?			//-----------------------------------------						if ( ! $topics and ! $posts )			{				$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) );			}		}				$url_words = $this->convert_highlite_words($this->ipsclass->input['highlite']);				if ($this->result_type == 'topics')		{			//-----------------------------------------			// CACHED QUERY?			//-----------------------------------------						if ( $this->cached_query )			{				$this->output .= $this->start_page($this->cached_matches);								$this->ipsclass->DB->prefix_changed = 1;				$this->ipsclass->DB->query( $this->cached_query );				$this->ipsclass->DB->prefix_changed = 0;			}			//-----------------------------------------			// PID / TID			//-----------------------------------------						else if ($this->search_in == 'titles')			{				if ( ! $topics )				{					$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) );				}							$this->output .= $this->start_page($topic_max_hits);								$this->ipsclass->DB->simple_construct( array( 'select' => 't.*',															  'from'   => 'topics t',															  'where'  => "t.tid IN({$topics})",															  'order'  => "t.pinned DESC, t.".$this->sort_key." ".$this->sort_order,															  'limit'  => array( $this->first, 25 )													 )      );				$this->ipsclass->DB->simple_exec();			}			else			{				//-----------------------------------------				// Add posts to the mix				//-----------------------------------------								if ($posts)				{					$this->ipsclass->DB->simple_construct( array( 'select' => 'topic_id', 'from' => 'posts', 'where' => "pid IN({$posts})" ) );					$this->ipsclass->DB->simple_exec();									while ( $pr = $this->ipsclass->DB->fetch_row() )					{						$topic_array[ $pr['topic_id'] ] = $pr['topic_id'];					}										$topics         = implode( ",", $topic_array );					$topic_max_hits = count( $topic_array );				}								$this->output .= $this->start_page($topic_max_hits);								$this->ipsclass->DB->simple_construct( array( 'select' => 't.*',															  'from'   => 'topics t',															  'where'  => "t.tid IN({$topics})",															  'order'  => "t.pinned DESC, t.".$this->sort_key." ".$this->sort_order,															  'limit'  => array( $this->first, 25 )													 )      );				$this->ipsclass->DB->simple_exec();			}						//-----------------------------------------			// PRINT: Any returned rows?			//-----------------------------------------						if ( $this->ipsclass->DB->get_num_rows() )			{				while ( $row = $this->ipsclass->DB->fetch_row() )				{					$row['keywords'] = $url_words;					$this->output   .= $this->ipsclass->compiled_templates['skin_search']->RenderRow( $this->parse_entry($row) );								}			}			else			{				if ( ! $this->ipsclass->input['lastdate'] )				{					$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) );				}				else				{					$this->output .= $this->ipsclass->compiled_templates['skin_search']->no_results_row(); 				}			}						//-----------------------------------------			// PRINT: End the page			//-----------------------------------------						$this->output .= $this->ipsclass->compiled_templates['skin_search']->end_results_table(array( 'SHOW_PAGES' => $this->links ));		}				//-----------------------------------------		// Results as posts...		//-----------------------------------------				else		{			//-----------------------------------------			// Grab topic lib			//-----------------------------------------						require_once( ROOT_PATH.'sources/action_public/topics.php' );			$this->topics = new topics();			$this->topics->ipsclass =& $this->ipsclass;			$this->topics->topic_init();						$attach_pids = array();						//-----------------------------------------			// CACHED QUERY?			//-----------------------------------------						if ( $this->cached_query )			{				$this->output .= $this->start_page($this->cached_matches, 1);								$this->ipsclass->DB->query( $this->cached_query );			}			//-----------------------------------------			// PID / TID			//-----------------------------------------						else			{				//-----------------------------------------				// Start...				//-----------------------------------------								if ($this->search_in == 'titles')				{					if ( ! $topics )					{						$this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) );					}									$this->output .= $this->start_page($topic_max_hits, 1);										$this->ipsclass->DB->cache_add_query( 'search_main_in_titles', array( 'topics' => $topics, 'limit_a' => $this->first ) );					$this->ipsclass->DB->cache_exec_query();				}				else				{					//-----------------------------------------					// Add Topics					//-----------------------------------------										if ( $topics )					{						$this->ipsclass->DB->simple_construct( array( 'select' => 'pid', 'from' => 'posts', 'where' => "topic_id IN({$topics}) AND new_topic=1" ) );						$this->ipsclass->DB->simple_exec();											while ( $pr = $this->ipsclass->DB->fetch_row() )						{							$post_array[ $pr['pid'] ] = $pr['pid'];						}												$posts         = implode( ",", $post_array );						$post_max_hits = count( $post_array );					}										$this->output .= $this->start_page($post_max_hits, 1);										$this->ipsclass->DB->cache_add_query( 'search_main_in_posts', array( 'posts' => $posts, 'limit_a' => $this->first ) );					$this->ipsclass->DB->cache_exec_query();				}			}						while ( $row = $this->ipsclass->DB->fetch_row() )			{				$row['keywords']  = $url_words;				$row['post_date'] = $this->ipsclass->get_date( $row['post_date'],'LONG' );								//-----------------------------------------				// Parse HTML tag on the fly				//-----------------------------------------								$this->topics->parser->parse_html  = ( $this->ipsclass->forums->forum_by_id[$row['forum_id']]['use_html'] and $this->ipsclass->cache['group_cache'][ $row['mgroup'] ]['g_dohtml'] and $row['post_htmlstate'] ) ? 1 : 0;				$this->topics->parser->parse_wordwrap = $this->ipsclass->vars['post_wordwrap'];				$this->topics->parser->parse_nl2br    = $row['post_htmlstate'] == 2 ? 1 : 0;								$row['post'] = $this->topics->parser->pre_display_parse( $row['post'] );								//-----------------------------------------				// Attachments?				//-----------------------------------------								if ( strstr( $row['post'], '[attachmentid=' ) )				{					$attach_pids[] = $row['pid'];				}								//-----------------------------------------				// Parse Member				//-----------------------------------------								$member = $this->topics->parse_member( $row );								//-----------------------------------------				// Do word wrap?				//-----------------------------------------								$this->output .= $this->ipsclass->compiled_templates['skin_search']->RenderPostRow( $this->parse_entry($row, 1), $member );						}						//-----------------------------------------			// Add in attachments?			//-----------------------------------------						if ( count( $attach_pids ) )			{				$this->output = $this->topics->parse_attachments( $this->output, $attach_pids );			}						$this->output .= $this->ipsclass->compiled_templates['skin_search']->end_results_table(array( 'SHOW_PAGES' => $this->links ), 1 );		}				$this->page_title = $this->ipsclass->lang['search_results'];				if ( $this->ipsclass->input['nav'] == 'lv' )		{			if ( $this->ipsclass->input['lastdate'] )			{				$this->nav = array( $this->ipsclass->lang['nav_au'] );			}			else			{				$this->nav = array( $this->ipsclass->lang['nav_since_lv'] );			}		}		else if ( $this->ipsclass->input['nav'] == 'lt' )		{			$this->nav = array( $this->ipsclass->lang['nav_lt'] );		}		else		{			$this->nav = array( "<a href='{$this->base_url}&act=Search'>{$this->ipsclass->lang['search_form']}</a>", $this->ipsclass->lang['search_title'] );		}				//-----------------------------------------		// Active topics fing?		//-----------------------------------------				if ( $this->ipsclass->input['lastdate'] )		{			$this->output = preg_replace( "#(value=[\"']".intval($this->ipsclass->input['lastdate'])."[\"'])#i", "\\1 selected='selected'", $this->output );		}	}		/*-------------------------------------------------------------------------*/	// Start the page functions	/*-------------------------------------------------------------------------*/		function start_page($amount, $is_post = 0)	{		$url_words = $this->convert_highlite_words($this->ipsclass->input['highlite']);		$extra     = $this->more_results ? str_replace( '%num', $this->resultlimit, $this->ipsclass->lang['too_many_children_for_santa'] ) : "";				$this->links = $this->ipsclass->build_pagelinks( array( 'TOTAL_POSS'  => $amount,													 'PER_PAGE'    => 25,													 'CUR_ST_VAL'  => $this->first,													 'L_SINGLE'    => "",													 'L_MULTI'     => $this->ipsclass->lang['search_pages'],													 'BASE_URL'    => $this->base_url."act=Search&nav=".$this->ipsclass->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->ipsclass->compiled_templates['skin_search']->start( array( 'SHOW_PAGES' => $this->links ), $extra  );		}		else		{			return $this->ipsclass->compiled_templates['skin_search']->start_as_post( array( 'SHOW_PAGES' => $this->links ), $extra );		}	}        /*-------------------------------------------------------------------------*/    // Parse search result entry    /*-------------------------------------------------------------------------*/    	function parse_entry($topic, $view_as_post=0)	{		$this->ipsclass->input['last_visit'] = $this->ipsclass->forum_read[ $topic['forum_id'] ] > $this->ipsclass->input['last_visit']        						       		 ? $this->ipsclass->forum_read[ $topic['forum_id'] ] : $this->ipsclass->input['last_visit'];				if ( $this->ipsclass->member['members_markers']['board'] > $this->ipsclass->input['last_visit'] )		{			$this->ipsclass->input['last_visit'] = $this->ipsclass->member['members_markers']['board'];		}				//echo "<pre>";print $this->ipsclass->input['last_visit']; print_r($topic);echo "</pre>";exit;				//-----------------------------------------		// Over ride with 'master' cookie?		//-----------------------------------------				if ( $this->ipsclass->forum_read[0] > $this->ipsclass->forum_read[ $topic['forum_id'] ] )		{			$this->ipsclass->forum_read[ $topic['forum_id'] ] = $this->ipsclass->forum_read[0];		}				//-----------------------------------------		// Disable DB tracking...		// ^^ We'll disable this disabling for now		// as it seems to affect today's active tpx		//-----------------------------------------				//$tmp = $this->ipsclass->vars['db_topic_read_cutoff'];

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?