Notice_tag.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2008, 2009, StatusNet, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
  20. class Notice_tag extends Managed_DataObject
  21. {
  22. ###START_AUTOCODE
  23. /* the code below is auto generated do not remove the above tag */
  24. public $__table = 'notice_tag'; // table name
  25. public $tag; // varchar(64) primary_key not_null
  26. public $notice_id; // int(4) primary_key not_null
  27. public $created; // datetime() not_null
  28. /* the code above is auto generated do not remove the tag below */
  29. ###END_AUTOCODE
  30. public static function schemaDef()
  31. {
  32. return array(
  33. 'description' => 'Hash tags',
  34. 'fields' => array(
  35. 'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this notice'),
  36. 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice tagged'),
  37. 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
  38. ),
  39. 'primary key' => array('tag', 'notice_id'),
  40. 'foreign keys' => array(
  41. 'notice_tag_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
  42. ),
  43. 'indexes' => array(
  44. 'notice_tag_created_idx' => array('created'),
  45. 'notice_tag_notice_id_idx' => array('notice_id'),
  46. 'notice_tag_tag_created_notice_id_idx' => array('tag', 'created', 'notice_id')
  47. ),
  48. );
  49. }
  50. static function getStream($tag, $offset=0, $limit=20, $sinceId=0, $maxId=0)
  51. {
  52. // FIXME: Get the Profile::current value some other way
  53. // to avoid confusino between queue processing and session.
  54. $stream = new TagNoticeStream($tag, Profile::current());
  55. return $stream;
  56. }
  57. function blowCache($blowLast=false)
  58. {
  59. self::blow('notice_tag:notice_ids:%s', Cache::keyize($this->tag));
  60. if ($blowLast) {
  61. self::blow('notice_tag:notice_ids:%s;last', Cache::keyize($this->tag));
  62. }
  63. }
  64. static function url($tag)
  65. {
  66. if (common_config('singleuser', 'enabled')) {
  67. // regular TagAction isn't set up in 1user mode
  68. $nickname = User::singleUserNickname();
  69. $url = common_local_url('showstream',
  70. array('nickname' => $nickname,
  71. 'tag' => $tag));
  72. } else {
  73. $url = common_local_url('tag', array('tag' => $tag));
  74. }
  75. return $url;
  76. }
  77. }