showstream.php 12 KB

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