]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/UserFlag/adminprofileflag.php
start showing actions for flagged profiles
[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
137     function showActions()
138     {
139         $this->user = common_current_user();
140
141         $this->startActions();
142         if (Event::handle('StartProfileListItemActionElements', array($this))) {
143             $this->showSandboxButton();
144             $this->showSilenceButton();
145             $this->showDeleteButton();
146             $this->showClearButton();
147             Event::handle('EndProfileListItemActionElements', array($this));
148         }
149         $this->endActions();
150     }
151
152     function showSandboxButton()
153     {
154         if ($this->user->hasRight(Right::SANDBOXUSER)) {
155             $this->out->elementStart('li', 'entity_sandbox');
156             if ($this->user->isSandboxed()) {
157                 $usf = new UnSandboxForm($this->out, $this->profile);
158                 $usf->show();
159             } else {
160                 $sf = new SandboxForm($this->out, $this->profile);
161                 $sf->show();
162             }
163             $this->out->elementEnd('li');
164         }
165     }
166
167     function showSilenceButton()
168     {
169         if ($this->user->hasRight(Right::SILENCEUSER)) {
170             $this->out->elementStart('li', 'entity_silence');
171             if ($this->user->isSilenced()) {
172                 $usf = new UnSilenceForm($this->out, $this->profile);
173                 $usf->show();
174             } else {
175                 $sf = new SilenceForm($this->out, $this->profile);
176                 $sf->show();
177             }
178             $this->out->elementEnd('li');
179         }
180     }
181
182     function showDeleteButton()
183     {
184
185         if ($this->user->hasRight(Right::DELETEUSER)) {
186             $this->out->elementStart('li', 'entity_delete');
187             $df = new DeleteUserForm($this->out, $this->profile);
188             $df->show();
189             $this->out->elementEnd('li');
190         }
191     }
192
193     function showClearButton()
194     {
195     }
196 }