class_bbcode.php
来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 704 行 · 第 1/2 页
PHP
704 行
<?php/*+--------------------------------------------------------------------------| Invision Power Board v2.1.6| =============================================| by Matthew Mecham| (c) 2001 - 2005 Invision Power Services, Inc.| http://www.invisionpower.com| =============================================| Web: http://www.invisionboard.com| Time: Thu, 04 May 2006 17:39:49 GMT| Release: b415613eeb952a2741ff6d53e0266428| Licence Info: http://www.invisionboard.com/?license+---------------------------------------------------------------------------| > $Date: 2006-03-06 14:58:13 +0000 (Mon, 06 Mar 2006) $| > $Revision: 161 $| > $Author: bfarber $+---------------------------------------------------------------------------|| > BB Code NEWER Module| > Module written by Matt Mecham| > Date started: Wednesday 9th March 2005 11:31|+--------------------------------------------------------------------------*//*** BBCode Parsing: Core class** This child class contains all methods* specific to the new parsing methods** @package InvisionPowerBoard* @subpackage BBCodeParser* @author Matt Mecham* @version 2.1* @since 2.1.0*//****//*** BBCode Parsing: Core class** This child class contains all methods* specific to the new parsing methods** @package InvisionPowerBoard* @subpackage BBCodeParser* @author Matt Mecham* @version 2.1* @since 2.1.0*/class class_bbcode extends class_bbcode_core{ /*-------------------------------------------------------------------------*/ // CONSTRUCTOR /*-------------------------------------------------------------------------*/ function class_bbcode( ) { } /*-------------------------------------------------------------------------*/ // Manage the raw text before inserting into the DB /*-------------------------------------------------------------------------*/ /** * Manage the raw text before inserting into the DB * * @param string Raw text * @return string Converted text */ function pre_db_parse( $txt="" ) { //----------------------------------------- // Reset //----------------------------------------- $this->quote_open = 0; $this->quote_closed = 0; $this->quote_error = 0; $this->error = ''; $this->image_count = 0; $this->emoticon_count = 0; //----------------------------------------- // Remove session id's from any post //----------------------------------------- $txt = preg_replace( "#(\?|&|;|&)s=([0-9a-zA-Z]){32}(&|;|&|$)?#e", "\$this->regex_bash_session('\\1', '\\3')", $txt ); //----------------------------------------- // convert <br> to \n //----------------------------------------- if ( ! $this->parse_nl2br ) { $txt = str_replace( "\n", "", $txt ); } $txt = preg_replace( "/<br>|<br \/>/", "\n", $txt ); # XSS Clean if( $this->strip_hex_entity ) { while( preg_match( "/[&|&\;]#x(\w+?);/i", $txt ) ) { $txt = preg_replace( "/[&|&\;]#x(\w+?);/ies" , "\$this->regex_bash_hex( '\\1' )" , $txt ); } $txt = preg_replace( "#&(?!\;)#", "", $txt ); } $txt = preg_replace( "#javascript\:#is" , "java script:", $txt ); $txt = preg_replace( "#vb(.+?)?script\:#is", "vb script:" , $txt ); $txt = str_replace( "`" , "`" , $txt ); $txt = preg_replace( "#moz\-binding:#is" , "moz binding:", $txt ); $txt = str_replace( "<script" , "<script" , $txt ); //----------------------------------------- // Are we parsing bbcode? //----------------------------------------- if ( $this->parse_bbcode ) { //----------------------------------------- // Do [CODE] tag //----------------------------------------- $txt = preg_replace( "#\[code\](.+?)\[/code\]#ies", "\$this->regex_code_tag( '\\1' )", $txt ); //----------------------------------------- // Do [QUOTE(name,date)] tags //----------------------------------------- $txt = preg_replace( "#(\[quote(.+?)?\].*\[/quote\])#ies" , "\$this->regex_parse_quotes('\\1')" , $txt ); // Quote changes \n to br $txt = preg_replace( "/<br>|<br \/>/", "\n", $txt ); //----------------------------------------- // Auto parse URLs //----------------------------------------- $txt = preg_replace( "#(^|\s|>)((http|https|news|ftp)://\w+[^\s\[\]\<]+)#ie" , "\$this->regex_build_url(array('html' => '\\2', 'show' => '\\2', 'st' => '\\1'))", $txt ); /*-------------------------------------------------------------------------*/ // If we are not parsing a siggie, lets have a bash // at the [PHP] [SQL] and [HTML] tags. /*-------------------------------------------------------------------------*/ $txt = preg_replace( "#\[sql\](.+?)\[/sql\]#ies" , "\$this->regex_sql_tag('\\1')" , $txt ); $txt = preg_replace( "#\[html\](.+?)\[/html\]#ies" , "\$this->regex_html_tag('\\1')" , $txt ); //----------------------------------------- // left, right, center //----------------------------------------- $txt = preg_replace( "#\[(left|right|center)\](.+?)\[/\\1\]#is" , "<div align=\"\\1\">\\2</div>", $txt ); //----------------------------------------- // Indent => Block quote //----------------------------------------- while( preg_match( "#\[indent\](.+?)\[/indent\]#is" , $txt ) ) { $txt = preg_replace( "#\[indent\](.+?)\[/indent\]#is" , "<blockquote>\\1</blockquote>", $txt ); } //----------------------------------------- // [LIST] [*] [/LIST] //----------------------------------------- while( preg_match( "#\n?\[list\](.+?)\[/list\]\n?#ies" , $txt ) ) { $txt = preg_replace( "#\n?\[list\](.+?)\[/list\]\n?#ies", "\$this->regex_list('\\1')" , $txt ); } while( preg_match( "#\n?\[list=(a|A|i|I|1)\](.+?)\[/list\]\n?#ies" , $txt ) ) { $txt = preg_replace( "#\n?\[list=(a|A|i|I|1)\](.+?)\[/list\]\n?#ies", "\$this->regex_list('\\2','\\1')" , $txt ); } //----------------------------------------- // Do [IMG] [FLASH] tags //----------------------------------------- if ( $this->ipsclass->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 ); } //----------------------------------------- // Start off with the easy stuff //----------------------------------------- $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", "<strike>\\1</strike>", $txt ); //----------------------------------------- // (c) (r) and (tm) //----------------------------------------- $txt = preg_replace( "#\(c\)#i" , "©" , $txt ); $txt = preg_replace( "#\(tm\)#i" , "™" , $txt ); $txt = preg_replace( "#\(r\)#i" , "®" , $txt ); //----------------------------------------- // [email]matt@index.com[/email] // [email=matt@index.com]Email me[/email] //----------------------------------------- $txt = preg_replace( "#\[email\](\S+?)\[/email\]#i" , "<a href=\"mailto:\\1\">\\1</a>", $txt ); $txt = preg_replace( "#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\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 ); //----------------------------------------- // [url]http://www.index.com[/url] // [url=http://www.index.com]ibforums![/url] //----------------------------------------- $txt = preg_replace( "#\[url\](\S+?)\[/url\]#ie" , "\$this->regex_build_url(array('html' => '\\1', 'show' => '\\1'))", $txt ); $txt = preg_replace( "#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\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 ); //----------------------------------------- // font size, colour and font style // [font=courier]Text here[/font] // [size=6]Text here[/size] // [color=red]Text here[/color] // [background=color]Text here[/background] //----------------------------------------- while ( preg_match( "#\[background=([^\]]+)\](.+?)\[/background\]#ies", $txt ) ) { $txt = preg_replace( "#\[background=([^\]]+)\](.+?)\[/background\]#ies", "\$this->regex_font_attr(array('s'=>'background','1'=>'\\1','2'=>'\\2'))", $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 ); } } //----------------------------------------- // Swap \n back to <br> //----------------------------------------- $txt = preg_replace( "/\n/", "<br />", $txt ); //----------------------------------------- // Unicode? //----------------------------------------- if ( $this->allow_unicode ) { $txt = preg_replace("/&#([0-9]+);/s", "&#\\1;", $txt ); } //----------------------------------------- // Parse smilies (disallow smilies in siggies, or we'll have to query the DB for each post // and each signature when viewing a topic, not something that we really want to do. //----------------------------------------- if ( $this->parse_smilies ) { $txt = ' '.$txt.' '; usort( $this->ipsclass->cache['emoticons'] , array( 'class_bbcode_core', 'smilie_length_sort' ) ); if ( count( $this->ipsclass->cache['emoticons'] ) > 0 ) { foreach( $this->ipsclass->cache['emoticons'] as $a_id => $row) { if ( $row['emo_set'] != $this->ipsclass->skin['_emodir'] ) { continue; } $code = $row['typed']; $image = $row['image']; //----------------------------------------- // Make safe for regex //----------------------------------------- $code = preg_quote($code, "/"); $txt = preg_replace( "!(?<=[^\w&;/\"])$code(?=.\W|\"|\W.|\W$)!ei", "\$this->convert_emoticon('$code', '$image')", $txt ); } } $txt = trim($txt); if ( $this->ipsclass->vars['max_emos'] ) { if ($this->emoticon_count > $this->ipsclass->vars['max_emos']) { $this->error = 'too_many_emoticons'; } } } //----------------------------------------- // Badwords //----------------------------------------- $txt = $this->bad_words($txt); //----------------------------------------- // Check BBcode //----------------------------------------- $txt = $this->bbcode_check($txt); return $txt; } /*-------------------------------------------------------------------------*/ // This function processes the DB post before printing as output /*-------------------------------------------------------------------------*/ /** * This function processes the DB post before printing as output * * @param string Raw text * @return string Converted text */ function pre_display_parse($t="") { if ( $this->parse_html ) { $t = $this->post_db_parse_html( $t ); } else {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?