1<?php 2/** 3 * Plugin bookmark: Creates a bookmark to your document. 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Otto Vainio <plugins@valjakko.net> 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'syntax.php'); 12 13/** 14 * All DokuWiki plugins to extend the parser/rendering mechanism 15 * need to inherit from this class 16 */ 17class syntax_plugin_externallink extends DokuWiki_Syntax_Plugin { 18 19 /** 20 * return some info 21 */ 22 function getInfo(){ 23 return array( 24 'author' => 'Otto Vainio', 25 'email' => 'plugins@valjakko.net', 26 'date' => '2007-02-26', 27 'name' => 'externallink', 28 'desc' => 'Inserts a link to a page outside your wiki, but on your server with a style of wikilink. Format is [[@/pagename|optional title]]', 29 'url' => 'http://wiki.splitbrain.org/wiki:plugins', 30 ); 31 } 32 33 /** 34 * What kind of syntax are we? 35 */ 36 function getType(){ 37 return 'substition'; 38 } 39 40 // Just before build in links 41 function getSort(){ return 299; } 42 43 function connectTo($mode) { 44 $this->Lexer->addSpecialPattern('\[\[\@.*?\]\]',$mode,'plugin_externallink'); 45 } 46 47 48 /** 49 * Handle the match 50 */ 51 function handle($match, $state, $pos, &$handler){ 52 $match = substr($match,3,-2); //strip [[@ from start and ]] from end 53 $match = explode("|",$match); 54 return $match; 55 } 56 57 /** 58 * Create output 59 */ 60 function render($mode, &$renderer, $data) { 61 if($mode == 'xhtml'){ 62 $text=$this->_externallink($renderer, $data[0], $data[1]); 63 $renderer->doc .= $text; 64 return true; 65 } 66 return false; 67 } 68 69 70 function _externallink(&$renderer, $url, $name = NULL) { 71 global $conf; 72 // Just some basic cleaning 73 if(substr($url,0,7) == 'http://') { 74 list($foo,$url) = explode("/",substr($url,7),2); 75 } 76 if(substr($url,0,5) == 'ftp://') { 77 list($foo,$url) = explode("/",substr($url,6),2); 78 } 79 if (!isset($name)) { 80 if (substr($url,0,1)=="/") { 81 $name=$_SERVER['HTTP_HOST'] . $url; 82 } elseif (substr($url,0,1)=="?") { 83 $name=$_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $url; 84 } else { 85 $name=$_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . $url; 86 } 87 } 88 89// $name = $renderer->_xmlEntities($renderer->_getLinkTitle($name, $url, $isImage)); 90 $name = $renderer->_getLinkTitle($name, $url, $isImage); 91 92 $class='wikilink1'; 93 $link['target'] = $conf['target']['wiki']; 94 $link['style'] = ''; 95 $link['pre'] = ''; 96 $link['suf'] = ''; 97 $link['more'] = ''; 98 $link['class'] = $class; 99 $link['url'] = $url; 100 $link['name'] = $name; 101 $link['title'] = $renderer->_xmlEntities($url); 102 103 //output formatted 104 return $renderer->_formatLink($link); 105 } 106 107} 108?>