xref: /dokuwiki/inc/Menu/MobileMenu.php (revision 594077226481fa39f12192df57a9418cb7a71239)
1b3680c4fSAndreas Gohr<?php
2b3680c4fSAndreas Gohr
3b3680c4fSAndreas Gohrnamespace dokuwiki\Menu;
4b3680c4fSAndreas Gohr
5b3680c4fSAndreas Gohruse dokuwiki\Menu\Item\AbstractItem;
6b3680c4fSAndreas Gohr
7368ce258SAndreas Gohr/**
8368ce258SAndreas Gohr * Class MobileMenu
9368ce258SAndreas Gohr *
10368ce258SAndreas Gohr * Note: this does not inherit from AbstractMenu because it is not working like the other
11368ce258SAndreas Gohr * menus. This is a meta menu, aggregating the items from the other menus and offering a combined
12368ce258SAndreas Gohr * view. The idea is to use this on mobile devices, thus the context is fixed to CTX_MOBILE
13368ce258SAndreas Gohr */
1431110e19SAndreas Gohrclass MobileMenu implements MenuInterface {
15b3680c4fSAndreas Gohr
16b3680c4fSAndreas Gohr    /**
1731110e19SAndreas Gohr     * Returns all items grouped by view
18b3680c4fSAndreas Gohr     *
19b3680c4fSAndreas Gohr     * @return AbstractItem[][]
20b3680c4fSAndreas Gohr     */
2131110e19SAndreas Gohr    public function getGroupedItems() {
22b3680c4fSAndreas Gohr        $pagemenu = new PageMenu(AbstractItem::CTX_MOBILE);
23b3680c4fSAndreas Gohr        $sitemenu = new SiteMenu(AbstractItem::CTX_MOBILE);
24b3680c4fSAndreas Gohr        $usermenu = new UserMenu(AbstractItem::CTX_MOBILE);
25b3680c4fSAndreas Gohr
26b3680c4fSAndreas Gohr        return array(
27b3680c4fSAndreas Gohr            'page' => $pagemenu->getItems(),
28b3680c4fSAndreas Gohr            'site' => $sitemenu->getItems(),
29b3680c4fSAndreas Gohr            'user' => $usermenu->getItems()
30b3680c4fSAndreas Gohr        );
31b3680c4fSAndreas Gohr    }
32b3680c4fSAndreas Gohr
33b3680c4fSAndreas Gohr    /**
3431110e19SAndreas Gohr     * Get all items in a flat array
3531110e19SAndreas Gohr     *
3631110e19SAndreas Gohr     * This returns the same format as AbstractMenu::getItems()
3731110e19SAndreas Gohr     *
3831110e19SAndreas Gohr     * @return AbstractItem[]
3931110e19SAndreas Gohr     */
4031110e19SAndreas Gohr    public function getItems() {
4131110e19SAndreas Gohr        $menu = $this->getGroupedItems();
4231110e19SAndreas Gohr        return call_user_func_array('array_merge', array_values($menu));
4331110e19SAndreas Gohr    }
4431110e19SAndreas Gohr
4531110e19SAndreas Gohr    /**
46b3680c4fSAndreas Gohr     * Print a dropdown menu with all DokuWiki actions
47b3680c4fSAndreas Gohr     *
48b3680c4fSAndreas Gohr     * Note: this will not use any pretty URLs
49b3680c4fSAndreas Gohr     *
50b3680c4fSAndreas Gohr     * @param string $empty empty option label
51b3680c4fSAndreas Gohr     * @param string $button submit button label
52b3680c4fSAndreas Gohr     * @return string
53b3680c4fSAndreas Gohr     */
54b3680c4fSAndreas Gohr    public function getDropdown($empty = '', $button = '&gt;') {
55b3680c4fSAndreas Gohr        global $ID;
56b3680c4fSAndreas Gohr        global $REV;
57b3680c4fSAndreas Gohr        /** @var string[] $lang */
58b3680c4fSAndreas Gohr        global $lang;
59b3680c4fSAndreas Gohr        global $INPUT;
60b3680c4fSAndreas Gohr
61b3680c4fSAndreas Gohr        $html = '<form action="' . script() . '" method="get" accept-charset="utf-8">';
62b3680c4fSAndreas Gohr        $html .= '<div class="no">';
63b3680c4fSAndreas Gohr        $html .= '<input type="hidden" name="id" value="' . $ID . '" />';
64b3680c4fSAndreas Gohr        if($REV) $html .= '<input type="hidden" name="rev" value="' . $REV . '" />';
65b3680c4fSAndreas Gohr        if($INPUT->server->str('REMOTE_USER')) {
66b3680c4fSAndreas Gohr            $html .= '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />';
67b3680c4fSAndreas Gohr        }
68b3680c4fSAndreas Gohr
69b3680c4fSAndreas Gohr        $html .= '<select name="do" class="edit quickselect" title="' . $lang['tools'] . '">';
70b3680c4fSAndreas Gohr        $html .= '<option value="">' . $empty . '</option>';
71b3680c4fSAndreas Gohr
7231110e19SAndreas Gohr        foreach($this->getGroupedItems() as $tools => $items) {
73*59407722SPhy            if (count($items)) {
74b3680c4fSAndreas Gohr                $html .= '<optgroup label="' . $lang[$tools . '_tools'] . '">';
75b3680c4fSAndreas Gohr                foreach($items as $item) {
76b3680c4fSAndreas Gohr                    $params = $item->getParams();
77b3680c4fSAndreas Gohr                    $html .= '<option value="' . $params['do'] . '">';
78b3680c4fSAndreas Gohr                    $html .= hsc($item->getLabel());
79b3680c4fSAndreas Gohr                    $html .= '</option>';
80b3680c4fSAndreas Gohr                }
81b3680c4fSAndreas Gohr                $html .= '</optgroup>';
82b3680c4fSAndreas Gohr            }
83*59407722SPhy        }
84b3680c4fSAndreas Gohr
85b3680c4fSAndreas Gohr        $html .= '</select>';
86b3680c4fSAndreas Gohr        $html .= '<button type="submit">' . $button . '</button>';
87b3680c4fSAndreas Gohr        $html .= '</div>';
88b3680c4fSAndreas Gohr        $html .= '</form>';
89b3680c4fSAndreas Gohr
90b3680c4fSAndreas Gohr        return $html;
91b3680c4fSAndreas Gohr    }
92b3680c4fSAndreas Gohr
93b3680c4fSAndreas Gohr}
94