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
185 const MAX_FLAGGERS = 5;
190 function showActions()
192 $this->user = common_current_user();
194 list($action, $this->r2args) = $this->out->returnToArgs();
196 $this->r2args['action'] = $action;
198 $this->startActions();
199 if (Event::handle('StartProfileListItemActionElements', array($this))) {
200 $this->out->elementStart('li', 'entity_moderation');
201 $this->out->element('p', null, _('Moderate'));
202 $this->out->elementStart('ul');
203 $this->showSandboxButton();
204 $this->showSilenceButton();
205 $this->showDeleteButton();
206 $this->showClearButton();
207 $this->out->elementEnd('ul');
208 $this->out->elementEnd('li');
209 Event::handle('EndProfileListItemActionElements', array($this));
214 function showSandboxButton()
216 if ($this->user->hasRight(Right::SANDBOXUSER)) {
217 $this->out->elementStart('li', 'entity_sandbox');
218 if ($this->profile->isSandboxed()) {
219 $usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
222 $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
225 $this->out->elementEnd('li');
229 function showSilenceButton()
231 if ($this->user->hasRight(Right::SILENCEUSER)) {
232 $this->out->elementStart('li', 'entity_silence');
233 if ($this->profile->isSilenced()) {
234 $usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
237 $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
240 $this->out->elementEnd('li');
244 function showDeleteButton()
247 if ($this->user->hasRight(Right::DELETEUSER)) {
248 $this->out->elementStart('li', 'entity_delete');
249 $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
251 $this->out->elementEnd('li');
255 function showClearButton()
257 if ($this->user->hasRight(UserFlagPlugin::CLEARFLAGS)) {
258 $this->out->elementStart('li', 'entity_clear');
259 $cf = new ClearFlagForm($this->out, $this->profile, $this->r2args);
261 $this->out->elementEnd('li');
265 function endProfile()
267 $this->showFlaggersList();
268 parent::endProfile();
271 function showFlaggersList()
275 $ufp = new User_flag_profile();
278 $ufp->selectAdd('user_id');
279 $ufp->profile_id = $this->profile->id;
280 $ufp->orderBy('created');
282 if ($ufp->find()) { // XXX: this should always happen
283 while ($ufp->fetch()) {
284 $user = User::staticGet('id', $ufp->user_id);
285 if (!empty($user)) { // XXX: this would also be unusual
286 $flaggers[] = clone($user);
291 $cnt = count($flaggers);
294 if ($cnt > self::MAX_FLAGGERS) {
295 $flaggers = array_slice($flaggers, 0, self::MAX_FLAGGERS);
296 $others = $cnt - self::MAX_FLAGGERS;
301 foreach ($flaggers as $flagger) {
303 $url = common_local_url('showstream',
304 array('nickname' => $flagger->nickname));
306 $lnks[] = XMLStringer::estring('a', array('href' => $url,
307 'class' => 'flagger'),
312 $text = _('Flagged by ');
313 $text .= implode(', ', $lnks);
315 $text .= sprintf(_(' and %d others'), $others);
318 $this->out->elementStart('p', array('class' => 'flaggers'));
319 $this->out->raw($text);
320 $this->out->elementEnd('p');