Completed
Push — master ( 9b78f7...5dcb4f )
by Andreas
08:15 queued 03:39
created

MobileMenu::getDropdown()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 36
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 26
nc 12
nop 2
dl 0
loc 36
rs 8.439
c 1
b 0
f 1
1
<?php
2
3
namespace dokuwiki\Menu;
4
5
use dokuwiki\Menu\Item\AbstractItem;
6
7
/**
8
 * Class MobileMenu
9
 *
10
 * Note: this does not inherit from AbstractMenu because it is not working like the other
11
 * menus. This is a meta menu, aggregating the items from the other menus and offering a combined
12
 * view. The idea is to use this on mobile devices, thus the context is fixed to CTX_MOBILE
13
 */
14
class MobileMenu {
15
16
    /**
17
     * Returns all items grouped
18
     *
19
     * @return AbstractItem[][]
20
     */
21
    public function getItems() {
22
        $pagemenu = new PageMenu(AbstractItem::CTX_MOBILE);
23
        $sitemenu = new SiteMenu(AbstractItem::CTX_MOBILE);
24
        $usermenu = new UserMenu(AbstractItem::CTX_MOBILE);
25
26
        return array(
27
            'page' => $pagemenu->getItems(),
28
            'site' => $sitemenu->getItems(),
29
            'user' => $usermenu->getItems()
30
        );
31
    }
32
33
    /**
34
     * Print a dropdown menu with all DokuWiki actions
35
     *
36
     * Note: this will not use any pretty URLs
37
     *
38
     * @param string $empty empty option label
39
     * @param string $button submit button label
40
     * @return string
41
     */
42
    public function getDropdown($empty = '', $button = '&gt;') {
43
        global $ID;
44
        global $REV;
45
        /** @var string[] $lang */
46
        global $lang;
47
        global $INPUT;
48
49
        $html = '<form action="' . script() . '" method="get" accept-charset="utf-8">';
50
        $html .= '<div class="no">';
51
        $html .= '<input type="hidden" name="id" value="' . $ID . '" />';
52
        if($REV) $html .= '<input type="hidden" name="rev" value="' . $REV . '" />';
53
        if($INPUT->server->str('REMOTE_USER')) {
54
            $html .= '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />';
55
        }
56
57
        $html .= '<select name="do" class="edit quickselect" title="' . $lang['tools'] . '">';
58
        $html .= '<option value="">' . $empty . '</option>';
59
60
        foreach($this->getItems() as $tools => $items) {
61
            $html .= '<optgroup label="' . $lang[$tools . '_tools'] . '">';
62
            foreach($items as $item) {
63
                $params = $item->getParams();
64
                $html .= '<option value="' . $params['do'] . '">';
65
                $html .= hsc($item->getLabel());
66
                $html .= '</option>';
67
            }
68
            $html .= '</optgroup>';
69
        }
70
71
        $html .= '</select>';
72
        $html .= '<button type="submit">' . $button . '</button>';
73
        $html .= '</div>';
74
        $html .= '</form>';
75
76
        return $html;
77
    }
78
79
}
80