class_bbcode_core.php
来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 1,825 行 · 第 1/4 页
PHP
1,825 行
<?php/*+--------------------------------------------------------------------------| Invision Power Board v2.1.5| =============================================| by Matthew Mecham| (c) 2001 - 2005 Invision Power Services, Inc.| | =============================================| Web: | Time: Wed, 01 Mar 2006 19:11:28 GMT| Release: | Licence Info: +---------------------------------------------------------------------------| > $Date: 2006-02-06 23:08:03 +0000 (Mon, 06 Feb 2006) $| > $Revision: 140 $| > $Author: bfarber $+---------------------------------------------------------------------------|| > BB Code Core Module| > Module written by Matt Mecham| > Date started: Wednesday 9th March 2005 11:27|+--------------------------------------------------------------------------*//*** BBCode Parsing Core Class** This class contains all the main class functions* EXAMPLE USAGE* <code>* $parser = new parse_bbcode();* $parser->ipsclass =& $this->ipsclass;* * # If you wish convert posted text into BBCode* $parser->parse_smilies = 1;* $parser->parse_bbcode = 1;* * $bbcode_text = $parser->pre_db_parse( $_POST['text'] );* * # If you wish to display this parsed BBCode, we've still got* # to parse HTML (where allowed) and parse user defined BBCode.* $parser->parse_html = 0;* $parser->parse_nl2br = 1;* $ready_to_print = $parser->pre_display_parse( $bbcode_text );* * # Sometimes, you may wish to just save the raw POST text and convert on-the-fly.* # IPB does this with private messages, calendar events and announcements. In this case, you'd use the following:* $parser->parse_html = 0;* $parser->parse_nl2br = 1;* $parser->parse_smilies = 1;* $parser->parse_bbcode = 1;* $bbcode_text = $parser->pre_db_parse( $_POST['text'] );* $ready_to_print = $parser->pre_display_parse( $bbcode_text );* * # If you wish to convert already converted BBCode back into the raw format* # (for use in an editing screen, for example) use this:* $raw_post = $parser->pre_edit_parse( $parsed_text );* * # Of course, if you're using the rich text editor (WYSIWYG) then you don't want to uncovert the HTML* # otherwise the rich text editor will show unparsed BBCode tags, and not formatted HTML. In this case use this:* $raw_post = $parser->convert_ipb_html_to_html( $parsed_text );* </code>** @package InvisionPowerBoard* @subpackage BBCodeParser* @author Matt Mecham* @copyright Invision Power Services, Inc.* @version 2.1*//****//*** BBCode Parsing Core Class** Main object class** @package InvisionPowerBoard* @subpackage BBCodeParser* @author Matt Mecham* @version 2.1* @since 2.1.0*/class class_bbcode_core{ /** * IPS Class Object * * @var object */ var $ipsclass; /**#@+ * User defined setting * @var integer */ var $parse_smilies = 0; var $parse_html = 0; var $parse_bbcode = 0; var $parse_wordwrap = 0; var $parse_nl2br = 1; var $strip_quotes = 0; var $allow_unicode = 1; var $bypass_badwords = 0; var $load_custom_tags = 0; var $max_embed_quotes = 15; // Do not change this unless you have a VERY good reason... var $strip_hex_entity = 1; /**#@-*/ /**#@+ * Internally defined setting * @var integer */ var $image_count = 0; var $emoticon_count = 0; var $quote_open = 0; var $quote_closed = 0; var $quote_error = 0; /**#@-*/ /**#@+ * Internally defined setting * @var string */ var $error = ""; var $emoticons = ""; var $badwords = ""; var $in_sig = ""; /**#@-*/ /**#@+ * Internally defined array * @var string */ var $quote_html = array(); var $rev_font_sizes = array(); var $font_sizes = array( 1 => '8', 2 => '10', 3 => '12', 4 => '14', 5 => '18', 6 => '24', 7 => '36' ); /**#@-*/ /*-------------------------------------------------------------------------*/ // Global init /*-------------------------------------------------------------------------*/ /** * Builds up font arrays * * @return void; */ function global_init() { //------------------------------- // Remap font sizes //------------------------------- foreach( $this->font_sizes as $bbcode => $real ) { $this->rev_font_sizes[ $bbcode ] = $real; } } /*-------------------------------------------------------------------------*/ // Get real font size /*-------------------------------------------------------------------------*/ /** * Convert pt size to BBCode size * * @param integer Real size * @return integer BBCode size */ function convert_realsize_to_bbsize( $real ) { $real = intval( $real ); if ( $this->rev_font_sizes[ $real ] ) { return $this->rev_font_sizes[ $real ]; } else { return 3; } } /*-------------------------------------------------------------------------*/ // Get BBcode font size /*-------------------------------------------------------------------------*/ /** * Convert BBCode size to px size * * @param integer BBCode size * @return integer Real size */ function convert_bbsize_to_realsize( $bb ) { $bb = intval( $bb ); if ( $this->font_sizes[ $bb ] ) { return $this->font_sizes[ $bb ]; } else { return 12; } } /*-------------------------------------------------------------------------*/ // Clean up IPB html /*-------------------------------------------------------------------------*/ /** * Convert special IPB HTML to normal HTML * * @param string Raw text * @return string Converted text */ function clean_ipb_html( $t="" ) { //----------------------------------------- // left, right, center //----------------------------------------- $t = preg_replace( "#\[(left|right|center)\](.+?)\[/\\1\]#is" , "<div align=\"\\1\">\\2</div>", $t ); //----------------------------------------- // Indent => Block quote //----------------------------------------- while( preg_match( "#\[indent\](.+?)\[/indent\]#is" , $t ) ) { $t = preg_replace( "#\[indent\](.+?)\[/indent\]#is" , "<blockquote>\\1</blockquote>", $t ); } //----------------------------------------- // Quotes //----------------------------------------- $t = preg_replace( "#<!--QuoteBegin-->(.+?)<!--QuoteEBegin-->#" , '[quote]' , $t ); $t = preg_replace( "#<!--QuoteBegin-{1,2}([^>]+?)\+([^>]+?)-->(.+?)<!--QuoteEBegin-->#", "[quote=\\1,\\2]" , $t ); $t = preg_replace( "#<!--QuoteBegin-{1,2}([^>]+?)\+-->(.+?)<!--QuoteEBegin-->#" , "[quote=\\1]" , $t ); $t = preg_replace( "#<!--QuoteEnd-->(.+?)<!--QuoteEEnd-->#" , '[/quote]' , $t ); //----------------------------------------- // New quote //----------------------------------------- $t = preg_replace( "#<!--quoteo([^>]+?)?-->(.+?)<!--quotec-->#sie", "\$this->_parse_new_quote('\\1', '\\2' )" , $t ); //----------------------------------------- // SQL //----------------------------------------- $t = preg_replace( "#<!--sql-->(.+?)<!--sql1-->(.+?)<!--sql2-->(.+?)<!--sql3-->#eis", "\$this->unconvert_sql(\"\\2\")", $t); //----------------------------------------- // HTML //----------------------------------------- $t = preg_replace( "#<!--html-->(.+?)<!--html1-->(.+?)<!--html2-->(.+?)<!--html3-->#e", "\$this->unconvert_htm(\"\\2\")", $t); //----------------------------------------- // CODE //----------------------------------------- $t = preg_replace( "#<!--c1-->(.+?)<!--ec1-->#", '[code]' , $t ); $t = preg_replace( "#<!--c2-->(.+?)<!--ec2-->#", '[/code]', $t ); //----------------------------------------- // Remove all comments //----------------------------------------- # Leave this to the editor to show? # If we strip comments here, the <!--size(..)--> tags won't be converted back //$t = preg_replace( "#\<\!\-\-(.+?)\-\-\>#is", "", $t ); $t = str_replace( ''' , "'", $t ); $t = str_replace( '!' , "!", $t ); $t = str_replace( ''' , "'", $t ); $t = str_replace( ''' , "'", $t ); //----------------------------------------- // Clean up nbsp //----------------------------------------- //$t = str_replace( ' ', "\t", $t ); //$t = str_replace( ' ' , " ", $t ); //----------------------------------------- // Remove snap back macro //----------------------------------------- $t = preg_replace("#<a href=['\"]index.php?act=findpost&(amp;)?pid=.+?['\"]><\{.+?\}></a>#", "", $t ); //----------------------------------------- // Remove all macros //----------------------------------------- $t = preg_replace( "#<\{.+?\}>#", "", $t ); return $t; } /*-------------------------------------------------------------------------*/ // Strip quote tags /*-------------------------------------------------------------------------*/ /** * Remove quote tags * * @param string Raw text * @return string Converted text */ function strip_quote_tags( $txt="" ) { return preg_replace( "#\[QUOTE(=.+?,.+?)?\].+?\[/QUOTE\]#is", "", $txt ); } /*-------------------------------------------------------------------------*/ // strip all tags /*-------------------------------------------------------------------------*/ /** * Remove ALL tags * * @param string Raw text * @return string Converted text */ function strip_all_tags( $txt="" ) { $txt = $this->strip_quote_tags( $this->pre_edit_parse( $txt ) ); while( preg_match( "#\[.+?\](.+?)\[/.+?\]#is", $txt ) ) { $txt = preg_replace( "#\[.+?\](.+?)\[/.+?\]#is", "\\1", $txt ); } $txt = preg_replace( "#\[attach.+?\]#is" , "" , $txt ); return $txt; } /*-------------------------------------------------------------------------*/ // strip all tags to formatted HTML /*-------------------------------------------------------------------------*/ /** * Remove all tags, but format neatly * * @param string Raw text * @return string Converted text * @deprecated 2.1.0 */ function strip_all_tags_to_formatted( $txt="" ) { //$txt = $this->strip_quote_tags( $this->unconvert( $txt ) ); //$txt = preg_replace( "#\[CODE\](.+?)\[/CODE\]#is", "<pre>\\1</pre>", $txt ); //$txt = preg_replace( "#\[LIST\](.+?)\[/LIST\]#eis", "'<ul>' .str_replace( '[*]', '<li>', nl2br('\\1') ).'</ul>';", $txt ); //$txt = preg_replace( "#\[LIST=.+?\](.+?)\[/LIST\]#eis", "'<ul>' .str_replace( '[*]', '<li>', nl2br('\\1') ).'</ul>';", $txt ); //$txt = preg_replace( "#\[.+?\](.+?)\[/.+?\]#is", "\\1", $txt ); return $txt; } /*-------------------------------------------------------------------------*/ // PARSE POLL TAGS // Converts certain code tags for polling /*-------------------------------------------------------------------------*/ /** * Parse poll tags * * @param string Raw text * @return string Converted text */ 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*\"\;\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 ); return $txt; } /*-------------------------------------------------------------------------*/ // My strip-tags. Converts HTML entities back before strippin' em /*-------------------------------------------------------------------------*/ /** * Convert HTML entities before stripping them * * @param string Raw text * @return string Converted text */ function my_strip_tags($t="") { $t = str_replace( '>', '>', $t ); $t = str_replace( '<', '<', $t ); $t = strip_tags($t); //----------------------------------------- // Make sure nothing naughty is left... //----------------------------------------- $t = str_replace( '<', '<', $t ); $t = str_replace( '>', '>', $t ); return $t; } /*-------------------------------------------------------------------------*/ // Checks opening and closing bbtags - never pre-parsed /*-------------------------------------------------------------------------*/ /** * Check for custom BBcode tags * * @param string Raw text * @return string Converted text */ function bbcode_check($t="") { $count = array(); foreach( $this->ipsclass->cache['bbcode'] as $i => $r ) { if ( $r['bbcode_useoption'] ) { $count[ $r['bbcode_id'] ]['open'] = substr_count( strtolower($t), '['.strtolower($r['bbcode_tag']).'=' ); $count[ $r['bbcode_id'] ]['wrongopen'] = substr_count( strtolower($t), '['.strtolower($r['bbcode_tag']).']' ); } else { $count[ $r['bbcode_id'] ]['open'] = substr_count( strtolower($t), '['.strtolower($r['bbcode_tag']).']' ); $count[ $r['bbcode_id'] ]['wrongopen'] = substr_count( strtolower($t), '['.strtolower($r['bbcode_tag']).'=' ); } $count[ $r['bbcode_id'] ]['closed'] = substr_count( strtolower($t), '[/'.strtolower($r['bbcode_tag']).']' ); //----------------------------------------- // check...
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?