searchsubmenu.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. defined('GNUSOCIAL') || die();
  17. /**
  18. * Class comment
  19. *
  20. * @category Plugin
  21. * @package SearchSubPlugin
  22. * @author Evan Prodromou <evan@status.net>
  23. * @copyright 2011 StatusNet, Inc.
  24. * @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org
  25. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  26. */
  27. class SearchSubMenu extends MoreMenu
  28. {
  29. protected $user;
  30. protected $searches;
  31. public function __construct($out, $user, $searches)
  32. {
  33. parent::__construct($out);
  34. $this->user = $user;
  35. $this->searches = $searches;
  36. }
  37. public function tag()
  38. {
  39. return 'searchsubs';
  40. }
  41. public function seeAllItem()
  42. {
  43. return array('searchsubs',
  44. array('nickname' => $this->user->nickname),
  45. _('See all'),
  46. _('See all searches you are following'));
  47. }
  48. public function getItems()
  49. {
  50. $items = array();
  51. foreach ($this->searches as $search) {
  52. if (!empty($search)) {
  53. $items[] = array('noticesearch',
  54. array('q' => $search),
  55. sprintf('"%s"', $search),
  56. sprintf(_('Notices including %s'), $search));;
  57. }
  58. }
  59. return $items;
  60. }
  61. public function item($actionName, array $args, $label, $description, $id = null, $cls = null)
  62. {
  63. if (empty($id)) {
  64. $id = $this->menuItemID($actionName, $args);
  65. }
  66. if ($actionName == 'noticesearch') {
  67. // Add 'q' as a search param, not part of the url path
  68. $url = common_local_url($actionName, array(), $args);
  69. } else {
  70. $url = common_local_url($actionName, $args);
  71. }
  72. $this->out->menuItem(
  73. $url,
  74. $label,
  75. $description,
  76. $this->isCurrent($actionName, $args),
  77. $id,
  78. $cls
  79. );
  80. }
  81. }