You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

96 lines
2.9 KiB

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