コード例 #1
0
ファイル: nbbcode.php プロジェクト: cbsistem/nexos
 protected static function split_on_bbcodes($text, $allowed = 0, $allow_html = false)
 {
     global $bb_codes;
     # Split all bbcodes.
     $text_parts = BBCode::split_bbcodes($text);
     # Merge all bbcodes and do special actions depending on the type of code.
     $text = '';
     while ($part = array_shift($text_parts)) {
         if ($part['code'] == 'php') {
             # [PHP]
             $text .= $allowed ? BBCode::decode_php($part['text']) : nl2br(htmlspecialchars($part['text']));
         } elseif ($part['code'] == 'code') {
             # [CODE]
             if (!$allowed && false !== strpos($part['text'], '<')) {
                 $part['text'] = nl2br(htmlspecialchars($part['text']));
             }
             $text .= $allowed ? BBCode::decode_code($part['text']) : $part['text'];
         } elseif ($part['code'] == 'quote') {
             # [QUOTE] and [QUOTE=""]
             if ($part['text'][6] == ']') {
                 $text .= $bb_codes['quote'] . BBCode::split_on_bbcodes(substr($part['text'], 7, -8), $allowed, $allow_html) . $bb_codes['quote_close'];
             } else {
                 $part['text'] = preg_replace('/\\[quote=["]*(.*?)["]*\\]/si', $bb_codes['quote_name'], BBCode::split_on_bbcodes(substr($part['text'], 0, -8), $allowed, $allow_html), 1);
                 $text .= $part['text'] . $bb_codes['quote_close'];
             }
         } elseif ($part['subc']) {
             $tmptext = '[' . BBCode::split_on_bbcodes(substr($part['text'], 1, -1)) . ']';
             $text .= $part['code'] == 'list' ? BBCode::decode_list($tmptext) : $tmptext;
             unset($tmptext);
         } else {
             if ($allow_html) {
                 $tmptext = false === strpos($part['text'], '<') ? nl2br($part['text']) : $part['text'];
             } else {
                 $tmptext = nl2br(BBCode::encode_html($part['text']));
             }
             $text .= $part['code'] == 'list' ? BBCode::decode_list($tmptext) : $tmptext;
             unset($tmptext);
         }
     }
     return $text;
 }