sitestreamaction.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. if (!defined('GNUSOCIAL')) { exit(1); }
  3. // Farther than any human will go
  4. define('MAX_PUBLIC_PAGE', 100);
  5. class SitestreamAction extends ManagedAction
  6. {
  7. /**
  8. * page of the stream we're on; default = 1
  9. */
  10. var $page = null;
  11. var $notice;
  12. protected $stream = null;
  13. function isReadOnly($args)
  14. {
  15. return true;
  16. }
  17. protected function doPreparation()
  18. {
  19. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  20. if ($this->page > MAX_PUBLIC_PAGE) {
  21. // TRANS: Client error displayed when requesting a public timeline page beyond the page limit.
  22. // TRANS: %s is the page limit.
  23. $this->clientError(sprintf(_('Beyond the page limit (%s).'), MAX_PUBLIC_PAGE));
  24. }
  25. common_set_returnto($this->selfUrl());
  26. $this->streamPrepare();
  27. $this->notice = $this->stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
  28. NOTICES_PER_PAGE + 1);
  29. if (!$this->notice) {
  30. // TRANS: Server error displayed when a public timeline cannot be retrieved.
  31. $this->serverError(_('Could not retrieve public timeline.'));
  32. }
  33. if ($this->page > 1 && $this->notice->N == 0){
  34. // TRANS: Client error when page not found (404).
  35. $this->clientError(_('No such page.'), 404);
  36. }
  37. return true;
  38. }
  39. /**
  40. * Title of the page
  41. *
  42. * @return page title, including page number if over 1
  43. */
  44. function title()
  45. {
  46. if ($this->page > 1) {
  47. // TRANS: Title for all public timeline pages but the first.
  48. // TRANS: %d is the page number.
  49. return sprintf(_('Public timeline, page %d'), $this->page);
  50. } else {
  51. // TRANS: Title for the first public timeline page.
  52. return _('Public timeline');
  53. }
  54. }
  55. function extraHead()
  56. {
  57. parent::extraHead();
  58. $rsd = common_local_url('rsd');
  59. // RSD, http://tales.phrasewise.com/rfc/rsd
  60. $this->element('link', array('rel' => 'EditURI',
  61. 'type' => 'application/rsd+xml',
  62. 'href' => $rsd));
  63. if ($this->page != 1) {
  64. $this->element('link', array('rel' => 'canonical',
  65. 'href' => common_local_url('public')));
  66. }
  67. }
  68. /**
  69. * Output <head> elements for RSS and Atom feeds
  70. *
  71. * @return void
  72. */
  73. function getFeeds()
  74. {
  75. return array(new Feed(Feed::JSON,
  76. common_local_url('ApiTimelinePublic',
  77. array('format' => 'as')),
  78. // TRANS: Link description for public timeline feed.
  79. _('Public Timeline Feed (Activity Streams JSON)')),
  80. new Feed(Feed::RSS1, common_local_url('publicrss'),
  81. // TRANS: Link description for public timeline feed.
  82. _('Public Timeline Feed (RSS 1.0)')),
  83. new Feed(Feed::RSS2,
  84. common_local_url('ApiTimelinePublic',
  85. array('format' => 'rss')),
  86. // TRANS: Link description for public timeline feed.
  87. _('Public Timeline Feed (RSS 2.0)')),
  88. new Feed(Feed::ATOM,
  89. common_local_url('ApiTimelinePublic',
  90. array('format' => 'atom')),
  91. // TRANS: Link description for public timeline feed.
  92. _('Public Timeline Feed (Atom)')));
  93. }
  94. function showEmptyList()
  95. {
  96. // TRANS: Text displayed for public feed when there are no public notices.
  97. $message = _('This is the public timeline for %%site.name%% but no one has posted anything yet.') . ' ';
  98. if (common_logged_in()) {
  99. // TRANS: Additional text displayed for public feed when there are no public notices for a logged in user.
  100. $message .= _('Be the first to post!');
  101. }
  102. else {
  103. if (! (common_config('site','closed') || common_config('site','inviteonly'))) {
  104. // TRANS: Additional text displayed for public feed when there are no public notices for a not logged in user.
  105. $message .= _('Why not [register an account](%%action.register%%) and be the first to post!');
  106. }
  107. }
  108. $this->elementStart('div', 'guide');
  109. $this->raw(common_markup_to_html($message));
  110. $this->elementEnd('div');
  111. }
  112. /**
  113. * Fill the content area
  114. *
  115. * Shows a list of the notices in the public stream, with some pagination
  116. * controls.
  117. *
  118. * @return void
  119. */
  120. function showContent()
  121. {
  122. if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
  123. $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
  124. } else {
  125. $nl = new ThreadedNoticeList($this->notice, $this, $this->scoped);
  126. }
  127. $cnt = $nl->show();
  128. if ($cnt == 0) {
  129. $this->showEmptyList();
  130. }
  131. $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
  132. $this->page, $this->action);
  133. }
  134. function showAnonymousMessage()
  135. {
  136. if (! (common_config('site','closed') || common_config('site','inviteonly'))) {
  137. // TRANS: Message for not logged in users at an invite-only site trying to view the public feed of notices.
  138. // TRANS: This message contains Markdown links. Please mind the formatting.
  139. $m = _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  140. 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
  141. '[Join now](%%action.register%%) to share notices about yourself with friends, family, and colleagues! ' .
  142. '([Read more](%%doc.help%%))');
  143. } else {
  144. // TRANS: Message for not logged in users at a closed site trying to view the public feed of notices.
  145. // TRANS: This message contains Markdown links. Please mind the formatting.
  146. $m = _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  147. 'based on the Free Software [StatusNet](http://status.net/) tool.');
  148. }
  149. $this->elementStart('div', array('id' => 'anon_notice'));
  150. $this->raw(common_markup_to_html($m));
  151. $this->elementEnd('div');
  152. }
  153. }