Notice_tag.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. * @copyright 2008, 2009 StatusNet, Inc.
  18. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  19. */
  20. defined('GNUSOCIAL') || die();
  21. class Notice_tag extends Managed_DataObject
  22. {
  23. ###START_AUTOCODE
  24. /* the code below is auto generated do not remove the above tag */
  25. public $__table = 'notice_tag'; // table name
  26. public $tag; // varchar(64) primary_key not_null
  27. public $notice_id; // int(4) primary_key not_null
  28. public $created; // datetime()
  29. /* the code above is auto generated do not remove the tag below */
  30. ###END_AUTOCODE
  31. public static function schemaDef()
  32. {
  33. return array(
  34. 'description' => 'Hash tags',
  35. 'fields' => array(
  36. 'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'hash tag associated with this notice'),
  37. 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice tagged'),
  38. 'created' => array('type' => 'datetime', 'description' => 'date this record was created'),
  39. ),
  40. 'primary key' => array('tag', 'notice_id'),
  41. 'foreign keys' => array(
  42. 'notice_tag_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
  43. ),
  44. 'indexes' => array(
  45. 'notice_tag_created_idx' => array('created'),
  46. 'notice_tag_notice_id_idx' => array('notice_id'),
  47. 'notice_tag_tag_created_notice_id_idx' => array('tag', 'created', 'notice_id')
  48. ),
  49. );
  50. }
  51. public static function getStream(
  52. $tag,
  53. $offset = 0,
  54. $limit = 20,
  55. $sinceId = 0,
  56. $maxId = 0
  57. ) {
  58. // FIXME: Get the Profile::current value some other way
  59. // to avoid confusino between queue processing and session.
  60. $stream = new TagNoticeStream($tag, Profile::current());
  61. return $stream;
  62. }
  63. public function blowCache($blowLast = false)
  64. {
  65. self::blow('notice_tag:notice_ids:%s', Cache::keyize($this->tag));
  66. if ($blowLast) {
  67. self::blow('notice_tag:notice_ids:%s;last', Cache::keyize($this->tag));
  68. }
  69. }
  70. public static function url($tag)
  71. {
  72. if (common_config('singleuser', 'enabled')) {
  73. // Regular TagAction isn't set up in 1user mode
  74. $nickname = User::singleUserNickname();
  75. $url = common_local_url(
  76. 'showstream',
  77. [
  78. 'nickname' => $nickname,
  79. 'tag' => $tag,
  80. ]
  81. );
  82. } else {
  83. $url = common_local_url('tag', ['tag' => $tag]);
  84. }
  85. return $url;
  86. }
  87. }