3 * Show latest and greatest profile flags
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2009, StatusNet, Inc.
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.
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.
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/>.
30 if (!defined('STATUSNET')) {
35 * Show the latest and greatest profile flags
39 * @author Evan Prodromou <evan@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41 * @link http://status.net/
44 class AdminprofileflagAction extends Action
49 * Take arguments for running
51 * @param array $args $_REQUEST args
53 * @return boolean success flag
56 function prepare($args)
58 parent::prepare($args);
60 $user = common_current_user();
62 // User must be logged in.
64 if (!common_logged_in()) {
65 $this->clientError(_('Not logged in.'));
69 $user = common_current_user();
71 // ...because they're logged in
73 assert(!empty($user));
75 // It must be a "real" login, not saved cookie login
77 if (!common_is_real_login()) {
78 // Cookie theft is too easy; we require automatic
79 // logins to re-authenticate before admining the site
80 common_set_returnto($this->selfUrl());
81 if (Event::handle('RedirectToLogin', array($this, $user))) {
82 common_redirect(common_local_url('login'), 303);
86 // User must have the right to review flags
88 if (!$user->hasRight(UserFlagPlugin::REVIEWFLAGS)) {
89 $this->clientError(_('You cannot review profile flags.'));
93 $page = $this->int('page');
107 * @param array $args $_REQUEST args; handled in prepare()
112 function handle($args)
114 parent::handle($args);
120 return _('Flagged profiles');
124 * save the profile flag
129 function showContent()
131 $profile = $this->getProfiles();
133 $pl = new FlaggedProfileList($profile, $this);
138 function getProfiles()
140 $ufp = new User_flag_profile();
143 $ufp->selectAdd('profile_id');
144 $ufp->selectAdd('count(*) as flag_count');
146 $ufp->whereAdd('cleared is NULL');
148 $ufp->groupBy('profile_id');
149 $ufp->orderBy('flag_count DESC');
154 while ($ufp->fetch()) {
155 $profile = Profile::staticGet('id', $ufp->profile_id);
156 if (!empty($profile)) {
157 $profiles[] = $profile;
164 return new ArrayWrapper($profiles);
168 class FlaggedProfileList extends ProfileList {
170 function newListItem($profile)
172 return new FlaggedProfileListItem($this->profile, $this->action);
176 class FlaggedProfileListItem extends ProfileListItem
181 function showActions()
183 $this->user = common_current_user();
185 list($action, $this->r2args) = $this->out->returnToArgs();
187 $this->r2args['action'] = $action;
189 $this->startActions();
190 if (Event::handle('StartProfileListItemActionElements', array($this))) {
191 $this->out->elementStart('li', 'entity_moderation');
192 $this->out->element('p', null, _('Moderate'));
193 $this->out->elementStart('ul');
194 $this->showSandboxButton();
195 $this->showSilenceButton();
196 $this->showDeleteButton();
197 $this->showClearButton();
198 $this->out->elementEnd('ul');
199 $this->out->elementEnd('li');
200 Event::handle('EndProfileListItemActionElements', array($this));
205 function showSandboxButton()
207 if ($this->user->hasRight(Right::SANDBOXUSER)) {
208 $this->out->elementStart('li', 'entity_sandbox');
209 if ($this->profile->isSandboxed()) {
210 $usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
213 $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
216 $this->out->elementEnd('li');
220 function showSilenceButton()
222 if ($this->user->hasRight(Right::SILENCEUSER)) {
223 $this->out->elementStart('li', 'entity_silence');
224 if ($this->profile->isSilenced()) {
225 $usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
228 $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
231 $this->out->elementEnd('li');
235 function showDeleteButton()
238 if ($this->user->hasRight(Right::DELETEUSER)) {
239 $this->out->elementStart('li', 'entity_delete');
240 $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
242 $this->out->elementEnd('li');
246 function showClearButton()