]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Notice_tag.php
Merge branch '1.0.x' into qna
[quix0rs-gnu-social.git] / classes / Notice_tag.php
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
20 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
21
22 class Notice_tag extends Memcached_DataObject
23 {
24     ###START_AUTOCODE
25     /* the code below is auto generated do not remove the above tag */
26
27     public $__table = 'notice_tag';                      // table name
28     public $tag;                             // varchar(64)  primary_key not_null
29     public $notice_id;                       // int(4)  primary_key not_null
30     public $created;                         // datetime()   not_null
31
32     /* Static get */
33     function staticGet($k,$v=null)
34     { return Memcached_DataObject::staticGet('Notice_tag',$k,$v); }
35
36     /* the code above is auto generated do not remove the tag below */
37     ###END_AUTOCODE
38
39     static function getStream($tag, $offset=0, $limit=20, $sinceId=0, $maxId=0)
40     {
41         $stream = new NoticeStream(array('Notice_tag', '_streamDirect'),
42                                    array($tag),
43                                    'notice_tag:notice_ids:' . Cache::keyize($tag));
44         
45         return $stream->getNotices($offset, $limit, $sinceId, $maxId);
46     }
47
48     function _streamDirect($tag, $offset, $limit, $since_id, $max_id)
49     {
50         $nt = new Notice_tag();
51
52         $nt->tag = $tag;
53
54         $nt->selectAdd();
55         $nt->selectAdd('notice_id');
56
57         Notice::addWhereSinceId($nt, $since_id, 'notice_id');
58         Notice::addWhereMaxId($nt, $max_id, 'notice_id');
59
60         $nt->orderBy('created DESC, notice_id DESC');
61
62         if (!is_null($offset)) {
63             $nt->limit($offset, $limit);
64         }
65
66         $ids = array();
67
68         if ($nt->find()) {
69             while ($nt->fetch()) {
70                 $ids[] = $nt->notice_id;
71             }
72         }
73
74         return $ids;
75     }
76
77     function blowCache($blowLast=false)
78     {
79         self::blow('notice_tag:notice_ids:%s', Cache::keyize($this->tag));
80         if ($blowLast) {
81             self::blow('notice_tag:notice_ids:%s;last', Cache::keyize($this->tag));
82         }
83     }
84
85     function pkeyGet($kv)
86     {
87         return Memcached_DataObject::pkeyGet('Notice_tag', $kv);
88     }
89
90         static function url($tag)
91         {
92                 if (common_config('singleuser', 'enabled')) {
93                         // regular TagAction isn't set up in 1user mode
94                         $nickname = User::singleUserNickname();
95                         $url = common_local_url('showstream',
96                                                                         array('nickname' => $nickname,
97                                                                                   'tag' => $tag));
98                 } else {
99                         $url = common_local_url('tag', array('tag' => $tag));
100                 }
101
102                 return $url;
103         }
104 }