2009-10-15 17:47:11 +09:00
|
|
|
<?php
|
2020-09-15 22:59:27 +09:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-10-15 17:47:11 +09:00
|
|
|
/**
|
|
|
|
* Show latest and greatest profile flags
|
|
|
|
*
|
2020-09-15 22:59:27 +09:00
|
|
|
* @category Action
|
|
|
|
* @package GNUsocial
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2009 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
2009-10-15 17:47:11 +09:00
|
|
|
*/
|
2020-09-15 22:59:27 +09:00
|
|
|
|
|
|
|
defined('GNUSOCIAL') || die();
|
2009-10-15 17:47:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the latest and greatest profile flags
|
|
|
|
*
|
2020-09-15 22:59:27 +09:00
|
|
|
* @category Action
|
|
|
|
* @package GNUsocial
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2009 StatusNet, Inc.
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2009-10-15 17:47:11 +09:00
|
|
|
*/
|
|
|
|
class AdminprofileflagAction extends Action
|
|
|
|
{
|
2020-07-21 20:43:46 +09:00
|
|
|
public $page;
|
|
|
|
public $profiles;
|
2009-12-28 04:04:53 +09:00
|
|
|
|
2009-10-15 17:47:11 +09:00
|
|
|
/**
|
|
|
|
* Take arguments for running
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST args
|
|
|
|
*
|
2020-07-21 20:43:46 +09:00
|
|
|
* @return bool success flag
|
2009-10-15 17:47:11 +09:00
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function prepare(array $args = [])
|
2009-10-15 17:47:11 +09:00
|
|
|
{
|
2009-11-17 01:43:15 +09:00
|
|
|
parent::prepare($args);
|
|
|
|
|
2009-12-28 04:04:53 +09:00
|
|
|
$user = common_current_user();
|
|
|
|
|
|
|
|
// User must be logged in.
|
|
|
|
|
|
|
|
if (!common_logged_in()) {
|
2011-04-04 07:41:21 +09:00
|
|
|
// TRANS: Error message displayed when trying to perform an action that requires a logged in user.
|
2011-03-31 05:30:23 +09:00
|
|
|
$this->clientError(_m('Not logged in.'));
|
2009-12-28 04:04:53 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
$user = common_current_user();
|
|
|
|
|
|
|
|
// ...because they're logged in
|
|
|
|
|
|
|
|
assert(!empty($user));
|
|
|
|
|
|
|
|
// It must be a "real" login, not saved cookie login
|
|
|
|
|
|
|
|
if (!common_is_real_login()) {
|
|
|
|
// Cookie theft is too easy; we require automatic
|
|
|
|
// logins to re-authenticate before admining the site
|
|
|
|
common_set_returnto($this->selfUrl());
|
2020-07-21 20:43:46 +09:00
|
|
|
if (Event::handle('RedirectToLogin', [$this, $user])) {
|
2009-12-28 04:04:53 +09:00
|
|
|
common_redirect(common_local_url('login'), 303);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// User must have the right to review flags
|
|
|
|
|
|
|
|
if (!$user->hasRight(UserFlagPlugin::REVIEWFLAGS)) {
|
2011-06-17 23:19:18 +09:00
|
|
|
// TRANS: Error message displayed when trying to review profile flags while not authorised.
|
2011-03-31 05:30:23 +09:00
|
|
|
$this->clientError(_m('You cannot review profile flags.'));
|
2009-12-28 04:04:53 +09:00
|
|
|
}
|
|
|
|
|
2009-12-28 04:47:54 +09:00
|
|
|
$this->page = $this->trimmed('page');
|
2009-12-28 04:04:53 +09:00
|
|
|
|
2009-12-28 04:47:54 +09:00
|
|
|
if (empty($this->page)) {
|
2009-12-28 04:04:53 +09:00
|
|
|
$this->page = 1;
|
|
|
|
}
|
|
|
|
|
2009-12-28 04:47:54 +09:00
|
|
|
$this->profiles = $this->getProfiles();
|
|
|
|
|
2009-10-15 17:47:11 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST args; handled in prepare()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function handle()
|
2009-10-15 17:47:11 +09:00
|
|
|
{
|
2016-06-01 11:05:11 +09:00
|
|
|
parent::handle();
|
2009-10-15 17:47:11 +09:00
|
|
|
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
/**
|
|
|
|
* Title of this page
|
|
|
|
*
|
|
|
|
* @return string Title of the page
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function title()
|
2009-12-29 01:45:21 +09:00
|
|
|
{
|
2010-10-03 05:25:32 +09:00
|
|
|
// TRANS: Title for page with a list of profiles that were flagged for review.
|
|
|
|
return _m('Flagged profiles');
|
2009-10-15 17:47:11 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* save the profile flag
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function showContent()
|
2009-10-15 17:47:11 +09:00
|
|
|
{
|
2009-12-28 04:47:54 +09:00
|
|
|
$pl = new FlaggedProfileList($this->profiles, $this);
|
2009-11-17 01:43:15 +09:00
|
|
|
|
2009-12-28 04:47:54 +09:00
|
|
|
$cnt = $pl->show();
|
2009-11-17 01:43:15 +09:00
|
|
|
|
2020-09-15 22:59:27 +09:00
|
|
|
$this->pagination(
|
|
|
|
$this->page > 1,
|
|
|
|
$cnt > PROFILES_PER_PAGE,
|
|
|
|
$this->page,
|
|
|
|
'adminprofileflag'
|
|
|
|
);
|
2009-11-17 01:43:15 +09:00
|
|
|
}
|
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
/**
|
|
|
|
* Retrieve this action's profiles
|
|
|
|
*
|
|
|
|
* @return Profile $profile Profile query results
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function getProfiles()
|
2009-11-17 01:43:15 +09:00
|
|
|
{
|
|
|
|
$ufp = new User_flag_profile();
|
|
|
|
|
|
|
|
$ufp->selectAdd();
|
|
|
|
$ufp->selectAdd('profile_id');
|
|
|
|
$ufp->selectAdd('count(*) as flag_count');
|
|
|
|
|
|
|
|
$ufp->whereAdd('cleared is NULL');
|
|
|
|
|
|
|
|
$ufp->groupBy('profile_id');
|
2009-12-28 04:47:54 +09:00
|
|
|
$ufp->orderBy('flag_count DESC, profile_id DESC');
|
|
|
|
|
2020-07-21 20:43:46 +09:00
|
|
|
$offset = ($this->page - 1) * PROFILES_PER_PAGE;
|
2009-12-29 01:45:21 +09:00
|
|
|
$limit = PROFILES_PER_PAGE + 1;
|
2009-12-28 04:47:54 +09:00
|
|
|
|
|
|
|
$ufp->limit($offset, $limit);
|
2009-11-17 01:43:15 +09:00
|
|
|
|
2020-07-21 20:43:46 +09:00
|
|
|
$profiles = [];
|
2009-11-17 01:43:15 +09:00
|
|
|
|
|
|
|
if ($ufp->find()) {
|
|
|
|
while ($ufp->fetch()) {
|
2013-08-18 20:04:58 +09:00
|
|
|
$profile = Profile::getKV('id', $ufp->profile_id);
|
2009-11-17 01:43:15 +09:00
|
|
|
if (!empty($profile)) {
|
|
|
|
$profiles[] = $profile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$ufp->free();
|
|
|
|
|
|
|
|
return new ArrayWrapper($profiles);
|
2009-10-15 17:47:11 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
/**
|
|
|
|
* Specialization of ProfileList to show flagging information
|
|
|
|
*
|
|
|
|
* Most of the hard part is done in FlaggedProfileListItem.
|
|
|
|
*
|
2020-09-15 22:59:27 +09:00
|
|
|
* @category Widget
|
|
|
|
* @package GNUsocial
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2009 StatusNet, Inc.
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2009-12-29 01:45:21 +09:00
|
|
|
*/
|
|
|
|
class FlaggedProfileList extends ProfileList
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Factory method for creating new list items
|
|
|
|
*
|
|
|
|
* @param Profile $profile Profile to create an item for
|
|
|
|
*
|
|
|
|
* @return ProfileListItem newly-created item
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function newListItem(Profile $profile)
|
2009-11-17 01:43:15 +09:00
|
|
|
{
|
2018-08-17 08:16:15 +09:00
|
|
|
return new FlaggedProfileListItem($profile, $this->action);
|
2009-11-17 01:43:15 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
/**
|
|
|
|
* Specialization of ProfileListItem to show flagging information
|
|
|
|
*
|
2020-09-15 22:59:27 +09:00
|
|
|
* @category Widget
|
|
|
|
* @package GNUsocial
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2009 StatusNet, Inc.
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2009-12-29 01:45:21 +09:00
|
|
|
*/
|
2009-11-17 01:43:15 +09:00
|
|
|
class FlaggedProfileListItem extends ProfileListItem
|
|
|
|
{
|
2009-12-29 01:19:56 +09:00
|
|
|
const MAX_FLAGGERS = 5;
|
|
|
|
|
2020-07-21 20:43:46 +09:00
|
|
|
public $user;
|
|
|
|
public $r2args;
|
2009-11-17 01:43:15 +09:00
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
/**
|
|
|
|
* Overload parent's action list with our own moderation-oriented buttons
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function showActions()
|
2009-11-17 01:43:15 +09:00
|
|
|
{
|
|
|
|
$this->user = common_current_user();
|
|
|
|
|
2009-11-17 01:55:00 +09:00
|
|
|
list($action, $this->r2args) = $this->out->returnToArgs();
|
|
|
|
|
|
|
|
$this->r2args['action'] = $action;
|
|
|
|
|
2009-11-17 01:43:15 +09:00
|
|
|
$this->startActions();
|
2020-07-21 20:43:46 +09:00
|
|
|
if (Event::handle('StartProfileListItemActionElements', [$this])) {
|
2009-11-27 03:46:11 +09:00
|
|
|
$this->out->elementStart('li', 'entity_moderation');
|
2010-10-03 05:25:32 +09:00
|
|
|
// TRANS: Header for moderation menu with action buttons for flagged profiles (like 'sandbox', 'silence', ...).
|
|
|
|
$this->out->element('p', null, _m('Moderate'));
|
2009-11-27 03:46:11 +09:00
|
|
|
$this->out->elementStart('ul');
|
2009-11-17 01:43:15 +09:00
|
|
|
$this->showSandboxButton();
|
|
|
|
$this->showSilenceButton();
|
|
|
|
$this->showDeleteButton();
|
|
|
|
$this->showClearButton();
|
2009-11-27 03:46:11 +09:00
|
|
|
$this->out->elementEnd('ul');
|
|
|
|
$this->out->elementEnd('li');
|
2020-07-21 20:43:46 +09:00
|
|
|
Event::handle('EndProfileListItemActionElements', [$this]);
|
2009-11-17 01:43:15 +09:00
|
|
|
}
|
|
|
|
$this->endActions();
|
|
|
|
}
|
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
/**
|
|
|
|
* Show a button to sandbox the profile
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function showSandboxButton()
|
2009-11-17 01:43:15 +09:00
|
|
|
{
|
|
|
|
if ($this->user->hasRight(Right::SANDBOXUSER)) {
|
|
|
|
$this->out->elementStart('li', 'entity_sandbox');
|
2009-11-17 01:55:00 +09:00
|
|
|
if ($this->profile->isSandboxed()) {
|
|
|
|
$usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
|
2009-11-17 01:43:15 +09:00
|
|
|
$usf->show();
|
|
|
|
} else {
|
2009-11-17 01:55:00 +09:00
|
|
|
$sf = new SandboxForm($this->out, $this->profile, $this->r2args);
|
2009-11-17 01:43:15 +09:00
|
|
|
$sf->show();
|
|
|
|
}
|
|
|
|
$this->out->elementEnd('li');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
/**
|
|
|
|
* Show a button to silence the profile
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function showSilenceButton()
|
2009-11-17 01:43:15 +09:00
|
|
|
{
|
|
|
|
if ($this->user->hasRight(Right::SILENCEUSER)) {
|
|
|
|
$this->out->elementStart('li', 'entity_silence');
|
2009-11-17 01:55:00 +09:00
|
|
|
if ($this->profile->isSilenced()) {
|
|
|
|
$usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
|
2009-11-17 01:43:15 +09:00
|
|
|
$usf->show();
|
|
|
|
} else {
|
2009-11-17 01:55:00 +09:00
|
|
|
$sf = new SilenceForm($this->out, $this->profile, $this->r2args);
|
2009-11-17 01:43:15 +09:00
|
|
|
$sf->show();
|
|
|
|
}
|
|
|
|
$this->out->elementEnd('li');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
/**
|
|
|
|
* Show a button to delete user and profile
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function showDeleteButton()
|
2009-11-17 01:43:15 +09:00
|
|
|
{
|
|
|
|
if ($this->user->hasRight(Right::DELETEUSER)) {
|
|
|
|
$this->out->elementStart('li', 'entity_delete');
|
2009-11-17 01:55:00 +09:00
|
|
|
$df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
|
2009-11-17 01:43:15 +09:00
|
|
|
$df->show();
|
|
|
|
$this->out->elementEnd('li');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
/**
|
|
|
|
* Show a button to clear flags
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function showClearButton()
|
2009-11-17 01:43:15 +09:00
|
|
|
{
|
2009-12-29 01:19:56 +09:00
|
|
|
if ($this->user->hasRight(UserFlagPlugin::CLEARFLAGS)) {
|
|
|
|
$this->out->elementStart('li', 'entity_clear');
|
|
|
|
$cf = new ClearFlagForm($this->out, $this->profile, $this->r2args);
|
|
|
|
$cf->show();
|
|
|
|
$this->out->elementEnd('li');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
/**
|
|
|
|
* Overload parent function to add flaggers list
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function endProfile()
|
2009-12-29 01:19:56 +09:00
|
|
|
{
|
|
|
|
$this->showFlaggersList();
|
|
|
|
parent::endProfile();
|
|
|
|
}
|
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
/**
|
|
|
|
* Show a list of people who've flagged this profile
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-07-21 20:43:46 +09:00
|
|
|
public function showFlaggersList()
|
2009-12-29 01:19:56 +09:00
|
|
|
{
|
2020-07-21 20:43:46 +09:00
|
|
|
$flaggers = [];
|
2009-12-29 01:19:56 +09:00
|
|
|
|
|
|
|
$ufp = new User_flag_profile();
|
|
|
|
|
|
|
|
$ufp->selectAdd();
|
|
|
|
$ufp->selectAdd('user_id');
|
|
|
|
$ufp->profile_id = $this->profile->id;
|
2020-09-15 22:59:27 +09:00
|
|
|
$ufp->orderBy('created, user_id');
|
2009-12-29 01:19:56 +09:00
|
|
|
|
|
|
|
if ($ufp->find()) { // XXX: this should always happen
|
|
|
|
while ($ufp->fetch()) {
|
2013-08-18 20:04:58 +09:00
|
|
|
$user = User::getKV('id', $ufp->user_id);
|
2009-12-29 01:19:56 +09:00
|
|
|
if (!empty($user)) { // XXX: this would also be unusual
|
2020-07-21 20:43:46 +09:00
|
|
|
$flaggers[] = clone $user;
|
2009-12-29 01:19:56 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-29 01:45:21 +09:00
|
|
|
$cnt = count($flaggers);
|
2009-12-29 01:19:56 +09:00
|
|
|
$others = 0;
|
|
|
|
|
|
|
|
if ($cnt > self::MAX_FLAGGERS) {
|
|
|
|
$flaggers = array_slice($flaggers, 0, self::MAX_FLAGGERS);
|
2009-12-29 01:45:21 +09:00
|
|
|
$others = $cnt - self::MAX_FLAGGERS;
|
2009-12-29 01:19:56 +09:00
|
|
|
}
|
|
|
|
|
2020-07-21 20:43:46 +09:00
|
|
|
$lnks = [];
|
2009-12-29 01:19:56 +09:00
|
|
|
|
|
|
|
foreach ($flaggers as $flagger) {
|
2020-09-15 22:59:27 +09:00
|
|
|
$url = common_local_url(
|
|
|
|
'showstream',
|
|
|
|
['nickname' => $flagger->nickname]
|
|
|
|
);
|
|
|
|
|
|
|
|
$lnks[] = XMLStringer::estring(
|
|
|
|
'a',
|
|
|
|
['href' => $url, 'class' => 'flagger'],
|
|
|
|
$flagger->nickname
|
|
|
|
);
|
2009-12-29 01:19:56 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($cnt > 0) {
|
|
|
|
if ($others > 0) {
|
2010-10-03 05:25:32 +09:00
|
|
|
$flagging_users = implode(', ', $lnks);
|
|
|
|
// TRANS: Message displayed on a profile if it has been flagged.
|
|
|
|
// TRANS: %1$s is a comma separated list of at most 5 user nicknames that flagged.
|
2011-06-17 23:19:18 +09:00
|
|
|
// TRANS: %2$d is a positive integer of additional flagging users. Also used for plural.
|
2010-10-03 05:25:32 +09:00
|
|
|
$text .= sprintf(_m('Flagged by %1$s and %2$d other', 'Flagged by %1$s and %2$d others', $others), $flagging_users, $others);
|
|
|
|
} else {
|
|
|
|
// TRANS: Message displayed on a profile if it has been flagged.
|
|
|
|
// TRANS: %s is a comma separated list of at most 5 user nicknames that flagged.
|
|
|
|
$text .= sprintf(_m('Flagged by %s'), $flagging_users);
|
2009-12-29 01:19:56 +09:00
|
|
|
}
|
|
|
|
|
2020-07-21 20:43:46 +09:00
|
|
|
$this->out->elementStart('p', ['class' => 'flaggers']);
|
2009-12-29 01:19:56 +09:00
|
|
|
$this->out->raw($text);
|
|
|
|
$this->out->elementEnd('p');
|
|
|
|
}
|
2009-11-17 01:43:15 +09:00
|
|
|
}
|
|
|
|
}
|