The official, canonical postActiv repository. http://www.postactiv.com

showstream.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <?php
  2. // !TODO: I WRITE HTML, REFACTOR FOR SMARTY
  3. /* ============================================================================
  4. * Title: ShowStream
  5. * User profile page
  6. *
  7. * postActiv:
  8. * the micro-blogging software
  9. *
  10. * Copyright:
  11. * Copyright (C) 2016-2018, Maiyannah Bishop
  12. *
  13. * Derived from code copyright various sources:
  14. * o GNU Social (C) 2013-2016, Free Software Foundation, Inc
  15. * o StatusNet (C) 2008-2012, StatusNet, Inc
  16. * ----------------------------------------------------------------------------
  17. * License:
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License as published by
  20. * the Free Software Foundation, either version 3 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. *
  31. * <https://www.gnu.org/licenses/agpl.html>
  32. * ----------------------------------------------------------------------------
  33. * About:
  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. * PHP version:
  41. * Tested with PHP 7.0
  42. * ----------------------------------------------------------------------------
  43. * File Authors:
  44. * o Evan Prodromou
  45. * o Mike Cochrane <mikec@mikenz.geek.nz>
  46. * o Matthew Gregg <matthew.gregg@gmail.com>
  47. * o Sarven Capadisli
  48. * o Robin Millette <robin@millette.info>
  49. * o Zach Copley
  50. * o Adrian Lang <mail@adrianlang.de>
  51. * o Sean Murphy <sgmurphy@gmail.com>
  52. * o Meitar Moscovitz <meitarm@gmail.com>
  53. * o Ciaran Gultneiks <ciaran@ciarang.com>
  54. * o Jeffery To <jeffery.to@gmail.com>
  55. * o Christopher Vollick <psycotica0@gmail.com>
  56. * o Sashi Gowda <connect2shashi@gmail.com>
  57. * o Siebrand Mazeland <s.mazeland@xs4all.nl>
  58. * o Brion Vibber <brion@pobox.com>
  59. * o Craig Andrews <candrews@integralblue.com>
  60. * o Eric Helgeson <erichelgeson@gmail.com>
  61. * o Mikael Nordfeldth <mmn@hethane.se>
  62. * o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
  63. *
  64. * Web:
  65. * o postActiv <http://www.postactiv.com>
  66. * o GNU social <https://www.gnu.org/s/social/>
  67. * ============================================================================
  68. */
  69. // This file is formatted so that it provides useful documentation output in
  70. // NaturalDocs. Please be considerate of this before changing formatting.
  71. if (!defined('POSTACTIV')) { exit(1); }
  72. /**
  73. * User profile page
  74. */
  75. class ShowstreamAction extends NoticestreamAction
  76. {
  77. public function getStream()
  78. {
  79. if (empty($this->tag)) {
  80. $stream = new ProfileNoticeStream($this->target, $this->scoped);
  81. } else {
  82. $stream = new TaggedProfileNoticeStream($this->target, $this->tag, $this->scoped);
  83. }
  84. return $stream;
  85. }
  86. function title()
  87. {
  88. $base = $this->target->getFancyName();
  89. if (!empty($this->tag)) {
  90. if ($this->page == 1) {
  91. // TRANS: Page title showing tagged notices in one user's timeline.
  92. // TRANS: %1$s is the username, %2$s is the hash tag.
  93. return sprintf(_('Notices by %1$s tagged %2$s'), $base, $this->tag);
  94. } else {
  95. // TRANS: Page title showing tagged notices in one user's timeline.
  96. // TRANS: %1$s is the username, %2$s is the hash tag, %3$d is the page number.
  97. return sprintf(_('Notices by %1$s tagged %2$s, page %3$d'), $base, $this->tag, $this->page);
  98. }
  99. } else {
  100. if ($this->page == 1) {
  101. return sprintf(_('Notices by %s'), $base);
  102. } else {
  103. // TRANS: Extended page title showing tagged notices in one user's timeline.
  104. // TRANS: %1$s is the username, %2$d is the page number.
  105. return sprintf(_('Notices by %1$s, page %2$d'),
  106. $base,
  107. $this->page);
  108. }
  109. }
  110. }
  111. protected function showContent()
  112. {
  113. $this->showNotices();
  114. }
  115. function showProfileBlock()
  116. {
  117. $block = new AccountProfileBlock($this, $this->target);
  118. $block->show();
  119. }
  120. function showPageNoticeBlock()
  121. {
  122. return;
  123. }
  124. function getFeeds()
  125. {
  126. if (!empty($this->tag)) {
  127. return array(new Feed(Feed::RSS1,
  128. common_local_url('userrss',
  129. array('nickname' => $this->target->getNickname(),
  130. 'tag' => $this->tag)),
  131. // TRANS: Title for link to notice feed.
  132. // TRANS: %1$s is a user nickname, %2$s is a hashtag.
  133. sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
  134. $this->target->getNickname(), $this->tag)));
  135. }
  136. if (!$this->target->isLocal()) {
  137. // remote profiles at least have Atom, but we can't guarantee anything else
  138. return array(
  139. new Feed(Feed::ATOM,
  140. $this->target->getAtomFeed(),
  141. // TRANS: Title for link to notice feed.
  142. // TRANS: %s is a user nickname.
  143. sprintf(_('Notice feed for %s (Atom)'),
  144. $this->target->getNickname()))
  145. );
  146. }
  147. return array(new Feed(Feed::JSON,
  148. common_local_url('ApiTimelineUser',
  149. array(
  150. 'id' => $this->target->getID(),
  151. 'format' => 'as')),
  152. // TRANS: Title for link to notice feed.
  153. // TRANS: %s is a user nickname.
  154. sprintf(_('Notice feed for %s (Activity Streams JSON)'),
  155. $this->target->getNickname())),
  156. new Feed(Feed::RSS1,
  157. common_local_url('userrss',
  158. array('nickname' => $this->target->getNickname())),
  159. // TRANS: Title for link to notice feed.
  160. // TRANS: %s is a user nickname.
  161. sprintf(_('Notice feed for %s (RSS 1.0)'),
  162. $this->target->getNickname())),
  163. new Feed(Feed::RSS2,
  164. common_local_url('ApiTimelineUser',
  165. array(
  166. 'id' => $this->target->getID(),
  167. 'format' => 'rss')),
  168. // TRANS: Title for link to notice feed.
  169. // TRANS: %s is a user nickname.
  170. sprintf(_('Notice feed for %s (RSS 2.0)'),
  171. $this->target->getNickname())),
  172. new Feed(Feed::ATOM,
  173. $this->target->getAtomFeed(),
  174. // TRANS: Title for link to notice feed.
  175. // TRANS: %s is a user nickname.
  176. sprintf(_('Notice feed for %s (Atom)'),
  177. $this->target->getNickname())),
  178. new Feed(Feed::FOAF,
  179. common_local_url('foaf', array('nickname' =>
  180. $this->target->getNickname())),
  181. // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
  182. // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
  183. sprintf(_('FOAF for %s'), $this->target->getNickname())));
  184. }
  185. public function extraHeaders()
  186. {
  187. parent::extraHeaders();
  188. // Publish all the rel="me" in the HTTP headers on our main profile page
  189. if (get_class($this) == 'ShowstreamAction') {
  190. foreach ($this->target->getRelMes() as $relMe) {
  191. header('Link: <'.htmlspecialchars($relMe['href']).'>; rel="me"', false);
  192. }
  193. }
  194. }
  195. function extraHead()
  196. {
  197. if ($this->target->bio) {
  198. $this->element('meta', array('name' => 'description',
  199. 'content' => $this->target->getDescription()));
  200. }
  201. $rsd = common_local_url('rsd',
  202. array('nickname' => $this->target->getNickname()));
  203. // RSD, http://tales.phrasewise.com/rfc/rsd
  204. $this->element('link', array('rel' => 'EditURI',
  205. 'type' => 'application/rsd+xml',
  206. 'href' => $rsd));
  207. if ($this->page != 1) {
  208. $this->element('link', array('rel' => 'canonical',
  209. 'href' => $this->target->getUrl()));
  210. }
  211. }
  212. function showEmptyListMessage()
  213. {
  214. // TRANS: First sentence of empty list message for a timeline. $1%s is a user nickname.
  215. $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->target->getNickname()) . ' ';
  216. if ($this->scoped instanceof Profile) {
  217. if ($this->target->getID() === $this->scoped->getID()) {
  218. // TRANS: Second sentence of empty list message for a stream for the user themselves.
  219. $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
  220. } else {
  221. // 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.
  222. // TRANS: This message contains a Markdown link. Keep "](" together.
  223. $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());
  224. }
  225. }
  226. else {
  227. // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
  228. // TRANS: This message contains a Markdown link. Keep "](" together.
  229. $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->getNickname());
  230. }
  231. $this->elementStart('div', 'guide');
  232. $this->raw(common_markup_to_html($message));
  233. $this->elementEnd('div');
  234. }
  235. function showNotices()
  236. {
  237. $pnl = new PrimaryNoticeList($this->notice, $this);
  238. $cnt = $pnl->show();
  239. if (0 == $cnt) {
  240. $this->showEmptyListMessage();
  241. }
  242. $args = array('nickname' => $this->target->getNickname());
  243. if (!empty($this->tag))
  244. {
  245. $args['tag'] = $this->tag;
  246. }
  247. $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
  248. 'showstream', $args);
  249. }
  250. function showAnonymousMessage()
  251. {
  252. if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
  253. // TRANS: Announcement for anonymous users showing a timeline if site registrations are open.
  254. // TRANS: This message contains a Markdown link. Keep "](" together.
  255. $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  256. 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
  257. '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
  258. $this->target->getNickname(), $this->target->getNickname());
  259. } else {
  260. // TRANS: Announcement for anonymous users showing a timeline if site registrations are closed or invite only.
  261. // TRANS: This message contains a Markdown link. Keep "](" together.
  262. $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  263. 'based on the Free Software [StatusNet](http://status.net/) tool.'),
  264. $this->target->getNickname(), $this->target->getNickname());
  265. }
  266. $this->elementStart('div', array('id' => 'anon_notice'));
  267. $this->raw(common_markup_to_html($m));
  268. $this->elementEnd('div');
  269. }
  270. function noticeFormOptions()
  271. {
  272. $options = parent::noticeFormOptions();
  273. if (!$this->scoped instanceof Profile || !$this->scoped->sameAs($this->target)) {
  274. $options['to_profile'] = $this->target;
  275. }
  276. return $options;
  277. }
  278. }
  279. // END OF FILE
  280. // ============================================================================
  281. ?>