コード例 #1
0
function format_comment($text, $strip_html = true, $urls = true, $images = true)
{
    global $smilies, $staff_smilies, $customsmilies, $INSTALLER09, $CURUSER;
    $s = $text;
    unset($text);
    $s = validate_imgs($s);
    $INSTALLER09['url'] = str_replace(array('http://', 'www', 'http://www', 'https://', 'https://www'), '', $INSTALLER09['baseurl']);
    if (isset($_SERVER['HTTPS']) && (bool) $_SERVER['HTTPS'] == true) {
        $s = preg_replace('/http:\\/\\/((?:www\\.)?' . $INSTALLER09['url'] . ')/i', 'https://$1', $s);
    } else {
        $s = preg_replace('/https:\\/\\/((?:www\\.)?' . $INSTALLER09['url'] . ')/i', 'http://$1', $s);
    }
    // This fixes the extraneous ;) smilies problem. When there was an html escaped
    // char before a closing bracket - like >), "), ... - this would be encoded
    // to &xxx;), hence all the extra smilies. I created a new :wink: label, removed
    // the ;) one, and replace all genuine ;) by :wink: before escaping the body.
    // (What took us so long? :blush:)- wyz
    $s = str_replace(';)', ':wink:', $s);
    // fix messed up links
    $s = str_replace('&', '&', $s);
    if ($strip_html) {
        $s = htmlsafechars($s, ENT_QUOTES, charset());
    }
    if (preg_match("#function\\s*\\((.*?)\\|\\|#is", $s)) {
        $s = str_replace(":", ":", $s);
        $s = str_replace("[", "[", $s);
        $s = str_replace("]", "]", $s);
        $s = str_replace(")", ")", $s);
        $s = str_replace("(", "(", $s);
        $s = str_replace("{", "{", $s);
        $s = str_replace("}", "}", $s);
        $s = str_replace("\$", "$", $s);
    }
    // BBCode to find...
    $bb_code_in = array('/\\[b\\]\\s*((\\s|.)+?)\\s*\\[\\/b\\]/i', '/\\[i\\]\\s*((\\s|.)+?)\\s*\\[\\/i\\]/i', '/\\[u\\]\\s*((\\s|.)+?)\\s*\\[\\/u\\]/i', '/\\[email\\](.*?)\\[\\/email\\]/i', '/\\[align=([a-zA-Z]+)\\]((\\s|.)+?)\\[\\/align\\]/i', '/\\[blockquote\\]\\s*((\\s|.)+?)\\s*\\[\\/blockquote\\]/i', '/\\[strike\\]\\s*((\\s|.)+?)\\s*\\[\\/strike\\]/i', '/\\[s\\]\\s*((\\s|.)+?)\\s*\\[\\/s\\]/i', '/\\[pre\\]\\s*((\\s|.)+?)\\s*\\[\\/pre\\]/i', '/\\[marquee\\](.*?)\\[\\/marquee\\]/i', '/\\[collapse=(.*?)\\]\\s*((\\s|.)+?)\\s*\\[\\/collapse\\]/i', '/\\[size=([1-7])\\]\\s*((\\s|.)+?)\\s*\\[\\/size\\]/i', '/\\[color=([a-zA-Z]+)\\]\\s*((\\s|.)+?)\\s*\\[\\/color\\]/i', '/\\[color=(#[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9])\\]\\s*((\\s|.)+?)\\s*\\[\\/color\\]/i', '/\\[font=([a-zA-Z ,]+)\\]((\\s|.)+?)\\[\\/font\\]/i', '/\\[spoiler\\]\\s*((\\s|.)+?)\\s*\\[\\/spoiler\\]/i', '/\\[video=[^\\s\'"<>]*youtube.com.*v=([^\\s\'"<>]+)\\]/ims', "/\\[video=[^\\s'\"<>]*video.google.com.*docid=(-?[0-9]+).*\\]/ims", '/\\[audio\\](http:\\/\\/[^\\s\'"<>]+(\\.(mp3|aiff|wav)))\\[\\/audio\\]/i', '/\\[list=([0-9]+)\\]((\\s|.)+?)\\[\\/list\\]/i', '/\\[list\\]((\\s|.)+?)\\[\\/list\\]/i', '/\\[\\*\\]\\s?(.*?)\\n/i', '/\\[li\\]\\s?(.*?)\\n/i', '/\\[hr\\]/');
    // And replace them by...
    $bb_code_out = array('<span style="font-weight: bold;">\\1</span>', '<span style="font-style: italic;">\\1</span>', '<span style="text-decoration: underline;">\\1</span>', '<a class="altlink" href="mailto:\\1">\\1</a>', '<div style="text-align: \\1;">\\2</div>', '<blockquote class="style"><span>\\1</span></blockquote>', '<span style="text-decoration: line-through;">\\1</span>', '<span style="text-decoration: line-through;">\\1</span>', '<span style="white-space: nowrap;">\\1</span>', '<marquee class="style">\\1</marquee>', '<div style="padding-top: 2px; white-space: nowrap"><span style="cursor: hand; cursor: pointer; border-bottom: 1px dotted" onclick="if (document.getElementById(\'collapseobj\\1\').style.display==\'block\') {document.getElementById(\'collapseobj\\1\').style.display=\'none\' } else { document.getElementById(\'collapseobj\\1\').style.display=\'block\' }">\\1</span></div><div id="collapseobj\\1" style="display:none; padding-top: 2px; padding-left: 14px; margin-bottom:10px; padding-bottom: 2px; background-color: #FEFEF4;">\\2</div>', '<span class="size\\1">\\2</span>', '<span style="color:\\1;">\\2</span>', '<span style="color:\\1;">\\2</span>', '<span style="font-family:\'\\1\';">\\2</span>', '<table cellspacing="0" cellpadding="10"><tr><td class="forum_head_dark" style="padding:5px">Spoiler! to view, roll over the spoiler box.</td></tr><tr><td class="spoiler"><a href="#">\\1</a></td></tr></table><br />', '<object width="500" height="410"><param name="movie" value="http://www.youtube.com/v/\\1"></param><embed src="http://www.youtube.com/v/\\1" type="application/x-shockwave-flash" width="500" height="410"></embed></object>', "<embed style=\"width:500px; height:410px;\" id=\"VideoPlayback\" align=\"middle\" type=\"application/x-shockwave-flash\" src=\"http://video.google.com/googleplayer.swf?docId=\\1\" allowScriptAccess=\"sameDomain\" quality=\"best\" bgcolor=\"#ffffff\" scale=\"noScale\" wmode=\"window\" salign=\"TL\"  FlashVars=\"playerMode=embedded\"> </embed>", '<span style="text-align: center;"><p>Audio From: \\1</p><embed type="application/x-shockwave-flash" src="http://www.google.com/reader/ui/3247397568-audio-player.swf?audioUrl=\\1" width="400" height="27" allowscriptaccess="never" quality="best" bgcolor="#ffffff" wmode="window" flashvars="playerMode=embedded" /></span>', '<ol class="style" start="\\1">\\2</ol>', '<ul class="style">\\1</ul>', '<li>\\1</li>', '<li>\\1</li>', '<hr />');
    $s = preg_replace($bb_code_in, $bb_code_out, $s);
    if ($urls) {
        $s = format_urls($s);
    }
    if (stripos($s, '[url') !== false && $urls) {
        $s = preg_replace_callback("/\\[url=([^()<>\\s]+?)\\](.+?)\\[\\/url\\]/is", "islocal", $s);
        // [url]http://www.example.com[/url]
        $s = preg_replace_callback("/\\[url\\]([^()<>\\s]+?)\\[\\/url\\]/is", "islocal", $s);
    }
    // Linebreaks
    $s = nl2br($s);
    // Dynamic Vars
    $s = dynamic_user_vars($s);
    // [pre]Preformatted[/pre]
    if (stripos($s, '[pre]') !== false) {
        $s = preg_replace("/\\[pre\\]((\\s|.)+?)\\[\\/pre\\]/i", "<tt><span style=\"white-space: nowrap;\">\\1</span></tt>", $s);
    }
    // [nfo]NFO-preformatted[/nfo]
    if (stripos($s, '[nfo]') !== false) {
        $s = preg_replace("/\\[nfo\\]((\\s|.)+?)\\[\\/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);
    }
    //==Media tag
    if (stripos($s, '[media=') !== false) {
        $s = preg_replace("#\\[media=(youtube|liveleak|GameTrailers|vimeo|imdb)\\](.+?)\\[/media\\]#ies", "_MediaTag('\\2','\\1')", $s);
    }
    if (stripos($s, '[img') !== false && $images) {
        // [img=http://www/image.gif]
        $s = preg_replace("/\\[img\\]((http|https):\\/\\/[^\\s'\"<>]+(\\.(jpg|gif|png|bmp)))\\[\\/img\\]/i", "<a href=\"\\1\" rel=\"lightbox\"><img src=\"\\1\" border=\"0\" alt=\"\" style=\"max-width: 150px;\" /></a>", $s);
        // [img=http://www/image.gif]
        $s = preg_replace("/\\[img=((http|https):\\/\\/[^\\s'\"<>]+(\\.(gif|jpg|png|bmp)))\\]/i", "<a href=\"\\1\" rel=\"lightbox\"><img src=\"\\1\" border=\"0\" alt=\"\" style=\"max-width: 150px;\" /></a>", $s);
    }
    // [mcom]Text[/mcom]
    if (stripos($s, '[mcom]') !== false) {
        $s = preg_replace("/\\[mcom\\](.+?)\\[\\/mcom\\]/is", "<div style=\"font-size: 18pt; line-height: 50%;\">\n   <div style=\"border-color: red; background-color: red; color: white; text-align: center; font-weight: bold; font-size: large;\"><b>\\1</b></div></div>", $s);
    }
    // the [you] tag
    if (stripos($s, '[you]') !== false) {
        $s = preg_replace("/\\[you\\]/i", $CURUSER['username'], $s);
    }
    // [php]code[/php]
    if (stripos($s, '[php]') !== false) {
        $s = preg_replace("#\\[(php|sql|html)\\](.+?)\\[\\/\\1\\]#ise", "source_highlighter('\\2','\\1')", $s);
    }
    // Maintain spacing
    $s = str_replace('  ', ' &nbsp;', $s);
    if (isset($smilies)) {
        foreach ($smilies as $code => $url) {
            $s = str_replace($code, "<img border='0' src=\"{$INSTALLER09['pic_base_url']}smilies/{$url}\" alt=\"\" />", $s);
            //$s = str_replace($code, '<span id="'.$attr.'"></span>', $s);
        }
    }
    if (isset($staff_smilies)) {
        foreach ($staff_smilies as $code => $url) {
            $s = str_replace($code, "<img border='0' src=\"{$INSTALLER09['pic_base_url']}smilies/{$url}\" alt=\"\" />", $s);
            //$s = str_replace($code, '<span id="'.$attr.'"></span>', $s);
        }
    }
    if (isset($customsmilies)) {
        foreach ($customsmilies as $code => $url) {
            $s = str_replace($code, "<img border='0' src=\"{$INSTALLER09['pic_base_url']}smilies/{$url}\" alt=\"\" />", $s);
            //$s = str_replace($code, '<span id="'.$attr.'"></span>', $s);
        }
    }
    $s = format_quotes($s);
    $s = check_BBcode($s);
    return $s;
}
コード例 #2
0
ファイル: bbcode_functions.php プロジェクト: thefkboss/U-232
function format_comment($text, $strip_html = true)
{
    global $smilies, $CURUSER, $customsmilies, $TBDEV;
    $s = $text;
    $s = validate_imgs($s);
    $s = str_replace("][", "] [", $s);
    unset($text);
    // This fixes the extraneous ;) smilies problem. When there was an html escaped
    // char before a closing bracket - like >), "), ... - this would be encoded
    // to &xxx;), hence all the extra smilies. I created a new :wink: label, removed
    // the ;) one, and replace all genuine ;) by :wink: before escaping the body.
    // (What took us so long? :blush:)- wyz
    $s = str_replace(";)", ":wink:", $s);
    if ($strip_html) {
        $s = htmlentities($s, ENT_QUOTES);
    }
    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 (stripos($s, '[*]') !== false) {
        $s = preg_replace("/\\[\\*\\]/", "<img src=\"" . $TBDEV['pic_base_url'] . "list.gif\" alt=\"List\" title=\"List\" class=\"listitem\" />", $s);
    }
    // [b]Bold[/b]
    if (stripos($s, '[b]') !== false) {
        $s = preg_replace('/\\[b\\](.+?)\\[\\/b\\]/is', "<b>\\1</b>", $s);
    }
    // [i]Italic[/i]
    if (stripos($s, '[i]') !== false) {
        $s = preg_replace('/\\[i\\](.+?)\\[\\/i\\]/is', "<i>\\1</i>", $s);
    }
    // [u]Underline[/u]
    if (stripos($s, '[u]') !== false) {
        $s = preg_replace('/\\[u\\](.+?)\\[\\/u\\]/is', "<span style='text-decoration:underline;'>\\1</span>", $s);
    }
    // [color=blue]Text[/color]
    if (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 (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
    if (stripos($s, '[img') !== false) {
        $s = preg_replace_callback("/\\[img\\](http:\\/\\/[^\\s'\"<>]+(\\.(jpg|gif|png)))\\[\\/img\\]/i", "scale", $s);
        $s = preg_replace_callback("/\\[img=(http:\\/\\/[^\\s'\"<>]+(\\.(gif|jpg|png)))\\]/i", "scale", $s);
    }
    // [size=4]Text[/size]
    if (stripos($s, '[size=') !== false) {
        $s = preg_replace('/\\[size=([1-7])\\](.+?)\\[\\/size\\]/is', "<span class='size\\1'>\\2</span>", $s);
    }
    // [font=Arial]Text[/font]
    if (stripos($s, '[font=') !== false) {
        $s = preg_replace('/\\[font=([a-zA-Z ,]+)\\](.+?)\\[\\/font\\]/is', '<span style="font-family: \\1">\\2</span>', $s);
    }
    // [s]Stroke[/s]
    if (stripos($s, '[s]') !== false) {
        $s = preg_replace("/\\[s\\](.+?)\\[\\/s\\]/is", "<s>\\1</s>", $s);
    }
    // the [you] tag
    if (stripos($s, '[you]') !== false) {
        $s = preg_replace("/\\[you\\]/i", $CURUSER['username'], $s);
    }
    // Dynamic Vars
    $s = dynamic_user_vars($s);
    // [Spoiler]TEXT[/Spoiler]
    if (stripos($s, '[spoiler]') !== false) {
        $s = preg_replace("/\\[spoiler\\](.+?)\\[\\/spoiler\\]/is", "<div class=\"smallfont\" align=\"left\">\r\n    <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'; }\" />\r\n    <div style=\"margin: 10px; padding: 10px; border: 1px inset;\" align=\"left\"><div style=\"display: none;\">\\1</div></div></div>", $s);
    }
    // [mcom]Text[/mcom]
    if (stripos($s, '[mcom]') !== false) {
        $s = preg_replace("/\\[mcom\\](.+?)\\[\\/mcom\\]/is", "<div style=\"font-size: 18pt; line-height: 50%;\">\r\n    <div style=\"border-color: red; background-color: red; color: white; text-align: center; font-weight: bold; font-size: large;\"><b>\\1</b></div></div>", $s);
    }
    // [php]php code[/php]
    if (stripos($s, '[php]') !== false) {
        $s = preg_replace_callback("/\\[php\\](.+?)\\[\\/php\\]/ims", "source_highlighter", $s);
    }
    // [sql]sql code[/sql]
    if (stripos($s, '[sql]') !== false) {
        $s = preg_replace_callback("/\\[sql\\](.+?)\\[\\/sql\\]/ims", "source_highlighter", $s);
    }
    // [html]html code[/html]
    if (stripos($s, '[html]') !== false) {
        $s = preg_replace_callback("/\\[html\\](.+?)\\[\\/html\\]/ims", "source_highlighter", $s);
    }
    //[mail]mail[/mail]
    if (stripos($s, '[mail]') !== false) {
        $s = preg_replace("/\\[mail\\](.+?)\\[\\/mail\\]/is", "<a href=\"mailto:\\1\" targe=\"_blank\">\\1</a>", $s);
    }
    //[align=(center|left|right|justify)]text[/align]
    if (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);
    //	$s = format_local_urls($s);
    // [url=http://www.example.com]Text[/url]
    if (stripos($s, '[url') !== false) {
        $s = preg_replace_callback("/\\[url=([^()<>\\s]+?)\\](.+?)\\[\\/url\\]/is", "islocal", $s);
        // [url]http://www.example.com[/url]
        $s = preg_replace_callback("/\\[url\\]([^()<>\\s]+?)\\[\\/url\\]/is", "islocal", $s);
    }
    // Linebreaks
    $s = nl2br($s);
    // [pre]Preformatted[/pre]
    if (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 (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("  ", " &nbsp;", $s);
    //==Smilies
    if (isset($smilies)) {
        foreach ($smilies as $code => $url) {
            $s = str_replace($code, "<img border='0' src=\"{$TBDEV['pic_base_url']}smilies/{$url}\" alt=\"" . htmlspecialchars($code) . "\" />", $s);
        }
    }
    if (isset($customsmilies)) {
        foreach ($customsmilies as $code => $url) {
            $s = str_replace($code, "<img border='0' src=\"{$TBDEV['pic_base_url']}smilies/{$url}\" alt=\"" . htmlspecialchars($code) . "\" />", $s);
        }
    }
    return $s;
}