1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| function fuckBBcode ($str)
{
# basic html
$str = str_ireplace('<br />', '', $str);
$str = str_ireplace('<b>', '[b]', $str);
$str = str_ireplace('<i>', '[i]', $str);
$str = str_ireplace('<u>', '[u]', $str);
$str = str_ireplace('</b>', '[/b]', $str);
$str = str_ireplace('</i>', '[/i]', $str);
$str = str_ireplace('</u>', '[/u]', $str);
$str = str_ireplace('<ul>', '[list]', $str);
$str = preg_replace("/<ol type=\"(\w{1})\">/si", "[list=\\1]", $str);
$str = str_ireplace('<li>', '[*]', $str);
$str = str_ireplace('</ul>', '[/list]', $str);
$str = str_ireplace('</ol>', '[/list]', $str);
# smilies
$str = str_ireplace('<img src="images/smilies/redface.gif" border="0" alt="" title="Embarrassment" class="inlineimg" />', ':o', $str);
$str = str_ireplace('<img src="images/smilies/smile.gif" border="0" alt="" title="Smile" class="inlineimg" />', ':)', $str);
$str = str_ireplace('<img src="images/smilies/frown.gif" border="0" alt="" title="Frown" class="inlineimg" />', ':(', $str);
$str = str_ireplace('<img src="images/smilies/confused.gif" border="0" alt="" title="Confused" class="inlineimg" />', ':confused:', $str);
$str = str_ireplace('<img src="images/smilies/mad.gif" border="0" alt="" title="Mad" class="inlineimg" />', ':mad:', $str);
$str = str_ireplace('<img src="images/smilies/tongue.gif" border="0" alt="" title="Stick Out Tongue" class="inlineimg" />', ':p', $str);
$str = str_ireplace('<img src="images/smilies/wink.gif" border="0" alt="" title="Wink" class="inlineimg" />', ';)', $str);
$str = str_ireplace('<img src="images/smilies/biggrin.gif" border="0" alt="" title="Big Grin" class="inlineimg" />', ':D', $str);
$str = str_ireplace('<img src="images/smilies/rolleyes.gif" border="0" alt="" title="Roll Eyes (Sarcastic)" class="inlineimg" />', ':rolleyes:', $str);
$str = str_ireplace('<img src="images/smilies/cool.gif" border="0" alt="" title="Cool" class="inlineimg" />', ':cool:', $str);
$str = str_ireplace('<img src="images/smilies/eek.gif" border="0" alt="" title="EEK!" class="inlineimg" />', ':eek:', $str);
# colors
$str = preg_replace("/<font color=\"([^\"]*)\">(.*?)<\/font>/si", "[color=\\1]\\2[/color]", $str);
$str = preg_replace("/<span class=\"highlight\">(.*?)<\/span>/si", "[highlight]\\1[/highlight]", $str);
# html code && code
$str = preg_replace("/<div style=\"margin:20px; margin-top:5px\">\s*<div class=\"smallfont\" style=\"margin-bottom:2px\">HTML Code:<\/div>\s*<pre class=\"alt2\" dir=\"ltr\" style=\"[^\"]*\">/si", '[code]', $str);
$str = preg_replace("/<div style=\"margin:20px; margin-top:5px\">\s*<div class=\"smallfont\" style=\"margin-bottom:2px\">Code:<\/div>\s*<pre class=\"alt2\" dir=\"ltr\" style=\"[^\"]*\">/si", '[code]', $str);
$str = preg_replace("/<\/pre>\s*<\/div>/", '[/code]', $str);
# php code
$str = preg_replace("/<div style=\"margin:20px; margin-top:5px\">\s*<div class=\"smallfont\" style=\"margin-bottom:2px\">PHP Code:<\/div>\s*<div class=\"alt2\" dir=\"ltr\" style=\"[^\"]*\">\s*<code style=\"white-space:nowrap\">\s*<!-- php buffer start -->/si", '[php]', $str);
$str = preg_replace("/<!-- php buffer end -->\s*<\/code>\s*<\/div>\s*<\/div>/", '[/php]', $str);
# quotes
$str = preg_replace("/<div style=\"margin:20px; margin-top:5px; \">\s*<div class=\"smallfont\" style=\"margin-bottom:2px\">Quote:<\/div>\s*<table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\s*<tr>\s*<td class=\"alt2\" style=\"border:1px inset\">\s*<div>\s*Originally Posted by <strong>([^<]*)<\/strong>\s*<a href=\"showthread\.php\?[^>]*p=(\d+)#post\d+\" rel=\"nofollow\"><img class=\"inlineimg\" src=\"images\/buttons\/viewpost\.gif\" border=\"0\" alt=\"View Post\" \/><\/a>\s*<\/div>\s*<div style=\"font-style:italic\">/si", "[quote=\\1;\\2]", $str);
$str = preg_replace("/<div style=\"margin:20px; margin-top:5px; \">\s*<div class=\"smallfont\" style=\"margin-bottom:2px\">Quote:<\/div>\s*<table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\s*<tr>\s*<td class=\"alt2\" style=\"border:1px inset\">\s*<div>\s*Originally Posted by <strong>([^<]*)<\/strong>\s*<\/div>\s*<div style=\"font-style:italic\">\s*/si", "[quote=\\1]", $str);
$str = preg_replace("/<div style=\"margin:20px; margin-top:5px; \">\s*<div class=\"smallfont\" style=\"margin-bottom:2px\">Quote:<\/div>\s*<table cellpadding=\"6\" cellspacing=\"0\" border=\"0\" width=\"100%\">\s*<tr>\s*<td class=\"alt2\" style=\"border:1px inset\">\s*/si", "[quote]", $str);
$str = preg_replace("/(<\/div>\s*)?<\/td>\s*<\/tr>\s*<\/table>\s*<\/div>/", '[/quote]', $str);
# urls && threads/posts internal linking
$str = preg_replace("/<a[^>]*href=\"([^\"]*)\"[^>]*>([^<]*)<\/a>/si", "[url=\\1]\\2[/url]", $str);
# mailto
$str = preg_replace("/<a[^>]*href=\"mailto:([^\"]*)\"[^>]*>([^<]*)<\/a>/si", "[email=\\1]\\2[/email]", $str);
# images (after quotes/smileys and others containig images: images/buttons/viewpost.gif)
$str = preg_replace("/<img[^>]*src=\"([^\"]*)\"[^>]*>/si", "[img]\\1[/img]", $str);
# screencast
$str = preg_replace("/<iframe width=\"\d+\" height=\"\d+\" frameborder=\"0\" scrolling=\"no\" src=\"http:\/\/www\.screencast-o-matic\.com\/embed\?sc=(\w+)&[^>]*\"><\/iframe>/si", "[screencast]\\1[/screencast]", $str);
# clear sig
$str = preg_replace("/<!-- sig -->.*?<!-- \/ sig -->/si", '', $str);
# clear attachment
$str = preg_replace("/<!-- attachments -->.*?<!-- \/ attachments -->/si", '', $str);
# html comments
$str = preg_replace("/<!-- \w+ -->/", '', $str);
$str = preg_replace("/<!-- \/ \w+ -->/", '', $str);
# clean all unmatched tags for clarity
$str = strip_tags($str);
# html characteres
$str = str_replace('"', '"', $str);
$str = str_replace(''', "'", $str);
$str = str_replace('&', "&", $str);
return trim($str);
} |