Пример #1
0
function plugin_pre_convert()
{
    if (file_exists(PLUGIN_DIR . 'code/codehighlight.php')) {
        require_once PLUGIN_DIR . 'code/codehighlight.php';
    } else {
        die_message('file ' . PLUGIN_DIR . 'code/codehighlight.php not exist or not readable.');
    }
    static $id_number = 0;
    // プラグインが呼ばれた回数(IDに利用)
    $id_number++;
    $option = array('number' => false, 'nonumber' => false, 'vervatim' => false, 'novervatim' => false, 'icon' => false, 'noicon' => false, 'link' => false, 'nolink' => false);
    $num_of_arg = func_num_args();
    $args = func_get_args();
    $text = '';
    $number = '';
    $style = '';
    $stylecnt = 0;
    $begin = 1;
    $end = null;
    $a = array();
    // オプションを調べる
    for ($i = 0; $i < $num_of_arg - 1; ++$i) {
        if (!_plugin_code_check_argment($args[$i], $option)) {
            if (!_plugin_code_get_region($args[$i], $begin, $end)) {
                // style
                if ($stylecnt == 0) {
                    $color = $args[$i];
                    ++$stylecnt;
                } else {
                    $bgcolor = $args[$i];
                }
            }
        }
    }
    if ($stylecnt) {
        // Invalid color
        foreach (array($color, $bgcolor) as $col) {
            if ($col != '' && !preg_match(PLUGIN_PRE_COLOR_REGEX, $col)) {
                return '<p class="error">#pre():Invalid color: ' . htmlspecialchars($col) . ';</p>';
            }
        }
        if ($color != '') {
            $style = ' style="color:' . $color;
            if ($bgcolor != '') {
                $style .= ';background-color:' . $bgcolor . '"';
            } else {
                $style .= '"';
            }
        } else {
            if ($bgcolor != '') {
                $style .= ' style="background-color:' . $bgcolor . '"';
            } else {
                $style = '';
            }
        }
    }
    _plugin_code_multiline_argment($args[$num_of_arg - 1], $data, $option, $begin, $end);
    if (isset($data['_error']) && $data['_error'] != '') {
        return $data['_error'];
    }
    $text = $data['data'];
    $title = $data['title'];
    if ($end === null) {
        $end = substr_count($text, "\n") + $begin - 1;
    }
    if (PLUGIN_PRE_VERVATIM && !$option['novervatim'] || $option['vervatim']) {
        $text = htmlspecialchars($text);
    } else {
        $text = make_link($text);
    }
    $html = '<pre class="' . PLUGIN_PRE_HEADER . 'body" ' . $style . '>' . $text . '</pre>';
    if (PLUGIN_PRE_NUMBER && !$option['nonumber'] || $option['number']) {
        $number = '<pre class="' . PLUGIN_PRE_HEADER . 'number">' . _plugin_code_makeNumber($end, $begin) . '</pre>';
        $html = '<div id="' . PLUGIN_PRE_HEADER . $id_number . '" class="' . PLUGIN_PRE_HEADER . 'table">' . _plugin_code_column($html, $number, null) . '</div>';
    }
    return $title . $html;
}
Пример #2
0
function plugin_code_convert()
{
    if (file_exists(PLUGIN_DIR . 'code/codehighlight.php')) {
        require_once PLUGIN_DIR . 'code/codehighlight.php';
    } else {
        die_message('file ' . PLUGIN_DIR . 'code/codehighlight.php not exist or not readable.');
    }
    static $plugin_code_jscript_flag = true;
    $lang = null;
    $option = array('number' => false, 'nonumber' => false, 'outline' => false, 'nooutline' => false, 'comment' => false, 'nocomment' => false, 'menu' => false, 'nomenu' => false, 'icon' => false, 'noicon' => false, 'link' => false, 'nolink' => false);
    $num_of_arg = func_num_args();
    $args = func_get_args();
    if ($num_of_arg < 1) {
        return PLUGIN_CODE_USAGE;
    }
    $arg = $args[$num_of_arg - 1];
    if (strlen($arg) == 0) {
        return PLUGIN_CODE_USAGE;
    }
    if ($num_of_arg != 1 && !_plugin_code_check_argment($args[0], $option)) {
        $is_setlang = true;
        $lang = htmlspecialchars(strtolower($args[0]));
        // 言語名かオプションの判定
    } else {
        $lang = PLUGIN_CODE_LANGUAGE;
        // default
    }
    $begin = 0;
    $end = null;
    // オプションを調べる
    for ($i = 1; $i < $num_of_arg - 1; ++$i) {
        if (!_plugin_code_check_argment($args[$i], $option)) {
            _plugin_code_get_region($args[$i], $begin, $end);
        }
    }
    $multiline = _plugin_code_multiline_argment($arg, $data, $option, $begin, $end);
    if (PLUGIN_CODE_CACHE && !$multiline) {
        $html = _plugin_code_read_cache($arg);
        if ($html != '' or $html != null) {
            return $html;
        }
    }
    if (isset($data['_error']) && $data['_error'] != '') {
        return $data['_error'];
    }
    $lines = $data['data'];
    $title = isset($data['title']) ? $data['title'] : '';
    $highlight = new CodeHighlight();
    $lines = $highlight->highlight($lang, $lines, $option);
    $lines = '<div class="' . $lang . '">' . $lines . '</div>';
    if ($plugin_code_jscript_flag && ($option['outline'] || $option['comment'])) {
        $plugin_code_jscript_flag = false;
        $title .= '<script type="text/javascript" src="' . SKIN_URI . 'code.js"></script>' . "\n";
    }
    $html = $title . $lines;
    if (PLUGIN_CODE_CACHE && !$multiline) {
        _plugin_code_write_cache($arg, $html);
    }
    return $html;
}