* @copyright (cc) creative commons - attribution-shareAlike 3.0 unported * @version 2.0 * @package qoob * @subpackage utils */ final class bbcode { /** * format * takes a bbcode string and creates it's html equivalent. * * @param string $str the bbcode string * @return string */ function format ($str) { //$str = htmlentities($str); $simple_search = array( //added line break '/\[br\]/is', '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[align\=(left|center|right)\](.*?)\[\/align\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[mail\=(.*?)\](.*?)\[\/mail\]/is', '/\[mail\](.*?)\[\/mail\]/is', '/\[font\=(.*?)\](.*?)\[\/font\]/is', '/\[size\=(.*?)\](.*?)\[\/size\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', //added textarea for code presentation '/\[codearea\](.*?)\[\/codearea\]/is', //added pre class for code presentation '/\[code\](.*?)\[\/code\]/is', //added paragraph '/\[p\](.*?)\[\/p\]/is', ); $simple_replace = array( //added line break '
', '$1', '$1', '$1', // added nofollow to prevent spam '$2', '$1', '
$2
', //added alt attribute for validation '', '$2', '$1', '
$2
', '
$2
', '
$2
', //added textarea for code presentation '', //added pre class for code presentation '
$1
', //added paragraph '

$1

', ); // Do simple BBCode's $str = preg_replace ($simple_search, $simple_replace, $str); // Do
BBCode $str = $this->quote($str); // convert new lines to line breaks return nl2br($str); } /** * quote * create an html quote box from bb codes * * @param string $str the string to be quoted * @return string */ function quote($str) { //added div and class for quotes $open = '
'; $close = '
'; // How often is the open tag? preg_match_all ('/\[quote\]/i', $str, $matches); $opentags = count($matches['0']); // How often is the close tag? preg_match_all ('/\[\/quote\]/i', $str, $matches); $closetags = count($matches['0']); // Check how many tags have been unclosed // And add the unclosing tag at the end of the message $unclosed = $opentags - $closetags; for ($i = 0; $i < $unclosed; $i++) { $str .= '
'; } // Do replacement $str = str_replace ('[' . 'quote]', $open, $str); $str = str_replace ('[/' . 'quote]', $close, $str); return $str; } } ?>