backup de julho
[h2N7SspZmY.git] / lib / plugins / info / syntax.php
blobdc0a7d2fc89ae9b75dae6be7b4b477439c1be08e
1 <?php
2 /**
3 * Info Plugin: Displays information about various DokuWiki internals
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Andreas Gohr <andi@splitbrain.org>
7 * @author Esther Brunner <wikidesign@gmail.com>
8 */
9 // must be run within Dokuwiki
10 if(!defined('DOKU_INC')) die();
12 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13 require_once(DOKU_PLUGIN.'syntax.php');
15 /**
16 * All DokuWiki plugins to extend the parser/rendering mechanism
17 * need to inherit from this class
19 class syntax_plugin_info extends DokuWiki_Syntax_Plugin {
21 /**
22 * return some info
24 function getInfo(){
25 return array(
26 'author' => 'Andreas Gohr',
27 'email' => 'andi@splitbrain.org',
28 'date' => '2008-09-12',
29 'name' => 'Info Plugin',
30 'desc' => 'Displays information about various DokuWiki internals',
31 'url' => 'http://dokuwiki.org/plugin:info',
35 /**
36 * What kind of syntax are we?
38 function getType(){
39 return 'substition';
42 /**
43 * What about paragraphs?
45 function getPType(){
46 return 'block';
49 /**
50 * Where to sort in?
52 function getSort(){
53 return 155;
57 /**
58 * Connect pattern to lexer
60 function connectTo($mode) {
61 $this->Lexer->addSpecialPattern('~~INFO:\w+~~',$mode,'plugin_info');
65 /**
66 * Handle the match
68 function handle($match, $state, $pos, &$handler){
69 $match = substr($match,7,-2); //strip ~~INFO: from start and ~~ from end
70 return array(strtolower($match));
73 /**
74 * Create output
76 function render($format, &$renderer, $data) {
77 if($format == 'xhtml'){
78 //handle various info stuff
79 switch ($data[0]){
80 case 'version':
81 $renderer->doc .= getVersion();
82 break;
83 case 'syntaxmodes':
84 $renderer->doc .= $this->_syntaxmodes_xhtml();
85 break;
86 case 'syntaxtypes':
87 $renderer->doc .= $this->_syntaxtypes_xhtml();
88 break;
89 case 'syntaxplugins':
90 $this->_plugins_xhtml('syntax', $renderer);
91 break;
92 case 'adminplugins':
93 $this->_plugins_xhtml('admin', $renderer);
94 break;
95 case 'actionplugins':
96 $this->_plugins_xhtml('action', $renderer);
97 break;
98 case 'rendererplugins':
99 $this->_plugins_xhtml('renderer', $renderer);
100 break;
101 case 'helperplugins':
102 $this->_plugins_xhtml('helper', $renderer);
103 break;
104 case 'helpermethods':
105 $this->_helpermethods_xhtml($renderer);
106 break;
107 default:
108 $renderer->doc .= "no info about ".htmlspecialchars($data[0]);
110 return true;
112 return false;
116 * list all installed plugins
118 * uses some of the original renderer methods
120 function _plugins_xhtml($type, &$renderer){
121 global $lang;
122 $renderer->doc .= '<ul>';
124 $plugins = plugin_list($type);
125 $plginfo = array();
127 // remove subparts
128 foreach($plugins as $p){
129 if (!$po =& plugin_load($type,$p)) continue;
130 list($name,$part) = explode('_',$p,2);
131 $plginfo[$name] = $po->getInfo();
134 // list them
135 foreach($plginfo as $info){
136 $renderer->doc .= '<li><div class="li">';
137 $renderer->externallink($info['url'],$info['name']);
138 $renderer->doc .= ' ';
139 $renderer->doc .= '<em>'.$info['date'].'</em>';
140 $renderer->doc .= ' ';
141 $renderer->doc .= $lang['by'];
142 $renderer->doc .= ' ';
143 $renderer->emaillink($info['email'],$info['author']);
144 $renderer->doc .= '<br />';
145 $renderer->doc .= strtr(hsc($info['desc']),array("\n"=>"<br />"));
146 $renderer->doc .= '</div></li>';
147 unset($po);
150 $renderer->doc .= '</ul>';
154 * list all installed plugins
156 * uses some of the original renderer methods
158 function _helpermethods_xhtml(&$renderer){
159 global $lang;
161 $plugins = plugin_list('helper');
162 foreach($plugins as $p){
163 if (!$po =& plugin_load('helper',$p)) continue;
165 if (!method_exists($po, 'getMethods')) continue;
166 $methods = $po->getMethods();
167 $info = $po->getInfo();
169 $hid = $this->_addToTOC($info['name'], 2, $renderer);
170 $doc = '<h2><a name="'.$hid.'" id="'.$hid.'">'.hsc($info['name']).'</a></h2>';
171 $doc .= '<div class="level2">';
172 $doc .= '<p>'.strtr(hsc($info['desc']), array("\n"=>"<br />")).'</p>';
173 $doc .= '<pre class="code">$'.$p." =& plugin_load('helper', '".$p."');</pre>";
174 $doc .= '</div>';
175 foreach ($methods as $method){
176 $title = '$'.$p.'->'.$method['name'].'()';
177 $hid = $this->_addToTOC($title, 3, $renderer);
178 $doc .= '<h3><a name="'.$hid.'" id="'.$hid.'">'.hsc($title).'</a></h3>';
179 $doc .= '<div class="level3">';
180 $doc .= '<table class="inline"><tbody>';
181 $doc .= '<tr><th>Description</th><td colspan="2">'.$method['desc'].
182 '</td></tr>';
183 if ($method['params']){
184 $c = count($method['params']);
185 $doc .= '<tr><th rowspan="'.$c.'">Parameters</th><td>';
186 $params = array();
187 foreach ($method['params'] as $desc => $type){
188 $params[] = hsc($desc).'</td><td>'.hsc($type);
190 $doc .= join($params, '</td></tr><tr><td>').'</td></tr>';
192 if ($method['return']){
193 $doc .= '<tr><th>Return value</th><td>'.hsc(key($method['return'])).
194 '</td><td>'.hsc(current($method['return'])).'</td></tr>';
196 $doc .= '</tbody></table>';
197 $doc .= '</div>';
199 unset($po);
201 $renderer->doc .= $doc;
206 * lists all known syntax types and their registered modes
208 function _syntaxtypes_xhtml(){
209 global $PARSER_MODES;
210 $doc = '';
212 $doc .= '<table class="inline"><tbody>';
213 foreach($PARSER_MODES as $mode => $modes){
214 $doc .= '<tr>';
215 $doc .= '<td class="leftalign">';
216 $doc .= $mode;
217 $doc .= '</td>';
218 $doc .= '<td class="leftalign">';
219 $doc .= join(', ',$modes);
220 $doc .= '</td>';
221 $doc .= '</tr>';
223 $doc .= '</tbody></table>';
224 return $doc;
228 * lists all known syntax modes and their sorting value
230 function _syntaxmodes_xhtml(){
231 $modes = p_get_parsermodes();
232 $doc = '';
234 foreach ($modes as $mode){
235 $doc .= $mode['mode'].' ('.$mode['sort'].'), ';
237 return $doc;
241 * Adds a TOC item
243 function _addToTOC($text, $level, &$renderer){
244 global $conf;
246 if (($level >= $conf['toptoclevel']) && ($level <= $conf['maxtoclevel'])){
247 $hid = $renderer->_headerToLink($text, 'true');
248 $renderer->toc[] = array(
249 'hid' => $hid,
250 'title' => $text,
251 'type' => 'ul',
252 'level' => $level - $conf['toptoclevel'] + 1
255 return $hid;
259 //Setup VIM: ex: et ts=4 enc=utf-8 :