peopletagged.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List of people tagged by the user with a tag
  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 Shashi Gowda <connect2shashi@gmail.com>
  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/profile/profilelist.php';
  33. /**
  34. * List of people tagged by the user with a tag
  35. *
  36. * @category Peopletag
  37. * @package StatusNet
  38. * @author Shashi Gowda <connect2shashi@gmail.com>
  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 PeopletaggedAction 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 when referring to 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 when referring to 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: Title for list of people listed by the user.
  92. // TRANS: %1$s is a list, %2$s is a username.
  93. return sprintf(_('People listed in %1$s by %2$s'),
  94. $this->peopletag->tag, $this->tagger->nickname);
  95. } else {
  96. // TRANS: Title for list of people listed by the user.
  97. // TRANS: %1$s is a list, %2$s is a username, %2$s is a page number.
  98. return sprintf(_('People listed in %1$s by %2$s, page %3$d'),
  99. $this->peopletag->tag, $this->user->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, $this->peopletag);
  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->getTagged($offset, $limit);
  122. if ($subs) {
  123. $subscriber_list = new PeopletagMemberList($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, 'peopletagged',
  129. array('tagger' => $this->tagger->nickname,
  130. 'tag' => $this->peopletag->tag));
  131. }
  132. }
  133. class PeopletagMemberList 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 PeopletagMemberListItem($profile, $this->peopletag, $this->action);
  144. }
  145. }
  146. class PeopletagMemberListItem 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 membership 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. // TODO: Untag button
  169. Event::handle('EndProfileListItemActionElements', array($this));
  170. }
  171. $this->endActions();
  172. }
  173. function linkAttributes()
  174. {
  175. // tagging people is healthy page-rank flow.
  176. return parent::linkAttributes();
  177. }
  178. /**
  179. * Fetch necessary return-to arguments for the profile forms
  180. * to return to this list when they're done.
  181. *
  182. * @return array
  183. */
  184. protected function returnToArgs()
  185. {
  186. $args = array('action' => 'peopletagged',
  187. 'tag' => $this->peopletag->tag,
  188. 'tagger' => $this->profile->nickname);
  189. $page = $this->out->arg('page');
  190. if ($page) {
  191. $args['param-page'] = $page;
  192. }
  193. return $args;
  194. }
  195. }