Пример #1
0
 public static function convert($line, $link = TRUE, $enc = TRUE)
 {
     if ($enc) {
         $line = preg_replace("/&/", "&", $line);
         $line = Utility::htmlsc($line);
     }
     // インライン・プラグイン
     $pattern = '/&(\\w+)(?:\\(((?:(?!\\)[;{]).)*)\\))?(?:\\{((?:(?R)|(?!};).)*)\\})?;/';
     $line = preg_replace_callback($pattern, array(&$this, 'convert_plugin'), $line);
     // ルールの変換
     $line = guiedit_make_line_rules($line);
     // 文字サイズの変換
     $pattern = "/<span\\s(style=\"font-size:(\\d+)px|class=\"size([1-7])).*?>/";
     $line = preg_replace_callback($pattern, array(&$this, 'convert_size'), $line);
     // 色の変換
     $pattern = "/<sapn\\sstyle=\"color:([#0-9a-z]+)(; background-color:([#0-9a-z]+))?\">/";
     $line = preg_replace_callback($pattern, array(&$this, 'convert_color'), $line);
     // 注釈
     $line = preg_replace("/\\(\\(((?:(?R)|(?!\\)\\)).)*)\\)\\)/", "<img alt=\"Note\" title=\"\$1\" />", $line);
     // 参照文字
     $line = preg_replace('/&amp;(#?[a-z0-9]+);/', "&\$1;", $line);
     // 上付き文字
     $line = preg_replace('/SUP{(.*?)}/', "<sup>\$1</sup>", $line);
     // 下付き文字・添え字
     $line = preg_replace('/SUB{(.*?)}/', "<sub>\$1</sub>", $line);
     // リンク
     if ($link) {
         $pattern = "/\\(\\(((?:(?R)|(?!\\)\\)).)*)\\)\\)/";
         $replace = "<img alt=\"Note\" title=\"\$1\" />";
         $line = $this->make_link($line);
     }
     if (preg_match("/^<br\\s\\/>\$/", $line)) {
         $line .= "\n&nbsp;";
     }
     return $line;
 }
Пример #2
0
 function convert_plugin($matches)
 {
     $aryargs = isset($matches[2]) && $matches[2] !== '' ? csv_explode(',', unhtmlspecialchars($matches[2])) : array();
     $name = strtolower($matches[1]);
     $body = isset($matches[3]) ? $matches[3] : '';
     //	プラグインが存在しない場合はそのまま返す。
     global $xpwiki;
     if (!$xpwiki->func->exist_plugin_inline($name)) {
         // ルールの変換
         $matches[0] = guiedit_make_line_rules($matches[0]);
         // 数値参照文字(10進)
         $matches[0] = preg_replace('/(&amp;#[0-9]+?;)+/e', '"<span class=\\"chrref10\\">".str_replace(\'&amp;\',\'&\',\'$0\')."</span>"', $matches[0]);
         // 文字実体参照
         $matches[0] = preg_replace('/(&amp;[a-z]+?;)+/ie', '"<span class=\\"chrref\\">".str_replace(\'&amp;\',\'&\',\'$0\')."</span>"', $matches[0]);
         return $matches[0];
     }
     switch ($name) {
         case 'aname':
             return "<a name=\"{$aryargs['0']}\">{$body}</a>";
         case 'br':
             return '<br class="inline" />';
         case 'font':
             $class = $style = "";
             $color_type = true;
             $decoration = array();
             foreach ($aryargs as $prm) {
                 $size = $color = array();
                 if ($prm == "") {
                     $color_type = false;
                 } elseif (preg_match("/^i(talic)?\$/i", $prm)) {
                     $style .= "font-style:italic;";
                 } elseif (preg_match("/^b(old)?\$/i", $prm)) {
                     $style .= "font-weight:bold;";
                 } elseif (preg_match("/^bl(ink)?\$/i", $prm)) {
                     $decoration[] = "blink";
                 } elseif (preg_match("/^u(nderline)?\$/i", $prm)) {
                     $decoration[] = "underline";
                 } elseif (preg_match("/^o(verline)?\$/i", $prm)) {
                     $decoration[] = "overline";
                 } elseif (preg_match("/^l(ine-through)?\$/i", $prm)) {
                     $decoration[] = "line-through";
                 } elseif (preg_match('/^(#[0-9a-f]+|' . COLORS_REG . ')$/i', $prm, $color)) {
                     if ($color_type) {
                         $style .= "color:" . _htmlspecialchars($color[1]) . ";";
                         $color_type = false;
                     } else {
                         $style .= "background-color:" . _htmlspecialchars($color[1]) . ";";
                     }
                 } elseif (preg_match('/^(\\d+(%|px|pt|em))$/', $prm, $size)) {
                     $style .= "font-size:" . _htmlspecialchars($size[1]) . ";line-height:130%;";
                 } elseif (preg_match('/^(\\d+)$/', $prm, $size)) {
                     $style .= "font-size:" . _htmlspecialchars($size[1]) . "px;line-height:130%;";
                 } elseif (preg_match('/^class:(.+)$/', $prm, $arg)) {
                     $class = ' class="' . str_replace('"', '', _htmlspecialchars($arg[1])) . '"';
                 }
             }
             if (count($decoration)) {
                 $style .= "text-decoration:" . join(" ", $decoration) . ";";
             }
             if (!$style && !$class) {
                 return $body;
             }
             return '<span style="' . $style . '"' . $class . '>' . $this->convert($body, TRUE, FALSE) . '</span>';
         case 'color':
             $color = $aryargs[0];
             $bgcolor = $aryargs[1];
             if ($body == '') {
                 return '';
             }
             if ($color != '' && !preg_match('/^(#[0-9a-f]+|[_0-9a-zA-Z-]+)$/i', $color)) {
                 return $body;
             }
             if ($bgcolor != '' && !preg_match('/^(#[0-9a-f]+|[_0-9a-zA-Z-]+)$/i', $bgcolor)) {
                 return $body;
             }
             if ($color != '') {
                 $color = "color:{$color}";
             }
             if ($bgcolor != '') {
                 $bgcolor = ($color ? "; " : "") . "background-color:{$bgcolor}";
             }
             return "<span style=\"{$color}{$bgcolor}\">" . $this->convert($body, TRUE, FALSE) . "</span>";
         case 'size':
             $size = $aryargs[0];
             if ($size == '' || $body == '') {
                 return '';
             }
             if (!preg_match('/^\\d+$/', $size)) {
                 return $body;
             }
             return '<span style="font-size:' . $size . 'px;line-height:130%">' . $this->convert($body, TRUE, FALSE) . "</span>";
         case 'ref':
             $aryargs[] = $body;
             return guiedit_convert_ref($aryargs, FALSE);
         case 'sub':
             if (!$body && isset($aryargs[0])) {
                 $body = _htmlspecialchars($aryargs[0]);
             }
             if ($body) {
                 return '<sub>' . $this->convert($body, TRUE, FALSE) . '</sub>';
             }
             break;
         case 'sup':
             if (!$body && isset($aryargs[0])) {
                 $body = _htmlspecialchars($aryargs[0]);
             }
             if ($body) {
                 return '<sup>' . $this->convert($body, TRUE, FALSE) . '</sup>';
             }
             break;
     }
     $inner = '&amp;' . $matches[1] . ($matches[2] ? "({$matches['2']})" : '') . ($body ? '{' . "{$body}}" : '') . ";";
     $style = MSIE ? ' style="cursor:default"' : '';
     return "<span class=\"plugin\" contenteditable=\"true\"{$style}>{$inner}</span>";
 }