$img_count=0;
// 3 functions for the bbcode. Have to be declared outside the function to be able to call bbcode more than once.
function dosize($matches) {
return ''.$matches[4].'';
}
function noparsed($matches) { // any character that is parsed, must be here
static $replace=array(
'://' => '://',
'(' => '(',
')' => ')',
'-' => '-',
'/' => '/',
':' => ':',
'[' => '[',
']' => ']',
'_' => '_',);
return str_replace( array_keys($replace), array_values($replace) ,$matches[2]);
}
function formatlist($matches) {
if ($matches[3]=='') {
$content.='
function parseimage($matches) {
global $img_count;
$img_count++;
return "
";
}
function bbcode($content) {
global $language;
// Fix & to be & unless it's already & or a special character like ▀ or some regualr ones like <,>,",(c), . More can be found here: http://www.utexas.edu/learn/html/spchar.html But they can use the decimal verisons if the want those
$content=preg_replace('/&(?!(amp|[#0-9]+|lt|gt|quot|copy|nbsp);)/ix','&',$content);
// But some special chars are bad, at least according to vB, so strip them. Most are just blank characters used to bypass filters, except for which is just awesome!
$content=str_replace(array(' ','','','','',''),'',$content);
// Change new lines to . nl2br function probably would work also. It's probably the same as this though. And gets rid of htmlchars. htmlentities screws up the & stuff.
$content=str_replace(array('<','>','\'','"',"\r\n","\r","\n"),array('<','>',''','"','','',''),$content);
do{ // No parse. Just replace anything that is parsed, into their HTML equivalents
$content=preg_replace_callback('/\[(noparse(?:\d|))\](.+?)\[\/\1\]/i','noparsed',$content, -1, $count);
}while($count);
do{ // code tags must be parsed first, because their contents are not parsed.
$content=preg_replace('/\[(code(?:\d|))\](.+?)\[\/\1\]/i','Code
do{ // code blocks insert the noparse tag. Can't parse the code block first, or you can't use noparse on it.
$content=preg_replace_callback('/\[(noparse(?:\d|))\](.+?)\[\/\1\]/i','noparsed',$content, -1, $count);
}while($count);
// Images. They have to have http://. src attributes are XSSable in IE 6.0, Netscape, and Opera. http://ha.ckers.org/xss.html. Even though it's hard to do without () or \, best not to mess around with it.
$content=preg_replace_callback('/\[(img(?:\d|))\]("|&#(?:0|)39;|"|\'|)(http|https|ftp|ftps):\/\/([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\2\[\/\1\]/i','parseimage',$content);
$content=preg_replace_callback('/\[(img(?:\d|))=("|&#(?:0|)39;|"|\'|)(http|https|ftp|ftps):\/\/([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\2\]/i','parseimage',$content);
// text
$content=preg_replace('/\[(url(?:\d|))\=("|&#(?:0|)39;|"|\'|)(http|https|ftp|ftps|ed2k|irc):\/\/([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\2\](.+?)\[\/\1\]/i', '$5', $content);
// For people too lazy to put http:// on the uri. /Shouldn't/ be XSSable
$content=preg_replace('/\[(url(?:\d|))\=("|&#(?:0|)39;|"|\'|)([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\2\](.+?)\[\/\1\]/i', '$4', $content);
// uri
$content=preg_replace('/\[(url(?:\d|))\](http|https|ftp|ftps|ed2k|irc):\/\/([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\[\/\1\]/i','$2://$3',$content);
// lazy http:// people...
$content=preg_replace('/\[(url(?:\d|))\]([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]*)\[\/\1\]/i','http://$2',$content);
// Email. Do people even use this? Yes, so they can get revenge on someone by posting their email address.
$content=preg_replace('/\[(email(?:\d|))\]([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]+)@([a-z0-9\/\-\+\?\&\.\=\_\~\#\'\%\;]+)\[\/\1\]/i','$2@$3',$content);
do{ // [left], [center], [right] and [justify] tags
$content=preg_replace('/\[((left|right|center|justify)(?:\d|))\](.+?)\[\/\1\]/i', '
$3
',$content, -1, $count);
}while($count);
do{ // the color is the tag itself, like [fgyellow]yellow text[/fgyellow], or [fg-blue]blue text[/fg-blue]
// If the color is the tag itself, like [green], then it must ALWAYS be a whitelist of accepted colors.
$content=preg_replace('/\[((?:fg|fg-|)(black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua)(?:\d|))\](.+?)\[\/\1\]/i','$3',$content, -1, $count);
}while($count);
do{ // font color. Word type, like RED not limited in name, for backwards compatability.
$content=preg_replace('/\[((?:fg|fg-|)colo(?:u|)r(?:\d|))=("|&#(?:0|)39;|"|\'|)([a-z]{0,25})\2\](.+?)\[\/\1\]/i','$4',$content, -1, $count);
}
/* while($count);
do{ // Color specified in RGB triplet, like GREY
$content=preg_replace('/\[((?:fg|fg-|)colo(?:u|)r(?:\d|))=("|#|&#(?:0|)39;|"|\'|)([\dA-F]{0,9})\2\](.+?)\[\/\1\]/i','$4',$content, -1, $count);
} */
while($count);
do{ // Color specified in RGB triplet, like GREY
$content=preg_replace('/\[color=(.+?)](.+?)\[\/color]/i','$2',$content, -1, $count);
}
while($count);
// background colors
do{ // background color specified in RGB triplet, like [bg-color=ff0000]red background[/bg-color]
$content=preg_replace('/\[bg-color=(.+?)](.+?)\[\/bg-color]/i','$2',$content, -1, $count);
}while($count);
do{ // but since the bgcolor tag is new, I will limit the colors, for maximum web compatability. Of course you can set any color you like with the RGB background tag. Maybe remove color whitelist, dependong on user feedback.
$content=preg_replace('/\[((?:bg|bg-)colo(?:u|)r(?:\d|))=("|&#(?:0|)39;|"|\'|)(black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua)\2\](.+?)\[\/\1\]/i','$4',$content, -1, $count);
}while($count);
do{ // This background tag uses the following syntax, for a red background: [bgred] or [bg-red]
$content=preg_replace('/\[((?:bg|bg-)(black|silver|gray|white|maroon|red|purple|fuchsia|green|lime|olive|yellow|navy|blue|teal|aqua)(?:\d|))\](.+?)\[\/\1\]/i','$3',$content, -1, $count);
}while($count);
do{ // background color specified in RGB triplet, like [bg-color=ff0000]red background[/bg-color]
$content=preg_replace('/\[((?:bg|bg-)colo(?:u|)r(?:\d|))=("|&#(?:0|)39;|"|\'|)([0-9A-F]{3,6})\2\](.+?)\[\/\1\]/i','$4',$content, -1, $count);
}while($count);
function dehtml($content) {
$content=preg_replace('/&(?!(amp|[#0-9]+|lt|gt|quot|copy|nbsp);)/ix','&',$content);
$content=str_replace(array(' ','','','','',''),'',$content);
return str_replace(array('<','>','\'','"'),array('<','>',''','"'),$content);
}
unable to parse smiley / errors occuring when using list
if i use another editor , i need to redo all bbcodes :sad:
xblade
14th February 2021 12:46
first of you need to fix this line
its backing on this so u get error page
// Change new lines to . nl2br function probably would work also. It's probably the same as this though. And gets rid of htmlchars. htmlentities screws up the & stuff.
Code:
$content=str_replace(array(' ','','','','','// Change new lines to . nl2br function probably would work also. It's probably the same as this though. And gets rid of
htmlchars. htmlentities screws up the & stuff.'),'',$content);
JohnHasher
20th February 2021 17:12
PHP Code:
function dehtml($content) { $content=preg_replace('/&(?!(amp|[#0-9]+|lt|gt|quot|copy|nbsp);)/ix','&',$content); $content=str_replace(array(' ','','','','',''),'',$content); return str_replace(array('<','>','\'','"'),array('<','>',''','"'),$content); }
the code is getting filtered by bvlist editor , here is the function.
by the way parse is working for now except for the emotes / smilies (i think the unicodes are getting filtered.)