search.php

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

PHP
1,763 行
字号
		//$this->ipsclass->vars['db_topic_read_cutoff'] = 0;				//-----------------------------------------		// Stop search from marking forum as read		//-----------------------------------------				if ( is_array( $this->read_array ) )		{			if ( array_key_exists( $topic['tid'], $this->read_array ) )			{				if( !$topic['db_read'] OR $this->read_array[$topic['tid']] > $topic['db_read'] )				{					$topic['db_read'] = $this->read_array[$topic['tid']];				}			}		}			$this->forums->new_posts = 1;				$topic = $this->forums->parse_data( $topic );				$this->ipsclass->vars['db_topic_read_cutoff'] = $tmp;				if ($topic['pinned'] == 1)		{			$topic['prefix']     = $this->ipsclass->vars['pre_pinned'];			$topic['topic_icon'] = "<{B_PIN}>";		}				//-----------------------------------------		// Remove potential [attachmentid= tag in title		//-----------------------------------------				$topic['topic_title'] = str_replace( '[attachmentid=', '&#91;attachmentid=', $topic['topic_title'] );				//-----------------------------------------		// Extra processing for posts..		//-----------------------------------------				if ($view_as_post == 1)		{			if ( $this->ipsclass->vars['search_post_cut'] )			{				$topic['post'] = substr( $topic['post'], 0, $this->ipsclass->vars['search_post_cut']) . '...';				$topic['post'] = str_replace( "\n", "<br />", $topic['post'] );			}						if ($topic['author_id'])			{				$topic['author_name'] = $topic['members_display_name'] ? $topic['members_display_name'] : $topic['author_name'];				$topic['author_name'] = "<b><a href='{$this->base_url}showuser={$topic['author_id']}'>{$topic['author_name']}</a></b>";			}						//-----------------------------------------			// Highlighting?			//-----------------------------------------						if ($topic['keywords'])			{				$topic['keywords'] = $this->ipsclass->clean_value(rawurldecode($topic['keywords']));				$loosematch = strstr( $topic['keywords'], '*' ) ? 1 : 0;				$keywords   = str_replace( '*', '', str_replace( "+", " ", str_replace( '-', '', trim($topic['keywords']) ) ) );				$word_array = array();				$endmatch1  = "";				$endmatch2  = "(.)?";								if ( preg_match("/,(and|or),/i", $keywords) )				{					while ( preg_match("/,(and|or),/i", $keywords, $match) )					{						$word_array = explode( ",".$match[1].",", $keywords );						$keywords   = str_replace( $match[0], '' ,$keywords );					}				}				else if ( strstr( $keywords, ' ' ) )				{					$word_array = explode( ' ', str_replace( '  ', ' ', $keywords ) );				}				else				{					$word_array[] = $keywords;				}								if ( ! $loosematch )				{					$endmatch1 = "(\s|,|\.|!|<br|&|$)";					$endmatch2 = "(\<|\s|,|\.|!|<br|&|$)";				}									if (is_array($word_array))				{					foreach ($word_array as $keywords)					{						while( preg_match( "/(^|\s|;)(".preg_quote($keywords, '/')."){$endmatch1}/i", $topic['post'] ) )					   {						   $topic['post'] = preg_replace( "/(^|\s|;|\>)(".preg_quote($keywords, '/')."){$endmatch2}/is", "\\1<span class='searchlite'>\\2</span>\\3", $topic['post'] );					   }					}				}			}		}				if ( ! $this->ipsclass->member['view_img'] )		{			//-----------------------------------------			// unconvert smilies first, or it looks a bit crap.			//-----------------------------------------						$topic['post'] = preg_replace( "#<!--emo&(.+?)-->.+?<!--endemo-->#", "\\1" , $topic['post'] );						$topic['post'] = preg_replace( "/<img src=[\"'](.+?)[\"'].+?".">/", "(IMG:<a href='\\1' target='_blank'>\\1</a>)", $topic['post'] );		}				$topic['forum_full_name'] = $this->ipsclass->forums->forum_by_id[ $topic['forum_id'] ]['name'];				if ( strlen($topic['forum_full_name']) > 50 )		{			$topic['forum_name'] = substr( $topic['forum_full_name'], 0, 47 ) .'...';		}		else		{			$topic['forum_name'] = $topic['forum_full_name'];		}				//$this->parser->parse_html  = ( $this->ipsclass->forums->forum_by_id[ $topic['forum_id'] ]['use_html'] and $this->ipsclass->cache['group_cache'][ $this->ipsclass->member['mgroup'] ]['g_dohtml'] and $topic['post_htmlstate'] ) ? 1 : 0;		//$this->parser->parse_wordwrap = $this->ipsclass->vars['post_wordwrap'];		//$this->parser->parse_nl2br    = $topic['post_htmlstate'] == 2 ? 1 : 0;				//$topic['post'] = $this->parser->pre_display_parse( $topic['post'] );				return $topic;	}            /*-------------------------------------------------------------------------*/    // Filter keywords    /*-------------------------------------------------------------------------*/            function filter_keywords($words="", $name=0)    {    	// force to lowercase and swop % into a safer version    	$words = trim( str_replace( "%", "\\%", $words) );    	// Remove trailing boolean operators    	$words = preg_replace( "/\s+(and|or)$/" , "" , $words );    	// Swop wildcard into *SQL percent    	//$words = str_replace( "*", "%", $words );    	    	// Make safe underscores    	    	$words = str_replace( "_", "\\_", $words );    	$words = str_replace( '|', "&#124;", $words );    	    	// Remove crap    	    	if ($name == 0)    	{    		$words = preg_replace( "/[\|\[\]\{\}\(\)\,:\\\\\/\"']|&quot;/", "", $words );    	}    	// Remove common words.. (should be expanded upon in a later release to return 'not searchable word'    	    	$words = preg_replace( "/^(?:img|quote|code|html|javascript|a href|color|span|div|border|style)$/", "", $words );    	return " ".preg_quote($words)." ";    }        /*-------------------------------------------------------------------------*/    // Filter keywords    /*-------------------------------------------------------------------------*/        function filter_ftext_keywords($words="")    {		// force to lowercase and swop % into a safer version    	    	$words = trim( rawurldecode($words) );    	$words = str_replace( '|', "&#124;", $words );    	    	// Remove crap    	    	$words = str_replace( "&quot;", '"', $words );    	$words = str_replace( "&gt;"  , ">", $words );    	$words = str_replace( "%"     , "" , $words );    	    	//-----------------------------------------    	// If it's a phrase in quotes..    	//-----------------------------------------    	    	if ( preg_match( "#^\"(.+?)\"$#", $words ) )    	{    		return $words;    	}    	    	// Remove common words..    	    	$words = preg_replace( "/^(?:img|quote|code|html|javascript|a href|color|span|div|border|style)$/", "", $words );    	    	// OK, lets break up the keywords    	    	// this or that and this not me    	    	$words = preg_replace( "/\s+and\s+/i", " ", $words );    	    	// this or that this not me    	    	$words = preg_replace( "/\s+not\s+/i", " -", $words );    	    	// this or that this -me    	    	$words = preg_replace( "/\s+or\s+/i", ' ~', $words );    	    	// this ~that this -me    	    	# Was added as a bug fix but really this causes more problems    	# than it solves. Complaint was that it should default to AND    	# matching, not OR matching. Problem is that it doesn't then    	# give a "true" search as one would expect Google to do.    	    	//$words = preg_replace( "/\s+(?!-|~)/", " +", $words );    	    	    	// this ~that +this -me    	    	$words = preg_replace( "/~/", "", $words );    	    	// this that +this -me    	    	return "+".$words;    }        /*-------------------------------------------------------------------------*/    // Make the hl words nice and stuff    /*-------------------------------------------------------------------------*/        function convert_highlite_words($words="")    {    	$words = $this->ipsclass->parse_clean_value(trim(urldecode($words)));    	    	// Convert booleans to something easy to match next time around    	    	$words = preg_replace("/\s+(and|or)(\s+|$)/i", ",\\1,", $words);    	    	// Convert spaces to plus signs    	    	$words = preg_replace("/\s/", "+", $words);    	    	return $words;    }            /*-------------------------------------------------------------------------*/    // Get the searchable forums    /*-------------------------------------------------------------------------*/            function get_searchable_forums()    {		$forumids = array();		    	//-----------------------------------------    	// Check for an array    	//-----------------------------------------    	    	if ( is_array( $_POST['forums'] )  )    	{    	    		if ( in_array( 'all', $_POST['forums'] ) )    		{    			//-----------------------------------------    			// Searching all forums..    			//-----------------------------------------    			    			foreach( $this->ipsclass->forums->forum_by_id as $id => $data )    			{    				$forumids[] = $data['id'];    			}    		}    		else    		{				//-----------------------------------------				// Go loopy loo				//-----------------------------------------								foreach( $_POST['forums'] as $l )				{					if ( $this->ipsclass->forums->forum_by_id[ $l ] )					{						$forumids[] = intval($l);					}				}								//-----------------------------------------				// Do we have cats? Give 'em to Charles!				//-----------------------------------------								if ( count( $forumids  ) )				{					foreach( $forumids as $f )					{						$children = $this->ipsclass->forums->forums_get_children( $f );												if ( is_array($children) and count($children) )						{							$forumids  = array_merge( $forumids , $children );						}					}				}				else				{					//-----------------------------------------					// No forums selected / we have available					//-----------------------------------------										return;				}    		}		}		else		{			//-----------------------------------------			// Not an array...			//-----------------------------------------						if ( $this->ipsclass->input['forums'] == 'all' )			{				foreach( $this->ipsclass->forums->forum_by_id as $id => $data )    			{    				$forumids[] = $data['id'];    			}			}			else			{				if ( $this->ipsclass->input['forums'] != "" )				{					$l = intval($this->ipsclass->input['forums']);										//-----------------------------------------					// Single forum					//-----------------------------------------										if ( $this->ipsclass->forums->forum_by_id[ $l ] )					{						$forumids[] = intval($l);					}										if ( $this->ipsclass->input['searchsubs'] == 1 )					{						$children = $this->ipsclass->forums->forums_get_children( $l );												if ( is_array($children) and count($children) )						{							$forumids  = array_merge( $forumids , $children );						}					}				}			}		}				$final = array();				foreach( $forumids  as $f )		{			if ( $this->check_access($this->ipsclass->forums->forum_by_id[ $f ] ) == TRUE )			{				$final[] = $f;			}		}				//-----------------------------------------		// Remove blocked forums		//-----------------------------------------				if ( $this->ipsclass->input['CODE'] == 'getnew' OR $this->ipsclass->input['CODE'] == 'getactive' )    	{    		$block_forums = explode( ',', $this->ipsclass->vars['vnp_block_forums'] );    		    		if ( is_array( $block_forums ) and count( $block_forums ) )    		{    			if ( is_array( $final ) and count( $final ) )    			{    				$tmp   = $final;    				$final = array();    								foreach( $tmp as $internal => $id )					{						if ( in_array( $id, $block_forums ) )						{							continue;						}						else						{							$final[] = $id;						}					}    			}    		}    	}    	    	//-----------------------------------------    	// Return    	//-----------------------------------------    	    	return implode( "," , $final );    }            /*-------------------------------------------------------------------------*/    // Check password...    /*-------------------------------------------------------------------------*/        function check_access($i)    {		$can_read = FALSE;      	if ( $this->ipsclass->check_perms( $i['read_perms'] ) == TRUE )    	{    		$can_read = TRUE;    	}    	else    	{    		$can_read = FALSE;    	}                if ( $i['password'] != "" and $can_read == TRUE )		{			if ( $this->ipsclass->forums->forums_compare_password( $i['id'] ) == TRUE )			{				$can_read = TRUE;			}			else			{				$can_read = FALSE;			}		}				return $can_read;	}        }?>

⌨️ 快捷键说明

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