public.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Action for displaying the public stream
  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 Public
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2008-2009 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. // Farther than any human will go
  31. define('MAX_PUBLIC_PAGE', 100);
  32. /**
  33. * Action for displaying the public stream
  34. *
  35. * @category Public
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. *
  41. * @see PublicrssAction
  42. * @see PublicxrdsAction
  43. */
  44. class PublicAction extends ManagedAction
  45. {
  46. /**
  47. * page of the stream we're on; default = 1
  48. */
  49. var $page = null;
  50. var $notice;
  51. protected $stream = null;
  52. function isReadOnly($args)
  53. {
  54. return true;
  55. }
  56. protected function doPreparation()
  57. {
  58. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  59. if ($this->page > MAX_PUBLIC_PAGE) {
  60. // TRANS: Client error displayed when requesting a public timeline page beyond the page limit.
  61. // TRANS: %s is the page limit.
  62. $this->clientError(sprintf(_('Beyond the page limit (%s).'), MAX_PUBLIC_PAGE));
  63. }
  64. common_set_returnto($this->selfUrl());
  65. $this->streamPrepare();
  66. $this->notice = $this->stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
  67. NOTICES_PER_PAGE + 1);
  68. if (!$this->notice) {
  69. // TRANS: Server error displayed when a public timeline cannot be retrieved.
  70. $this->serverError(_('Could not retrieve public timeline.'));
  71. }
  72. if ($this->page > 1 && $this->notice->N == 0){
  73. // TRANS: Client error when page not found (404).
  74. $this->clientError(_('No such page.'), 404);
  75. }
  76. return true;
  77. }
  78. protected function streamPrepare()
  79. {
  80. if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
  81. $this->stream = new PublicNoticeStream($this->scoped);
  82. } else {
  83. $this->stream = new ThreadingPublicNoticeStream($this->scoped);
  84. }
  85. }
  86. /**
  87. * Title of the page
  88. *
  89. * @return page title, including page number if over 1
  90. */
  91. function title()
  92. {
  93. if ($this->page > 1) {
  94. // TRANS: Title for all public timeline pages but the first.
  95. // TRANS: %d is the page number.
  96. return sprintf(_('Public timeline, page %d'), $this->page);
  97. } else {
  98. // TRANS: Title for the first public timeline page.
  99. return _('Public timeline');
  100. }
  101. }
  102. function extraHead()
  103. {
  104. parent::extraHead();
  105. $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
  106. 'content' => common_local_url('publicxrds')));
  107. $rsd = common_local_url('rsd');
  108. // RSD, http://tales.phrasewise.com/rfc/rsd
  109. $this->element('link', array('rel' => 'EditURI',
  110. 'type' => 'application/rsd+xml',
  111. 'href' => $rsd));
  112. if ($this->page != 1) {
  113. $this->element('link', array('rel' => 'canonical',
  114. 'href' => common_local_url('public')));
  115. }
  116. }
  117. /**
  118. * Output <head> elements for RSS and Atom feeds
  119. *
  120. * @return void
  121. */
  122. function getFeeds()
  123. {
  124. return array(new Feed(Feed::JSON,
  125. common_local_url('ApiTimelinePublic',
  126. array('format' => 'as')),
  127. // TRANS: Link description for public timeline feed.
  128. _('Public Timeline Feed (Activity Streams JSON)')),
  129. new Feed(Feed::RSS1, common_local_url('publicrss'),
  130. // TRANS: Link description for public timeline feed.
  131. _('Public Timeline Feed (RSS 1.0)')),
  132. new Feed(Feed::RSS2,
  133. common_local_url('ApiTimelinePublic',
  134. array('format' => 'rss')),
  135. // TRANS: Link description for public timeline feed.
  136. _('Public Timeline Feed (RSS 2.0)')),
  137. new Feed(Feed::ATOM,
  138. common_local_url('ApiTimelinePublic',
  139. array('format' => 'atom')),
  140. // TRANS: Link description for public timeline feed.
  141. _('Public Timeline Feed (Atom)')));
  142. }
  143. function showEmptyList()
  144. {
  145. // TRANS: Text displayed for public feed when there are no public notices.
  146. $message = _('This is the public timeline for %%site.name%% but no one has posted anything yet.') . ' ';
  147. if (common_logged_in()) {
  148. // TRANS: Additional text displayed for public feed when there are no public notices for a logged in user.
  149. $message .= _('Be the first to post!');
  150. }
  151. else {
  152. if (! (common_config('site','closed') || common_config('site','inviteonly'))) {
  153. // TRANS: Additional text displayed for public feed when there are no public notices for a not logged in user.
  154. $message .= _('Why not [register an account](%%action.register%%) and be the first to post!');
  155. }
  156. }
  157. $this->elementStart('div', 'guide');
  158. $this->raw(common_markup_to_html($message));
  159. $this->elementEnd('div');
  160. }
  161. /**
  162. * Fill the content area
  163. *
  164. * Shows a list of the notices in the public stream, with some pagination
  165. * controls.
  166. *
  167. * @return void
  168. */
  169. function showContent()
  170. {
  171. if ($this->scoped instanceof Profile && $this->scoped->isLocal() && $this->scoped->getUser()->streamModeOnly()) {
  172. $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
  173. } else {
  174. $nl = new ThreadedNoticeList($this->notice, $this, $this->scoped);
  175. }
  176. $cnt = $nl->show();
  177. if ($cnt == 0) {
  178. $this->showEmptyList();
  179. }
  180. $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
  181. $this->page, $this->action);
  182. }
  183. function showSections()
  184. {
  185. // Show invite button, as long as site isn't closed, and
  186. // we have a logged in user.
  187. if (common_config('invite', 'enabled') && !common_config('site', 'closed') && common_logged_in()) {
  188. if (!common_config('site', 'private')) {
  189. $ibs = new InviteButtonSection(
  190. $this,
  191. // TRANS: Button text for inviting more users to the StatusNet instance.
  192. // TRANS: Less business/enterprise-oriented language for public sites.
  193. _m('BUTTON', 'Send invite')
  194. );
  195. } else {
  196. $ibs = new InviteButtonSection($this);
  197. }
  198. $ibs->show();
  199. }
  200. $p = Profile::current();
  201. if (!common_config('performance', 'high')) {
  202. $cloud = new PublicTagCloudSection($this);
  203. $cloud->show();
  204. }
  205. $feat = new FeaturedUsersSection($this);
  206. $feat->show();
  207. }
  208. function showAnonymousMessage()
  209. {
  210. if (! (common_config('site','closed') || common_config('site','inviteonly'))) {
  211. // TRANS: Message for not logged in users at an invite-only site trying to view the public feed of notices.
  212. // TRANS: This message contains Markdown links. Please mind the formatting.
  213. $m = _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  214. 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
  215. '[Join now](%%action.register%%) to share notices about yourself with friends, family, and colleagues! ' .
  216. '([Read more](%%doc.help%%))');
  217. } else {
  218. // TRANS: Message for not logged in users at a closed site trying to view the public feed of notices.
  219. // TRANS: This message contains Markdown links. Please mind the formatting.
  220. $m = _('This is %%site.name%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  221. 'based on the Free Software [StatusNet](http://status.net/) tool.');
  222. }
  223. $this->elementStart('div', array('id' => 'anon_notice'));
  224. $this->raw(common_markup_to_html($m));
  225. $this->elementEnd('div');
  226. }
  227. }