summaryrefslogtreecommitdiff
path: root/platform/www/inc/Menu/MobileMenu.php
blob: 20980564691173cc88cefbfa9b241ea80b1044c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php

namespace dokuwiki\Menu;

use dokuwiki\Menu\Item\AbstractItem;

/**
 * Class MobileMenu
 *
 * Note: this does not inherit from AbstractMenu because it is not working like the other
 * menus. This is a meta menu, aggregating the items from the other menus and offering a combined
 * view. The idea is to use this on mobile devices, thus the context is fixed to CTX_MOBILE
 */
class MobileMenu implements MenuInterface {

    /**
     * Returns all items grouped by view
     *
     * @return AbstractItem[][]
     */
    public function getGroupedItems() {
        $pagemenu = new PageMenu(AbstractItem::CTX_MOBILE);
        $sitemenu = new SiteMenu(AbstractItem::CTX_MOBILE);
        $usermenu = new UserMenu(AbstractItem::CTX_MOBILE);

        return array(
            'page' => $pagemenu->getItems(),
            'site' => $sitemenu->getItems(),
            'user' => $usermenu->getItems()
        );
    }

    /**
     * Get all items in a flat array
     *
     * This returns the same format as AbstractMenu::getItems()
     *
     * @return AbstractItem[]
     */
    public function getItems() {
        $menu = $this->getGroupedItems();
        return call_user_func_array('array_merge', array_values($menu));
    }

    /**
     * Print a dropdown menu with all DokuWiki actions
     *
     * Note: this will not use any pretty URLs
     *
     * @param string $empty empty option label
     * @param string $button submit button label
     * @return string
     */
    public function getDropdown($empty = '', $button = '&gt;') {
        global $ID;
        global $REV;
        /** @var string[] $lang */
        global $lang;
        global $INPUT;

        $html = '<form action="' . script() . '" method="get" accept-charset="utf-8">';
        $html .= '<div class="no">';
        $html .= '<input type="hidden" name="id" value="' . $ID . '" />';
        if($REV) $html .= '<input type="hidden" name="rev" value="' . $REV . '" />';
        if($INPUT->server->str('REMOTE_USER')) {
            $html .= '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />';
        }

        $html .= '<select name="do" class="edit quickselect" title="' . $lang['tools'] . '">';
        $html .= '<option value="">' . $empty . '</option>';

        foreach($this->getGroupedItems() as $tools => $items) {
            if (count($items)) {
                $html .= '<optgroup label="' . $lang[$tools . '_tools'] . '">';
                foreach($items as $item) {
                    $params = $item->getParams();
                    $html .= '<option value="' . $params['do'] . '">';
                    $html .= hsc($item->getLabel());
                    $html .= '</option>';
                }
                $html .= '</optgroup>';
            }
        }

        $html .= '</select>';
        $html .= '<button type="submit">' . $button . '</button>';
        $html .= '</div>';
        $html .= '</form>';

        return $html;
    }

}