1<?php 2/** 3 * This plugin allows to add an unordered list of toolbar-Links 4 * It can be used to create the wiki-syntax of a list that is needed by 5 * the plugin topbarsyntax to show a tabfolder. 6 * 7 * 8 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 9 * @author Dietrich Wittenberg <info.wittenberg@online.de> 10 */ 11 12// must be run within Dokuwiki 13//if(!defined('DOKU_INC')) die(); 14 15if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 16if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 17require_once(DOKU_PLUGIN.'syntax.php'); 18 19// 20 21class syntax_plugin_dwspecialist extends DokuWiki_Syntax_Plugin { 22 23 function syntax_plugin_dwspecialist() { 24 } 25 26/* not longer needed for DokuWiki 2009-12-25 “Lemming” and later 27 function getInfo(){ 28 return array( 29 'author' => 'Dietrich Wittenberg', 30 'email' => 'info.wittenberg@online.de', 31 'date' => '2012-07-01', 32 'name' => 'plugin dwspecialist', 33 'desc' => 'includes an unordered list used as a menu', 34 'url' => 'http://dokuwiki.org/plugin:dwspecialist', 35 ); 36 } 37*/ 38 39 function getType(){ return 'substition'; } 40 function getAllowedTypes() { return array('disabled'); } 41 function getPType(){ return 'block'; } 42 function getSort(){ return 160; } 43 44 45 function connectTo($mode) { 46 $this->Lexer->addEntryPattern('<specialist>(?=.*?</specialist>)', $mode, 'plugin_dwspecialist' ); // the entry of <specialist> 47 $this->Lexer->addPattern('\n {2,}/*?[ ]*[^\n<]*<special[^\n>]*>', 'plugin_dwspecialist' ); // {\n * BlaBla <special ...>} 48 $this->Lexer->addPattern('\n {2,}/*?[ ]*<special[^\n>]*>', 'plugin_dwspecialist' ); // {\n * <special ...>} 49 $this->Lexer->addPattern('\n[ ]*<special[^\n>]*>', 'plugin_dwspecialist' ); // {\n <special ...>} 50 $this->Lexer->addPattern('[^\n<]<special[^\n>]*>', 'plugin_dwspecialist' ); // {BlaBla <special ...>} 51 } 52 //$this->Lexer->addSpecialPattern('<test>',$mode,'plugin_dwlistmenu'); 53 function postConnect() { $this->Lexer->addExitPattern('</specialist\>', 'plugin_dwspecialist');} // the exit of <specialist> 54 55 56 /** 57 * Handle the match 58 */ 59 function handle($match, $state, $pos, &$handler){ 60 61 switch ($state) { 62 case DOKU_LEXER_ENTER: 63 break; 64 65 case DOKU_LEXER_UNMATCHED: 66 return array($state, $match); 67 break; 68 69 case DOKU_LEXER_MATCHED: 70 if (preg_match('#(\n)( {2,}[/*]?)([ ]*[^\n<]*)<special([^\n>]*)>#', $match, $result)) { 71 } elseif (preg_match('#(\n)( {2,}[/*]?)([ ]*)<special([^\n>]*)>#', $match, $result)) { 72 } elseif (preg_match('#(\n)([ ]*)()<special([^\n>]*)>#', $match, $result)) { 73 } elseif (preg_match('#()()([^\n<])<special([^\n>]*)>#', $match, $result)) { 74 } 75 return array($state, $result); 76 break; 77 78 case DOKU_LEXER_EXIT: 79 return array($state, ''); 80 break; 81 82 case DOKU_LEXER_SPECIAL : 83 return array($state, $match); 84 break; 85 } 86 return array(); 87 } 88 89 function _render_special($actions, $crlf, $listoffset, $prolog) { 90 global $conf; 91 global $lang; 92 global $INFO; 93 global $ID; 94 global $REV; 95 96 $id = getID(); 97 $rev = $conf['REV']; 98 99 $line=""; 100 foreach ($actions as $action) { 101 switch ($action) { 102 case "export_pdf": 103 $act=array( 'params' => array('do' => $action, 'rev' => $rev), 104 'type' => $action); 105 $name="Export PDF"; 106 $line.=$crlf.$listoffset.$prolog."[[".$id."?".http_build_query ($act['params'])."|".$name."]]"; 107 break; 108 109 case "edit": 110 case "history": 111 case "recent": 112 case "login": 113 case "profile": 114 case "index": 115 case "admin": 116 case "top": 117 case "back": 118 case "backlink": 119 case "subscribe": 120 case "subscription": 121 $act=tpl_get_action($action); //$act['params']['do']; is now defined 122 if ($act) { 123 $name=(key_exists('btn_'.$act['type'], $lang)) ? $lang['btn_'.$act['type']] : $action; 124 //$act['params']['id']=$ID; 125 $act['params']['rev']=$rev; 126 //$act['params']['sectoc']=getSecurityToken(); 127 128 $line.=$crlf.$listoffset.$prolog."[[".$id."?".http_build_query ($act['params'])."|".$name."]]"; 129 } else { 130 $line.=$crlf.$listoffset.$prolog.$action; 131 } 132 break; 133 134 case "topbar": 135 if ($this->getConf('topbarname')) { 136 $topbar=$this->getConf('topbarname'); 137 $line.=$crlf.$listoffset.$prolog."[[".$topbar."|Navigationsleiste]]"; 138 } 139 break; 140 141 case "breadcrumbs": 142 if(!$conf['breadcrumbs']) { 143 // special is empty 144 } else { 145 $i=1; 146 $special= array_reverse(breadcrumbs()); // array([plf:plf] => 'Projektleitfaden', ...) 147 foreach ($special as $id => $name) { 148 $wikilinks[]="[[".$id."|".(($i<10)?"0":"").$i.": ".$name."]]"; 149 $i++; 150 } 151 $line.=$crlf.$listoffset.$prolog.implode($crlf.$listoffset, $wikilinks); 152 } 153 break; 154 155 default: // action not defined 156 $line.=$crlf.$listoffset.$prolog.$action; 157 break; 158 } // switch 159 } 160 return $line; 161 } 162 163 /** 164 * Create output 165 */ 166 function render($mode, &$renderer, $data) { 167 //global $this->dwspecialist_content; 168 169 if($mode == 'xhtml'){ 170 list($state,$match) = $data; 171 switch ($state) { 172 case DOKU_LEXER_ENTER: 173 $this->dwspecialist_content=""; 174 break; 175 case DOKU_LEXER_UNMATCHED: 176 $this->dwspecialist_content.=$match; //$renderer->_xmlEntities($match); 177 break; 178 case DOKU_LEXER_MATCHED: 179 180 // not in handle because $INFO is not initialized 181 list($matchall, $crlf, $listoffset, $prolog, $parameter)=$match; 182 if ($matchall != "") { // any match 183 $parameters=explode("&", $parameter); 184 $wikitext=""; 185 186 foreach ($parameters as $action) { 187 $action=trim($action); 188 switch ($action) { 189 case "page_tools": 190 $wikitext.=$this->_render_special(array($action), $crlf, $listoffset, $prolog); 191 $actions=array("edit", "revert", "revisions", "backlink", "subscribe"); 192 $wikitext.=$this->_render_special($actions, $crlf, " ".$listoffset, $prolog); 193 break; 194 case "site_tools": 195 $wikitext.=$this->_render_special(array($action), $crlf, $listoffset, $prolog); 196 $actions=array("recent", "media", "index"); 197 $wikitext.=$this->_render_special($actions, $crlf, " ".$listoffset, $prolog); 198 break; 199 case "user_tools": 200 $wikitext.=$this->_render_special(array($action), $crlf, $listoffset, $prolog); 201 $actions=array("login", "register", "profile", "admin"); 202 $wikitext.=$this->_render_special($actions, $crlf, " ".$listoffset, $prolog); 203 break; 204 205 default: 206 $wikitext.=$this->_render_special(array($action), $crlf, $listoffset, $prolog); 207 break; 208 } // switch 209 } // foreach 210 } // !($match=="") 211 212 //return array($state, $match); 213 214 $this->dwspecialist_content.=$wikitext; //$renderer->_xmlEntities($match); 215 break; 216 case DOKU_LEXER_EXIT: 217 $renderer->info['cache'] = false; 218 $renderer->doc .= p_render($mode, p_get_instructions($this->dwspecialist_content), $info); 219 $this->dwspecialist_content=""; 220 break; 221 } 222 return true; 223 } 224 return false; 225 } 226 227} 228//Setup VIM: ex: et ts=4 enc=utf-8 : 229