peopletag.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Lists by a user
  18. *
  19. * @category Personal
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @author Zach Copley <zach@status.net>
  23. * @author Shashi Gowda <connect2shashi@gmail.com>
  24. * @copyright 2009 StatusNet, Inc.
  25. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  26. */
  27. defined('GNUSOCIAL') || die();
  28. require_once INSTALLDIR . '/lib/profile/peopletaglist.php';
  29. // cache 3 pages
  30. define('PEOPLETAG_CACHE_WINDOW', PEOPLETAGS_PER_PAGE*3 + 1);
  31. class PeopletagAction extends Action
  32. {
  33. public $page = null;
  34. public $tag = null;
  35. public function isReadOnly($args)
  36. {
  37. return true;
  38. }
  39. public function title()
  40. {
  41. if ($this->page == 1) {
  42. // TRANS: Title for list page.
  43. // TRANS: %s is a list.
  44. return sprintf(_('Public list %s'), $this->tag);
  45. } else {
  46. // TRANS: Title for list page.
  47. // TRANS: %1$s is a list, %2$d is a page number.
  48. return sprintf(_('Public list %1$s, page %2$d'), $this->tag, $this->page);
  49. }
  50. }
  51. public function prepare(array $args = [])
  52. {
  53. parent::prepare($args);
  54. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  55. $tag_arg = $this->arg('tag');
  56. $tag = common_canonical_tag($tag_arg);
  57. // Permanent redirect on non-canonical nickname
  58. if ($tag_arg != $tag) {
  59. $args = array('tag' => $nickname);
  60. if ($this->page && $this->page != 1) {
  61. $args['page'] = $this->page;
  62. }
  63. common_redirect(common_local_url('peopletag', $args), 301);
  64. }
  65. $this->tag = $tag;
  66. return true;
  67. }
  68. public function handle()
  69. {
  70. parent::handle();
  71. $this->showPage();
  72. }
  73. public function showLocalNav()
  74. {
  75. $nav = new PublicGroupNav($this);
  76. $nav->show();
  77. }
  78. public function showAnonymousMessage()
  79. {
  80. $notice =
  81. // TRANS: Message for anonymous users on list page.
  82. // TRANS: This message contains Markdown links in the form [description](link).
  83. _('Lists are how you sort similar ' .
  84. 'people on %%site.name%%, a [micro-blogging]' .
  85. '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  86. 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
  87. 'You can then easily keep track of what they ' .
  88. "are doing by subscribing to the list's timeline.");
  89. $this->elementStart('div', array('id' => 'anon_notice'));
  90. $this->raw(common_markup_to_html($notice));
  91. $this->elementEnd('div');
  92. }
  93. public function showContent()
  94. {
  95. $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
  96. $limit = PEOPLETAGS_PER_PAGE + 1;
  97. $ptags = new Profile_list();
  98. $ptags->tag = $this->tag;
  99. $user = common_current_user();
  100. if (empty($user)) {
  101. $ckey = sprintf('profile_list:tag:%s', $this->tag);
  102. $ptags->private = false;
  103. $ptags->orderBy('profile_list.modified DESC');
  104. $c = Cache::instance();
  105. if ($offset+$limit <= PEOPLETAG_CACHE_WINDOW && !empty($c)) {
  106. $cached_ptags = Profile_list::getCached($ckey, $offset, $limit);
  107. if ($cached_ptags === false) {
  108. $ptags->limit(0, PEOPLETAG_CACHE_WINDOW);
  109. $ptags->find();
  110. Profile_list::setCache($ckey, $ptags, $offset, $limit);
  111. } else {
  112. $ptags = clone($cached_ptags);
  113. }
  114. } else {
  115. $ptags->limit($offset, $limit);
  116. $ptags->find();
  117. }
  118. } else {
  119. $ptags->whereAdd(sprintf(
  120. <<<'END'
  121. (
  122. (profile_list.tagger = %d AND profile_list.private IS TRUE)
  123. OR profile_list.private IS NOT TRUE
  124. )
  125. END,
  126. $user->getID()
  127. ));
  128. $ptags->orderBy('profile_list.modified DESC');
  129. $ptags->find();
  130. }
  131. $pl = new PeopletagList($ptags, $this);
  132. $cnt = $pl->show();
  133. $this->pagination(
  134. ($this->page > 1),
  135. ($cnt > PEOPLETAGS_PER_PAGE),
  136. $this->page,
  137. 'peopletag',
  138. ['tag' => $this->tag]
  139. );
  140. }
  141. public function showSections()
  142. {
  143. }
  144. }