post_parser.php

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

PHP
1,500
字号
			if ( $ibforums->vars['max_emos'] )			{				if ($this->emoticon_count > $ibforums->vars['max_emos'])				{					$this->error = 'too_many_emoticons';				}			}		}				$txt = $this->bad_words($txt);				$txt = $this->bbcode_check($txt);				return $txt;	}		//-----------------------------------------	// Checks opening and closing bbtags - doesn't parse at this point	//-----------------------------------------		function bbcode_check($t="")	{		global $ibforums, $DB, $std;				$count = array();				foreach( $ibforums->cache['bbcode'] as $i => $r )		{			if ( $r['bbcode_useoption'] )			{				$count[ $r['bbcode_id'] ]['open']      = substr_count( strtolower($t), '['.strtolower($r['bbcode_tag']).'=' );				$count[ $r['bbcode_id'] ]['wrongopen'] = substr_count( strtolower($t), '['.strtolower($r['bbcode_tag']).']' );			}			else			{				$count[ $r['bbcode_id'] ]['open']      = substr_count( strtolower($t), '['.strtolower($r['bbcode_tag']).']' );				$count[ $r['bbcode_id'] ]['wrongopen'] = substr_count( strtolower($t), '['.strtolower($r['bbcode_tag']).'=' );			}						$count[ $r['bbcode_id'] ]['closed'] = substr_count( strtolower($t), '[/'.strtolower($r['bbcode_tag']).']' );						//-----------------------------------------			// check...			//-----------------------------------------						if ( $count[ $r['bbcode_id'] ]['open'] != $count[ $r['bbcode_id'] ]['closed'] )			{				if ( $count[ $r['bbcode_id'] ]['wrongopen'] == $count[ $r['bbcode_id'] ]['closed'] )				{					$this->error = 'custom_tags_incorrect2';				}				else				{					$this->error = 'custom_tags_incorrect';				}			}		}				return $t;	}		//-----------------------------------------	// My strip-tags. Converts HTML entities back before strippin' em	//-----------------------------------------		function my_strip_tags($t="")	{		$t = str_replace( '&gt;', '>', $t );		$t = str_replace( '&lt;', '<', $t );				$t = strip_tags($t);				// Make sure nothing naughty is left...				$t = str_replace( '<', '&lt;', $t );		$t = str_replace( '>', '&gt;', $t );				return $t;	}				//-----------------------------------------	// Word wrap, wraps 'da word innit	//-----------------------------------------		function my_wordwrap($t="", $chrs=0, $replace="<br />")	{		if ( $t == "" )		{			return $t;		}				if ( $chrs < 1 )		{			return $t;		}				$t = preg_replace("#([^\s<>'\"/\.\\-\?&\n\r\%]{".$chrs."})#i", " \\1".$replace ,$t);				return $t;			}		//-----------------------------------------	// Post DB parse tags	//-----------------------------------------		function post_db_parse($t="")	{		global $ibforums, $DB;				if ( $this->pp_do_html )		{			$t = $this->post_db_parse_html( $t );		}		else		{			//$t = $this->my_strip_tags( $t );		}				if ( $this->pp_wordwrap > 0 )		{			$t = $this->my_wordwrap( $t, $this->pp_wordwrap );		}				//-----------------------------------------		// Custom BB code		//-----------------------------------------				if ( strstr( $t, '[/' )  )		{ 			$t = $this->post_db_parse_bbcode($t);		}				return $t;	}		//-----------------------------------------	// Post DB parse BBCode	//-----------------------------------------		function post_db_parse_bbcode($t="")	{		global $ibforums, $DB, $std;				if ( is_array( $ibforums->cache['bbcode'] ) and count( $ibforums->cache['bbcode'] ) )		{			foreach( $ibforums->cache['bbcode'] as $i => $row )			{				if ( substr_count( $row['bbcode_replace'], '{content}' ) > 1 )				{					//-----------------------------------------					// Slightly slower					//-----------------------------------------										if ( $row['bbcode_useoption'] )					{						preg_match_all( "#(\[".preg_quote($row['bbcode_tag'], '#' )."=(?:&quot;|&\#39;)?(.+?)(?:&quot;|&\#39;)?\])(.+?)(\[/".preg_quote($row['bbcode_tag'], '#' )."\])#si", $t, $match );												for ($i=0; $i < count($match[0]); $i++)						{							$tmp = $row['bbcode_replace'];							$tmp = str_replace( '{option}' , $match[2][$i], $tmp );							$tmp = str_replace( '{content}', $match[3][$i], $tmp );							$t   = str_replace( $match[0][$i], $tmp, $t );						}					}					else					{						preg_match_all( "#(\[".preg_quote($row['bbcode_tag'], '#' )."\])(.+?)(\[/".preg_quote($row['bbcode_tag'], '#' )."\])#si", $t, $match );							for ($i=0; $i < count($match[0]); $i++)						{							$tmp = $row['bbcode_replace'];							$tmp = str_replace( '{content}', $match[2][$i], $tmp );							$t   = str_replace( $match[0][$i], $tmp, $t );						}					}				}				else				{					$replace = explode( '{content}', $row['bbcode_replace'] );										if ( $row['bbcode_useoption'] )					{						$t = preg_replace( "#\[".$row['bbcode_tag']."=(?:&quot;|&\#39;)?(.+?)(?:&quot;|&\#39;)?\]#si", str_replace( '{option}', "\\1", $replace[0] ), $t );					}					else					{						$t = preg_replace( '#\['.$row['bbcode_tag'].'\]#i' , $replace[0], $t );					}										$t = preg_replace( '#\[/'.$row['bbcode_tag'].'\]#i', $replace[1], $t );				}			}		}				return $t;	}		//-----------------------------------------	// parse_html	// Converts the doHTML tag	//-----------------------------------------		function post_db_parse_html($t="")	{		if ( $t == "" )		{			return $t;		}				//-----------------------------------------		// Remove <br>s 'cos we know they can't		// be user inputted, 'cos they are still		// &lt;br&gt; at this point :)		//-----------------------------------------				if ( $this->pp_nl2br != 1 )		{			$t = str_replace( "<br>"    , "\n" , $t );			$t = str_replace( "<br />"  , "\n" , $t );		}				$t = str_replace( "&#39;"   , "'", $t );		$t = str_replace( "&#33;"   , "!", $t );		$t = str_replace( "&#036;"   , "$", $t );		$t = str_replace( "&#124;"  , "|", $t );		$t = str_replace( "&amp;"   , "&", $t );		$t = str_replace( "&gt;"    , ">", $t );		$t = str_replace( "&lt;"    , "<", $t );		$t = str_replace( "&quot;"  , '"', $t );				//-----------------------------------------		// Take a crack at parsing some of the nasties		// NOTE: THIS IS NOT DESIGNED AS A FOOLPROOF METHOD		// AND SHOULD NOT BE RELIED UPON!		//-----------------------------------------				$t = preg_replace( "/javascript/i" , "j&#097;v&#097;script", $t );		$t = preg_replace( "/alert/i"      , "&#097;lert"          , $t );		$t = preg_replace( "/about:/i"     , "&#097;bout:"         , $t );		$t = preg_replace( "/onmouseover/i", "&#111;nmouseover"    , $t );		$t = preg_replace( "/onclick/i"    , "&#111;nclick"        , $t );		$t = preg_replace( "/onload/i"     , "&#111;nload"         , $t );		$t = preg_replace( "/onsubmit/i"   , "&#111;nsubmit"       , $t );				return $t;	}			//-----------------------------------------	// Badwords:	// Swops naughty, naugty words and stuff	//-----------------------------------------		function bad_words($text = "")	{		global $DB, $ibforums;				if ($text == "")		{			return "";		}				if ( $this->bypass_badwords == 1 )		{			return $text;		}				//-----------------------------------------				if ( is_array( $ibforums->cache['badwords'] ) )		{			usort( $ibforums->cache['badwords'] , array( 'post_parser', 'word_length_sort' ) );						if ( count($ibforums->cache['badwords']) > 0 )			{				foreach($ibforums->cache['badwords'] as $idx => $r)				{									if ($r['swop'] == "")					{						$replace = '######';					}					else					{						$replace = $r['swop'];					}										//-----------------------------------------										$r['type'] = preg_quote($r['type'], "/");										//-----------------------------------------									if ($r['m_exact'] == 1)					{						$text = preg_replace( "/(^|\b)".$r['type']."(\b|!|\?|\.|,|$)/i", "$replace", $text );					}					else					{						$text = preg_replace( "/".$r['type']."/i", "$replace", $text );					}				}			}		}				return $text;			}			/*-------------------------------------------------------------------------*/	// unconvert:	// Parses the HTML back into plain text	/*-------------------------------------------------------------------------*/			function unconvert($txt="", $code=1, $html=0) {			$txt = preg_replace( "#<!--emo&(.+?)-->.+?<!--endemo-->#", "\\1" , $txt );				if ($code == 1)		{			$txt = preg_replace( "#<!--sql-->(.+?)<!--sql1-->(.+?)<!--sql2-->(.+?)<!--sql3-->#eis"    , "\$this->unconvert_sql(\"\\2\")", $txt);			$txt = preg_replace( "#<!--html-->(.+?)<!--html1-->(.+?)<!--html2-->(.+?)<!--html3-->#e", "\$this->unconvert_htm(\"\\2\")", $txt);					$txt = preg_replace( "#<!--Flash (.+?)-->.+?<!--End Flash-->#e"  , "\$this->unconvert_flash('\\1')", $txt );			$txt = preg_replace( "#<img src=[\"'](\S+?)['\"].+?".">#"           , "\[img\]\\1\[/img\]"            , $txt );						$txt = preg_replace( "#<a href=[\"']mailto:(.+?)['\"]>(.+?)</a>#"                         , "\[email=\\1\]\\2\[/email\]"   , $txt );			$txt = preg_replace( "#<a href=[\"'](http://|https://|ftp://|news://)?(\S+?)['\"].+?".">(.+?)</a>#" , "\[url=\\1\\2\]\\3\[/url\]"  , $txt );						$txt = preg_replace( "#<!--QuoteBegin-->(.+?)<!--QuoteEBegin-->#"                , '[quote]'         , $txt );			$txt = preg_replace( "#<!--QuoteBegin-{1,2}([^>]+?)\+([^>]+?)-->(.+?)<!--QuoteEBegin-->#"  , "[quote=\\1,\\2]" , $txt );			$txt = preg_replace( "#<!--QuoteBegin-{1,2}([^>]+?)\+-->(.+?)<!--QuoteEBegin-->#"       , "[quote=\\1]" , $txt );						$txt = preg_replace( "#<!--QuoteEnd-->(.+?)<!--QuoteEEnd-->#"                    , '[/quote]'        , $txt );						$txt = preg_replace( "#<!--c1-->(.+?)<!--ec1-->#", '[code]'   , $txt );			$txt = preg_replace( "#<!--c2-->(.+?)<!--ec2-->#", '[/code]'  , $txt );						$txt = preg_replace( "#<i>(.+?)</i>#is"  , "\[i\]\\1\[/i\]"  , $txt );			$txt = preg_replace( "#<b>(.+?)</b>#is"  , "\[b\]\\1\[/b\]"  , $txt );			$txt = preg_replace( "#<s>(.+?)</s>#is"  , "\[s\]\\1\[/s\]"  , $txt );			$txt = preg_replace( "#<u>(.+?)</u>#is"  , "\[u\]\\1\[/u\]"  , $txt );						$txt = preg_replace( "#(\n){0,}<ul>#" , "\\1\[list\]"  , $txt );			$txt = preg_replace( "#(\n){0,}<ol type='(a|A|i|I|1)'>#" , "\\1\[list=\\2\]\n"  , $txt );			$txt = preg_replace( "#(\n){0,}<li>#" , "\n\[*\]"     , $txt );			$txt = preg_replace( "#(\n){0,}</ul>(\n){0,}#", "\n\[/list\]\\2" , $txt );			$txt = preg_replace( "#(\n){0,}</ol>(\n){0,}#", "\n\[/list\]\\2" , $txt );						while ( preg_match( "#<span style=['\"]font-size:(.+?)pt;line-height:100%['\"]>(.+?)</span>#is", $txt ) )			{				$txt = preg_replace( "#<span style=['\"]font-size:(.+?)pt;line-height:100%['\"]>(.+?)</span>#ise" , "\$this->unconvert_size('\\1', '\\2')", $txt );			}						while ( preg_match( "#<span style=['\"]color:(.+?)['\"]>(.+?)</span>#is", $txt ) )			{				$txt = preg_replace( "#<span style=['\"]color:(.+?)['\"]>(.+?)</span>#is"    , "\[color=\\1\]\\2\[/color\]", $txt );			}						while ( preg_match( "#<span style=['\"]font-family:(.+?)['\"]>(.+?)</span>#is", $txt ) )			{				$txt = preg_replace( "#<span style=['\"]font-family:(.+?)['\"]>(.+?)</span>#is", "\[font=\\1\]\\2\[/font\]", $txt );			}						// Tidy up the end quote stuff						$txt = preg_replace( "#(\[/QUOTE\])\s*?<br />\s*#si", "\\1\n", $txt );			$txt = preg_replace( "#(\[/QUOTE\])\s*?<br>\s*#si"  , "\\1\n", $txt );						$txt = preg_replace( "#<!--EDIT\|.+?\|.+?-->#" , "" , $txt );			

⌨️ 快捷键说明

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