1<?php
2/**
3 * Plugin Password: hides passwords with syntax <PASSWORD></PASSWORD>
4 *
5 * @license    GPL2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Roland Eckert <roland.eckert@gmail.com>
7 */
8
9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(DOKU_PLUGIN.'syntax.php');
12
13/**
14 * All DokuWiki plugins to extend the parser/rendering mechanism
15 * need to inherit from this class
16 */
17class syntax_plugin_password extends DokuWiki_Syntax_Plugin {
18
19    /**
20     * return some info
21     */
22    function getInfo(){
23        return array(
24            'author' => 'Roland Eckert',
25            'email'  => 'roland.eckert@gmail.com',
26            'date'   => '2007-09-26',
27            'name'   => 'Password Plugin',
28            'desc'   => 'This plugin hides passwords from plain view',
29            'url'    => 'http://wiki.splitbrain.org/plugin:password',
30        );
31    }
32
33    /**
34     * What kind of syntax are we?
35     */
36    function getType(){
37        return 'protected';
38    }
39
40    /**
41     * Where to sort in?
42     */
43    function getSort(){
44        return 201;
45    }
46
47    /**
48     * Connect pattern to lexer
49     */
50    function connectTo($mode) {
51        $this->Lexer->addEntryPattern('<PASSWORD>(?=.*?</PASSWORD>)',$mode,'plugin_password');
52    }
53
54    function postConnect() {
55        $this->Lexer->addExitPattern('</PASSWORD>','plugin_password');
56    }
57
58    /**
59     * Handle the match
60     */
61    function handle($match, $state, $pos, &$handler){
62        switch ($state) {
63            case DOKU_LEXER_ENTER :
64                return array($state, '');
65            break;
66            case DOKU_LEXER_UNMATCHED :
67                return array($state, $match);
68            break;
69            case DOKU_LEXER_EXIT :
70                return array($state, '');
71            break;
72        }
73        return array();
74    }
75
76    /**
77     * Create output
78     */
79    function render($mode, &$renderer, $data) {
80        if($mode == 'xhtml'){
81
82           list($state, $match) = $data;
83            switch ($state) {
84                case DOKU_LEXER_ENTER :
85                    list($color, $background) = $match;
86                    $renderer->doc.= '<span style="color:#aaaaaa; padding:2px; border: 1px grey dotted;">';
87                    break;
88                case DOKU_LEXER_UNMATCHED :
89                    $renderer->doc.= 'see wiki source';
90                    break;
91                case DOKU_LEXER_EXIT :
92                    $renderer->doc .= "</span>";
93                    break;
94            }
95            return true;
96        }
97        return false;
98    }
99}
100?>
101