1<?php
2/**
3 * Add Note capability to dokuwiki
4 *
5 * <xterm2>This is a console</xterm2>
6 * <xterm2 root>This is a ROOT console</xterm2>
7 *
8 * Authors of the note plugin
9 *----------------------------*
10 * by Olivier Cortès <olive@deep-ocean.net>
11 * under the terms of the GNU GPL v2.
12 *
13 * Originaly derived from the work of :
14 * Stephane Chamberland <stephane.chamberland@ec.gc.ca> (Side Notes PlugIn)
15 * Carl-Christian Salvesen <calle@ioslo.net> (Graphviz plugin)
16 *
17 * Contributions by Eric Hameleers <alien [at] slackware [dot] com> :
18 *   use <div> instead of <table>,
19 *   contain the images and stylesheet inside the plugin,
20 *   permit nesting of notes,
21 *
22 * Contributed by Christopher Smith <chris [at] jalakai [dot] co [dot] uk>
23 *   fix some parsing problems and a security hole.
24 *   make note types case independent
25 *   simplify code reading
26 *   modernise the plugin for changes/fixes/improvements to the underlying Dokuwiki plugin class,
27 *   improve efficiency.
28 *
29 * Contributed by Aurélien Bompard <aurelien [at] bompard [dot] org>
30 *   support for the ODT output format.
31 *
32 * @license    GNU_GPL_v2
33 * @author     Olivier Cortes <olive@deep-ocean.net>
34 */
35
36if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
37if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
38require_once(DOKU_PLUGIN.'syntax.php');
39
40
41class syntax_plugin_xterm2 extends DokuWiki_Syntax_Plugin {
42
43    var $notes = array(
44		'xterm2user'	=> array('', 'user'),
45		'xterm2root'	=> array('root', 'admin')
46      );
47
48    var $default = 'xterm2user';
49
50    function getInfo(){
51        return array(
52            'author' => 'Olivier Cortès / Eric Hameleers / Christopher Smith / Aurélien Bompard',
53            'email'  => 'olive@deep-ocean.net',
54            'date'   => '2006-03-29',
55            'name'   => 'Xterm2 Plugin',
56            'desc'   => 'Add console root or user Capability <xterm2 root> for root console(DIV+CSS box)\n Adapted by Xarkam',
57            'url'    => 'http://wiki.splitbrain.org/plugin:xterm2',
58        );
59    }
60
61
62    function getType(){ return 'container'; }
63    function getPType(){ return 'normal'; }
64    function getAllowedTypes() {
65        return array('container','substition','protected','disabled','formatting','paragraphs');
66    }
67    function getSort(){ return 195; }
68
69    // override default accepts() method to allow nesting
70    // - ie, to get the plugin accepts its own entry syntax
71    function accepts($mode) {
72      if ($mode == substr(get_class($this), 7)) return true;
73        return parent::accepts($mode);
74      }
75
76    function connectTo($mode) {
77        $this->Lexer->addEntryPattern('<xterm2.*?>(?=.*?</xterm2>)',$mode,'plugin_xterm2');
78    }
79    function postConnect() {
80        $this->Lexer->addExitPattern('</xterm2>','plugin_xterm2');
81    }
82
83    function handle($match, $state, $pos, &$handler){
84
85        switch ($state) {
86
87          case DOKU_LEXER_ENTER :
88            $note = strtolower(trim(substr($match,7,-1)));
89
90            foreach( $this->notes as $class => $names ) {
91              if (in_array($note, $names))
92                return array($state, $class);
93            }
94
95            return array($state, $this->default);
96
97          case DOKU_LEXER_UNMATCHED :
98            return array($state, $match);
99
100          default:
101            return array($state);
102        }
103    }
104
105    function render($mode, &$renderer, $indata) {
106
107        if($mode == 'xhtml'){
108
109          list($state, $data) = $indata;
110
111          switch ($state) {
112            case DOKU_LEXER_ENTER :
113              $renderer->doc .= '<pre class="'.$data.'">';
114              break;
115
116            case DOKU_LEXER_UNMATCHED :
117              $renderer->doc .= $renderer->_xmlEntities($data);
118              break;
119
120            case DOKU_LEXER_EXIT :
121              $renderer->doc .= "</pre>";
122              break;
123          }
124          return true;
125
126        }
127        // unsupported $mode
128        return false;
129    }
130}
131
132//Setup VIM: ex: et ts=4 enc=utf-8 :
133?>
134