]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/blockedfromgroup.php
Merge branch '0.8.x' of git@gitorious.org:laconica/dev into 0.8.x
[quix0rs-gnu-social.git] / actions / blockedfromgroup.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @copyright 2008-2009 Control Yourself, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * List of profiles blocked from this group
36  *
37  * @category Group
38  * @package  Laconica
39  * @author   Evan Prodromou <evan@controlyourself.ca>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://laconi.ca/
42  */
43
44 class BlockedfromgroupAction extends Action
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         $this->group = User_group::staticGet('nickname', $nickname);
78
79         if (!$this->group) {
80             $this->clientError(_('No such group'), 404);
81             return false;
82         }
83
84         return true;
85     }
86
87     function title()
88     {
89         if ($this->page == 1) {
90             return sprintf(_('%s blocked profiles'),
91                            $this->group->nickname);
92         } else {
93             return sprintf(_('%s blocked profiles, page %d'),
94                            $this->group->nickname,
95                            $this->page);
96         }
97     }
98
99     function handle($args)
100     {
101         parent::handle($args);
102         $this->showPage();
103     }
104
105     function showPageNotice()
106     {
107         $this->element('p', 'instructions',
108                        _('A list of the users blocked from joining this group.'));
109     }
110
111     function showLocalNav()
112     {
113         $nav = new GroupNav($this, $this->group);
114         $nav->show();
115     }
116
117     function showContent()
118     {
119         $offset = ($this->page-1) * PROFILES_PER_PAGE;
120         $limit =  PROFILES_PER_PAGE + 1;
121
122         $cnt = 0;
123
124         $blocked = $this->group->getBlocked($offset, $limit);
125
126         if ($blocked) {
127             $blocked_list = new GroupBlockList($blocked, $this->group, $this);
128             $cnt = $blocked_list->show();
129         }
130
131         $blocked->free();
132
133         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
134                           $this->page, 'blockedfromgroup',
135                           array('nickname' => $this->group->nickname));
136     }
137 }
138
139 class GroupBlockList extends ProfileList
140 {
141     var $group = null;
142
143     function __construct($profile, $group, $action)
144     {
145         parent::__construct($profile, $action);
146
147         $this->group = $group;
148     }
149
150     function newListItem($profile)
151     {
152         return new GroupBlockListItem($profile, $this->group, $this->action);
153     }
154 }
155
156 class GroupBlockListItem extends ProfileListItem
157 {
158     var $group = null;
159
160     function __construct($profile, $group, $action)
161     {
162         parent::__construct($profile, $action);
163
164         $this->group = $group;
165     }
166
167     function showActions()
168     {
169         $this->startActions();
170         $this->showGroupUnblockForm();
171         $this->endActions();
172     }
173
174     function showGroupUnblockForm()
175     {
176         $user = common_current_user();
177
178         if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
179             $bf = new GroupUnblockForm($this->out, $this->profile, $this->group,
180                                        array('action' => 'blockedfromgroup',
181                                              'nickname' => $this->group->nickname));
182             $bf->show();
183         }
184     }
185 }
186
187 /**
188  * Form for unblocking a user from a group
189  *
190  * @category Form
191  * @package  Laconica
192  * @author   Evan Prodromou <evan@controlyourself.ca>
193  * @author   Sarven Capadisli <csarven@controlyourself.ca>
194  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
195  * @link     http://laconi.ca/
196  *
197  * @see      UnblockForm
198  */
199
200 class GroupUnblockForm extends Form
201 {
202     /**
203      * Profile of user to block
204      */
205
206     var $profile = null;
207
208     /**
209      * Group to block the user from
210      */
211
212     var $group = null;
213
214     /**
215      * Return-to args
216      */
217
218     var $args = null;
219
220     /**
221      * Constructor
222      *
223      * @param HTMLOutputter $out     output channel
224      * @param Profile       $profile profile of user to block
225      * @param User_group    $group   group to block user from
226      * @param array         $args    return-to args
227      */
228
229     function __construct($out=null, $profile=null, $group=null, $args=null)
230     {
231         parent::__construct($out);
232
233         $this->profile = $profile;
234         $this->group   = $group;
235         $this->args    = $args;
236     }
237
238     /**
239      * ID of the form
240      *
241      * @return int ID of the form
242      */
243
244     function id()
245     {
246         // This should be unique for the page.
247         return 'unblock-' . $this->profile->id;
248     }
249
250     /**
251      * class of the form
252      *
253      * @return string class of the form
254      */
255
256     function formClass()
257     {
258         return 'form_group_unblock';
259     }
260
261     /**
262      * Action of the form
263      *
264      * @return string URL of the action
265      */
266
267     function action()
268     {
269         return common_local_url('groupunblock');
270     }
271
272     /**
273      * Legend of the Form
274      *
275      * @return void
276      */
277     function formLegend()
278     {
279         $this->out->element('legend', null, _('Unblock user from group'));
280     }
281
282     /**
283      * Data elements of the form
284      *
285      * @return void
286      */
287
288     function formData()
289     {
290         $this->out->hidden('unblockto-' . $this->profile->id,
291                            $this->profile->id,
292                            'unblockto');
293         $this->out->hidden('unblockgroup-' . $this->group->id,
294                            $this->group->id,
295                            'unblockgroup');
296         if ($this->args) {
297             foreach ($this->args as $k => $v) {
298                 $this->out->hidden('returnto-' . $k, $v);
299             }
300         }
301     }
302
303     /**
304      * Action elements
305      *
306      * @return void
307      */
308
309     function formActions()
310     {
311         $this->out->submit('submit', _('Unblock'), 'submit', null, _('Unblock this user'));
312     }
313 }