function bbcode_bbc2html($text) { $bbcode_emoticons = bbcode_emoticons(); // By BlackWizard, http://www.phpcs.com/codes/BBCODE-SIMPLEMENT_17638.aspx $text = preg_replace("#\\[img\\]((ht|f)tp://)([^\r\n\t<\"]*?)\\[/img\\]#sie", "'<img src=\\1' . str_replace(' ', '%20', '\\3') . ' />'", $text); $text = preg_replace("#\\[url=((ht|f)tp://)([^\r\n\t<\"]*?)\\](.+?)\\[\\/url\\]#sie", "'<a href=\"\\1' . str_replace(' ', '%20', '\\3') . '\" target=blank>\\4</a>'", $text); $text = preg_replace("#\\[url\\]((ht|f)tp://)([^\r\n\t<\"]*?)\\[/url\\]#sie", "'<a href=\"\\1' . str_replace(' ', '%20', '\\3') . '\" target=blank>\\1\\3</a>'", $text); $text = preg_replace("#\\[b\\](.+?)\\[\\/b\\]#sie", "'<b>\\1</b>'", $text); $text = preg_replace("#\\[i\\](.+?)\\[\\/i\\]#sie", "'<i>\\1</i>'", $text); $text = preg_replace("#\\[u\\](.+?)\\[\\/u\\]#sie", "'<u>\\1</u>'", $text); $text = preg_replace("#\\[h1\\](.+?)\\[\\/h1\\]#sie", "'<h1>\\1</h1>'", $text); $text = preg_replace("#\\[h2\\](.+?)\\[\\/h2\\]#sie", "'<h2>\\1</h2>'", $text); $text = preg_replace("#\\[code\\](.+?)\\[\\/code\\]#sie", "'<br /><table class=\"flat\" width=90%><tr><th align=left style=\"background-color:#344;font-size:16px;\">#:</th></tr><tr><td align=left style=\"background-color:#333;\"><code>\\1</code></td></tr></table>'", $text); $text = preg_replace("#\\[quote\\](.+?)\\[\\/quote\\]#sie", "'<br /><table class=\"flat\" width=90%><tr><th align=left style=\"background-color:#443;font-size:16px;\">Cita :</th></tr><tr><td align=left style=\"background-color:#333;\">\\1</td></tr></table>'", $text); $text = preg_replace("#\\[quote=(.+?)\\](.+?)\\[\\/quote\\]#sie", "'<br /><table class=\"flat\" width=90%><tr><th align=left style=\"background-color:#443;font-size:16px;\">\\1 :</th></tr><tr><td align=left style=\"background-color:#333;>\\2</td></tr></table>'", $text); $text = preg_replace("#\\[color=(.+?)\\](.+?)\\[\\/color\\]#sie", "'<font color=\\1>\\2</font>'", $text); $text = preg_replace("#\\[size=(.+?)\\](.+?)\\[\\/size\\]#sie", "'<font size=\\1>\\2</font>'", $text); $text = preg_replace("#\\[font=(.+?)\\](.+?)\\[\\/font\\]#sie", "'<font face=\"\\1\">\\2</font>'", $text); $text = preg_replace("#\\[left\\](.+?)\\[\\/left\\]#sie", "'<p style=\"text-align:left;\">\\1</p>'", $text); $text = preg_replace("#\\[right\\](.+?)\\[\\/right\\]#sie", "'<p style=\"text-align:right;\">\\1</p>'", $text); $text = preg_replace("#\\[center\\](.+?)\\[\\/center\\]#sie", "'<center>\\1</center>'", $text); $text = preg_replace("/([^\\/=\"\\]])((http|ftp)+(s)?:\\/\\/[^<>\\s]+)/i", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $text); $text = preg_replace('/([^\\/=\\"\\]])(www\\.)(\\S+)/', '\\1<a href="http://\\2\\3" target="_blank">\\2\\3</a>', $text); $text = preg_replace('#\\r\\n#', '<br />', $text); $text = str_replace('#\\r#', '<br />', $text); // Emoticons for ($i = 0; $i < count($bbcode_emoticons); $i++) { $text = preg_replace("#" . preg_quote($bbcode_emoticons[$i][0]) . "#sie", "'<img src=\"img/emoticons/{$bbcode_emoticons[$i][1]}.gif\" />'", $text); } $text = str_replace("<br />", "<br />", $text); return $text; }
function bbcode_add_editor() { global $output; $bbcode_fonts = bbcode_fonts(); $bbcode_sizes = bbcode_sizes(); $bbcode_colors = bbcode_colors(); $bbcode_emoticons = bbcode_emoticons(); $output .= ' <script type="text/javascript" src="libs/js/bbcode.js"></script> <div style="display:block"> <select> <option>' . $bbcode_fonts[0] . '</option>'; for ($i = 0; $i < count($bbcode_fonts); $i++) { $output .= ' <option onclick="addbbcode(\'msg\',\'font\',\'' . $bbcode_fonts[$i] . '\');" style="font-family:\'' . $bbcode_fonts[$i] . '\';">' . $bbcode_fonts[$i] . '</option>'; } $output .= ' </select> <select> <option>Size</option>'; for ($i = 0; $i < count($bbcode_sizes); $i++) { $output .= ' <option onclick="addbbcode(\'msg\',\'size\',\'' . $bbcode_sizes[$i][1] . '\');">' . $bbcode_sizes[$i][0] . '</option>'; } $output .= ' </select> <select> <option>' . $bbcode_colors[0][1] . '</option>'; for ($i = 1; $i < count($bbcode_colors); $i++) { $output .= ' <option onclick="addbbcode(\'msg\',\'color\',\'' . $bbcode_colors[$i][0] . '\');" style="color:' . $bbcode_colors[$i][0] . ';background-color:#383838;">' . $bbcode_colors[$i][1] . '</option>'; } $output .= ' </select> <img src="img/editor/bold.gif" onclick="addbbcode(\'msg\',\'b\')" width="21" height="20" style="cursor:pointer;" alt="" /> <img src="img/editor/italic.gif" onclick="addbbcode(\'msg\',\'i\')" width="21" height="20" style="cursor:pointer;" alt="" /> <img src="img/editor/underline.gif" onclick="addbbcode(\'msg\',\'u\')" width="21" height="20" style="cursor:pointer;" alt="" /> <img src="img/editor/strikethrough.gif" onclick="addbbcode(\'msg\',\'strike\')" width="21" height="20" style="cursor:pointer;" alt="" /> <!-- img src="img/editor/justifyleft.gif" onclick="addbbcode(\'msg\',\'left\')" width="21" height="20" style="cursor:pointer;" alt="" / --> <img src="img/editor/justifycenter.gif" onclick="addbbcode(\'msg\',\'center\')" width="21" height="20" style="cursor:pointer;" alt="" /> <!-- img src="img/editor/justifyright.gif" onclick="addbbcode(\'msg\',\'right\')" width="21" height="20" style="cursor:pointer;" alt="" / --> <img src="img/editor/image.gif" onclick="add_img(\'msg\')" width="21" height="20" style="cursor:pointer;" alt="" /> <img src="img/editor/link.gif" onclick="add_url(\'msg\')" width="21" height="20" style="cursor:pointer;" alt="" /> <!-- img src="img/editor/mail.gif" onclick="add_mail(\'msg\')" width="21" height="20" style="cursor:pointer;" alt="" / --> <img src="img/editor/code.gif" onclick="addbbcode(\'msg\',\'code\')" width="21" height="20" style="cursor:pointer;" alt="" /> <img src="img/editor/quote.gif" onclick="add_quote(\'msg\')" width="21" height="20" style="cursor:pointer;" alt="" /> </div> <div style="display:block;padding-top:5px;">'; for ($i = 0; $i < count($bbcode_emoticons); $i++) { $output .= ' <img src="img/emoticons/' . $bbcode_emoticons[$i][1] . '.gif" onclick="addText(\'msg\',\'' . $bbcode_emoticons[$i][0] . '\')" width="' . $bbcode_emoticons[$i][2] . '" height="' . $bbcode_emoticons[$i][3] . '" style="cursor:pointer;padding:1px;" alt="" />'; } $output .= ' </div>'; }