Example #1
0
function ParseMessage($strMessage, $bDisableSmilies, $bDisableCodes = FALSE)
{
    global $CFG, $aSmilies;
    // Are smilies disabled here?
    if (!$bDisableSmilies) {
        // Parse the smilies.
        foreach ($aSmilies as $iSmilieID => $aSmilie) {
            $strMessage = str_replace($aSmilie['code'], "[smilie={$iSmilieID}]", $strMessage);
        }
    }
    // Make the message safe to display.
    $strMessage = htmlsanitize($strMessage);
    // Take care of the newlines.
    $strMessage = str_replace("\r\n", '<br />', $strMessage);
    $strMessage = str_replace("\n", '<br />', $strMessage);
    $strMessage = str_replace("\r", '<br />', $strMessage);
    // Parse the BB codes.
    if (!$bDisableCodes) {
        $strMessage = ParseTag('/\\[b\\](.+?)\\[\\/b\\]/is', '<b>$1</b>', $strMessage);
        $strMessage = ParseTag('/\\[i\\](.+?)\\[\\/i\\]/is', '<i>$1</i>', $strMessage);
        $strMessage = ParseTag('/\\[u\\](.+?)\\[\\/u\\]/is', '<u>$1</u>', $strMessage);
        $strMessage = ParseTag('/\\[sup\\](.+?)\\[\\/sup\\]/i', '<sup>$1</sup>', $strMessage);
        $strMessage = ParseTag('/\\[sub\\](.+?)\\[\\/sub\\]/i', '<sub>$1</sub>', $strMessage);
        $strMessage = ParseTag('/\\[size=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/size\\]/is', '<font size="$3">$5</font>', $strMessage);
        $strMessage = ParseTag('/\\[font=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/font\\]/is', '<span style="font-family: $3;">$5</span>', $strMessage);
        $strMessage = ParseTag('/\\[color=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/color\\]/is', '<span style="color: $3;">$5</span>', $strMessage);
        $strMessage = preg_replace('/\\[url\\](.+?)\\[\\/url\\]/i', '<a href="$1" target="_blank">$1</a>', $strMessage);
        $strMessage = preg_replace('/\\[url=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/url\\]/i', '<a href="$3" target="_blank">$5</a>', $strMessage);
        $strMessage = preg_replace('/\\[thread=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/thread\\]/i', '<a href="thread.php?threadid=$3">$5</a>', $strMessage);
        $strMessage = preg_replace('/\\[email\\](.+?)\\[\\/email\\]/i', '<a href="mailto:$1">$1</a>', $strMessage);
        $strMessage = preg_replace('/\\[email=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/email\\]/i', '<a href="mailto:$3">$5</a>', $strMessage);
        $strMessage = preg_replace('/\\[code\\](.+?)\\[\\/code\\]/eis', 'ProcessCode(\'$1\')', $strMessage);
        $strMessage = preg_replace('/\\[php\\](.+?)\\[\\/php\\]/eis', 'HighlightPHP(\'$1\')', $strMessage);
        $strMessage = preg_replace('/\\[list\\](.+?)\\[\\/list\\]/eis', 'ProcessList(\'$1\')', $strMessage);
        $strMessage = preg_replace('/\\[list=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/list\\]/eis', 'ProcessList(\'$5\', \'$3\')', $strMessage);
        $strMessage = ParseTag('/\\[quote\\](.+?)\\[\\/quote\\]/is', '<blockquote><small>quote:</small><hr /><div class="quote"><div style="float: left;">$1</div></div><hr /></blockquote>', $strMessage);
        $strMessage = ParseTag('/\\[quote=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/quote\\]/is', '<blockquote><small>quote:</small><hr /><div class="quote"><div style="float: left;"><i>Originally posted by $3</i><br /><b>$5</b></div></div><hr /></blockquote>', $strMessage);
        $strMessage = preg_replace('/\\[dt=(.+?)\\]/ei', 'ReplaceTime(\'$1\')', $strMessage);
        if ($CFG['parsing']['showimages']) {
            $strMessage = preg_replace('/\\[img\\](.+?)\\[\\/img\\]/i', '<img src="$1" alt="" border="0" />', $strMessage);
        } else {
            $strMessage = preg_replace('/\\[img\\](.+?)\\[\\/img\\]/i', '<a href="$1" target="_blank">$1</a>', $strMessage);
        }
    }
    // Parse the smilies.
    if (!$bDisableSmilies) {
        foreach ($aSmilies as $iSmilieID => $aSmilie) {
            $strMessage = str_replace("[smilie={$iSmilieID}]", "<img src=\"{$CFG['paths']['smilies']}{$aSmilie['filename']}\" style=\"vertical-align: middle;\" alt=\"\" />", $strMessage);
        }
    }
    // Censor bad words.
    $strMessage = Censor($strMessage);
    return $strMessage;
}
Example #2
0
function ParseTags($tags)
{
    $result = array();
    $tags = trim($tags);
    if ($tags !== '') {
        if ($tags[0] !== '@') {
            throw new Exception('A tag block started with text instead of an actual tag, this makes the tag block invalid: ' . $tags);
        }
        foreach (explode("\n", $tags) as $tag_line) {
            if (isset($tag_line[0]) && $tag_line[0] === '@') {
                $result[] = $tag_line;
            } else {
                $result[count($result) - 1] .= "\n" . $tag_line;
            }
        }
        foreach ($result as $key => $tag_line) {
            if (preg_match('/^@([\\w\\-\\_\\\\]+)(?:\\s*([^\\s].*)|$)?/us', trim($tag_line), $Matches) !== 1) {
                throw new Exception('Invalid tag_line detected: ' . $tag_line);
            }
            $result[$key] = ParseTag($Matches);
        }
    }
    return $result;
}
Example #3
0
File: search.php Project: OvBB/v1.0
function RemoveBBCode($strText)
{
    $strText = ParseTag('/\\[b\\](.+?)\\[\\/b\\]/is', '$1', $strText);
    $strText = ParseTag('/\\[i\\](.+?)\\[\\/i\\]/is', '$1', $strText);
    $strText = ParseTag('/\\[u\\](.+?)\\[\\/u\\]/is', '$1', $strText);
    $strText = ParseTag('/\\[size=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/size\\]/is', '$5', $strText);
    $strText = ParseTag('/\\[font=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/font\\]/is', '$5', $strText);
    $strText = ParseTag('/\\[color=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/color\\]/is', '$5', $strText);
    $strText = preg_replace('/\\[url\\](.+?)\\[\\/url\\]/i', '$1', $strText);
    $strText = preg_replace('/\\[url=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/url\\]/i', '$5', $strText);
    $strText = preg_replace('/\\[thread=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/thread\\]/i', '$5', $strText);
    $strText = preg_replace('/\\[email\\](.+?)\\[\\/email\\]/i', '$1', $strText);
    $strText = preg_replace('/\\[email=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/email\\]/i', '$5', $strText);
    $strText = preg_replace('/\\[code\\](.+?)\\[\\/code\\]/is', '$1', $strText);
    $strText = preg_replace('/\\[php\\](.+?)\\[\\/php\\]/is', '$1', $strText);
    $strText = preg_replace('/\\[list\\](.+?)\\[\\/list\\]/is', '$1', $strText);
    $strText = preg_replace('/\\[list=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/list\\]/is', '$5', $strText);
    $strText = ParseTag('/\\[quote\\](.+?)\\[\\/quote\\]/is', '$1', $strText);
    $strText = ParseTag('/\\[quote=((&quot;)?)(.+?)(\\1)\\](.+?)\\[\\/quote\\]/is', '$5', $strText);
    $strText = preg_replace('/\\[img\\](.+?)\\[\\/img\\]/i', '$1', $strText);
    return $strText;
}