1<?php 2/** 3 * directions Plugin - global directions component 4 * - shows the whole wiki navigational structure and graph 5 * 6 * Usage: <globaldirections>, <globaldirections graph> 7 * 8 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 9 * @author Nuno Flores <nuno.flores@gmail.com> 10 */ 11if (!defined('DOKU_INC')) die(); 12//if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 13if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 14require_once(DOKU_PLUGIN.'syntax.php'); 15require_once(DOKU_INC.'inc/common.php'); 16require_once(DOKU_INC.'inc/pageutils.php'); 17require_once(DOKU_INC.'inc/parserutils.php'); 18require_once(DOKU_INC.'inc/pluginutils.php'); 19require_once('common.php'); 20 21/** 22 * All DokuWiki plugins to extend the parser/rendering mechanism 23 * need to inherit from this class 24 */ 25class syntax_plugin_directions_globaldirections extends DokuWiki_Syntax_Plugin { 26 27 /** 28 * Get an associative array with plugin info. 29 * 30 * <p> 31 * The returned array holds the following fields: 32 * <dl> 33 * <dt>author</dt><dd>Author of the plugin</dd> 34 * <dt>email</dt><dd>Email address to contact the author</dd> 35 * <dt>date</dt><dd>Last modified date of the plugin in 36 * <tt>YYYY-MM-DD</tt> format</dd> 37 * <dt>name</dt><dd>Name of the plugin</dd> 38 * <dt>desc</dt><dd>Short description of the plugin (Text only)</dd> 39 * <dt>url</dt><dd>Website with more information on the plugin 40 * (eg. syntax description)</dd> 41 * </dl> 42 * @param none 43 * @return Array Information about this plugin class. 44 * @public 45 * @static 46 */ 47 function getInfo() { 48 return array( 49 'author' => 'Nuno Flores', 50 'email' => 'nuno.flores@gmail.com', 51 'date' => @file_get_contents(DOKU_PLUGIN.'directions/VERSION'), 52 'name' => 'directions Plugin (globaldirections component)', 53 'desc' => 'shows the whole wiki navigational structure and graph', 54 'url' => 'http://www.dokuwiki.org/plugin:directions', 55 ); 56} 57 58 /** 59 * Get the type of syntax this plugin defines. 60 * 61 * @param none 62 * @return String <tt>'substition'</tt> (i.e. 'substitution'). 63 * @public 64 * @static 65 */ 66 function getType(){ 67 return 'substition'; 68 //return 'nocache'; 69 } 70 71 /** 72 * What kind of syntax do we allow (optional) 73 */ 74// function getAllowedTypes() { 75// return array(); 76// } 77 78 /** 79 * Define how this plugin is handled regarding paragraphs. 80 * 81 * <p> 82 * This method is important for correct XHTML nesting. It returns 83 * one of the following values: 84 * </p> 85 * <dl> 86 * <dt>normal</dt><dd>The plugin can be used inside paragraphs.</dd> 87 * <dt>block</dt><dd>Open paragraphs need to be closed before 88 * plugin output.</dd> 89 * <dt>stack</dt><dd>Special case: Plugin wraps other paragraphs.</dd> 90 * </dl> 91 * @param none 92 * @return String <tt>'block'</tt>. 93 * @public 94 * @static 95 */ 96 function getPType(){ 97 return 'normal'; 98 } 99 100 /** 101 * Where to sort in? 102 * 103 * @param none 104 * @return Integer <tt>6</tt>. 105 * @public 106 * @static 107 */ 108 function getSort(){ 109 return 999; 110 } 111 112 113 /** 114 * Connect lookup pattern to lexer. 115 * 116 * @param $aMode String The desired rendermode. 117 * @return none 118 * @public 119 * @see render() 120 */ 121 function connectTo($mode) { 122 $this->Lexer->addSpecialPattern('<(?|globaldirections|globaldirections graph)>',$mode,'plugin_directions_globaldirections'); 123 } 124 125// function postConnect() { 126// } 127 128 /** 129 * Handler to prepare matched data for the rendering process. 130 * 131 * <p> 132 * The <tt>$aState</tt> parameter gives the type of pattern 133 * which triggered the call to this method: 134 * </p> 135 * <dl> 136 * <dt>DOKU_LEXER_ENTER</dt> 137 * <dd>a pattern set by <tt>addEntryPattern()</tt></dd> 138 * <dt>DOKU_LEXER_MATCHED</dt> 139 * <dd>a pattern set by <tt>addPattern()</tt></dd> 140 * <dt>DOKU_LEXER_EXIT</dt> 141 * <dd> a pattern set by <tt>addExitPattern()</tt></dd> 142 * <dt>DOKU_LEXER_SPECIAL</dt> 143 * <dd>a pattern set by <tt>addSpecialPattern()</tt></dd> 144 * <dt>DOKU_LEXER_UNMATCHED</dt> 145 * <dd>ordinary text encountered within the plugin's syntax mode 146 * which doesn't match any pattern.</dd> 147 * </dl> 148 * @param $aMatch String The text matched by the patterns. 149 * @param $aState Integer The lexer state for the match. 150 * @param $aPos Integer The character position of the matched text. 151 * @param $aHandler Object Reference to the Doku_Handler object. 152 * @return Integer The current lexer state for the match. 153 * @public 154 * @see render() 155 * @static 156 */ 157 function handle($match, $state, $pos, &$handler){ 158 159 switch ($state) { 160 case DOKU_LEXER_ENTER : 161 break; 162 case DOKU_LEXER_MATCHED : 163 break; 164 case DOKU_LEXER_UNMATCHED : 165 break; 166 case DOKU_LEXER_EXIT : 167 break; 168 case DOKU_LEXER_SPECIAL : 169 break; 170 } 171 172 $result = array(); 173 174 // check for graph atttribute 175 $graph = trim(substr($match,-7,-1)); 176 $result[] = $graph; 177 178 // parse hits file 179 $registeredOnly = ($this->getConf('registeredOnly') == 0) ? false : true; 180 $filename = DOKU_INC . $this->getConf('hitslog'); 181 $result[] = dir_parseHitsFile($filename, $registeredOnly); 182 183 return $result; 184 } 185 186 /** 187 * Handle the actual output creation. 188 * 189 * <p> 190 * The method checks for the given <tt>$aFormat</tt> and returns 191 * <tt>FALSE</tt> when a format isn't supported. <tt>$aRenderer</tt> 192 * contains a reference to the renderer object which is currently 193 * handling the rendering. The contents of <tt>$aData</tt> is the 194 * return value of the <tt>handle()</tt> method. 195 * </p> 196 * @param $aFormat String The output format to generate. 197 * @param $aRenderer Object A reference to the renderer object. 198 * @param $aData Array The data created by the <tt>handle()</tt> 199 * method. 200 * @return Boolean <tt>TRUE</tt> if rendered successfully, or 201 * <tt>FALSE</tt> otherwise. 202 * @public 203 * @see handle() 204 */ 205 function render($mode, &$renderer, $data) { 206 207 if($mode == 'xhtml'){ 208 if (!is_array($data)) { 209 $renderer->doc .= "<b>directions plug-in (globaldirections component): Returned data in 'render' function is not an array</b>"; 210 return false; 211 } 212 213 // check if graphviz plugin exists. 214 $graph = (strcmp($data[0],'graph') == 0) ? true : false; 215 216 if ($graph) { 217 if(!in_array('graphviz',plugin_list())) { 218 $renderer->doc .= '<p><i>(directions plug-in: To view the graph the graphviz plug-in must be installed.)</i></p>'; 219 } else { 220 //graph 221 $renderer->doc .= dir_generateGraph($this->getInfo(),$data[1]); 222 } 223 } 224 225 // table of jumps 226 $renderer->doc .= dir_generateListofJumps($data[1]); 227 228 return true; 229 } 230 return false; 231 } 232} 233 234//Setup VIM: ex: et ts=4 enc=utf-8 : 235?>