SimpleMenuAction.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
  4. *
  5. * @author Julius Härtl <jus@bitgrid.net>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCP\AppFramework\Http\Template;
  25. use OCP\Util;
  26. /**
  27. * Class SimpleMenuAction
  28. *
  29. * @since 14.0.0
  30. */
  31. class SimpleMenuAction implements IMenuAction {
  32. /** @var string */
  33. private $id;
  34. /** @var string */
  35. private $label;
  36. /** @var string */
  37. private $icon;
  38. /** @var string */
  39. private $link;
  40. /** @var int */
  41. private $priority;
  42. /** @var string */
  43. private $detail;
  44. /**
  45. * SimpleMenuAction constructor.
  46. *
  47. * @param string $id
  48. * @param string $label
  49. * @param string $icon
  50. * @param string $link
  51. * @param int $priority
  52. * @param string $detail
  53. * @since 14.0.0
  54. */
  55. public function __construct(string $id, string $label, string $icon, string $link = '', int $priority = 100, string $detail = '') {
  56. $this->id = $id;
  57. $this->label = $label;
  58. $this->icon = $icon;
  59. $this->link = $link;
  60. $this->priority = $priority;
  61. $this->detail = $detail;
  62. }
  63. /**
  64. * @return string
  65. * @since 14.0.0
  66. */
  67. public function getId(): string {
  68. return $this->id;
  69. }
  70. /**
  71. * @return string
  72. * @since 14.0.0
  73. */
  74. public function getLabel(): string {
  75. return $this->label;
  76. }
  77. /**
  78. * @return string
  79. * @since 14.0.0
  80. */
  81. public function getIcon(): string {
  82. return $this->icon;
  83. }
  84. /**
  85. * @return string
  86. * @since 14.0.0
  87. */
  88. public function getLink(): string {
  89. return $this->link;
  90. }
  91. /**
  92. * @return int
  93. * @since 14.0.0
  94. */
  95. public function getPriority(): int {
  96. return $this->priority;
  97. }
  98. /**
  99. * @return string
  100. * @since 14.0.0
  101. */
  102. public function render(): string {
  103. $detailContent = ($this->detail !== '') ? '&nbsp;<span class="download-size">(' . Util::sanitizeHTML($this->detail) . ')</span>' : '';
  104. return sprintf(
  105. '<li id="%s"><a href="%s"><span class="icon %s"></span>%s %s</a></li>',
  106. Util::sanitizeHTML($this->id), Util::sanitizeHTML($this->link), Util::sanitizeHTML($this->icon), Util::sanitizeHTML($this->label), $detailContent
  107. );
  108. }
  109. }