$Date: 2005-10-24 22:17:00 +0100 (Mon, 24 Oct 2005) $ | > $Revision: 64 $ | > $Author: bfarber $ +--------------------------------------------------------------------------- | | > Handler for BBCode parsing | > Module written by Matt Mecham | > Date started: Wednesday 9th March 2005 11:03 +-------------------------------------------------------------------------- */ class parse_bbcode { # Global var $ipsclass; var $bbclass; # Already loaded classes? var $classes_loaded = 0; # Update caches if not present? var $allow_update_caches = 0; var $pre_db_parse_method = 'new'; # Permissions var $parse_smilies = 0; var $parse_html = 0; var $parse_bbcode = 1; var $strip_quotes = 1; var $parse_n12br = 1; var $bypass_badwords = 0; # Error var $error; /*-------------------------------------------------------------------------*/ // Constructor /*-------------------------------------------------------------------------*/ function parse_bbcode() { //----------------------------------------- // Anything to init? //----------------------------------------- } /*-------------------------------------------------------------------------*/ // This function is called before inserting the post text into the DB // Depending on which method we're using, it will either check for errors // or parse the code into legacy (IPB 2.0<) format. /*-------------------------------------------------------------------------*/ function pre_db_parse( $text ) { //----------------------------------------- // INIT //----------------------------------------- $class = ""; //----------------------------------------- // Check the DB cache //----------------------------------------- $this->check_caches(); //----------------------------------------- // Get the correct class //----------------------------------------- $this->_load_classes(); //----------------------------------------- // Decide the settings... //----------------------------------------- $this->bbclass->bypass_badwords = $this->bypass_badwords ? $this->bypass_badwords : intval($this->ipsclass->member['g_bypass_badwords']); $this->bbclass->parse_smilies = $this->parse_smilies; $this->bbclass->parse_html = $this->parse_html; $this->bbclass->parse_bbcode = $this->parse_bbcode; $this->bbclass->strip_quotes = $this->ipsclass->vars['strip_quotes']; $this->bbclass->parse_n12br = $this->parse_n12br; $this->bbclass->parse_wordwrap = $this->ipsclass->vars['post_wordwrap']; $this->bbclass->max_embed_quotes = $this->ipsclass->vars['max_quotes_per_post']; //----------------------------------------- // Parse //----------------------------------------- return $this->bbclass->pre_db_parse( $text ); } /*-------------------------------------------------------------------------*/ // This function is called before showing the post for edit /*-------------------------------------------------------------------------*/ function pre_edit_parse( $text ) { //----------------------------------------- // INIT //----------------------------------------- $class = ""; //----------------------------------------- // Check the DB cache //----------------------------------------- $this->check_caches(); //----------------------------------------- // Get the correct class //----------------------------------------- $this->_load_classes(); //----------------------------------------- // Decide the settings... //----------------------------------------- $this->bbclass->bypass_badwords = $this->bypass_badwords ? $this->bypass_badwords : intval($this->ipsclass->member['g_bypass_badwords']); $this->bbclass->parse_smilies = $this->parse_smilies; $this->bbclass->parse_html = $this->parse_html; $this->bbclass->parse_bbcode = $this->parse_bbcode; $this->bbclass->strip_quotes = $this->ipsclass->vars['strip_quotes']; $this->bbclass->parse_n12br = $this->parse_n12br; $this->bbclass->parse_wordwrap = $this->ipsclass->vars['post_wordwrap']; $this->bbclass->max_embed_quotes = $this->ipsclass->vars['max_quotes_per_post']; //----------------------------------------- // Parse //----------------------------------------- return $this->bbclass->pre_edit_parse( $text ); } /*-------------------------------------------------------------------------*/ // This function is called before displaying the final post in the user's browser /*-------------------------------------------------------------------------*/ function pre_display_parse( $text ) { //----------------------------------------- // INIT //----------------------------------------- $class = ""; //----------------------------------------- // Check the DB cache // { Dont need this, for this } //----------------------------------------- ///$this->check_caches(); //----------------------------------------- // Get the correct class //----------------------------------------- $this->_load_classes(); //----------------------------------------- // Decide the settings... //----------------------------------------- $this->bbclass->bypass_badwords = $this->bypass_badwords ? $this->bypass_badwords : intval($this->ipsclass->member['g_bypass_badwords']); $this->bbclass->parse_smilies = $this->parse_smilies; $this->bbclass->parse_html = $this->parse_html; $this->bbclass->parse_bbcode = $this->parse_bbcode; $this->bbclass->strip_quotes = $this->ipsclass->vars['strip_quotes']; $this->bbclass->parse_nl2br = $this->parse_nl2br; $this->bbclass->parse_wordwrap = $this->ipsclass->vars['post_wordwrap']; $this->bbclass->max_embed_quotes = $this->ipsclass->vars['max_quotes_per_post']; //----------------------------------------- // Parse //----------------------------------------- return $this->bbclass->pre_display_parse( $text ); } /*-------------------------------------------------------------------------*/ // Function: convert_std_to_rte /*-------------------------------------------------------------------------*/ /** * Convert STD contents TO RTE compatible * * Used when switching between editors or * when using the fast reply and hitting "More..." * * @param string STD text * @return string RTE text */ function convert_std_to_rte( $t ) { //----------------------------------------- // Get the correct class //----------------------------------------- $this->_load_classes(); //----------------------------------------- // Ensure no slashy slashy //----------------------------------------- $t = str_replace( '"','"', $t ); $t = str_replace( "'",''', $t ); //----------------------------------------- // Convert <> //----------------------------------------- $t = str_replace( '<', '<', $t ); $t = str_replace( '>', '>', $t ); //----------------------------------------- // RTE expects
not \n //----------------------------------------- $t = str_replace( "\n", "
", str_replace( "\r\n", "\n", $t ) ); //----------------------------------------- // Okay, convert ready for DB //----------------------------------------- $t = $this->pre_db_parse( $t ); $t = $this->bbclass->clean_ipb_html( $t ); return $t; } /*-------------------------------------------------------------------------*/ // Passthrough function: Clean up IPB HTML /*-------------------------------------------------------------------------*/ function convert_ipb_html_to_html( $t ) { //----------------------------------------- // Get the correct class //----------------------------------------- $this->_load_classes(); return $this->bbclass->clean_ipb_html( $t ); } /*-------------------------------------------------------------------------*/ // Passthrough function: Strip all tags /*-------------------------------------------------------------------------*/ function strip_all_tags( $t ) { //----------------------------------------- // Get the correct class //----------------------------------------- $this->_load_classes(); return $this->bbclass->strip_all_tags( $t ); } /*-------------------------------------------------------------------------*/ // Passthrough function: Badwords /*-------------------------------------------------------------------------*/ function bad_words( $t ) { //----------------------------------------- // Get the correct class //----------------------------------------- $this->_load_classes(); $this->bbclass->bypass_badwords = $this->bypass_badwords ? $this->bypass_badwords : intval($this->ipsclass->member['g_bypass_badwords']); return $this->bbclass->bad_words( $t ); } /*-------------------------------------------------------------------------*/ // Passthrough function: Parse poll tags /*-------------------------------------------------------------------------*/ function parse_poll_tags( $txt ) { //----------------------------------------- // Get the correct class //----------------------------------------- $this->_load_classes(); //----------------------------------------- // [url]http://www.index.com[/url] // [url=http://www.index.com]ibforums![/url] //----------------------------------------- $txt = preg_replace( "#\[url\](\S+?)\[/url\]#ie" , "\$this->bbclass->regex_build_url(array('html' => '\\1', 'show' => '\\1'))", $txt ); $txt = preg_replace( "#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#ie" , "\$this->bbclass->regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt ); $txt = preg_replace( "#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#ie" , "\$this->bbclass->regex_build_url(array('html' => '\\1', 'show' => '\\2'))", $txt ); if ( $this->ipsclass->vars['allow_images'] ) { $txt = preg_replace( "#\[img\](.+?)\[/img\]#ie", "\$this->bbclass->regex_check_image('\\1')", $txt ); } return $txt; } /*-------------------------------------------------------------------------*/ // Passthrough function: make_quote_safe /*-------------------------------------------------------------------------*/ function make_quote_safe( $t ) { //----------------------------------------- // Get the correct class //----------------------------------------- $this->_load_classes(); return $this->bbclass->_make_quote_safe( $t ); } /*-------------------------------------------------------------------------*/ // Passthrough function: Strip Quotes /*-------------------------------------------------------------------------*/ function strip_quotes( $t ) { //----------------------------------------- // Get the correct class //----------------------------------------- $this->_load_classes(); return $this->bbclass->strip_quotes( $t ); } /*-------------------------------------------------------------------------*/ // CHECK (AND LOAD) CACHES // This function loads all the data we'll need. /*-------------------------------------------------------------------------*/ function check_caches() { //----------------------------------------- // Check emoticons //----------------------------------------- if ( ! is_array( $this->ipsclass->cache['emoticons'] ) ) { $this->ipsclass->cache['emoticons'] = array(); $this->ipsclass->DB->simple_construct( array( 'select' => 'typed,image,clickable,emo_set', 'from' => 'emoticons' ) ); $this->ipsclass->DB->simple_exec(); while ( $r = $this->ipsclass->DB->fetch_row() ) { $this->ipsclass->cache['emoticons'][] = $r; } if ( $this->allow_update_caches ) { $this->ipsclass->update_cache( array( 'name' => 'emoticons', 'array' => 1, 'deletefirst' => 1 ) ); } } //----------------------------------------- // Check BBCode //----------------------------------------- if ( ! is_array( $this->ipsclass->cache['bbcode'] ) ) { $this->ipsclass->cache['bbcode'] = array(); $this->ipsclass->DB->simple_construct( array( 'select' => 'bbcode_id, bbcode_tag, bbcode_replace, bbcode_useoption', 'from' => 'custom_bbcode' ) ); $bbcode = $this->ipsclass->DB->simple_exec(); while ( $r = $this->ipsclass->DB->fetch_row($bbcode) ) { $this->ipsclass->cache['bbcode'][] = $r; } if ( $this->allow_update_caches ) { $this->ipsclass->update_cache( array( 'name' => 'bbcode', 'array' => 1, 'deletefirst' => 1 ) ); } } //----------------------------------------- // Check badwords //----------------------------------------- if ( ! is_array( $this->ipsclass->cache['badwords'] ) ) { $this->ipsclass->cache['badwords'] = array(); $this->ipsclass->DB->simple_construct( array( 'select' => 'type,swop,m_exact', 'from' => 'badwords' ) ); $bbcode = $this->ipsclass->DB->simple_exec(); while ( $r = $this->ipsclass->DB->fetch_row($bbcode) ) { $this->ipsclass->cache['badwords'][] = $r; } if ( $this->allow_update_caches ) { $this->ipsclass->update_cache( array( 'name' => 'badwords', 'array' => 1, 'deletefirst' => 1 ) ); } } } /*-------------------------------------------------------------------------*/ // Load classes /*-------------------------------------------------------------------------*/ function _load_classes() { if ( ! $this->classes_loaded ) { require_once( ROOT_PATH . 'sources/classes/bbcode/class_bbcode_core.php' ); switch( $this->pre_db_parse_method ) { case 'legacy': $class = 'class_bbcode_legacy.php'; break; default: $class = 'class_bbcode.php'; break; } require_once ( ROOT_PATH . 'sources/classes/bbcode/' . $class ); $this->bbclass = new class_bbcode(); $this->bbclass->ipsclass =& $this->ipsclass; $this->classes_loaded = 1; $this->error =& $this->bbclass->error; } } } ?>