groupfavorited.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List of popular notices
  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. class GroupFavoritedAction extends ShowgroupAction
  34. {
  35. /**
  36. * Title of the page
  37. *
  38. * @return string page title, with page number
  39. */
  40. function title()
  41. {
  42. $base = $this->group->getFancyName();
  43. if ($this->page == 1) {
  44. // TRANS: %s is a group name.
  45. return sprintf(_m('Popular posts in %s group'), $base);
  46. } else {
  47. // TRANS: %1$s is a group name, %2$s is a group number.
  48. return sprintf(_m('Popular posts in %1$s group, page %2$d'),
  49. $base,
  50. $this->page);
  51. }
  52. }
  53. /**
  54. * Content area
  55. *
  56. * Shows the list of popular notices
  57. *
  58. * @return void
  59. */
  60. function showContent()
  61. {
  62. $groupId = intval($this->group->id);
  63. $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
  64. $cutoff = sprintf("fave.modified > '%s'",
  65. common_sql_date(time() - common_config('popular', 'cutoff')));
  66. $qry = 'SELECT notice.*, '.
  67. $weightexpr . ' as weight ' .
  68. 'FROM notice ' .
  69. "JOIN group_inbox ON notice.id = group_inbox.notice_id " .
  70. 'JOIN fave ON notice.id = fave.notice_id ' .
  71. "WHERE $cutoff AND group_id = $groupId " .
  72. 'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source,notice.conversation ' .
  73. 'ORDER BY weight DESC';
  74. $offset = ($this->page - 1) * NOTICES_PER_PAGE;
  75. $limit = NOTICES_PER_PAGE + 1;
  76. if (common_config('db', 'type') == 'pgsql') {
  77. $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
  78. } else {
  79. $qry .= ' LIMIT ' . $offset . ', ' . $limit;
  80. }
  81. $notice = Memcached_DataObject::cachedQuery('Notice',
  82. $qry,
  83. 600);
  84. $nl = new NoticeList($notice, $this);
  85. $cnt = $nl->show();
  86. if ($cnt == 0) {
  87. //$this->showEmptyList();
  88. }
  89. $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
  90. $this->page, 'groupfavorited',
  91. array('nickname' => $this->group->nickname));
  92. }
  93. }