sitestreamaction.php 6.7 KB

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