bbcode_firstpass::bbcode_parse_code PHP Méthode

bbcode_parse_code() public méthode

Parse code text from code tag
public bbcode_parse_code ( $stx, &$code )
    function bbcode_parse_code($stx, &$code)
    {
        switch (strtolower($stx)) {
            case 'php':
                $remove_tags = false;
                $str_from = array('<', '>', '[', ']', '.', ':', ':');
                $str_to = array('<', '>', '[', ']', '.', ':', ':');
                $code = str_replace($str_from, $str_to, $code);
                if (!preg_match('/\\<\\?.*?\\?\\>/is', $code)) {
                    $remove_tags = true;
                    $code = "<?php {$code} ?>";
                }
                $conf = array('highlight.bg', 'highlight.comment', 'highlight.default', 'highlight.html', 'highlight.keyword', 'highlight.string');
                foreach ($conf as $ini_var) {
                    @ini_set($ini_var, str_replace('highlight.', 'syntax', $ini_var));
                }
                // Because highlight_string is specialcharing the text (but we already did this before), we have to reverse this in order to get correct results
                $code = htmlspecialchars_decode($code);
                $code = highlight_string($code, true);
                $str_from = array('<span style="color: ', '<font color="syntax', '</font>', '<code>', '</code>', '[', ']', '.', ':');
                $str_to = array('<span class="', '<span class="syntax', '</span>', '', '', '&#91;', '&#93;', '&#46;', '&#58;');
                if ($remove_tags) {
                    $str_from[] = '<span class="syntaxdefault">&lt;?php </span>';
                    $str_to[] = '';
                    $str_from[] = '<span class="syntaxdefault">&lt;?php&nbsp;';
                    $str_to[] = '<span class="syntaxdefault">';
                }
                $code = str_replace($str_from, $str_to, $code);
                $code = preg_replace('#^(<span class="[a-z_]+">)\\n?(.*?)\\n?(</span>)$#is', '$1$2$3', $code);
                if ($remove_tags) {
                    $code = preg_replace('#(<span class="[a-z]+">)?\\?&gt;(</span>)#', '$1&nbsp;$2', $code);
                }
                $code = preg_replace('#^<span class="[a-z]+"><span class="([a-z]+)">(.*)</span></span>#s', '<span class="$1">$2</span>', $code);
                $code = preg_replace('#(?:\\s++|&nbsp;)*+</span>$#u', '</span>', $code);
                // remove newline at the end
                if (!empty($code) && substr($code, -1) == "\n") {
                    $code = substr($code, 0, -1);
                }
                return "[code={$stx}:" . $this->bbcode_uid . ']' . $code . '[/code:' . $this->bbcode_uid . ']';
                break;
            default:
                return '[code:' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($code) . '[/code:' . $this->bbcode_uid . ']';
                break;
        }
    }