PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/actions/showfavorites.php

https://gitlab.com/windigo-gs/windigos-gnu-social
PHP | 261 lines | 130 code | 29 blank | 102 comment | 21 complexity | 3f6f9e941f8af6510ef59b79cec335c1 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0
  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. if (!empty($cur) && $cur->id == $this->user->id) {
  106. // Show imported/gateway notices as well as local if
  107. // the user is looking at their own favorites
  108. $this->notice = $this->user->favoriteNotices(true, ($this->page-1)*NOTICES_PER_PAGE,
  109. NOTICES_PER_PAGE + 1);
  110. } else {
  111. $this->notice = $this->user->favoriteNotices(false, ($this->page-1)*NOTICES_PER_PAGE,
  112. NOTICES_PER_PAGE + 1);
  113. }
  114. if (empty($this->notice)) {
  115. // TRANS: Server error displayed when favourite notices could not be retrieved from the database.
  116. $this->serverError(_('Could not retrieve favorite notices.'));
  117. }
  118. if($this->page > 1 && $this->notice->N == 0){
  119. // TRANS: Server error when page not found (404)
  120. $this->serverError(_('No such page.'),$code=404);
  121. }
  122. return true;
  123. }
  124. /**
  125. * Handle a request
  126. *
  127. * Just show the page. All args already handled.
  128. *
  129. * @param array $args $_REQUEST data
  130. *
  131. * @return void
  132. */
  133. function handle($args)
  134. {
  135. parent::handle($args);
  136. $this->showPage();
  137. }
  138. /**
  139. * Feeds for the <head> section
  140. *
  141. * @return array Feed objects to show
  142. */
  143. function getFeeds()
  144. {
  145. return array(new Feed(Feed::JSON,
  146. common_local_url('ApiTimelineFavorites',
  147. array(
  148. 'id' => $this->user->nickname,
  149. 'format' => 'as')),
  150. // TRANS: Feed link text. %s is a username.
  151. sprintf(_('Feed for favorites of %s (Activity Streams JSON)'),
  152. $this->user->nickname)),
  153. new Feed(Feed::RSS1,
  154. common_local_url('favoritesrss',
  155. array('nickname' => $this->user->nickname)),
  156. // TRANS: Feed link text. %s is a username.
  157. sprintf(_('Feed for favorites of %s (RSS 1.0)'),
  158. $this->user->nickname)),
  159. new Feed(Feed::RSS2,
  160. common_local_url('ApiTimelineFavorites',
  161. array(
  162. 'id' => $this->user->nickname,
  163. 'format' => 'rss')),
  164. // TRANS: Feed link text. %s is a username.
  165. sprintf(_('Feed for favorites of %s (RSS 2.0)'),
  166. $this->user->nickname)),
  167. new Feed(Feed::ATOM,
  168. common_local_url('ApiTimelineFavorites',
  169. array(
  170. 'id' => $this->user->nickname,
  171. 'format' => 'atom')),
  172. // TRANS: Feed link text. %s is a username.
  173. sprintf(_('Feed for favorites of %s (Atom)'),
  174. $this->user->nickname)));
  175. }
  176. function showEmptyListMessage()
  177. {
  178. if (common_logged_in()) {
  179. $current_user = common_current_user();
  180. if ($this->user->id === $current_user->id) {
  181. // TRANS: Text displayed instead of favourite notices for the current logged in user that has no favourites.
  182. $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.');
  183. } else {
  184. // TRANS: Text displayed instead of favourite notices for a user that has no favourites while logged in.
  185. // TRANS: %s is a username.
  186. $message = sprintf(_('%s hasn\'t added any favorite notices yet. Post something interesting they would add to their favorites :)'), $this->user->nickname);
  187. }
  188. }
  189. else {
  190. // TRANS: Text displayed instead of favourite notices for a user that has no favourites while not logged in.
  191. // TRANS: %s is a username, %%%%action.register%%%% is a link to the user registration page.
  192. // TRANS: (link text)[link] is a Mark Down link.
  193. $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);
  194. }
  195. $this->elementStart('div', 'guide');
  196. $this->raw(common_markup_to_html($message));
  197. $this->elementEnd('div');
  198. }
  199. /**
  200. * Show the content
  201. *
  202. * A list of notices that this user has marked as a favorite
  203. *
  204. * @return void
  205. */
  206. function showContent()
  207. {
  208. $nl = new FavoritesNoticeList($this->notice, $this);
  209. $cnt = $nl->show();
  210. if (0 == $cnt) {
  211. $this->showEmptyListMessage();
  212. }
  213. $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
  214. $this->page, 'showfavorites',
  215. array('nickname' => $this->user->nickname));
  216. }
  217. function showPageNotice() {
  218. // TRANS: Page notice for show favourites page.
  219. $this->element('p', 'instructions', _('This is a way to share what you like.'));
  220. }
  221. }
  222. class FavoritesNoticeList extends NoticeList
  223. {
  224. function newListItem($notice)
  225. {
  226. return new FavoritesNoticeListItem($notice, $this->out);
  227. }
  228. }
  229. // All handled by superclass
  230. class FavoritesNoticeListItem extends DoFollowListItem
  231. {
  232. }