-
Notifications
You must be signed in to change notification settings - Fork 14
/
helper.php
88 lines (78 loc) · 2.21 KB
/
helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Redirect plugin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
/**
* Class helper_plugin_redirect
*
* Save and load the config file
*/
class helper_plugin_redirect extends DokuWiki_Admin_Plugin {
const CONFIG_FILE = DOKU_CONF . '/redirect.conf';
const LEGACY_FILE = __DIR__ . '/redirect.conf';
/**
* helper_plugin_redirect constructor.
*
* handles the legacy file
*/
public function __construct() {
// move config from plugin directory to conf directory
if(!file_exists(self::CONFIG_FILE) &&
file_exists(self::LEGACY_FILE)) {
rename(self::LEGACY_FILE, self::CONFIG_FILE);
}
}
/**
* Saves the config file
*
* @param string $config the raw text for the config
* @return bool
*/
public function saveConfigFile($config) {
return io_saveFile(self::CONFIG_FILE, cleanText($config));
}
/**
* Load the config file
*
* @return string the raw text of the config
*/
public function loadConfigFile() {
if(!file_exists(self::CONFIG_FILE)) return '';
return io_readFile(self::CONFIG_FILE);
}
/**
* Get the redirect URL for a given ID
*
* Handles conf['showmsg']
*
* @param string $id the ID for which the redirect is wanted
* @return bool|string the full URL to redirect to
*/
public function getRedirectURL($id) {
$redirects = confToHash(self::CONFIG_FILE);
if(empty($redirects[$id])) return false;
if(preg_match('/^https?:\/\//', $redirects[$id])) {
$url = $redirects[$id];
} else {
if($this->getConf('showmsg')) {
msg(sprintf($this->getLang('redirected'), hsc($id)));
}
$link = explode('#', $redirects[$id], 2);
$url = wl($link[0], '', true, '&');
if(isset($link[1])) $url .= '#' . rawurlencode($link[1]);
}
return $url;
}
/**
* Dummy implementation of an abstract method
*/
public function html()
{
return '';
}
}