searchsubs.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List of a user's subscriptions
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Social
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @author Sarven Capadisli <csarven@status.net>
  26. * @copyright 2008-2009 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * A list of the user's subscriptions
  33. *
  34. * @category Social
  35. * @package StatusNet
  36. * @author Evan Prodromou <evan@status.net>
  37. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  38. * @link http://status.net/
  39. */
  40. class SearchSubsAction extends GalleryAction
  41. {
  42. function title()
  43. {
  44. if ($this->page == 1) {
  45. // TRANS: Header for subscriptions overview for a user (first page).
  46. // TRANS: %s is a user nickname.
  47. return sprintf(_m('%s\'s search subscriptions'), $this->getTarget()->getNickname());
  48. } else {
  49. // TRANS: Header for subscriptions overview for a user (not first page).
  50. // TRANS: %1$s is a user nickname, %2$d is the page number.
  51. return sprintf(_m('%1$s\'s search subscriptions, page %2$d'),
  52. $this->getTarget()->getNickname(),
  53. $this->page);
  54. }
  55. }
  56. function showPageNotice()
  57. {
  58. if ($this->scoped instanceof Profile && $this->scoped->sameAs($this->getTarget())) {
  59. $this->element('p', null,
  60. // TRANS: Page notice for page with an overview of all search subscriptions
  61. // TRANS: of the logged in user's own profile.
  62. _m('You have subscribed to receive all notices on this site matching the following searches:'));
  63. } else {
  64. $this->element('p', null,
  65. // TRANS: Page notice for page with an overview of all subscriptions of a user other
  66. // TRANS: than the logged in user. %s is the user nickname.
  67. sprintf(_m('%s has subscribed to receive all notices on this site matching the following searches:'),
  68. $this->getTarget()->getNickname()));
  69. }
  70. }
  71. function showContent()
  72. {
  73. if (Event::handle('StartShowTagSubscriptionsContent', array($this))) {
  74. parent::showContent();
  75. $offset = ($this->page-1) * PROFILES_PER_PAGE;
  76. $limit = PROFILES_PER_PAGE + 1;
  77. $cnt = 0;
  78. $searchsub = new SearchSub();
  79. $searchsub->profile_id = $this->getTarget()->getID();
  80. $searchsub->limit($limit, $offset);
  81. $searchsub->find();
  82. if ($searchsub->N) {
  83. $list = new SearchSubscriptionsList($searchsub, $this->getTarget(), $this);
  84. $cnt = $list->show();
  85. if (0 == $cnt) {
  86. $this->showEmptyListMessage();
  87. }
  88. } else {
  89. $this->showEmptyListMessage();
  90. }
  91. $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
  92. $this->page, 'searchsubs',
  93. array('nickname' => $this->getTarget()->getNickname()));
  94. Event::handle('EndShowTagSubscriptionsContent', array($this));
  95. }
  96. }
  97. 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. }
  111. else {
  112. // TRANS: Subscription list text when looking at the subscriptions for a of a user that has none
  113. // TRANS: as an anonymous user. %s is the user nickname.
  114. $message = sprintf(_m('%s is not subscribed to any searches.'), $this->getTarget()->getNickname());
  115. }
  116. $this->elementStart('div', 'guide');
  117. $this->raw(common_markup_to_html($message));
  118. $this->elementEnd('div');
  119. }
  120. }
  121. // XXX SubscriptionsList and SubscriptionList are dangerously close
  122. class SearchSubscriptionsList extends SubscriptionList
  123. {
  124. function newListItem(Profile $searchsub)
  125. {
  126. return new SearchSubscriptionsListItem($searchsub, $this->owner, $this->action);
  127. }
  128. }
  129. class SearchSubscriptionsListItem extends SubscriptionListItem
  130. {
  131. function startItem()
  132. {
  133. $this->out->elementStart('li', array('class' => 'searchsub'));
  134. }
  135. function showProfile()
  136. {
  137. $searchsub = $this->profile;
  138. $search = $searchsub->search;
  139. // Relevant portion!
  140. $cur = common_current_user();
  141. if (!empty($cur) && $cur->id == $this->owner->id) {
  142. $this->showOwnerControls();
  143. }
  144. $url = common_local_url('noticesearch', array('q' => $search));
  145. // TRANS: Search subscription list item. %1$s is a URL to a notice search,
  146. // TRANS: %2$s are the search criteria, %3$s is a datestring.
  147. $linkline = sprintf(_m('"<a href="%1$s">%2$s</a>" since %3$s'),
  148. htmlspecialchars($url),
  149. htmlspecialchars($search),
  150. common_date_string($searchsub->created));
  151. $this->out->elementStart('div', 'searchsub-item');
  152. $this->out->raw($linkline);
  153. $this->out->element('div', array('style' => 'clear: both'));
  154. $this->out->elementEnd('div');
  155. }
  156. function showActions()
  157. {
  158. }
  159. function showOwnerControls()
  160. {
  161. $this->out->elementStart('div', 'entity_actions');
  162. $searchsub = $this->profile; // ?
  163. $form = new SearchUnsubForm($this->out, $searchsub->search);
  164. $form->show();
  165. $this->out->elementEnd('div');
  166. return;
  167. }
  168. }