peopletag.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Lists by a user
  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. * PHP version 5
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. * @category Personal
  25. * @package StatusNet
  26. * @author Evan Prodromou <evan@status.net>
  27. * @author Zach Copley <zach@status.net>
  28. * @author Shashi Gowda <connect2shashi@gmail.com>
  29. * @copyright 2009 StatusNet, Inc.
  30. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  31. * @link http://status.net/
  32. */
  33. if (!defined('STATUSNET') && !defined('LACONICA')) {
  34. exit(1);
  35. }
  36. require_once INSTALLDIR.'/lib/peopletaglist.php';
  37. // cache 3 pages
  38. define('PEOPLETAG_CACHE_WINDOW', PEOPLETAGS_PER_PAGE*3 + 1);
  39. class PeopletagAction extends Action
  40. {
  41. var $page = null;
  42. var $tag = null;
  43. function isReadOnly($args)
  44. {
  45. return true;
  46. }
  47. function title()
  48. {
  49. if ($this->page == 1) {
  50. // TRANS: Title for list page.
  51. // TRANS: %s is a list.
  52. return sprintf(_('Public list %s'), $this->tag);
  53. } else {
  54. // TRANS: Title for list page.
  55. // TRANS: %1$s is a list, %2$d is a page number.
  56. return sprintf(_('Public list %1$s, page %2$d'), $this->tag, $this->page);
  57. }
  58. }
  59. function prepare($args)
  60. {
  61. parent::prepare($args);
  62. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  63. $tag_arg = $this->arg('tag');
  64. $tag = common_canonical_tag($tag_arg);
  65. // Permanent redirect on non-canonical nickname
  66. if ($tag_arg != $tag) {
  67. $args = array('tag' => $nickname);
  68. if ($this->page && $this->page != 1) {
  69. $args['page'] = $this->page;
  70. }
  71. common_redirect(common_local_url('peopletag', $args), 301);
  72. }
  73. $this->tag = $tag;
  74. return true;
  75. }
  76. function handle($args)
  77. {
  78. parent::handle($args);
  79. $this->showPage();
  80. }
  81. function showLocalNav()
  82. {
  83. $nav = new PublicGroupNav($this);
  84. $nav->show();
  85. }
  86. function showAnonymousMessage()
  87. {
  88. $notice =
  89. // TRANS: Message for anonymous users on list page.
  90. // TRANS: This message contains Markdown links in the form [description](link).
  91. _('Lists are how you sort similar ' .
  92. 'people on %%site.name%%, a [micro-blogging]' .
  93. '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
  94. 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
  95. 'You can then easily keep track of what they ' .
  96. 'are doing by subscribing to the list\'s timeline.' );
  97. $this->elementStart('div', array('id' => 'anon_notice'));
  98. $this->raw(common_markup_to_html($notice));
  99. $this->elementEnd('div');
  100. }
  101. function showContent()
  102. {
  103. $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
  104. $limit = PEOPLETAGS_PER_PAGE + 1;
  105. $ptags = new Profile_list();
  106. $ptags->tag = $this->tag;
  107. $user = common_current_user();
  108. if (empty($user)) {
  109. $ckey = sprintf('profile_list:tag:%s', $this->tag);
  110. $ptags->private = false;
  111. $ptags->orderBy('profile_list.modified DESC');
  112. $c = Cache::instance();
  113. if ($offset+$limit <= PEOPLETAG_CACHE_WINDOW && !empty($c)) {
  114. $cached_ptags = Profile_list::getCached($ckey, $offset, $limit);
  115. if ($cached_ptags === false) {
  116. $ptags->limit(0, PEOPLETAG_CACHE_WINDOW);
  117. $ptags->find();
  118. Profile_list::setCache($ckey, $ptags, $offset, $limit);
  119. } else {
  120. $ptags = clone($cached_ptags);
  121. }
  122. } else {
  123. $ptags->limit($offset, $limit);
  124. $ptags->find();
  125. }
  126. } else {
  127. $ptags->whereAdd('(profile_list.private = false OR (' .
  128. ' profile_list.tagger =' . $user->id .
  129. ' AND profile_list.private = true) )');
  130. $ptags->orderBy('profile_list.modified DESC');
  131. $ptags->find();
  132. }
  133. $pl = new PeopletagList($ptags, $this);
  134. $cnt = $pl->show();
  135. $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
  136. $this->page, 'peopletag', array('tag' => $this->tag));
  137. }
  138. function showSections()
  139. {
  140. }
  141. }