class_bbcode_core.php

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

PHP
1,825 行
字号
		//-----------------------------------------				if ($date == "")		{			$hextra = "($name)";		}		else		{			$hextra = "($name &#064; $date)";		}				$html = $this->wrap_style( 'quote', $hextra );				//-----------------------------------------		// Sort out extra		//-----------------------------------------				$extra = "-".$name.'+'.$date;				//-----------------------------------------		// Return...		//-----------------------------------------				return "<!--QuoteBegin".$extra."-->{$html['START']}<!--QuoteEBegin-->";	}				/*-------------------------------------------------------------------------*/	// regex_build_url: Checks, and builds the a href	/*-------------------------------------------------------------------------*/		/**	* Convert URLs	*	* @param	array	Input vars	* @return	string	Converted text	*/	function regex_build_url( $url=array() )	{		$skip_it = 0;				//-----------------------------------------		// Make sure the last character isn't punctuation..		// if it is, remove it and add it to the		// end array		//-----------------------------------------				if ( preg_match( "/([\.,\?]|&#33;)$/", $url['html'], $match) )		{			$url['end'] .= $match[1];			$url['html'] = preg_replace( "/([\.,\?]|&#33;)$/", "", $url['html'] );			$url['show'] = preg_replace( "/([\.,\?]|&#33;)$/", "", $url['show'] );		}				//-----------------------------------------		// Make sure it's not being used in a		// closing code/quote/html or sql block		//-----------------------------------------				if (preg_match( "/\[\/(html|quote|code|sql)/i", $url['html']) )		{			return $url['html'];		}				//-----------------------------------------		// clean up the ampersands / brackets		//-----------------------------------------				$url['html'] = str_replace( "&amp;" , "&"   , $url['html'] );		$url['html'] = str_replace( "["     , "%5b" , $url['html'] );		$url['html'] = str_replace( "]"     , "%5d" , $url['html'] );				//-----------------------------------------		// Make sure we don't have a JS link		//-----------------------------------------				$url['html'] = preg_replace( "/javascript:/i", "java script&#58; ", $url['html'] );				//-----------------------------------------		// Do we have http:// at the front?		//-----------------------------------------				if ( ! preg_match("#^(http|news|https|ftp|aim)://#", $url['html'] ) )		{			$url['html'] = 'http://'.$url['html'];		}				//-----------------------------------------		// Tidy up the viewable URL		//-----------------------------------------		if ( preg_match( "/^<img src/i", $url['show'] ) )		{			$skip_it     = 1;			$url['show'] = stripslashes($url['show']);		}		$url['show'] = preg_replace( "/&amp;/" , "&" , $url['show'] );		$url['show'] = preg_replace( "/javascript:/i", "javascript&#58; ", $url['show'] );				if ( (strlen($url['show']) -58 ) < 3 )  $skip_it = 1;				//-----------------------------------------		// Make sure it's a "proper" url		//-----------------------------------------				if ( ! preg_match( "/^(http|ftp|https|news):\/\//i", $url['show'] )) $skip_it = 1;				$show = $url['show'];				if ($skip_it != 1)		{			$stripped = preg_replace( "#^(http|ftp|https|news)://(\S+)$#i", "\\2", $url['show'] );			$uri_type = preg_replace( "#^(http|ftp|https|news)://(\S+)$#i", "\\1", $url['show'] );						$show = $uri_type.'://'.substr( $stripped , 0, 35 ).'...'.substr( $stripped , -15   );		}				return $url['st'] . "<a href=\"".$url['html']."\" target=\"_blank\">".$show."</a>" . $url['end'];	}		/*-------------------------------------------------------------------------*/	// Remove sessions in a nice way	/*-------------------------------------------------------------------------*/		/**	* Remove session keys from URLs	*	* @param	string	Start token	* @param	string	End token	* @return	string	Converted text	*/	function regex_bash_session($start_tok, $end_tok)	{		//-----------------------------------------		// Case 1: index.php?s=0000        :: Return nothing (parses: index.php)		// Case 2: index.php?s=0000&this=1 :: Return ?       (parses: index.php?this=1)		// Case 3: index.php?this=1&s=0000 :: Return nothing (parses: index.php?this=1)		// Case 4: index.php?t=1&s=00&y=2  :: Return &       (parses: index.php?t=1&y=2)		//-----------------------------------------				$start_tok = str_replace( '&amp;', '&', $start_tok );		$end_tok   = str_replace( '&amp;', '&', $end_tok   );				//1:		if ($start_tok == '?' and $end_tok == '')		{			return "";		}		//2:		else if ($start_tok == '?' and $end_tok == '&')		{			return '?';		}		//3:		else if ($start_tok == '&' and $end_tok == '')		{			return "";		}		else if ($start_tok == '&' and $end_tok == '&')		{			return "&";		}		else		{			return $start_tok.$end_tok;		}	}			/*-------------------------------------------------------------------------*/	// Converts hex entity code to character	/*-------------------------------------------------------------------------*/		/**	* Converts hex entity code to character	*	* @param	string	hex entity	* @return	string	decimal entity	*/	function regex_bash_hex($hex_entity)	{		return html_entity_decode( "&#".hexdec( $hex_entity ).";" );	}			/*-------------------------------------------------------------------------*/	// regex_check_flash: Checks, and builds the <object>	// html.	/*-------------------------------------------------------------------------*/		/**	* Check and convert flash BBcode tags	*	* @param	integer	Movie width	* @param	integer	Movie height	* @param	string	Movie URL	* @return	string	Converted text	*/	function regex_check_flash($width="", $height="", $url="")	{		$default = "\[flash=$width,$height\]$url\[/flash\]";				if ( ! $this->ipsclass->vars['allow_flash'] )		{			return $default;		}				if ( $width > $this->ipsclass->vars['max_w_flash'] )		{			$this->error = 'flash_too_big';			return $default;		}				if ( $height > $this->ipsclass->vars['max_h_flash'] )		{			$this->error = 'flash_too_big';			return $default;		}				if ( ! preg_match( "/^http:\/\/(\S+)\.swf$/i", $url) )		{			$this->error = 'flash_url';			return $default;		}				return "<!--Flash $width+$height+$url--><OBJECT CLASSID='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' WIDTH=$width HEIGHT=$height><PARAM NAME=MOVIE VALUE=$url><PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><EMBED SRC=$url WIDTH=$width HEIGHT=$height PLAY=TRUE LOOP=TRUE QUALITY=HIGH></EMBED></OBJECT><!--End Flash-->";	}		/*-------------------------------------------------------------------------*/	// Unconvert size	/*-------------------------------------------------------------------------*/		/**	* Convert font-size HTML back into BBCode	*	* @param	integer	Core size	* @param	string	Raw text	* @return	string	Converted text	*/	function unconvert_size($size="", $text="")	{		$size -= 7;				return '[size='.$size.']'.$text.'[/size]';	}		/*-------------------------------------------------------------------------*/	// Unconvert flash	/*-------------------------------------------------------------------------*/		/**	* Convert flash HTML back into BBCode	*	* @param	string	Raw text	* @return	string	Converted text	*/	function unconvert_flash($flash="")	{		$f_arr = explode( "+", $flash );				return '[flash='.$f_arr[0].','.$f_arr[1].']'.$f_arr[2].'[/flash]';	}		/*-------------------------------------------------------------------------*/	// Unconvert SQL	/*-------------------------------------------------------------------------*/		/**	* Convert SQL HTML back into BBCode	*	* @param	string	Raw text	* @return	string	Converted text	*/	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]';	}	/*-------------------------------------------------------------------------*/	// Unconvert HTML	/*-------------------------------------------------------------------------*/		/**	* Convert HTML TAG HTML back into BBCode	*	* @param	string	Raw text	* @return	string	Converted text	*/	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_emoticon:	// replaces the text with the emoticon image	/*-------------------------------------------------------------------------*/		/**	* Convert emoticon to image HTML	*	* @param	string	Emo code :)	* @param	string	Image URL	* @return	string	Converted text	*/	function convert_emoticon($code="", $image="")	{		if (!$code or !$image) return;				//-----------------------------------------		// Remove slashes added by preg_quote		//-----------------------------------------				$code = stripslashes($code);				$this->emoticon_count++;				return "<!--emo&".trim($code)."--><img src='{$this->ipsclass->vars['EMOTICONS_URL']}/$image' border='0' style='vertical-align:middle' alt='$image' /><!--endemo-->";	}		/*-------------------------------------------------------------------------*/	// Custom array sort	/*-------------------------------------------------------------------------*/		/**	* Custom sort operation	*	* @param	string	A	* @param	string	B	* @return	integer	*/	function smilie_length_sort($a, $b)	{		if ( strlen($a['typed']) == strlen($b['typed']) )		{			return 0;		}		return ( strlen($a['typed']) > strlen($b['typed']) ) ? -1 : 1;	}		/*-------------------------------------------------------------------------*/	// Custom array sort	/*-------------------------------------------------------------------------*/		/**	* Custom sort operation	*	* @param	string	A	* @param	string	B	* @return	integer	*/	function word_length_sort($a, $b)	{		if ( strlen($a['type']) == strlen($b['type']) )		{			return 0;		}		return ( strlen($a['type']) > strlen($b['type']) ) ? -1 : 1;	}		/*-------------------------------------------------------------------------*/	// Make quote safe	/*-------------------------------------------------------------------------*/		/**	* Make quotes safe	*	* @param	string	Raw text	* @return	string	Converted text	*/	function _make_quote_safe( $txt='' )	{		//-----------------------------------------		// Sort name		//-----------------------------------------				$txt = str_replace( "+", "&#043;" , $txt );		$txt = str_replace( "-", "&#045;" , $txt );		$txt = str_replace( ":", "&#58;"  , $txt );		$txt = str_replace( "[", "&#91;"  , $txt );		$txt = str_replace( "]", "&#93;"  , $txt );		$txt = str_replace( ")", "&#41;"  , $txt );		$txt = str_replace( "(", "&#40;"  , $txt );		$txt = str_replace( "'", "&#039;" , $txt );				return $txt;	}		/*-------------------------------------------------------------------------*/	// Parse new quotes	/*-------------------------------------------------------------------------*/		/**	* Parse new quotes	*	* @param	string	Quote data	* @param	string	Raw text	* @return	string	Converted text	*/	function _parse_new_quote( $quote_data='', $quote_text='' )	{		//-----------------------------------------		// INIT		//-----------------------------------------				$return = array();				//-----------------------------------------		// No data?		//-----------------------------------------				if ( ! $quote_data )		{			return '[quote]';		}		else		{			preg_match( "#\(post=(.+?)?:date=(.+?)?:name=(.+?)?\)#", $quote_data, $match );						if ( $match[3] )			{				$return[] = " name='{$match[3]}'";			}						if ( $match[1] )			{				$return[] = " post='".intval($match[1])."'";			}						if ( $match[2] )			{				$return[] = " date='{$match[2]}'";			}									return str_replace( '  ', ' ', '[quote' . implode( ' ', $return ).']' );		}	}	}?>

⌨️ 快捷键说明

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