]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/groupmembers.php
Merge branch '0.9.x'
[quix0rs-gnu-social.git] / actions / groupmembers.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 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  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://status.net/
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         $local = Local_group::staticGet('nickname', $nickname);
81
82         if (!$local) {
83             $this->clientError(_('No such group.'), 404);
84             return false;
85         }
86
87         $this->group = User_group::staticGet('id', $local->group_id);
88
89         if (!$this->group) {
90             $this->clientError(_('No such group.'), 404);
91             return false;
92         }
93
94         return true;
95     }
96
97     function title()
98     {
99         if ($this->page == 1) {
100             // TRANS: Title of the page showing group members.
101             // TRANS: %s is the name of the group.
102             return sprintf(_('%s group members'),
103                            $this->group->nickname);
104         } else {
105             // TRANS: Title of the page showing group members.
106             // TRANS: %1$s is the name of the group, %2$d is the page number of the members list.
107             return sprintf(_('%1$s group members, page %2$d'),
108                            $this->group->nickname,
109                            $this->page);
110         }
111     }
112
113     function handle($args)
114     {
115         parent::handle($args);
116         $this->showPage();
117     }
118
119     function showPageNotice()
120     {
121         $this->element('p', 'instructions',
122                        _('A list of the users in 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         $members = $this->group->getMembers($offset, $limit);
139
140         if ($members) {
141             $member_list = new GroupMemberList($members, $this->group, $this);
142             $cnt = $member_list->show();
143         }
144
145         $members->free();
146
147         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
148                           $this->page, 'groupmembers',
149                           array('nickname' => $this->group->nickname));
150     }
151 }
152
153 class GroupMemberList 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 GroupMemberListItem($profile, $this->group, $this->action);
167     }
168 }
169
170 class GroupMemberListItem 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 showFullName()
182     {
183         parent::showFullName();
184         if ($this->profile->isAdmin($this->group)) {
185             $this->out->text(' ');
186             $this->out->element('span', 'role', _('Admin'));
187         }
188     }
189
190     function showActions()
191     {
192         $this->startActions();
193         if (Event::handle('StartProfileListItemActionElements', array($this))) {
194             $this->showSubscribeButton();
195             $this->showMakeAdminForm();
196             $this->showGroupBlockForm();
197             Event::handle('EndProfileListItemActionElements', array($this));
198         }
199         $this->endActions();
200     }
201
202     function showMakeAdminForm()
203     {
204         $user = common_current_user();
205
206         if (!empty($user) &&
207             $user->id != $this->profile->id &&
208             ($user->isAdmin($this->group) || $user->hasRight(Right::MAKEGROUPADMIN)) &&
209             !$this->profile->isAdmin($this->group)) {
210             $this->out->elementStart('li', 'entity_make_admin');
211             $maf = new MakeAdminForm($this->out, $this->profile, $this->group,
212                                      $this->returnToArgs());
213             $maf->show();
214             $this->out->elementEnd('li');
215         }
216
217     }
218
219     function showGroupBlockForm()
220     {
221         $user = common_current_user();
222
223         if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
224             $this->out->elementStart('li', 'entity_block');
225             $bf = new GroupBlockForm($this->out, $this->profile, $this->group,
226                                      $this->returnToArgs());
227             $bf->show();
228             $this->out->elementEnd('li');
229         }
230     }
231
232     function linkAttributes()
233     {
234         $aAttrs = parent::linkAttributes();
235
236         if (common_config('nofollow', 'members')) {
237             $aAttrs['rel'] .= ' nofollow';
238         }
239
240         return $aAttrs;
241     }
242
243     function homepageAttributes()
244     {
245         $aAttrs = parent::linkAttributes();
246
247         if (common_config('nofollow', 'members')) {
248             $aAttrs['rel'] = 'nofollow';
249         }
250
251         return $aAttrs;
252     }
253
254     /**
255      * Fetch necessary return-to arguments for the profile forms
256      * to return to this list when they're done.
257      * 
258      * @return array
259      */
260     protected function returnToArgs()
261     {
262         $args = array('action' => 'groupmembers',
263                       'nickname' => $this->group->nickname);
264         $page = $this->out->arg('page');
265         if ($page) {
266             $args['param-page'] = $page;
267         }
268         return $args;
269     }
270 }
271
272 /**
273  * Form for blocking a user from a group
274  *
275  * @category Form
276  * @package  StatusNet
277  * @author   Evan Prodromou <evan@status.net>
278  * @author   Sarven Capadisli <csarven@status.net>
279  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
280  * @link     http://status.net/
281  *
282  * @see      BlockForm
283  */
284
285 class GroupBlockForm extends Form
286 {
287     /**
288      * Profile of user to block
289      */
290
291     var $profile = null;
292
293     /**
294      * Group to block the user from
295      */
296
297     var $group = null;
298
299     /**
300      * Return-to args
301      */
302
303     var $args = null;
304
305     /**
306      * Constructor
307      *
308      * @param HTMLOutputter $out     output channel
309      * @param Profile       $profile profile of user to block
310      * @param User_group    $group   group to block user from
311      * @param array         $args    return-to args
312      */
313
314     function __construct($out=null, $profile=null, $group=null, $args=null)
315     {
316         parent::__construct($out);
317
318         $this->profile = $profile;
319         $this->group   = $group;
320         $this->args    = $args;
321     }
322
323     /**
324      * ID of the form
325      *
326      * @return int ID of the form
327      */
328
329     function id()
330     {
331         // This should be unique for the page.
332         return 'block-' . $this->profile->id;
333     }
334
335     /**
336      * class of the form
337      *
338      * @return string class of the form
339      */
340
341     function formClass()
342     {
343         return 'form_group_block';
344     }
345
346     /**
347      * Action of the form
348      *
349      * @return string URL of the action
350      */
351
352     function action()
353     {
354         return common_local_url('groupblock');
355     }
356
357     /**
358      * Legend of the Form
359      *
360      * @return void
361      */
362     function formLegend()
363     {
364         $this->out->element('legend', null, _('Block user from group'));
365     }
366
367     /**
368      * Data elements of the form
369      *
370      * @return void
371      */
372
373     function formData()
374     {
375         $this->out->hidden('blockto-' . $this->profile->id,
376                            $this->profile->id,
377                            'blockto');
378         $this->out->hidden('blockgroup-' . $this->group->id,
379                            $this->group->id,
380                            'blockgroup');
381         if ($this->args) {
382             foreach ($this->args as $k => $v) {
383                 $this->out->hidden('returnto-' . $k, $v);
384             }
385         }
386     }
387
388     /**
389      * Action elements
390      *
391      * @return void
392      */
393
394     function formActions()
395     {
396         $this->out->submit(
397             'submit',
398             // TRANS: Button text for the form that will block a user from a group.
399             _m('BUTTON','Block'),
400             'submit',
401             null,
402             // TRANS: Submit button title.
403             _m('TOOLTIP',_('Block this user'));
404     }
405 }
406
407 /**
408  * Form for making a user an admin for a group
409  *
410  * @category Form
411  * @package  StatusNet
412  * @author   Evan Prodromou <evan@status.net>
413  * @author   Sarven Capadisli <csarven@status.net>
414  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
415  * @link     http://status.net/
416  */
417
418 class MakeAdminForm extends Form
419 {
420     /**
421      * Profile of user to block
422      */
423
424     var $profile = null;
425
426     /**
427      * Group to block the user from
428      */
429
430     var $group = null;
431
432     /**
433      * Return-to args
434      */
435
436     var $args = null;
437
438     /**
439      * Constructor
440      *
441      * @param HTMLOutputter $out     output channel
442      * @param Profile       $profile profile of user to block
443      * @param User_group    $group   group to block user from
444      * @param array         $args    return-to args
445      */
446
447     function __construct($out=null, $profile=null, $group=null, $args=null)
448     {
449         parent::__construct($out);
450
451         $this->profile = $profile;
452         $this->group   = $group;
453         $this->args    = $args;
454     }
455
456     /**
457      * ID of the form
458      *
459      * @return int ID of the form
460      */
461
462     function id()
463     {
464         // This should be unique for the page.
465         return 'makeadmin-' . $this->profile->id;
466     }
467
468     /**
469      * class of the form
470      *
471      * @return string class of the form
472      */
473
474     function formClass()
475     {
476         return 'form_make_admin';
477     }
478
479     /**
480      * Action of the form
481      *
482      * @return string URL of the action
483      */
484
485     function action()
486     {
487         return common_local_url('makeadmin', array('nickname' => $this->group->nickname));
488     }
489
490     /**
491      * Legend of the Form
492      *
493      * @return void
494      */
495
496     function formLegend()
497     {
498         $this->out->element('legend', null, _('Make user an admin of the group'));
499     }
500
501     /**
502      * Data elements of the form
503      *
504      * @return void
505      */
506
507     function formData()
508     {
509         $this->out->hidden('profileid-' . $this->profile->id,
510                            $this->profile->id,
511                            'profileid');
512         $this->out->hidden('groupid-' . $this->group->id,
513                            $this->group->id,
514                            'groupid');
515         if ($this->args) {
516             foreach ($this->args as $k => $v) {
517                 $this->out->hidden('returnto-' . $k, $v);
518             }
519         }
520     }
521
522     /**
523      * Action elements
524      *
525      * @return void
526      */
527
528     function formActions()
529     {
530         $this->out->submit(
531           'submit',
532           // TRANS: Button text for the form that will make a user administrator.
533           _m('BUTTON','Make Admin'),
534           'submit',
535           null,
536           // TRANS: Submit button title.
537           _m('TOOLTIP','Make this user an admin'));
538     }
539 }