SimpleMenuAction.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCP\AppFramework\Http\Template;
  7. use OCP\Util;
  8. /**
  9. * Class SimpleMenuAction
  10. *
  11. * @since 14.0.0
  12. */
  13. class SimpleMenuAction implements IMenuAction {
  14. /** @var string */
  15. private $id;
  16. /** @var string */
  17. private $label;
  18. /** @var string */
  19. private $icon;
  20. /** @var string */
  21. private $link;
  22. /** @var int */
  23. private $priority;
  24. /** @var string */
  25. private $detail;
  26. /**
  27. * SimpleMenuAction constructor.
  28. *
  29. * @param string $id
  30. * @param string $label
  31. * @param string $icon
  32. * @param string $link
  33. * @param int $priority
  34. * @param string $detail
  35. * @since 14.0.0
  36. */
  37. public function __construct(string $id, string $label, string $icon, string $link = '', int $priority = 100, string $detail = '') {
  38. $this->id = $id;
  39. $this->label = $label;
  40. $this->icon = $icon;
  41. $this->link = $link;
  42. $this->priority = $priority;
  43. $this->detail = $detail;
  44. }
  45. /**
  46. * @return string
  47. * @since 14.0.0
  48. */
  49. public function getId(): string {
  50. return $this->id;
  51. }
  52. /**
  53. * @return string
  54. * @since 14.0.0
  55. */
  56. public function getLabel(): string {
  57. return $this->label;
  58. }
  59. /**
  60. * @return string
  61. * @since 14.0.0
  62. */
  63. public function getIcon(): string {
  64. return $this->icon;
  65. }
  66. /**
  67. * @return string
  68. * @since 14.0.0
  69. */
  70. public function getLink(): string {
  71. return $this->link;
  72. }
  73. /**
  74. * @return int
  75. * @since 14.0.0
  76. */
  77. public function getPriority(): int {
  78. return $this->priority;
  79. }
  80. /**
  81. * @return string
  82. * @since 14.0.0
  83. */
  84. public function render(): string {
  85. $detailContent = ($this->detail !== '') ? '&nbsp;<span class="download-size">(' . Util::sanitizeHTML($this->detail) . ')</span>' : '';
  86. return sprintf(
  87. '<li id="%s"><a href="%s"><span class="icon %s"></span>%s %s</a></li>',
  88. Util::sanitizeHTML($this->id), Util::sanitizeHTML($this->link), Util::sanitizeHTML($this->icon), Util::sanitizeHTML($this->label), $detailContent
  89. );
  90. }
  91. }