peopletagsubscribers.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List of peopletag subscribers
  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 Group
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2008-2011 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once(INSTALLDIR.'/lib/profilelist.php');
  33. /**
  34. * List of peopletag subscribers
  35. *
  36. * @category Peopletag
  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 PeopletagsubscribersAction extends Action
  43. {
  44. var $page = null;
  45. var $peopletag = null;
  46. var $tagger = null;
  47. function isReadOnly($args)
  48. {
  49. return true;
  50. }
  51. function prepare(array $args = array())
  52. {
  53. parent::prepare($args);
  54. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  55. if (common_config('singleuser', 'enabled')) {
  56. $tagger_arg = User::singleUserNickname();
  57. } else {
  58. $tagger_arg = $this->arg('tagger');
  59. }
  60. $tag_arg = $this->arg('tag');
  61. $tagger = common_canonical_nickname($tagger_arg);
  62. $tag = common_canonical_tag($tag_arg);
  63. // Permanent redirect on non-canonical nickname
  64. if ($tagger_arg != $tagger || $tag_arg != $tag) {
  65. $args = array('tagger' => $nickname, 'tag' => $tag);
  66. if ($this->page != 1) {
  67. $args['page'] = $this->page;
  68. }
  69. common_redirect(common_local_url('peopletagged', $args), 301);
  70. }
  71. if (!$tagger) {
  72. // TRANS: Client error displayed when a tagger is expected but not provided.
  73. $this->clientError(_('No tagger.'), 404);
  74. }
  75. $user = User::getKV('nickname', $tagger);
  76. if (!$user) {
  77. // TRANS: Client error displayed trying to perform an action related to a non-existing user.
  78. $this->clientError(_('No such user.'), 404);
  79. }
  80. $this->tagger = $user->getProfile();
  81. $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
  82. if (!$this->peopletag) {
  83. // TRANS: Client error displayed trying to reference a non-existing list.
  84. $this->clientError(_('No such list.'), 404);
  85. }
  86. return true;
  87. }
  88. function title()
  89. {
  90. if ($this->page == 1) {
  91. // TRANS: Page title for list of list subscribers.
  92. // TRANS: %1$s is a list, %2$s is a user nickname.
  93. return sprintf(_('Subscribers to list %1$s by %2$s'),
  94. $this->peopletag->tag, $this->tagger->nickname);
  95. } else {
  96. // TRANS: Page title for list of list subscribers.
  97. // TRANS: %1$s is a list, %2$s is a user nickname, %3$d is a page number.
  98. return sprintf(_('Subscribers to list %1$s by %2$s, page %3$d'),
  99. $this->peopletag->tag, $this->tagger->nickname,
  100. $this->page);
  101. }
  102. }
  103. function handle()
  104. {
  105. parent::handle();
  106. $this->showPage();
  107. }
  108. function showPageNotice()
  109. {
  110. }
  111. function showLocalNav()
  112. {
  113. $nav = new PeopletagGroupNav($this);
  114. $nav->show();
  115. }
  116. function showContent()
  117. {
  118. $offset = ($this->page-1) * PROFILES_PER_PAGE;
  119. $limit = PROFILES_PER_PAGE + 1;
  120. $cnt = 0;
  121. $subs = $this->peopletag->getSubscribers($offset, $limit);
  122. if ($subs) {
  123. $subscriber_list = new PeopletagSubscriberList($subs, $this->peopletag, $this);
  124. $cnt = $subscriber_list->show();
  125. }
  126. $subs->free();
  127. $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
  128. $this->page, 'peopletagsubscribers',
  129. array('tagger' => $this->tagger->nickname,
  130. 'tag' => $this->peopletag->tag));
  131. }
  132. }
  133. class PeopletagSubscriberList extends ProfileList
  134. {
  135. var $peopletag = null;
  136. function __construct($profile, $peopletag, $action)
  137. {
  138. parent::__construct($profile, $action);
  139. $this->peopletag = $peopletag;
  140. }
  141. function newListItem(Profile $profile)
  142. {
  143. return new PeopletagSubscriberListItem($profile, $this->peopletag, $this->action);
  144. }
  145. }
  146. class PeopletagSubscriberListItem extends ProfileListItem
  147. {
  148. var $peopletag = null;
  149. function __construct($profile, $peopletag, $action)
  150. {
  151. parent::__construct($profile, $action);
  152. $this->peopletag = $peopletag;
  153. }
  154. function showFullName()
  155. {
  156. parent::showFullName();
  157. if ($this->profile->id == $this->peopletag->tagger) {
  158. $this->out->text(' ');
  159. // TRANS: Addition in tag subscribers list for creator of a tag.
  160. $this->out->element('span', 'role', _('Creator'));
  161. }
  162. }
  163. function showActions()
  164. {
  165. $this->startActions();
  166. if (Event::handle('StartProfileListItemActionElements', array($this))) {
  167. $this->showSubscribeButton();
  168. Event::handle('EndProfileListItemActionElements', array($this));
  169. }
  170. $this->endActions();
  171. }
  172. function linkAttributes()
  173. {
  174. $aAttrs = parent::linkAttributes();
  175. if (common_config('nofollow', 'members')) {
  176. $aAttrs['rel'] .= ' nofollow';
  177. }
  178. return $aAttrs;
  179. }
  180. function homepageAttributes()
  181. {
  182. $aAttrs = parent::linkAttributes();
  183. if (common_config('nofollow', 'members')) {
  184. $aAttrs['rel'] = 'nofollow';
  185. }
  186. return $aAttrs;
  187. }
  188. /**
  189. * Fetch necessary return-to arguments for the profile forms
  190. * to return to this list when they're done.
  191. *
  192. * @return array
  193. */
  194. protected function returnToArgs()
  195. {
  196. $args = array('action' => 'peopletagsubscribers',
  197. 'tag' => $this->peopletag->tag,
  198. 'tagger' => $this->profile->nickname);
  199. $page = $this->out->arg('page');
  200. if ($page) {
  201. $args['param-page'] = $page;
  202. }
  203. return $args;
  204. }
  205. }