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
12/**
13 * All DokuWiki plugins to extend the parser/rendering mechanism
14 * need to inherit from this class
15 */
16class syntax_plugin_pagestat_word extends DokuWiki_Syntax_Plugin {
17
18
19
20    public function getType(){ return 'formatting'; }
21    public function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
22    public function getSort(){ return 409; }
23    public function connectTo($mode) { $this->Lexer->addEntryPattern('<WORDLIST.*?>(?=.*?</WORDLIST>)',$mode,'plugin_pagestat_word'); }
24    public function postConnect() { $this->Lexer->addExitPattern('</WORDLIST>','plugin_pagestat_word'); }
25
26
27    /**
28     * Handle the match
29     */
30    public function handle($match, $state, $pos, Doku_Handler $handler){
31        switch ($state) {
32            case DOKU_LEXER_ENTER :
33                $match = trim(substr($match,9,-1));
34                return array($state, $match);
35
36            case DOKU_LEXER_UNMATCHED :  return array($state, $match);
37            case DOKU_LEXER_EXIT :       return array($state, '');
38        }
39        return array();
40    }
41
42    /**
43     * Create output
44     */
45    public function render($mode, Doku_Renderer $renderer, $data) {
46        // $data is what the function handle() return'ed.
47        if($mode == 'xhtml'){
48            /** @var Doku_Renderer_xhtml $renderer */
49            list($state,$match) = $data;
50            switch ($state) {
51                case DOKU_LEXER_ENTER :
52                    $renderer->doc .= '<span class="pg_show_wl">Wordlist:</span><div class="wordlist" id="wordlist_'.$match.'">';
53                    break;
54
55                case DOKU_LEXER_UNMATCHED :
56                    $renderer->doc .= $renderer->_xmlEntities($match);
57                    break;
58                case DOKU_LEXER_EXIT :
59                    $renderer->doc .= "<input class='button' type='button' value='Filt Words'id='pg_filt_wl'></div>";
60                    break;
61            }
62            return true;
63        }
64        return false;
65    }
66
67}