bookmarks.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. * Give a warm greeting to our friendly user
  4. *
  5. * PHP version 5
  6. *
  7. * @category Bookmark
  8. * @package StatusNet
  9. * @author Evan Prodromou <evan@status.net>
  10. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  11. * @link http://status.net/
  12. *
  13. * StatusNet - the distributed open-source microblogging tool
  14. * Copyright (C) 2009, StatusNet, Inc.
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. /**
  33. * List currently logged-in user's bookmakrs
  34. *
  35. * @category Bookmark
  36. * @package StatusNet
  37. * @author Stephane Berube <chimo@chromic.org>
  38. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  39. * @link https://github.com/chimo/BookmarkList
  40. */
  41. class BookmarksAction extends Action
  42. {
  43. var $user = null;
  44. var $gc = null;
  45. /**
  46. * Take arguments for running
  47. *
  48. * This method is called first, and it lets the action class get
  49. * all its arguments and validate them. It's also the time
  50. * to fetch any relevant data from the database.
  51. *
  52. * Action classes should run parent::prepare($args) as the first
  53. * line of this method to make sure the default argument-processing
  54. * happens.
  55. *
  56. * @param array $args $_REQUEST args
  57. *
  58. * @return boolean success flag
  59. */
  60. function prepare(array $args = array())
  61. {
  62. parent::prepare($args);
  63. if (common_config('singleuser', 'enabled')) {
  64. $nickname = User::singleUserNickname();
  65. } else {
  66. // PHP 5.4
  67. // $nickname = $this->returnToArgs()[1]['nickname'];
  68. // PHP < 5.4
  69. $nickname = $this->returnToArgs();
  70. $nickname = $nickname[1]['nickname'];
  71. }
  72. $this->user = User::getKV('nickname', $nickname);
  73. if (!$this->user) {
  74. // TRANS: Client error displayed when trying to display bookmarks for a non-existing user.
  75. $this->clientError(_('No such user.'));
  76. }
  77. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  78. $stream = new BookmarksNoticeStream($this->user->id, true);
  79. $this->notices = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
  80. NOTICES_PER_PAGE + 1);
  81. if($this->page > 1 && $this->notices->N == 0) {
  82. throw new ClientException(_('No such page.'), 404);
  83. }
  84. return true;
  85. }
  86. /**
  87. * Handle request
  88. *
  89. * This is the main method for handling a request. Note that
  90. * most preparation should be done in the prepare() method;
  91. * by the time handle() is called the action should be
  92. * more or less ready to go.
  93. *
  94. * @param array $args $_REQUEST args; handled in prepare()
  95. *
  96. * @return void
  97. */
  98. function handle()
  99. {
  100. parent::handle();
  101. $this->showPage();
  102. }
  103. /**
  104. * Title of this page
  105. *
  106. * Override this method to show a custom title.
  107. *
  108. * @return string Title of the page
  109. */
  110. function title()
  111. {
  112. if (empty($this->user)) {
  113. // TRANS: Page title for sample plugin.
  114. return _m('Log in');
  115. } else {
  116. // TRANS: Page title for sample plugin. %s is a user nickname.
  117. return sprintf(_m('%s\'s bookmarks'), $this->user->nickname);
  118. }
  119. }
  120. /**
  121. * Feeds for the <head> section
  122. *
  123. * @return array Feed objects to show
  124. */
  125. function getFeeds()
  126. {
  127. return array(new Feed(Feed::JSON,
  128. common_local_url('ApiTimelineBookmarks',
  129. array(
  130. 'id' => $this->user->nickname,
  131. 'format' => 'as')),
  132. // TRANS: Feed link text. %s is a username.
  133. sprintf(_('Feed for bookmarks of %s (Activity Streams JSON)'),
  134. $this->user->nickname)),
  135. new Feed(Feed::RSS1,
  136. common_local_url('bookmarksrss',
  137. array('nickname' => $this->user->nickname)),
  138. // TRANS: Feed link text. %s is a username.
  139. sprintf(_('Feed for bookmarks of %s (RSS 1.0)'),
  140. $this->user->nickname)),
  141. new Feed(Feed::RSS2,
  142. common_local_url('ApiTimelineBookmarks',
  143. array(
  144. 'id' => $this->user->nickname,
  145. 'format' => 'rss')),
  146. // TRANS: Feed link text. %s is a username.
  147. sprintf(_('Feed for bookmarks of %s (RSS 2.0)'),
  148. $this->user->nickname)),
  149. new Feed(Feed::ATOM,
  150. common_local_url('ApiTimelineBookmarks',
  151. array(
  152. 'id' => $this->user->nickname,
  153. 'format' => 'atom')),
  154. // TRANS: Feed link text. %s is a username.
  155. sprintf(_('Feed for bookmarks of %s (Atom)'),
  156. $this->user->nickname)));
  157. }
  158. /**
  159. * Show content in the content area
  160. *
  161. * The default StatusNet page has a lot of decorations: menus,
  162. * logos, tabs, all that jazz. This method is used to show
  163. * content in the content area of the page; it's the main
  164. * thing you want to overload.
  165. *
  166. * This method also demonstrates use of a plural localized string.
  167. *
  168. * @return void
  169. */
  170. function showContent()
  171. {
  172. $nl = new NoticeList($this->notices, $this);
  173. $cnt = $nl->show();
  174. if ($cnt == 0) {
  175. $this->showEmptyList();
  176. }
  177. $this->pagination($this->page > 1,
  178. $cnt > NOTICES_PER_PAGE,
  179. $this->page, 'bookmarks',
  180. array('nickname' => $this->user->nickname));
  181. }
  182. function showEmptyList() {
  183. $message = sprintf(_('This is %1$s\'s bookmark stream, but %1$s hasn\'t bookmarked anything yet.'), $this->user->nickname) . ' ';
  184. $this->elementStart('div', 'guide');
  185. $this->raw(common_markup_to_html($message));
  186. $this->elementEnd('div');
  187. }
  188. /**
  189. * Return true if read only.
  190. *
  191. * Some actions only read from the database; others read and write.
  192. * The simple database load-balancer built into StatusNet will
  193. * direct read-only actions to database mirrors (if they are configured),
  194. * and read-write actions to the master database.
  195. *
  196. * This defaults to false to avoid data integrity issues, but you
  197. * should make sure to overload it for performance gains.
  198. *
  199. * @param array $args other arguments, if RO/RW status depends on them.
  200. *
  201. * @return boolean is read only action?
  202. */
  203. function isReadOnly($args)
  204. {
  205. return true;
  206. }
  207. }