]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/blockedfromgroup.php
Merge commit 'refs/merge-requests/164' of git://gitorious.org/statusnet/mainline...
[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 GroupAction
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 showContent()
126     {
127         $offset = ($this->page-1) * PROFILES_PER_PAGE;
128         $limit =  PROFILES_PER_PAGE + 1;
129
130         $cnt = 0;
131
132         $blocked = $this->group->getBlocked($offset, $limit);
133
134         if ($blocked) {
135             $blocked_list = new GroupBlockList($blocked, $this->group, $this);
136             $cnt = $blocked_list->show();
137         }
138
139         $blocked->free();
140
141         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
142                           $this->page, 'blockedfromgroup',
143                           array('nickname' => $this->group->nickname));
144     }
145 }
146
147 class GroupBlockList extends ProfileList
148 {
149     var $group = null;
150
151     function __construct($profile, $group, $action)
152     {
153         parent::__construct($profile, $action);
154
155         $this->group = $group;
156     }
157
158     function newListItem($profile)
159     {
160         return new GroupBlockListItem($profile, $this->group, $this->action);
161     }
162 }
163
164 class GroupBlockListItem extends ProfileListItem
165 {
166     var $group = null;
167
168     function __construct($profile, $group, $action)
169     {
170         parent::__construct($profile, $action);
171
172         $this->group = $group;
173     }
174
175     function showActions()
176     {
177         $this->startActions();
178         $this->showGroupUnblockForm();
179         $this->endActions();
180     }
181
182     function showGroupUnblockForm()
183     {
184         $user = common_current_user();
185
186         if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
187             $this->out->elementStart('li', 'entity_block');
188             $bf = new GroupUnblockForm($this->out, $this->profile, $this->group,
189                                        array('action' => 'blockedfromgroup',
190                                              'nickname' => $this->group->nickname));
191             $bf->show();
192             $this->out->elementEnd('li');
193         }
194     }
195 }
196
197 /**
198  * Form for unblocking a user from a group
199  *
200  * @category Form
201  * @package  StatusNet
202  * @author   Evan Prodromou <evan@status.net>
203  * @author   Sarven Capadisli <csarven@status.net>
204  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
205  * @link     http://status.net/
206  *
207  * @see      UnblockForm
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     function __construct($out=null, $profile=null, $group=null, $args=null)
238     {
239         parent::__construct($out);
240
241         $this->profile = $profile;
242         $this->group   = $group;
243         $this->args    = $args;
244     }
245
246     /**
247      * ID of the form
248      *
249      * @return int ID of the form
250      */
251     function id()
252     {
253         // This should be unique for the page.
254         return 'unblock-' . $this->profile->id;
255     }
256
257     /**
258      * class of the form
259      *
260      * @return string class of the form
261      */
262     function formClass()
263     {
264         return 'form_group_unblock';
265     }
266
267     /**
268      * Action of the form
269      *
270      * @return string URL of the action
271      */
272     function action()
273     {
274         return common_local_url('groupunblock');
275     }
276
277     /**
278      * Legend of the Form
279      *
280      * @return void
281      */
282     function formLegend()
283     {
284         // TRANS: Form legend for unblocking a user from a group.
285         $this->out->element('legend', null, _('Unblock user from group'));
286     }
287
288     /**
289      * Data elements of the form
290      *
291      * @return void
292      */
293     function formData()
294     {
295         $this->out->hidden('unblockto-' . $this->profile->id,
296                            $this->profile->id,
297                            'unblockto');
298         $this->out->hidden('unblockgroup-' . $this->group->id,
299                            $this->group->id,
300                            'unblockgroup');
301         if ($this->args) {
302             foreach ($this->args as $k => $v) {
303                 $this->out->hidden('returnto-' . $k, $v);
304             }
305         }
306     }
307
308     /**
309      * Action elements
310      *
311      * @return void
312      */
313     function formActions()
314     {
315         $this->out->submit('submit',
316                            // TRANS: Button text for unblocking a user from a group.
317                            _m('BUTTON','Unblock'),
318                            'submit',
319                            null,
320                            // TRANS: Tooltip for button for unblocking a user from a group.
321                            _('Unblock this user'));
322     }
323 }