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

showprofiletag.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. // !TODO: I WRITE HTML, REFACTOR FOR SMARTY
  3. /* ============================================================================
  4. * Title: ShowProfileTag
  5. * Show a given peopletag on a profile
  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. * Show a given peopletag on a profile
  35. *
  36. * PHP version:
  37. * Tested with PHP 7.0
  38. * ----------------------------------------------------------------------------
  39. * File Authors:
  40. * o Sashi Gowda <connect2shashi@gmail.com>
  41. * o Siebrand Mazeland <s.mazeland@xs4all.nl>
  42. * o Evan Prodromou
  43. * o Mikael Nordfeldth <mmn@hethane.se>
  44. * o Maiyannah Bishop <maiyannah.bishop@postactiv.com>
  45. *
  46. * Web:
  47. * o postActiv <http://www.postactiv.com>
  48. * o GNU social <https://www.gnu.org/s/social/>
  49. * ============================================================================
  50. */
  51. // This file is formatted so that it provides useful documentation output in
  52. // NaturalDocs. Please be considerate of this before changing formatting.
  53. if (!defined('POSTACTIV')) { exit(1); }
  54. class ShowprofiletagAction extends ShowstreamAction
  55. {
  56. var $notice, $peopletag;
  57. protected function doStreamPreparation()
  58. {
  59. $tag = common_canonical_tag($this->arg('tag'));
  60. try {
  61. $this->peopletag = Profile_list::getByPK(array('tagger' => $this->target->getID(), 'tag' => $tag));
  62. } catch (NoResultException $e) {
  63. // TRANS: Client error displayed trying to reference a non-existing list.
  64. throw new ClientException('No such list.');
  65. }
  66. if ($this->peopletag->private && !$this->peopletag->getTagger()->sameAs($this->scoped)) {
  67. // TRANS: Client error displayed trying to reference a non-existing list.
  68. throw new AuthorizationException('You do not have permission to see this list.');
  69. }
  70. }
  71. public function getStream()
  72. {
  73. return new PeopletagNoticeStream($this->peopletag, $this->scoped);
  74. }
  75. function title()
  76. {
  77. if ($this->page > 1) {
  78. if($this->peopletag->private) {
  79. // TRANS: Title for private list timeline.
  80. // TRANS: %1$s is a list, %2$s is a page number.
  81. return sprintf(_('Private timeline for %1$s list by you, page %2$d'),
  82. $this->peopletag->tag, $this->page);
  83. }
  84. $current = common_current_user();
  85. if (!empty($current) && $current->id == $this->peopletag->tagger) {
  86. // TRANS: Title for public list timeline where the viewer is the tagger.
  87. // TRANS: %1$s is a list, %2$s is a page number.
  88. return sprintf(_('Timeline for %1$s list by you, page %2$d'),
  89. $this->peopletag->tag, $this->page);
  90. }
  91. // TRANS: Title for private list timeline.
  92. // TRANS: %1$s is a list, %2$s is the tagger's nickname, %3$d is a page number.
  93. return sprintf(_('Timeline for %1$s list by %2$s, page %3$d'),
  94. $this->peopletag->tag,
  95. $this->target->getNickname(),
  96. $this->page
  97. );
  98. } else {
  99. if($this->peopletag->private) {
  100. // TRANS: Title for private list timeline.
  101. // TRANS: %s is a list.
  102. return sprintf(_('Private timeline of %s list by you'),
  103. $this->peopletag->tag);
  104. }
  105. $current = common_current_user();
  106. if (!empty($current) && $current->id == $this->peopletag->tagger) {
  107. // TRANS: Title for public list timeline where the viewer is the tagger.
  108. // TRANS: %s is a list.
  109. return sprintf(_('Timeline for %s list by you'),
  110. $this->peopletag->tag);
  111. }
  112. // TRANS: Title for private list timeline.
  113. // TRANS: %1$s is a list, %2$s is the tagger's nickname.
  114. return sprintf(_('Timeline for %1$s list by %2$s'),
  115. $this->peopletag->tag,
  116. $this->target->getNickname()
  117. );
  118. }
  119. }
  120. function getFeeds()
  121. {
  122. #XXX: make these actually work
  123. return array(new Feed(Feed::JSON,
  124. common_local_url(
  125. 'ApiTimelineList', array(
  126. 'user' => $this->target->id,
  127. 'id' => $this->peopletag->id,
  128. 'format' => 'as'
  129. )
  130. ),
  131. // TRANS: Feed title.
  132. // TRANS: %s is tagger's nickname.
  133. sprintf(_('Feed for friends of %s (Activity Streams JSON)'), $this->target->getNickname())),
  134. new Feed(Feed::RSS2,
  135. common_local_url(
  136. 'ApiTimelineList', array(
  137. 'user' => $this->target->id,
  138. 'id' => $this->peopletag->id,
  139. 'format' => 'rss'
  140. )
  141. ),
  142. // TRANS: Feed title.
  143. // TRANS: %s is tagger's nickname.
  144. sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->target->getNickname())),
  145. new Feed(Feed::ATOM,
  146. common_local_url(
  147. 'ApiTimelineList', array(
  148. 'user' => $this->target->id,
  149. 'id' => $this->peopletag->id,
  150. 'format' => 'atom'
  151. )
  152. ),
  153. // TRANS: Feed title.
  154. // TRANS: %1$s is a list, %2$s is tagger's nickname.
  155. sprintf(_('Feed for %1$s list by %2$s (Atom)'),
  156. $this->peopletag->tag, $this->target->getNickname()
  157. )
  158. )
  159. );
  160. }
  161. function showObjectNav()
  162. {
  163. $nav = new PeopletagGroupNav($this);
  164. $nav->show();
  165. }
  166. function showEmptyListMessage()
  167. {
  168. // TRANS: Empty list message for list timeline.
  169. // TRANS: %1$s is a list, %2$s is a tagger's nickname.
  170. $message = sprintf(_('This is the timeline for %1$s list by %2$s but no one has posted anything yet.'),
  171. $this->peopletag->tag,
  172. $this->target->getNickname()) . ' ';
  173. if (common_logged_in()) {
  174. if ($this->target->sameAs($this->scoped)) {
  175. // TRANS: Additional empty list message for list timeline for currently logged in user tagged tags.
  176. $message .= _('Try tagging more people.');
  177. }
  178. } else {
  179. // TRANS: Additional empty list message for list timeline.
  180. // TRANS: This message contains Markdown links in the form [description](link).
  181. $message .= _('Why not [register an account](%%%%action.register%%%%) and start following this timeline!');
  182. }
  183. $this->elementStart('div', 'guide');
  184. $this->raw(common_markup_to_html($message));
  185. $this->elementEnd('div');
  186. }
  187. protected function showContent()
  188. {
  189. $this->showPeopletag();
  190. parent::showContent();
  191. }
  192. function showPeopletag()
  193. {
  194. $tag = new Peopletag($this->peopletag, $this->scoped, $this);
  195. $tag->show();
  196. }
  197. function showNotices()
  198. {
  199. if (Event::handle('StartShowProfileTagContent', array($this))) {
  200. $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
  201. $cnt = $nl->show();
  202. if (0 == $cnt) {
  203. $this->showEmptyListMessage();
  204. }
  205. $this->pagination($this->page > 1,
  206. $cnt > NOTICES_PER_PAGE,
  207. $this->page,
  208. 'showprofiletag',
  209. array('tag' => $this->peopletag->tag,
  210. 'nickname' => $this->target->getNickname())
  211. );
  212. Event::handle('EndShowProfileTagContent', array($this));
  213. }
  214. }
  215. function showSections()
  216. {
  217. $this->showTagged();
  218. if (!$this->peopletag->private) {
  219. $this->showSubscribers();
  220. }
  221. # $this->showStatistics();
  222. }
  223. function showTagged()
  224. {
  225. $profile = $this->peopletag->getTagged(0, PROFILES_PER_MINILIST + 1);
  226. $this->elementStart('div', array('id' => 'entity_tagged',
  227. 'class' => 'section'));
  228. if (Event::handle('StartShowTaggedProfilesMiniList', array($this))) {
  229. $title = '';
  230. // TRANS: Header on show list page.
  231. $this->element('h2', null, _('Listed'));
  232. $cnt = 0;
  233. if (!empty($profile)) {
  234. $pml = new ProfileMiniList($profile, $this);
  235. $cnt = $pml->show();
  236. if ($cnt == 0) {
  237. // TRANS: Content of "Listed" page if there are no listed users.
  238. $this->element('p', null, _('(None)'));
  239. }
  240. }
  241. if ($cnt > PROFILES_PER_MINILIST) {
  242. $this->elementStart('p');
  243. $this->element('a', array('href' => common_local_url('taggedprofiles',
  244. array('nickname' => $this->target->getNickname(),
  245. 'profiletag' => $this->peopletag->tag)),
  246. 'class' => 'more'),
  247. // TRANS: Link for more "People in list x by a user"
  248. // TRANS: if there are more than the mini list's maximum.
  249. _('Show all'));
  250. $this->elementEnd('p');
  251. }
  252. Event::handle('EndShowTaggedProfilesMiniList', array($this));
  253. }
  254. $this->elementEnd('div');
  255. }
  256. function showSubscribers()
  257. {
  258. $profile = $this->peopletag->getSubscribers(0, PROFILES_PER_MINILIST + 1);
  259. $this->elementStart('div', array('id' => 'entity_subscribers',
  260. 'class' => 'section'));
  261. if (Event::handle('StartShowProfileTagSubscribersMiniList', array($this))) {
  262. // TRANS: Header for tag subscribers.
  263. $this->element('h2', null, _('Subscribers'));
  264. $cnt = 0;
  265. if (!empty($profile)) {
  266. $pml = new ProfileMiniList($profile, $this);
  267. $cnt = $pml->show();
  268. if ($cnt == 0) {
  269. // TRANS: Content of "People following tag x" if there are no subscribed users.
  270. $this->element('p', null, _('(None)'));
  271. }
  272. }
  273. // FIXME: link to full list
  274. Event::handle('EndShowProfileTagSubscribersMiniList', array($this));
  275. }
  276. $this->elementEnd('div');
  277. }
  278. }
  279. // END OF FILE
  280. // ============================================================================
  281. ?>