]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/adminprofileflag.php
use return-to method for adminprofileflag
[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     /**
47      * Take arguments for running
48      *
49      * @param array $args $_REQUEST args
50      *
51      * @return boolean success flag
52      */
53
54     function prepare($args)
55     {
56         parent::prepare($args);
57
58         return true;
59     }
60
61     /**
62      * Handle request
63      *
64      * @param array $args $_REQUEST args; handled in prepare()
65      *
66      * @return void
67      */
68
69     function handle($args)
70     {
71         parent::handle($args);
72
73         $this->showPage();
74     }
75
76     function title() {
77         return _('Flagged profiles');
78     }
79
80     /**
81      * save the profile flag
82      *
83      * @return void
84      */
85
86     function showContent()
87     {
88         $profile = $this->getProfiles();
89
90         $pl = new FlaggedProfileList($profile, $this);
91
92         $pl->show();
93     }
94
95     function getProfiles()
96     {
97         $ufp = new User_flag_profile();
98
99         $ufp->selectAdd();
100         $ufp->selectAdd('profile_id');
101         $ufp->selectAdd('count(*) as flag_count');
102
103         $ufp->whereAdd('cleared is NULL');
104
105         $ufp->groupBy('profile_id');
106         $ufp->orderBy('flag_count DESC');
107
108         $profiles = array();
109
110         if ($ufp->find()) {
111             while ($ufp->fetch()) {
112                 $profile = Profile::staticGet('id', $ufp->profile_id);
113                 if (!empty($profile)) {
114                     $profiles[] = $profile;
115                 }
116             }
117         }
118
119         $ufp->free();
120
121         return new ArrayWrapper($profiles);
122     }
123 }
124
125 class FlaggedProfileList extends ProfileList {
126
127     function newListItem($profile)
128     {
129         return new FlaggedProfileListItem($this->profile, $this->action);
130     }
131 }
132
133 class FlaggedProfileListItem extends ProfileListItem
134 {
135     var $user = null;
136     var $r2args = null;
137
138     function showActions()
139     {
140         $this->user = common_current_user();
141
142         list($action, $this->r2args) = $this->out->returnToArgs();
143
144         $this->r2args['action'] = $action;
145
146         $this->startActions();
147         if (Event::handle('StartProfileListItemActionElements', array($this))) {
148             $this->showSandboxButton();
149             $this->showSilenceButton();
150             $this->showDeleteButton();
151             $this->showClearButton();
152             Event::handle('EndProfileListItemActionElements', array($this));
153         }
154         $this->endActions();
155     }
156
157     function showSandboxButton()
158     {
159         if ($this->user->hasRight(Right::SANDBOXUSER)) {
160             $this->out->elementStart('li', 'entity_sandbox');
161             if ($this->profile->isSandboxed()) {
162                 $usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
163                 $usf->show();
164             } else {
165                 $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
166                 $sf->show();
167             }
168             $this->out->elementEnd('li');
169         }
170     }
171
172     function showSilenceButton()
173     {
174         if ($this->user->hasRight(Right::SILENCEUSER)) {
175             $this->out->elementStart('li', 'entity_silence');
176             if ($this->profile->isSilenced()) {
177                 $usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
178                 $usf->show();
179             } else {
180                 $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
181                 $sf->show();
182             }
183             $this->out->elementEnd('li');
184         }
185     }
186
187     function showDeleteButton()
188     {
189
190         if ($this->user->hasRight(Right::DELETEUSER)) {
191             $this->out->elementStart('li', 'entity_delete');
192             $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
193             $df->show();
194             $this->out->elementEnd('li');
195         }
196     }
197
198     function showClearButton()
199     {
200     }
201 }