⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 post_parser.php

📁 泛微协同办公系统标准版E-office V5.5的源代码内含泛微办公系统V5.5自动注册文件。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php

class post_parser
{

	var $error = "";
	var $image_count = 0;
	var $emoticon_count = 0;
	var $quote_html = array( );
	var $quote_open = 0;
	var $quote_closed = 0;
	var $quote_error = 0;
	var $emoticons = "";
	var $badwords = "";
	var $strip_quotes = "";
	var $in_sig = "";

	function smilie_length_sort( $a, $b )
	{
		if ( strlen( $a['typed'] ) == strlen( $b['typed'] ) )
		{
			return 0;
		}
		return strlen( $b['typed'] ) < strlen( $a['typed'] ) ? -1 : 1;
	}

	function word_length_sort( $a, $b )
	{
		if ( strlen( $a['type'] ) == strlen( $b['type'] ) )
		{
			return 0;
		}
		return strlen( $b['type'] ) < strlen( $a['type'] ) ? -1 : 1;
	}

	function post_parser( $load = 0 )
	{
		global $ibforums;
		global $DB;
		$this->strip_quotes = $ibforums->vars['strip_quotes'];
		if ( $load != 0 )
		{
			$DB->query( "SELECT * from ibf_badwords" );
			while ( $DB->get_num_rows( ) && ( $r = $DB->fetch_row( ) ) )
			{
				$this->badwords[] = array(
					"type" => stripslashes( $r['type'] ),
					"swop" => stripslashes( $r['swop'] ),
					"m_exact" => $r['m_exact']
				);
			}
			$this->emoticons = array( );
			$DB->query( "SELECT typed, image from ibf_emoticons" );
			while ( $DB->get_num_rows( ) && ( $r = $DB->fetch_row( ) ) )
			{
				$this->emoticons[] = array(
					"typed" => stripslashes( $r['typed'] ),
					"image" => stripslashes( $r['image'] ),
					"clickable" => $r['clickable']
				);
			}
		}
	}

