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