spamnoticestream.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Spam notice stream
  18. *
  19. * @category Spam
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @copyright 2012 StatusNet, Inc.
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. /**
  27. * Spam notice stream
  28. *
  29. * @copyright 2012 StatusNet, Inc.
  30. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  31. */
  32. class SpamNoticeStream extends ScopingNoticeStream
  33. {
  34. public function __construct(Profile $scoped = null)
  35. {
  36. parent::__construct(
  37. new CachingNoticeStream(new RawSpamNoticeStream(), 'spam_score:notice_ids'),
  38. $scoped
  39. );
  40. }
  41. }
  42. /**
  43. * Raw stream of spammy notices
  44. *
  45. * @category Stream
  46. * @copyright 2011 StatusNet, Inc.
  47. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  48. */
  49. class RawSpamNoticeStream extends NoticeStream
  50. {
  51. public function getNoticeIds($offset, $limit, $since_id, $max_id)
  52. {
  53. $ss = new Spam_score();
  54. $ss->is_spam = true;
  55. $ss->selectAdd();
  56. $ss->selectAdd('notice_id');
  57. Notice::addWhereSinceId($ss, $since_id, 'notice_id');
  58. Notice::addWhereMaxId($ss, $max_id, 'notice_id');
  59. $ss->orderBy('notice_created DESC, notice_id DESC');
  60. if (!is_null($offset)) {
  61. $ss->limit($offset, $limit);
  62. }
  63. $ids = array();
  64. if ($ss->find()) {
  65. while ($ss->fetch()) {
  66. $ids[] = $ss->notice_id;
  67. }
  68. }
  69. return $ids;
  70. }
  71. }