groupfavorited.php 3.2 KB

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