replies.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 RepliesAction extends Action
  45. {
  46. var $page = null;
  47. var $notice;
  48. /**
  49. * Prepare the object
  50. *
  51. * Check the input values and initialize the object.
  52. * Shows an error page on bad input.
  53. *
  54. * @param array $args $_REQUEST data
  55. *
  56. * @return boolean success flag
  57. */
  58. function prepare($args)
  59. {
  60. parent::prepare($args);
  61. $nickname = common_canonical_nickname($this->arg('nickname'));
  62. $this->user = User::getKV('nickname', $nickname);
  63. if (!$this->user) {
  64. // TRANS: Client error displayed when trying to reply to a non-exsting user.
  65. $this->clientError(_('No such user.'));
  66. }
  67. $profile = $this->user->getProfile();
  68. if (!$profile) {
  69. // TRANS: Error message displayed when referring to a user without a profile.
  70. $this->serverError(_('User has no profile.'));
  71. }
  72. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  73. common_set_returnto($this->selfUrl());
  74. $stream = new ReplyNoticeStream($this->user->id,
  75. Profile::current());
  76. $this->notice = $stream->getNotices(($this->page-1) * NOTICES_PER_PAGE,
  77. NOTICES_PER_PAGE + 1);
  78. if($this->page > 1 && $this->notice->N == 0){
  79. // TRANS: Client error when page not found (404)
  80. $this->clientError(_('No such page.'), 404);
  81. }
  82. return true;
  83. }
  84. /**
  85. * Handle a request
  86. *
  87. * Just show the page. All args already handled.
  88. *
  89. * @param array $args $_REQUEST data
  90. *
  91. * @return void
  92. */
  93. function handle($args)
  94. {
  95. parent::handle($args);
  96. $this->showPage();
  97. }
  98. /**
  99. * Title of the page
  100. *
  101. * Includes name of user and page number.
  102. *
  103. * @return string title of page
  104. */
  105. function title()
  106. {
  107. if ($this->page == 1) {
  108. // TRANS: Title for first page of replies for a user.
  109. // TRANS: %s is a user nickname.
  110. return sprintf(_("Replies to %s"), $this->user->nickname);
  111. } else {
  112. // TRANS: Title for all but the first page of replies for a user.
  113. // TRANS: %1$s is a user nickname, %2$d is a page number.
  114. return sprintf(_('Replies to %1$s, page %2$d'),
  115. $this->user->nickname,
  116. $this->page);
  117. }
  118. }
  119. /**
  120. * Feeds for the <head> section
  121. *
  122. * @return void
  123. */
  124. function getFeeds()
  125. {
  126. return array(new Feed(Feed::JSON,
  127. common_local_url('ApiTimelineMentions',
  128. array(
  129. 'id' => $this->user->nickname,
  130. 'format' => 'as')),
  131. // TRANS: Link for feed with replies for a user.
  132. // TRANS: %s is a user nickname.
  133. sprintf(_('Replies feed for %s (Activity Streams JSON)'),
  134. $this->user->nickname)),
  135. new Feed(Feed::RSS1,
  136. common_local_url('repliesrss',
  137. array('nickname' => $this->user->nickname)),
  138. // TRANS: Link for feed with replies for a user.
  139. // TRANS: %s is a user nickname.
  140. sprintf(_('Replies feed for %s (RSS 1.0)'),
  141. $this->user->nickname)),
  142. new Feed(Feed::RSS2,
  143. common_local_url('ApiTimelineMentions',
  144. array(
  145. 'id' => $this->user->nickname,
  146. 'format' => 'rss')),
  147. // TRANS: Link for feed with replies for a user.
  148. // TRANS: %s is a user nickname.
  149. sprintf(_('Replies feed for %s (RSS 2.0)'),
  150. $this->user->nickname)),
  151. new Feed(Feed::ATOM,
  152. common_local_url('ApiTimelineMentions',
  153. array(
  154. 'id' => $this->user->nickname,
  155. 'format' => 'atom')),
  156. // TRANS: Link for feed with replies for a user.
  157. // TRANS: %s is a user nickname.
  158. sprintf(_('Replies feed for %s (Atom)'),
  159. $this->user->nickname)));
  160. }
  161. /**
  162. * Show the content
  163. *
  164. * A list of notices that are replies to the user, plus pagination.
  165. *
  166. * @return void
  167. */
  168. function showContent()
  169. {
  170. $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
  171. $cnt = $nl->show();
  172. if (0 === $cnt) {
  173. $this->showEmptyListMessage();
  174. }
  175. $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
  176. $this->page, 'replies',
  177. array('nickname' => $this->user->nickname));
  178. }
  179. function showEmptyListMessage()
  180. {
  181. // TRANS: Empty list message for page with replies for a user.
  182. // TRANS: %1$s and %s$s are the user nickname.
  183. $message = sprintf(_('This is the timeline showing replies to %1$s but %2$s hasn\'t received a notice to them yet.'),
  184. $this->user->nickname,
  185. $this->user->nickname) . ' ';
  186. if (common_logged_in()) {
  187. $current_user = common_current_user();
  188. if ($this->user->id === $current_user->id) {
  189. // TRANS: Empty list message for page with replies for a user for the logged in user.
  190. // TRANS: This message contains a Markdown link in the form [link text](link).
  191. $message .= _('You can engage other users in a conversation, subscribe to more people or [join groups](%%action.groups%%).');
  192. } else {
  193. // TRANS: Empty list message for page with replies for a user for all logged in users but the user themselves.
  194. // TRANS: %1$s, %2$s and %3$s are a user nickname. This message contains a Markdown link in the form [link text](link).
  195. $message .= sprintf(_('You can try to [nudge %1$s](../%2$s) or [post something to them](%%%%action.newnotice%%%%?status_textarea=%3$s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname);
  196. }
  197. }
  198. else {
  199. // TRANS: Empty list message for page with replies for a user for not logged in users.
  200. // TRANS: %1$s is a user nickname. This message contains a Markdown link in the form [link text](link).
  201. $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->user->nickname);
  202. }
  203. $this->elementStart('div', 'guide');
  204. $this->raw(common_markup_to_html($message));
  205. $this->elementEnd('div');
  206. }
  207. function isReadOnly($args)
  208. {
  209. return true;
  210. }
  211. }