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 implements MenuInterface {
15 
16     /**
17      * Returns all items grouped by view
18      *
19      * @return AbstractItem[][]
20      */
21     public function getGroupedItems() {
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      * Get all items in a flat array
35      *
36      * This returns the same format as AbstractMenu::getItems()
37      *
38      * @return AbstractItem[]
39      */
40     public function getItems() {
41         $menu = $this->getGroupedItems();
42         return call_user_func_array('array_merge', array_values($menu));
43     }
44 
45     /**
46      * Print a dropdown menu with all DokuWiki actions
47      *
48      * Note: this will not use any pretty URLs
49      *
50      * @param string $empty empty option label
51      * @param string $button submit button label
52      * @return string
53      */
54     public function getDropdown($empty = '', $button = '&gt;') {
55         global $ID;
56         global $REV;
57         /** @var string[] $lang */
58         global $lang;
59         global $INPUT;
60 
61         $html = '<form action="' . script() . '" method="get" accept-charset="utf-8">';
62         $html .= '<div class="no">';
63         $html .= '<input type="hidden" name="id" value="' . $ID . '" />';
64         if($REV) $html .= '<input type="hidden" name="rev" value="' . $REV . '" />';
65         if($INPUT->server->str('REMOTE_USER')) {
66             $html .= '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />';
67         }
68 
69         $html .= '<select name="do" class="edit quickselect" title="' . $lang['tools'] . '">';
70         $html .= '<option value="">' . $empty . '</option>';
71 
72         foreach($this->getGroupedItems() as $tools => $items) {
73             if (count($items)) {
74                 $html .= '<optgroup label="' . $lang[$tools . '_tools'] . '">';
75                 foreach($items as $item) {
76                     $params = $item->getParams();
77                     $html .= '<option value="' . $params['do'] . '">';
78                     $html .= hsc($item->getLabel());
79                     $html .= '</option>';
80                 }
81                 $html .= '</optgroup>';
82             }
83         }
84 
85         $html .= '</select>';
86         $html .= '<button type="submit">' . $button . '</button>';
87         $html .= '</div>';
88         $html .= '</form>';
89 
90         return $html;
91     }
92 
93 }
94