コード例 #1
0
function parse_code($string, $do_br = 0, $do_img = 0, $do_code = 0, $do_smilies = 0)
{
    global $config, $style;
    static $smilies_fixed = 0;
    // HTML-Security & special characters
    $trans = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
    foreach ($trans as $key => $value) {
        $trans[$key] = '&#' . ord($key) . ';';
    }
    strtr($string, $trans);
    $string = str_replace('<', '&lt;', $string);
    $string = str_replace('>', '&gt;', $string);
    if ($do_code) {
        global $a_thwbcode, $a_thwbcode2nd;
        if (!defined('THWB_TAGS')) {
            get_thwb_tags();
        }
        $string = preg_replace($a_thwbcode[SEARCH], $a_thwbcode[REPLACE], $string);
        // nested [quote] fixup
        $string = fixup_quotes($string);
        $string = preg_replace($a_thwbcode2nd[SEARCH], $a_thwbcode2nd[REPLACE], $string);
    }
    if ($do_smilies && $config['smilies']) {
        global $a_smilies;
        if (!defined('THWB_SMILIES')) {
            $a_smilies = get_smilies();
        }
        if (!$smilies_fixed) {
            reset($a_smilies);
            $url_prepend = '<img src="templates/' . $style['styletemplate'] . '/images/icon/';
            while (current($a_smilies)) {
                $a_smilies[key($a_smilies)] = $url_prepend . current($a_smilies) . '_new.png" border="0">';
                next($a_smilies);
            }
            $smilies_fixed = 1;
        }
        $string = strtr($string, $a_smilies);
    }
    // reinsert extracted parts
    $string = preg_replace('/\\<noparse ([0-9]+)\\>/e', 'noparse("",\\1)', $string);
    if ($do_img && $config['imageslevel'] != 2) {
        $string = preg_replace('/\\[img\\](|[ \\n]*<a href=\\")([a-zA-Z]+):\\/\\/([^ \\"\\n]+)(|\\" target=\\"_blank\\">\\2:\\/\\/\\3([ \\n]*)<\\/a>[ \\n]*)\\[\\/img\\]/Usi', '<img src="\\2://\\3" alt="" border="0">', $string);
    }
    if ($do_br) {
        $string = str_replace("\n", '<br />', $string);
    } else {
        $string = str_replace("\n", '', $string);
    }
    return $string;
}
コード例 #2
0
ファイル: bcode.inc.php プロジェクト: BackupTheBerlios/thwc
function parse_code($string, $do_br = 0, $do_img = 0, $do_code = 0, $do_smilies = 0)
{
    global $config, $style;
    static $smilies_fixed = 0;
    // HTML-Security
    $string = str_replace('&', '&amp;', $string);
    $string = str_replace('<', '&lt;', $string);
    $string = str_replace('>', '&gt;', $string);
    if ($do_code) {
        global $a_thwbcode;
        if (!defined('THWB_TAGS')) {
            $a_thwbcode = get_thwb_tags();
        }
        //echo "<pre style=\"font-size:8pt\">";
        // nested [quote] fixup
        $string = fixup_quotes($string);
        //echo "$string</pre>";
        $string = preg_replace($a_thwbcode[SEARCH], $a_thwbcode[REPLACE], $string);
    }
    if ($do_img && $config['imageslevel'] != 2) {
        $string = preg_replace('/\\[img\\]([a-zA-Z]+):\\/\\/([^ ,\\"\\n]+)\\[\\/img\\]/Usi', '<img src="\\1://\\2.\\3" alt="" border="0">', $string);
    }
    if ($do_smilies && $config['smilies']) {
        global $a_smilies;
        if (!defined('THWB_SMILIES')) {
            $a_smilies = get_smilies();
        }
        if (!$smilies_fixed) {
            reset($a_smilies);
            $url_prepend = '<img src="templates/' . $style['styletemplate'] . '/images/icon/';
            while (current($a_smilies)) {
                $a_smilies[key($a_smilies)] = $url_prepend . current($a_smilies) . '_new.gif" width="15" height="15" border="0">';
                next($a_smilies);
            }
            $smilies_fixed = 1;
        }
        $string = strtr($string, $a_smilies);
    }
    // reinsert extracted parts
    $string = preg_replace('/\\<noparse ([0-9]+)\\>/e', 'noparse("",\\1)', $string);
    if ($do_br) {
        $string = str_replace("\n", '<br>', $string);
    } else {
        $string = str_replace("\n", '', $string);
    }
    return $string;
}