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 * What kind of syntax are we? 21 */ 22 function getType(){ 23 return 'substition'; 24 } 25 26 /** 27 * Where to sort in? 28 */ 29 function getSort(){ 30 return 155; 31 } 32 33 34 /** 35 * Connect pattern to lexer 36 */ 37 function connectTo($mode) { 38 $this->Lexer->addSpecialPattern('~~INFO:\w+~~',$mode,'plugin_info'); 39 } 40 41 42 /** 43 * Handle the match 44 */ 45 function handle($match, $state, $pos, &$handler){ 46 $match = substr($match,7,-2); //strip ~~INFO: from start and ~~ from end 47 return array(strtolower($match)); 48 } 49 50 /** 51 * Create output 52 */ 53 function render($mode, &$renderer, $data) { 54 if($mode == 'xhtml'){ 55 //handle various info stuff 56 switch ($data[0]){ 57 case 'version'; 58 $renderer->doc .= getVersion(); 59 break; 60 case 'syntaxmodes'; 61 $renderer->doc .= $this->_syntaxmodes_xhtml(); 62 break; 63 case 'syntaxtypes'; 64 $renderer->doc .= $this->_syntaxtypes_xhtml(); 65 break; 66 default: 67 $renderer->doc .= "no info about ".htmlspecialchars($data[0]); 68 } 69 return true; 70 } 71 return false; 72 } 73 74 /** 75 * lists all known syntax types and their registered modes 76 */ 77 function _syntaxtypes_xhtml(){ 78 global $PARSER_MODES; 79 $doc = ''; 80 81 $doc .= '<table class="inline"><tbody>'; 82 foreach($PARSER_MODES as $mode => $modes){ 83 $doc .= '<tr>'; 84 $doc .= '<td class="leftalign">'; 85 $doc .= $mode; 86 $doc .= '</td>'; 87 $doc .= '<td class="leftalign">'; 88 $doc .= join(', ',$modes); 89 $doc .= '</td>'; 90 $doc .= '</tr>'; 91 } 92 $doc .= '</tbody></table>'; 93 return $doc; 94 } 95 96 /** 97 * lists all known syntax modes and their sorting value 98 */ 99 function _syntaxmodes_xhtml(){ 100 $modes = p_get_parsermodes(); 101 $doc = ''; 102 103 foreach ($modes as $mode){ 104 $doc .= $mode['mode'].' ('.$mode['sort'].'), '; 105 } 106 return $doc; 107 } 108} 109 110//Setup VIM: ex: et ts=4 enc=utf-8 : 111