]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/publicnoticestream.php
Merge remote-tracking branch 'mainline/1.0.x' into people_tags_rebase
[quix0rs-gnu-social.git] / lib / publicnoticestream.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Public stream
7  * 
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Stream
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Public stream
39  *
40  * @category  Stream
41  * @package   StatusNet
42  * @author    Evan Prodromou <evan@status.net>
43  * @copyright 2011 StatusNet, Inc.
44  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45  * @link      http://status.net/
46  */
47
48 class PublicNoticeStream extends ScopingNoticeStream
49 {
50     const THREADED=true;
51
52     /**
53      *
54      * @param boolean $threaded set to true to exclude replies, for later fetching
55      */
56     function __construct($threaded=false)
57     {
58         parent::__construct(new CachingNoticeStream(new RawPublicNoticeStream($threaded),
59                                                     $threaded ? 'public:threaded' : 'public'));
60     }
61 }
62
63 /**
64  * Raw public stream
65  *
66  * @category  Stream
67  * @package   StatusNet
68  * @author    Evan Prodromou <evan@status.net>
69  * @copyright 2011 StatusNet, Inc.
70  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
71  * @link      http://status.net/
72  */
73
74 class RawPublicNoticeStream extends NoticeStream
75 {
76     var $threaded;
77
78     function __construct($threaded=false)
79     {
80         $this->threaded = $threaded;
81     }
82
83     function getNoticeIds($offset, $limit, $since_id, $max_id)
84     {
85         $notice = new Notice();
86
87         $notice->selectAdd(); // clears it
88         $notice->selectAdd('id');
89
90         $notice->orderBy('created DESC, id DESC');
91
92         if (!is_null($offset)) {
93             $notice->limit($offset, $limit);
94         }
95
96         if (common_config('public', 'localonly')) {
97             $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
98         } else {
99             // -1 == blacklisted, -2 == gateway (i.e. Twitter)
100             $notice->whereAdd('is_local !='. Notice::LOCAL_NONPUBLIC);
101             $notice->whereAdd('is_local !='. Notice::GATEWAY);
102         }
103         if ($this->threaded) {
104             $notice->whereAdd('reply_to IS NULL');
105         }
106
107         Notice::addWhereSinceId($notice, $since_id);
108         Notice::addWhereMaxId($notice, $max_id);
109
110         $ids = array();
111
112         if ($notice->find()) {
113             while ($notice->fetch()) {
114                 $ids[] = $notice->id;
115             }
116         }
117
118         $notice->free();
119         $notice = NULL;
120
121         return $ids;
122     }
123 }