featureduserssection.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Section for 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 Widget
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2009 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. /**
  33. * Section for featured users
  34. *
  35. * @category Widget
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. */
  41. class FeaturedUsersSection extends ProfileSection
  42. {
  43. function show()
  44. {
  45. $featured_nicks = common_config('nickname', 'featured');
  46. if (empty($featured_nicks)) {
  47. return;
  48. }
  49. parent::show();
  50. }
  51. function getProfiles()
  52. {
  53. $featured_nicks = common_config('nickname', 'featured');
  54. if (!$featured_nicks) {
  55. return null;
  56. }
  57. $quoted = array();
  58. foreach ($featured_nicks as $nick) {
  59. $quoted[] = "'$nick'";
  60. }
  61. $table = "user";
  62. if(common_config('db','quote_identifiers')) {
  63. $table = '"' . $table . '"';
  64. }
  65. $qry = 'SELECT profile.* ' .
  66. 'FROM profile JOIN '. $table .' on profile.id = '. $table .'.id ' .
  67. 'WHERE '. $table .'.nickname in (' . implode(',', $quoted) . ') ' .
  68. 'ORDER BY profile.created DESC ';
  69. $limit = PROFILES_PER_SECTION + 1;
  70. $offset = 0;
  71. if (common_config('db','type') == 'pgsql') {
  72. $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
  73. } else {
  74. $qry .= ' LIMIT ' . $offset . ', ' . $limit;
  75. }
  76. $profile = Memcached_DataObject::cachedQuery('Profile',
  77. $qry,
  78. 6 * 3600);
  79. return $profile;
  80. }
  81. function title()
  82. {
  83. // TRANS: Title for featured users section.
  84. return _('Featured users');
  85. }
  86. function divId()
  87. {
  88. return 'featured_users';
  89. }
  90. function moreUrl()
  91. {
  92. return common_local_url('featured');
  93. }
  94. }