]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/ActivitySpam/actions/spam.php
Use File->getID()
[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         if (!$this->scoped instanceof Profile) {
78             throw new ClientException(_("You must be logged in to review."), 403);
79         }
80
81         // User must have the right to review spam
82
83         if (!$this->scoped->hasRight(ActivitySpamPlugin::REVIEWSPAM)) {
84             throw new ClientException(_('You cannot review spam on this site.'), 403);
85         }
86
87         $stream = new SpamNoticeStream($this->scoped);
88
89         $this->notices = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
90                                              NOTICES_PER_PAGE + 1);
91
92         if($this->page > 1 && $this->notices->N == 0) {
93             throw new ClientException(_('No such page.'), 404);
94         }
95
96         return true;
97     }
98
99     /**
100      * Handler method
101      *
102      * @param array $argarray is ignored since it's now passed in in prepare()
103      *
104      * @return void
105      */
106
107     function handle($argarray=null)
108     {
109         parent::handle();
110
111         $this->showPage();
112     }
113
114     /**
115      * Fill the content area
116      *
117      * Shows a list of the notices in the public stream, with some pagination
118      * controls.
119      *
120      * @return void
121      */
122
123     function showContent()
124     {
125         $nl = new NoticeList($this->notices, $this);
126
127         $cnt = $nl->show();
128
129         if ($cnt == 0) {
130             $this->showEmptyList();
131         }
132
133         $this->pagination($this->page > 1, 
134                           $cnt > NOTICES_PER_PAGE,
135                           $this->page,
136                           'spam');
137     }
138
139     function showEmptyList()
140     {
141         // TRANS: Text displayed for public feed when there are no public notices.
142         $message = _('This is the timeline of spam messages for %%site.name%% but none have been detected yet.');
143
144         $this->elementStart('div', 'guide');
145         $this->raw(common_markup_to_html($message));
146         $this->elementEnd('div');
147     }
148
149     /**
150      * Return true if read only.
151      *
152      * MAY override
153      *
154      * @param array $args other arguments
155      *
156      * @return boolean is read only action?
157      */
158
159     function isReadOnly($args)
160     {
161         return true;
162     }
163 }