private function _parseBB($text, $type = 'pm')
 {
     include_once DIR . '/includes/class_dle_parse.php';
     $parse = new DLE_ParseFilter();
     $parse->safe_mode = true;
     //        $parse->allow_url = false;
     //        $parse->allow_image = false;
     $bbparser = new vB_BbCodeParser($this->vbulletin, fetch_tag_list());
     $this->_fetch_home_url();
     $text = $bbparser->parse_smilies($text);
     $text = preg_replace('#<img .*?src=[\'"]([^h].+?)[\'"] .*?/>#si', "[img]{$this->vbulletin->basepath}\\1[/img]", $text);
     $text = $parse->process($text);
     if ($type == 'pm') {
         $quote = 'Цитата';
         if (strtolower($this->vbulletin->userinfo['lang_charset']) != 'utf-8') {
             $quote = iconv('utf-8', $this->vbulletin->userinfo['lang_charset'], $quote);
         }
         $text = preg_replace('#\\[QUOTE\\]#si', "<!--QuoteBegin--><div class=\"quote\"><!--QuoteEBegin-->", $text);
         $text = preg_replace('#\\[quote=(.+?)\\]#si', "<!--QuoteBegin \\1 --><div class=\"title_quote\">{$quote}: \\1</div><div class=\"quote\"><!--QuoteEBegin-->", $text);
         $text = preg_replace('#\\[/quote\\]#si', "<!--QuoteEnd--></div><!--QuoteEEnd-->", $text);
         $text = preg_replace('#\\[post\\]([0-9]+)\\[/post\\]#si', "<a href='" . $this->vbulletin->basepath . "showthread.php?p=\\1#post\\1'>" . $this->vbulletin->basepath . "showthread.php?p=\\1</a>", $text);
     } else {
         if ($type == 'signature') {
             $text = strip_tags($text);
             if ($this->vbulletin->options['usefileavatar']) {
                 $sigpic_url = $this->vbulletin->options['sigpicurl'] . '/sigpic' . $this->vbulletin->userinfo['userid'] . '_' . $this->vbulletin->userinfo['sigpicrevision'] . '.gif';
             } else {
                 $sigpic_url = 'image.php?u=' . $this->vbulletin->userinfo['userid'] . "&amp;type=sigpic&amp;dateline=" . $userinfo_sigpic['sigpicdateline'];
             }
             $text = preg_replace('#\\[SIGPIC\\]\\[/SIGPIC\\]#si', "[img]{$this->vbulletin->basepath}{$sigpic_url}[/img]", $text);
             $text = preg_replace('#\\[SIGPIC\\](.+?)\\[/SIGPIC\\]#si', "[img=|\\1]{$this->vbulletin->basepath}{$sigpic_url}[/img]", $text);
         }
     }
     $text = preg_replace("#\\[size=&quot;([^&]+)&quot;\\]#is", "[size=\\1]", $text);
     $text = preg_replace("#\\[font=&quot;([^&]+)&quot;\\]#is", "[font=\\1]", $text);
     $text = $parse->BB_Parse($text, false);
     //        $text = preg_replace('#\[.+?\]#si', "", $text);
     return $text;
 }
示例#2
0
文件: utils.php 项目: 0hyeah/yurivn
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);
}