OSDN Git Service

Import current code.
[osdn-codes/wiki-parser.git] / sfjp / wiki / formatter / base.php
1 <?php
2 namespace sfjp\Wiki\Formatter;
3 abstract class Base {
4         protected $processor;
5         function __construct() {
6         }
7
8         function __destruct() {
9                 unset($this->processor);
10         }
11
12         public function cleanup() {}
13
14         public function reset() {}
15
16         public function setProcessor($proc) {
17                 $this->processor = $proc;
18         }
19
20         public function getProcessor() {
21                 return $this->processor;
22         }
23
24         public function setContext($c) {
25                 return $this->getProcessor()->setContext($c);
26         }
27
28         public function getContext($key = null) {
29                 return $this->getProcessor()->getContext($key);
30         }
31
32         public function __($text, $args=array()) {
33                 return $this->getProcessor()->__($text, $args);
34         }
35
36         abstract public function raw_node($string);
37         abstract public function text_node($text);
38         abstract public function open_element($neme, $opt = null);
39         abstract public function close_element($name, $opt = null);
40
41         static public function escape_id_value($str) {
42                 $str = preg_replace_callback('/[^A-Za-z0-9_:.-]+/',
43                                              create_function('$m', '$p = unpack("H*", $m[0]); return $p[1];'),
44                                              $str);
45                 if (!ctype_alpha(substr($str, 0, 1))) $str = "badid-".$str;
46                 return $str;
47         }
48 }