subscriptions.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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('STATUSNET') && !defined('LACONICA')) {
  31. exit(1);
  32. }
  33. /**
  34. * A list of the user's subscriptions
  35. *
  36. * @category Social
  37. * @package StatusNet
  38. * @author Evan Prodromou <evan@status.net>
  39. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  40. * @link http://status.net/
  41. */
  42. class SubscriptionsAction extends GalleryAction
  43. {
  44. function title()
  45. {
  46. if ($this->page == 1) {
  47. // TRANS: Header for subscriptions overview for a user (first page).
  48. // TRANS: %s is a user nickname.
  49. return sprintf(_('%s subscriptions'), $this->target->getNickname());
  50. } else {
  51. // TRANS: Header for subscriptions overview for a user (not first page).
  52. // TRANS: %1$s is a user nickname, %2$d is the page number.
  53. return sprintf(_('%1$s subscriptions, page %2$d'),
  54. $this->target->getNickname(),
  55. $this->page);
  56. }
  57. }
  58. function showPageNotice()
  59. {
  60. if ($this->scoped instanceof Profile && $this->scoped->id === $this->target->id) {
  61. $this->element('p', null,
  62. // TRANS: Page notice for page with an overview of all subscriptions
  63. // TRANS: of the logged in user's own profile.
  64. _('These are the people whose notices '.
  65. 'you listen to.'));
  66. } else {
  67. $this->element('p', null,
  68. // TRANS: Page notice for page with an overview of all subscriptions of a user other
  69. // TRANS: than the logged in user. %s is the user nickname.
  70. sprintf(_('These are the people whose '.
  71. 'notices %s listens to.'),
  72. $this->target->getNickname()));
  73. }
  74. }
  75. function getAllTags()
  76. {
  77. return $this->getTags('subscribed', 'subscriber');
  78. }
  79. function showContent()
  80. {
  81. if (Event::handle('StartShowSubscriptionsContent', array($this))) {
  82. parent::showContent();
  83. $offset = ($this->page-1) * PROFILES_PER_PAGE;
  84. $limit = PROFILES_PER_PAGE + 1;
  85. $cnt = 0;
  86. if ($this->tag) {
  87. $subscriptions = $this->target->getTaggedSubscriptions($this->tag, $offset, $limit);
  88. } else {
  89. $subscriptions = $this->target->getSubscribed($offset, $limit);
  90. }
  91. if ($subscriptions) {
  92. $subscriptions_list = new SubscriptionsList($subscriptions, $this->target, $this);
  93. $cnt = $subscriptions_list->show();
  94. if (0 == $cnt) {
  95. $this->showEmptyListMessage();
  96. }
  97. }
  98. $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
  99. $this->page, 'subscriptions',
  100. array('nickname' => $this->target->getNickname()));
  101. Event::handle('EndShowSubscriptionsContent', array($this));
  102. }
  103. }
  104. function showScripts()
  105. {
  106. parent::showScripts();
  107. $this->autofocus('tag');
  108. }
  109. function showEmptyListMessage()
  110. {
  111. if ($this->scoped instanceof Profile && $this->target->id === $this->scoped->id) {
  112. // TRANS: Subscription list text when the logged in user has no subscriptions.
  113. // TRANS: This message contains Markdown URLs. The link description is between
  114. // TRANS: square brackets, and the link between parentheses. Do not separate "]("
  115. // TRANS: and do not change the URL part.
  116. $message = _('You\'re not listening to anyone\'s notices right now, try subscribing to people you know. '.
  117. 'Try [people search](%%action.peoplesearch%%), look for members in groups you\'re interested '.
  118. 'in and in our [featured users](%%action.featured%%).');
  119. } else {
  120. // TRANS: Subscription list text when looking at the subscriptions for a of a user that has none
  121. // TRANS: as an anonymous user. %s is the user nickname.
  122. $message = sprintf(_('%s is not listening to anyone.'), $this->target->getNickname());
  123. }
  124. $this->elementStart('div', 'guide');
  125. $this->raw(common_markup_to_html($message));
  126. $this->elementEnd('div');
  127. }
  128. /**
  129. * Link to feeds of subscriptions
  130. *
  131. * @return array of Feed objects
  132. */
  133. function getFeeds()
  134. {
  135. return array(new Feed(Feed::ATOM,
  136. common_local_url('AtomPubSubscriptionFeed',
  137. array('subscriber' => $this->target->id)),
  138. // TRANS: Atom feed title. %s is a profile nickname.
  139. sprintf(_('Subscription feed for %s (Atom)'),
  140. $this->target->getNickname())));
  141. }
  142. }
  143. // XXX SubscriptionsList and SubscriptionList are dangerously close
  144. class SubscriptionsList extends SubscriptionList
  145. {
  146. function newListItem($profile)
  147. {
  148. return new SubscriptionsListItem($profile, $this->owner, $this->action);
  149. }
  150. }
  151. class SubscriptionsListItem extends SubscriptionListItem
  152. {
  153. function showOwnerControls()
  154. {
  155. $sub = Subscription::pkeyGet(array('subscriber' => $this->owner->id,
  156. 'subscribed' => $this->profile->id));
  157. if (!$sub) {
  158. return;
  159. }
  160. $transports = array();
  161. Event::handle('GetImTransports', array(&$transports));
  162. if (!$transports && !common_config('sms', 'enabled')) {
  163. return;
  164. }
  165. $this->out->elementStart('form', array('id' => 'subedit-' . $this->profile->id,
  166. 'method' => 'post',
  167. 'class' => 'form_subscription_edit',
  168. 'action' => common_local_url('subedit')));
  169. $this->out->hidden('token', common_session_token());
  170. $this->out->hidden('profile', $this->profile->id);
  171. if ($transports) {
  172. $attrs = array('name' => 'jabber',
  173. 'type' => 'checkbox',
  174. 'class' => 'checkbox',
  175. 'id' => 'jabber-'.$this->profile->id);
  176. if ($sub->jabber) {
  177. $attrs['checked'] = 'checked';
  178. }
  179. $this->out->element('input', $attrs);
  180. // TRANS: Checkbox label for enabling IM messages for a profile in a subscriptions list.
  181. $this->out->element('label', array('for' => 'jabber-'.$this->profile->id), _m('LABEL','IM'));
  182. } else {
  183. $this->out->hidden('jabber', $sub->jabber);
  184. }
  185. if (common_config('sms', 'enabled')) {
  186. $attrs = array('name' => 'sms',
  187. 'type' => 'checkbox',
  188. 'class' => 'checkbox',
  189. 'id' => 'sms-'.$this->profile->id);
  190. if ($sub->sms) {
  191. $attrs['checked'] = 'checked';
  192. }
  193. $this->out->element('input', $attrs);
  194. // TRANS: Checkbox label for enabling SMS messages for a profile in a subscriptions list.
  195. $this->out->element('label', array('for' => 'sms-'.$this->profile->id), _('SMS'));
  196. } else {
  197. $this->out->hidden('sms', $sub->sms);
  198. }
  199. // TRANS: Save button for settings for a profile in a subscriptions list.
  200. $this->out->submit('save', _m('BUTTON','Save'));
  201. $this->out->elementEnd('form');
  202. }
  203. }