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

/actions/showstream.php

https://gitlab.com/windigo-gs/windigos-gnu-social
PHP | 349 lines | 215 code | 41 blank | 93 comment | 36 complexity | f04a1112f4db43e5ab1d877073817e0a MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0
  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('STATUSNET') && !defined('LACONICA')) {
  31. exit(1);
  32. }
  33. require_once INSTALLDIR.'/lib/personalgroupnav.php';
  34. require_once INSTALLDIR.'/lib/noticelist.php';
  35. require_once INSTALLDIR.'/lib/profileminilist.php';
  36. require_once INSTALLDIR.'/lib/groupminilist.php';
  37. require_once INSTALLDIR.'/lib/feedlist.php';
  38. /**
  39. * User profile page
  40. *
  41. * When I created this page, "show stream" seemed like the best name for it.
  42. * Now, it seems like a really bad name.
  43. *
  44. * It shows a stream of the user's posts, plus lots of profile info, links
  45. * to subscriptions and stuff, etc.
  46. *
  47. * @category Personal
  48. * @package StatusNet
  49. * @author Evan Prodromou <evan@status.net>
  50. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  51. * @link http://status.net/
  52. */
  53. class ShowstreamAction extends ProfileAction
  54. {
  55. var $notice;
  56. protected function prepare(array $args=array())
  57. {
  58. parent::prepare($args);
  59. if (empty($this->tag)) {
  60. $stream = new ProfileNoticeStream($this->profile, $this->scoped);
  61. } else {
  62. $stream = new TaggedProfileNoticeStream($this->profile, $this->tag, $this->scoped);
  63. }
  64. $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
  65. return true;
  66. }
  67. function title()
  68. {
  69. $base = $this->profile->getFancyName();
  70. if (!empty($this->tag)) {
  71. if ($this->page == 1) {
  72. // TRANS: Page title showing tagged notices in one user's timeline.
  73. // TRANS: %1$s is the username, %2$s is the hash tag.
  74. return sprintf(_('Notices by %1$s tagged %2$s'), $base, $this->tag);
  75. } else {
  76. // TRANS: Page title showing tagged notices in one user's timeline.
  77. // TRANS: %1$s is the username, %2$s is the hash tag, %3$d is the page number.
  78. return sprintf(_('Notices by %1$s tagged %2$s, page %3$d'), $base, $this->tag, $this->page);
  79. }
  80. } else {
  81. if ($this->page == 1) {
  82. return $base;
  83. } else {
  84. // TRANS: Extended page title showing tagged notices in one user's timeline.
  85. // TRANS: %1$s is the username, %2$d is the page number.
  86. return sprintf(_('Notices by %1$s, page %2$d'),
  87. $base,
  88. $this->page);
  89. }
  90. }
  91. }
  92. function showContent()
  93. {
  94. $this->showNotices();
  95. }
  96. function showProfileBlock()
  97. {
  98. $block = new AccountProfileBlock($this, $this->profile);
  99. $block->show();
  100. }
  101. function showPageNoticeBlock()
  102. {
  103. return;
  104. }
  105. function getFeeds()
  106. {
  107. if (!empty($this->tag)) {
  108. return array(new Feed(Feed::RSS1,
  109. common_local_url('userrss',
  110. array('nickname' => $this->target->nickname,
  111. 'tag' => $this->tag)),
  112. // TRANS: Title for link to notice feed.
  113. // TRANS: %1$s is a user nickname, %2$s is a hashtag.
  114. sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
  115. $this->target->nickname, $this->tag)));
  116. }
  117. return array(new Feed(Feed::JSON,
  118. common_local_url('ApiTimelineUser',
  119. array(
  120. 'id' => $this->user->id,
  121. 'format' => 'as')),
  122. // TRANS: Title for link to notice feed.
  123. // TRANS: %s is a user nickname.
  124. sprintf(_('Notice feed for %s (Activity Streams JSON)'),
  125. $this->target->nickname)),
  126. new Feed(Feed::RSS1,
  127. common_local_url('userrss',
  128. array('nickname' => $this->target->nickname)),
  129. // TRANS: Title for link to notice feed.
  130. // TRANS: %s is a user nickname.
  131. sprintf(_('Notice feed for %s (RSS 1.0)'),
  132. $this->target->nickname)),
  133. new Feed(Feed::RSS2,
  134. common_local_url('ApiTimelineUser',
  135. array(
  136. 'id' => $this->user->id,
  137. 'format' => 'rss')),
  138. // TRANS: Title for link to notice feed.
  139. // TRANS: %s is a user nickname.
  140. sprintf(_('Notice feed for %s (RSS 2.0)'),
  141. $this->target->nickname)),
  142. new Feed(Feed::ATOM,
  143. common_local_url('ApiTimelineUser',
  144. array(
  145. 'id' => $this->user->id,
  146. 'format' => 'atom')),
  147. // TRANS: Title for link to notice feed.
  148. // TRANS: %s is a user nickname.
  149. sprintf(_('Notice feed for %s (Atom)'),
  150. $this->target->nickname)),
  151. new Feed(Feed::FOAF,
  152. common_local_url('foaf', array('nickname' =>
  153. $this->target->nickname)),
  154. // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
  155. // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
  156. sprintf(_('FOAF for %s'), $this->target->nickname)));
  157. }
  158. function extraHead()
  159. {
  160. if ($this->profile->bio) {
  161. $this->element('meta', array('name' => 'description',
  162. 'content' => $this->profile->bio));
  163. }
  164. if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
  165. $id = new Microid('mailto:'.$this->user->email,
  166. $this->selfUrl());
  167. $this->element('meta', array('name' => 'microid',
  168. 'content' => $id->toString()));
  169. }
  170. // See https://wiki.mozilla.org/Microsummaries
  171. $this->element('link', array('rel' => 'microsummary',
  172. 'href' => common_local_url('microsummary',
  173. array('nickname' => $this->profile->nickname))));
  174. $rsd = common_local_url('rsd',
  175. array('nickname' => $this->profile->nickname));
  176. // RSD, http://tales.phrasewise.com/rfc/rsd
  177. $this->element('link', array('rel' => 'EditURI',
  178. 'type' => 'application/rsd+xml',
  179. 'href' => $rsd));
  180. if ($this->page != 1) {
  181. $this->element('link', array('rel' => 'canonical',
  182. 'href' => $this->profile->profileurl));
  183. }
  184. }
  185. function showEmptyListMessage()
  186. {
  187. // TRANS: First sentence of empty list message for a timeline. $1%s is a user nickname.
  188. $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->target->nickname) . ' ';
  189. if (common_logged_in()) {
  190. $current_user = common_current_user();
  191. if ($this->user->id === $current_user->id) {
  192. // TRANS: Second sentence of empty list message for a stream for the user themselves.
  193. $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
  194. } else {
  195. // 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.
  196. // TRANS: This message contains a Markdown link. Keep "](" together.
  197. $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);
  198. }
  199. }
  200. else {
  201. // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
  202. // TRANS: This message contains a Markdown link. Keep "](" together.
  203. $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->nickname);
  204. }
  205. $this->elementStart('div', 'guide');
  206. $this->raw(common_markup_to_html($message));
  207. $this->elementEnd('div');
  208. }
  209. function showNotices()
  210. {
  211. $pnl = null;
  212. if (Event::handle('ShowStreamNoticeList', array($this->notice, $this, &$pnl))) {
  213. $pnl = new ProfileNoticeList($this->notice, $this);
  214. }
  215. $cnt = $pnl->show();
  216. if (0 == $cnt) {
  217. $this->showEmptyListMessage();
  218. }
  219. $args = array('nickname' => $this->target->nickname);
  220. if (!empty($this->tag))
  221. {
  222. $args['tag'] = $this->tag;
  223. }
  224. $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
  225. 'showstream', $args);
  226. }
  227. function showAnonymousMessage()
  228. {
  229. if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
  230. // TRANS: Announcement for anonymous users showing a timeline if site registrations are open.
  231. // TRANS: This message contains a Markdown link. Keep "](" together.
  232. $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  233. 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
  234. '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
  235. $this->target->nickname, $this->target->nickname);
  236. } else {
  237. // TRANS: Announcement for anonymous users showing a timeline if site registrations are closed or invite only.
  238. // TRANS: This message contains a Markdown link. Keep "](" together.
  239. $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  240. 'based on the Free Software [StatusNet](http://status.net/) tool.'),
  241. $this->target->nickname, $this->target->nickname);
  242. }
  243. $this->elementStart('div', array('id' => 'anon_notice'));
  244. $this->raw(common_markup_to_html($m));
  245. $this->elementEnd('div');
  246. }
  247. function showSections()
  248. {
  249. parent::showSections();
  250. if (!common_config('performance', 'high')) {
  251. $cloud = new PersonalTagCloudSection($this, $this->user);
  252. $cloud->show();
  253. }
  254. }
  255. function noticeFormOptions()
  256. {
  257. $options = parent::noticeFormOptions();
  258. $cur = common_current_user();
  259. if (empty($cur) || $cur->id != $this->profile->id) {
  260. $options['to_profile'] = $this->profile;
  261. }
  262. return $options;
  263. }
  264. }
  265. // We don't show the author for a profile, since we already know who it is!
  266. /**
  267. * Slightly modified from standard list; the author & avatar are hidden
  268. * in CSS. We used to remove them here too, but as it turns out that
  269. * confuses the inline reply code... and we hide them in CSS anyway
  270. * since realtime updates come through in original form.
  271. *
  272. * Remaining customization right now is for the repeat marker, where
  273. * it'll list who the original poster was instead of who did the repeat
  274. * (since the repeater is you, and the repeatee isn't shown!)
  275. * This will remain inconsistent if realtime updates come through,
  276. * since those'll get rendered as a regular NoticeListItem.
  277. */
  278. class ProfileNoticeList extends NoticeList
  279. {
  280. function newListItem($notice)
  281. {
  282. return new ProfileNoticeListItem($notice, $this->out);
  283. }
  284. }
  285. class ProfileNoticeListItem extends DoFollowListItem
  286. {
  287. /**
  288. * show a link to the author of repeat
  289. *
  290. * @return void
  291. */
  292. function showRepeat()
  293. {
  294. if (!empty($this->repeat)) {
  295. // FIXME: this code is almost identical to default; need to refactor
  296. $attrs = array('href' => $this->profile->profileurl,
  297. 'class' => 'url');
  298. if (!empty($this->profile->fullname)) {
  299. $attrs['title'] = $this->profile->getFancyName();
  300. }
  301. $this->out->elementStart('span', 'repeat');
  302. $text_link = XMLStringer::estring('a', $attrs, $this->profile->nickname);
  303. // TRANS: Link to the author of a repeated notice. %s is a linked nickname.
  304. $this->out->raw(sprintf(_('Repeat of %s'), $text_link));
  305. $this->out->elementEnd('span');
  306. }
  307. }
  308. }