1<?php 2 3use dokuwiki\Extension\SyntaxPlugin; 4 5/** 6 * DokuWiki Plugin golocal (Syntax Component) 7 * 8 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 9 * @author Andreas Gohr <dokuwiki@cosmocode.de> 10 */ 11class syntax_plugin_golocal extends SyntaxPlugin 12{ 13 /** @inheritDoc */ 14 public function getType() 15 { 16 return 'substition'; 17 } 18 19 /** @inheritDoc */ 20 public function getPType() 21 { 22 return 'normal'; 23 } 24 25 /** @inheritDoc */ 26 public function getSort() 27 { 28 return 150; 29 } 30 31 /** @inheritDoc */ 32 public function connectTo($mode) 33 { 34 $this->Lexer->addSpecialPattern('\\[\\[[C-Z]:\\\\[^]]*\\]\\]', $mode, 'plugin_golocal'); 35 } 36 37 38 /** @inheritDoc */ 39 public function handle($match, $state, $pos, Doku_Handler $handler) 40 { 41 $match = substr($match, 2, -2); 42 [$path, $title] = sexplode('|', $match, 2); 43 $path = trim($path); 44 $title = trim($title); 45 if (!$title) $title = $path; 46 47 return [$path, $title]; 48 } 49 50 /** @inheritDoc */ 51 public function render($mode, Doku_Renderer $renderer, $data) 52 { 53 if ($mode == 'xhtml') { 54 $params = [ 55 'href' => 'file:////' . str_replace(':', '/', str_replace('\\', '/', $data[0])), 56 'title' => $data[0], 57 'class' => 'windows' 58 ]; 59 60 $renderer->doc .= '<a ' . buildAttributes($params) . '>' . hsc($data[1]) . '</a>'; 61 } else { 62 $renderer->cdata($data[1]); 63 } 64 65 return true; 66 } 67} 68