moderatednoticestream.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. public $widgetOpts;
  21. public $scoped;
  22. protected function filter(Notice $notice)
  23. {
  24. if (!parent::filter($notice)) {
  25. return false;
  26. }
  27. if(self::include_or_not($notice) === false) {
  28. return false;
  29. }
  30. // If this is a repeat the repeated notice is moderated
  31. if($notice->isRepeat()) {
  32. try {
  33. $repeated_notice = Notice::getById($notice->repeat_of);
  34. } catch (Exception $e) {
  35. // if we can't get the repeated notice by id, something is seriously wrong with it, so don't include it
  36. return false;
  37. }
  38. if(self::include_or_not($repeated_notice) === false) {
  39. return false;
  40. }
  41. }
  42. return true;
  43. }
  44. protected function include_or_not(Notice $notice)
  45. {
  46. $profile = $notice->getProfile();
  47. if ($profile->isSandboxed()) {
  48. if (!$this->scoped instanceof Profile) {
  49. // Non-logged in users don't get to see posts by sandboxed users
  50. return false;
  51. } elseif (!$profile->sameAs($this->scoped) && !$this->scoped->hasRight(Right::REVIEWSPAM)) {
  52. // And if we are logged in, deny if scoped user is neither the author nor has the right to review spam
  53. return false;
  54. }
  55. }
  56. }
  57. }