post_parser.php

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

PHP
1,500
字号
			$txt = str_replace( "</li>", "", $txt );						$txt = str_replace( "&#153;", "(tm)", $txt );		}		if ($html == 1)		{			$txt = str_replace( "&#39;", "'", $txt);		}				$txt = str_replace( "<br>"  , "\n", $txt );		$txt = str_replace( "<br />", "\n", $txt );						return trim(stripslashes($txt));	}	//-----------------------------------------//+-----------------------------------------------------------------------------------------// UNCONVERT FUNCTIONS//+-----------------------------------------------------------------------------------------//+-----------------------------------------------------------------------------------------	function unconvert_size($size="", $text="")	{				$size -= 7;				return '[size='.$size.']'.$text.'[/size]';			}	function unconvert_flash($flash="")	{			$f_arr = explode( "+", $flash );				return '[flash='.$f_arr[0].','.$f_arr[1].']'.$f_arr[2].'[/flash]';			}		function unconvert_sql($sql="")	{		$sql = stripslashes($sql);				$sql = preg_replace( "#<span style='.+?'>#is", "", $sql );		$sql = str_replace( "</span>"                , "", $sql );		$sql = preg_replace( "#\s*$#"                , "", $sql );				return '[sql]'.$sql.'[/sql]';			}	function unconvert_htm($html="")	{		$html = stripslashes($html);				$html = preg_replace( "#<span style='.+?'>#is", "", $html );		$html = str_replace( "</span>"                , "", $html );		$html = preg_replace( "#\s*$#"                , "", $html );				return '[html]'.$html.'[/html]';			}		//-----------------------------------------//+-----------------------------------------------------------------------------------------// CONVERT FUNCTIONS//+-----------------------------------------------------------------------------------------//+-----------------------------------------------------------------------------------------	/*-------------------------------------------------------------------------*/	// convert_emoticon:	// replaces the text with the emoticon image	/*-------------------------------------------------------------------------*/		function convert_emoticon($code="", $image="")	{		global $ibforums;				if (!$code or !$image) return;				//-----------------------------------------		// Remove slashes added by preg_quote		//-----------------------------------------				$code = stripslashes($code);				$this->emoticon_count++;				return "<!--emo&".trim($code)."--><img src='{$ibforums->vars['EMOTICONS_URL']}/$image' border='0' style='vertical-align:middle' alt='$image' /><!--endemo-->";	}		/*-------------------------------------------------------------------------*/	// wrap style:	// code and quote table HTML generator	/*-------------------------------------------------------------------------*/		function wrap_style( $type='quote', $extra="" )	{		global $ibforums;				$used = array(					   'quote' => array( 'title' => 'QUOTE', 'css_top' => 'quotetop' , 'css_main' => 'quotemain' ),					   'code'  => array( 'title' => 'CODE' , 'css_top' => 'codetop'  , 'css_main' => 'codemain'  ),					   'sql'   => array( 'title' => 'SQL'  , 'css_top' => 'sqltop'   , 'css_main' => 'sqlmain'   ),					   'html'  => array( 'title' => 'HTML' , 'css_top' => 'htmltop'  , 'css_main' => 'htmlmain'  )					 );						return array( 'START' => "<div class='{$used[ $type ]['css_top']}'>{$used[ $type ]['title']}{$extra}</div><div class='{$used[ $type ]['css_main']}'>",					  'END'   => "</div>"					);	}	/*-------------------------------------------------------------------------*/	// regex_list: List generation	// 	/*-------------------------------------------------------------------------*/		function regex_list( $txt="", $type="" )	{		if ($txt == "")		{			return;		}				if ( $type == "" )		{			// Unordered list.						return "<ul>".$this->regex_list_item($txt)."</ul>";		}		else		{			return "<ol type='$type'>".$this->regex_list_item($txt)."</ol>";		}	}		function regex_list_item($txt)	{		$txt = preg_replace( "#\[\*\]#", "</li><li>" , trim($txt) );				$txt = preg_replace( "#^</?li>#"  , "", $txt );				return str_replace( "\n</li>", "</li>", $txt."</li>" );	}							/*-------------------------------------------------------------------------*/	// regex_html_tag: HTML syntax highlighting	// 	/*-------------------------------------------------------------------------*/		function regex_html_tag($html="") {			if ($html == "") return;				//-----------------------------------------		// Too many embedded code/quote/html/sql tags can crash Opera and Moz		//-----------------------------------------				if (preg_match( "/\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\]/i", $html) )		{			return $default;		}						//-----------------------------------------		// Take a stab at removing most of the common		// smilie characters.		//-----------------------------------------				$html = preg_replace( "#:#"      , "&#58;", $html );		$html = preg_replace( "#\[#"     , "&#91;", $html );		$html = preg_replace( "#\]#"     , "&#93;", $html );		$html = preg_replace( "#\)#"     , "&#41;", $html );		$html = preg_replace( "#\(#"     , "&#40;", $html );				$html = preg_replace( "/^<br>/"  , "", $html );		$html = preg_replace( "#^<br />#", "", $html );		$html = preg_replace( "/^\s+/"   , "", $html );				$html = preg_replace( "#&lt;([^&<>]+)&gt;#"                           , "&lt;<span style='color:blue'>\\1</span>&gt;"        , $html );   //Matches <tag>		$html = preg_replace( "#&lt;([^&<>]+)=#"                              , "&lt;<span style='color:blue'>\\1</span>="           , $html );   //Matches <tag		$html = preg_replace( "#&lt;/([^&]+)&gt;#"                            , "&lt;/<span style='color:blue'>\\1</span>&gt;"       , $html );   //Matches </tag>		$html = preg_replace( "!=(&quot;|&#39;)(.+?)?(&quot;|&#39;)(\s|&gt;)!" , "=\\1<span style='color:orange'>\\2</span>\\3\\4"    , $html );   //Matches ='this'		$html = preg_replace( "!&#60;&#33;--(.+?)--&#62;!"                    , "&lt;&#33;<span style='color:red'>--\\1--</span>&gt;", $html );				$wrap = $this->wrap_style( 'html' );				return "<!--html-->{$wrap['START']}<!--html1-->$html<!--html2-->{$wrap['END']}<!--html3-->";	}			/*-------------------------------------------------------------------------*/	// regex_sql_tag: SQL syntax highlighting	// 	/*-------------------------------------------------------------------------*/		function regex_sql_tag($sql="") {				if ($sql == "") return;				//-----------------------------------------		// Too many embedded code/quote/html/sql tags can crash Opera and Moz		//-----------------------------------------				if (preg_match( "/\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\]/i", $sql) ) {			return $default;		}				//-----------------------------------------			// Knock off any preceeding newlines (which have		// since been converted into <br>)		//-----------------------------------------				$sql = preg_replace( "/^<br>/"  , "", $sql );		$sql = preg_replace( "#^<br />#", "", $sql );		$sql = preg_replace( "/^\s+/"   , "", $sql );				//-----------------------------------------		// Make certain regex work..		//-----------------------------------------				if (! preg_match( "/\s+$/" , $sql) )		{			$sql = $sql.' ';		}				$sql = preg_replace( "#(=|\+|\-|&gt;|&lt;|~|==|\!=|LIKE|NOT LIKE|REGEXP)#i"            , "<span style='color:orange'>\\1</span>", $sql );		$sql = preg_replace( "#(MAX|AVG|SUM|COUNT|MIN)\(#i"                                    , "<span style='color:blue'>\\1</span>("    , $sql );	    $sql = preg_replace( "!(&quot;|&#39;|&#039;)(.+?)(&quot;|&#39;|&#039;)!i"              , "<span style='color:red'>\\1\\2\\3</span>" , $sql );	    $sql = preg_replace( "#\s{1,}(AND|OR)\s{1,}#i"                                         , " <span style='color:blue'>\\1</span> "    , $sql );	    $sql = preg_replace( "#(LEFT|JOIN|WHERE|MODIFY|CHANGE|AS|DISTINCT|IN|ASC|DESC|ORDER BY)\s{1,}#i" , "<span style='color:green'>\\1</span> "   , $sql );	    $sql = preg_replace( "#LIMIT\s*(\d+)\s*,\s*(\d+)#i"                                    , "<span style='color:green'>LIMIT</span> <span style='color:orange'>\\1, \\2</span>" , $sql );	    $sql = preg_replace( "#(FROM|INTO)\s{1,}(\S+?)\s{1,}#i"                                , "<span style='color:green'>\\1</span> <span style='color:orange'>\\2</span> ", $sql );	    $sql = preg_replace( "#(SELECT|INSERT|UPDATE|DELETE|ALTER TABLE|DROP)#i"               , "<span style='color:blue;font-weight:bold'>\\1</span>" , $sql );	    	    $html = $this->wrap_style( 'sql' );	    	    return "<!--sql-->{$html['START']}<!--sql1-->{$sql}<!--sql2-->{$html['END']}<!--sql3-->";	 }		/*-------------------------------------------------------------------------*/	// regex_code_tag: Builds this code tag HTML	// 	/*-------------------------------------------------------------------------*/		function regex_code_tag($txt="")	{		global $ibforums;				$default = "\[code\]$txt\[/code\]";				if ($txt == "") return;				//-----------------------------------------		// Too many embedded code/quote/html/sql tags can crash Opera and Moz		//-----------------------------------------				if (preg_match( "/\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\].+?\[(quote|code|html|sql)\]/i", $txt) ) {			return $default;		}				//-----------------------------------------		// Take a stab at removing most of the common		// smilie characters.		//-----------------------------------------				//$txt = str_replace( "&" , "&amp;", $txt );		$txt = preg_replace( "#&lt;#"   , "&#60;", $txt );		$txt = preg_replace( "#&gt;#"   , "&#62;", $txt );		$txt = preg_replace( "#&quot;#" , "&#34;", $txt );		$txt = preg_replace( "#:#"      , "&#58;", $txt );		$txt = preg_replace( "#\[#"     , "&#91;", $txt );		$txt = preg_replace( "#\]#"     , "&#93;", $txt );		$txt = preg_replace( "#\)#"     , "&#41;", $txt );		$txt = preg_replace( "#\(#"     , "&#40;", $txt );		$txt = preg_replace( "#\r#"     , "<br />", $txt );		$txt = preg_replace( "#\n#"     , "<br />", $txt );		$txt = preg_replace( "#\s{1};#" , "&#59;", $txt );				//-----------------------------------------		// Ensure that spacing is preserved		//-----------------------------------------				$txt = preg_replace( "#\s{2}#", " &nbsp;", $txt );				$html = $this->wrap_style( 'code' );				return "<!--c1-->{$html['START']}<!--ec1-->$txt<!--c2-->{$html['END']}<!--ec2-->";			}		/*-------------------------------------------------------------------------*/	// regex_parse_quotes: Builds this quote tag HTML	// [QUOTE] .. [/QUOTE] - allows for embedded quotes	/*-------------------------------------------------------------------------*/		function regex_parse_quotes($the_txt="") {				if ($the_txt == "") return;				$txt = $the_txt;				if ( substr_count( strtolower($txt), '[quote' ) > $this->max_embed_quotes )		{			return $txt;		}				$txt = str_replace( chr(173).']', '&#93;', $txt );				$this->quote_html = $this->wrap_style('quote');				$txt = preg_replace( "#\[quote\]#ie"                        , "\$this->regex_simple_quote_tag()"       , $txt );		$txt = preg_replace( "#\[quote=([^\],]+?),([^\]]+?)\]#ie"   , "\$this->regex_quote_tag('\\1', '\\2')"  , $txt );		$txt = preg_replace( "#\[quote=([^\]]+?)\]#ie"              , "\$this->regex_quote_tag('\\1', '')"     , $txt );		$txt = preg_replace( "#\[/quote\]#ie"                       , "\$this->regex_close_quote()"            , $txt );				$txt = str_replace( "\n", "<br />", $txt );				if ( ($this->quote_open == $this->quote_closed) and ($this->quote_error == 0) )		{			$txt = preg_replace( "#(<!--QuoteEBegin-->.+?<!--QuoteEnd-->)#es", "\$this->regex_preserve_spacing('\\1')", trim($txt) );						return $txt;		}		else		{			return $the_txt;		}			}		/*-------------------------------------------------------------------------*/	// regex_preserve_spacing: keeps double spaces	// without CSS killing <pre> tags	/*-------------------------------------------------------------------------*/		function regex_preserve_spacing($txt="")	{		$txt = preg_replace( "#^<!--QuoteEBegin-->(?:<br>|<br />)#", "<!--QuoteEBegin-->", trim($txt) );				$txt = preg_replace( "#\s{2}#", "&nbsp; ", $txt );		return $txt;	}		/*-------------------------------------------------------------------------*/	// regex_simple_quote_tag: Builds this quote tag HTML	// [QUOTE] .. [/QUOTE]	/*-------------------------------------------------------------------------*/		function regex_simple_quote_tag()	{		global $ibforums;				$this->quote_open++;		return "<!--QuoteBegin-->{$this->quote_html['START']}<!--QuoteEBegin-->";	}		/*-------------------------------------------------------------------------*/	// regex_close_quote: closes a quote tag	// 	/*-------------------------------------------------------------------------*/		function regex_close_quote() {			if ($this->quote_open == 0)		{			$this->quote_error++;		 	return;		}

⌨️ 快捷键说明

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