searchsubs.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. * A list of the user's subscriptions
  19. *
  20. * @category Plugin
  21. * @package SearchSubPlugin
  22. * @author Evan Prodromou <evan@status.net>
  23. * @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org
  24. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  25. */
  26. class SearchSubsAction extends GalleryAction
  27. {
  28. public function title()
  29. {
  30. if ($this->page == 1) {
  31. // TRANS: Header for subscriptions overview for a user (first page).
  32. // TRANS: %s is a user nickname.
  33. return sprintf(_m('%s\'s search subscriptions'), $this->getTarget()->getNickname());
  34. } else {
  35. // TRANS: Header for subscriptions overview for a user (not first page).
  36. // TRANS: %1$s is a user nickname, %2$d is the page number.
  37. return sprintf(
  38. _m('%1$s\'s search subscriptions, page %2$d'),
  39. $this->getTarget()->getNickname(),
  40. $this->page
  41. );
  42. }
  43. }
  44. public function showPageNotice()
  45. {
  46. if ($this->scoped instanceof Profile && $this->scoped->sameAs($this->getTarget())) {
  47. $this->element(
  48. 'p',
  49. null,
  50. // TRANS: Page notice for page with an overview of all search subscriptions
  51. // TRANS: of the logged in user's own profile.
  52. _m('You have subscribed to receive all notices on this site matching the following searches:')
  53. );
  54. } else {
  55. $this->element(
  56. 'p',
  57. null,
  58. // TRANS: Page notice for page with an overview of all subscriptions of a user other
  59. // TRANS: than the logged in user. %s is the user nickname.
  60. sprintf(
  61. _m('%s has subscribed to receive all notices on this site matching the following searches:'),
  62. $this->getTarget()->getNickname()
  63. )
  64. );
  65. }
  66. }
  67. public function showContent()
  68. {
  69. if (Event::handle('StartShowTagSubscriptionsContent', array($this))) {
  70. parent::showContent();
  71. $offset = ($this->page - 1) * PROFILES_PER_PAGE;
  72. $limit = PROFILES_PER_PAGE + 1;
  73. $cnt = 0;
  74. $searchsub = new SearchSub();
  75. $searchsub->profile_id = $this->getTarget()->getID();
  76. $searchsub->limit($limit, $offset);
  77. $searchsub->find();
  78. if ($searchsub->N) {
  79. $list = new SearchSubscriptionsList($searchsub, $this->getTarget(), $this);
  80. $cnt = $list->show();
  81. if (0 == $cnt) {
  82. $this->showEmptyListMessage();
  83. }
  84. } else {
  85. $this->showEmptyListMessage();
  86. }
  87. $this->pagination(
  88. $this->page > 1,
  89. $cnt > PROFILES_PER_PAGE,
  90. $this->page,
  91. 'searchsubs',
  92. array('nickname' => $this->getTarget()->getNickname())
  93. );
  94. Event::handle('EndShowTagSubscriptionsContent', array($this));
  95. }
  96. }
  97. public function showEmptyListMessage()
  98. {
  99. if (common_logged_in()) {
  100. if ($this->scoped->sameAs($this->getTarget())) {
  101. // TRANS: Search subscription list text when the logged in user has no search subscriptions.
  102. $message = _m('You are not subscribed to any text searches right now. You can push the "Subscribe" button ' .
  103. 'on any notice text search to automatically receive any public messages on this site that match that ' .
  104. 'search, even if you are not subscribed to the poster.');
  105. } else {
  106. // TRANS: Search subscription list text when looking at the subscriptions for a of a user other
  107. // TRANS: than the logged in user that has no search subscriptions. %s is the user nickname.
  108. $message = sprintf(_m('%s is not subscribed to any searches.'), $this->getTarget()->getNickname());
  109. }
  110. } else {
  111. // TRANS: Subscription list text when looking at the subscriptions for a of a user that has none
  112. // TRANS: as an anonymous user. %s is the user nickname.
  113. $message = sprintf(_m('%s is not subscribed to any searches.'), $this->getTarget()->getNickname());
  114. }
  115. $this->elementStart('div', 'guide');
  116. $this->raw(common_markup_to_html($message));
  117. $this->elementEnd('div');
  118. }
  119. }
  120. // XXX SubscriptionsList and SubscriptionList are dangerously close
  121. class SearchSubscriptionsList extends SubscriptionList
  122. {
  123. public function newListItem(Profile $searchsub)
  124. {
  125. return new SearchSubscriptionsListItem($searchsub, $this->owner, $this->action);
  126. }
  127. }
  128. class SearchSubscriptionsListItem extends SubscriptionListItem
  129. {
  130. public function startItem()
  131. {
  132. $this->out->elementStart('li', array('class' => 'searchsub'));
  133. }
  134. public function showProfile()
  135. {
  136. $searchsub = $this->profile;
  137. $search = $searchsub->search;
  138. // Relevant portion!
  139. $cur = common_current_user();
  140. if (!empty($cur) && $cur->id == $this->owner->id) {
  141. $this->showOwnerControls();
  142. }
  143. $url = common_local_url('noticesearch', array('q' => $search));
  144. // TRANS: Search subscription list item. %1$s is a URL to a notice search,
  145. // TRANS: %2$s are the search criteria, %3$s is a datestring.
  146. $linkline = sprintf(
  147. _m('"<a href="%1$s">%2$s</a>" since %3$s'),
  148. htmlspecialchars($url),
  149. htmlspecialchars($search),
  150. common_date_string($searchsub->created)
  151. );
  152. $this->out->elementStart('div', 'searchsub-item');
  153. $this->out->raw($linkline);
  154. $this->out->element('div', array('style' => 'clear: both'));
  155. $this->out->elementEnd('div');
  156. }
  157. public function showActions()
  158. {
  159. }
  160. public function showOwnerControls()
  161. {
  162. $this->out->elementStart('div', 'entity_actions');
  163. $searchsub = $this->profile; // ?
  164. $form = new SearchUnsubForm($this->out, $searchsub->search);
  165. $form->show();
  166. $this->out->elementEnd('div');
  167. return;
  168. }
  169. }