all.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008-2011, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @category Actions
  20. * @package Actions
  21. * @author Adrian Lang <mail@adrianlang.de>
  22. * @author Brenda Wallace <shiny@cpan.org>
  23. * @author Brion Vibber <brion@pobox.com>
  24. * @author Craig Andrews <candrews@integralblue.com>
  25. * @author Evan Prodromou <evan@status.net>
  26. * @author Jeffery To <jeffery.to@gmail.com>
  27. * @author Meitar Moscovitz <meitarm@gmail.com>
  28. * @author Mike Cochrane <mikec@mikenz.geek.nz>
  29. * @author Robin Millette <millette@status.net>
  30. * @author Sarven Capadisli <csarven@status.net>
  31. * @author Siebrand Mazeland <s.mazeland@xs4all.nl>
  32. * @author Zach Copley <zach@status.net>
  33. * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
  34. * @license GNU Affero General Public License http://www.gnu.org/licenses/
  35. * @link http://status.net
  36. */
  37. if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
  38. class AllAction extends ProfileAction
  39. {
  40. var $notice;
  41. protected function prepare(array $args=array())
  42. {
  43. parent::prepare($args);
  44. $user = common_current_user();
  45. if (!empty($user) && $user->streamModeOnly()) {
  46. $stream = new InboxNoticeStream($this->target, $this->scoped);
  47. } else {
  48. $stream = new ThreadingInboxNoticeStream($this->target, $this->scoped);
  49. }
  50. $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
  51. NOTICES_PER_PAGE + 1);
  52. if ($this->page > 1 && $this->notice->N == 0) {
  53. // TRANS: Client error when page not found (404).
  54. $this->clientError(_('No such page.'), 404);
  55. }
  56. return true;
  57. }
  58. function title()
  59. {
  60. if (!empty($this->scoped) && $this->scoped->id == $this->target->id) {
  61. // TRANS: Title of a user's own start page.
  62. return _('Home timeline');
  63. } else {
  64. // TRANS: Title of another user's start page.
  65. // TRANS: %s is the other user's name.
  66. return sprintf(_("%s's home timeline"), $this->target->getBestName());
  67. }
  68. }
  69. function getFeeds()
  70. {
  71. return array(
  72. new Feed(Feed::JSON,
  73. common_local_url(
  74. 'ApiTimelineFriends', array(
  75. 'format' => 'as',
  76. 'id' => $this->target->nickname
  77. )
  78. ),
  79. // TRANS: %s is user nickname.
  80. sprintf(_('Feed for friends of %s (Activity Streams JSON)'), $this->target->nickname)),
  81. new Feed(Feed::RSS1,
  82. common_local_url(
  83. 'allrss', array(
  84. 'nickname' =>
  85. $this->target->nickname)
  86. ),
  87. // TRANS: %s is user nickname.
  88. sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->target->nickname)),
  89. new Feed(Feed::RSS2,
  90. common_local_url(
  91. 'ApiTimelineFriends', array(
  92. 'format' => 'rss',
  93. 'id' => $this->target->nickname
  94. )
  95. ),
  96. // TRANS: %s is user nickname.
  97. sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->target->nickname)),
  98. new Feed(Feed::ATOM,
  99. common_local_url(
  100. 'ApiTimelineFriends', array(
  101. 'format' => 'atom',
  102. 'id' => $this->target->nickname
  103. )
  104. ),
  105. // TRANS: %s is user nickname.
  106. sprintf(_('Feed for friends of %s (Atom)'), $this->target->nickname))
  107. );
  108. }
  109. function showEmptyListMessage()
  110. {
  111. // TRANS: Empty list message. %s is a user nickname.
  112. $message = sprintf(_('This is the timeline for %s and friends but no one has posted anything yet.'), $this->target->nickname) . ' ';
  113. if (common_logged_in()) {
  114. if ($this->target->id === $this->scoped->id) {
  115. // TRANS: Encouragement displayed on logged in user's empty timeline.
  116. // TRANS: This message contains Markdown links. Keep "](" together.
  117. $message .= _('Try subscribing to more people, [join a group](%%action.groups%%) or post something yourself.');
  118. } else {
  119. // TRANS: %1$s is user nickname, %2$s is user nickname, %2$s is user nickname prefixed with "@".
  120. // TRANS: This message contains Markdown links. Keep "](" together.
  121. $message .= sprintf(_('You can try to [nudge %1$s](../%2$s) from their profile or [post something to them](%%%%action.newnotice%%%%?status_textarea=%3$s).'), $this->target->nickname, $this->target->nickname, '@' . $this->target->nickname);
  122. }
  123. } else {
  124. // TRANS: Encouragement displayed on empty timeline user pages for anonymous users.
  125. // TRANS: %s is a user nickname. This message contains Markdown links. Keep "](" together.
  126. $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->nickname);
  127. }
  128. $this->elementStart('div', 'guide');
  129. $this->raw(common_markup_to_html($message));
  130. $this->elementEnd('div');
  131. }
  132. function showContent()
  133. {
  134. if (Event::handle('StartShowAllContent', array($this))) {
  135. $profile = null;
  136. $current_user = common_current_user();
  137. if (!empty($current_user)) {
  138. $profile = $current_user->getProfile();
  139. }
  140. if (!empty($current_user) && $current_user->streamModeOnly()) {
  141. $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
  142. } else {
  143. $nl = new ThreadedNoticeList($this->notice, $this, $profile);
  144. }
  145. $cnt = $nl->show();
  146. if (0 == $cnt) {
  147. $this->showEmptyListMessage();
  148. }
  149. $this->pagination(
  150. $this->page > 1, $cnt > NOTICES_PER_PAGE,
  151. $this->page, 'all', array('nickname' => $this->target->nickname)
  152. );
  153. Event::handle('EndShowAllContent', array($this));
  154. }
  155. }
  156. function showSections()
  157. {
  158. // Show invite button, as long as site isn't closed, and
  159. // we have a logged in user.
  160. if (common_config('invite', 'enabled') && !common_config('site', 'closed') && common_logged_in()) {
  161. if (!common_config('site', 'private')) {
  162. $ibs = new InviteButtonSection(
  163. $this,
  164. // TRANS: Button text for inviting more users to the StatusNet instance.
  165. // TRANS: Less business/enterprise-oriented language for public sites.
  166. _m('BUTTON', 'Send invite')
  167. );
  168. } else {
  169. $ibs = new InviteButtonSection($this);
  170. }
  171. $ibs->show();
  172. }
  173. // XXX: make this a little more convenient
  174. if (!common_config('performance', 'high')) {
  175. $pop = new InboxTagCloudSection($this, $this->target);
  176. $pop->show();
  177. }
  178. }
  179. }
  180. class ThreadingInboxNoticeStream extends ThreadingNoticeStream
  181. {
  182. function __construct(Profile $target, Profile $scoped=null)
  183. {
  184. parent::__construct(new InboxNoticeStream($target, $scoped));
  185. }
  186. }