grouptagcloudsection.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Personal tag cloud section
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Widget
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2009 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. /**
  33. * Group tag cloud section
  34. *
  35. * @category Widget
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. */
  41. class GroupTagCloudSection extends TagCloudSection
  42. {
  43. var $group = null;
  44. function __construct($out=null, $group=null)
  45. {
  46. parent::__construct($out);
  47. $this->group = $group;
  48. }
  49. function title()
  50. {
  51. // TRANS: Title for group tag cloud section.
  52. // TRANS: %s is a group name.
  53. return _('Tags');
  54. }
  55. function getTags()
  56. {
  57. $weightexpr = common_sql_weight('notice_tag.created', common_config('tag', 'dropoff'));
  58. // @fixme should we use the cutoff too? Doesn't help with indexing per-group.
  59. $names = $this->group->getAliases();
  60. $names = array_merge(array($this->group->nickname), $names);
  61. // XXX This is dumb.
  62. $quoted = array();
  63. foreach ($names as $name) {
  64. $quoted[] = "'$name'";
  65. }
  66. $namestring = implode(',', $quoted);
  67. $qry = 'SELECT notice_tag.tag, '.
  68. $weightexpr . ' as weight ' .
  69. 'FROM notice_tag JOIN notice ' .
  70. 'ON notice_tag.notice_id = notice.id ' .
  71. 'JOIN group_inbox on group_inbox.notice_id = notice.id ' .
  72. 'WHERE group_inbox.group_id = %d ' .
  73. 'AND notice_tag.tag not in (%s) '.
  74. 'GROUP BY notice_tag.tag ' .
  75. 'ORDER BY weight DESC ';
  76. $limit = TAGS_PER_SECTION;
  77. $offset = 0;
  78. if (common_config('db','type') == 'pgsql') {
  79. $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
  80. } else {
  81. $qry .= ' LIMIT ' . $offset . ', ' . $limit;
  82. }
  83. $tag = Memcached_DataObject::cachedQuery('Notice_tag',
  84. sprintf($qry,
  85. $this->group->id,
  86. $namestring),
  87. 3600);
  88. return $tag;
  89. }
  90. }