publictagcloudsection.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * Public 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. * Public 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 PublicTagCloudSection extends TagCloudSection
  33. {
  34. public function __construct($out = null)
  35. {
  36. parent::__construct($out);
  37. }
  38. public function title()
  39. {
  40. // TRANS: Title for inbox tag cloud section.
  41. return _m('TITLE', 'Trends');
  42. }
  43. public function getTags()
  44. {
  45. $profile = Profile::current();
  46. if (empty($profile)) {
  47. $keypart = sprintf('Notice:public_tag_cloud:null');
  48. } else {
  49. $keypart = sprintf('Notice:public_tag_cloud:%d', $profile->id);
  50. }
  51. $tag = Memcached_DataObject::cacheGet($keypart);
  52. if ($tag === false) {
  53. $stream = new PublicNoticeStream($profile);
  54. $ids = $stream->getNoticeIds(0, 500, null, null);
  55. if (empty($ids)) {
  56. $tag = array();
  57. } else {
  58. $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
  59. // @fixme should we use the cutoff too? Doesn't help with indexing per-user.
  60. $limit = TAGS_PER_SECTION;
  61. $qry = 'SELECT notice_tag.tag, ' . $weightexpr . ' AS weight ' .
  62. 'FROM notice_tag JOIN notice ' .
  63. 'ON notice_tag.notice_id = notice.id ' .
  64. 'WHERE notice.id in (' . implode(',', $ids) . ') '.
  65. 'GROUP BY notice_tag.tag ' .
  66. 'ORDER BY weight DESC LIMIT ' . $limit;
  67. $t = new Notice_tag();
  68. $t->query($qry);
  69. $tag = array();
  70. while ($t->fetch()) {
  71. $tag[] = clone($t);
  72. }
  73. }
  74. Memcached_DataObject::cacheSet($keypart, $tag, 60 * 60 * 24);
  75. }
  76. return new ArrayWrapper($tag);
  77. }
  78. public function showMore()
  79. {
  80. }
  81. }