MobileMenu.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace dokuwiki\Menu;
  3. use dokuwiki\Menu\Item\AbstractItem;
  4. /**
  5. * Class MobileMenu
  6. *
  7. * Note: this does not inherit from AbstractMenu because it is not working like the other
  8. * menus. This is a meta menu, aggregating the items from the other menus and offering a combined
  9. * view. The idea is to use this on mobile devices, thus the context is fixed to CTX_MOBILE
  10. */
  11. class MobileMenu implements MenuInterface {
  12. /**
  13. * Returns all items grouped by view
  14. *
  15. * @return AbstractItem[][]
  16. */
  17. public function getGroupedItems() {
  18. $pagemenu = new PageMenu(AbstractItem::CTX_MOBILE);
  19. $sitemenu = new SiteMenu(AbstractItem::CTX_MOBILE);
  20. $usermenu = new UserMenu(AbstractItem::CTX_MOBILE);
  21. return array(
  22. 'page' => $pagemenu->getItems(),
  23. 'site' => $sitemenu->getItems(),
  24. 'user' => $usermenu->getItems()
  25. );
  26. }
  27. /**
  28. * Get all items in a flat array
  29. *
  30. * This returns the same format as AbstractMenu::getItems()
  31. *
  32. * @return AbstractItem[]
  33. */
  34. public function getItems() {
  35. $menu = $this->getGroupedItems();
  36. return call_user_func_array('array_merge', array_values($menu));
  37. }
  38. /**
  39. * Print a dropdown menu with all DokuWiki actions
  40. *
  41. * Note: this will not use any pretty URLs
  42. *
  43. * @param string $empty empty option label
  44. * @param string $button submit button label
  45. * @return string
  46. */
  47. public function getDropdown($empty = '', $button = '&gt;') {
  48. global $ID;
  49. global $REV;
  50. /** @var string[] $lang */
  51. global $lang;
  52. global $INPUT;
  53. $html = '<form action="' . script() . '" method="get" accept-charset="utf-8">';
  54. $html .= '<div class="no">';
  55. $html .= '<input type="hidden" name="id" value="' . $ID . '" />';
  56. if($REV) $html .= '<input type="hidden" name="rev" value="' . $REV . '" />';
  57. if($INPUT->server->str('REMOTE_USER')) {
  58. $html .= '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />';
  59. }
  60. $html .= '<select name="do" class="edit quickselect" title="' . $lang['tools'] . '">';
  61. $html .= '<option value="">' . $empty . '</option>';
  62. foreach($this->getGroupedItems() as $tools => $items) {
  63. if (count($items)) {
  64. $html .= '<optgroup label="' . $lang[$tools . '_tools'] . '">';
  65. foreach($items as $item) {
  66. $params = $item->getParams();
  67. $html .= '<option value="' . $params['do'] . '">';
  68. $html .= hsc($item->getLabel());
  69. $html .= '</option>';
  70. }
  71. $html .= '</optgroup>';
  72. }
  73. }
  74. $html .= '</select>';
  75. $html .= '<button type="submit">' . $button . '</button>';
  76. $html .= '</div>';
  77. $html .= '</form>';
  78. return $html;
  79. }
  80. }