Backend   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 62
c 3
b 0
f 1
dl 0
loc 97
rs 10
wmc 18

3 Methods

Rating   Name   Duplication   Size   Complexity  
A digestTest() 0 12 2
A loading() 0 4 1
C help() 0 75 15
1
<?php
2
class Backend extends Handler {
3
    public function loading() {
4
        header("Content-type: text/html");
5
        print __("Loading, please wait...")." ".
6
            "<img src='images/indicator_tiny.gif'>";
7
    }
8
9
    public function digestTest() {
10
        if (isset($_SESSION['uid'])) {
11
            header("Content-type: text/html");
12
13
            $rv = Digest::prepare_headlines_digest($_SESSION['uid'], 1, 1000);
14
15
            print "<h1>HTML</h1>";
16
            print $rv[0];
17
            print "<h1>Plain text</h1>";
18
            print "<pre>".$rv[3]."</pre>";
19
        } else {
20
            print error_json(6);
21
        }
22
    }
23
24
    public function help() {
25
        $topic = clean_filename($_REQUEST["topic"]); // only one for now
26
27
        if ($topic == "main") {
28
            $info = get_hotkeys_info();
29
            $imap = get_hotkeys_map();
30
            $omap = array();
31
32
            foreach ($imap[1] as $sequence => $action) {
33
                if (!isset($omap[$action])) {
34
                    $omap[$action] = array();
35
                }
36
37
                array_push($omap[$action], $sequence);
38
            }
39
40
            print "<ul class='panel panel-scrollable hotkeys-help' style='height : 300px'>";
41
42
            $cur_section = "";
43
            foreach ($info as $section => $hotkeys) {
44
45
                if ($cur_section) {
46
                    print "<li>&nbsp;</li>";
47
                }
48
                print "<li><h3>".$section."</h3></li>";
49
                $cur_section = $section;
50
51
                foreach ($hotkeys as $action => $description) {
52
53
                    if (is_array($omap[$action])) {
54
                        foreach ($omap[$action] as $sequence) {
55
                            if (strpos($sequence, "|") !== false) {
56
                                $sequence = substr($sequence,
57
                                    strpos($sequence, "|") + 1,
58
                                    strlen($sequence));
59
                            } else {
60
                                $keys = explode(" ", $sequence);
61
62
                                for ($i = 0; $i < count($keys); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
63
                                    if (strlen($keys[$i]) > 1) {
64
                                        $tmp = '';
65
                                        foreach (str_split($keys[$i]) as $c) {
66
                                            switch ($c) {
67
                                            case '*':
68
                                                $tmp .= __('Shift').'+';
69
                                                break;
70
                                            case '^':
71
                                                $tmp .= __('Ctrl').'+';
72
                                                break;
73
                                            default:
74
                                                $tmp .= $c;
75
                                            }
76
                                        }
77
                                        $keys[$i] = $tmp;
78
                                    }
79
                                }
80
                                $sequence = join(" ", $keys);
81
                            }
82
83
                            print "<li>";
84
                            print "<div class='hk'><code>$sequence</code></div>";
85
                            print "<div class='desc'>$description</div>";
86
                            print "</li>";
87
                        }
88
                    }
89
                }
90
            }
91
92
            print "</ul>";
93
        }
94
95
        print "<footer class='text-center'>";
96
        print "<button dojoType='dijit.form.Button'
97
			onclick=\"return dijit.byId('helpDlg').hide()\">".__('Close this window')."</button>";
98
        print "</footer>";
99
100
    }
101
}
102