showprofiletag.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008, 2009, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @category Actions
  20. * @package Actions
  21. * @license GNU Affero General Public License http://www.gnu.org/licenses/
  22. * @link http://status.net
  23. */
  24. if (!defined('GNUSOCIAL')) { exit(1); }
  25. class ShowprofiletagAction extends ShowstreamAction
  26. {
  27. var $notice, $peopletag;
  28. protected function doStreamPreparation()
  29. {
  30. $tag = common_canonical_tag($this->arg('tag'));
  31. try {
  32. $this->peopletag = Profile_list::getByPK(['tagger' => $this->target->getID(), 'tag' => $tag]);
  33. } catch (NoResultException $e) {
  34. // TRANS: Client error displayed trying to reference a non-existing list.
  35. throw new ClientException('No such list.');
  36. }
  37. if ($this->peopletag->private && !$this->peopletag->getTagger()->sameAs($this->scoped)) {
  38. // TRANS: Client error displayed trying to reference a non-existing list.
  39. throw new AuthorizationException('You do not have permission to see this list.');
  40. }
  41. }
  42. public function getStream()
  43. {
  44. return new PeopletagNoticeStream($this->peopletag, $this->scoped);
  45. }
  46. function title()
  47. {
  48. if ($this->page > 1) {
  49. if($this->peopletag->private) {
  50. // TRANS: Title for private list timeline.
  51. // TRANS: %1$s is a list, %2$s is a page number.
  52. return sprintf(_('Private timeline for %1$s list by you, page %2$d'),
  53. $this->peopletag->tag, $this->page);
  54. }
  55. $current = common_current_user();
  56. if (!empty($current) && $current->id == $this->peopletag->tagger) {
  57. // TRANS: Title for public list timeline where the viewer is the tagger.
  58. // TRANS: %1$s is a list, %2$s is a page number.
  59. return sprintf(_('Timeline for %1$s list by you, page %2$d'),
  60. $this->peopletag->tag, $this->page);
  61. }
  62. // TRANS: Title for private list timeline.
  63. // TRANS: %1$s is a list, %2$s is the tagger's nickname, %3$d is a page number.
  64. return sprintf(_('Timeline for %1$s list by %2$s, page %3$d'),
  65. $this->peopletag->tag,
  66. $this->target->getNickname(),
  67. $this->page
  68. );
  69. } else {
  70. if($this->peopletag->private) {
  71. // TRANS: Title for private list timeline.
  72. // TRANS: %s is a list.
  73. return sprintf(_('Private timeline of %s list by you'),
  74. $this->peopletag->tag);
  75. }
  76. $current = common_current_user();
  77. if (!empty($current) && $current->id == $this->peopletag->tagger) {
  78. // TRANS: Title for public list timeline where the viewer is the tagger.
  79. // TRANS: %s is a list.
  80. return sprintf(_('Timeline for %s list by you'),
  81. $this->peopletag->tag);
  82. }
  83. // TRANS: Title for private list timeline.
  84. // TRANS: %1$s is a list, %2$s is the tagger's nickname.
  85. return sprintf(_('Timeline for %1$s list by %2$s'),
  86. $this->peopletag->tag,
  87. $this->target->getNickname()
  88. );
  89. }
  90. }
  91. function getFeeds()
  92. {
  93. #XXX: make these actually work
  94. return array(new Feed(Feed::JSON,
  95. common_local_url(
  96. 'ApiTimelineList', array(
  97. 'user' => $this->target->id,
  98. 'id' => $this->peopletag->id,
  99. 'format' => 'as'
  100. )
  101. ),
  102. // TRANS: Feed title.
  103. // TRANS: %s is tagger's nickname.
  104. sprintf(_('Feed for friends of %s (Activity Streams JSON)'), $this->target->getNickname())),
  105. new Feed(Feed::RSS2,
  106. common_local_url(
  107. 'ApiTimelineList', array(
  108. 'user' => $this->target->id,
  109. 'id' => $this->peopletag->id,
  110. 'format' => 'rss'
  111. )
  112. ),
  113. // TRANS: Feed title.
  114. // TRANS: %s is tagger's nickname.
  115. sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->target->getNickname())),
  116. new Feed(Feed::ATOM,
  117. common_local_url(
  118. 'ApiTimelineList', array(
  119. 'user' => $this->target->id,
  120. 'id' => $this->peopletag->id,
  121. 'format' => 'atom'
  122. )
  123. ),
  124. // TRANS: Feed title.
  125. // TRANS: %1$s is a list, %2$s is tagger's nickname.
  126. sprintf(_('Feed for %1$s list by %2$s (Atom)'),
  127. $this->peopletag->tag, $this->target->getNickname()
  128. )
  129. )
  130. );
  131. }
  132. function showObjectNav()
  133. {
  134. $nav = new PeopletagGroupNav($this);
  135. $nav->show();
  136. }
  137. function showEmptyListMessage()
  138. {
  139. // TRANS: Empty list message for list timeline.
  140. // TRANS: %1$s is a list, %2$s is a tagger's nickname.
  141. $message = sprintf(_('This is the timeline for %1$s list by %2$s but no one has posted anything yet.'),
  142. $this->peopletag->tag,
  143. $this->target->getNickname()) . ' ';
  144. if (common_logged_in()) {
  145. if ($this->target->sameAs($this->scoped)) {
  146. // TRANS: Additional empty list message for list timeline for currently logged in user tagged tags.
  147. $message .= _('Try tagging more people.');
  148. }
  149. } else {
  150. // TRANS: Additional empty list message for list timeline.
  151. // TRANS: This message contains Markdown links in the form [description](link).
  152. $message .= _('Why not [register an account](%%%%action.register%%%%) and start following this timeline!');
  153. }
  154. $this->elementStart('div', 'guide');
  155. $this->raw(common_markup_to_html($message));
  156. $this->elementEnd('div');
  157. }
  158. protected function showContent()
  159. {
  160. $this->showPeopletag();
  161. parent::showContent();
  162. }
  163. function showPeopletag()
  164. {
  165. $tag = new Peopletag($this->peopletag, $this->scoped, $this);
  166. $tag->show();
  167. }
  168. function showNotices()
  169. {
  170. if (Event::handle('StartShowProfileTagContent', array($this))) {
  171. $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
  172. $cnt = $nl->show();
  173. if (0 == $cnt) {
  174. $this->showEmptyListMessage();
  175. }
  176. $this->pagination($this->page > 1,
  177. $cnt > NOTICES_PER_PAGE,
  178. $this->page,
  179. 'showprofiletag',
  180. array('tag' => $this->peopletag->tag,
  181. 'nickname' => $this->target->getNickname())
  182. );
  183. Event::handle('EndShowProfileTagContent', array($this));
  184. }
  185. }
  186. function showSections()
  187. {
  188. $this->showTagged();
  189. if (!$this->peopletag->private) {
  190. $this->showSubscribers();
  191. }
  192. # $this->showStatistics();
  193. }
  194. function showTagged()
  195. {
  196. $profile = $this->peopletag->getTagged(0, PROFILES_PER_MINILIST + 1);
  197. $this->elementStart('div', array('id' => 'entity_tagged',
  198. 'class' => 'section'));
  199. if (Event::handle('StartShowTaggedProfilesMiniList', array($this))) {
  200. $title = '';
  201. // TRANS: Header on show list page.
  202. $this->element('h2', null, _('Listed'));
  203. $cnt = 0;
  204. if (!empty($profile)) {
  205. $pml = new ProfileMiniList($profile, $this);
  206. $cnt = $pml->show();
  207. if ($cnt == 0) {
  208. // TRANS: Content of "Listed" page if there are no listed users.
  209. $this->element('p', null, _('(None)'));
  210. }
  211. }
  212. if ($cnt > PROFILES_PER_MINILIST) {
  213. $this->elementStart('p');
  214. $this->element('a', array('href' => common_local_url('taggedprofiles',
  215. array('nickname' => $this->target->getNickname(),
  216. 'profiletag' => $this->peopletag->tag)),
  217. 'class' => 'more'),
  218. // TRANS: Link for more "People in list x by a user"
  219. // TRANS: if there are more than the mini list's maximum.
  220. _('Show all'));
  221. $this->elementEnd('p');
  222. }
  223. Event::handle('EndShowTaggedProfilesMiniList', array($this));
  224. }
  225. $this->elementEnd('div');
  226. }
  227. function showSubscribers()
  228. {
  229. $profile = $this->peopletag->getSubscribers(0, PROFILES_PER_MINILIST + 1);
  230. $this->elementStart('div', array('id' => 'entity_subscribers',
  231. 'class' => 'section'));
  232. if (Event::handle('StartShowProfileTagSubscribersMiniList', array($this))) {
  233. // TRANS: Header for tag subscribers.
  234. $this->element('h2', null, _('Subscribers'));
  235. $cnt = 0;
  236. if (!empty($profile)) {
  237. $pml = new ProfileMiniList($profile, $this);
  238. $cnt = $pml->show();
  239. if ($cnt == 0) {
  240. // TRANS: Content of "People following tag x" if there are no subscribed users.
  241. $this->element('p', null, _('(None)'));
  242. }
  243. }
  244. // FIXME: link to full list
  245. Event::handle('EndShowProfileTagSubscribersMiniList', array($this));
  246. }
  247. $this->elementEnd('div');
  248. }
  249. }