spamnoticestream.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2012, StatusNet, Inc.
  5. *
  6. * Spam notice stream
  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 Spam
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2012 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * Spam notice stream
  33. *
  34. * @category Spam
  35. * @package StatusNet
  36. * @author Evan Prodromou <evan@status.net>
  37. * @copyright 2012 StatusNet, Inc.
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  39. * @link http://status.net/
  40. */
  41. class SpamNoticeStream extends ScopingNoticeStream
  42. {
  43. function __construct(Profile $scoped=null)
  44. {
  45. parent::__construct(new CachingNoticeStream(new RawSpamNoticeStream(), 'spam_score:notice_ids'),
  46. $scoped);
  47. }
  48. }
  49. /**
  50. * Raw stream of spammy notices
  51. *
  52. * @category Stream
  53. * @package StatusNet
  54. * @author Evan Prodromou <evan@status.net>
  55. * @copyright 2011 StatusNet, Inc.
  56. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  57. * @link http://status.net/
  58. */
  59. class RawSpamNoticeStream extends NoticeStream
  60. {
  61. function getNoticeIds($offset, $limit, $since_id, $max_id)
  62. {
  63. $ss = new Spam_score();
  64. $ss->is_spam = 1;
  65. $ss->selectAdd();
  66. $ss->selectAdd('notice_id');
  67. Notice::addWhereSinceId($ss, $since_id, 'notice_id');
  68. Notice::addWhereMaxId($ss, $max_id, 'notice_id');
  69. $ss->orderBy('notice_created DESC, notice_id DESC');
  70. if (!is_null($offset)) {
  71. $ss->limit($offset, $limit);
  72. }
  73. $ids = array();
  74. if ($ss->find()) {
  75. while ($ss->fetch()) {
  76. $ids[] = $ss->notice_id;
  77. }
  78. }
  79. return $ids;
  80. }
  81. }