]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/blockedfromgroup.php
Merge branch 'blacklistplus' into testing
[quix0rs-gnu-social.git] / actions / blockedfromgroup.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of group members
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Group
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2008-2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * List of profiles blocked from this group
36  *
37  * @category Group
38  * @package  StatusNet
39  * @author   Evan Prodromou <evan@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43
44 class BlockedfromgroupAction extends GroupDesignAction
45 {
46     var $page = null;
47
48     function isReadOnly($args)
49     {
50         return true;
51     }
52
53     function prepare($args)
54     {
55         parent::prepare($args);
56         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
57
58         $nickname_arg = $this->arg('nickname');
59         $nickname = common_canonical_nickname($nickname_arg);
60
61         // Permanent redirect on non-canonical nickname
62
63         if ($nickname_arg != $nickname) {
64             $args = array('nickname' => $nickname);
65             if ($this->page != 1) {
66                 $args['page'] = $this->page;
67             }
68             common_redirect(common_local_url('blockedfromgroup', $args), 301);
69             return false;
70         }
71
72         if (!$nickname) {
73             $this->clientError(_('No nickname.'), 404);
74             return false;
75         }
76
77         $local = Local_group::staticGet('nickname', $nickname);
78
79         if (!$local) {
80             $this->clientError(_('No such group.'), 404);
81             return false;
82         }
83
84         $this->group = User_group::staticGet('id', $local->group_id);
85
86         if (!$this->group) {
87             $this->clientError(_('No such group.'), 404);
88             return false;
89         }
90
91         return true;
92     }
93
94     function title()
95     {
96         if ($this->page == 1) {
97             return sprintf(_('%s blocked profiles'),
98                            $this->group->nickname);
99         } else {
100             return sprintf(_('%1$s blocked profiles, page %2$d'),
101                            $this->group->nickname,
102                            $this->page);
103         }
104     }
105
106     function handle($args)
107     {
108         parent::handle($args);
109         $this->showPage();
110     }
111
112     function showPageNotice()
113     {
114         $this->element('p', 'instructions',
115                        _('A list of the users blocked from joining this group.'));
116     }
117
118     function showLocalNav()
119     {
120         $nav = new GroupNav($this, $this->group);
121         $nav->show();
122     }
123
124     function showContent()
125     {
126         $offset = ($this->page-1) * PROFILES_PER_PAGE;
127         $limit =  PROFILES_PER_PAGE + 1;
128
129         $cnt = 0;
130
131         $blocked = $this->group->getBlocked($offset, $limit);
132
133         if ($blocked) {
134             $blocked_list = new GroupBlockList($blocked, $this->group, $this);
135             $cnt = $blocked_list->show();
136         }
137
138         $blocked->free();
139
140         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
141                           $this->page, 'blockedfromgroup',
142                           array('nickname' => $this->group->nickname));
143     }
144 }
145
146 class GroupBlockList extends ProfileList
147 {
148     var $group = null;
149
150     function __construct($profile, $group, $action)
151     {
152         parent::__construct($profile, $action);
153
154         $this->group = $group;
155     }
156
157     function newListItem($profile)
158     {
159         return new GroupBlockListItem($profile, $this->group, $this->action);
160     }
161 }
162
163 class GroupBlockListItem extends ProfileListItem
164 {
165     var $group = null;
166
167     function __construct($profile, $group, $action)
168     {
169         parent::__construct($profile, $action);
170
171         $this->group = $group;
172     }
173
174     function showActions()
175     {
176         $this->startActions();
177         $this->showGroupUnblockForm();
178         $this->endActions();
179     }
180
181     function showGroupUnblockForm()
182     {
183         $user = common_current_user();
184
185         if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
186             $this->out->elementStart('li', 'entity_block');
187             $bf = new GroupUnblockForm($this->out, $this->profile, $this->group,
188                                        array('action' => 'blockedfromgroup',
189                                              'nickname' => $this->group->nickname));
190             $bf->show();
191             $this->out->elementEnd('li');
192         }
193     }
194 }
195
196 /**
197  * Form for unblocking a user from a group
198  *
199  * @category Form
200  * @package  StatusNet
201  * @author   Evan Prodromou <evan@status.net>
202  * @author   Sarven Capadisli <csarven@status.net>
203  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
204  * @link     http://status.net/
205  *
206  * @see      UnblockForm
207  */
208
209 class GroupUnblockForm extends Form
210 {
211     /**
212      * Profile of user to block
213      */
214
215     var $profile = null;
216
217     /**
218      * Group to block the user from
219      */
220
221     var $group = null;
222
223     /**
224      * Return-to args
225      */
226
227     var $args = null;
228
229     /**
230      * Constructor
231      *
232      * @param HTMLOutputter $out     output channel
233      * @param Profile       $profile profile of user to block
234      * @param User_group    $group   group to block user from
235      * @param array         $args    return-to args
236      */
237
238     function __construct($out=null, $profile=null, $group=null, $args=null)
239     {
240         parent::__construct($out);
241
242         $this->profile = $profile;
243         $this->group   = $group;
244         $this->args    = $args;
245     }
246
247     /**
248      * ID of the form
249      *
250      * @return int ID of the form
251      */
252
253     function id()
254     {
255         // This should be unique for the page.
256         return 'unblock-' . $this->profile->id;
257     }
258
259     /**
260      * class of the form
261      *
262      * @return string class of the form
263      */
264
265     function formClass()
266     {
267         return 'form_group_unblock';
268     }
269
270     /**
271      * Action of the form
272      *
273      * @return string URL of the action
274      */
275
276     function action()
277     {
278         return common_local_url('groupunblock');
279     }
280
281     /**
282      * Legend of the Form
283      *
284      * @return void
285      */
286     function formLegend()
287     {
288         $this->out->element('legend', null, _('Unblock user from group'));
289     }
290
291     /**
292      * Data elements of the form
293      *
294      * @return void
295      */
296
297     function formData()
298     {
299         $this->out->hidden('unblockto-' . $this->profile->id,
300                            $this->profile->id,
301                            'unblockto');
302         $this->out->hidden('unblockgroup-' . $this->group->id,
303                            $this->group->id,
304                            'unblockgroup');
305         if ($this->args) {
306             foreach ($this->args as $k => $v) {
307                 $this->out->hidden('returnto-' . $k, $v);
308             }
309         }
310     }
311
312     /**
313      * Action elements
314      *
315      * @return void
316      */
317
318     function formActions()
319     {
320         $this->out->submit('submit', _('Unblock'), 'submit', null, _('Unblock this user'));
321     }
322 }