]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/groupmembers.php
d132cdf9670512d5f5083a713726af77b014d90b
[quix0rs-gnu-social.git] / actions / groupmembers.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 require_once(INSTALLDIR.'/lib/profilelist.php');
35 require_once INSTALLDIR.'/lib/publicgroupnav.php';
36
37 /**
38  * List of group members
39  *
40  * @category Group
41  * @package  Laconica
42  * @author   Evan Prodromou <evan@controlyourself.ca>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://laconi.ca/
45  */
46
47 class GroupmembersAction extends GroupDesignAction
48 {
49     var $page = null;
50
51     function isReadOnly($args)
52     {
53         return true;
54     }
55
56     function prepare($args)
57     {
58         parent::prepare($args);
59         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
60
61         $nickname_arg = $this->arg('nickname');
62         $nickname = common_canonical_nickname($nickname_arg);
63
64         // Permanent redirect on non-canonical nickname
65
66         if ($nickname_arg != $nickname) {
67             $args = array('nickname' => $nickname);
68             if ($this->page != 1) {
69                 $args['page'] = $this->page;
70             }
71             common_redirect(common_local_url('groupmembers', $args), 301);
72             return false;
73         }
74
75         if (!$nickname) {
76             $this->clientError(_('No nickname'), 404);
77             return false;
78         }
79
80         $this->group = User_group::staticGet('nickname', $nickname);
81
82         if (!$this->group) {
83             $this->clientError(_('No such group'), 404);
84             return false;
85         }
86
87         return true;
88     }
89
90     function title()
91     {
92         if ($this->page == 1) {
93             return sprintf(_('%s group members'),
94                            $this->group->nickname);
95         } else {
96             return sprintf(_('%s group members, page %d'),
97                            $this->group->nickname,
98                            $this->page);
99         }
100     }
101
102     function handle($args)
103     {
104         parent::handle($args);
105         $this->showPage();
106     }
107
108     function showPageNotice()
109     {
110         $this->element('p', 'instructions',
111                        _('A list of the users in this group.'));
112     }
113
114     function showLocalNav()
115     {
116         $nav = new GroupNav($this, $this->group);
117         $nav->show();
118     }
119
120     function showContent()
121     {
122         $offset = ($this->page-1) * PROFILES_PER_PAGE;
123         $limit =  PROFILES_PER_PAGE + 1;
124
125         $cnt = 0;
126
127         $members = $this->group->getMembers($offset, $limit);
128
129         if ($members) {
130             $member_list = new GroupMemberList($members, $this->group, $this);
131             $cnt = $member_list->show();
132         }
133
134         $members->free();
135
136         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
137                           $this->page, 'groupmembers',
138                           array('nickname' => $this->group->nickname));
139     }
140 }
141
142 class GroupMemberList extends ProfileList
143 {
144     var $group = null;
145
146     function __construct($profile, $group, $action)
147     {
148         parent::__construct($profile, $action);
149
150         $this->group = $group;
151     }
152
153     function newListItem($profile)
154     {
155         return new GroupMemberListItem($profile, $this->group, $this->action);
156     }
157 }
158
159 class GroupMemberListItem extends ProfileListItem
160 {
161     var $group = null;
162
163     function __construct($profile, $group, $action)
164     {
165         parent::__construct($profile, $action);
166
167         $this->group = $group;
168     }
169
170     function showActions()
171     {
172         $this->startActions();
173         $this->showSubscribeButton();
174         $this->showMakeAdminForm();
175         $this->showGroupBlockForm();
176         $this->endActions();
177     }
178
179     function showMakeAdminForm()
180     {
181         $user = common_current_user();
182
183         if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group) &&
184             !$this->profile->isAdmin($this->group)) {
185             $this->out->elementStart('li', 'entity_make_admin');
186             $maf = new MakeAdminForm($this->out, $this->profile, $this->group,
187                                      array('action' => 'groupmembers',
188                                            'nickname' => $this->group->nickname));
189             $maf->show();
190             $this->out->elementEnd('li');
191         }
192
193     }
194     function showGroupBlockForm()
195     {
196         $user = common_current_user();
197
198         if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
199             $this->out->elementStart('li', 'entity_block');
200             $bf = new GroupBlockForm($this->out, $this->profile, $this->group,
201                                 array('action' => 'groupmembers',
202                                       'nickname' => $this->group->nickname));
203             $bf->show();
204             $this->out->elementEnd('li');
205         }
206
207     }
208 }
209
210 /**
211  * Form for blocking a user from a group
212  *
213  * @category Form
214  * @package  Laconica
215  * @author   Evan Prodromou <evan@controlyourself.ca>
216  * @author   Sarven Capadisli <csarven@controlyourself.ca>
217  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
218  * @link     http://laconi.ca/
219  *
220  * @see      BlockForm
221  */
222
223 class GroupBlockForm extends Form
224 {
225     /**
226      * Profile of user to block
227      */
228
229     var $profile = null;
230
231     /**
232      * Group to block the user from
233      */
234
235     var $group = null;
236
237     /**
238      * Return-to args
239      */
240
241     var $args = null;
242
243     /**
244      * Constructor
245      *
246      * @param HTMLOutputter $out     output channel
247      * @param Profile       $profile profile of user to block
248      * @param User_group    $group   group to block user from
249      * @param array         $args    return-to args
250      */
251
252     function __construct($out=null, $profile=null, $group=null, $args=null)
253     {
254         parent::__construct($out);
255
256         $this->profile = $profile;
257         $this->group   = $group;
258         $this->args    = $args;
259     }
260
261     /**
262      * ID of the form
263      *
264      * @return int ID of the form
265      */
266
267     function id()
268     {
269         // This should be unique for the page.
270         return 'block-' . $this->profile->id;
271     }
272
273     /**
274      * class of the form
275      *
276      * @return string class of the form
277      */
278
279     function formClass()
280     {
281         return 'form_group_block';
282     }
283
284     /**
285      * Action of the form
286      *
287      * @return string URL of the action
288      */
289
290     function action()
291     {
292         return common_local_url('groupblock');
293     }
294
295     /**
296      * Legend of the Form
297      *
298      * @return void
299      */
300     function formLegend()
301     {
302         $this->out->element('legend', null, _('Block user from group'));
303     }
304
305     /**
306      * Data elements of the form
307      *
308      * @return void
309      */
310
311     function formData()
312     {
313         $this->out->hidden('blockto-' . $this->profile->id,
314                            $this->profile->id,
315                            'blockto');
316         $this->out->hidden('blockgroup-' . $this->group->id,
317                            $this->group->id,
318                            'blockgroup');
319         if ($this->args) {
320             foreach ($this->args as $k => $v) {
321                 $this->out->hidden('returnto-' . $k, $v);
322             }
323         }
324     }
325
326     /**
327      * Action elements
328      *
329      * @return void
330      */
331
332     function formActions()
333     {
334         $this->out->submit('submit', _('Block'), 'submit', null, _('Block this user'));
335     }
336 }
337
338 /**
339  * Form for making a user an admin for a group
340  *
341  * @category Form
342  * @package  Laconica
343  * @author   Evan Prodromou <evan@controlyourself.ca>
344  * @author   Sarven Capadisli <csarven@controlyourself.ca>
345  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
346  * @link     http://laconi.ca/
347  */
348
349 class MakeAdminForm extends Form
350 {
351     /**
352      * Profile of user to block
353      */
354
355     var $profile = null;
356
357     /**
358      * Group to block the user from
359      */
360
361     var $group = null;
362
363     /**
364      * Return-to args
365      */
366
367     var $args = null;
368
369     /**
370      * Constructor
371      *
372      * @param HTMLOutputter $out     output channel
373      * @param Profile       $profile profile of user to block
374      * @param User_group    $group   group to block user from
375      * @param array         $args    return-to args
376      */
377
378     function __construct($out=null, $profile=null, $group=null, $args=null)
379     {
380         parent::__construct($out);
381
382         $this->profile = $profile;
383         $this->group   = $group;
384         $this->args    = $args;
385     }
386
387     /**
388      * ID of the form
389      *
390      * @return int ID of the form
391      */
392
393     function id()
394     {
395         // This should be unique for the page.
396         return 'makeadmin-' . $this->profile->id;
397     }
398
399     /**
400      * class of the form
401      *
402      * @return string class of the form
403      */
404
405     function formClass()
406     {
407         return 'form_make_admin';
408     }
409
410     /**
411      * Action of the form
412      *
413      * @return string URL of the action
414      */
415
416     function action()
417     {
418         return common_local_url('makeadmin', array('nickname' => $this->group->nickname));
419     }
420
421     /**
422      * Legend of the Form
423      *
424      * @return void
425      */
426
427     function formLegend()
428     {
429         $this->out->element('legend', null, _('Make user an admin of the group'));
430     }
431
432     /**
433      * Data elements of the form
434      *
435      * @return void
436      */
437
438     function formData()
439     {
440         $this->out->hidden('profileid-' . $this->profile->id,
441                            $this->profile->id,
442                            'profileid');
443         $this->out->hidden('groupid-' . $this->group->id,
444                            $this->group->id,
445                            'groupid');
446         if ($this->args) {
447             foreach ($this->args as $k => $v) {
448                 $this->out->hidden('returnto-' . $k, $v);
449             }
450         }
451     }
452
453     /**
454      * Action elements
455      *
456      * @return void
457      */
458
459     function formActions()
460     {
461         $this->out->submit('submit', _('Make Admin'), 'submit', null, _('Make this user an admin'));
462     }
463 }