1<?php
2/**
3 * Date: 2015/3/14
4 * Time: 8:14
5 *
6 */
7
8if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
10require_once(DOKU_PLUGIN . 'syntax.php');
11
12class syntax_plugin_pagestat_editpt extends DokuWiki_Syntax_Plugin {
13    private $pg_count=0;
14    function getType(){ return 'formatting';}
15    function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
16    function getPType(){ return 'normal';}
17    public function getSort() { return 323; }
18
19    public function connectTo($mode) { $this->Lexer->addEntryPattern('<pt.*?>(?=.*?</pt>)',$mode,'plugin_pagestat_editpt'); }
20    public function postConnect() { $this->Lexer->addExitPattern('</pt>','plugin_pagestat_editpt'); }
21
22
23
24    /*
25        public function connectTo($mode) { $this->Lexer->addEntryPattern($this->entry_pattern,$mode,'plugin_pagestat_'.$this->getPluginComponent());}
26        public function connectTo($mode) { $this->Lexer->addSpecialPattern('<PT.*?>',$mode,'plugin_now');}
27       function connectTo($mode) { $this->Lexer->addEntryPattern('\+\+\+\+.*?\|(?=.*\+\+\+\+)',$mode,'plugin_folded_div'); }
28    */
29    public function handle($match, $state, $pos, Doku_Handler $handler){
30        switch ($state) {
31            case DOKU_LEXER_ENTER :
32                $match = trim(substr($match,3,-1));
33                $arg_list = explode(" ",$match);
34                $this->pg_count=$this->pg_count+1;
35                return array($state, $arg_list,$this->pg_count-1);
36
37            case DOKU_LEXER_UNMATCHED :  return array($state, $match);
38            case DOKU_LEXER_EXIT :       return array($state, '');
39        }
40        return array();
41    }
42
43    public function render($mode, Doku_Renderer $renderer, $data) {
44        // $data is what the function handle() return'ed.
45        if($mode == 'xhtml'){
46            /** @var Doku_Renderer_xhtml $renderer */
47            list($state,$match,$count) = $data;
48            switch ($state) {
49                case DOKU_LEXER_ENTER :
50                    $arg_list = $match;
51                    $length = count($arg_list);
52                    if($length<1){
53                        break;
54                    }
55                    $subname=$arg_list[0];
56                    $arg_count=1;
57//            $str =  '<div class="xxpg xxpg_'.$match.'" id="xxpg_'.$match+$count.'"></div>';
58
59                    $pt_arg=implode(";",array_slice($arg_list,1));
60                    $str2 =<<<MYSTR2
61<span class="xxpg xxpg_$subname" id="xxpg_$subname$count" pt_arg="$pt_arg" pt_arg_count="$length" >
62MYSTR2;
63                    $renderer->doc .= $str2;
64
65
66                    break;
67
68                case DOKU_LEXER_UNMATCHED :
69                    $renderer->doc .= $renderer->_xmlEntities($match);
70                    break;
71                case DOKU_LEXER_EXIT :
72                    $renderer->doc .= "</span>";
73                    break;
74            }
75            return true;
76        }
77        return false;
78    }
79
80
81}
82