]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/inboxnoticestream.php
*** Privacy Leak fixed: ***
[quix0rs-gnu-social.git] / lib / inboxnoticestream.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Stream of notices for a profile's "all" feed
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  * @category  NoticeStream
22  * @package   StatusNet
23  * @author    Evan Prodromou <evan@status.net>
24  * @author    Mikael Nordfeldth <mmn@hethane.se>
25  * @author    Alexei Sorokin <sor.alexei@meowr.ru>
26  * @copyright 2011 StatusNet, Inc.
27  * @copyright 2014 Free Software Foundation, Inc.
28  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
29  * @link      http://status.net/
30  */
31
32 if (!defined('GNUSOCIAL')) {
33     exit(1);
34 }
35
36 /**
37  * Stream of notices for a profile's "all" feed
38  *
39  * @category  General
40  * @package   StatusNet
41  * @author    Evan Prodromou <evan@status.net>
42  * @author    Mikael Nordfeldth <mmn@hethane.se>
43  * @author    Alexei Sorokin <sor.alexei@meowr.ru>
44  * @author    chimo <chimo@chromic.org>
45  * @copyright 2011 StatusNet, Inc.
46  * @copyright 2014 Free Software Foundation, Inc.
47  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
48  * @link      http://status.net/
49  */
50 class InboxNoticeStream extends ScopingNoticeStream
51 {
52     /**
53      * Constructor
54      *
55      * @param Profile $target Profile to get a stream for
56      * @param Profile $scoped Currently scoped profile (if null, it is fetched)
57      */
58     public function __construct(Profile $target, Profile $scoped = null)
59     {
60         parent::__construct(new CachingNoticeStream(new RawInboxNoticeStream($target), 'profileall:'.$target->getID()), $scoped);
61     }
62 }
63
64 /**
65  * Raw stream of notices for the target's inbox
66  *
67  * @category  General
68  * @package   StatusNet
69  * @author    Evan Prodromou <evan@status.net>
70  * @author    Mikael Nordfeldth <mmn@hethane.se>
71  * @author    Alexei Sorokin <sor.alexei@meowr.ru>
72  * @copyright 2011 StatusNet, Inc.
73  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
74  * @link      http://status.net/
75  */
76 class RawInboxNoticeStream extends FullNoticeStream
77 {
78     protected $target = null;
79     protected $inbox = null;
80
81     /**
82      * Constructor
83      *
84      * @param Profile $target Profile to get a stream for
85      */
86     public function __construct(Profile $target)
87     {
88         parent::__construct();
89         $this->target = $target;
90     }
91
92     /**
93      * Get IDs in a range
94      *
95      * @param int $offset Offset from start
96      * @param int $limit Limit of number to get
97      * @param int $since_id Since this notice
98      * @param int $max_id Before this notice
99      *
100      * @return array IDs found
101      */
102     public function getNoticeIds($offset, $limit, $since_id = null, $max_id = null)
103     {
104         $notice = new Notice();
105         $notice->selectAdd();
106         $notice->selectAdd('id');
107         $notice->whereAdd(sprintf('notice.created > "%s"', $notice->escape($this->target->created)));
108         // Reply:: is a table of mentions
109         // Subscription:: is a table of subscriptions (every user is subscribed to themselves)
110         // Sort in descending order as id will give us even really old posts,
111         // which were recently imported. For example, if a remote instance had
112         // problems and just managed to post here.
113         $notice->whereAdd(
114             sprintf('id IN (SELECT DISTINCT id FROM (' .
115                 '(SELECT id FROM notice WHERE profile_id IN (SELECT subscribed FROM subscription WHERE subscriber = %1$d)) UNION ' .
116                 '(SELECT notice_id AS id FROM reply WHERE profile_id = %1$d) UNION ' .
117                 '(SELECT notice_id AS id FROM attention WHERE profile_id = %1$d) UNION ' .
118                 '(SELECT notice_id AS id FROM group_inbox WHERE group_id IN (SELECT group_id FROM group_member WHERE profile_id = %1$d)) ' .
119                 'ORDER BY id DESC) AS T)',
120                 $this->target->getID())
121         );
122
123         if (!empty($since_id)) {
124             $notice->whereAdd(sprintf('notice.id > %d', $since_id));
125         }
126         if (!empty($max_id)) {
127             $notice->whereAdd(sprintf('notice.id <= %d', $max_id));
128         }
129
130         self::filterVerbs($notice, $this->selectVerbs);
131
132         $notice->limit($offset, $limit);
133
134         if (!$notice->find()) {
135             return [];
136         }
137
138         return $notice->fetchAll('id');
139     }
140 }