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