3
* Action Plugin: Redirects page requests based on content
5
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
* @author David Lorentsen <zyberdog@quakenet.org>
9
if(!defined('DOKU_INC')) die();
11
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12
require_once(DOKU_PLUGIN.'action.php');
15
* All DokuWiki action plugins need to inherit from this class
17
class action_plugin_pageredirect extends DokuWiki_Action_Plugin {
24
'author' => 'David Lorentsen',
25
'email' => 'zyberdog@quakenet.org',
26
'date' => '2007-01-24',
27
'name' => 'Page Redirect',
28
'desc' => 'Redirects page requests based on content',
29
'url' => 'http://wiki.splitbrain.org/plugin:page_redirector',
33
function register(&$controller) {
3
* Action Plugin: Redirects page requests based on content
5
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
* @author Elan Ruusamäe <glen@delfi.ee>
7
* @author David Lorentsen <zyberdog@quakenet.org>
10
if(!defined('DOKU_INC')) die();
12
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13
require_once(DOKU_PLUGIN.'action.php');
16
* All DokuWiki action plugins need to inherit from this class
18
class action_plugin_pageredirect extends DokuWiki_Action_Plugin {
19
function register(&$controller) {
34
20
$controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handle_pageredirect_redirect');
35
21
$controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'handle_pageredirect_note');
36
22
$controller->register_hook('PARSER_METADATA_RENDER','BEFORE', $this, 'handle_pageredirect_metadata');
24
// This plugin goes first
25
$hooks =& $controller->_hooks[TPL_ACT_RENDER_BEFORE];
26
if ($hooks[0][0] != $this) {
27
array_unshift($hooks, array_pop($hooks));
39
function handle_pageredirect_redirect(&$event, $param) {
40
global $ID, $ACT, $REV;
42
if (($ACT == 'show' || $ACT == '') && empty($REV)) {
31
function handle_pageredirect_redirect(&$event, $param) {
32
global $ID, $ACT, $REV;
34
if (($ACT == 'show' || $ACT == '') && empty($REV)) {
43
35
$page = p_get_metadata($ID,'relation isreplacedby');
45
37
// return if no redirection data
46
38
if (empty($page)) { return; }
48
40
if (isset($_GET['redirect'])) {
49
// return if redirection is temporarily disabled,
41
// return if redirection is temporarily disabled,
50
42
// or we have been redirected 5 times in a row
51
43
if ($_GET['redirect'] == 'no' || $_GET['redirect'] > 4) { return; }
52
44
elseif ($_GET['redirect'] > 0) { $redirect = $_GET['redirect'] +1; }
58
// verify metadata currency
59
if (@filemtime(metaFN($ID,'.meta')) < @filemtime(wikiFN($ID))) { return; }
50
// verify metadata currency
51
if (@filemtime(metaFN($ID,'.meta')) < @filemtime(wikiFN($ID))) { return; }
61
53
if (!headers_sent() && $this->getConf('show_note')) {
62
54
// remember to show note about being redirected from another page
64
56
$_SESSION[DOKU_COOKIE]['redirect'] = $ID;
59
// preserve #section from $page
60
list($page, $section) = explode('#', $page, 2);
61
if (isset($section)) {
62
$section = '#' . $section;
68
header("Location: ".wl($page, Array('redirect' => $redirect), TRUE, '&'));
68
header("HTTP/1.1 301 Moved Permanently");
69
header("Location: ".wl($page, Array('redirect' => $redirect), TRUE, '&'). $section);
73
74
function handle_pageredirect_note(&$event, $param) {
76
77
if ($ACT == 'show' || $ACT == '') {
77
78
if (!$this->getConf('show_note')) { return; }
78
79
if (isset($_GET['redirect']) && $_GET['redirect'] > 0 && $_GET['redirect'] < 6) {
81
82
$page = $_SESSION[DOKU_COOKIE]['redirect'];
82
83
echo '<div class="noteredirect">'.sprintf($this->getLang('redirected_from'), '<a href="'.wl(':'.$page, Array('redirect' => 'no'), TRUE, '&').'" class="wikilink1" title="'.$page.'">'.$page.'</a>').'</div>';
83
84
unset($_SESSION[DOKU_COOKIE]['redirect']);
93
94
function handle_pageredirect_metadata(&$event, $param) {
94
if( isset($event→data→meta['relation']['isreplacedby'])) {
95
unset($event->data->meta['relation']['isreplacedby']);
95
if (isset($event->data->meta['relation'])) {
96
unset($event->data->meta['relation']['isreplacedby']);