2 namespace sfjp\Wiki\Plugin;
3 use sfjp\Wiki\Exception\Plugin_Error;
5 public $is_vary = true;
6 public $is_block = false;
9 function __construct($processor) {
10 $this->processor = $processor;
13 public function setContext($ctx) {
14 return $this->processor->setContext($ctx);
17 public function getContext($key=null) {
18 return $this->processor->getContext($key);
21 public function error($msg) {
22 $this->setContext(array('whole_page_cachable' => false));
23 throw new Plugin_Error($msg);
26 public function __($text, $args=array()) {
27 if (!$this->processor->hasContext('i18n')) {
30 return $this->getContext('i18n')->__($text, $args);
34 public function getProcessor() {
35 return $this->processor;
38 public function getFormatter() {
39 return $this->getProcessor()->getFormatter();
42 public function parseArgs($args, $list = array(), $default = null) {
44 foreach ($args as $arg) {
45 if (strpos($arg, '=')) {
46 list($key, $value) = explode('=', $arg, 2);
49 } elseif (isset($default) && !empty($default)) {
53 if (!in_array($key, $list) && !array_key_exists($key, $list)) {
54 $this->error("unknown argument $arg");
61 public function render_table($data) {
62 $fmt = $this->getFormatter();
65 $ret .= $fmt->open_element('table');
66 foreach ($data as $cols) {
67 $ret .= $fmt->open_element('table_row');
68 foreach ($cols as $col) {
69 $ret .= $fmt->open_element('table_col');
71 $ret .= $fmt->close_element('table_col');
73 $ret .= $fmt->close_element('table_row');
75 $ret .= $fmt->close_element('table');
76 return $fmt->raw_node($ret);
79 public function render_date_separated_list($data) {
83 foreach ($data as $item) {
84 if ($last_date != date('Y-m-d', $item[0]))
85 $wikistr .= "==== " . date('Y-m-d', $item[0]) . " ====\n";
86 $last_date = date('Y-m-d', $item[0]);
87 $wikistr .= " * " . $item[1];
89 $p = new \sfjp\Wiki\Parser($this->getContext());
90 return $this->getFormatter()->raw_node($p->parse($wikistr));