	function parse_poll_tags( $txt )
	{
		$txt = preg_replace( "#\\[img\\](.+?)\\[/img\\]#ie", "\$this->regex_check_image('\\1')", $txt );
		$txt = preg_replace( "#\\[url\\](\\S+?)\\[/url\\]#ie", "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\1'))", $txt );
		$txt = preg_replace( "#\\[url\\s*=\\s*\\&quot\\;\\s*(\\S+?)\\s*\\&quot\\;\\s*\\](.*?)\\[\\/url\\]#ie", "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt );
		$txt = preg_replace( "#\\[url\\s*=\\s*(\\S+?)\\s*\\](.*?)\\[\\/url\\]#ie", "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt );
		return $txt;
	}

	function convert( $in = array
	(
		"TEXT" => "",
		"SMILIES" => 0,
		"CODE" => 0,
		"SIGNATURE" => 0,
		"HTML" => 0
	) )
	{
		global $ibforums;
		global $DB;
		$this->in_sig = $in['SIGNATURE'];
		$txt = $in['TEXT'];
		$txt = preg_replace( "#(\\?|&amp;|;|&)s=([0-9a-zA-Z]){32}(&amp;|;|&|\$)?#e", "\$this->regex_bash_session('\\1', '\\3')", $txt );
		$txt = preg_replace( "/<br>|<br\\s*\\/>/", "\n", $txt );
		if ( $in['CODE'] == 1 )
		{
			$txt = preg_replace( "#\\[code\\](.+?)\\[/code\\]#ies", "\$this->regex_code_tag('\\1')", $txt );
			$txt = preg_replace( "#(^|\\s)((http|https|news|ftp)://\\w+[^\\s\\[\\]]+)#ie", "\$this->regex_build_url(array('html' => '\\2', 'show' => '\\2', 'st' => '\\1'))", $txt );
			$txt = preg_replace( "#(\\[quote(.+?)?\\].*\\[/quote\\])#ies", "\$this->regex_parse_quotes('\\1')", $txt );
			if ( $in['SIGNATURE'] != 1 )
			{
				$txt = preg_replace( "#\\[sql\\](.+?)\\[/sql\\]#ies", "\$this->regex_sql_tag('\\1')", $txt );
				$txt = preg_replace( "#\\[html\\](.+?)\\[/html\\]#ies", "\$this->regex_html_tag('\\1')", $txt );
				$txt = preg_replace( "#\\[list\\]#i", "<ul>", $txt );
				$txt = preg_replace( "#\\[\\*\\]#", "<li>", $txt );
				$txt = preg_replace( "#\\[/list\\]#i", "</ul>", $txt );
			}
			if ( $ibforums->vars['allow_images'] )
			{
				$txt = preg_replace( "#\\[img\\](.+?)\\[/img\\]#ie", "\$this->regex_check_image('\\1')", $txt );
				$txt = preg_replace( "#(\\[flash=)(\\S+?)(\\,)(\\S+?)(\\])(\\S+?)(\\[\\/flash\\])#ie", "\$this->regex_check_flash('\\2','\\4','\\6')", $txt );
			}
			$txt = preg_replace( "#\\[b\\](.+?)\\[/b\\]#is", "<b>\\1</b>", $txt );
			$txt = preg_replace( "#\\[i\\](.+?)\\[/i\\]#is", "<i>\\1</i>", $txt );
			$txt = preg_replace( "#\\[u\\](.+?)\\[/u\\]#is", "<u>\\1</u>", $txt );
			$txt = preg_replace( "#\\[s\\](.+?)\\[/s\\]#is", "<s>\\1</s>", $txt );
			$txt = preg_replace( "#\\(c\\)#i", "&copy;", $txt );
			$txt = preg_replace( "#\\(tm\\)#i", "&#153;", $txt );
			$txt = preg_replace( "#\\(r\\)#i", "&reg;", $txt );
			while ( preg_match( "#\\[size=([^\\]]+)\\](.+?)\\[/size\\]#ies", $txt ) )
			{
				$txt = preg_replace( "#\\[size=([^\\]]+)\\](.+?)\\[/size\\]#ies", "\$this->regex_font_attr(array('s'=>'size','1'=>'\\1','2'=>'\\2'))", $txt );
			}
			while ( preg_match( "#\\[font=([^\\]]+)\\](.*?)\\[/font\\]#ies", $txt ) )
			{
				$txt = preg_replace( "#\\[font=([^\\]]+)\\](.*?)\\[/font\\]#ies", "\$this->regex_font_attr(array('s'=>'font','1'=>'\\1','2'=>'\\2'))", $txt );
			}
			while ( preg_match( "#\\[color=([^\\]]+)\\](.+?)\\[/color\\]#ies", $txt ) )
			{
				$txt = preg_replace( "#\\[color=([^\\]]+)\\](.+?)\\[/color\\]#ies", "\$this->regex_font_attr(array('s'=>'col' ,'1'=>'\\1','2'=>'\\2'))", $txt );
			}
			$txt = preg_replace( "#\\[email\\](\\S+?)\\[/email\\]#i", "<a href='mailto:\\1'>\\1</a>", $txt );
			$txt = preg_replace( "#\\[email\\s*=\\s*\\&quot\\;([\\.\\w\\-]+\\@[\\.\\w\\-]+\\.[\\.\\w\\-]+)\\s*\\&quot\\;\\s*\\](.*?)\\[\\/email\\]#i", "<a href='mailto:\\1'>\\2</a>", $txt );
			$txt = preg_replace( "#\\[email\\s*=\\s*([\\.\\w\\-]+\\@[\\.\\w\\-]+\\.[\\w\\-]+)\\s*\\](.*?)\\[\\/email\\]#i", "<a href='mailto:\\1'>\\2</a>", $txt );
			$txt = preg_replace( "#\\[url\\](\\S+?)\\[/url\\]#ie", "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\1'))", $txt );
			$txt = preg_replace( "#\\[url\\s*=\\s*\\&quot\\;\\s*(\\S+?)\\s*\\&quot\\;\\s*\\](.*?)\\[\\/url\\]#ie", "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt );
			$txt = preg_replace( "#\\[url\\s*=\\s*(\\S+?)\\s*\\](.*?)\\[\\/url\\]#ie", "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt );
		}
		$txt = preg_replace( "/\n/", "<br>", $txt );
		if ( $in['SMILIES'] != 0 && $in['SIGNATURE'] == 0 )
		{
			$txt = " ".$txt." ";
			if ( !is_array( $this->emoticons ) )
			{
				$DB->query( "SELECT typed, image from ibf_emoticons" );
				$this->emoticons = array( );
				while ( $DB->get_num_rows( ) && ( $r = $DB->fetch_row( ) ) )
				{
					$this->emoticons[] = array(
						"typed" => stripslashes( $r['typed'] ),
						"image" => stripslashes( $r['image'] ),
						"clickable" => $r['clickable']
					);
				}
			}
			usort( $this->emoticons, array( "post_parser", "smilie_length_sort" ) );
			if ( 0 < count( $this->emoticons ) )
			{
				foreach ( $this->emoticons as $a_id => $row )
				{
					$code = $row['typed'];
					$image = $row['image'];
					$code = preg_quote( $code, "/" );
					$txt = preg_replace( "!(?<=[^\\w&;]){$code}(?=.\\W|\\W.|\\W\$)!ei", "\$this->convert_emoticon('{$code}', '{$image}')", $txt );
				}
			}
			if ( $ibforums->vars['max_emos'] && $ibforums->vars['max_emos'] < $this->emoticon_count )
			{
				$this->error = "too_many_emoticons";
			}
		}
		if ( $in['HTML'] == 1 )
		{
			$txt = str_replace( "&lt;", "<", $txt );
			$txt = str_replace( "&gt;", ">", $txt );
			$txt = str_replace( "&quot;", "\"", $txt );
			$txt = str_replace( "&#039;", "'", $txt );
			$txt = str_replace( "&amp;", "&", $txt );
		}
		$txt = $this->bad_words( $txt );
		return $txt;
	}

	function bad_words( $text = "" )
	{
		global $DB;
		global $ibforums;
		if ( $text == "" )
		{
			return "";
		}
		if ( !is_array( $this->badwords ) )
		{
			$DB->query( "SELECT * from ibf_badwords" );
			$this->badwords = array( );
			while ( $DB->get_num_rows( ) && ( $r = $DB->fetch_row( ) ) )
			{
				$this->badwords[] = array(
					"type" => stripslashes( $r['type'] ),
					"swop" => stripslashes( $r['swop'] ),
					"m_exact" => $r['m_exact']
				);
			}
		}
		usort( $this->badwords, array( "post_parser", "word_length_sort" ) );
		if ( 0 < count( $this->badwords ) )
		{
			foreach ( $this->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;
	}

	function unconvert( $txt = "", $code = 1, $html = 0 )
	{
		if ( $code == 1 )
		{
			$txt = preg_replace( "#<!--emo&(.+?)-->.+?<!--endemo-->#", "\\1", $txt );
			$txt = preg_replace( "#<!--sql-->(.+?)<!--sql1-->(.+?)<!--sql2-->(.+?)<!--sql3-->#e", "\$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( "#<!--c1-->(.+?)<!--ec1-->#", "[CODE]", $txt );
			$txt = preg_replace( "#<!--c2-->(.+?)<!--ec2-->#", "[/CODE]", $txt );
			$txt = preg_replace( "#<!--QuoteBegin--(.+?)\\+(.+?)-->(.+?)<!--QuoteEBegin-->#", "[QUOTE=\\1,\\2]", $txt );
			$txt = preg_replace( "#<!--QuoteBegin--(.+?)\\+-->(.+?)<!--QuoteEBegin-->#", "[QUOTE=\\1]", $txt );
			$txt = preg_replace( "#<!--QuoteBegin-->(.+?)<!--QuoteEBegin-->#", "[QUOTE]", $txt );
			$txt = preg_replace( "#<!--QuoteEnd-->(.+?)<!--QuoteEEnd-->#", "[/QUOTE]", $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( "#<ul>#", "\\[LIST\\]", $txt );
			$txt = preg_replace( "#<li>#", "\\[*\\]", $txt );
			$txt = preg_replace( "#</ul>#", "\\[/LIST\\]", $txt );
			$txt = preg_replace( "#<!--me&(.+?)-->(.+?)<!--e--me-->#e", "\$this->unconvert_me('\\1', '\\2')", $txt );
			$txt = preg_replace( "#<span style=['\"]font-size:(.+?)pt;line-height:100%['\"]>(.+?)</span>#e", "\$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 );
			}
			$txt = preg_replace( "#<span style=['\"]font-family:(.+?)['\"]>(.+?)</span>#", "\\[font=\\1\\]\\2\\[/font\\]", $txt );
			$txt = preg_replace( "#(\\[/QUOTE\\])\\s*?<br>\\s*#si", "\\1\n", $txt );
			$txt = preg_replace( "#<!--EDIT\\|.+?\\|.+?-->#", "", $txt );
		}
		if ( $html == 1 )
		{
			$txt = str_replace( "&#39;", "'", $txt );
		}
		$txt = preg_replace( "#<br>#", "\n", $txt );
		return trim( stripslashes( $txt ) );
	}

	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_me( $name = "", $text = "" )
	{
		$text = preg_replace( "#<span class='ME'><center>(.+?)</center></span>#", "\\1", $text );
		$text = preg_replace( "#{$name}#", "", $text );
		return "[ME=".$name."]".$text."[/ME]";
	}

	function unconvert_sql( $sql = "" )
	{
		$sql = stripslashes( $sql );
		$sql = preg_replace( "#<span style='.+?'>(.+?)</span>#", "\\1", $sql );
		$sql = preg_replace( "#\\s*\$#", "", $sql );
		return "[SQL]".$sql."[/SQL]";
	}

	function unconvert_htm( $html = "" )
	{
		$html = stripslashes( $html );
		$html = preg_replace( "#<span style='.+?'>(.+?)</span>#", "\\1", $html );
		$html = preg_replace( "#\\s*\$#", "", $html );
		return "[HTML]".$html."[/HTML]";
	}

	function convert_emoticon( $code = "", $image = "" )
	{
		global $ibforums;
		if ( !$code || !$image )
		{
			return;
		}
		$code = stripslashes( $code );
		++$this->emoticon_count;
		return "<!--emo&{$code}--><img src='{$ibforums->vars['EMOTICONS_URL']}/{$image}' border='0' style='vertical-align:middle' alt='{$image}'><!--endemo-->";
	}

	function wrap_style( $in = array( ) )
	{
		global $ibforums;
		if ( !isset( $in['TYPE'] ) )
		{
			$in['TYPE'] = "class";
		}
		if ( !isset( $in['CSS'] ) )
		{
			$in['CSS'] = $this->in_sig == 1 ? "signature" : "postcolor";
		}
		if ( !isset( $in['STYLE'] ) )
		{
			$in['STYLE'] = "QUOTE";
		}
		$possible_use = array(
			"CODE" => array( "CODE", "CODE" ),
			"QUOTE" => array( "QUOTE", "QUOTE" ),
			"SQL" => array( "CODE", "SQL" ),
			"HTML" => array( "CODE", "HTML" ),
			"PHP" => array( "CODE", "PHP" )
		);
		return array(
			"START" => "</span><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>{$possible_use[$in[STYLE]][1]}</b> {$in[EXTRA]}</td></tr><tr><td id='{$possible_use[$in[STYLE]][0]}'>",
			"END" => "</td></tr></table><span {$in[TYPE]}='{$in[CSS]}'>"
		);
	}

	function regex_html_tag( $html = "" )
	{
		if ( $html == "" )
		{
			return;
		}
		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;
		}
		$html = preg_replace( "#:#", "&#58;", $html );
		$html = preg_replace( "#\\[#", "&#91;", $html );
		$html = preg_replace( "#\\]#", "&#93;", $html );

⌨️ 快捷键说明

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