]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/adminprofileflag.php
5d6acf0863c4cb94ec28575e9afc735b30f95294
[quix0rs-gnu-social.git] / plugins / UserFlag / adminprofileflag.php
1 <?php
2 /**
3  * Show latest and greatest profile flags
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2009, StatusNet, Inc.
15  *
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.
20  *
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.
25  *
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/>.
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Show the latest and greatest profile flags
36  *
37  * @category Action
38  * @package  StatusNet
39  * @author   Evan Prodromou <evan@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41  * @link     http://status.net/
42  */
43
44 class AdminprofileflagAction extends Action
45 {
46     var $page = null;
47
48     /**
49      * Take arguments for running
50      *
51      * @param array $args $_REQUEST args
52      *
53      * @return boolean success flag
54      */
55
56     function prepare($args)
57     {
58         parent::prepare($args);
59
60         $user = common_current_user();
61
62         // User must be logged in.
63
64         if (!common_logged_in()) {
65             $this->clientError(_('Not logged in.'));
66             return;
67         }
68
69         $user = common_current_user();
70
71         // ...because they're logged in
72
73         assert(!empty($user));
74
75         // It must be a "real" login, not saved cookie login
76
77         if (!common_is_real_login()) {
78             // Cookie theft is too easy; we require automatic
79             // logins to re-authenticate before admining the site
80             common_set_returnto($this->selfUrl());
81             if (Event::handle('RedirectToLogin', array($this, $user))) {
82                 common_redirect(common_local_url('login'), 303);
83             }
84         }
85
86         // User must have the right to review flags
87
88         if (!$user->hasRight(UserFlagPlugin::REVIEWFLAGS)) {
89             $this->clientError(_('You cannot review profile flags.'));
90             return false;
91         }
92
93         $page = $this->int('page');
94
95         if (empty($page)) {
96             $this->page = 1;
97         } else {
98             $this->page = $page;
99         }
100
101         return true;
102     }
103
104     /**
105      * Handle request
106      *
107      * @param array $args $_REQUEST args; handled in prepare()
108      *
109      * @return void
110      */
111
112     function handle($args)
113     {
114         parent::handle($args);
115
116         $this->showPage();
117     }
118
119     function title() {
120         return _('Flagged profiles');
121     }
122
123     /**
124      * save the profile flag
125      *
126      * @return void
127      */
128
129     function showContent()
130     {
131         $profile = $this->getProfiles();
132
133         $pl = new FlaggedProfileList($profile, $this);
134
135         $pl->show();
136     }
137
138     function getProfiles()
139     {
140         $ufp = new User_flag_profile();
141
142         $ufp->selectAdd();
143         $ufp->selectAdd('profile_id');
144         $ufp->selectAdd('count(*) as flag_count');
145
146         $ufp->whereAdd('cleared is NULL');
147
148         $ufp->groupBy('profile_id');
149         $ufp->orderBy('flag_count DESC');
150
151         $profiles = array();
152
153         if ($ufp->find()) {
154             while ($ufp->fetch()) {
155                 $profile = Profile::staticGet('id', $ufp->profile_id);
156                 if (!empty($profile)) {
157                     $profiles[] = $profile;
158                 }
159             }
160         }
161
162         $ufp->free();
163
164         return new ArrayWrapper($profiles);
165     }
166 }
167
168 class FlaggedProfileList extends ProfileList {
169
170     function newListItem($profile)
171     {
172         return new FlaggedProfileListItem($this->profile, $this->action);
173     }
174 }
175
176 class FlaggedProfileListItem extends ProfileListItem
177 {
178     var $user = null;
179     var $r2args = null;
180
181     function showActions()
182     {
183         $this->user = common_current_user();
184
185         list($action, $this->r2args) = $this->out->returnToArgs();
186
187         $this->r2args['action'] = $action;
188
189         $this->startActions();
190         if (Event::handle('StartProfileListItemActionElements', array($this))) {
191             $this->out->elementStart('li', 'entity_moderation');
192             $this->out->element('p', null, _('Moderate'));
193             $this->out->elementStart('ul');
194             $this->showSandboxButton();
195             $this->showSilenceButton();
196             $this->showDeleteButton();
197             $this->showClearButton();
198             $this->out->elementEnd('ul');
199             $this->out->elementEnd('li');
200             Event::handle('EndProfileListItemActionElements', array($this));
201         }
202         $this->endActions();
203     }
204
205     function showSandboxButton()
206     {
207         if ($this->user->hasRight(Right::SANDBOXUSER)) {
208             $this->out->elementStart('li', 'entity_sandbox');
209             if ($this->profile->isSandboxed()) {
210                 $usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
211                 $usf->show();
212             } else {
213                 $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
214                 $sf->show();
215             }
216             $this->out->elementEnd('li');
217         }
218     }
219
220     function showSilenceButton()
221     {
222         if ($this->user->hasRight(Right::SILENCEUSER)) {
223             $this->out->elementStart('li', 'entity_silence');
224             if ($this->profile->isSilenced()) {
225                 $usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
226                 $usf->show();
227             } else {
228                 $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
229                 $sf->show();
230             }
231             $this->out->elementEnd('li');
232         }
233     }
234
235     function showDeleteButton()
236     {
237
238         if ($this->user->hasRight(Right::DELETEUSER)) {
239             $this->out->elementStart('li', 'entity_delete');
240             $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
241             $df->show();
242             $this->out->elementEnd('li');
243         }
244     }
245
246     function showClearButton()
247     {
248     }
249 }