]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/adminprofileflag.php
pagination works for flagged profiles
[quix0rs-gnu-social.git] / plugins / UserFlag / adminprofileflag.php
1 <?php
2 /**
3  * Show latest and greatest profile flags
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2009, StatusNet, Inc.
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU Affero General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU Affero General Public License for more details.
25  *
26  * You should have received a copy of the GNU Affero General Public License
27  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Show the latest and greatest profile flags
36  *
37  * @category Action
38  * @package  StatusNet
39  * @author   Evan Prodromou <evan@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41  * @link     http://status.net/
42  */
43
44 class AdminprofileflagAction extends Action
45 {
46     var $page     = null;
47     var $profiles = null;
48
49     /**
50      * Take arguments for running
51      *
52      * @param array $args $_REQUEST args
53      *
54      * @return boolean success flag
55      */
56
57     function prepare($args)
58     {
59         parent::prepare($args);
60
61         $user = common_current_user();
62
63         // User must be logged in.
64
65         if (!common_logged_in()) {
66             $this->clientError(_('Not logged in.'));
67             return;
68         }
69
70         $user = common_current_user();
71
72         // ...because they're logged in
73
74         assert(!empty($user));
75
76         // It must be a "real" login, not saved cookie login
77
78         if (!common_is_real_login()) {
79             // Cookie theft is too easy; we require automatic
80             // logins to re-authenticate before admining the site
81             common_set_returnto($this->selfUrl());
82             if (Event::handle('RedirectToLogin', array($this, $user))) {
83                 common_redirect(common_local_url('login'), 303);
84             }
85         }
86
87         // User must have the right to review flags
88
89         if (!$user->hasRight(UserFlagPlugin::REVIEWFLAGS)) {
90             $this->clientError(_('You cannot review profile flags.'));
91             return false;
92         }
93
94         $this->page = $this->trimmed('page');
95
96         if (empty($this->page)) {
97             $this->page = 1;
98         }
99
100         $this->profiles = $this->getProfiles();
101
102         return true;
103     }
104
105     /**
106      * Handle request
107      *
108      * @param array $args $_REQUEST args; handled in prepare()
109      *
110      * @return void
111      */
112
113     function handle($args)
114     {
115         parent::handle($args);
116
117         $this->showPage();
118     }
119
120     function title() {
121         return _('Flagged profiles');
122     }
123
124     /**
125      * save the profile flag
126      *
127      * @return void
128      */
129
130     function showContent()
131     {
132         $pl = new FlaggedProfileList($this->profiles, $this);
133
134         $cnt = $pl->show();
135
136         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
137                           $this->page, 'adminprofileflag');
138     }
139
140     function getProfiles()
141     {
142         $ufp = new User_flag_profile();
143
144         $ufp->selectAdd();
145         $ufp->selectAdd('profile_id');
146         $ufp->selectAdd('count(*) as flag_count');
147
148         $ufp->whereAdd('cleared is NULL');
149
150         $ufp->groupBy('profile_id');
151         $ufp->orderBy('flag_count DESC, profile_id DESC');
152
153         $offset = ($this->page-1) * PROFILES_PER_PAGE;
154         $limit =  PROFILES_PER_PAGE + 1;
155
156         $ufp->limit($offset, $limit);
157
158         $profiles = array();
159
160         if ($ufp->find()) {
161             while ($ufp->fetch()) {
162                 $profile = Profile::staticGet('id', $ufp->profile_id);
163                 if (!empty($profile)) {
164                     $profiles[] = $profile;
165                 }
166             }
167         }
168
169         $ufp->free();
170
171         return new ArrayWrapper($profiles);
172     }
173 }
174
175 class FlaggedProfileList extends ProfileList {
176
177     function newListItem($profile)
178     {
179         return new FlaggedProfileListItem($this->profile, $this->action);
180     }
181 }
182
183 class FlaggedProfileListItem extends ProfileListItem
184 {
185     var $user = null;
186     var $r2args = null;
187
188     function showActions()
189     {
190         $this->user = common_current_user();
191
192         list($action, $this->r2args) = $this->out->returnToArgs();
193
194         $this->r2args['action'] = $action;
195
196         $this->startActions();
197         if (Event::handle('StartProfileListItemActionElements', array($this))) {
198             $this->out->elementStart('li', 'entity_moderation');
199             $this->out->element('p', null, _('Moderate'));
200             $this->out->elementStart('ul');
201             $this->showSandboxButton();
202             $this->showSilenceButton();
203             $this->showDeleteButton();
204             $this->showClearButton();
205             $this->out->elementEnd('ul');
206             $this->out->elementEnd('li');
207             Event::handle('EndProfileListItemActionElements', array($this));
208         }
209         $this->endActions();
210     }
211
212     function showSandboxButton()
213     {
214         if ($this->user->hasRight(Right::SANDBOXUSER)) {
215             $this->out->elementStart('li', 'entity_sandbox');
216             if ($this->profile->isSandboxed()) {
217                 $usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
218                 $usf->show();
219             } else {
220                 $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
221                 $sf->show();
222             }
223             $this->out->elementEnd('li');
224         }
225     }
226
227     function showSilenceButton()
228     {
229         if ($this->user->hasRight(Right::SILENCEUSER)) {
230             $this->out->elementStart('li', 'entity_silence');
231             if ($this->profile->isSilenced()) {
232                 $usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
233                 $usf->show();
234             } else {
235                 $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
236                 $sf->show();
237             }
238             $this->out->elementEnd('li');
239         }
240     }
241
242     function showDeleteButton()
243     {
244
245         if ($this->user->hasRight(Right::DELETEUSER)) {
246             $this->out->elementStart('li', 'entity_delete');
247             $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
248             $df->show();
249             $this->out->elementEnd('li');
250         }
251     }
252
253     function showClearButton()
254     {
255     }
256 }