1<?php 2 3namespace dokuwiki\Menu; 4 5use 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 */ 14class 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 = '>') { 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