featured.php 4.2 KB

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