123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class AdminprofileflagAction extends Action
- {
- var $page = null;
- var $profiles = null;
-
- function prepare($args)
- {
- parent::prepare($args);
- $user = common_current_user();
-
- if (!common_logged_in()) {
-
- $this->clientError(_m('Not logged in.'));
- }
- $user = common_current_user();
-
- assert(!empty($user));
-
- if (!common_is_real_login()) {
-
-
- common_set_returnto($this->selfUrl());
- if (Event::handle('RedirectToLogin', array($this, $user))) {
- common_redirect(common_local_url('login'), 303);
- }
- }
-
- if (!$user->hasRight(UserFlagPlugin::REVIEWFLAGS)) {
-
- $this->clientError(_m('You cannot review profile flags.'));
- }
- $this->page = $this->trimmed('page');
- if (empty($this->page)) {
- $this->page = 1;
- }
- $this->profiles = $this->getProfiles();
- return true;
- }
-
- function handle($args)
- {
- parent::handle($args);
- $this->showPage();
- }
-
- function title()
- {
-
- return _m('Flagged profiles');
- }
-
- function showContent()
- {
- $pl = new FlaggedProfileList($this->profiles, $this);
- $cnt = $pl->show();
- $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
- $this->page, 'adminprofileflag');
- }
-
- function getProfiles()
- {
- $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');
- $ufp->orderBy('flag_count DESC, profile_id DESC');
- $offset = ($this->page-1) * PROFILES_PER_PAGE;
- $limit = PROFILES_PER_PAGE + 1;
- $ufp->limit($offset, $limit);
- $profiles = array();
- if ($ufp->find()) {
- while ($ufp->fetch()) {
- $profile = Profile::getKV('id', $ufp->profile_id);
- if (!empty($profile)) {
- $profiles[] = $profile;
- }
- }
- }
- $ufp->free();
- return new ArrayWrapper($profiles);
- }
- }
- class FlaggedProfileList extends ProfileList
- {
-
- function newListItem($profile)
- {
- return new FlaggedProfileListItem($this->profile, $this->action);
- }
- }
- class FlaggedProfileListItem extends ProfileListItem
- {
- const MAX_FLAGGERS = 5;
- var $user = null;
- var $r2args = null;
-
- function showActions()
- {
- $this->user = common_current_user();
- list($action, $this->r2args) = $this->out->returnToArgs();
- $this->r2args['action'] = $action;
- $this->startActions();
- if (Event::handle('StartProfileListItemActionElements', array($this))) {
- $this->out->elementStart('li', 'entity_moderation');
-
- $this->out->element('p', null, _m('Moderate'));
- $this->out->elementStart('ul');
- $this->showSandboxButton();
- $this->showSilenceButton();
- $this->showDeleteButton();
- $this->showClearButton();
- $this->out->elementEnd('ul');
- $this->out->elementEnd('li');
- Event::handle('EndProfileListItemActionElements', array($this));
- }
- $this->endActions();
- }
-
- function showSandboxButton()
- {
- if ($this->user->hasRight(Right::SANDBOXUSER)) {
- $this->out->elementStart('li', 'entity_sandbox');
- if ($this->profile->isSandboxed()) {
- $usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
- $usf->show();
- } else {
- $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
- $sf->show();
- }
- $this->out->elementEnd('li');
- }
- }
-
- function showSilenceButton()
- {
- if ($this->user->hasRight(Right::SILENCEUSER)) {
- $this->out->elementStart('li', 'entity_silence');
- if ($this->profile->isSilenced()) {
- $usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
- $usf->show();
- } else {
- $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
- $sf->show();
- }
- $this->out->elementEnd('li');
- }
- }
-
- function showDeleteButton()
- {
- if ($this->user->hasRight(Right::DELETEUSER)) {
- $this->out->elementStart('li', 'entity_delete');
- $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
- $df->show();
- $this->out->elementEnd('li');
- }
- }
-
- function showClearButton()
- {
- 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');
- }
- }
-
- function endProfile()
- {
- $this->showFlaggersList();
- parent::endProfile();
- }
-
- function showFlaggersList()
- {
- $flaggers = array();
- $ufp = new User_flag_profile();
- $ufp->selectAdd();
- $ufp->selectAdd('user_id');
- $ufp->profile_id = $this->profile->id;
- $ufp->orderBy('created');
- if ($ufp->find()) {
- while ($ufp->fetch()) {
- $user = User::getKV('id', $ufp->user_id);
- if (!empty($user)) {
- $flaggers[] = clone($user);
- }
- }
- }
- $cnt = count($flaggers);
- $others = 0;
- if ($cnt > self::MAX_FLAGGERS) {
- $flaggers = array_slice($flaggers, 0, self::MAX_FLAGGERS);
- $others = $cnt - self::MAX_FLAGGERS;
- }
- $lnks = array();
- foreach ($flaggers as $flagger) {
- $url = common_local_url('showstream',
- array('nickname' => $flagger->nickname));
- $lnks[] = XMLStringer::estring('a', array('href' => $url,
- 'class' => 'flagger'),
- $flagger->nickname);
- }
- if ($cnt > 0) {
- if ($others > 0) {
- $flagging_users = implode(', ', $lnks);
-
-
-
- $text .= sprintf(_m('Flagged by %1$s and %2$d other', 'Flagged by %1$s and %2$d others', $others), $flagging_users, $others);
- } else {
-
-
- $text .= sprintf(_m('Flagged by %s'), $flagging_users);
- }
- $this->out->elementStart('p', array('class' => 'flaggers'));
- $this->out->raw($text);
- $this->out->elementEnd('p');
- }
- }
- }
|