replies.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 RepliesAction extends ManagedAction
  40. {
  41. var $page = null;
  42. var $notice;
  43. protected function doPreparation()
  44. {
  45. $nickname = common_canonical_nickname($this->arg('nickname'));
  46. $this->user = User::getKV('nickname', $nickname);
  47. if (!$this->user instanceof User) {
  48. // TRANS: Client error displayed when trying to reply to a non-exsting user.
  49. $this->clientError(_('No such user.'));
  50. }
  51. $this->target = $this->user->getProfile();
  52. if (!$this->target instanceof Profile) {
  53. // TRANS: Error message displayed when referring to a user without a profile.
  54. $this->serverError(_('User has no profile.'));
  55. }
  56. $this->page = $this->int('page') ?: 1;
  57. common_set_returnto($this->selfUrl());
  58. $stream = new ReplyNoticeStream($this->target->getID(), $this->scoped);
  59. $this->notice = $stream->getNotices(($this->page-1) * NOTICES_PER_PAGE,
  60. NOTICES_PER_PAGE + 1);
  61. if ($this->page > 1 && $this->notice->N == 0) {
  62. // TRANS: Client error when page not found (404)
  63. $this->clientError(_('No such page.'), 404);
  64. }
  65. }
  66. /**
  67. * Title of the page
  68. *
  69. * Includes name of user and page number.
  70. *
  71. * @return string title of page
  72. */
  73. function title()
  74. {
  75. if ($this->page == 1) {
  76. // TRANS: Title for first page of replies for a user.
  77. // TRANS: %s is a user nickname.
  78. return sprintf(_("Replies to %s"), $this->target->getNickname());
  79. } else {
  80. // TRANS: Title for all but the first page of replies for a user.
  81. // TRANS: %1$s is a user nickname, %2$d is a page number.
  82. return sprintf(_('Replies to %1$s, page %2$d'),
  83. $this->target->getNickname(),
  84. $this->page);
  85. }
  86. }
  87. /**
  88. * Feeds for the <head> section
  89. *
  90. * @return void
  91. */
  92. function getFeeds()
  93. {
  94. return array(new Feed(Feed::JSON,
  95. common_local_url('ApiTimelineMentions',
  96. array(
  97. 'id' => $this->target->getNickname(),
  98. 'format' => 'as')),
  99. // TRANS: Link for feed with replies for a user.
  100. // TRANS: %s is a user nickname.
  101. sprintf(_('Replies feed for %s (Activity Streams JSON)'),
  102. $this->user->nickname)),
  103. new Feed(Feed::RSS1,
  104. common_local_url('repliesrss',
  105. array('nickname' => $this->target->getNickname())),
  106. // TRANS: Link for feed with replies for a user.
  107. // TRANS: %s is a user nickname.
  108. sprintf(_('Replies feed for %s (RSS 1.0)'),
  109. $this->target->getNickname())),
  110. new Feed(Feed::RSS2,
  111. common_local_url('ApiTimelineMentions',
  112. array(
  113. 'id' => $this->target->getNickname(),
  114. 'format' => 'rss')),
  115. // TRANS: Link for feed with replies for a user.
  116. // TRANS: %s is a user nickname.
  117. sprintf(_('Replies feed for %s (RSS 2.0)'),
  118. $this->target->getNickname())),
  119. new Feed(Feed::ATOM,
  120. common_local_url('ApiTimelineMentions',
  121. array(
  122. 'id' => $this->target->getNickname(),
  123. 'format' => 'atom')),
  124. // TRANS: Link for feed with replies for a user.
  125. // TRANS: %s is a user nickname.
  126. sprintf(_('Replies feed for %s (Atom)'),
  127. $this->target->getNickname())));
  128. }
  129. function showContent()
  130. {
  131. $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
  132. $cnt = $nl->show();
  133. if (0 === $cnt) {
  134. $this->showEmptyListMessage();
  135. }
  136. $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
  137. $this->page, 'replies',
  138. array('nickname' => $this->target->getNickname()));
  139. }
  140. function showEmptyListMessage()
  141. {
  142. // TRANS: Empty list message for page with replies for a user.
  143. // TRANS: %1$s is the user nickname.
  144. $message = sprintf(_('This is the timeline showing replies to %1$s but no notices have arrived yet.'), $this->target->getNickname());
  145. $message .= ' '; // Spacing between this sentence and the next.
  146. if (common_logged_in()) {
  147. if ($this->target->getID() === $this->scoped->getID()) {
  148. // TRANS: Empty list message for page with replies for a user for the logged in user.
  149. // TRANS: This message contains a Markdown link in the form [link text](link).
  150. $message .= _('You can engage other users in a conversation, subscribe to more people or [join groups](%%action.groups%%).');
  151. } else {
  152. // TRANS: Empty list message for page with replies for a user for all logged in users but the user themselves.
  153. // TRANS: %1$s is a user nickname and %2$s is the same but with a prepended '@' character. This message contains a Markdown link in the form [link text](link).
  154. $message .= sprintf(_('You can try to [nudge %1$s](../%1$s) or [post something to them](%%%%action.newnotice%%%%?content=%2$s).'), $this->target->getNickname(), '@' . $this->target->getNickname());
  155. }
  156. } else {
  157. // TRANS: Empty list message for page with replies for a user for not logged in users.
  158. // TRANS: %1$s is a user nickname. This message contains a Markdown link in the form [link text](link).
  159. $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->getNickname());
  160. }
  161. $this->elementStart('div', 'guide');
  162. $this->raw(common_markup_to_html($message));
  163. $this->elementEnd('div');
  164. }
  165. public function isReadOnly($args)
  166. {
  167. return true;
  168. }
  169. }