grouptagcloudsection.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. * Group tag cloud section
  28. *
  29. * @category Widget
  30. * @package StatusNet
  31. * @author Evan Prodromou <evan@status.net>
  32. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  33. * @link http://status.net/
  34. */
  35. class GroupTagCloudSection extends TagCloudSection
  36. {
  37. public $group = null;
  38. public function __construct($out = null, $group = null)
  39. {
  40. parent::__construct($out);
  41. $this->group = $group;
  42. }
  43. public function title()
  44. {
  45. // TRANS: Title for group tag cloud section.
  46. // TRANS: %s is a group name.
  47. return _('Tags');
  48. }
  49. public function getTags()
  50. {
  51. $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
  52. // @fixme should we use the cutoff too? Doesn't help with indexing per-group.
  53. $names = $this->group->getAliases();
  54. $names = array_merge(array($this->group->nickname), $names);
  55. // XXX This is dumb.
  56. $quoted = array();
  57. foreach ($names as $name) {
  58. $quoted[] = "'$name'";
  59. }
  60. $namestring = implode(',', $quoted);
  61. $limit = TAGS_PER_SECTION;
  62. $qry = 'SELECT notice_tag.tag, ' . $weightexpr . ' AS weight ' .
  63. 'FROM notice_tag INNER JOIN notice ' .
  64. 'ON notice_tag.notice_id = notice.id ' .
  65. 'INNER JOIN group_inbox ON group_inbox.notice_id = notice.id ' .
  66. 'WHERE group_inbox.group_id = %d ' .
  67. 'AND notice_tag.tag NOT IN (%s) '.
  68. 'GROUP BY notice_tag.tag ' .
  69. 'ORDER BY weight DESC LIMIT ' . $limit;
  70. $tag = Memcached_DataObject::cachedQuery(
  71. 'Notice_tag',
  72. sprintf($qry, $this->group->id, $namestring),
  73. 3600
  74. );
  75. return $tag;
  76. }
  77. }