if ( !defined('MAIN_LOADED') ) {
die("Direct access not allowed");
}
/*
bbcode functions
!regexp leeched from phpBB
*/
function message_bbdecode($text) {
GLOBAL $lang, $config;
# func 0 - str, 1 -preg
$enlarge_sz = (isset($lang['Enlarge_Image'])) ? $lang['Enlarge_Image'] : '';
$s_path = (isset($config['script_path'])) ? $config['script_path'] : '';
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
$ru_preg = chr(0x7F)."-".chr(0xff);
// set id if wanna to get rid of &?
$bb_tags = array (
array ( 'func' => 1, 'pattern' => "/\[color=(\#[0-9A-F]array ( 6 )|[a-z]+)\]/si", 'replacement' => '' ),
array ( 'func' => 0, 'pattern' => "[/color]", 'replacement' => '' ),
array ( 'func' => 1, 'pattern' => "/\[size=([1-2]?[0-9])\]/si", 'replacement' => '' ),
array ( 'func' => 0, 'pattern' => "[/size]", 'replacement' => '' ),
array ( 'func' => 0, 'pattern' => "[b]", 'replacement' => '' ),
array ( 'func' => 0, 'pattern' => "[/b]", 'replacement' => '' ),
array ( 'func' => 0, 'pattern' => "[u]", 'replacement' => '' ),
array ( 'func' => 0, 'pattern' => "[/u]", 'replacement' => '' ),
array ( 'func' => 0, 'pattern' => "[i]", 'replacement' => '' ),
array ( 'func' => 0, 'pattern' => "[/i]", 'replacement' => '' ),
array ( 'func' => 0, 'pattern' => "[pre]", 'replacement' => '
' ),
array ( 'func' => 0, 'pattern' => "[/pre]", 'replacement' => '
' ),
// external images
array ( 'func' => 1, 'pattern' => "#\[img\](http|ftp)([^?].*?)\[/img\]#i", 'replacement' => '
' ),
// internal
array ( 'func' => 1, 'pattern' => "#\[img\]([^?].*?)\[/img\]#i", 'replacement' => '
' ),
//external urls
array ( 'id' => '1', 'func' => 1, 'pattern' => "#\[url=([\w]+?://[\d\w\#$%&~/.\-;:=,?@\(\)\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is" , 'replacement' => '$2' ),
array ( 'id' => '1', 'func' => 1, 'pattern' => "#\[url\]([\w]+?://[\d\w\#$%&~/.\-;:=,?@\(\)\[\]+]*?)\[/url\]#is", 'replacement' => '$1' ),
array ( 'id' => '1', 'func' => 1, 'pattern' => "#\[url\]((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\[/url\]#is", 'replacement' => '$1' ),
array ( 'id' => '1', 'func' => 1, 'pattern' => "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is", 'replacement' => '$3' ),
array ( 'func' => 1, 'pattern' => "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#si", 'replacement' => '$1'),
//internal urls
array ( 'id' => '1', 'func' => 1, 'pattern' => "#\[url=([\w\d\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is" , 'replacement' => '$2' ), // $config['self_url']
array ( 'id' => '1', 'func' => 1, 'pattern' => "#\[url\]([\w\d\#$%&~/.\-;:=,?@\[\]+]*?)\[/url\]#is", 'replacement' => '$1' ),
/*
style="margin:4px"
*/
//[thumb align=align title=title]pic.ext[/thumb]
array ( 'id' => '1', 'func' => 1, 'pattern' => "#\[thumb align=(\w+) title=([{$ru_preg}\d\s\w\-_\(\)]+)\]([\w\d-_\^\?]+\.(?:gif|jpeg|jpg|png))\[/thumb\]#is" , 'replacement' => '
' ),
// [thumb align=align]thumb.ext[/thumb]
array ( 'id' => '1', 'func' => 1, 'pattern' => "#\[thumb align=(\w+)\]([{$ru_preg}\w\d\-_\^\?]+\.(?:gif|jpeg|jpg|png))\[/thumb\]#is" , 'replacement' => '
' ),
// geshi
array ( 'id' => 'geshi', 'func' => 1, 'pattern' => "#\[code type=(\w+)\](.*)\[/code\]#smU" )
);
# REPLACE
while ( list($k,$v) = each($bb_tags) ) {
# print "{$k} -> {$v['pattern']} -> " . htmlspecialchars($v['replacement']) ."
";
$id = @$v['id'];
if (isset($v['id']))
$text = str_replace( '&', '&', $text) ;
switch ($id) {
case 'geshi':
require_once($GLOBALS['root_path'].'includes/geshi/geshi.php');
$text = preg_replace_callback(
$v['pattern'],
"geshi_highlight_callback",
$text);
break;
default:
$text = ($v['func']) ?
preg_replace( $v['pattern'], $v['replacement'], $text) :
str_replace( $v['pattern'], $v['replacement'], $text) ;
break;
}
}
return $text;
}
/*
check message
textonly = 0, bbcode = 1, html = 2
*/
function message_decode( $text, $type ) {
// $text = trim($text);
if ($type < TEXT_TYPE_HTML /*bbcode&text*/) {
$text = htmlspecialchars($text);
}
if($type == TEXT_TYPE_BBCODE /*bbcode*/) {
$text = message_bbdecode($text);
}
if ($type < TEXT_TYPE_HTML /*bbcode&text*/) {
$text = nl2br($text);
}
if ($type == TEXT_TYPE_HTML) {
//clear from nasty boyz
$text = preg_replace( '/\<[\s]+script[\s]*(\"|\'|\`)[\w]?script[^\>]+/is', 'SKILLZ_JS_FILTERED', $text);
$text = preg_replace( '/javascript:/is', 'SKILLZ_JS_FILTERED', $text);
}
return $text;
}
/*
geshi highlight
*/
function geshi_highlight_callback($matches) {
$geshi = new GeSHi(html_entity_decode($matches[2]), $matches[1]);
$geshi->set_header_type(GESHI_HEADER_NONE);
# $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$buff = $geshi->parse_code();
$buff = "{$buff}
";
return $buff;
}