showstream.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. if (!$this->target->isLocal()) {
  108. // remote profiles at least have Atom, but we can't guarantee anything else
  109. return array(
  110. new Feed(Feed::ATOM,
  111. $this->target->getAtomFeed(),
  112. // TRANS: Title for link to notice feed.
  113. // TRANS: %s is a user nickname.
  114. sprintf(_('Notice feed for %s (Atom)'),
  115. $this->target->getNickname()))
  116. );
  117. }
  118. return array(new Feed(Feed::JSON,
  119. common_local_url('ApiTimelineUser',
  120. array(
  121. 'id' => $this->target->getID(),
  122. 'format' => 'as')),
  123. // TRANS: Title for link to notice feed.
  124. // TRANS: %s is a user nickname.
  125. sprintf(_('Notice feed for %s (Activity Streams JSON)'),
  126. $this->target->getNickname())),
  127. new Feed(Feed::RSS1,
  128. common_local_url('userrss',
  129. array('nickname' => $this->target->getNickname())),
  130. // TRANS: Title for link to notice feed.
  131. // TRANS: %s is a user nickname.
  132. sprintf(_('Notice feed for %s (RSS 1.0)'),
  133. $this->target->getNickname())),
  134. new Feed(Feed::RSS2,
  135. common_local_url('ApiTimelineUser',
  136. array(
  137. 'id' => $this->target->getID(),
  138. 'format' => 'rss')),
  139. // TRANS: Title for link to notice feed.
  140. // TRANS: %s is a user nickname.
  141. sprintf(_('Notice feed for %s (RSS 2.0)'),
  142. $this->target->getNickname())),
  143. new Feed(Feed::ATOM,
  144. $this->target->getAtomFeed(),
  145. // TRANS: Title for link to notice feed.
  146. // TRANS: %s is a user nickname.
  147. sprintf(_('Notice feed for %s (Atom)'),
  148. $this->target->getNickname())),
  149. new Feed(Feed::FOAF,
  150. common_local_url('foaf', array('nickname' =>
  151. $this->target->getNickname())),
  152. // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
  153. // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
  154. sprintf(_('FOAF for %s'), $this->target->getNickname())));
  155. }
  156. public function extraHeaders()
  157. {
  158. parent::extraHeaders();
  159. // Publish all the rel="me" in the HTTP headers on our main profile page
  160. if (get_class($this) == 'ShowstreamAction') {
  161. foreach ($this->target->getRelMes() as $relMe) {
  162. header('Link: <'.htmlspecialchars($relMe['href']).'>; rel="me"', false);
  163. }
  164. }
  165. }
  166. function extraHead()
  167. {
  168. if ($this->target->bio) {
  169. $this->element('meta', array('name' => 'description',
  170. 'content' => $this->target->getDescription()));
  171. }
  172. $rsd = common_local_url('rsd',
  173. array('nickname' => $this->target->getNickname()));
  174. // RSD, http://tales.phrasewise.com/rfc/rsd
  175. $this->element('link', array('rel' => 'EditURI',
  176. 'type' => 'application/rsd+xml',
  177. 'href' => $rsd));
  178. if ($this->page != 1) {
  179. $this->element('link', array('rel' => 'canonical',
  180. 'href' => $this->target->getUrl()));
  181. }
  182. }
  183. function showEmptyListMessage()
  184. {
  185. // TRANS: First sentence of empty list message for a timeline. $1%s is a user nickname.
  186. $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->target->getNickname()) . ' ';
  187. if ($this->scoped instanceof Profile) {
  188. if ($this->target->getID() === $this->scoped->getID()) {
  189. // TRANS: Second sentence of empty list message for a stream for the user themselves.
  190. $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
  191. } else {
  192. // 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.
  193. // TRANS: This message contains a Markdown link. Keep "](" together.
  194. $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());
  195. }
  196. }
  197. else {
  198. // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
  199. // TRANS: This message contains a Markdown link. Keep "](" together.
  200. $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->getNickname());
  201. }
  202. $this->elementStart('div', 'guide');
  203. $this->raw(common_markup_to_html($message));
  204. $this->elementEnd('div');
  205. }
  206. function showNotices()
  207. {
  208. $pnl = new PrimaryNoticeList($this->notice, $this);
  209. $cnt = $pnl->show();
  210. if (0 == $cnt) {
  211. $this->showEmptyListMessage();
  212. }
  213. // either nickname or id will be used, depending on which action (showstream, userbyid...)
  214. $args = array('nickname' => $this->target->getNickname(), 'id' => $this->target->getID());
  215. if (!empty($this->tag))
  216. {
  217. $args['tag'] = $this->tag;
  218. }
  219. $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
  220. $this->getActionName(), $args);
  221. }
  222. function showAnonymousMessage()
  223. {
  224. if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
  225. // TRANS: Announcement for anonymous users showing a timeline if site registrations are open.
  226. // TRANS: This message contains a Markdown link. Keep "](" together.
  227. $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  228. 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
  229. '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
  230. $this->target->getNickname(), $this->target->getNickname());
  231. } else {
  232. // TRANS: Announcement for anonymous users showing a timeline if site registrations are closed or invite only.
  233. // TRANS: This message contains a Markdown link. Keep "](" together.
  234. $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  235. 'based on the Free Software [StatusNet](http://status.net/) tool.'),
  236. $this->target->getNickname(), $this->target->getNickname());
  237. }
  238. $this->elementStart('div', array('id' => 'anon_notice'));
  239. $this->raw(common_markup_to_html($m));
  240. $this->elementEnd('div');
  241. }
  242. function noticeFormOptions()
  243. {
  244. $options = parent::noticeFormOptions();
  245. if (!$this->scoped instanceof Profile || !$this->scoped->sameAs($this->target)) {
  246. $options['to_profile'] = $this->target;
  247. }
  248. return $options;
  249. }
  250. }