showstream.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 ProfileAction
  47. {
  48. var $notice;
  49. protected function profileActionPreparation()
  50. {
  51. if (empty($this->tag)) {
  52. $stream = new ProfileNoticeStream($this->target, $this->scoped);
  53. } else {
  54. $stream = new TaggedProfileNoticeStream($this->target, $this->tag, $this->scoped);
  55. }
  56. $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
  57. return true;
  58. }
  59. function title()
  60. {
  61. $base = $this->target->getFancyName();
  62. if (!empty($this->tag)) {
  63. if ($this->page == 1) {
  64. // TRANS: Page title showing tagged notices in one user's timeline.
  65. // TRANS: %1$s is the username, %2$s is the hash tag.
  66. return sprintf(_('Notices by %1$s tagged %2$s'), $base, $this->tag);
  67. } else {
  68. // TRANS: Page title showing tagged notices in one user's timeline.
  69. // TRANS: %1$s is the username, %2$s is the hash tag, %3$d is the page number.
  70. return sprintf(_('Notices by %1$s tagged %2$s, page %3$d'), $base, $this->tag, $this->page);
  71. }
  72. } else {
  73. if ($this->page == 1) {
  74. return $base;
  75. } else {
  76. // TRANS: Extended page title showing tagged notices in one user's timeline.
  77. // TRANS: %1$s is the username, %2$d is the page number.
  78. return sprintf(_('Notices by %1$s, page %2$d'),
  79. $base,
  80. $this->page);
  81. }
  82. }
  83. }
  84. function showContent()
  85. {
  86. $this->showNotices();
  87. }
  88. function showProfileBlock()
  89. {
  90. $block = new AccountProfileBlock($this, $this->target);
  91. $block->show();
  92. }
  93. function showPageNoticeBlock()
  94. {
  95. return;
  96. }
  97. function getFeeds()
  98. {
  99. if (!empty($this->tag)) {
  100. return array(new Feed(Feed::RSS1,
  101. common_local_url('userrss',
  102. array('nickname' => $this->target->getNickname(),
  103. 'tag' => $this->tag)),
  104. // TRANS: Title for link to notice feed.
  105. // TRANS: %1$s is a user nickname, %2$s is a hashtag.
  106. sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
  107. $this->target->getNickname(), $this->tag)));
  108. }
  109. return array(new Feed(Feed::JSON,
  110. common_local_url('ApiTimelineUser',
  111. array(
  112. 'id' => $this->user->id,
  113. 'format' => 'as')),
  114. // TRANS: Title for link to notice feed.
  115. // TRANS: %s is a user nickname.
  116. sprintf(_('Notice feed for %s (Activity Streams JSON)'),
  117. $this->target->getNickname())),
  118. new Feed(Feed::RSS1,
  119. common_local_url('userrss',
  120. array('nickname' => $this->target->getNickname())),
  121. // TRANS: Title for link to notice feed.
  122. // TRANS: %s is a user nickname.
  123. sprintf(_('Notice feed for %s (RSS 1.0)'),
  124. $this->target->getNickname())),
  125. new Feed(Feed::RSS2,
  126. common_local_url('ApiTimelineUser',
  127. array(
  128. 'id' => $this->user->id,
  129. 'format' => 'rss')),
  130. // TRANS: Title for link to notice feed.
  131. // TRANS: %s is a user nickname.
  132. sprintf(_('Notice feed for %s (RSS 2.0)'),
  133. $this->target->getNickname())),
  134. new Feed(Feed::ATOM,
  135. common_local_url('ApiTimelineUser',
  136. array(
  137. 'id' => $this->user->id,
  138. 'format' => 'atom')),
  139. // TRANS: Title for link to notice feed.
  140. // TRANS: %s is a user nickname.
  141. sprintf(_('Notice feed for %s (Atom)'),
  142. $this->target->getNickname())),
  143. new Feed(Feed::FOAF,
  144. common_local_url('foaf', array('nickname' =>
  145. $this->target->getNickname())),
  146. // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
  147. // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
  148. sprintf(_('FOAF for %s'), $this->target->getNickname())));
  149. }
  150. function extraHead()
  151. {
  152. if ($this->target->bio) {
  153. $this->element('meta', array('name' => 'description',
  154. 'content' => $this->target->getDescription()));
  155. }
  156. if ($this->target->isLocal() && $this->target->getUser()->emailmicroid && $this->target->getUser()->email && $this->target->getUrl()) {
  157. $id = new Microid('mailto:'.$this->target->getUser()->email,
  158. $this->selfUrl());
  159. $this->element('meta', array('name' => 'microid',
  160. 'content' => $id->toString()));
  161. }
  162. // See https://wiki.mozilla.org/Microsummaries
  163. $this->element('link', array('rel' => 'microsummary',
  164. 'href' => common_local_url('microsummary',
  165. array('nickname' => $this->target->getNickname()))));
  166. $rsd = common_local_url('rsd',
  167. array('nickname' => $this->target->getNickname()));
  168. // RSD, http://tales.phrasewise.com/rfc/rsd
  169. $this->element('link', array('rel' => 'EditURI',
  170. 'type' => 'application/rsd+xml',
  171. 'href' => $rsd));
  172. if ($this->page != 1) {
  173. $this->element('link', array('rel' => 'canonical',
  174. 'href' => $this->target->getUrl()));
  175. }
  176. }
  177. function showEmptyListMessage()
  178. {
  179. // TRANS: First sentence of empty list message for a timeline. $1%s is a user nickname.
  180. $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->target->nickname) . ' ';
  181. if (common_logged_in()) {
  182. $current_user = common_current_user();
  183. if ($this->user->id === $current_user->id) {
  184. // TRANS: Second sentence of empty list message for a stream for the user themselves.
  185. $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
  186. } else {
  187. // 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.
  188. // TRANS: This message contains a Markdown link. Keep "](" together.
  189. $message .= sprintf(_('You can try to nudge %1$s or [post something to them](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->target->nickname, '@' . $this->target->nickname);
  190. }
  191. }
  192. else {
  193. // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
  194. // TRANS: This message contains a Markdown link. Keep "](" together.
  195. $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->nickname);
  196. }
  197. $this->elementStart('div', 'guide');
  198. $this->raw(common_markup_to_html($message));
  199. $this->elementEnd('div');
  200. }
  201. function showNotices()
  202. {
  203. $pnl = new NoticeList($this->notice, $this);
  204. $cnt = $pnl->show();
  205. if (0 == $cnt) {
  206. $this->showEmptyListMessage();
  207. }
  208. $args = array('nickname' => $this->target->nickname);
  209. if (!empty($this->tag))
  210. {
  211. $args['tag'] = $this->tag;
  212. }
  213. $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
  214. 'showstream', $args);
  215. }
  216. function showAnonymousMessage()
  217. {
  218. if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
  219. // TRANS: Announcement for anonymous users showing a timeline if site registrations are open.
  220. // TRANS: This message contains a Markdown link. Keep "](" together.
  221. $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  222. 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
  223. '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
  224. $this->target->nickname, $this->target->nickname);
  225. } else {
  226. // TRANS: Announcement for anonymous users showing a timeline if site registrations are closed or invite only.
  227. // TRANS: This message contains a Markdown link. Keep "](" together.
  228. $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  229. 'based on the Free Software [StatusNet](http://status.net/) tool.'),
  230. $this->target->nickname, $this->target->nickname);
  231. }
  232. $this->elementStart('div', array('id' => 'anon_notice'));
  233. $this->raw(common_markup_to_html($m));
  234. $this->elementEnd('div');
  235. }
  236. function showSections()
  237. {
  238. parent::showSections();
  239. if (!common_config('performance', 'high')) {
  240. $cloud = new PersonalTagCloudSection($this, $this->user);
  241. $cloud->show();
  242. }
  243. }
  244. function noticeFormOptions()
  245. {
  246. $options = parent::noticeFormOptions();
  247. if (!$this->scoped instanceof Profile || $this->scoped->id != $this->target->id) {
  248. $options['to_profile'] = $this->target;
  249. }
  250. return $options;
  251. }
  252. }