]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/moderatednoticestream.php
*** Privacy Leak fixed: ***
[quix0rs-gnu-social.git] / lib / moderatednoticestream.php
1 <?php
2
3 if (!defined('GNUSOCIAL')) { exit(1); }
4
5 /**
6  * Moderated notice stream, will take into account the scoping of
7  * notices as well as whether the profile is moderated somehow,
8  * such as by sandboxing or silencing.
9  *
10  * Inherits $this->scoped from ScopingNoticeStream as the Profile
11  * this stream is meant for. Can be null in case we're not logged in.
12  *
13  * @category  Stream
14  * @package   GNUsocial
15  * @author    Mikael Nordfeldth <mmn@hethane.se>
16  * @copyright 2016 Free Software Foundation, Inc.
17  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
18  * @link      https://gnu.io/social
19  */
20
21 class ModeratedNoticeStream extends ScopingNoticeStream
22 {
23     protected function filter(Notice $notice)
24     {
25         if (!parent::filter($notice)) {
26             return false;
27         }
28         
29         if(self::include_or_not($notice) === false) {
30             return false;
31         }
32         
33         // If this is a repeat the repeated notice is moderated
34         if($notice->isRepeat()) {
35             try {
36                 $repeated_notice = Notice::getById($notice->repeat_of);
37             } catch (Exception $e) {
38                 // if we can't get the repeated notice by id, something is seriously wrong with it, so don't include it
39                 return false;
40             }
41
42             if(self::include_or_not($repeated_notice) === false) {
43                 return false;
44             }
45         }         
46
47         return true;
48     }
49     
50     protected function include_or_not(Notice $notice)
51     {    
52         $profile = $notice->getProfile();
53
54         if ($profile->isSandboxed()) {
55             if (!$this->scoped instanceof Profile) {
56                 // Non-logged in users don't get to see posts by sandboxed users
57                 return false;
58             } elseif (!$profile->sameAs($this->scoped) && !$this->scoped->hasRight(Right::REVIEWSPAM)) {
59                 // And if we are logged in, deny if scoped user is neither the author nor has the right to review spam
60                 return false;
61             } 
62         }    
63     }
64 }