featured.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. * List of featured users
  18. *
  19. * @category Public
  20. * @package GNUsocial
  21. * @author Zach Copley <zach@status.net>
  22. * @author Evan Prodromou <evan@status.net>
  23. * @copyright 2008-2009 StatusNet, Inc.
  24. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  25. */
  26. defined('GNUSOCIAL') || die();
  27. require_once INSTALLDIR . '/lib/profile/profilelist.php';
  28. require_once INSTALLDIR . '/lib/groups/publicgroupnav.php';
  29. /**
  30. * List of featured users
  31. *
  32. * @copyright 2008-2009 StatusNet, Inc.
  33. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  34. */
  35. class FeaturedAction extends Action
  36. {
  37. public $page = null;
  38. public function isReadOnly($args)
  39. {
  40. return true;
  41. }
  42. public function prepare(array $args = [])
  43. {
  44. parent::prepare($args);
  45. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  46. return true;
  47. }
  48. public function title()
  49. {
  50. if ($this->page == 1) {
  51. // TRANS: Page title for first page of featured users.
  52. return _('Featured users');
  53. } else {
  54. // TRANS: Page title for all but first page of featured users.
  55. // TRANS: %d is the page number being displayed.
  56. return sprintf(_('Featured users, page %d'), $this->page);
  57. }
  58. }
  59. public function handle()
  60. {
  61. parent::handle();
  62. $this->showPage();
  63. }
  64. public function showPageNotice()
  65. {
  66. $instr = $this->getInstructions();
  67. $output = common_markup_to_html($instr);
  68. $this->elementStart('div', 'instructions');
  69. $this->raw($output);
  70. $this->elementEnd('div');
  71. }
  72. public function getInstructions()
  73. {
  74. // TRANS: Description on page displaying featured users.
  75. return sprintf(
  76. _('A selection of some great users on %s.'),
  77. common_config('site', 'name')
  78. );
  79. }
  80. public function showContent()
  81. {
  82. // XXX: Note I'm doing it this two-stage way because a raw query
  83. // with a JOIN was *not* working. --Zach
  84. $featured_nicks = common_config('nickname', 'featured');
  85. if (count($featured_nicks) > 0) {
  86. $quoted = array();
  87. foreach ($featured_nicks as $nick) {
  88. $quoted[] = "'$nick'";
  89. }
  90. $user = new User;
  91. $user->whereAdd(sprintf('nickname IN (%s)', implode(',', $quoted)));
  92. $user->limit(($this->page - 1) * PROFILES_PER_PAGE, PROFILES_PER_PAGE + 1);
  93. $user->orderBy($user->escapedTableName() . '.nickname ASC');
  94. $user->find();
  95. $profile_ids = array();
  96. while ($user->fetch()) {
  97. $profile_ids[] = $user->id;
  98. }
  99. $profile = new Profile;
  100. $profile->whereAdd(sprintf('profile.id IN (%s)', implode(',', $profile_ids)));
  101. $profile->orderBy('nickname ASC');
  102. $cnt = $profile->find();
  103. if ($cnt > 0) {
  104. $featured = new ProfileList($profile, $this);
  105. $featured->show();
  106. }
  107. $profile->free();
  108. $this->pagination(
  109. $this->page > 1,
  110. $cnt > PROFILES_PER_PAGE,
  111. $this->page,
  112. 'featured'
  113. );
  114. }
  115. }
  116. }