moderatednoticestream.php 2.0 KB

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