Completed
Push — actionrefactor ( 0f9e19...272271 )
by Andreas
04:18
created

actions.php ➔ subscription_handle_post()   D

Complexity

Conditions 9
Paths 11

Size

Total Lines 44
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 28
nc 11
nop 1
dl 0
loc 44
rs 4.909
c 0
b 0
f 0
1
<?php
2
/**
3
 * DokuWiki Actions
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 * @author     Andreas Gohr <[email protected]>
7
 */
8
9
if(!defined('DOKU_INC')) die('meh.');
10
11
12
function act_dispatch(){
13
    $router = \dokuwiki\ActionRouter::getInstance(); // is this needed here or could we delegate it to tpl_content() later?
14
15
    $headers = array('Content-Type: text/html; charset=utf-8');
16
    trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders');
17
18
    // clear internal variables
19
    unset($router);
20
    unset($headers);
21
    // make all globals available to the template
22
    extract($GLOBALS);
23
24
    include(template('main.php'));
25
    // output for the commands is now handled in inc/templates.php
26
    // in function tpl_content()
27
}
28
29
/**
30
 * Send the given headers using header()
31
 *
32
 * @param array $headers The headers that shall be sent
33
 */
34
function act_sendheaders($headers) {
35
    foreach ($headers as $hdr) header($hdr);
36
}
37
38
/**
39
 * Sanitize the action command
40
 *
41
 * @author Andreas Gohr <[email protected]>
42
 *
43
 * @param array|string $act
44
 * @return string
45
 */
46
function act_clean($act){
47
    // check if the action was given as array key
48
    if(is_array($act)){
49
        list($act) = array_keys($act);
50
    }
51
52
    //remove all bad chars
53
    $act = strtolower($act);
54
    $act = preg_replace('/[^1-9a-z_]+/','',$act);
55
56
    if($act == 'export_html') $act = 'export_xhtml';
57
    if($act == 'export_htmlbody') $act = 'export_xhtmlbody';
58
59
    if($act === '') $act = 'show';
60
    return $act;
61
}
62
63
/**
64
 * Handle 'draftdel'
65
 *
66
 * Deletes the draft for the current page and user
67
 *
68
 * @param string $act action command
69
 * @return string action command
70
 */
71
function act_draftdel($act){
0 ignored issues
show
Unused Code introduced by
The parameter $act is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
    global $INFO;
73
    @unlink($INFO['draft']);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
74
    $INFO['draft'] = null;
75
    return 'show';
76
}
77