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