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);
123 * @return string Title of the page
128 return _('Flagged profiles');
132 * save the profile flag
137 function showContent()
139 $pl = new FlaggedProfileList($this->profiles, $this);
143 $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
144 $this->page, 'adminprofileflag');
148 * Retrieve this action's profiles
150 * @return Profile $profile Profile query results
153 function getProfiles()
155 $ufp = new User_flag_profile();
158 $ufp->selectAdd('profile_id');
159 $ufp->selectAdd('count(*) as flag_count');
161 $ufp->whereAdd('cleared is NULL');
163 $ufp->groupBy('profile_id');
164 $ufp->orderBy('flag_count DESC, profile_id DESC');
166 $offset = ($this->page-1) * PROFILES_PER_PAGE;
167 $limit = PROFILES_PER_PAGE + 1;
169 $ufp->limit($offset, $limit);
174 while ($ufp->fetch()) {
175 $profile = Profile::staticGet('id', $ufp->profile_id);
176 if (!empty($profile)) {
177 $profiles[] = $profile;
184 return new ArrayWrapper($profiles);
189 * Specialization of ProfileList to show flagging information
191 * Most of the hard part is done in FlaggedProfileListItem.
195 * @author Evan Prodromou <evan@status.net>
196 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
197 * @link http://status.net/
200 class FlaggedProfileList extends ProfileList
203 * Factory method for creating new list items
205 * @param Profile $profile Profile to create an item for
207 * @return ProfileListItem newly-created item
210 function newListItem($profile)
212 return new FlaggedProfileListItem($this->profile, $this->action);
217 * Specialization of ProfileListItem to show flagging information
221 * @author Evan Prodromou <evan@status.net>
222 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
223 * @link http://status.net/
226 class FlaggedProfileListItem extends ProfileListItem
228 const MAX_FLAGGERS = 5;
234 * Overload parent's action list with our own moderation-oriented buttons
239 function showActions()
241 $this->user = common_current_user();
243 list($action, $this->r2args) = $this->out->returnToArgs();
245 $this->r2args['action'] = $action;
247 $this->startActions();
248 if (Event::handle('StartProfileListItemActionElements', array($this))) {
249 $this->out->elementStart('li', 'entity_moderation');
250 $this->out->element('p', null, _('Moderate'));
251 $this->out->elementStart('ul');
252 $this->showSandboxButton();
253 $this->showSilenceButton();
254 $this->showDeleteButton();
255 $this->showClearButton();
256 $this->out->elementEnd('ul');
257 $this->out->elementEnd('li');
258 Event::handle('EndProfileListItemActionElements', array($this));
264 * Show a button to sandbox the profile
269 function showSandboxButton()
271 if ($this->user->hasRight(Right::SANDBOXUSER)) {
272 $this->out->elementStart('li', 'entity_sandbox');
273 if ($this->profile->isSandboxed()) {
274 $usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
277 $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
280 $this->out->elementEnd('li');
285 * Show a button to silence the profile
290 function showSilenceButton()
292 if ($this->user->hasRight(Right::SILENCEUSER)) {
293 $this->out->elementStart('li', 'entity_silence');
294 if ($this->profile->isSilenced()) {
295 $usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
298 $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
301 $this->out->elementEnd('li');
306 * Show a button to delete user and profile
311 function showDeleteButton()
314 if ($this->user->hasRight(Right::DELETEUSER)) {
315 $this->out->elementStart('li', 'entity_delete');
316 $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
318 $this->out->elementEnd('li');
323 * Show a button to clear flags
328 function showClearButton()
330 if ($this->user->hasRight(UserFlagPlugin::CLEARFLAGS)) {
331 $this->out->elementStart('li', 'entity_clear');
332 $cf = new ClearFlagForm($this->out, $this->profile, $this->r2args);
334 $this->out->elementEnd('li');
339 * Overload parent function to add flaggers list
344 function endProfile()
346 $this->showFlaggersList();
347 parent::endProfile();
351 * Show a list of people who've flagged this profile
356 function showFlaggersList()
360 $ufp = new User_flag_profile();
363 $ufp->selectAdd('user_id');
364 $ufp->profile_id = $this->profile->id;
365 $ufp->orderBy('created');
367 if ($ufp->find()) { // XXX: this should always happen
368 while ($ufp->fetch()) {
369 $user = User::staticGet('id', $ufp->user_id);
370 if (!empty($user)) { // XXX: this would also be unusual
371 $flaggers[] = clone($user);
376 $cnt = count($flaggers);
379 if ($cnt > self::MAX_FLAGGERS) {
380 $flaggers = array_slice($flaggers, 0, self::MAX_FLAGGERS);
381 $others = $cnt - self::MAX_FLAGGERS;
386 foreach ($flaggers as $flagger) {
388 $url = common_local_url('showstream',
389 array('nickname' => $flagger->nickname));
391 $lnks[] = XMLStringer::estring('a', array('href' => $url,
392 'class' => 'flagger'),
397 $text = _('Flagged by ');
399 $text .= implode(', ', $lnks);
402 $text .= sprintf(_(' and %d others'), $others);
405 $this->out->elementStart('p', array('class' => 'flaggers'));
406 $this->out->raw($text);
407 $this->out->elementEnd('p');