showfavorites.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once INSTALLDIR.'/lib/personalgroupnav.php';
  33. require_once INSTALLDIR.'/lib/noticelist.php';
  34. require_once INSTALLDIR.'/lib/feedlist.php';
  35. /**
  36. * List of replies
  37. *
  38. * @category Personal
  39. * @package StatusNet
  40. * @author Evan Prodromou <evan@status.net>
  41. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  42. * @link http://status.net/
  43. */
  44. class ShowfavoritesAction extends Action
  45. {
  46. /** User we're getting the faves of */
  47. var $user = null;
  48. /** Page of the faves we're on */
  49. var $page = null;
  50. /**
  51. * Is this a read-only page?
  52. *
  53. * @return boolean true
  54. */
  55. function isReadOnly($args)
  56. {
  57. return true;
  58. }
  59. /**
  60. * Title of the page
  61. *
  62. * Includes name of user and page number.
  63. *
  64. * @return string title of page
  65. */
  66. function title()
  67. {
  68. if ($this->page == 1) {
  69. // TRANS: Title for first page of favourite notices of a user.
  70. // TRANS: %s is the user for whom the favourite notices are displayed.
  71. return sprintf(_('%s\'s favorite notices'), $this->user->nickname);
  72. } else {
  73. // TRANS: Title for all but the first page of favourite notices of a user.
  74. // TRANS: %1$s is the user for whom the favourite notices are displayed, %2$d is the page number.
  75. return sprintf(_('%1$s\'s favorite notices, page %2$d'),
  76. $this->user->nickname,
  77. $this->page);
  78. }
  79. }
  80. /**
  81. * Prepare the object
  82. *
  83. * Check the input values and initialize the object.
  84. * Shows an error page on bad input.
  85. *
  86. * @param array $args $_REQUEST data
  87. *
  88. * @return boolean success flag
  89. */
  90. function prepare($args)
  91. {
  92. parent::prepare($args);
  93. $nickname = common_canonical_nickname($this->arg('nickname'));
  94. $this->user = User::getKV('nickname', $nickname);
  95. if (!$this->user) {
  96. // TRANS: Client error displayed when trying to display favourite notices for a non-existing user.
  97. $this->clientError(_('No such user.'));
  98. }
  99. $this->page = $this->trimmed('page');
  100. if (!$this->page) {
  101. $this->page = 1;
  102. }
  103. common_set_returnto($this->selfUrl());
  104. $cur = common_current_user();
  105. // Show imported/gateway notices as well as local if
  106. // the user is looking at their own favorites, otherwise not.
  107. $this->notice = Fave::stream($this->user->id,
  108. ($this->page-1)*NOTICES_PER_PAGE, // offset
  109. NOTICES_PER_PAGE + 1, // limit
  110. (!empty($cur) && $cur->id == $this->user->id) // own feed?
  111. );
  112. if (empty($this->notice)) {
  113. // TRANS: Server error displayed when favourite notices could not be retrieved from the database.
  114. $this->serverError(_('Could not retrieve favorite notices.'));
  115. }
  116. if($this->page > 1 && $this->notice->N == 0){
  117. // TRANS: Client error when page not found (404)
  118. $this->clientError(_('No such page.'), 404);
  119. }
  120. return true;
  121. }
  122. /**
  123. * Handle a request
  124. *
  125. * Just show the page. All args already handled.
  126. *
  127. * @param array $args $_REQUEST data
  128. *
  129. * @return void
  130. */
  131. function handle($args)
  132. {
  133. parent::handle($args);
  134. $this->showPage();
  135. }
  136. /**
  137. * Feeds for the <head> section
  138. *
  139. * @return array Feed objects to show
  140. */
  141. function getFeeds()
  142. {
  143. return array(new Feed(Feed::JSON,
  144. common_local_url('ApiTimelineFavorites',
  145. array(
  146. 'id' => $this->user->nickname,
  147. 'format' => 'as')),
  148. // TRANS: Feed link text. %s is a username.
  149. sprintf(_('Feed for favorites of %s (Activity Streams JSON)'),
  150. $this->user->nickname)),
  151. new Feed(Feed::RSS1,
  152. common_local_url('favoritesrss',
  153. array('nickname' => $this->user->nickname)),
  154. // TRANS: Feed link text. %s is a username.
  155. sprintf(_('Feed for favorites of %s (RSS 1.0)'),
  156. $this->user->nickname)),
  157. new Feed(Feed::RSS2,
  158. common_local_url('ApiTimelineFavorites',
  159. array(
  160. 'id' => $this->user->nickname,
  161. 'format' => 'rss')),
  162. // TRANS: Feed link text. %s is a username.
  163. sprintf(_('Feed for favorites of %s (RSS 2.0)'),
  164. $this->user->nickname)),
  165. new Feed(Feed::ATOM,
  166. common_local_url('ApiTimelineFavorites',
  167. array(
  168. 'id' => $this->user->nickname,
  169. 'format' => 'atom')),
  170. // TRANS: Feed link text. %s is a username.
  171. sprintf(_('Feed for favorites of %s (Atom)'),
  172. $this->user->nickname)));
  173. }
  174. function showEmptyListMessage()
  175. {
  176. if (common_logged_in()) {
  177. $current_user = common_current_user();
  178. if ($this->user->id === $current_user->id) {
  179. // TRANS: Text displayed instead of favourite notices for the current logged in user that has no favourites.
  180. $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.');
  181. } else {
  182. // TRANS: Text displayed instead of favourite notices for a user that has no favourites while logged in.
  183. // TRANS: %s is a username.
  184. $message = sprintf(_('%s hasn\'t added any favorite notices yet. Post something interesting they would add to their favorites :)'), $this->user->nickname);
  185. }
  186. }
  187. else {
  188. // TRANS: Text displayed instead of favourite notices for a user that has no favourites while not logged in.
  189. // TRANS: %s is a username, %%%%action.register%%%% is a link to the user registration page.
  190. // TRANS: (link text)[link] is a Mark Down link.
  191. $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);
  192. }
  193. $this->elementStart('div', 'guide');
  194. $this->raw(common_markup_to_html($message));
  195. $this->elementEnd('div');
  196. }
  197. /**
  198. * Show the content
  199. *
  200. * A list of notices that this user has marked as a favorite
  201. *
  202. * @return void
  203. */
  204. function showContent()
  205. {
  206. $nl = new FavoritesNoticeList($this->notice, $this);
  207. $cnt = $nl->show();
  208. if (0 == $cnt) {
  209. $this->showEmptyListMessage();
  210. }
  211. $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
  212. $this->page, 'showfavorites',
  213. array('nickname' => $this->user->nickname));
  214. }
  215. function showPageNotice() {
  216. // TRANS: Page notice for show favourites page.
  217. $this->element('p', 'instructions', _('This is a way to share what you like.'));
  218. }
  219. }
  220. class FavoritesNoticeList extends NoticeList
  221. {
  222. function newListItem($notice)
  223. {
  224. return new FavoritesNoticeListItem($notice, $this->out);
  225. }
  226. }
  227. // All handled by superclass
  228. class FavoritesNoticeListItem extends DoFollowListItem
  229. {
  230. }