1<?php
2/**
3 * DokuWiki Plugin linkprefix (Renderer Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Heiko Barth
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) die();
11
12if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
13if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
14require_once DOKU_INC.'inc/parser/xhtml.php';
15
16class renderer_plugin_linkprefix extends Doku_Renderer_xhtml {
17	function getInfo() {
18		return confToHash(dirname(__FILE__).'/plugin.info.txt');
19	}
20
21	/**
22	* Make available as XHTML replacement renderer
23	*/
24	function canRender($format){
25		if($format == 'xhtml') return true;
26		return false;
27	}
28
29	function externallink($url, $name = null, $returnonly = false) {
30		if (!$this->getConf('prefix') || $this->getConf('ignore_same_domain') == 1 && strtolower(parse_url($url, PHP_URL_HOST)) == strtolower($_SERVER["HTTP_HOST"])) {
31			return parent::externallink($url, $name);
32		}
33
34		$name = ($name) ? $name : "$url";
35		$protocol = ($_SERVER["HTTPS"]) ? "https" : "http";
36		$url = $this->getConf('encode_url') ? urlencode($url) : $url;
37		if ($this->getConf('prefix') == DOKU_BASE . 'lib/plugins/linkprefix/redirect.php?') {
38			$url	= $protocol . "://" . $_SERVER["HTTP_HOST"] . $this->getConf('prefix') . $url;
39		}
40		else {
41			$url	= $this->getConf('prefix') . $url;
42		}
43		return parent::externallink($url, $name);
44	}
45
46	function _resolveInterWiki(&$shortcut, $reference, &$exists = null){
47		if (!$this->getConf('prefix')) {
48			return parent::_resolveInterWiki($shortcut,$reference);
49		}
50
51		$backup = $this->interwiki[$shortcut];
52		$url = $this->getConf('encode_url') ? urlencode($this->interwiki[$shortcut]) : $this->interwiki[$shortcut];
53		if ($backup) $this->interwiki[$shortcut] = $this->getConf('prefix') . $url;
54		$return = parent::_resolveInterWiki($shortcut,$reference);
55		$this->interwiki[$shortcut] = $backup;
56		return $return;
57	}
58}
59