PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/actions/showstream.php

https://gitlab.com/BeS/io.schiessle.org
PHP | 268 lines | 170 code | 25 blank | 73 comment | 28 complexity | 0ac963b872902e03ebf3e21c6782b294 MD5 | raw file
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * User profile page
  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. * @author Sarven Capadisli <csarven@status.net>
  26. * @copyright 2008-2009 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * User profile page
  33. *
  34. * When I created this page, "show stream" seemed like the best name for it.
  35. * Now, it seems like a really bad name.
  36. *
  37. * It shows a stream of the user's posts, plus lots of profile info, links
  38. * to subscriptions and stuff, etc.
  39. *
  40. * @category Personal
  41. * @package StatusNet
  42. * @author Evan Prodromou <evan@status.net>
  43. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  44. * @link http://status.net/
  45. */
  46. class ShowstreamAction extends NoticestreamAction
  47. {
  48. public function getStream()
  49. {
  50. if (empty($this->tag)) {
  51. $stream = new ProfileNoticeStream($this->target, $this->scoped);
  52. } else {
  53. $stream = new TaggedProfileNoticeStream($this->target, $this->tag, $this->scoped);
  54. }
  55. return $stream;
  56. }
  57. function title()
  58. {
  59. $base = $this->target->getFancyName();
  60. if (!empty($this->tag)) {
  61. if ($this->page == 1) {
  62. // TRANS: Page title showing tagged notices in one user's timeline.
  63. // TRANS: %1$s is the username, %2$s is the hash tag.
  64. return sprintf(_('Notices by %1$s tagged %2$s'), $base, $this->tag);
  65. } else {
  66. // TRANS: Page title showing tagged notices in one user's timeline.
  67. // TRANS: %1$s is the username, %2$s is the hash tag, %3$d is the page number.
  68. return sprintf(_('Notices by %1$s tagged %2$s, page %3$d'), $base, $this->tag, $this->page);
  69. }
  70. } else {
  71. if ($this->page == 1) {
  72. return sprintf(_('Notices by %s'), $base);
  73. } else {
  74. // TRANS: Extended page title showing tagged notices in one user's timeline.
  75. // TRANS: %1$s is the username, %2$d is the page number.
  76. return sprintf(_('Notices by %1$s, page %2$d'),
  77. $base,
  78. $this->page);
  79. }
  80. }
  81. }
  82. protected function showContent()
  83. {
  84. $this->showNotices();
  85. }
  86. function showProfileBlock()
  87. {
  88. $block = new AccountProfileBlock($this, $this->target);
  89. $block->show();
  90. }
  91. function showPageNoticeBlock()
  92. {
  93. return;
  94. }
  95. function getFeeds()
  96. {
  97. if (!empty($this->tag)) {
  98. return array(new Feed(Feed::RSS1,
  99. common_local_url('userrss',
  100. array('nickname' => $this->target->getNickname(),
  101. 'tag' => $this->tag)),
  102. // TRANS: Title for link to notice feed.
  103. // TRANS: %1$s is a user nickname, %2$s is a hashtag.
  104. sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
  105. $this->target->getNickname(), $this->tag)));
  106. }
  107. return array(new Feed(Feed::JSON,
  108. common_local_url('ApiTimelineUser',
  109. array(
  110. 'id' => $this->target->getID(),
  111. 'format' => 'as')),
  112. // TRANS: Title for link to notice feed.
  113. // TRANS: %s is a user nickname.
  114. sprintf(_('Notice feed for %s (Activity Streams JSON)'),
  115. $this->target->getNickname())),
  116. new Feed(Feed::RSS1,
  117. common_local_url('userrss',
  118. array('nickname' => $this->target->getNickname())),
  119. // TRANS: Title for link to notice feed.
  120. // TRANS: %s is a user nickname.
  121. sprintf(_('Notice feed for %s (RSS 1.0)'),
  122. $this->target->getNickname())),
  123. new Feed(Feed::RSS2,
  124. common_local_url('ApiTimelineUser',
  125. array(
  126. 'id' => $this->target->getID(),
  127. 'format' => 'rss')),
  128. // TRANS: Title for link to notice feed.
  129. // TRANS: %s is a user nickname.
  130. sprintf(_('Notice feed for %s (RSS 2.0)'),
  131. $this->target->getNickname())),
  132. new Feed(Feed::ATOM,
  133. common_local_url('ApiTimelineUser',
  134. array(
  135. 'id' => $this->target->getID(),
  136. 'format' => 'atom')),
  137. // TRANS: Title for link to notice feed.
  138. // TRANS: %s is a user nickname.
  139. sprintf(_('Notice feed for %s (Atom)'),
  140. $this->target->getNickname())),
  141. new Feed(Feed::FOAF,
  142. common_local_url('foaf', array('nickname' =>
  143. $this->target->getNickname())),
  144. // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
  145. // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
  146. sprintf(_('FOAF for %s'), $this->target->getNickname())));
  147. }
  148. function extraHead()
  149. {
  150. if ($this->target->bio) {
  151. $this->element('meta', array('name' => 'description',
  152. 'content' => $this->target->getDescription()));
  153. }
  154. // See https://wiki.mozilla.org/Microsummaries
  155. $this->element('link', array('rel' => 'microsummary',
  156. 'href' => common_local_url('microsummary',
  157. array('nickname' => $this->target->getNickname()))));
  158. $rsd = common_local_url('rsd',
  159. array('nickname' => $this->target->getNickname()));
  160. // RSD, http://tales.phrasewise.com/rfc/rsd
  161. $this->element('link', array('rel' => 'EditURI',
  162. 'type' => 'application/rsd+xml',
  163. 'href' => $rsd));
  164. if ($this->page != 1) {
  165. $this->element('link', array('rel' => 'canonical',
  166. 'href' => $this->target->getUrl()));
  167. }
  168. }
  169. function showEmptyListMessage()
  170. {
  171. // TRANS: First sentence of empty list message for a timeline. $1%s is a user nickname.
  172. $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->target->getNickname()) . ' ';
  173. if ($this->scoped instanceof Profile) {
  174. if ($this->target->getID() === $this->scoped->getID()) {
  175. // TRANS: Second sentence of empty list message for a stream for the user themselves.
  176. $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
  177. } else {
  178. // TRANS: Second sentence of empty list message for a non-self timeline. %1$s is a user nickname, %2$s is a part of a URL.
  179. // TRANS: This message contains a Markdown link. Keep "](" together.
  180. $message .= sprintf(_('You can try to nudge %1$s or [post something to them](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->target->getNickname(), '@' . $this->target->getNickname());
  181. }
  182. }
  183. else {
  184. // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
  185. // TRANS: This message contains a Markdown link. Keep "](" together.
  186. $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->getNickname());
  187. }
  188. $this->elementStart('div', 'guide');
  189. $this->raw(common_markup_to_html($message));
  190. $this->elementEnd('div');
  191. }
  192. function showNotices()
  193. {
  194. $pnl = new NoticeList($this->notice, $this);
  195. $cnt = $pnl->show();
  196. if (0 == $cnt) {
  197. $this->showEmptyListMessage();
  198. }
  199. $args = array('nickname' => $this->target->getNickname());
  200. if (!empty($this->tag))
  201. {
  202. $args['tag'] = $this->tag;
  203. }
  204. $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
  205. 'showstream', $args);
  206. }
  207. function showAnonymousMessage()
  208. {
  209. if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
  210. // TRANS: Announcement for anonymous users showing a timeline if site registrations are open.
  211. // TRANS: This message contains a Markdown link. Keep "](" together.
  212. $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  213. 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
  214. '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
  215. $this->target->getNickname(), $this->target->getNickname());
  216. } else {
  217. // TRANS: Announcement for anonymous users showing a timeline if site registrations are closed or invite only.
  218. // TRANS: This message contains a Markdown link. Keep "](" together.
  219. $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  220. 'based on the Free Software [StatusNet](http://status.net/) tool.'),
  221. $this->target->getNickname(), $this->target->getNickname());
  222. }
  223. $this->elementStart('div', array('id' => 'anon_notice'));
  224. $this->raw(common_markup_to_html($m));
  225. $this->elementEnd('div');
  226. }
  227. function showSections()
  228. {
  229. parent::showSections();
  230. if (!common_config('performance', 'high')) {
  231. $cloud = new PersonalTagCloudSection($this->target, $this);
  232. $cloud->show();
  233. }
  234. }
  235. function noticeFormOptions()
  236. {
  237. $options = parent::noticeFormOptions();
  238. if (!$this->scoped instanceof Profile || !$this->scoped->sameAs($this->target)) {
  239. $options['to_profile'] = $this->target;
  240. }
  241. return $options;
  242. }
  243. }