1<?php 2/** 3 * Action link plugin. Lets you use action links in your wiki syntax. 4 * Based on the core function - tpl_actionlink(). 5 * 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author Andreas Gohr <andi@splitbrain.org> 8 * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> 9 * @author nowotny <nowotnypl@gmail.com> 10 * @author Chang Zhao https://github.com/chang-zhao/ 11 */ 12 13if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 14if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 15require_once(DOKU_PLUGIN.'syntax.php'); 16require_once(DOKU_INC.'inc/template.php'); //mod 17 18class syntax_plugin_actionlink extends DokuWiki_Syntax_Plugin { 19 20 function getInfo(){ 21 return array( 22 'author' => 'nowotny', 23 'email' => 'nowotnypl@gmail.com', 24 'date' => '2006-05-26', 25 'name' => 'Actionlink plugin', 26 'desc' => 'Actionlink plugin lets you use action links in your wiki syntax. 27 Basic syntax: {{actionlink>action|title}}', 28 'url' => 'http://dokuwiki.org/plugin:actionlink', 29 ); 30 } 31 32 function getType(){ 33 return 'substition'; 34 } 35 36 function getSort(){ 37 return 306; 38 } 39 40 function connectTo($mode) { 41 $this->Lexer->addSpecialPattern('\{\{actionlink>.+?\}\}',$mode,'plugin_actionlink'); 42 } 43 44 function handle($match, $state, $pos, $handler){ 45 $match = substr($match,13, -2); 46 $matches=explode('|', $match, 2); 47 return array('action'=>hsc($matches[0]),'title'=>hsc($matches[1])); 48 } 49 50 function render($mode, $renderer, $data){ 51 if($mode == 'xhtml'){ 52 53 if(!empty($data['action'])) $action=$data['action']; 54 else $action=''; 55 if(!empty($data['title'])) $title=$data['title']; 56 57 global $ID; 58 global $INFO; 59 global $REV; 60 global $ACT; 61 global $conf; 62 global $lang; 63 global $auth; 64 65 switch($action){ 66 case 'edit': 67 #most complicated type - we need to decide on current action 68 if($ACT == 'show' || $ACT == 'search'){ 69 if($INFO['writable']){ 70 if($INFO['exists']){ 71 if(!isset($title)) $title=$lang['btn_edit']; 72 $renderer->doc .=$this->tpll_link(wl($ID,'do=edit&rev='.$REV), 73 $title, 74 'class="action edit" accesskey="e" rel="nofollow"'); 75 }else{ 76 if(!isset($title)) $title=$lang['btn_create']; 77 $renderer->doc .=$this->tpll_link(wl($ID,'do=edit&rev='.$REV), 78 $title, 79 'class="action create" accesskey="e" rel="nofollow"'); 80 } 81 }else{ 82 if(!isset($title)) $title=$lang['btn_source']; 83 $renderer->doc .=$this->tpll_link(wl($ID,'do=edit&rev='.$REV), 84 $title, 85 'class="action source" accesskey="v" rel="nofollow"'); 86 } 87 }else{ 88 if(!isset($title)) $title=$lang['btn_show']; 89 $renderer->doc .=$this->tpll_link(wl($ID,'do=show'), 90 $title, 91 'class="action show" accesskey="v" rel="nofollow"'); 92 } 93 return true; 94 case 'history': 95 if(!isset($title)) $title=$lang['btn_revs']; 96 $renderer->doc .=$this->tpll_link(wl($ID,'do=revisions'),$title,'class="action revisions" accesskey="o"'); 97 return true; 98 case 'recent': 99 if(!isset($title)) $title=$lang['btn_recent']; 100 $renderer->doc .=$this->tpll_link(wl($ID,'do=recent'),$title,'class="action recent" accesskey="r"'); 101 return true; 102 case ':recent': 103 case '/recent': 104 if(!isset($title)) $title=$lang['btn_recent']; 105 $renderer->doc .=$this->tpll_link(wl('','do=recent'),$title,'class="action recent" accesskey="r"'); 106 return true; 107 case 'index': 108 if(!isset($title)) $title=$lang['btn_index']; 109 $renderer->doc .=$this->tpll_link(wl($ID,'do=index'),$title,'class="action index" accesskey="x"'); 110 return true; 111 case 'top': 112 if(!isset($title)) $title=$lang['btn_top']; 113 $renderer->doc .= '<a href="#dokuwiki__top" class="action top" accesskey="x">'.$title.'</a>'; 114 return true; 115 case 'search': 116 if(!isset($title)) $title=$lang['search']; 117 $renderer->doc .= '<a href="javascript:dw__search.id.focus()" class="action search" accesskey="f">'.$title.'</a>'; 118 return true; 119 case 'back': 120 if ($ID = tpl_getparent($ID)) { 121 if(!isset($title)) $title=$lang['btn_back']; 122 $renderer->doc .=$this->tpll_link(wl($ID,'do=show'),$title,'class="action back" accesskey="b"'); 123 return true; 124 } 125 return false; 126 case 'login': 127 if($conf['useacl']){ 128 if($_SERVER['REMOTE_USER']){ 129 if(!isset($title)) $title=$lang['btn_logout']; 130 $renderer->doc .=$this->tpll_link(wl($ID,'do=logout'),$title,'class="action logout"'); 131 }else{ 132 if(!isset($title)) $title=$lang['btn_login']; 133 $renderer->doc .=$this->tpll_link(wl($ID,'do=login'),$title,'class="action logout"'); 134 } 135 return true; 136 } 137 return false; 138 case 'admin': 139 if($INFO['perm'] == AUTH_ADMIN){ 140 if(!isset($title)) $title=$lang['btn_admin']; 141 $renderer->doc .=$this->tpll_link(wl($ID,'do=admin'),$title,'class="action admin"'); 142 return true; 143 } 144 return false; 145 case 'backlink': 146 if(!isset($title)) $title=$lang['btn_backlink']; 147 $renderer->doc .=$this->tpll_link(wl($ID,'do=backlink'),$title, 'class="action backlink"'); 148 return true; 149 case 'purge': // {{actionlink>purge|Purge}} 150 if(!isset($title)) $title=$lang['btn_purge']; 151 $renderer->doc .=$this->tpll_link(wl($ID,'purge=true'),$title, 'class="action purge"'); 152 return true; 153 case 'subscribe': //mod 154 if(!isset($title)) $title=$lang['btn_subscribe']; 155 $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"subscribe"), false, "&"),$title,'class="action subscribe"'); 156 return true; 157 case 'addtobook': //mod 158 if(!isset($title)) $title=$lang['btn_addtobook']; 159 $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"addtobook"), false, "&"),$title,'class="action addtobook"'); 160 return true; 161 case 'cite': //mod 162 if(!isset($title)) $title=$lang['btn_cite']; 163 $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"cite"), false, "&"),$title,'class="action cite"'); 164 return true; 165 case 'infomail': //mod 166 if(!isset($title)) $title=$lang['btn_infomail']; 167 $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"infomail"), false, "&"),$title,'class="action infomail"'); 168 return true; 169 case 'export_odt': //mod 170 if(!isset($title)) $title=$lang['btn_export_odt']; 171 $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"export_odt"), false, "&"),$title,'class="action export_odt"'); 172 return true; 173 case 'export_pdf': //mod 174 if(!isset($title)) $title=$lang['btn_export_pdf']; 175 $renderer->doc .=$this->tpll_link(wl($ID, array("do"=>"export_pdf"), false, "&"),$title,'class="action export_pdf"'); 176 return true; 177 default: 178 if(!isset($title)) $title=''; 179 $this_link_start=$action{0}; 180 switch ($this_link_start) { 181 case '/': 182 $this_link_prefix='http://'.$_SERVER['SERVER_NAME']; break; 183 case '#': 184 $this_link_prefix=''; break; 185 default: 186 $renderer->doc .= $title; 187 return true; 188 } 189 $renderer->doc .= '<a href="'.$this_link_prefix.$action.'">'.$title.'</a>'; 190 return true; 191 } 192 } 193 return false; 194 } 195 function tpll_link($url,$name,$more=''){ 196 $link='<a href="'.$url.'" '; 197 if ($more) $link.=' '.$more; 198 $link.=">$name</a>"; 199 return $link; 200} 201} 202 203//Setup VIM: ex: et ts=4 enc=utf-8 : 204