inboxtagcloudsection.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. * Personal tag cloud section
  18. *
  19. * @category Widget
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @copyright 2009 StatusNet, Inc.
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * Personal tag cloud section
  28. *
  29. * @copyright 2009 StatusNet, Inc.
  30. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  31. */
  32. class InboxTagCloudSection extends TagCloudSection
  33. {
  34. const MAX_NOTICES = 1024; // legacy value for "Inbox" table size when that existed
  35. protected $target = null;
  36. public function __construct($out = null, Profile $target)
  37. {
  38. parent::__construct($out);
  39. $this->target = $target;
  40. }
  41. public function title()
  42. {
  43. // TRANS: Title for inbox tag cloud section.
  44. return _m('TITLE', 'Trends');
  45. }
  46. public function getTags()
  47. {
  48. // FIXME: Get the Profile::current() value some other way
  49. // to avoid confusion between background stuff and session.
  50. $stream = new InboxNoticeStream($this->target, Profile::current());
  51. $ids = $stream->getNoticeIds(0, self::MAX_NOTICES, null, null);
  52. if (empty($ids)) {
  53. $tag = array();
  54. } else {
  55. $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
  56. // @fixme should we use the cutoff too? Doesn't help with indexing per-user.
  57. $limit = TAGS_PER_SECTION;
  58. $qry = 'SELECT notice_tag.tag, '.
  59. $weightexpr . ' as weight ' .
  60. 'FROM notice_tag JOIN notice ' .
  61. 'ON notice_tag.notice_id = notice.id ' .
  62. 'WHERE notice.id in (' . implode(',', $ids) . ')'.
  63. 'GROUP BY notice_tag.tag ' .
  64. 'ORDER BY weight DESC LIMIT ' . $limit;
  65. $t = new Notice_tag();
  66. $t->query($qry);
  67. $tag = array();
  68. while ($t->fetch()) {
  69. $tag[] = clone($t);
  70. }
  71. }
  72. return new ArrayWrapper($tag);
  73. }
  74. public function showMore()
  75. {
  76. }
  77. }