syntax.php 2.8 KB
Newer Older
Michael Schreiber's avatar
Michael Schreiber committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
/**
 * Plugin passwordgrey: displays Passwords in light grey
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Michael Schreiber <passwordgrey@creatronics.de>
 * @based 		on color plugin by Christopher Smith
 */
 
// must be run within DokuWiki
if(!defined('DOKU_INC')) die();
 
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
Michael Schreiber's avatar
Michael Schreiber committed
15
16


Michael Schreiber's avatar
Michael Schreiber committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_passwordgrey extends DokuWiki_Syntax_Plugin {
 
    function getType(){ return 'formatting'; }
    function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }   
    function getSort(){ return 158; }
    function connectTo($mode) { $this->Lexer->addEntryPattern('<pwd>(?=.*?</pwd>)',$mode,'plugin_passwordgrey'); }
    function postConnect() { $this->Lexer->addExitPattern('</pwd>','plugin_passwordgrey'); }
 
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, Doku_Handler $handler){
        switch ($state) {
          case DOKU_LEXER_ENTER :
                return array($state, array('color:lightgrey', ''));
 
          case DOKU_LEXER_UNMATCHED :  return array($state, $match);
          case DOKU_LEXER_EXIT :       return array($state, '');
        }
        return array();
    }
 
    /**
     * Create output
     */
    function render($mode, Doku_Renderer $renderer, $data) {
Michael Schreiber's avatar
Michael Schreiber committed
48
49
50
      if($mode == 'xhtml'){
          $r = rand(0,100000);
          list($state, $match) = $data;
Michael Schreiber's avatar
Michael Schreiber committed
51
52
53
            switch ($state) {
              case DOKU_LEXER_ENTER :      
                list($color, $background) = $match;
Michael Schreiber's avatar
Michael Schreiber committed
54
                $renderer->doc .= "<span id='clipID_$r' onclick=\"javaScript:copyClip('clipID_".$r."');\" style='$color $background'>";
Michael Schreiber's avatar
Michael Schreiber committed
55
56
57
58
59
60
61
62
63
64
65
66
67
                break;
 
              case DOKU_LEXER_UNMATCHED :  $renderer->doc .= $renderer->_xmlEntities($match); break;
              case DOKU_LEXER_EXIT :       $renderer->doc .= "</span>"; break;
            }
            return true;
        }
        if($mode == 'odt'){
            list($state, $match) = $data;
            switch ($state) {
              case DOKU_LEXER_ENTER :      
                list($color, $background) = $match;
                if (class_exists('ODTDocument')) {
Michael Schreiber's avatar
Michael Schreiber committed
68
                    $renderer->_odtSpanOpenUseCSS (NULL, 'style="'.$color.' '.$background.'"');
Michael Schreiber's avatar
Michael Schreiber committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
                }
                break;
 
              case DOKU_LEXER_UNMATCHED :
                $renderer->cdata($match);
                break;

              case DOKU_LEXER_EXIT :
                if (class_exists('ODTDocument')) {
                    $renderer->_odtSpanClose();
                }
                break;
            }
            return true;
        }
        return false;
    }
}