1<?php 2 3use dokuwiki\Extension\SyntaxPlugin; 4 5/** 6 * BBCode plugin: allows BBCode markup familiar from forum software 7 * 8 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 9 * @author Esther Brunner <esther@kaffeehaus.ch> 10 */ 11class syntax_plugin_bbcode_link extends SyntaxPlugin 12{ 13 /** @inheritdoc */ 14 public function getType() 15 { 16 return 'substition'; 17 } 18 /** @inheritdoc */ 19 public function getSort() 20 { 21 return 105; 22 } 23 /** @inheritdoc */ 24 public function connectTo($mode) 25 { 26 $this->Lexer->addSpecialPattern('\[url.+?\[/url\]', $mode, 'plugin_bbcode_link'); 27 } 28 29 /** @inheritdoc */ 30 public function handle($match, $state, $pos, Doku_Handler $handler) 31 { 32 $match = substr($match, 5, -6); 33 if (preg_match('/".+?"/', $match)) $match = substr($match, 1, -1); // addition #1: unquote 34 [$url, $title] = sexplode(']', $match, 2, null); 35 36 // external link (accepts all protocols) 37 if (preg_match('#^([a-z0-9\-.+]+?)://#i', $url)) { 38 $handler->addCall('externallink', [$url,$title], $pos); 39 40 // local link 41 } elseif (preg_match('!^#.+!', $url)) { 42 $handler->addCall('locallink', [substr($url, 1),$title], $pos); 43 44 // internal link 45 } else { 46 $handler->addCall('internallink', [$url,$title], $pos); 47 } 48 return true; 49 } 50 51 /** @inheritdoc */ 52 public function render($format, Doku_Renderer $renderer, $data) 53 { 54 return true; 55 } 56} 57