コード例 #1
0
function format_comment($text, $strip_html = true)
{
    global $smilies;
    $s = $text;
    unset($text);
    $s = str_replace(";)", ":wink:", $s);
    if ($strip_html) {
        $s = htmlentities($s, ENT_QUOTES, 'UTF-8');
    }
    $f = @fopen("badwords.txt", "r");
    if ($f && filesize("badwords.txt") != 0) {
        $bw = fread($f, filesize("badwords.txt"));
        $badwords = explode("\n", $bw);
        for ($i = 0; $i < count($badwords); ++$i) {
            $badwords[$i] = trim($badwords[$i]);
        }
        $s = str_replace($badwords, "*Censored*", $s);
    }
    @fclose($f);
    if (preg_match("#function\\s*\\((.*?)\\|\\|#is", $s)) {
        $s = str_replace(":", "&#58;", $s);
        $s = str_replace("[", "&#91;", $s);
        $s = str_replace("]", "&#93;", $s);
        $s = str_replace(")", "&#41;", $s);
        $s = str_replace("(", "&#40;", $s);
        $s = str_replace("{", "&#123;", $s);
        $s = str_replace("}", "&#125;", $s);
        $s = str_replace("\$", "&#36;", $s);
    }
    //-- [*] --//
    if (utf8::stripos($s, '[*]') !== false) {
        $s = preg_replace("/\\[\\*\\]/", "<img src=\"images/list.gif\" alt=\"List\" title=\"List\" class=\"listitem\" />", $s);
    }
    //-- [b]Bold[/b] --//
    if (utf8::stripos($s, '[b]') !== false) {
        $s = preg_replace('/\\[b\\](.+?)\\[\\/b\\]/is', "<span style='font-weight:bold;'>\\1</span>", $s);
    }
    //-- [i]Italic[/i] --//
    if (utf8::stripos($s, '[i]') !== false) {
        $s = preg_replace('/\\[i\\](.+?)\\[\\/i\\]/is', "<span style='font-style: italic;'>\\1</span>", $s);
    }
    //-- [u]Underline[/u] --//
    if (utf8::stripos($s, '[u]') !== false) {
        $s = preg_replace('/\\[u\\](.+?)\\[\\/u\\]/is', "<span style='text-decoration:underline;'>\\1</span>", $s);
    }
    //-- [color=blue]Text[/color] --//
    if (utf8::stripos($s, '[color=') !== false) {
        $s = preg_replace('/\\[color=([a-zA-Z]+)\\](.+?)\\[\\/color\\]/is', '<span style="color: \\1">\\2</span>', $s);
        //-- [color=#ffcc99]Text[/color] --//
        $s = preg_replace('/\\[color=(#[a-f0-9]{6})\\](.+?)\\[\\/color\\]/is', '<span style="color: \\1">\\2</span>', $s);
    }
    //-- Media Tag --//
    if (utf8::stripos($s, '[media=') !== false) {
        $s = preg_replace("#\\[media=(youtube|liveleak|GameTrailers|imdb)\\](.+?)\\[/media\\]#ies", "_MediaTag('\\2','\\1')", $s);
        $s = preg_replace("#\\[media=(youtube|liveleak|GameTrailers|vimeo)\\](.+?)\\[/media\\]#ies", "_MediaTag('\\2','\\1')", $s);
    }
    //-- Img Using Lightbox --//
    //-- [img=http://www/image.gif] --//
    if (utf8::stripos($s, '[img') !== false) {
        $s = preg_replace("/\\[img\\]((http|https):\\/\\/[^\\s'\"<>]+(\\.(jpg|gif|png|bmp|jpeg)))\\[\\/img\\]/i", "<img src=\"\\1\" alt=\"\" />", $s);
        $s = preg_replace("/\\[img=((http|https):\\/\\/[^\\s'\"<>]+(\\.(gif|jpg|png|bmp|jpeg)))\\]/i", "<img src=\"\\1\" alt=\"\" />", $s);
    }
    //-- [size=4]Text[/size] --//
    if (utf8::stripos($s, '[size=') !== false) {
        $s = preg_replace("/\\[size=([1-7])\\]((\\s|.)+?)\\[\\/size\\]/i", "<font size=\\1>\\2</font>", $s);
    }
    //-- [font=Arial]Text[/font] --//
    if (utf8::stripos($s, '[face=') !== false) {
        $s = preg_replace('/\\[face=([a-zA-Z ,]+)\\](.+?)\\[\\/face\\]/is', '<span style="font-family: \\1">\\2</span>', $s);
    }
    //-- [s]Stroke[/s] --//
    if (utf8::stripos($s, '[s]') !== false) {
        $s = preg_replace("/\\[s\\](.+?)\\[\\/s\\]/is", "<s>\\1</s>", $s);
    }
    //-- Dynamic Vars --//
    //-- [Spoiler]TEXT[/Spoiler] --//
    if (utf8::stripos($s, '[spoiler]') !== false) {
        $s = preg_replace("/\\[spoiler\\](.+?)\\[\\/spoiler\\]/is", "<div class=\"smallfont\" align=\"left\"><input type=\"button\" value=\"Show\" style=\"width:75px;font-size:10px;margin:0px;padding:0px;\" onclick=\"if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') {this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = '';this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }\" /><div style=\"margin: 10px; padding: 10px; border: 1px inset;\" align=\"left\"><div style=\"display: none;\">\\1</div></div></div>", $s);
    }
    //-- [mcom]Text[/mcom] --//
    if (utf8::stripos($s, '[mcom]') !== false) {
        $s = preg_replace("/\\[mcom\\](.+?)\\[\\/mcom\\]/is", "<div style=\"font-size: 18pt; line-height: 50%;\"><div style=\"border-color: red; background-color: red; color: white; text-align: center; font-weight: bold; font-size: large;\"><strong>\\1</strong></div></div>", $s);
    }
    //-- The [you] Tag --//
    if (utf8::stripos($s, '[you]') !== false) {
        $s = preg_replace("/\\[you\\]/i", user::$current['username'], $s);
    }
    //-- [mail]Mail[/mail] --//
    if (stripos($s, '[mail]') !== false) {
        $s = preg_replace("/\\[mail\\](.+?)\\[\\/mail\\]/is", "<a href=\"mailto:\\1\" target=\"_blank\">\\1</a>", $s);
    }
    //--[Align=(center|left|right|justify)]Text[/align] --//
    if (utf8::stripos($s, '[align=') !== false) {
        $s = preg_replace("/\\[align=([a-zA-Z]+)\\](.+?)\\[\\/align\\]/is", "<div style=\"text-align:\\1\">\\2</div>", $s);
    }
    //-- Quotes --//
    $s = format_quotes($s);
    //-- URLs --//
    $s = format_urls($s);
    if (utf8::stripos($s, '[url') !== false) {
        //-- [url=http://www.example.com]Text[/url] --//
        $s = preg_replace("/\\[url=([^()<>\\s]+?)\\]((\\s|.)+?)\\[\\/url\\]/i", "<a target=_blank href=redir.php?url=\\1>\\2</a>", $s);
        //-- [url]http://www.example.com[/url] --//
        $s = preg_replace("/\\[url\\]([^()<>\\s]+?)\\[\\/url\\]/i", "<a target=_blank href=redir.php?url=\\1>\\1</a>", $s);
    }
    //-- Linebreaks --//
    $s = nl2br($s);
    //-- [pre]Preformatted[/pre] --//
    if (utf8::stripos($s, '[pre]') !== false) {
        $s = preg_replace("/\\[pre\\](.+?)\\[\\/pre\\]/is", "<tt><span style=\"white-space: nowrap;\">\\1</span></tt>", $s);
    }
    //-- [nfo]NFO-preformatted[/nfo] --//
    if (utf8::stripos($s, '[nfo]') !== false) {
        $s = preg_replace("/\\[nfo\\](.+?)\\[\\/nfo\\]/i", "<tt><span style=\"white-space: nowrap;\"><font face='MS Linedraw' size='2' style='font-size: 10pt; line-height: " . "10pt'>\\1</font></span></tt>", $s);
    }
    //-- Maintain Spacing --//
    $s = str_replace(utf8::NBSP, ' ', $s);
    $s = str_replace(' ', ' ' . utf8::NBSP, $s);
    reset($smilies);
    while (list($code, $url) = each($smilies)) {
        $s = str_replace($code, "<img src='images/smilies/{$url}' border='0' alt='" . security::html_safe($code) . "' title='" . security::html_safe($code) . "' />", $s);
    }
    return $s;
}