Completed
Push — master ( bf6f54...20dc95 )
by Andreas
03:16
created

Redirect   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 6
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
B preProcess() 0 27 4
A redirect() 0 7 2
1
<?php
2
3
namespace dokuwiki\Action;
4
5
use dokuwiki\Action\Exception\ActionAbort;
6
7
/**
8
 * Class Redirect
9
 *
10
 * Used to redirect to the current page with the last edited section as a target if found
11
 *
12
 * @package dokuwiki\Action
13
 */
14
class Redirect extends AbstractAliasAction {
15
16
    /**
17
     * Redirect to the show action, trying to jump to the previously edited section
18
     *
19
     * @triggers ACTION_SHOW_REDIRECT
20
     * @throws ActionAbort
21
     */
22
    public function preProcess() {
23
        global $PRE;
24
        global $TEXT;
25
        global $INPUT;
26
        global $ID;
27
        global $ACT;
28
29
        $opts = array(
30
            'id' => $ID,
31
            'preact' => $ACT
32
        );
33
        //get section name when coming from section edit
34
        if($INPUT->has('hid')) {
35
            // Use explicitly transmitted header id
36
            $opts['fragment'] = $INPUT->str('hid');
37
        } else if($PRE && preg_match('/^\s*==+([^=\n]+)/', $TEXT, $match)) {
38
            // Fallback to old mechanism
39
            $check = false; //Byref
40
            $opts['fragment'] = sectionID($match[0], $check);
41
        }
42
43
        // execute the redirect
44
        trigger_event('ACTION_SHOW_REDIRECT', $opts, array($this, 'redirect'));
45
46
        // should never be reached
47
        throw new ActionAbort();
48
    }
49
50
    /**
51
     * Execute the redirect
52
     *
53
     * Default action for ACTION_SHOW_REDIRECT
54
     *
55
     * @param array $opts id and fragment for the redirect and the preact
56
     */
57
    public function redirect($opts) {
58
        $go = wl($opts['id'], '', true);
59
        if(isset($opts['fragment'])) $go .= '#' . $opts['fragment'];
60
61
        //show it
62
        send_redirect($go);
63
    }
64
}
65