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

📄 post_parser.php

📁 简介:IceBB是一个强大
💻 PHP
📖 第 1 页 / 共 2 页
字号:
	/**	 * Undos the parsing of smilies	 *	 * @param		string		Parsed smilies string	 * @return		string		Unparsed smilies string	 */	function smilies_undo($t)	{		global $icebb,$db,$config,$std;				if(is_array($this->smilies_list))		{			foreach($this->smilies_list as $s)			{				$s['code']		= $this->xss_is_bad($s['code']);				$smiley_code	= preg_quote($s['code'],"`");				$find			= preg_quote("<img src='{$icebb->settings['board_url']}smilies/{$s['smiley_set']}/{$s['image']}' border='0' alt='{$s['code']}' />",'`');               				$t				= preg_replace("`{$find}`i",$s['code'],$t);			}		}				return $t;	}	/**	 * Parses bad words	 *	 * @param		string		String to parse	 * @return		string		Parsed string	 */	function bad_words($t)	{		global $icebb,$db,$std;				if(is_array($this->word_filters))		{			foreach($this->word_filters as $bw)			{				$word			= preg_quote($bw['bw_word'],'`');				//echo $word;				//$word			= str_replace('.','\.',$word);				//$word			= str_replace('\*','(.?)',$word);				//echo substr($word,strlen($word)-2,2);				if(substr($word,0,2)!='\*')				{					$word		= "(^|\b)".$word;				}				if(substr($word,strlen($word)-2,2)!='\*')				{					$word	   .= "(\b|\.|!|\?|,|$)";				}				$word		= str_replace('\*','',$word);				//echo $word;				$t				= preg_replace("`{$word}`i",$bw['bw_replacement'],$t);			}		}				return $t;	}		/**	 * Parses a string with the settings you specify	 *	 * @param		array		$t		Array including settings and string to parse	 * @param		array		$pdata	Info about a post	 * @return		string		Parsed string	 */	function parse($t,$pdata=array())	{		global $icebb,$std,$db;			if(!is_array($t))		{			// hmm, why did I do these uppercase? lol			$opt			= array('TEXT'=>$t,'SMILIES'=>1,'BBCODE'=>1,'BAD_WORDS'=>1,'ME_TAG'=>1,'YOU_TAG'=>1,'PARSE_ATTACHMENTS'=>1,'PARSE_QUOTES'=>1);		}		else {			$opt			= $t;			$t				= $opt['TEXT'];		}				//$t					= html_entity_decode($t,ENT_QUOTES);		$t					= $this->xss_is_bad($t);				// fix up a few things		$t					= preg_replace("`\(c\)`",'&copy;',$t);		$t					= preg_replace("`\(tm\)`",'&#153;',$t);		$t					= preg_replace("`\(r\)`",'&reg;',$t);		$t					= preg_replace("`\t`",'&nbsp;&nbsp;&nbsp;&nbsp;',$t);				if($icebb->user['view_smileys'] == 0)		{			$opt['SMILIES'] = 0;		}				if(!isset($opt['PARSE_QUOTES']))		{			$opt['PARSE_QUOTES']= 1;		}				// quotes disabled?		$this->parse_quotes	= $opt['PARSE_QUOTES'];			// do teh smilies		if($opt['SMILIES'] == 1)		{			$t				= $this->smilies($t);		}				// word wrap		//$t					= _wordwrap($t,100," ");		$t					= nl2br($t);		$t					= preg_replace("`&amp;#`","&#",$t);				// do teh bbcode		if($opt['BBCODE']  == 1)		{			$t				= $this->parse_links($t);			$t				= $this->bbcode($t);		}				// do teh bad words		if($opt['BAD_WORDS']  == 1)		{			$t				= $this->bad_words($t);		}				// me tag - something unique :o		if($opt['ME_TAG']  == 1)		{			$t				= preg_replace("`/me (.*)`","<span class='medoes'>* {$pdata['pauthor']} \\1</span>",$t);			// You tag ^_^			$t				= preg_replace("`/you (.*)`","<span class='medoes'>* {$icebb->user['username']} \\1</span>",$t);		}				// you tag - this will scare some people lol - *[you]* is a faggot		if($opt['YOU_TAG']  == 1)		{			$t				= preg_replace("`\*\[you\]\*`",$icebb->user['username'],$t);			// Theese two are gonna be funny:			$t				= preg_replace("`\*\[you_ip\]\*`",$icebb->client_ip,$t);			$t				= preg_replace("`\*\[you_host\]\*`",$_SERVER['REMOTE_HOST'],$t);		}		// option tag		if($opt['PARSE_ATTACHMENTS']== 1)		{			$t				= preg_replace("`\[attachment=([0-9]+)\]`ie","\$this->parse_attachment(\$this->uploads[\\1])",$t);		}				return $t;	}		/**	 * Parses attachments	 *	 * @param		string		String to parse	 * @return		string		Parsed string	 */	function parse_attachment($u)	{		global $icebb,$std;				$ext				= explode('.',$u['uname']);				$u['upath_real']	= str_replace($icebb->settings['board_url'],'',$u['upath']);		$u['upath']			= "{$icebb->base_url}act=attach&amp;upload={$u['uid']}";				if(class_exists('skin_func'))		{			$html			= $icebb->skin->load_template('topic');						if(strtolower($ext[1])=='jpg' || strtolower($ext[1])=='jpeg' || 			   strtolower($ext[1])=='gif' || strtolower($ext[1])=='png')			{				list($w,$h)	= getimagesize($u['upath-real']);				$t			= $html->attachment_view_image($u,$w,$h);			}			else {				$t			= $html->attachment_view($u);			}		}				return $t;	}	/**	 * Parses links	 *	 * @param		string		String to parse	 * @return		string		Parsed string	 */	function parse_links($t)	{		$t					= preg_replace("`\[url\]{$this->url_regex}\[/url\]`","[url]$1://$2[/url]",$t);		$t					= preg_replace("`\[url\]www\.{$this->url_regex_main}\[/url\]`","[url]http://www.$1[/url]",$t);		$t					= preg_replace("`(?<=^|[\n ]|\.){$this->url_regex}`","[url]$1://$2[/url]",$t);		$t					= preg_replace("`(?<=^|[\n ]|\.)www\.{$this->url_regex_main}`","[url=http://www.$1]www.$1[/url]",$t);			return $t;	}		/**	 * Gets rid of all known XSS vulnerabilities. Created with a lot of help from	 * http://blog.bitflux.ch/wiki/XSS_Prevention	 *	 * @param		string		String to parse	 * @return		string		Parsed string	*/	function xss_is_bad($t)	{		//echo "&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;";				//$t				= html_entity_decode($t,ENT_QUOTES,'UTF-8');		$t				= htmlspecialchars_decode($t,ENT_QUOTES);			$t				= str_replace("<","&#60;",$t);		$t				= str_replace(">","&#62;",$t);			//$t				= str_replace("&quot;","&quot;",$t);		$t				= preg_replace("/&#0*([0-9]*);?/",'&#\\1;',$t);		$t				= str_replace('&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;','javascript:',$t);			//$t				= html_entity_decode($t,ENT_QUOTES);		//echo $t;			$t				= preg_replace("/javascript:/i"		, "nojava"/*&#97;v&#97;*/."script:"	,$t);		$t				= preg_replace("/vbscript:/i"		, "novb"/*&#98;*/."script:"	,$t);		//$t				= preg_replace('/&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;/i','j&#97;v&#97;script:',$t);		//$t				= preg_replace('#(<[^>]+[\s\r\n\"\'])(on|xmlns)[^>]*\]#iU',"$1]",$t);			//$t				= htmlspecialchars($t,ENT_QUOTES);				//$t					= htmlentities($t,ENT_QUOTES);				//$t					= preg_replace("`&#38;#([0-9]+);`s",'&#\\1;',$t);			return $t;	}		/**	 * Removes "faked" characters	 *	 * @param		string		String to parse	 * @return		string		Parsed string	 */	function remove_fakechars($t)	{		$replace	= array(			'&#1072;'=>'a',			'&#1077;'=>'e',			'&#1086;'=>'o',			'&#1088;'=>'p',			'&#1089;'=>'c',			'&#1091;'=>'y',			'&#1093;'=>'x',		);				//print_r($arran);				$t			= str_replace(array_keys($replace),$replace,$t);				return $t;	}		/**	 * Changes HTML (from the WYSIWYG editor) to BBCode	 *	 * @param		string		String to parse	 * @param		string		Parsed string	 */	function html_to_bbcode($t)	{		global $icebb,$db,$std;				// take care of smilies first		if(is_array($this->smilies_list))		{			foreach($this->smilies_list as $s)			{				$s['code']		= $this->xss_is_bad($s['code']);				$smiley_code	= preg_quote($s['code'],"`");								$t				= preg_replace("`(&#60;|&lt;)img src=(&#34;|&quot;)({$icebb->settings['board_url']})?smilies/{$s['smiley_set']}/{$s['image']}(&#34;|&quot;)(\s/)?(&#62;|&gt;)`i","{$s['code']}",$t);			}		}				// then newlines		$t			= preg_replace("`(&#60;|&lt;)br(\s/)?(&#62;|&gt;)`is","\n",$t);		$t			= preg_replace("`(&#60;|&lt;)p(&#62;|&gt;)(.+?)(&#60;|&lt;)/p(&#62;|&gt;)`is","\\3\n\n",$t);				// then some BBCode		$t			= preg_replace("`(&#60;|&lt;)b(&#62;|&gt;)(.+?)(&#60;|&lt;)/b(&#62;|&gt;)`is","[b]\\3[/b]",$t);		$t			= preg_replace("`(&#60;|&lt;)u(&#62;|&gt;)(.+?)(&#60;|&lt;)/u(&#62;|&gt;)`is","[u]\\3[/u]",$t);		$t			= preg_replace("`(&#60;|&lt;)i(&#62;|&gt;)(.+?)(&#60;|&lt;)/i(&#62;|&gt;)`is","[i]\\3[/i]",$t);				$t			= preg_replace("`(&#60;|&lt;)img src=(&#34;|&quot;)(.+?)(&#34;|&quot;)(\s/)?(&#62;|&gt;)`i","[img]\\3[/img]",$t);		$t			= preg_replace("`(&#60;|&lt;)a href=(&#34;|&quot;)(.+?)(&#34;|&quot;)(&#62;|&gt;)(.+?)(&#60;|&lt;)/a(&#62;|&gt;)`is","[url=\\3]\\6[/url]",$t);				$t			= preg_replace("`(&#60;|&lt;)p align=(&#34;|&quot;)left(&#34;|&quot;)(&#62;|&gt;)(.+?)(&#60;|&lt;)/p(&#62;|&gt;)`is","[left]\\5[/left]",$t);		$t			= preg_replace("`(&#60;|&lt;)p align=(&#34;|&quot;)center(&#34;|&quot;)(&#62;|&gt;)(.+?)(&#60;|&lt;)/p(&#62;|&gt;)`is","[center]\\5[/center]",$t);		$t			= preg_replace("`(&#60;|&lt;)p align=(&#34;|&quot;)right(&#34;|&quot;)(&#62;|&gt;)(.+?)(&#60;|&lt;)/p(&#62;|&gt;)`is","[right]\\5[/right]",$t);				$t			= preg_replace("`(&#60;|&lt;)div align=(&#34;|&quot;)left(&#34;|&quot;)(&#62;|&gt;)(.+?)(&#60;|&lt;)/div(&#62;|&gt;)`is","[left]\\5[/left]",$t);		$t			= preg_replace("`(&#60;|&lt;)div align=(&#34;|&quot;)center(&#34;|&quot;)(&#62;|&gt;)(.+?)(&#60;|&lt;)/div(&#62;|&gt;)`is","[center]\\5[/center]",$t);		$t			= preg_replace("`(&#60;|&lt;)div align=(&#34;|&quot;)right(&#34;|&quot;)(&#62;|&gt;)(.+?)(&#60;|&lt;)/div(&#62;|&gt;)`is","[right]\\5[/right]",$t);						// font - I WANT TO FUCKING KILL THE WYSIWYG EDITOR >_<		$t			= $this->_recurse_html_regex('font',"`(&#60;|&lt;)font(.+?)(&#62;|&gt;)(.+?)(&#60;|&lt;)/font(&#62;|&gt;)`ise","\$this->_handle_font_html('$2','$4')",$t);		// clean up extras		$t			= str_replace("&amp;nbsp;",' ',$t);		return $t;	}		function _recurse_html_regex($tag,$regex,$replace,$r,$recursion=0)	{		//if($recursion>15) return $r;			$r			= preg_replace($regex,$replace,$r);			if(preg_match("`(&#60;|&lt;){$tag}`i",$r))		{			//echo "<br />STILL MORE ({$recursion})<br />";			$r		= $this->_recurse_html_regex($tag,$regex,$replace,$r,$recursion+1);		}				return $r;	}		function _handle_font_html($attributes,$r)	{		global $db;			$attributes		= trim($attributes);		$attributes		= html_entity_decode($attributes,ENT_QUOTES);		$attributes		= $this->_attribute_split($attributes);		//$attr			= trim($attributes);				foreach($attributes as $attr)		{			$at		= explode('=',$attr);			$at[1]	= preg_replace("`(&#34;|&quot;)`i",'',$at[1]);			$at[1]	= $db->escape_string($at[1]);						switch($at[0])			{				case 'color':					$r= "[color={$at[1]}]{$r}[/color]";					break;				case 'face':					$r= "[font={$at[1]}]{$r}[/font]";					break;				case 'size':					$at[1]= intval($at[1])*7;					$r= "[size={$at[1]}]{$r}[/size]";					break;			}		}				return $r;	}		function _attribute_split($raw)	{		$in_quotes			= 0;		$counter			= 0;		for($i=0;$i<=strlen($raw);$i++)		{			$chr			= $raw{$i};			if($chr			== '"')			{				$in_quotes= $in_quotes ? 0 : 1;				$chr		= '';			}						if(!$in_quotes && $chr==' ')			{				$chr		= '';				$counter++;			}						$attrs[$counter].= $chr;		}				return $attrs;	}}?>

⌨️ 快捷键说明

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