]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/blockedfromgroup.php
Merge branch 'master' into 0.9.x
[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 class BlockedfromgroupAction extends GroupDesignAction
44 {
45     var $page = null;
46
47     function isReadOnly($args)
48     {
49         return true;
50     }
51
52     function prepare($args)
53     {
54         parent::prepare($args);
55         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
56
57         $nickname_arg = $this->arg('nickname');
58         $nickname = common_canonical_nickname($nickname_arg);
59
60         // Permanent redirect on non-canonical nickname
61
62         if ($nickname_arg != $nickname) {
63             $args = array('nickname' => $nickname);
64             if ($this->page != 1) {
65                 $args['page'] = $this->page;
66             }
67             common_redirect(common_local_url('blockedfromgroup', $args), 301);
68             return false;
69         }
70
71         if (!$nickname) {
72             // TRANS: Client error displayed when requesting a list of blocked users for a group without providing a group nickname.
73             $this->clientError(_('No nickname.'), 404);
74             return false;
75         }
76
77         $local = Local_group::staticGet('nickname', $nickname);
78
79         if (!$local) {
80             // TRANS: Client error displayed when requesting a list of blocked users for a non-local group.
81             $this->clientError(_('No such group.'), 404);
82             return false;
83         }
84
85         $this->group = User_group::staticGet('id', $local->group_id);
86
87         if (!$this->group) {
88             // TRANS: Client error displayed when requesting a list of blocked users for a non-existing group.
89             $this->clientError(_('No such group.'), 404);
90             return false;
91         }
92
93         return true;
94     }
95
96     function title()
97     {
98         if ($this->page == 1) {
99             // TRANS: Title for first page with list of users blocked from a group.
100             // TRANS: %s is a group nickname.
101             return sprintf(_('%s blocked profiles'),
102                            $this->group->nickname);
103         } else {
104             // TRANS: Title for any but the first page with list of users blocked from a group.
105             // TRANS: %1$s is a group nickname, %2$d is a page number.
106             return sprintf(_('%1$s blocked profiles, page %2$d'),
107                            $this->group->nickname,
108                            $this->page);
109         }
110     }
111
112     function handle($args)
113     {
114         parent::handle($args);
115         $this->showPage();
116     }
117
118     function showPageNotice()
119     {
120         $this->element('p', 'instructions',
121                        // TRANS: Instructions for list of users blocked from a group.
122                        _('A list of the users blocked from joining this group.'));
123     }
124
125     function showLocalNav()
126     {
127         $nav = new GroupNav($this, $this->group);
128         $nav->show();
129     }
130
131     function showContent()
132     {
133         $offset = ($this->page-1) * PROFILES_PER_PAGE;
134         $limit =  PROFILES_PER_PAGE + 1;
135
136         $cnt = 0;
137
138         $blocked = $this->group->getBlocked($offset, $limit);
139
140         if ($blocked) {
141             $blocked_list = new GroupBlockList($blocked, $this->group, $this);
142             $cnt = $blocked_list->show();
143         }
144
145         $blocked->free();
146
147         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
148                           $this->page, 'blockedfromgroup',
149                           array('nickname' => $this->group->nickname));
150     }
151 }
152
153 class GroupBlockList extends ProfileList
154 {
155     var $group = null;
156
157     function __construct($profile, $group, $action)
158     {
159         parent::__construct($profile, $action);
160
161         $this->group = $group;
162     }
163
164     function newListItem($profile)
165     {
166         return new GroupBlockListItem($profile, $this->group, $this->action);
167     }
168 }
169
170 class GroupBlockListItem extends ProfileListItem
171 {
172     var $group = null;
173
174     function __construct($profile, $group, $action)
175     {
176         parent::__construct($profile, $action);
177
178         $this->group = $group;
179     }
180
181     function showActions()
182     {
183         $this->startActions();
184         $this->showGroupUnblockForm();
185         $this->endActions();
186     }
187
188     function showGroupUnblockForm()
189     {
190         $user = common_current_user();
191
192         if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
193             $this->out->elementStart('li', 'entity_block');
194             $bf = new GroupUnblockForm($this->out, $this->profile, $this->group,
195                                        array('action' => 'blockedfromgroup',
196                                              'nickname' => $this->group->nickname));
197             $bf->show();
198             $this->out->elementEnd('li');
199         }
200     }
201 }
202
203 /**
204  * Form for unblocking a user from a group
205  *
206  * @category Form
207  * @package  StatusNet
208  * @author   Evan Prodromou <evan@status.net>
209  * @author   Sarven Capadisli <csarven@status.net>
210  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
211  * @link     http://status.net/
212  *
213  * @see      UnblockForm
214  */
215 class GroupUnblockForm extends Form
216 {
217     /**
218      * Profile of user to block
219      */
220
221     var $profile = null;
222
223     /**
224      * Group to block the user from
225      */
226
227     var $group = null;
228
229     /**
230      * Return-to args
231      */
232
233     var $args = null;
234
235     /**
236      * Constructor
237      *
238      * @param HTMLOutputter $out     output channel
239      * @param Profile       $profile profile of user to block
240      * @param User_group    $group   group to block user from
241      * @param array         $args    return-to args
242      */
243     function __construct($out=null, $profile=null, $group=null, $args=null)
244     {
245         parent::__construct($out);
246
247         $this->profile = $profile;
248         $this->group   = $group;
249         $this->args    = $args;
250     }
251
252     /**
253      * ID of the form
254      *
255      * @return int ID of the form
256      */
257     function id()
258     {
259         // This should be unique for the page.
260         return 'unblock-' . $this->profile->id;
261     }
262
263     /**
264      * class of the form
265      *
266      * @return string class of the form
267      */
268     function formClass()
269     {
270         return 'form_group_unblock';
271     }
272
273     /**
274      * Action of the form
275      *
276      * @return string URL of the action
277      */
278     function action()
279     {
280         return common_local_url('groupunblock');
281     }
282
283     /**
284      * Legend of the Form
285      *
286      * @return void
287      */
288     function formLegend()
289     {
290         // TRANS: Form legend for unblocking a user from a group.
291         $this->out->element('legend', null, _('Unblock user from group'));
292     }
293
294     /**
295      * Data elements of the form
296      *
297      * @return void
298      */
299     function formData()
300     {
301         $this->out->hidden('unblockto-' . $this->profile->id,
302                            $this->profile->id,
303                            'unblockto');
304         $this->out->hidden('unblockgroup-' . $this->group->id,
305                            $this->group->id,
306                            'unblockgroup');
307         if ($this->args) {
308             foreach ($this->args as $k => $v) {
309                 $this->out->hidden('returnto-' . $k, $v);
310             }
311         }
312     }
313
314     /**
315      * Action elements
316      *
317      * @return void
318      */
319     function formActions()
320     {
321         $this->out->submit('submit',
322                            // TRANS: Button text for unblocking a user from a group.
323                            _m('BUTTON','Unblock'),
324                            'submit',
325                            null,
326                            // TRANS: Tooltip for button for unblocking a user from a group.
327                            _('Unblock this user'));
328     }
329 }