/** * Parse BBCode into HTML. * * @param string $data BBCode string to be converted to HTML. * * @return string HTML representation of $data. */ protected static function parse($data) { $bbcodedata = array('b' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<b>', 'close_tag' => '</b>'), 'u' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<u>', 'close_tag' => '</u>'), 'i' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<i>', 'close_tag' => '</i>'), 'list' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<ul>', 'close_tag' => '</ul>', 'childs' => 'li'), 'olist' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<ol>', 'close_tag' => '</ol>', 'childs' => 'li'), 'li' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<li>', 'close_tag' => '</li>', 'parents' => 'list'), 'url' => array('type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<a href="{PARAM}">', 'close_tag' => '</a>', 'default_arg' => '{CONTENT}', 'param_handling' => 'self::cleanUrl'), 'code' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<pre>', 'close_tag' => '</pre>', 'content_handling' => 'self::noBrs'), 'h1' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<h2><u>', 'close_tag' => '</u></h2>'), 'h2' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<h3><u>', 'close_tag' => '</u></h3>'), 'center' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<center>', 'close_tag' => '</center>'), 'img' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<img src="', 'close_tag' => '" />', 'content_handling' => 'self::cleanContentUrl'), 'indexlink' => array('type' => BBCODE_TYPE_ARG, 'open_tag' => '<a href="#{PARAM}">', 'close_tag' => '</a>'), 'index' => array('type' => BBCODE_TYPE_ARG, 'open_tag' => '<a style="padding-top: 50px;" name="{PARAM}">', 'close_tag' => '</a>')); $bbcode = bbcode_create($bbcodedata); $return = "<div align=\"left\">" . str_replace(array('<ul><br />', '</li><br />'), array('<ul>', '</li>'), bbcode_parse($bbcode, nl2br($data))) . "</div>"; return $return; }
/** * {@inheritdoc} */ public function bb2html($text) { $this->handler = bbcode_create($this->tags); $this->addSmiles(); $parsedText = bbcode_parse($this->handler, $text); bbcode_destroy($this->handler); return $parsedText; }
private function __construct() { if (function_exists('bbcode_create')) { $this->bbcode = bbcode_create($this->getTags()); $this->initSmilies(); return; } show_error_msg('Error', 'BBCode not available, you need to run `pecl install bbcode-1.0.3b1`', 1); }
/** * Replace bbcodes if enabled php extension * @param null $str * @return string */ protected function getBBParsed($str = null) { if ($str === null) { $str = $this->description; } if (!extension_loaded('bbcode')) { return $str; } $arrayBBCode = ['' => ['type' => BBCODE_TYPE_ROOT, 'childs' => '!i'], 'b' => ['type' => BBCODE_TYPE_NOARG, 'open_tag' => '<b>', 'close_tag' => '</b>'], 'i' => ['type' => BBCODE_TYPE_NOARG, 'open_tag' => '<i>', 'close_tag' => '</i>', 'childs' => 'b'], 'u' => ['type' => BBCODE_TYPE_NOARG, 'open_tag' => '', 'close_tag' => ''], 's' => ['type' => BBCODE_TYPE_NOARG, 'open_tag' => '', 'close_tag' => ''], 'img' => ['type' => BBCODE_TYPE_NOARG, 'open_tag' => '<img alt="image" src="', 'close_tag' => '" />', 'childs' => ''], 'url' => ['type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<a href="{PARAM}" rel="nofollow">', 'close_tag' => '</a>', 'default_arg' => '{CONTENT}', 'childs' => 'b,i,img'], 'quote' => ['type' => BBCODE_TYPE_NOARG, 'open_tag' => '', 'close_tag' => ''], 'code' => ['type' => BBCODE_TYPE_NOARG, 'open_tag' => '<pre>', 'close_tag' => '</pre>'], 'size' => ['type' => BBCODE_TYPE_OPTARG, 'open_tag' => '', 'close_tag' => '', 'default_arg' => '{CONTENT}', 'childs' => 'b,i'], 'color' => ['type' => BBCODE_TYPE_OPTARG, 'open_tag' => '', 'close_tag' => '', 'default_arg' => '{CONTENT}', 'childs' => 'b,i']]; $BBHandler = bbcode_create($arrayBBCode); return bbcode_parse($BBHandler, $str); }
function discussion_forum_parse_output($text, $options = array()) { // BBcode part $bbcode_ruleset = array('' => array('type' => BBCODE_TYPE_ROOT), 'i' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<i>', 'close_tag' => '</i>'), 'img' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<img src="', 'close_tag' => '" class="forum_post_image" />', 'childs' => ''), 'b' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<b>', 'close_tag' => '</b>'), 'spoiler' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<div class="spoiler"><span>Spoiler: <button class="spoiler_control">Visa</button></span><span class="spoiler_content">', 'close_tag' => '</span></div>', 'childs' => '')); $text = clickable_links($text); if (isset($options['search_highlight'])) { $options['search_highlight'] = is_array($options['search_highlight']) ? $options['search_highlight'] : explode(' ', $options['search_highlight']); $safe_wordlist = array_map('preg_quote', $options['search_highlight']); $pattern = '/(' . str_replace('/', '\\/', implode('|', $safe_wordlist)) . ')/'; echo $pattern . "\n"; $replacement = '<strong class="search_highlight">$1</strong>'; $text = preg_replace($pattern, $replacement, $text); } $text = nl2br($text); $text = str_replace(array("\n", "\r"), '', $text); $bbcode_handler = bbcode_create($bbcode_ruleset); $text = bbcode_parse($bbcode_handler, $text); $pattern = '/\\[svar:(.+?):([0-9]+?)\\](.*?)(\\[\\/svar\\])/'; $replacement = '<div class="answer" id="forum_answer_to_$2"><strong>Svar till <a href="/traffa/quicksearch.php?username=$1">$1</a></strong> [<a href="/diskussionsforum/gaa_till_post.php?post_id=$2">Gå till post</a>]: $3</div>'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[svar:(.+?)\\](.+?)(\\[\\/svar\\])/'; $replacement = '<div class="answer"><a href="?$1">$1</a>: $2</div>'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[poll:(.+?)\\]/'; $text = preg_replace_callback($pattern, 'discussion_forum_insert_poll', $text); $pattern = '/\\@(.+?)\\@/'; $replacement = '<span class="forum_answer" id="$1">Svar till $1</span>'; $text = preg_replace($pattern, $replacement, $text); $pattern = '/\\[tillagg:(.+?):(.+?)\\](.*?)(\\[\\/tillagg\\])/'; $replacement = '<div class="answer" id="forum_answer_to_$2">Tilläg av <a href="/traffa/quicksearch.php?username=$1">$1</a> klockan $2<br />$3</div>'; $text = preg_replace_callback($pattern, 'discussion_forum_tillagg_callback', $text); $code_languages = array('php', 'html', 'javascript', 'css', 'C#', 'asp', 'joar'); // Note: The pattern modifier /i makes the pattern case-insensitive. $pattern = '/\\[code:(' . implode('|', $code_languages) . ')\\](.*?)(\\[\\/code\\])/i'; $text = preg_replace_callback($pattern, 'discussion_forum_code_tag_callback', $text); // Note: See above for explanation on /i, /e evaluates (an escaped version) of the search string. $pattern = '/\\[code\\](.*?)\\[\\/code\\]/ie'; //$text = preg_replace($pattern, 'discussion_forum_code_tag_callback(array(1 => "", 2 => "$1"))', $text); // $text = ($_SESSION['preferences']['forum_enable_smilies'] == 1) ? setSmilies($text) : $text; if (isset($options['post']['quality_level']) && $options['post']['quality_level'] <= 3 && $_SESSION['preferences']['forum_enable_smilies'] == 1) { $text = setSmilies($text); } return $text; }
function profile_presentation_parse($options) { if (!isset($options['presentation_text'])) { return 'Presentation data does not exist.'; } $bbcode_ruleset = array('' => array('type' => BBCODE_TYPE_ROOT), 'i' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<i>', 'close_tag' => '</i>'), 'b' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<strong>', 'close_tag' => '</strong>'), 'rubrik' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<h2>', 'close_tag' => '</h2>', 'childs' => ''), 'underrubrik' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<h3>', 'close_tag' => '</h3>', 'childs' => ''), 'minirubrik' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<h4>', 'close_tag' => '</h4>', 'childs' => '')); //$options['presentation_text'] = clickable_links($options['presentation_text']); $options['presentation_text'] = nl2br($options['presentation_text']); $options['presentation_text'] = str_replace(array("\n", "\r"), '', $options['presentation_text']); $bbcode_handler = bbcode_create($bbcode_ruleset); $options['presentation_text'] = bbcode_parse($bbcode_handler, $options['presentation_text']); $pattern = '/\\[poll:(.+?)\\]/'; $options['presentation_text'] = preg_replace_callback($pattern, 'profile_presentation_poll_tag_callback', $options['presentation_text']); $options['presentation_text'] = setSmilies($options['presentation_text']); //$options['presentation_text'] = profile_presentation_friends_tag_callback($options); $pattern = '/\\[link:(profile\\]([a-zA-Z0-9_-]+)|webb\\](.+?))\\[\\/link\\]/'; $options['presentation_text'] = preg_replace_callback($pattern, 'profile_presentation_link_tag_callback', $options['presentation_text']); $pattern = '/\\[link:(photos|guestbook)\\]/'; $options['presentation_text'] = preg_replace_callback($pattern, 'profile_presentation_link_tag_callback', $options['presentation_text']); $pattern = '/\\[fotoalbum:([0-9]+)\\]/'; $options['presentation_text'] = str_replace('%USERID%', $options['user_id'], preg_replace_callback($pattern, 'profile_presentation_photos_callback', $options['presentation_text'])); $output .= '<div class="profile_presentation_text">'; $output .= $options['presentation_text']; $output .= '</div>'; return $output; }
public static function micsText($text, $mode = 'format') { // init and configure BBcode engine if (!isset($GLOBALS['bbcodeEngine'])) { function bbcode_clean_list($text) { return preg_replace("/[\r\n]/", '', $text); } $GLOBALS['bbcodeEngine'] = bbcode_create(array('' => array('type' => BBCODE_TYPE_ROOT, 'childs' => '!*'), 'h2' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<h2>', 'close_tag' => '</h2>'), 'h3' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<h3>', 'close_tag' => '</h3>'), 'h4' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<h4>', 'close_tag' => '</h4>'), 'h5' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<h5>', 'close_tag' => '</h5>'), 'h6' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<h6>', 'close_tag' => '</h6>'), 'i' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<i>', 'close_tag' => '</i>'), 'cite' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<cite>', 'close_tag' => '</cite>'), 'b' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<b>', 'close_tag' => '</b>'), 'u' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<u>', 'close_tag' => '</u>'), 's' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<s>', 'close_tag' => '</s>'), 'small' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<small>', 'close_tag' => '</small>'), 'quote' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<blockquote>', 'close_tag' => '</blockquote>'), 'sig' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<div class="sig">', 'close_tag' => '</div>'), 'url' => array('type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<a href="{PARAM}" target="_blank">', 'close_tag' => '</a>', 'default_arg' => '{CONTENT}', 'childs' => 'b,i'), 'img' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<img src="', 'close_tag' => '" />', 'childs' => ''), 'list' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<ul>', 'close_tag' => '</ul>', 'childs' => '*', 'content_handling' => 'bbcode_clean_list'), '*' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<li>', 'close_tag' => '</li>', 'parent' => 'list', 'flags' => BBCODE_FLAGS_ONE_OPEN_PER_LEVEL), 'l' => array('type' => BBCODE_TYPE_SINGLE, 'open_tag' => '['), 'r' => array('type' => BBCODE_TYPE_SINGLE, 'open_tag' => ']'))); } if ($mode == 'strip') { return preg_replace('/\\[[^\\[]+\\]/', '', htmlspecialchars($text)); } else { // block elements $blockEls = 'h[1-6]|ul'; // encode and parse bbcode $text = @bbcode_parse($GLOBALS['bbcodeEngine'], htmlspecialchars($text)); // pad block elements with double newlines to break paragraphs $text = preg_replace('/\\s*<(' . $blockEls . ')>(.*?)<\\/\\1>\\s*/i', "\n\n<\$1>\$2</\$1>\n\n", $text); // trim ends $text = trim($text); // replace 4+ dashes with <hr> $text = preg_replace('/-{4,}/i', '<hr />', $text); // turn 2+ newlines into paragraphs $text = '<p>' . preg_replace('/\\s*\\n\\s*\\n\\s*/', '</p><p>', $text) . '</p>'; // remove paragraphs and newlines wrapping block-level elements $text = preg_replace('/\\s*<p>\\s*<(' . $blockEls . ')>(.*?)<\\/\\1>\\s*<\\/p>\\s*/i', '<$1>$2</$1>', $text); // simple character replacements $text = str_replace(array('--', '(r)', '(tm)', '(c)'), array('—', '®', '™', '©'), $text); // ordinals $text = preg_replace('/(\\d+)(st|nd|rd|th|st)\\b/i', '$1<sup>$2</sup>', $text); // turn remaining single newlines into brs $text = nl2br($text); return $text; } }
'i'=> array('type'=>BBCODE_TYPE_NOARG, 'open_tag'=>'<i>', 'close_tag'=>'</i>', 'childs'=>'b'), 'url'=> array('type'=>BBCODE_TYPE_OPTARG, 'open_tag'=>'<a href="{PARAM}">', 'close_tag'=>'</a>', 'default_arg'=>'{CONTENT}', 'childs'=>'b,i'), 'img'=> array('type'=>BBCODE_TYPE_NOARG, 'open_tag'=>'<img src="', 'close_tag'=>'" />', 'childs'=>''), 'b'=> array('type'=>BBCODE_TYPE_NOARG, 'open_tag'=>'<b>', 'close_tag'=>'</b>'), 'br'=> array('type'=>BBCODE_TYPE_NOARG, 'open_tag'=>'<br>', 'close_tag'=>''), ); $BBHandler=bbcode_create($arrayBBCode); $comment = strip_tags($comment, ""); $comment = bbcode_parse($BBHandler,$comment); $xxx = "INSERT INTO `homepage` (text,postid) VALUES ('$comment','$_POST[id]')"; $result = mysql_query($xxx); if (!$result) { die('Invalid query'); } echo "Comment Submitted. Redirecting in 1..."; echo "<meta http-equiv=\"refresh\" content=\"1;url=http://cryptum.net/post_view.php?id=".$_POST[id].'"'.">"; }
function bbcode_kotoba_mark($text, $board) { static $arrayBBCode = array('i' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<i>', 'close_tag' => '</i>', 'childs' => 'b,s,u'), 'b' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<b>', 'close_tag' => '</b>', 'childs' => 'i,s,u'), 'code' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<pre>', 'close_tag' => '</pre>'), 'spoiler' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<span class="spoiler" style="color: black;" onmouseover="this.style.color=\'white\';" onmouseout="this.style.color=\'black\'">', 'close_tag' => '</span>'), 's' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<s>', 'close_tag' => '</s>', 'childs' => 'b,i'), 'u' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<u>', 'close_tag' => '</u>', 'childs' => 'b,i'), 'ul' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<ul>', 'close_tag' => '</ul>', 'childs' => 'li'), 'ol' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<ol>', 'close_tag' => '</ol>', 'childs' => 'li'), 'li' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<li>', 'close_tag' => '</li>', 'childs' => 'i,b,s,u,spoiler'), 'url' => array('type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<a href="{PARAM}">', 'close_tag' => '</a>', 'default_arg' => '{CONTENT}'), 'google' => array('type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<a href="http://www.google.ru/search?q={PARAM}">', 'close_tag' => '</a>', 'content_handling' => 'google_content_handler', 'param_handling' => 'param_handler'), 'wiki' => array('type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<a href="http://ru.wikipedia.org/wiki/{PARAM}">', 'close_tag' => '</a>', 'content_handling' => 'wiki_content_handler', 'param_handling' => 'param_handler'), 'quote' => array('type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<span style="color:green;">', 'close_tag' => '</span>'), 'lurl' => array('type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<a {PARAM}>', 'close_tag' => '</a>', 'content_handling' => 'lurl_content_handler', 'param_handling' => 'lurl_param_handler'), 'gurl' => array('type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<a {PARAM}>', 'close_tag' => '</a>', 'content_handling' => 'gurl_content_handler', 'param_handling' => 'gurl_param_handler')); static $BBHandler = NULL; if ($BBHandler == NULL) { $BBHandler = bbcode_create($arrayBBCode); } $text = preg_replace('/>>>\\/(\\w+?)\\/(\\d+)/', '[gurl=$1/$2]/$1/$2[/gurl]', $text); $text = preg_replace('/>>(\\d+)/', "[lurl={$board}/\$1]\$1[/lurl]", $text); $text = preg_replace('/(>.+)/', '[quote]$1[/quote]', $text); return bbcode_parse($BBHandler, $text); }
/** * Performs the ::toHtml() processing using the BBCode extension * @param string $string * @return string * @access protected */ protected function _toHtmlExtension($string = '') { return bbcode_parse(bbcode_create(), $string); }
private static function initialize(&$bb_code) { $bb = array('' => array('type' => BBCODE_TYPE_ROOT), 'code' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<span class="code">', 'close_tag' => '</span>'), 'b' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<b>', 'close_tag' => '</b>'), 'i' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<i>', 'close_tag' => '</i>'), 'url' => array('type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<a href="{PARAM}">', 'close_tag' => '</a>'), 'color' => array('type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<span style="color:{PARAM};">', 'close_tag' => '</span>'), 'img' => array('type' => BBCODE_TYPE_OPTARG, 'open_tag' => '<img class="floating_image" src="{PARAM}">', 'close_tag' => '</img>'), 'cursor' => array('type' => BBCODE_TYPE_NOARG, 'open_tag' => '<span class="blinking">', 'close_tag' => '</span>')); $bb_code = bbcode_create($bb); }