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