1<?php 2/** 3 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 4 * @author Brend Wanders <b.wanders@utwente.nl> 5 */ 6// must be run within Dokuwiki 7if(!defined('DOKU_INC')) die('Meh.'); 8 9/** 10 * The multi-purpose link type. 11 */ 12class plugin_strata_type_link extends plugin_strata_type { 13 function render($mode, &$renderer, &$triples, $value, $hint) { 14 if(preg_match('/^[a-zA-Z0-9\.]+>{1}.*$/u',$value)) { 15 // Interwiki 16 $interwiki = explode('>',$value,2); 17 $renderer->interwikilink($value,$hint, strtolower($interwiki[0]), $interwiki[1]); 18 19 } elseif(preg_match('/^\\\\\\\\[^\\\\]+?\\\\/u',$value)) { 20 $renderer->windowssharelink($value,$hint); 21 22 } elseif(preg_match('#^([a-z0-9\-\.+]+?)://#i',$value)) { 23 $renderer->externallink($value,$hint); 24 25 } elseif(preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$value)) { 26 $renderer->emaillink($value,$hint); 27 28 } else { 29 $renderer->internallink(':'.$value, $hint); 30 } 31 32 return true; 33 } 34 35 function normalize($value, $hint) { 36 // strip off leading [[ and trailing ]] to offer a more 37 // user-friendly syntax. 38 if(substr($value,0,2) == '[[' && substr($value,-2) == ']]') { 39 $value = substr($value,2,-2); 40 } 41 42 if(!preg_match('/^[a-zA-Z0-9\.]+>{1}.*$/u',$value) 43 && !preg_match('/^\\\\\\\\[^\\\\]+?\\\\/u',$value) 44 && !preg_match('#^([a-z0-9\-\.+]+?)://#i',$value) 45 && !preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$value)) { 46 $page = new plugin_strata_type_page(); 47 return $page->normalize($value,null); 48 } 49 50 return $value; 51 } 52 53 function getInfo() { 54 return array( 55 'desc'=>'Creates a link. This type is multi-purpose: it handles external links, interwiki links, email addresses, windows shares and normal wiki links (basically any link DokuWiki knows of). The optional hint will be used as link title.', 56 'hint'=>'The link title' 57 ); 58 } 59} 60