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 */ 14*33b91513SAndreas Gohrclass MobileMenu implements MenuInterface 15*33b91513SAndreas Gohr{ 16b3680c4fSAndreas Gohr 17b3680c4fSAndreas Gohr /** 1831110e19SAndreas Gohr * Returns all items grouped by view 19b3680c4fSAndreas Gohr * 20b3680c4fSAndreas Gohr * @return AbstractItem[][] 21b3680c4fSAndreas Gohr */ 22*33b91513SAndreas Gohr public function getGroupedItems() 23*33b91513SAndreas Gohr { 24b3680c4fSAndreas Gohr $pagemenu = new PageMenu(AbstractItem::CTX_MOBILE); 25b3680c4fSAndreas Gohr $sitemenu = new SiteMenu(AbstractItem::CTX_MOBILE); 26b3680c4fSAndreas Gohr $usermenu = new UserMenu(AbstractItem::CTX_MOBILE); 27b3680c4fSAndreas Gohr 28*33b91513SAndreas Gohr return [ 29b3680c4fSAndreas Gohr 'page' => $pagemenu->getItems(), 30b3680c4fSAndreas Gohr 'site' => $sitemenu->getItems(), 31b3680c4fSAndreas Gohr 'user' => $usermenu->getItems() 32*33b91513SAndreas Gohr ]; 33b3680c4fSAndreas Gohr } 34b3680c4fSAndreas Gohr 35b3680c4fSAndreas Gohr /** 3631110e19SAndreas Gohr * Get all items in a flat array 3731110e19SAndreas Gohr * 3831110e19SAndreas Gohr * This returns the same format as AbstractMenu::getItems() 3931110e19SAndreas Gohr * 4031110e19SAndreas Gohr * @return AbstractItem[] 4131110e19SAndreas Gohr */ 42*33b91513SAndreas Gohr public function getItems() 43*33b91513SAndreas Gohr { 4431110e19SAndreas Gohr $menu = $this->getGroupedItems(); 45*33b91513SAndreas Gohr return array_merge(...array_values($menu)); 4631110e19SAndreas Gohr } 4731110e19SAndreas Gohr 4831110e19SAndreas Gohr /** 49b3680c4fSAndreas Gohr * Print a dropdown menu with all DokuWiki actions 50b3680c4fSAndreas Gohr * 51b3680c4fSAndreas Gohr * Note: this will not use any pretty URLs 52b3680c4fSAndreas Gohr * 53b3680c4fSAndreas Gohr * @param string $empty empty option label 54b3680c4fSAndreas Gohr * @param string $button submit button label 55b3680c4fSAndreas Gohr * @return string 56b3680c4fSAndreas Gohr */ 57*33b91513SAndreas Gohr public function getDropdown($empty = '', $button = '>') 58*33b91513SAndreas Gohr { 59b3680c4fSAndreas Gohr global $ID; 60b3680c4fSAndreas Gohr global $REV; 61b3680c4fSAndreas Gohr /** @var string[] $lang */ 62b3680c4fSAndreas Gohr global $lang; 63b3680c4fSAndreas Gohr global $INPUT; 64b3680c4fSAndreas Gohr 65b3680c4fSAndreas Gohr $html = '<form action="' . script() . '" method="get" accept-charset="utf-8">'; 66b3680c4fSAndreas Gohr $html .= '<div class="no">'; 67b3680c4fSAndreas Gohr $html .= '<input type="hidden" name="id" value="' . $ID . '" />'; 68b3680c4fSAndreas Gohr if ($REV) $html .= '<input type="hidden" name="rev" value="' . $REV . '" />'; 69b3680c4fSAndreas Gohr if ($INPUT->server->str('REMOTE_USER')) { 70b3680c4fSAndreas Gohr $html .= '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />'; 71b3680c4fSAndreas Gohr } 72b3680c4fSAndreas Gohr 73b3680c4fSAndreas Gohr $html .= '<select name="do" class="edit quickselect" title="' . $lang['tools'] . '">'; 74b3680c4fSAndreas Gohr $html .= '<option value="">' . $empty . '</option>'; 75b3680c4fSAndreas Gohr 7631110e19SAndreas Gohr foreach ($this->getGroupedItems() as $tools => $items) { 77*33b91513SAndreas Gohr if ($items !== []) { 78b3680c4fSAndreas Gohr $html .= '<optgroup label="' . $lang[$tools . '_tools'] . '">'; 79b3680c4fSAndreas Gohr foreach ($items as $item) { 80b3680c4fSAndreas Gohr $params = $item->getParams(); 81b3680c4fSAndreas Gohr $html .= '<option value="' . $params['do'] . '">'; 82b3680c4fSAndreas Gohr $html .= hsc($item->getLabel()); 83b3680c4fSAndreas Gohr $html .= '</option>'; 84b3680c4fSAndreas Gohr } 85b3680c4fSAndreas Gohr $html .= '</optgroup>'; 86b3680c4fSAndreas Gohr } 8759407722SPhy } 88b3680c4fSAndreas Gohr 89b3680c4fSAndreas Gohr $html .= '</select>'; 90b3680c4fSAndreas Gohr $html .= '<button type="submit">' . $button . '</button>'; 91b3680c4fSAndreas Gohr $html .= '</div>'; 92b3680c4fSAndreas Gohr $html .= '</form>'; 93b3680c4fSAndreas Gohr 94b3680c4fSAndreas Gohr return $html; 95b3680c4fSAndreas Gohr } 96b3680c4fSAndreas Gohr 97b3680c4fSAndreas Gohr} 98