~yoboy-leguesh/ubuntu-fr-doc/maj20150810a

« back to all changes in this revision

Viewing changes to lib/plugins/pageredirect/action.php

  • Committer: YoBoY
  • Date: 2012-10-24 19:05:18 UTC
  • mfrom: (114.1.3 maj-AdoraBelle)
  • Revision ID: yoboy.leguesh@gmail.com-20121024190518-bgtic5m3dt8gnzfn
Mise à jour de Dokuwiki 2012-10-13 "Adora Belle"
Application des patch ubuntu-fr d'optimisation
Ajout des thèmes ubuntu-fr
Ajout des plugins
Mise à jour des plugins box, orphanswanted, pageredirect, tag, cloud, forcepreview, pagelist
Désactivation de la nouvelle option d'envoie de notifications mail en html
Application des derniers patchs correctifs de Dokuwiki.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php 
2
 
/** 
3
 
 * Action Plugin:   Redirects page requests based on content 
4
 
 *  
5
 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html) 
6
 
 * @author     David Lorentsen <zyberdog@quakenet.org>   
7
 
 */ 
8
 
 
9
 
if(!defined('DOKU_INC')) die(); 
10
 
 
11
 
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 
12
 
require_once(DOKU_PLUGIN.'action.php'); 
13
 
 
14
 
/** 
15
 
 * All DokuWiki action plugins need to inherit from this class 
16
 
 */ 
17
 
class action_plugin_pageredirect extends DokuWiki_Action_Plugin { 
18
 
 
19
 
        /** 
20
 
         * return some info 
21
 
         */ 
22
 
        function getInfo(){ 
23
 
                return array( 
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', 
30
 
                ); 
31
 
        } 
32
 
        
33
 
        function register(&$controller) { 
 
1
<?php
 
2
/**
 
3
 * Action Plugin:   Redirects page requests based on content
 
4
 *
 
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>
 
8
 */
 
9
 
 
10
if(!defined('DOKU_INC')) die();
 
11
 
 
12
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 
13
require_once(DOKU_PLUGIN.'action.php');
 
14
 
 
15
/**
 
16
 * All DokuWiki action plugins need to inherit from this class
 
17
 */
 
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');
 
23
 
 
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));
 
28
                }
37
29
        }
38
30
 
39
 
        function handle_pageredirect_redirect(&$event, $param) { 
40
 
                global $ID, $ACT, $REV; 
41
 
                
42
 
                if (($ACT == 'show' || $ACT == '') && empty($REV)) { 
 
31
        function handle_pageredirect_redirect(&$event, $param) {
 
32
                global $ID, $ACT, $REV;
 
33
 
 
34
                if (($ACT == 'show' || $ACT == '') && empty($REV)) {
43
35
                        $page = p_get_metadata($ID,'relation isreplacedby');
44
 
                        
 
36
 
45
37
                        // return if no redirection data
46
38
                        if (empty($page)) { return; }
47
 
                        
 
39
 
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; }
54
46
                        } else {
55
47
                                $redirect = 1;
56
48
                        }
57
 
        
58
 
                        // verify metadata currency 
59
 
                        if (@filemtime(metaFN($ID,'.meta')) < @filemtime(wikiFN($ID))) { return; } 
60
 
                        
 
49
 
 
50
                        // verify metadata currency
 
51
                        if (@filemtime(metaFN($ID,'.meta')) < @filemtime(wikiFN($ID))) { return; }
 
52
 
61
53
                        if (!headers_sent() && $this->getConf('show_note')) {
62
54
                                // remember to show note about being redirected from another page
63
55
                                session_start();
64
56
                                $_SESSION[DOKU_COOKIE]['redirect'] = $ID;
65
57
                        }
66
 
        
 
58
 
 
59
                        // preserve #section from $page
 
60
                        list($page, $section) = explode('#', $page, 2);
 
61
                        if (isset($section)) {
 
62
                                $section = '#' . $section;
 
63
                        } else {
 
64
                                $section = '';
 
65
                        }
 
66
 
67
67
                        // redirect
68
 
                        header("Location: ".wl($page, Array('redirect' => $redirect), TRUE, '&')); 
69
 
                        exit(); 
70
 
                } 
 
68
                        header("HTTP/1.1 301 Moved Permanently");
 
69
                        header("Location: ".wl($page, Array('redirect' => $redirect), TRUE, '&'). $section);
 
70
                        exit();
 
71
                }
71
72
        }
72
73
 
73
74
        function handle_pageredirect_note(&$event, $param) {
74
75
                global $ID, $ACT;
75
 
                
 
76
 
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']);
84
 
                                        
 
85
 
85
86
                                        return true;
86
87
                                }
87
88
                        }
88
89
                }
89
 
                
 
90
 
90
91
                return true;
91
92
        }
92
93
 
93
94
        function handle_pageredirect_metadata(&$event, $param) {
94
 
        if( isset($event→data→meta['relation']['isreplacedby'])) {
95
 
                unset($event->data->meta['relation']['isreplacedby']);
96
 
        }
 
95
                if (isset($event->data->meta['relation'])) {
 
96
                        unset($event->data->meta['relation']['isreplacedby']);
 
97
                }
97
98
        }
98
 
 
99
99
}