spam.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2012, StatusNet, Inc.
  5. *
  6. * Stream of latest spam messages
  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('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. require_once INSTALLDIR . '/lib/notices/noticelist.php';
  36. /**
  37. * SpamAction
  38. *
  39. * Shows the latest spam on the service
  40. *
  41. * @category Spam
  42. * @package StatusNet
  43. * @author Evan Prodromou <evan@status.net>
  44. * @copyright 2012 StatusNet, Inc.
  45. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  46. * @link http://status.net/
  47. */
  48. class SpamAction extends Action
  49. {
  50. var $page = null;
  51. var $notices = null;
  52. function title()
  53. {
  54. return _("Latest Spam");
  55. }
  56. /**
  57. * For initializing members of the class.
  58. *
  59. * @param array $args misc. arguments
  60. *
  61. * @return boolean true
  62. * @throws ClientException
  63. */
  64. function prepare(array $args = [])
  65. {
  66. parent::prepare($args);
  67. $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
  68. // User must be logged in.
  69. if (!$this->scoped instanceof Profile) {
  70. throw new ClientException(_("You must be logged in to review."), 403);
  71. }
  72. // User must have the right to review spam
  73. if (!$this->scoped->hasRight(ActivitySpamPlugin::REVIEWSPAM)) {
  74. throw new ClientException(_('You cannot review spam on this site.'), 403);
  75. }
  76. $stream = new SpamNoticeStream($this->scoped);
  77. $this->notices = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE,
  78. NOTICES_PER_PAGE + 1);
  79. if ($this->page > 1 && $this->notices->N == 0) {
  80. throw new ClientException(_('No such page.'), 404);
  81. }
  82. return true;
  83. }
  84. /**
  85. * Handler method
  86. *
  87. * @return void
  88. */
  89. function handle()
  90. {
  91. parent::handle();
  92. $this->showPage();
  93. }
  94. /**
  95. * Fill the content area
  96. *
  97. * Shows a list of the notices in the public stream, with some pagination
  98. * controls.
  99. *
  100. * @return void
  101. */
  102. function showContent()
  103. {
  104. $nl = new NoticeList($this->notices, $this);
  105. $cnt = $nl->show();
  106. if ($cnt == 0) {
  107. $this->showEmptyList();
  108. }
  109. $this->pagination($this->page > 1,
  110. $cnt > NOTICES_PER_PAGE,
  111. $this->page,
  112. 'spam');
  113. }
  114. function showEmptyList()
  115. {
  116. // TRANS: Text displayed for public feed when there are no public notices.
  117. $message = _('This is the timeline of spam messages for %%site.name%% but none have been detected yet.');
  118. $this->elementStart('div', 'guide');
  119. $this->raw(common_markup_to_html($message));
  120. $this->elementEnd('div');
  121. }
  122. /**
  123. * Return true if read only.
  124. *
  125. * MAY override
  126. *
  127. * @param array $args other arguments
  128. *
  129. * @return boolean is read only action?
  130. */
  131. function isReadOnly($args)
  132. {
  133. return true;
  134. }
  135. }