]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/profilenoticestream.php
*** Privacy Leak fixed: ***
[quix0rs-gnu-social.git] / lib / profilenoticestream.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Stream of notices by a profile
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('GNUSOCIAL')) { exit(1); }
32
33 /**
34  * Stream of notices by a profile
35  *
36  * @category  General
37  * @package   StatusNet
38  * @author    Evan Prodromou <evan@status.net>
39  * @copyright 2011 StatusNet, Inc.
40  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
41  * @link      http://status.net/
42  */
43
44 class ProfileNoticeStream extends ScopingNoticeStream
45 {
46     protected $target;
47
48     function __construct(Profile $target, Profile $scoped=null)
49     {
50         $this->target = $target;
51         parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($target),
52                                                     'profile:notice_ids:' . $target->getID()),
53                             $scoped);
54     }
55
56     function getNoticeIds($offset, $limit, $since_id=null, $max_id=null)
57     {
58         if ($this->impossibleStream()) {
59             return array();
60         } else {
61             return parent::getNoticeIds($offset, $limit, $since_id, $max_id);
62         }
63     }
64
65     function getNotices($offset, $limit, $since_id=null, $max_id=null)
66     {
67         if ($this->impossibleStream()) {
68             throw new PrivateStreamException($this->target, $this->scoped);
69         } else {
70             return parent::getNotices($offset, $limit, $since_id, $max_id);
71         }
72     }
73
74     function impossibleStream() 
75     {
76         if (!$this->target->readableBy($this->scoped)) {
77             // cannot read because it's a private stream and either noone's logged in or they are not subscribers
78             return true;
79         }
80
81         // If it's a spammy stream, and no user or not a moderator
82
83         if (common_config('notice', 'hidespam')) {
84             // if this is a silenced user
85             if ($this->target->hasRole(Profile_role::SILENCED)
86                     // and we are either not logged in
87                     && (!$this->scoped instanceof Profile
88                         // or if we are, we are not logged in as the target, and we don't have right to review spam
89                         || (!$this->scoped->sameAs($this->target) && !$this->scoped->hasRight(Right::REVIEWSPAM))
90                     )) {
91                 return true;
92             }
93         }
94
95         return false;
96     }
97 }
98
99 /**
100  * Raw stream of notices by a profile
101  *
102  * @category  General
103  * @package   StatusNet
104  * @author    Evan Prodromou <evan@status.net>
105  * @copyright 2011 StatusNet, Inc.
106  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
107  * @link      http://status.net/
108  */
109
110 class RawProfileNoticeStream extends NoticeStream
111 {
112     protected $target;
113     protected $selectVerbs = array();   // select all verbs
114
115     function __construct(Profile $target)
116     {
117         parent::__construct();
118         $this->target = $target;
119     }
120
121     function getNoticeIds($offset, $limit, $since_id, $max_id)
122     {
123         $notice = new Notice();
124
125         $notice->profile_id = $this->target->getID();
126
127         $notice->selectAdd();
128         $notice->selectAdd('id');
129
130         Notice::addWhereSinceId($notice, $since_id);
131         Notice::addWhereMaxId($notice, $max_id);
132
133         self::filterVerbs($notice, $this->selectVerbs);
134
135         $notice->orderBy('created DESC, id DESC');
136
137         if (!is_null($offset)) {
138             $notice->limit($offset, $limit);
139         }
140
141         $notice->find();
142
143         $ids = array();
144
145         while ($notice->fetch()) {
146             $ids[] = $notice->id;
147         }
148
149         return $ids;
150     }
151 }