groupfavorited.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * The GroupFavorited plugin adds a menu item for popular notices in groups.
  18. *
  19. * @package GroupFavoritedPlugin
  20. * @author Brion Vibber <brion@status.net>
  21. * @copyright 2010-2019 Free Software Foundation, Inc http://www.fsf.org
  22. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  23. */
  24. defined('GNUSOCIAL') || die();
  25. class GroupFavoritedAction extends ShowgroupAction
  26. {
  27. /**
  28. * Title of the page
  29. *
  30. * @return string page title, with page number
  31. * @throws Exception
  32. */
  33. public function title()
  34. {
  35. $base = $this->group->getFancyName();
  36. if ($this->page == 1) {
  37. // TRANS: %s is a group name.
  38. return sprintf(_m('Popular posts in %s group'), $base);
  39. } else {
  40. // TRANS: %1$s is a group name, %2$s is a group number.
  41. return sprintf(
  42. _m('Popular posts in %1$s group, page %2$d'),
  43. $base,
  44. $this->page
  45. );
  46. }
  47. }
  48. /**
  49. * Content area
  50. *
  51. * Shows the list of popular notices
  52. *
  53. * @return void
  54. */
  55. public function showContent()
  56. {
  57. $groupId = (int)$this->group->id;
  58. $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
  59. $cutoff = sprintf(
  60. "fave.modified > CURRENT_TIMESTAMP - INTERVAL '%d' SECOND",
  61. common_config('popular', 'cutoff')
  62. );
  63. $offset = ($this->page - 1) * NOTICES_PER_PAGE;
  64. $limit = NOTICES_PER_PAGE + 1;
  65. $qry = <<<END
  66. SELECT *
  67. FROM notice INNER JOIN (
  68. SELECT notice_id AS id, {$weightexpr} AS weight
  69. FROM fave
  70. INNER JOIN group_inbox USING (notice_id)
  71. WHERE {$cutoff} AND group_inbox.group_id = {$groupId}
  72. GROUP BY notice_id
  73. ) AS t1 USING (id)
  74. ORDER BY weight DESC
  75. LIMIT {$limit} OFFSET {$offset};
  76. END;
  77. $notice = Memcached_DataObject::cachedQuery('Notice', $qry, 600);
  78. $nl = new NoticeList($notice, $this);
  79. $cnt = $nl->show();
  80. /*if ($cnt == 0) {
  81. $this->showEmptyList();
  82. }*/
  83. $this->pagination(
  84. $this->page > 1,
  85. $cnt > NOTICES_PER_PAGE,
  86. $this->page,
  87. 'groupfavorited',
  88. array('nickname' => $this->group->nickname)
  89. );
  90. }
  91. }