spam.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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/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. return _("Latest Spam");
  54. }
  55. /**
  56. * For initializing members of the class.
  57. *
  58. * @param array $argarray misc. arguments
  59. *
  60. * @return boolean true
  61. */
  62. function prepare($argarray)
  63. {
  64. parent::prepare($argarray);
  65. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  66. // User must be logged in.
  67. if (!$this->scoped instanceof Profile) {
  68. throw new ClientException(_("You must be logged in to review."), 403);
  69. }
  70. // User must have the right to review spam
  71. if (!$this->scoped->hasRight(ActivitySpamPlugin::REVIEWSPAM)) {
  72. throw new ClientException(_('You cannot review spam on this site.'), 403);
  73. }
  74. $stream = new SpamNoticeStream($this->scoped);
  75. $this->notices = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
  76. NOTICES_PER_PAGE + 1);
  77. if($this->page > 1 && $this->notices->N == 0) {
  78. throw new ClientException(_('No such page.'), 404);
  79. }
  80. return true;
  81. }
  82. /**
  83. * Handler method
  84. *
  85. * @param array $argarray is ignored since it's now passed in in prepare()
  86. *
  87. * @return void
  88. */
  89. function handle($argarray=null)
  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. }