xref: /dokuwiki/lib/plugins/info/syntax.php (revision e60c9d46bd2b3cbed0ac8754712e54a3d23bf363)
1<?php
2/**
3 * Info Plugin: Displays information about various DokuWiki internals
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Andreas Gohr <andi@splitbrain.org>
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_info extends DokuWiki_Syntax_Plugin {
18
19    /**
20     * return some info
21     */
22    function getInfo(){
23        return array(
24            'author' => 'Andreas Gohr',
25            'email'  => 'andi@splitbrain.org',
26            'date'   => '2005-06-26',
27            'name'   => 'Info Plugin',
28            'desc'   => 'Displays information about various DokuWiki internals',
29            'url'    => 'http://wiki.splitbrain.org/plugin:info',
30        );
31    }
32
33    /**
34     * What kind of syntax are we?
35     */
36    function getType(){
37        return 'substition';
38    }
39
40    /**
41     * What about paragraphs?
42     */
43    function getPType(){
44        return 'block';
45    }
46
47    /**
48     * Where to sort in?
49     */
50    function getSort(){
51        return 155;
52    }
53
54
55    /**
56     * Connect pattern to lexer
57     */
58    function connectTo($mode) {
59        $this->Lexer->addSpecialPattern('~~INFO:\w+~~',$mode,'plugin_info');
60    }
61
62
63    /**
64     * Handle the match
65     */
66    function handle($match, $state, $pos, &$handler){
67        $match = substr($match,7,-2); //strip ~~INFO: from start and ~~ from end
68        return array(strtolower($match));
69    }
70
71    /**
72     * Create output
73     */
74    function render($mode, &$renderer, $data) {
75        if($mode == 'xhtml'){
76            //handle various info stuff
77            switch ($data[0]){
78                case 'version':
79                    $renderer->doc .= getVersion();
80                    break;
81                case 'syntaxmodes':
82                    $renderer->doc .= $this->_syntaxmodes_xhtml();
83                    break;
84                case 'syntaxtypes':
85                    $renderer->doc .= $this->_syntaxtypes_xhtml();
86                    break;
87                case 'syntaxplugins':
88                    $this->_syntaxplugins_xhtml($renderer);
89                    break;
90                default:
91                    $renderer->doc .= "no info about ".htmlspecialchars($data[0]);
92            }
93            return true;
94        }
95        return false;
96    }
97
98    /**
99     * list all installed syntax plugins
100     *
101     * uses some of the original renderer methods
102     */
103    function _syntaxplugins_xhtml(& $renderer){
104        global $lang;
105        $renderer->doc .= '<ul>';
106
107        $plugins = plugin_list('syntax');
108        foreach($plugins as $p){
109            if(plugin_load('syntax',$p,$po)){
110                $info = $po->getInfo();
111
112                $renderer->doc .= '<li>';
113                $renderer->externallink($info['url'],$info['name']);
114                $renderer->doc .= ' ';
115                $renderer->doc .= '<i>'.$info['date'].'</i>';
116                $renderer->doc .= ' ';
117                $renderer->doc .= $lang['by'];
118                $renderer->doc .= ' ';
119                $renderer->emaillink($info['email'],$info['author']);
120                $renderer->doc .= '<br />';
121                $renderer->doc .= htmlspecialchars($info['desc']);
122                $renderer->doc .= '</li>';
123            }
124        }
125
126        $renderer->doc .= '</ul>';
127    }
128
129    /**
130     * lists all known syntax types and their registered modes
131     */
132    function _syntaxtypes_xhtml(){
133        global $PARSER_MODES;
134        $doc  = '';
135
136        $doc .= '<table class="inline"><tbody>';
137        foreach($PARSER_MODES as $mode => $modes){
138            $doc .= '<tr>';
139            $doc .= '<td class="leftalign">';
140            $doc .= $mode;
141            $doc .= '</td>';
142            $doc .= '<td class="leftalign">';
143            $doc .= join(', ',$modes);
144            $doc .= '</td>';
145            $doc .= '</tr>';
146        }
147        $doc .= '</tbody></table>';
148        return $doc;
149    }
150
151    /**
152     * lists all known syntax modes and their sorting value
153     */
154    function _syntaxmodes_xhtml(){
155        $modes = p_get_parsermodes();
156        $doc  = '';
157
158        foreach ($modes as $mode){
159            $doc .= $mode['mode'].' ('.$mode['sort'].'), ';
160        }
161        return $doc;
162    }
163}
164
165//Setup VIM: ex: et ts=4 enc=utf-8 :
166