/** * Construct the BBCodeHandler */ public function __construct() { parent::__construct(); $this->setDefaultSettings(); }
return true; } if (!isset($attributes['default'])) { return '<a href="' . htmlspecialchars($content) . '">' . htmlspecialchars($content) . '</a>'; } return '<a href="' . htmlspecialchars($attributes['default']) . '">' . $content . '</a>'; } // Funktion zum Einbinden von Bildern function do_bbcode_img($action, $attributes, $content, $params, $node_object) { if ($action == 'validate') { return true; } return '<img src="' . htmlspecialchars($content) . '" alt="">'; } $bbcode = new StringParser_BBCode(); $bbcode->addFilter(STRINGPARSER_FILTER_PRE, 'convertlinebreaks'); $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), 'htmlspecialchars'); $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), 'nl2br'); $bbcode->addParser('list', 'bbcode_stripcontents'); $bbcode->addCode('b', 'simple_replace', null, array('start_tag' => '<b>', 'end_tag' => '</b>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('code', 'simple_replace', null, array('start_tag' => '<code>', 'end_tag' => '</code>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('i', 'simple_replace', null, array('start_tag' => '<i>', 'end_tag' => '</i>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('url', 'usecontent?', 'do_bbcode_url', array('usecontent_param' => 'default'), 'link', array('listitem', 'block', 'inline'), array('link')); $bbcode->addCode('link', 'callback_replace_single', 'do_bbcode_url', array(), 'link', array('listitem', 'block', 'inline'), array('link')); $bbcode->addCode('img', 'usecontent', 'do_bbcode_img', array(), 'image', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('bild', 'usecontent', 'do_bbcode_img', array(), 'image', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->setOccurrenceType('img', 'image'); $bbcode->setOccurrenceType('bild', 'image'); $bbcode->setMaxOccurrences('image', 2); $bbcode->addCode('list', 'simple_replace', null, array('start_tag' => '<ul>', 'end_tag' => '</ul>'), 'list', array('block', 'listitem'), array());
function BBCodeToHTML($content) { global $_ARRAYLANG; $objBBCode = new \StringParser_BBCode(); $objBBCode->addFilter(STRINGPARSER_FILTER_PRE, array(&$this, 'convertlinebreaks')); //unify all linebreak variants from different systems $objBBCode->addFilter(STRINGPARSER_FILTER_PRE, array(&$this, 'convertlinks')); // $objBBCode->addFilter(STRINGPARSER_FILTER_POST, array(&$this, 'stripBBtags')); $objBBCode->addFilter(STRINGPARSER_FILTER_POST, array(&$this, 'removeDoubleEscapes')); $objBBCode->addParser(array('block', 'inline', 'link', 'listitem'), 'htmlspecialchars'); $objBBCode->addParser(array('block', 'inline', 'link', 'listitem'), 'nl2br'); $objBBCode->addParser('list', array(&$this, 'bbcode_stripcontents')); $objBBCode->addCode('b', 'simple_replace', null, array('start_tag' => '<b>', 'end_tag' => '</b>'), 'inline', array('block', 'inline'), array()); $objBBCode->addCode('i', 'simple_replace', null, array('start_tag' => '<i>', 'end_tag' => '</i>'), 'inline', array('block', 'inline'), array()); $objBBCode->addCode('u', 'simple_replace', null, array('start_tag' => '<u>', 'end_tag' => '</u>'), 'inline', array('block', 'inline'), array()); $objBBCode->addCode('s', 'simple_replace', null, array('start_tag' => '<strike>', 'end_tag' => '</strike>'), 'inline', array('block', 'inline'), array()); $objBBCode->addCode('url', 'usecontent?', array(&$this, 'do_bbcode_url'), array('usecontent_param' => 'default'), 'inline', array('listitem', 'block', 'inline'), array('link')); $objBBCode->addCode('img', 'usecontent', array(&$this, 'do_bbcode_img'), array('usecontent_param' => array('w', 'h')), 'image', array('listitem', 'block', 'inline', 'link'), array()); $objBBCode->addCode('quote', 'callback_replace', array(&$this, 'do_bbcode_quote'), array('usecontent_param' => 'default'), 'block', array('block', 'inline'), array('list', 'listitem')); $objBBCode->addCode('code', 'usecontent', array(&$this, 'do_bbcode_code'), array('usecontent_param' => 'default'), 'block', array('block', 'inline'), array('list', 'listitem')); $objBBCode->addCode('list', 'simple_replace', null, array('start_tag' => '<ul>', 'end_tag' => '</ul>'), 'list', array('block', 'listitem'), array()); $objBBCode->addCode('*', 'simple_replace', null, array('start_tag' => '<li>', 'end_tag' => '</li>'), 'listitem', array('list'), array()); $objBBCode->setCodeFlag('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL); $objBBCode->setCodeFlag('*', 'paragraphs', true); $objBBCode->setCodeFlag('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); $objBBCode->setCodeFlag('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP); $objBBCode->setCodeFlag('list', 'closetag.before.newline', BBCODE_NEWLINE_DROP); $objBBCode->setOccurrenceType('img', 'image'); $objBBCode->setMaxOccurrences('image', 5); $objBBCode->setRootParagraphHandling(false); //do not convert new lines to paragraphs, see stringparser_bbcode::setParagraphHandlingParameters(); $content = $objBBCode->parse($content); return $content; }
function parseBBcode($input) { //load our BBcode parser - Dan: This probably shouldn't be in the controller but I can't think of a better place for it if (!class_exists('StringParser_BBCode')) { include_once JPATH_BASE . "/administrator/components/com_ninja/helpers/bbcode/stringparser_bbcode.class.php"; } $bbcode = new StringParser_BBCode(); //this is a temporary fix, so the module can appear on pages that have Ninjamonials or Ninjaboard installed //in which case these functions will already have been created. So we don't want to cause an error by creatign thema again if (!function_exists('convertlinebreaks')) { //Initialise the settings // Unify line breaks of different operating systems function convertlinebreaks($text) { $text = preg_replace("/\r\n|\r|\n/", "\n", $text); $text = str_replace("\r\n", "\n", $text); $text = str_replace('\\r\\n', "\n", $text); $text = str_replace("<br/>", "\n", $text); $text = str_replace("<br />", "\n", $text); return str_replace("<br>", "\n", $text); } // Remove everything but the newline charachter function bbcode_stripcontents($text) { return preg_replace("/[^\n]/", '', $text); } function do_bbcode_url($action, $attributes, $content, $params, $node_object) { if (!isset($attributes['default'])) { $url = $content; $text = htmlspecialchars($content); } else { $url = $attributes['default']; $text = $content; } if ($action == 'validate') { if (substr($url, 0, 5) == 'data:' || substr($url, 0, 5) == 'file:' || substr($url, 0, 11) == 'javascript:' || substr($url, 0, 4) == 'jar:') { return false; } return true; } return '<a href="' . htmlspecialchars($url) . '">' . $text . '</a>'; } // Function to include images function do_bbcode_img($action, $attributes, $content, $params, $node_object) { if ($action == 'validate') { if (substr($content, 0, 5) == 'data:' || substr($content, 0, 5) == 'file:' || substr($content, 0, 11) == 'javascript:' || substr($content, 0, 4) == 'jar:' || substr($content, -4) == '.php') { return false; } return true; } return '<img src="' . htmlspecialchars($content) . '" alt="">'; } function do_bbcode_color($action, $attributes, $content, $params, $node_object) { //the default attribute is one after the bbtag itself [color=blah]text[/color] if (isset($attributes['default'])) { return '<span style="color:' . $attributes['default'] . '">' . $content . '</span>'; } return $content; } function do_bbcode_quote($action, $attributes, $content, $params, $node_object) { if (!isset($attributes['default'])) { $whoSaid = ''; } else { $whoSaid = '<span class="nmWhoSaid">' . JText::sprintf('NM_WHOSAID', $attributes['default']) . '</span>'; } return '<blockquote class="nmQuote"><span>' . $whoSaid . $content . '</span></blockquote>'; } function do_bbcode_size($action, $attributes, $content, $params, $node_object) { if (isset($attributes['default'])) { return '<span style="font-size:' . $attributes['default'] . '%">' . $content . '</span>'; } return $content; } } $bbcode->addFilter(1, 'convertlinebreaks'); $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), 'htmlspecialchars'); $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), 'nl2br'); $bbcode->addParser('list', 'bbcode_stripcontents'); $bbcode->addCode('b', 'simple_replace', null, array('start_tag' => '<strong>', 'end_tag' => '</strong>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('i', 'simple_replace', null, array('start_tag' => '<em>', 'end_tag' => '</em>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('u', 'simple_replace', null, array('start_tag' => '<u>', 'end_tag' => '</u>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('color', 'callback_replace', 'do_bbcode_color', array('usecontent_param' => 'default'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('url', 'usecontent?', 'do_bbcode_url', array('usecontent_param' => 'default'), 'link', array('listitem', 'block', 'inline'), array('link')); $bbcode->addCode('quote', 'callback_replace', 'do_bbcode_quote', array('usecontent_param' => 'default'), 'block', array('block'), array('link', 'listitem', 'inline')); $bbcode->addCode('size', 'callback_replace', 'do_bbcode_size', array('usecontent_param' => 'default'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('img', 'usecontent', 'do_bbcode_img', array(), 'image', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->setOccurrenceType('img', 'image'); $bbcode->setMaxOccurrences('image', 4); $bbcode->addCode('ul', 'simple_replace', null, array('start_tag' => '<ul>', 'end_tag' => '</ul>'), 'list', array('block', 'listitem'), array()); $bbcode->addCode('ol', 'simple_replace', null, array('start_tag' => '<ol>', 'end_tag' => '</ol>'), 'list', array('block', 'listitem'), array()); $bbcode->addCode('*', 'simple_replace', null, array('start_tag' => '<li>', 'end_tag' => '</li>'), 'listitem', array('list'), array()); $bbcode->setCodeFlag('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL); $bbcode->setCodeFlag('*', 'paragraphs', true); $bbcode->setCodeFlag('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); $bbcode->setCodeFlag('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP); $bbcode->setCodeFlag('list', 'closetag.before.newline', BBCODE_NEWLINE_DROP); $bbcode->setRootParagraphHandling(false); /* * End setup bbcode */ $parsed_input = $bbcode->parse(trim($input)); /* * TODO - This is a very quick and dirty emoticon emoticon handler. * This MUST be replaced asap */ // Smileys to find... $emoticonsIn = array(':)', ':(', ':o', ':s', '8)', ':D'); // And replace them with... $emoticonsOut = array('<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_smile.png') . '" alt=":)"/>', '<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_sad.png') . '" alt=":("/>', '<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_surprised.png') . '" alt=":o"/>', '<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_confused.png') . '" alt=":s"/>', '<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_cool.png') . '" alt="8)"/>', '<img border="0" src="' . JRoute::_('media/com_ninjamonials/images/emoticons/smiley_biggrin.png') . '" alt=":D"/>'); $output = str_replace($emoticonsIn, $emoticonsOut, $parsed_input); return $output; }
private function addReply() { if (isset($_POST['addReply'])) { if (!isset($_POST['reply']) or empty($_POST['reply'])) { $msg = 'You need to fillout a reply!'; header('Location: index.php?mod=Forum&act=read&id=' . (int) $_GET['id'] . '&msg=' . urlencode($msg)); exit; } else { $message = nl2br(htmlentities($_POST['reply'], ENT_COMPAT, 'UTF-8')); // Smiley //$message = str_replace(":-)","<img src=\"/images/smiley/smile.png\">",$message); $message = str_replace(":-)", "<img src=images/smiley/smile.png>", $message); //$message = str_replace(":-(","<img src=\"/images/smiley/sad.png\">",$message); $message = str_replace(":-(", "<img src=images/smiley/sad.png>", $message); //Smiley ende //BBCodes test require_once 'stringparser_bbcode.class.php'; $bbcode = new StringParser_BBCode(); $bbcode->addCode('b', 'simple_replace', null, array('start_tag' => '<b>', 'end_tag' => '</b>'), 'inline', array('block', 'inline'), array()); // Fett $bbcode->addCode('i', 'simple_replace', null, array('start_tag' => '<i>', 'end_tag' => '</i>'), 'inline', array('block', 'inline'), array()); // Kursiv $bbcode->addCode('u', 'simple_replace', null, array('start_tag' => '<u>', 'end_tag' => '</u>'), 'inline', array('block', 'inline'), array()); // Unterstrichen $bbcode->addCode('list', 'simple_replace', null, array('start_tag' => '<ul>', 'end_tag' => '</ul>'), 'list', array('block', 'listitem'), array()); // Liste $bbcode->addCode('*', 'simple_replace', null, array('start_tag' => '<li>', 'end_tag' => '</li>'), 'listitem', array('list'), array()); // Punkt in der Liste $bbcode->addCode('url', 'usecontent?', 'do_bbcode_url', array('usecontent_param' => 'default'), 'link', array('listitem', 'block', 'inline'), array('link')); $bbcode->addCode('link', 'callback_replace_single', 'do_bbcode_url', array(), 'link', array('listitem', 'block', 'inline'), array('link')); $bbcode->addCode('img', 'usecontent', 'do_bbcode_img', array(), 'image', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('bild', 'usecontent', 'do_bbcode_img', array(), 'image', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->setOccurrenceType('img', 'image'); $bbcode->setOccurrenceType('bild', 'image'); $bbcode->setMaxOccurrences('image', 2); $bbcode->setCodeFlag('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL); $bbcode->setCodeFlag('*', 'paragraphs', true); $bbcode->setCodeFlag('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); $bbcode->setCodeFlag('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP); $bbcode->setCodeFlag('list', 'closetag.before.newline', BBCODE_NEWLINE_DROP); $bbcode->setRootParagraphHandling(true); $message = $bbcode->parse($message); //BBCodes ende test $top = $this->db->fetchRow('SELECT * FROM `<ezrpg>forum_top` WHERE `id`=?', array($_GET['id'])); $insert = array(); $insert['id_cat'] = $top->id_cat; $insert['id_top'] = $top->id; $insert['poster'] = $this->player->username; $insert['message'] = $message; $insert['date'] = time(); $this->db->insert('<ezrpg>forum_mes', $insert); $msg = 'The reply is succesfull added!'; header('Location: index.php?mod=Forum&act=read&id=' . (int) $_GET['id'] . '&msg=' . urlencode($msg)); exit; } } }
protected static function parseBbcode($str, $special_code, $strip = true) { if (static::$_bbcode_parser === null) { $bbcode = new \StringParser_BBCode(); // add list of bbcode for formatting $codes = []; $codes[] = ['code', 'simple_replace', null, ['start_tag' => '<code>', 'end_tag' => '</code>'], 'code', ['block', 'inline'], []]; $codes[] = ['spoiler', 'simple_replace', null, ['start_tag' => '<span class="spoiler">', 'end_tag' => '</span>'], 'inline', ['block', 'inline'], ['code']]; $codes[] = ['sub', 'simple_replace', null, ['start_tag' => '<sub>', 'end_tag' => '</sub>'], 'inline', ['block', 'inline'], ['code']]; $codes[] = ['sup', 'simple_replace', null, ['start_tag' => '<sup>', 'end_tag' => '</sup>'], 'inline', ['block', 'inline'], ['code']]; $codes[] = ['b', 'simple_replace', null, ['start_tag' => '<b>', 'end_tag' => '</b>'], 'inline', ['block', 'inline'], ['code']]; $codes[] = ['i', 'simple_replace', null, ['start_tag' => '<em>', 'end_tag' => '</em>'], 'inline', ['block', 'inline'], ['code']]; $codes[] = ['m', 'simple_replace', null, ['start_tag' => '<tt class="code">', 'end_tag' => '</tt>'], 'inline', ['block', 'inline'], ['code']]; $codes[] = ['o', 'simple_replace', null, ['start_tag' => '<span class="overline">', 'end_tag' => '</span>'], 'inline', ['block', 'inline'], ['code']]; $codes[] = ['s', 'simple_replace', null, ['start_tag' => '<span class="strikethrough">', 'end_tag' => '</span>'], 'inline', ['block', 'inline'], ['code']]; $codes[] = ['u', 'simple_replace', null, ['start_tag' => '<span class="underline">', 'end_tag' => '</span>'], 'inline', ['block', 'inline'], ['code']]; $codes[] = ['EXPERT', 'simple_replace', null, ['start_tag' => '<span class="expert">', 'end_tag' => '</span>'], 'inline', ['block', 'inline'], ['code']]; foreach ($codes as $code) { if ($strip) { $code[1] = 'callback_replace'; $code[2] = '\\Comment::stripUnusedBbcode'; // this also fixes pre/code } $bbcode->addCode($code[0], $code[1], $code[2], $code[3], $code[4], $code[5], $code[6]); } static::$_bbcode_parser = $bbcode; } // if $special == true, add special bbcode if ($special_code === true) { static::$_bbcode_parser->addCode('moot', 'simple_replace', null, ['start_tag' => '', 'end_tag' => ''], 'inline', ['block', 'inline'], []); static::$_bbcode_parser->addCode('fortune', 'usecontent?', '\\Comment::parseBbcodeAttr', ['usecontent_param' => 'color'], 'inline', ['block', 'inline'], []); } return static::$_bbcode_parser->parse($str); }
function parse_post($text, $allowsmilie = false) { global $nuke_quotes, $fr_platform, $images; $images = array(); if (is_ipb()) { // Replace <br.*/> with \n $text = preg_replace('#<br.*?/>#is', "\n", $text); } $smilies = false; $v = process_input(array('smilies' => BOOLEAN)); if (isset($v['smilies'])) { $smilies = $v['smilies'] === true; } // Trim each line $lines = preg_split("/\n/", $text); for ($i = 0; $i < count($lines); $i++) { $lines[$i] = trim($lines[$i]); } $text = join("\n", $lines); $text = prepare_utf8_string($text, false); $bbcode = new StringParser_BBCode(); $bbcode->setGlobalCaseSensitive(false); // Handle default BBCode $bbcode->addCode('quote', 'callback_replace', 'handle_quotes', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); $bbcode->addCode('url', 'usecontent?', 'handle_url', array('usecontent_param' => 'default'), 'link', array('listitem', 'block', 'inline'), array('link')); $bbcode->addCode('source', 'usecontent?', 'handle_url', array('usecontent_param' => 'default'), 'link', array('listitem', 'block', 'inline'), array('link')); if (!is_mybb()) { // myBB wonky attachment codes are already handled $bbcode->addCode('attach', 'callback_replace', 'handle_attach', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); } $bbcode->addCode('attach', 'callback_replace', 'handle_attach', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); $bbcode->addCode('img', 'callback_replace', 'handle_image', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); $bbcode->addCode('imgl', 'callback_replace', 'handle_image', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); $bbcode->addCode('imgr', 'callback_replace', 'handle_image', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); //$bbcode->addCode('spoiler', 'callback_replace', 'handle_spoiler', array(), 'inline', //array('listitem', 'block', 'inline', 'link'), array('')); $bbcode->addCode('b', 'callback_replace', 'handle_bbcode_bold', array('usecontent_param' => array('default')), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('i', 'callback_replace', 'handle_bbcode_italic', array('usecontent_param' => array('default')), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('color', 'callback_replace', 'handle_bbcode_color', array('usecontent_param' => array('default')), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->setCodeFlag('color', 'closetag', BBCODE_CLOSETAG_MUSTEXIST); // Video Link BBCode $bbcode->addCode('yt', 'callback_replace', 'fr_handle_youtube', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); $bbcode->addCode('youtube', 'callback_replace', 'fr_handle_youtube', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); $bbcode->addCode('video', 'callback_replace', 'handle_video', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); $bbcode->addCode('ame', 'callback_replace', 'handle_video', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); $bbcode->addCode('media', 'callback_replace', is_xen() ? 'handle_xen_media' : 'handle_video', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); $bbcode->addCode('tex', 'callback_replace', 'fr_handle_tex', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array('')); if (function_exists('fr_branded_bbcode_handler')) { @fr_branded_bbcode_handler($bbcode); } if (is_mybb()) { $bbcode->setMixedAttributeTypes(true); } $nuked_quotes = $text; $text = htmlspecialchars_uni($text); $nuke_quotes = true; $nuked_quotes = $bbcode->parse($nuked_quotes); if (is_ipb()) { $nuked_quotes = ipb_handle_attachments($nuked_quotes); } $nuke_quotes = false; $text = $bbcode->parse($text); if (is_ipb()) { $text = ipb_handle_attachments($text); } // Snag out images preg_match_all('#\\[IMG\\](.*?)\\[/IMG\\]#is', $text, $matches); $text = preg_replace("#\\[IMG\\](.*?)\\[/IMG\\]#is", '', $text); $nuked_quotes = preg_replace("#\\[IMG\\](.*?)\\[/IMG\\]#is", '', $nuked_quotes); if ($smilies) { if (is_vb()) { global $vbulletin; $parser = new vB_BbCodeParser($vbulletin, fetch_tag_list()); $text = $parser->parse_smilies($text, false); $text = preg_replace_callback('#img src="(.*?)"#is', parse_post_callback, $text); } } $text = preg_replace("#\n\n\n+#", "\n\n", $text); $text = preg_replace("#\n#", "<br/>", $text); $text = remove_bbcode($text); $nuked_quotes = preg_replace("#\n\n\n+#", "\n\n", $nuked_quotes); $nuked_quotes = remove_bbcode($nuked_quotes); return array($text, $nuked_quotes, $images); }
/** * strips bbcodes out of a string * * @global Database $db * @param string $text the string * @param bool $strict if true codes with strippable 1 are stripped too * @return string the stripped string */ public function strip($text, $strict = false) { $parser = new StringParser_BBCode(); $parser->setGlobalCaseSensitive(false); $parser->addCode('list', 'callback_replace', 'bbcode_list', array(), 'list', array('block', 'listitem'), array('inline')); $parser->addCode('*', 'simple_replace', null, array('start_tag' => '<li>', 'end_tag' => '</li>'), 'listitem', array('list'), array()); $parser->setCodeFlag('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL); $parser->setCodeFlag('*', 'paragraphs', true); $parser->setCodeFlag('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); $parser->setCodeFlag('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP); $parser->setCodeFlag('list', 'closetag.before.newline', BBCODE_NEWLINE_DROP); foreach ($result as $code) { if ($code['strippable'] === '0') { continue; } elseif ($code['strippable'] === '1' && !$strict) { continue; } $params = array('start_tag' => '', 'end_tag' => ''); $tmp = explode('&', $code['params']); foreach ($tmp as $pair) { $parts = explode('=', $pair); if (count($parts) < 2) { continue; } $values = explode(',', $parts[1]); if (count($values) == 1) { $values = urldecode($values[0]); } else { $values = array_map('urldecode', $values); } $params[urldecode($parts[0])] = $values; } unset($tmp); $parser->addCode($code['name'], $code['parsetype'], preg_match('/(simple_replace|simple_replace_simgle)/i', $code['parsetype']) ? null : array('BBCodes', '_strip'), $params, $code['contenttype'], explode('|', $code['allowedin']), explode('|', $code['notallowedin'])); } return $parser->parse($text); }
function smarty_modifier_bbcode2html($message) { $bbcode = new StringParser_BBCode(); $bbcode->addFilter(STRINGPARSER_FILTER_PRE, 'convertlinebreaks'); //$bbcode->addParser (array ('block', 'inline', 'link', 'listitem'), 'htmlspecialchars'); $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), 'nl2br'); $bbcode->addParser('list', 'bbcode_stripcontents'); $bbcode->addCode('b', 'simple_replace', null, array('start_tag' => '<span style="font-weight:bold">', 'end_tag' => '</span>'), 'inline', array('listitem', 'block', 'inline', 'link', 'quote', 'color', 'size'), array()); $bbcode->addCode('i', 'simple_replace', null, array('start_tag' => '<span style="font-style:italic">', 'end_tag' => '</span>'), 'inline', array('listitem', 'block', 'inline', 'link', 'quote', 'color', 'size'), array()); $bbcode->addCode('u', 'simple_replace', null, array('start_tag' => '<span style="text-decoration:underline">', 'end_tag' => '</span>'), 'inline', array('listitem', 'block', 'inline', 'link', 'quote', 'color', 'size'), array()); $bbcode->addCode('url', 'usecontent?', 'do_bbcode_url', array('usecontent_param' => 'default'), 'link', array('listitem', 'block', 'inline', 'quote', 'color', 'size'), array('link')); $bbcode->addCode('quote', 'callback_replace', 'do_bbcode_quote', array('usecontent_param' => 'default'), 'quote', array('listitem', 'block', 'inline', 'quote'), array('link')); $bbcode->addCode('code', 'usecontent', 'do_bbcode_code', array(), 'code', array('listitem', 'block', 'inline', 'quote', 'code'), array('link')); $bbcode->addCode('color', 'callback_replace', 'do_bbcode_color', array('usecontent_param' => 'default'), 'color', array('listitem', 'block', 'inline', 'quote', 'size'), array('link')); $bbcode->addCode('size', 'callback_replace', 'do_bbcode_size', array('usecontent_param' => 'default'), 'size', array('listitem', 'block', 'inline', 'quote', 'color'), array('link')); $bbcode->addCode('link', 'callback_replace_single', 'do_bbcode_url', array(), 'link', array('listitem', 'block', 'inline', 'quote', 'color', 'size'), array('link')); $bbcode->addCode('img', 'usecontent', 'do_bbcode_img', array(), 'image', array('listitem', 'block', 'inline', 'link', 'quote', 'color', 'size'), array()); $bbcode->addCode('list', 'callback_replace', 'do_bbcode_list', array('usecontent_param' => 'default'), 'list', array('block', 'listitem', 'quote', 'color', 'size'), array()); $bbcode->addCode('*', 'simple_replace', null, array('start_tag' => '<li>', 'end_tag' => '</li>'), 'listitem', array('list'), array()); $bbcode->setCodeFlag('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL); $bbcode->setCodeFlag('*', 'paragraphs', true); $bbcode->setCodeFlag('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT); $bbcode->setCodeFlag('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP); $bbcode->setCodeFlag('list', 'closetag.before.newline', BBCODE_NEWLINE_DROP); $bbcode->setRootParagraphHandling(false); return $bbcode->parse($message); }
function _ff_checkHTMLforSQL($str, $postmode = 'html') { global $_FF_CONF; $bbcode = new StringParser_BBCode(); $bbcode->setGlobalCaseSensitive(false); if ($postmode == 'html' || $postmode == 'HTML') { $bbcode->addParser(array('block', 'inline'), '_ff_cleanHTML'); } $bbcode->addCode('code', 'simple_replace', null, array('start_tag' => '[code]', 'end_tag' => '[/code]'), 'code', array('listitem', 'block', 'inline', 'link'), array()); $str = $bbcode->parse($str); return $str; }
/** * Parse text block and interpret BBcodes * * @param string $str text to parse * @param string $postmode Either html or text * @param array $parser Additional parsers for the bbcode interpreter * @param array $code Additional bbcodes * @return string the formatted string */ function BBC_formatTextBlock($str, $postmode = 'html', $parser = array(), $code = array()) { global $_CONF; $postmode = strtolower($postmode); $bbcode = new StringParser_BBCode(); $bbcode->setGlobalCaseSensitive(false); if ($postmode == 'text') { $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), '_bbcode_htmlspecialchars'); $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), 'nl2br'); } else { $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), 'COM_checkHTML'); } $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), '_bcode_replacetags'); $bbcode->addParser('list', '_bbcode_stripcontents'); if (is_array($parser) && count($parser) > 0) { foreach ($parser as $extraparser) { if (isset($extraparser[0])) { $parm1 = $extraparser[0]; } else { $parm1 = ''; } if (isset($extraparser[1])) { $parm2 = $extraparser[1]; } else { $parm2 = ''; } $bbcode->addParser($parm1, $parm2); // $extraparser[0],$extraparser[1]); } } $bbcode->addCode('b', 'simple_replace', null, array('start_tag' => '<b>', 'end_tag' => '</b>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('i', 'simple_replace', null, array('start_tag' => '<i>', 'end_tag' => '</i>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('u', 'simple_replace', null, array('start_tag' => '<span style="text-decoration: underline;">', 'end_tag' => '</span>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('p', 'simple_replace', null, array('start_tag' => '<p>', 'end_tag' => '</p>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('s', 'simple_replace', null, array('start_tag' => '<del>', 'end_tag' => '</del>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('size', 'callback_replace', '_bbcode_size', array('usecontent_param' => 'default'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('color', 'callback_replace', '_bbcode_color', array('usercontent_param' => 'default'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('list', 'callback_replace', '_bbcode_list', array('usecontent_param' => 'default'), 'list', array('inline', 'block', 'listitem'), array()); $bbcode->addCode('*', 'simple_replace', null, array('start_tag' => '<li>', 'end_tag' => '</li>'), 'listitem', array('list'), array()); $bbcode->addCode('quote', 'simple_replace', null, array('start_tag' => '</p><div class="quotemain"><img src="' . $_CONF['site_url'] . '/forum/images/img_quote.gif" alt=""/>', 'end_tag' => '</div><p>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('url', 'usecontent?', '_bbcode_url', array('usecontent_param' => 'default'), 'link', array('listitem', 'block', 'inline'), array('link')); $bbcode->addCode('img', 'usecontent', '_bbcode_img', array(), 'image', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('code', 'usecontent', '_bbcode_code', array('usecontent_param' => 'default'), 'code', array('listitem', 'block', 'inline', 'link'), array()); if (is_array($code) && count($code) > 0) { foreach ($code as $extracode) { $bbcode->addCode($extracode[0], $extracode[1], $extracode[2], $extracode[3], $extracode[4], $extracode[5], $extracode[6]); } } $bbcode->setCodeFlag('quote', 'paragraph_type', BBCODE_PARAGRAPH_ALLOW_INSIDE); $bbcode->setCodeFlag('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL); $bbcode->setCodeFlag('*', 'paragraphs', true); $bbcode->setCodeFlag('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP); $bbcode->setCodeFlag('list', 'closetag.before.newline', BBCODE_NEWLINE_DROP); $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), '_bbcode_replacetags'); $bbcode->setRootParagraphHandling(true); if ($_CONF['censormode']) { $str = COM_checkWords($str); } $str = $bbcode->parse($str); return $str; }
/** * formats posting texts into plain text for e-mail notifications using the stringparser bbcode class * http://www.christian-seiler.de/projekte/php/bbcode/ * * @param string $string * @return string */ function email_format($string) { global $settings; require_once 'modules/stringparser_bbcode/stringparser_bbcode.class.php'; $bbcode = new StringParser_BBCode(); $bbcode->setGlobalCaseSensitive(false); $bbcode->addCode('quote', 'simple_replace', null, array('start_tag' => '', 'end_tag' => ''), 'inline', array('listitem', 'block', 'inline', 'link', 'quote'), array()); if ($settings['bbcode'] == 1) { $bbcode->addParser('list', 'bbcode_stripcontents'); $bbcode->addCode('b', 'simple_replace', null, array('start_tag' => '*', 'end_tag' => '*'), 'inline', array('listitem', 'block', 'inline', 'link', 'quote', 'pre', 'monospace'), array()); $bbcode->addCode('i', 'simple_replace', null, array('start_tag' => '', 'end_tag' => ''), 'inline', array('listitem', 'block', 'inline', 'link', 'quote', 'pre', 'monospace'), array()); $bbcode->addCode('u', 'simple_replace', null, array('start_tag' => '', 'end_tag' => ''), 'inline', array('listitem', 'block', 'inline', 'link', 'quote', 'pre', 'monospace'), array()); $bbcode->addCode('url', 'usecontent?', 'do_bbcode_url_email', array('usecontent_param' => 'default'), 'link', array('listitem', 'block', 'inline', 'quote', 'pre', 'monospace'), array('link')); $bbcode->addCode('link', 'usecontent?', 'do_bbcode_url_email', array('usecontent_param' => 'default'), 'link', array('listitem', 'block', 'inline', 'quote', 'pre', 'monospace'), array('link')); if ($settings['bbcode_img'] == 1) { $bbcode->addCode('img', 'usecontent', 'do_bbcode_img_email', array(), 'image', array('listitem', 'block', 'inline', 'link', 'quote'), array()); } $bbcode->addCode('color', 'callback_replace', 'do_bbcode_color_email', array('start_tag' => '', 'end_tag' => ''), 'inline', array('listitem', 'block', 'inline', 'link', 'quote', 'pre', 'monospace'), array()); $bbcode->addCode('size', 'callback_replace', 'do_bbcode_size_email', array('start_tag' => '', 'end_tag' => ''), 'inline', array('listitem', 'block', 'inline', 'link', 'quote'), array()); $bbcode->addCode('list', 'simple_replace', null, array('start_tag' => '', 'end_tag' => ''), 'list', array('block', 'listitem'), array()); $bbcode->addCode('*', 'simple_replace', null, array('start_tag' => '* ', 'end_tag' => ''), 'listitem', array('list'), array()); $bbcode->setCodeFlag('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL); #$bbcode->addCode ('code', 'simple_replace', null, array ('start_tag' => '', 'end_tag' => ''), 'code', array ('block', 'inline'), array ()); if ($settings['bbcode_code'] == 1) { $bbcode->addCode('code', 'usecontent', 'do_bbcode_code_email', array(), 'code', array('block', 'quote'), array()); $bbcode->addCode('pre', 'simple_replace', null, array('start_tag' => '', 'end_tag' => ''), 'pre', array('block', 'quote'), array()); $bbcode->addCode('inlinecode', 'simple_replace', null, array('start_tag' => '', 'end_tag' => ''), 'inline', array('listitem', 'block', 'inline', 'link', 'quote'), array()); $bbcode->addCode('monospace', 'simple_replace', null, array('start_tag' => '', 'end_tag' => ''), 'inline', array('listitem', 'block', 'inline', 'link', 'quote'), array()); } } $string = $bbcode->parse($string); return $string; }
/** * A wrapper arond the parser function so it works with the koowa helpers * * Use the options cache_group and cache_key to control the cache behavior. * @TIP set your own group and key, as the way keys are generated isn't optimal when using md5 other than * you don't need to purge cache when the text changes, as that also changes the key * * @author Stian Didriksen */ public function parse($config = array()) { //If no text, no need to run all this code if (empty($config['text'])) { return; } if (!isset($config['cache_group'])) { $config['cache_group'] = 'com.ninja.helper.bbcode.parsed'; } if (!isset($config['cache_key'])) { $config['cache_key'] = md5($config['text']); } //$config['cache_key'] = '8690303dcae84177bf642ba30b76393f'; if (!isset($this->_cache[$config['cache_group']])) { $this->_cache[$config['cache_group']] = KFactory::tmp('lib.joomla.cache', array($config['cache_group'], 'output')); } $cache = $this->_cache[$config['cache_group']]; //If it's cached, no need to parse so return the cached text if ($cached_output = $cache->get($config['cache_key'])) { return $cached_output; } //For debugging //$before = microtime(true); //This bbCode parser does not pick up [list=], but treats it as [list] $config['text'] = str_replace('[list=]', '[list=1]', $config['text']); $config['text'] = preg_replace('/\\[([a-z0-9=#]+)\\:([a-z0-9:]+)\\]/m', '[\\1]', $config['text']); $config['text'] = preg_replace('/\\[\\/([a-z0-9]+)\\:([a-z0-9:]+)\\]/m', '[/\\1]', $config['text']); $config['text'] = preg_replace('/\\[\\*\\:([a-z0-9:]+)\\]/m', '[*]', $config['text']); $config['text'] = preg_replace('/\\[\\/\\*\\:([a-z0-9:]+)\\]/m', '[/*]', $config['text']); ///* //Preprocessing of links //@TODO this fix should be optimized, preferrably by using cache //Modified with a handle for dealing with this kind of problem: http://example.com[/quote] causing unclosed tags $config['text'] = preg_replace_callback('#(^|[ \\t\\r\\n"“\'])(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:\'".,<>?«»“”‘’]))#ui', array($this, '_pregUrlReplaceCallback'), $config['text']); //*/ //Preprocessing of links //$config['text'] = preg_replace('#(^|[ \t\r\n"“\'])(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))#ui', '$1[url]$2[/url]', $config['text']); //Parse the bbcode $config['text'] = parent::parse($config['text']); //Strip out any [url] tags that failed validation (like javascript:alert(1) style urls) $config['text'] = str_replace(array('[url]', '[/url]'), '', $config['text']); //This interferes with some tags //$config['text'] = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a rel="nofollow" href="\\1">\\1</a>', $config['text']); $cache->store($config['text'], $config['cache_key']); //For debugging //error_log('Missed cache and that cost you '.(microtime(true)-$before).' seconds'); return $config['text']; }
public function displayText($str) { $sp = new StringParser_BBCode(); $sp->setGlobalCaseSensitive(false); if ($this->_postmode != 'html') { $sp->addParser(array('block', 'inline'), array($this, 'htmlspecialchars')); $sp->addParser(array('block', 'inline'), 'nl2br'); $sp->addParser(array('block', 'inline'), array($this, 'linkify')); } $sp->addCode('code', 'usecontent', array($this, '_codeblock'), array('usecontent_param' => 'default'), 'code', array('block'), array()); if ($this->replaceTags) { $sp->addParser(array('block'), array($this, '_replacetags')); } if ($this->_censorData) { $str = $this->censor($str); } $str = $sp->parse($str); return $str; }
function gf_formatOldPost($str, $postmode = 'html', $mode = '') { global $CONF_FORUM; $oldPost = 0; if ($CONF_FORUM['pre2.5_mode'] != true) { return $str; } if (strstr($str, '<pre class="forumCode">') !== false) { $oldPost = 1; } if (strstr($str, "[code]<code>") !== false) { $oldPost = 1; } if (strstr($str, "<pre>") !== false) { $oldPost = 1; } if (stristr($str, '[code') == false || stristr($str, '[code]<code>') == true) { if (strstr($str, "<pre>") !== false) { $oldPost = 1; } $str = str_replace('<pre>', '[code]', $str); $str = str_replace('</pre>', '[/code]', $str); } $str = str_ireplace("[code]<code>", '[code]', $str); $str = str_ireplace("</code>[/code]", '[/code]', $str); $str = str_replace(array("<br />\r\n", "<br />\n\r", "<br />\r", "<br />\n", "<br>\r\n", "<br>\n\r", "<br>\r", "<br>\n"), '<br' . XHTML . '>', $str); $str = preg_replace("/\\[QUOTE\\sBY=\\s(.+?)\\]/i", "[QUOTE] Quote by \$1:", $str); /* Reformat code blocks - version 2.3.3 and prior */ $str = str_replace('<pre class="forumCode">', '[code]', $str); $str = preg_replace("/\\[QUOTE\\sBY=(.+?)\\]/i", "[QUOTE] Quote by \$1:", $str); $bbcode = new StringParser_BBCode(); $bbcode->setGlobalCaseSensitive(false); // It is impossible to include block level elements in a <p> element. Therefore I fix this. $bbcode->setParagraphHandlingParameters("\n\n", "", ""); if ($postmode == 'text') { $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), 'bbcode_htmlspecialchars'); } if ($CONF_FORUM['use_glfilter'] == 1 && ($postmode == 'html' || $postmode == 'HTML')) { $bbcode->addParser(array('block', 'inline', 'link', 'listitem'), 'gf_checkHTML'); // calls checkHTML on all text blocks } $bbcode->addParser(array('block', 'inline', 'link', 'list', 'listitem'), 'bbcode_oldpost'); $bbcode->addCode('code', 'simple_replace', null, array('start_tag' => '[code]', 'end_tag' => '[/code]'), 'code', array('listitem', 'block', 'inline', 'link'), array()); if ($CONF_FORUM['use_censor']) { $str = COM_checkWords($str); } $str = $bbcode->parse($str); // If we have identified an old post based on the checks above // it is possible that code blocks will have htmlencoded items // we need to reverse that ... if ($oldPost) { if (strstr($str, "\\'") !== false) { $str = stripslashes($str); } $str = str_replace("$", "\$", $str); $str = str_replace("<br />", "\r", $str); $str = str_replace("<br>", "\r", $str); $str = str_replace('&', '&', $str); $str = str_replace(''', '\'', $str); $str = str_replace('"', '"', $str); $str = str_replace('<', '<', $str); $str = str_replace('>', '>', $str); } $str = str_replace('\', '\\', $str); return $str; }
/** * Converts bbcodes in the given text to HTML. Also auto-links URLs. * * @param string $text The text to parse * @return string */ function parse_bbcode($text) { require_once 'stringparser_bbcode/stringparser_bbcode.class.php'; $bbcode = new StringParser_BBCode(); $bbcode->setGlobalCaseSensitive(false); $bbcode->setRootParagraphHandling(true); // Convert all newlines to a common form $bbcode->addFilter(STRINGPARSER_FILTER_PRE, create_function('$a', 'return preg_replace("/\\015\\012|015\\012/", "\\n", $a);')); $bbcode->addParser(array('block', 'inline'), 'format_whitespace'); $bbcode->addParser(array('block', 'inline'), 'autolink_text'); // The bbcodes themselves $bbcode->addCode('b', 'simple_replace', null, array('start_tag' => '<strong>', 'end_tag' => '</strong>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('i', 'simple_replace', null, array('start_tag' => '<em>', 'end_tag' => '</em>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('url', 'usecontent?', 'bbcode_url', array('usecontent_param' => 'default'), 'link', array('listitem', 'block', 'inline'), array('link')); $bbcode->addCode('img', 'usecontent', 'bbcode_img', array(), 'image', array('listitem', 'block', 'inline', 'link'), array()); $text = $bbcode->parse($text); return $text; }
/** * Simplified codes for comments. * * @param string $text * @return strng */ function plugin_bbcode_comment($text) { $bbcode = new StringParser_BBCode(); // If you set it to false the case-sensitive will be ignored for all codes $bbcode->setGlobalCaseSensitive(false); $bbcode->setMixedAttributeTypes(true); $bbcode->addCode('b', 'simple_replace', null, array('start_tag' => '<strong>', 'end_tag' => '</strong>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('strong', 'simple_replace', null, array('start_tag' => '<strong>', 'end_tag' => '</strong>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('i', 'simple_replace', null, array('start_tag' => '<em>', 'end_tag' => '</em>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('em', 'simple_replace', null, array('start_tag' => '<em>', 'end_tag' => '</em>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('ins', 'simple_replace', null, array('start_tag' => '<ins>', 'end_tag' => '</ins>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('u', 'simple_replace', null, array('start_tag' => '<ins>', 'end_tag' => '</ins>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('del', 'simple_replace', null, array('start_tag' => '<del>', 'end_tag' => '</del>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('strike', 'simple_replace', null, array('start_tag' => '<del>', 'end_tag' => '</del>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('blockquote', 'simple_replace', null, array('start_tag' => '<blockquote><p>', 'end_tag' => '</p></blockquote>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('quote', 'simple_replace', null, array('start_tag' => '<blockquote><p>', 'end_tag' => '</p></blockquote>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('pre', 'simple_replace', null, array('start_tag' => '<pre>', 'end_tag' => '</pre>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $bbcode->addCode('code', 'usecontent', 'do_bbcode_code', array(), 'inline', array('listitem', 'block', 'inline', 'link'), array()); return $bbcode->parse($text); }
<?php // Using StringParser_BBCode to parse bbcode require_once $conf['bbcode']['path'] . "/stringparser_bbcode.class.php"; $bbcode = new StringParser_BBCode(); function parsebbcode($text) { global $bbcode; return $bbcode->parse($text); } // parsebbcode // Using GeSHi to highlight code function bbcodehighlight($action, $attributes, $content, $params, &$node_object) { global $conf; if ($action == "validate") { if (!isset($attributes['default']) || isset($attributes['default']) && in_array($attributes['default'], $conf['highlight']['languages'])) { return true; } return false; } //$content = stripslashes($content); if (!isset($attributes['default'])) { $attributes['default'] = "text"; } require_once $conf['highlight']['path'] . "geshi.php"; $geshi =& new GeSHi($content, $attributes['default']); //$attributes['default']); $geshi->set_header_type(GESHI_HEADER_NONE); if ($conf['highlight']['linenumbers']) { $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
return "<span>" . html_encode($content) . "</span>"; } return "<span style=\"color: " . html_encode($attributes["default"]) . "\">" . $content . "</span>"; } } // Function to include images if (!function_exists("do_bbcode_img")) { function do_bbcode_img($action, $attributes, $content, $params, $node_object) { if ($action == "validate") { return true; } return "<img src=\"" . html_encode($content) . "\" alt=\"\" title=\"\" />"; } } $bbcode = new StringParser_BBCode(); $bbcode->addFilter(STRINGPARSER_FILTER_PRE, "convertlinebreaks"); $bbcode->addParser(array("block", "inline", "link", "listitem"), "htmlspecialchars"); $bbcode->addParser(array("block", "inline", "link", "listitem"), "nl2br"); $bbcode->addParser("list", "bbcode_stripcontents"); $bbcode->addCode("quote", "simple_replace", null, array("start_tag" => "<span class=\"quoteStyle\">", "end_tag" => "</span>"), "inline", array("block", "inline"), array()); $bbcode->addCode("code", "simple_replace", null, array("start_tag" => "<span class=\"codeStyle\">", "end_tag" => "</span>"), "inline", array("block", "inline"), array()); $bbcode->addCode("u", "simple_replace", null, array("start_tag" => "<span style=\"text-decoration: underline\">", "end_tag" => "</span>"), "inline", array("listitem", "block", "inline", "link"), array()); $bbcode->addCode("b", "simple_replace", null, array("start_tag" => "<span style=\"font-weight: bold\">", "end_tag" => "</span>"), "inline", array("listitem", "block", "inline", "link"), array()); $bbcode->addCode("i", "simple_replace", null, array("start_tag" => "<span style=\"font-style: oblique\">", "end_tag" => "</span>"), "inline", array("listitem", "block", "inline", "link"), array()); $bbcode->addCode("url", "usecontent?", "do_bbcode_url", array("usecontent_param" => "default"), "link", array("listitem", "block", "inline"), array("link")); $bbcode->addCode("color", "usecontent?", "do_bbcode_color", array("usecontent_param" => "default"), "link", array("listitem", "block", "inline"), array()); $bbcode->addCode("link", "callback_replace_single", "do_bbcode_url", array(), "link", array("listitem", "block", "inline"), array("link")); $bbcode->addCode("img", "usecontent", "do_bbcode_img", array(), "image", array("listitem", "block", "inline", "link"), array()); $bbcode->setOccurrenceType("img", "image"); $bbcode->setMaxOccurrences("image", 10);