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
50 * Take arguments for running
52 * @param array $args $_REQUEST args
54 * @return boolean success flag
57 function prepare($args)
59 parent::prepare($args);
61 $user = common_current_user();
63 // User must be logged in.
65 if (!common_logged_in()) {
66 $this->clientError(_('Not logged in.'));
70 $user = common_current_user();
72 // ...because they're logged in
74 assert(!empty($user));
76 // It must be a "real" login, not saved cookie login
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);
87 // User must have the right to review flags
89 if (!$user->hasRight(UserFlagPlugin::REVIEWFLAGS)) {
90 $this->clientError(_('You cannot review profile flags.'));
94 $this->page = $this->trimmed('page');
96 if (empty($this->page)) {
100 $this->profiles = $this->getProfiles();
108 * @param array $args $_REQUEST args; handled in prepare()
113 function handle($args)
115 parent::handle($args);
121 return _('Flagged profiles');
125 * save the profile flag
130 function showContent()
132 $pl = new FlaggedProfileList($this->profiles, $this);
136 $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
137 $this->page, 'adminprofileflag');
140 function getProfiles()
142 $ufp = new User_flag_profile();
145 $ufp->selectAdd('profile_id');
146 $ufp->selectAdd('count(*) as flag_count');
148 $ufp->whereAdd('cleared is NULL');
150 $ufp->groupBy('profile_id');
151 $ufp->orderBy('flag_count DESC, profile_id DESC');
153 $offset = ($this->page-1) * PROFILES_PER_PAGE;
154 $limit = PROFILES_PER_PAGE + 1;
156 $ufp->limit($offset, $limit);
161 while ($ufp->fetch()) {
162 $profile = Profile::staticGet('id', $ufp->profile_id);
163 if (!empty($profile)) {
164 $profiles[] = $profile;
171 return new ArrayWrapper($profiles);
175 class FlaggedProfileList extends ProfileList {
177 function newListItem($profile)
179 return new FlaggedProfileListItem($this->profile, $this->action);
183 class FlaggedProfileListItem extends ProfileListItem
188 function showActions()
190 $this->user = common_current_user();
192 list($action, $this->r2args) = $this->out->returnToArgs();
194 $this->r2args['action'] = $action;
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));
212 function showSandboxButton()
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);
220 $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
223 $this->out->elementEnd('li');
227 function showSilenceButton()
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);
235 $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
238 $this->out->elementEnd('li');
242 function showDeleteButton()
245 if ($this->user->hasRight(Right::DELETEUSER)) {
246 $this->out->elementStart('li', 'entity_delete');
247 $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
249 $this->out->elementEnd('li');
253 function showClearButton()