spam.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. $user = common_current_user();
  68. if (empty($user)) {
  69. throw new ClientException(_("You must be logged in to review."), 403);
  70. }
  71. // User must have the right to review spam
  72. if (!$user->hasRight(ActivitySpamPlugin::REVIEWSPAM)) {
  73. throw new ClientException(_('You cannot review spam on this site.'), 403);
  74. }
  75. $stream = new SpamNoticeStream($user->getProfile());
  76. $this->notices = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
  77. NOTICES_PER_PAGE + 1);
  78. if($this->page > 1 && $this->notices->N == 0) {
  79. throw new ClientException(_('No such page.'), 404);
  80. }
  81. return true;
  82. }
  83. /**
  84. * Handler method
  85. *
  86. * @param array $argarray is ignored since it's now passed in in prepare()
  87. *
  88. * @return void
  89. */
  90. function handle($argarray=null)
  91. {
  92. parent::handle($args);
  93. $this->showPage();
  94. }
  95. /**
  96. * Fill the content area
  97. *
  98. * Shows a list of the notices in the public stream, with some pagination
  99. * controls.
  100. *
  101. * @return void
  102. */
  103. function showContent()
  104. {
  105. $nl = new NoticeList($this->notices, $this);
  106. $cnt = $nl->show();
  107. if ($cnt == 0) {
  108. $this->showEmptyList();
  109. }
  110. $this->pagination($this->page > 1,
  111. $cnt > NOTICES_PER_PAGE,
  112. $this->page,
  113. 'spam');
  114. }
  115. function showEmptyList()
  116. {
  117. // TRANS: Text displayed for public feed when there are no public notices.
  118. $message = _('This is the timeline of spam messages for %%site.name%% but none have been detected yet.');
  119. $this->elementStart('div', 'guide');
  120. $this->raw(common_markup_to_html($message));
  121. $this->elementEnd('div');
  122. }
  123. /**
  124. * Return true if read only.
  125. *
  126. * MAY override
  127. *
  128. * @param array $args other arguments
  129. *
  130. * @return boolean is read only action?
  131. */
  132. function isReadOnly($args)
  133. {
  134. return true;
  135. }
  136. }