groupfavorited.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 > '%s'",
  61. common_sql_date(time() - common_config('popular', 'cutoff'))
  62. );
  63. $qry = 'SELECT notice.*, ' .
  64. $weightexpr . ' as weight ' .
  65. 'FROM notice ' .
  66. "JOIN group_inbox ON notice.id = group_inbox.notice_id " .
  67. 'JOIN fave ON notice.id = fave.notice_id ' .
  68. "WHERE $cutoff AND group_id = $groupId " .
  69. 'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source,notice.conversation ' .
  70. 'ORDER BY weight DESC';
  71. $offset = ($this->page - 1) * NOTICES_PER_PAGE;
  72. $limit = NOTICES_PER_PAGE + 1;
  73. if (common_config('db', 'type') == 'pgsql') {
  74. $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
  75. } else {
  76. $qry .= ' LIMIT ' . $offset . ', ' . $limit;
  77. }
  78. $notice = Memcached_DataObject::cachedQuery(
  79. 'Notice',
  80. $qry,
  81. 600
  82. );
  83. $nl = new NoticeList($notice, $this);
  84. $cnt = $nl->show();
  85. /*if ($cnt == 0) {
  86. $this->showEmptyList();
  87. }*/
  88. $this->pagination(
  89. $this->page > 1,
  90. $cnt > NOTICES_PER_PAGE,
  91. $this->page,
  92. 'groupfavorited',
  93. array('nickname' => $this->group->nickname)
  94. );
  95. }
  96. }