$Date: 2006-09-22 05:28:54 -0500 (Fri, 22 Sep 2006) $
| > $Revision: 567 $
| > $Author: matt $
+---------------------------------------------------------------------------
|
| > BB Code LEGACY Module
| > Module written by Matt Mecham
| > Date started: Wednesday 9th March 2005 11:31
|
+--------------------------------------------------------------------------
*/
/**
* BBCode Parsing: Legacy sub class
*
* Sub class
*
* @package InvisionPowerBoard
* @subpackage BBCodeParser
* @author Matt Mecham
* @version 2.1
* @ignore
*/
/**
*
*/
/**
* BBCode Parsing: Legacy sub class
*
* Sub class
*
* @package InvisionPowerBoard
* @subpackage BBCodeParser
* @author Matt Mecham
* @version 2.1
* @ignore
*/
if ( ! defined( 'IN_IPB' ) )
{
print "
Некорректный адрес
Вы не имеете доступа к этому файлу напрямую. Если вы недавно обновляли форум, вы должны обновить все соответствующие файлы.";
exit();
}
class class_bbcode extends class_bbcode_core
{
var $parse_smilies = 0;
var $parse_html = 0;
var $parse_bbcode = 0;
var $parse_wordwrap = 0;
var $parse_nl2br = 1;
var $parse_custombbcode = 1;
/*-------------------------------------------------------------------------*/
// CONSTRUCTOR
/*-------------------------------------------------------------------------*/
function class_bbcode( )
{
$this->strip_quotes = $this->ipsclass->vars['strip_quotes'];
}
/*-------------------------------------------------------------------------*/
// Manage the raw text before inserting into the DB
/*-------------------------------------------------------------------------*/
function pre_db_parse( $txt="" )
{
//-----------------------------------------
// 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
to \n
//-----------------------------------------
$txt = preg_replace( "/
|
/", "\n", $txt );
//-----------------------------------------
// Are we parsing bbcode?
//-----------------------------------------
if ( $this->parse_bbcode )
{
//-----------------------------------------
// Do [CODE] tag
//-----------------------------------------
$txt = preg_replace( "#\[code\](.+?)\[/code\]#ies", "\$this->regex_code_tag( '\\1' )", $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 );
//-----------------------------------------
// Do [QUOTE(name,date)] tags
//-----------------------------------------
$txt = preg_replace( "#(\[quote(.+?)?\].*\[/quote\])#ies" , "\$this->regex_parse_quotes('\\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 );
//-----------------------------------------
// [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", "\\1", $txt );
$txt = preg_replace( "#\[i\](.+?)\[/i\]#is", "\\1", $txt );
$txt = preg_replace( "#\[u\](.+?)\[/u\]#is", "\\1", $txt );
$txt = preg_replace( "#\[s\](.+?)\[/s\]#is", "\\1", $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" , "\\1", $txt );
$txt = preg_replace( "#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i" , "\\2", $txt );
$txt = preg_replace( "#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i" , "\\2", $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]
//-----------------------------------------
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 );
}
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 );
}
}
//-----------------------------------------
// Swap \n back to
//-----------------------------------------
$txt = preg_replace( "/\n/", "
", $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.' ';
$codes_seen = array();
if ( count( $this->ipsclass->cache['emoticons'] ) > 0 )
{
foreach( $this->ipsclass->cache['emoticons'] as $row)
{
if ( $this->ipsclass->skin['_emodir'] && $row['emo_set'] != $this->ipsclass->skin['_emodir'] )
{
continue;
}
$code = $row['typed'];
if( in_array( $code, $codes_seen ) )
{
continue;
}
$codes_seen[] = $code;
$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 trim($txt);
}
/*-------------------------------------------------------------------------*/
// This function processes the DB post before printing as output
/*-------------------------------------------------------------------------*/
function pre_display_parse($t="")
{
if ( $this->parse_html )
{
$t = $this->post_db_parse_html( $t );
}
else
{
//$t = $this->my_strip_tags( $t );
}
if ( $this->parse_wordwrap > 0 )
{
$t = $this->my_wordwrap( $t, $this->parse_wordwrap );
}
//-----------------------------------------
// Custom BB code
//-----------------------------------------
if ( strstr( $t, '[/' ) )
{
$t = $this->post_db_parse_bbcode($t);
}
return $t;
}
/*-------------------------------------------------------------------------*/
// This function processes the text before showing for editing, etc
/*-------------------------------------------------------------------------*/
function pre_edit_parse($txt="")
{
$txt = preg_replace( "#.+?#", "\\1" , $txt );
if ( $this->parse_bbcode )
{
//-----------------------------------------
// SQL
//-----------------------------------------
$txt = preg_replace( "#(.+?)(.+?)(.+?)#eis", "\$this->unconvert_sql(\"\\2\")", $txt);
//-----------------------------------------
// HTML
//-----------------------------------------
$txt = preg_replace( "#(.+?)(.+?)(.+?)#e", "\$this->unconvert_htm(\"\\2\")", $txt);
//-----------------------------------------
// Images / Flash
//-----------------------------------------
$txt = preg_replace( "#.+?#e", "\$this->unconvert_flash('\\1')", $txt );
$txt = preg_replace( "#
#" , "\[img\]\\1\[/img\]" , $txt );
//-----------------------------------------
// Email, URLs
//-----------------------------------------
$txt = preg_replace( "#(.+?)#" , "\[email=\\1\]\\2\[/email\]" , $txt );
$txt = preg_replace( "#(.+?)#" , "\[url=\\1\\2\]\\3\[/url\]" , $txt );
//-----------------------------------------
// Quote
//-----------------------------------------
$txt = preg_replace( "#(.+?)#" , '[quote]' , $txt );
$txt = preg_replace( "#(.+?)#", "[quote=\\1,\\2]" , $txt );
$txt = preg_replace( "#(.+?)#" , "[quote=\\1]" , $txt );
$txt = preg_replace( "#(.+?)#" , '[/quote]' , $txt );
//-----------------------------------------
// CODE
//-----------------------------------------
$txt = preg_replace( "#(.+?)#", '[code]' , $txt );
$txt = preg_replace( "#(.+?)#", '[/code]', $txt );
//-----------------------------------------
// Easy peasy
//-----------------------------------------
$txt = preg_replace( "#(.+?)#is" , "\[i\]\\1\[/i\]" , $txt );
$txt = preg_replace( "#(.+?)#is" , "\[b\]\\1\[/b\]" , $txt );
$txt = preg_replace( "#(.+?)#is" , "\[s\]\\1\[/s\]" , $txt );
$txt = preg_replace( "#(.+?)#is" , "\[u\]\\1\[/u\]" , $txt );
//-----------------------------------------
// List headache
//-----------------------------------------
$txt = preg_replace( "#(\n){0,}#" , "\\1\[list\]" , $txt );
$txt = preg_replace( "#(\n){0,}#" , "\\1\[list=\\2\]\n" , $txt );
$txt = preg_replace( "#(\n){0,}- #" , "\n\[*\]" , $txt );
$txt = preg_replace( "#(\n){0,}
(\n){0,}#", "\n\[/list\]\\2" , $txt );
$txt = preg_replace( "#(\n){0,}(\n){0,}#", "\n\[/list\]\\2" , $txt );
//-----------------------------------------
// SPAN
//-----------------------------------------
while ( preg_match( "#(.+?)#is", $txt ) )
{
$txt = preg_replace( "#(.+?)#ise" , "\$this->unconvert_size('\\1', '\\2')", $txt );
}
while ( preg_match( "#(.+?)#is", $txt ) )
{
$txt = preg_replace( "#(.+?)#is" , "\[color=\\1\]\\2\[/color\]", $txt );
}
while ( preg_match( "#(.+?)#is", $txt ) )
{
$txt = preg_replace( "#(.+?)#is", "\[font=\\1\]\\2\[/font\]", $txt );
}
while ( preg_match( "#(.+?)#is", $txt ) )
{
$txt = preg_replace( "#(.+?)#is", "\[background=\\1\]\\2\[/font\]", $txt );
}
//-----------------------------------------
// Tidy up the end quote stuff
//-----------------------------------------
$txt = preg_replace( "#(\[/QUOTE\])\s*?
\s*#si", "\\1\n", $txt );
$txt = preg_replace( "#(\[/QUOTE\])\s*?
\s*#si" , "\\1\n", $txt );
$txt = preg_replace( "##" , "" , $txt );
$txt = str_replace( "", "", $txt );
$txt = str_replace( "", "(tm)", $txt );
}
//-----------------------------------------
// Parse html
//-----------------------------------------
if ( $this->parse_html )
{
$txt = str_replace( "'", "'", $txt);
}
//-----------------------------------------
// Clean up BR tags
//-----------------------------------------
$txt = str_replace( "
" , "\n", $txt );
$txt = str_replace( "
", "\n", $txt );
return trim(stripslashes($txt));
}
}
?>