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; }
function highlight(&$lang, &$src, &$option) { static $id_number = 0; // プラグインが呼ばれた回数(IDに利用) ++$id_number; if (strlen($lang) > 16) { $lang = ''; } $option['number'] = PLUGIN_CODE_NUMBER && !$option['nonumber'] || $option['number']; $option['outline'] = PLUGIN_CODE_OUTLINE && !$option['nooutline'] || $option['outline']; $option['comment'] = PLUGIN_CODE_COMMENT && !$option['nocomment'] || $option['comment']; $option['link'] = PLUGIN_CODE_LINK && !$option['nolink'] || $option['link']; // mozillaの空白行対策 if ($option['number'] || $option['outline']) { // ライン表示用補正 $src = preg_replace('/^$/m', ' ', $src); } if (file_exists(PLUGIN_DIR . 'code/keyword.' . $lang . '.php')) { // 言語定義ファイルが有る言語 $data = $this->srcToHTML($src, $lang, $id_number, $option); $src = '<pre class="code"><code class="' . $lang . '">' . $data['src'] . '</code></pre>'; } else { if (file_exists(PLUGIN_DIR . 'code/line.' . $lang . '.php')) { // 行指向解析設定ファイルが有る言語 $data = $this->lineToHTML($src, $lang, $id_number, $option); $src = '<pre class="code"><code class="' . $lang . '">' . $data['src'] . '</code></pre>'; } else { // PHP と 未定義言語 $option['outline'] = false; $option['comment'] = false; // 最後の余分な改行を削除 if ($src[strlen($src) - 2] == ' ') { $src = substr($src, 0, -2); } else { $src = substr($src, 0, -1); } if ($option['number']) { // 行数を得る $num_of_line = substr_count($src, "\n"); if ($src[strlen($src) - 1] == "\n") { $src = substr($src, 0, -1); } $data = array('number' => ''); $data['number'] = _plugin_code_makeNumber($num_of_line - 1); } if ('php' == $lang) { // PHPは標準機能を使う $src = '<pre class="code">' . $this->highlightPHP($src) . '</pre>'; } else { // 未定義言語 $src = '<pre class="code"><code class="unknown">' . htmlspecialchars($src) . '</code></pre>'; } } } $option['menu'] = PLUGIN_CODE_MENU && !$option['nomenu'] || $option['menu']; $option['menu'] = $option['menu'] && ($option['outline'] || $option['comment']); $menu = ''; if ($option['menu']) { // アイコンの設定 $menu .= '<div class="' . PLUGIN_CODE_HEADER . 'menu">'; if ($option['outline']) { // アウトラインのメニュー $_code_expand = _('Everything is expanded.'); $_code_short = _('Everything is shortened.'); $menu .= '<img src="' . PLUGIN_CODE_OUTLINE_OPEN_FILE . '" style="cursor: hand" alt="' . $_code_expand . '" title="' . $_code_expand . '" ' . 'onclick="javascript:code_all_outline(\'' . PLUGIN_CODE_HEADER . $id_number . '\',' . $data['blocknum'] . ',\'\',\'' . IMAGE_DIR . '\')" ' . 'onkeypress="javascript:code_all_outline(\'' . CODE_HEADER . $id_number . '\',' . $data['blocknum'] . ',\'\',\'' . IMAGE_DIR . '\')" />'; $menu .= '<img src="' . PLUGIN_CODE_OUTLINE_CLOSE_FILE . '" style="cursor: hand" alt="' . $_code_short . '" title="' . $_code_short . '" ' . 'onclick="javascript:code_all_outline(\'' . PLUGIN_CODE_HEADER . $id_number . '\',' . $data['blocknum'] . ',\'none\',\'' . IMAGE_DIR . '\')" ' . 'onkeypress="javascript:code_all_outline(\'' . PLUGIN_CODE_HEADER . $id_number . '\',' . $data['blocknum'] . ",'none','" . IMAGE_DIR . '\')" />' . "\n"; } if ($option['comment']) { // コメントの開閉ボタン $menu .= '<input type="button" value="comment open" ' . 'onclick="javascript:code_comment(\'' . PLUGIN_CODE_HEADER . $id_number . '\',' . $data['commentnum'] . ',\')" ' . 'onkeypress="javascript:code_comment(\'' . PLUGIN_CODE_HEADER . $id_number . '\',' . $data['commentnum'] . ',\')" />'; $menu .= '<input type="button" value="comment close" ' . ' onclick="javascript:code_comment(\'' . PLUGIN_CODE_HEADER . $id_number . '\',' . $data['commentnum'] . ',\'none\')" ' . ' onkeypress="javascript:code_comment(\'' . PLUGIN_CODE_HEADER . $id_number . '\',' . $data['commentnum'] . ',\'none\')" />'; } $menu .= '</div>'; } if ($option['number']) { $data['number'] = '<pre class="' . PLUGIN_CODE_HEADER . 'number">' . $data['number'] . '</pre>'; } else { $data['number'] = null; } if ($option['outline']) { $data['outline'] = '<pre class="' . PLUGIN_CODE_HEADER . 'outline">' . $data['outline'] . '</pre>'; } $html .= '<div id="' . PLUGIN_CODE_HEADER . $id_number . '" class="' . PLUGIN_CODE_HEADER . 'table">' . $menu . _plugin_code_column($src, $data['number'], $data['outline']) . '</div>'; return $html; }