1 <?php 2 /** 3 * Shortcut, anchor component: generates anchors for the shortcuts. 4 * 5 * $Id: anchor.php 43 2007-02-04 17:01:50Z wingedfox $ 6 * $HeadURL: https://svn.debugger.ru/repos/common/DokuWiki/Shortcut/tags/Shortcut.v0.1.0/syntax/anchor.php $ 7 * 8 * @lastmodified $Date: 2007-02-04 20:01:50 +0300 (Вск, 04 Фев 2007) $ 9 * @license LGPL 2 (http://www.gnu.org/licenses/lgpl.html) 10 * @author Ilya Lebedev <ilya@lebedev.net> 11 * @version $Rev: 43 $ 12 * @copyright (c) 2005-2007, Ilya Lebedev 13 */ 14 15 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 16 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 17 require_once(DOKU_PLUGIN.'syntax.php'); 18 19 /** 20 * All DokuWiki plugins to extend the parser/rendering mechanism 21 * need to inherit from this class 22 */ 23 class syntax_plugin_shortcut_anchor extends DokuWiki_Syntax_Plugin { 24 25 /** 26 * return some info 27 */ 28 function getInfo() { 29 preg_match("#^.*?Shortcut/([^\\/]+)#"," $HeadURL: https://svn.debugger.ru/repos/common/DokuWiki/Shortcut/tags/Shortcut.v0.1.0/syntax/anchor.php $ ", $v); 30 $v = preg_replace("#.*?((trunk|.v)[\d.]+)#","\\1",$v[1]); 31 $b = preg_replace("/\\D/","", " $Rev: 43 $ "); 32 33 return array( 'author' => "Ilya Lebedev" 34 ,'email' => 'ilya@lebedev.net' 35 ,'date' => preg_replace("#.*?(\d{4}-\d{2}-\d{2}).*#","\\1",'$Date: 2007-02-04 20:01:50 +0300 (Вск, 04 Фев 2007) $') 36 ,'name' => "Shortcut anchor module {$v}.$b" 37 ,'desc' => "Converts ordinary links to the shortcuts." 38 ,'url' => 'http://wiki.splitbrain.org/plugin:shortcut' 39 ); 40 } 41 42 /** 43 * What kind of syntax are we? 44 */ 45 function getType(){ 46 return 'substition'; 47 } 48 49 function getPType(){ 50 return 'normal'; 51 } 52 /** 53 * Where to sort in? 54 */ 55 function getSort(){ 56 return 199; 57 } 58 59 /** 60 * Connect pattern to lexer 61 */ 62 function connectTo($mode) { 63 $this->Lexer->addSpecialPattern('\[\[.+?\]\]',$mode,'plugin_shortcut_anchor'); 64 } 65 66 /** 67 * Handle the match 68 */ 69 function handle($match, $state, $pos, &$handler){ 70 return $match; 71 72 } 73 74 /** 75 * Render output 76 */ 77 function render($mode, &$renderer, $data) { 78 79 switch ($mode) { 80 case 'xhtml' : 81 $meta = p_get_metadata('shortcuts','shortcut'); 82 list($url, $title) = explode("|",trim($data,'[]')); 83 $url = trim($url); 84 $title = trim($title); 85 $title = $title?$title 86 :($tgt['title']?$tgt['title'] 87 :$url); 88 if ($tgt = $meta[cleanID($url)]) { 89 $renderer->doc .= '<a href="'.wl($tgt['target']) 90 .'" id="shortcut_'.str_replace(":","_",cleanID($tgt['target'])) 91 .'" title="'.$title.'"><span>' 92 .($title).'</span></a>'; 93 $renderer->nest($tgt['desc']); 94 return true; 95 } else { 96 $h = new Doku_Handler(); 97 $h->internallink($data,"",0); 98 $renderer->nest($h->calls); 99 } 100 break; 101 case 'metadata' : 102 break; 103 } 104 return false; 105 } 106 } // Shortcut_anchor class end