showfavorites.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List of replies
  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 Personal
  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('GNUSOCIAL')) { exit(1); }
  30. /**
  31. * List of replies
  32. *
  33. * @category Personal
  34. * @package StatusNet
  35. * @author Evan Prodromou <evan@status.net>
  36. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  37. * @link http://status.net/
  38. */
  39. class ShowfavoritesAction extends ShowstreamAction
  40. {
  41. function title()
  42. {
  43. if ($this->page == 1) {
  44. // TRANS: Title for first page of favourite notices of a user.
  45. // TRANS: %s is the user for whom the favourite notices are displayed.
  46. return sprintf(_('%s\'s favorite notices'), $this->getTarget()->getNickname());
  47. } else {
  48. // TRANS: Title for all but the first page of favourite notices of a user.
  49. // TRANS: %1$s is the user for whom the favourite notices are displayed, %2$d is the page number.
  50. return sprintf(_('%1$s\'s favorite notices, page %2$d'),
  51. $this->getTarget()->getNickname(),
  52. $this->page);
  53. }
  54. }
  55. public function getStream()
  56. {
  57. $own = $this->scoped instanceof Profile ? $this->scoped->sameAs($this->getTarget()) : false;
  58. return new FaveNoticeStream($this->getTarget()->getID(), $own);
  59. }
  60. function getFeeds()
  61. {
  62. return array(new Feed(Feed::JSON,
  63. common_local_url('ApiTimelineFavorites',
  64. array(
  65. 'id' => $this->user->nickname,
  66. 'format' => 'as')),
  67. // TRANS: Feed link text. %s is a username.
  68. sprintf(_('Feed for favorites of %s (Activity Streams JSON)'),
  69. $this->user->nickname)),
  70. new Feed(Feed::RSS1,
  71. common_local_url('favoritesrss',
  72. array('nickname' => $this->user->nickname)),
  73. // TRANS: Feed link text. %s is a username.
  74. sprintf(_('Feed for favorites of %s (RSS 1.0)'),
  75. $this->user->nickname)),
  76. new Feed(Feed::RSS2,
  77. common_local_url('ApiTimelineFavorites',
  78. array(
  79. 'id' => $this->user->nickname,
  80. 'format' => 'rss')),
  81. // TRANS: Feed link text. %s is a username.
  82. sprintf(_('Feed for favorites of %s (RSS 2.0)'),
  83. $this->user->nickname)),
  84. new Feed(Feed::ATOM,
  85. common_local_url('ApiTimelineFavorites',
  86. array(
  87. 'id' => $this->user->nickname,
  88. 'format' => 'atom')),
  89. // TRANS: Feed link text. %s is a username.
  90. sprintf(_('Feed for favorites of %s (Atom)'),
  91. $this->user->nickname)));
  92. }
  93. function showEmptyListMessage()
  94. {
  95. if (common_logged_in()) {
  96. $current_user = common_current_user();
  97. if ($this->user->id === $current_user->id) {
  98. // TRANS: Text displayed instead of favourite notices for the current logged in user that has no favourites.
  99. $message = _('You haven\'t chosen any favorite notices yet. Click the fave button on notices you like to bookmark them for later or shed a spotlight on them.');
  100. } else {
  101. // TRANS: Text displayed instead of favourite notices for a user that has no favourites while logged in.
  102. // TRANS: %s is a username.
  103. $message = sprintf(_('%s hasn\'t added any favorite notices yet. Post something interesting they would add to their favorites :)'), $this->user->nickname);
  104. }
  105. }
  106. else {
  107. // TRANS: Text displayed instead of favourite notices for a user that has no favourites while not logged in.
  108. // TRANS: %s is a username, %%%%action.register%%%% is a link to the user registration page.
  109. // TRANS: (link text)[link] is a Mark Down link.
  110. $message = sprintf(_('%s hasn\'t added any favorite notices yet. Why not [register an account](%%%%action.register%%%%) and then post something interesting they would add to their favorites :)'), $this->user->nickname);
  111. }
  112. $this->elementStart('div', 'guide');
  113. $this->raw(common_markup_to_html($message));
  114. $this->elementEnd('div');
  115. }
  116. /**
  117. * Show the content
  118. *
  119. * A list of notices that this user has marked as a favorite
  120. *
  121. * @return void
  122. */
  123. function showNotices()
  124. {
  125. $nl = new FavoritesNoticeList($this->notice, $this);
  126. $cnt = $nl->show();
  127. if (0 == $cnt) {
  128. $this->showEmptyListMessage();
  129. }
  130. $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
  131. $this->page, 'showfavorites',
  132. array('nickname' => $this->getTarget()->getNickname()));
  133. }
  134. function showPageNotice() {
  135. // TRANS: Page notice for show favourites page.
  136. $this->element('p', 'instructions', _('This is a way to share what you like.'));
  137. }
  138. }
  139. class FavoritesNoticeList extends NoticeList
  140. {
  141. function newListItem($notice)
  142. {
  143. return new FavoritesNoticeListItem($notice, $this->out);
  144. }
  145. }
  146. // All handled by superclass
  147. class FavoritesNoticeListItem extends DoFollowListItem
  148. {
  149. }