class_bbcode_core.php

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

PHP
1,825 行
字号
	* @param	string	URL	* @return	string	IMG tag HTML	*/	function regex_check_image($url="")	{		if ( ! $url )		{			return;		}				$url = trim($url);				$default = "[img]".$url."[/img]";				$this->image_count++;			//-----------------------------------------		// Make sure we've not overriden the set image # limit		//-----------------------------------------				if ($this->ipsclass->vars['max_images'])		{			if ($this->image_count > $this->ipsclass->vars['max_images'])			{				$this->error = 'too_many_img';				return $default;			}		}				//-----------------------------------------		// XSS check		//-----------------------------------------				$url = urldecode( $url );		$url = str_replace( "document.cookie", "", $url );				//-----------------------------------------		// Are they attempting to post a dynamic image, or JS?		//-----------------------------------------				if ( $this->ipsclass->vars['allow_dynamic_img'] != 1 )		{			if ( preg_match( "/[?&;]/", $url) )			{				$this->error = 'no_dynamic';				return $default;			}						if ( preg_match( "/java(\s+?)?script(\:|\s)/is", $url ) )			{				$this->error = 'no_dynamic';				return $default;			}		}			//-----------------------------------------		// Is the img extension allowed to be posted?		//-----------------------------------------				if ( $this->ipsclass->vars['img_ext'] )		{			$extension = preg_replace( "#^.*\.(\w+)(\?.*$|$)#", "\\1", $url );						$extension = strtolower($extension);						if ( (! $extension) OR ( preg_match( "#/#", $extension ) ) )			{				$this->error = 'invalid_ext';				return $default;			}						$this->ipsclass->vars['img_ext'] = strtolower($this->ipsclass->vars['img_ext']);						if ( ! preg_match( "/".preg_quote($extension, '/')."(,|$)/", $this->ipsclass->vars['img_ext'] ))			{				$this->error = 'invalid_ext';				return $default;			}		}				//-----------------------------------------		// Is it a legitimate image?		//-----------------------------------------				/*if ( ! preg_match( "/^(http|https|ftp):\/\//i", $url ) )		{			$this->error = 'no_dynamic';			return $default;		}*/				//-----------------------------------------		// If we are still here....		//-----------------------------------------				$url = str_replace( " ", "%20", $url );				return "<img src=\"$url\" border=\"0\" alt=\"{$this->ipsclass->lang['bbcode_img_alt']}\" />";	}	    /*-------------------------------------------------------------------------*/	// regex_font_attr:	// Returns a string for an /e regexp based on the input	/*-------------------------------------------------------------------------*/		/**	* Convert size / color / font BBCode tags	*	* @param	array	Vars	* @return	string	Converted text	*/	function regex_font_attr( $IN )	{		if ( ! is_array($IN) )		{			return;		}				//-----------------------------------------		// Make safe		//-----------------------------------------				$IN['1'] = preg_replace( "/[&\(\)\.\%\[\]<>]/", "", preg_replace( "#^(.+?)(?:;|$)#", "\\1", $IN['1'] ) );				//-----------------------------------------		// Size		//-----------------------------------------				if ($IN['s'] == 'size')		{			$IN['1'] = intval($IN['1']) + 7;						if ($IN['1'] > 30)			{				$IN['1'] = 30;			}						return "<span style='font-size:".$IN['1']."pt;line-height:100%'>".$IN['2']."</span>";		}				//-----------------------------------------		// BACKGROUND		//-----------------------------------------				else if ($IN['s'] == 'background')		{			$IN[1] = preg_replace( "/[^\d\w\#\s]/s", "", $IN[1] );			return "<span style='background-color:".$IN[1]."'>".$IN['2']."</span>";		}				//-----------------------------------------		// COLOR		//-----------------------------------------				else if ($IN['s'] == 'col')		{			$IN[1] = preg_replace( "/[^\d\w\#\s]/s", "", $IN[1] );			return "<span style='color:".$IN[1]."'>".$IN['2']."</span>";		}				//-----------------------------------------		// FONT		//-----------------------------------------				else if ($IN['s'] == 'font')		{			$IN['1'] = preg_replace( "/[^\d\w\#\-\_\s]/s", "", $IN['1'] );			return "<span style='font-family:".$IN['1']."'>".$IN['2']."</span>";		}	}		/*-------------------------------------------------------------------------*/	// regex_list: List generation	/*-------------------------------------------------------------------------*/		/**	* Convert list BBCode	*	* @param	string	Raw text	* @param	string	List type	* @return	string	Converted text	*/	function regex_list( $txt="", $type="" )	{		if ($txt == "")		{			return;		}				if ( $type == "" )		{			return "<ul>".$this->regex_list_item($txt)."</ul>";		}		else		{			return "<ol type='$type'>".$this->regex_list_item($txt)."</ol>";		}	}		/*-------------------------------------------------------------------------*/	// Regex list item	/*-------------------------------------------------------------------------*/		/**	* Convert list item	*	* @param	string	Raw text	* @return	string	Converted text	*/	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_parse_quotes: Builds this quote tag HTML	/*-------------------------------------------------------------------------*/		/**	* Parse quotes: main	*	* @param	string	Raw text	* @return	string	Converted text	*/	function regex_parse_quotes($the_txt="")	{		$this->quote_open   = 0;		$this->quote_closed = 0;		$this->quote_error  = 0;				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_close_quote()"                  , $txt );		$txt = preg_replace( "#\[quote=([^\],]+?),([^\]]+?)\]#ie" , "\$this->regex_quote_tag('\\1', '\\2', '\\3')" , $txt );		$txt = preg_replace( "#\[quote=([^\]]+?)\]#ie"            , "\$this->regex_quote_tag('\\1', '')"           , $txt );		$txt = preg_replace( "#\[quote([^\]]+?)?\]#ie"            , "\$this->regex_simple_quote_tag('\\1')"        , $txt );						$txt = str_replace( "\n", "<br />", $txt );				if ( ($this->quote_open == $this->quote_closed) and ($this->quote_error == 0) )		{			return $txt;		}		else		{			//print "{$this->quote_open} == {$this->quote_closed}";			return $the_txt;		}	}			/*-------------------------------------------------------------------------*/	// regex_simple_quote_tag: Builds this quote tag HTML	/*-------------------------------------------------------------------------*/		/**	* Convert simple quote tag	*	* @param	string	Raw text	* @return	string	Converted text	*/	function regex_simple_quote_tag( $extra='' )	{		//-----------------------------------------		// INIT		//-----------------------------------------				$extra   = $extra;		$post_id = 0;		$date    = '';		$name    = '';				//-----------------------------------------		// Inc..		//-----------------------------------------				$this->quote_open++;				//-----------------------------------------		// Post?		//-----------------------------------------				preg_match( "#post=([\"']|&quot;|&\#039;|&\#39;)?(\d+)([\"']|&quot;|&\#039;|&\#39;)?#", $extra, $match );				if ( intval( $match[2] ) )		{			$post_id = intval( $match[2] );		}				//-----------------------------------------		// Name?		//-----------------------------------------				preg_match( "#name=([\"']|&quot;|&\#039;|&\#39;)(.+?)([\"']|&quot;|&\#039;|&\#39;)\s?(date|post)#is", $extra, $match );				if ( $match[2] )		{			$name = $this->_make_quote_safe($match[2]);		}				//-----------------------------------------		// Date?		//-----------------------------------------				preg_match( "#date=([\"']|&quot;|&\#039;|&\#39;)(.+?)([\"']|&quot;|&\#039;|&\#39;)#", $extra, $match );				if ( $match[2] )		{			$date = $this->_make_quote_safe($match[2]);		}				//-----------------------------------------		// Anything?		//-----------------------------------------				if ( ! $post_id AND ! $date AND ! $name )		{			return "<!--quoteo-->{$this->quote_html['START']}<!--quotec-->";		}		else		{			//-----------------------------------------			// Name...			//-----------------------------------------						if ( $name or $date )			{				$textra = '(';			}						if ( $name )			{				$textra .= $name;			}						//-----------------------------------------			// Date...			//-----------------------------------------						if ( $date )			{				$textra .= ' &#064; '.$date;			}						if ( $name or $date )			{				$textra .= ')';			}						//-----------------------------------------			// Post...			//-----------------------------------------						if ( $post_id )			{				$textra .= " [snapback]{$post_id}[/snapback]";			}						$html = $this->wrap_style( 'quote', $textra );						//-----------------------------------------			// Return...			//-----------------------------------------						return "<!--quoteo(post={$post_id}:date={$date}:name={$name})-->{$html['START']}<!--quotec-->";		}	}		/*-------------------------------------------------------------------------*/	// regex_close_quote: closes a quote tag	/*-------------------------------------------------------------------------*/		/**	* Convert quote close tag	*	* @return	string	Converted text	*/	function regex_close_quote()	{		$this->quote_closed++;				return "<!--QuoteEnd-->{$this->quote_html['END']}<!--QuoteEEnd-->";	}		/*-------------------------------------------------------------------------*/	// regex_quote_tag: Builds this quote tag HTML (OLD)	/*-------------------------------------------------------------------------*/		/**	* Convert quote tag: Main	*	* @param	string	Poster's name	* @param	string	Date String	* @param	string	Post content	* @return	string	Converted text	*/	function regex_quote_tag($name="", $date="", $post="")	{ 		//-----------------------------------------		// Defaults		//-----------------------------------------				$name = $name;		$date = $date;		$post = $post;				if ( $date != "" )		{			$default = "[quote=$name,$date{$post}]";		}		else		{			$default = "[quote=$name{$post}]";		}				if ( strstr( $name, '<!--c1-->' ) or strstr( $date, '<!--c1-->' ) )		{			//-----------------------------------------			// Code tag detected...			//-----------------------------------------						$this->quote_error++;		 	return $default;		}				//-----------------------------------------		// Sort name		//-----------------------------------------				$name = str_replace( "+", "&#043;", $name );		$name = str_replace( "-", "&#045;", $name );		$name = str_replace( '[', "&#091;", $name );		$name = str_replace( ']', "&#093;", $name );				//-----------------------------------------		// Inc..		//-----------------------------------------				$this->quote_open++;				//-----------------------------------------		// Quote header

⌨️ 快捷键说明

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