]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/groupmembers.php
Merge branch 'master' of gitorious.org:statusnet/mainline 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
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(_('%1$s group members, page %2$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 showFullName()
171     {
172         parent::showFullName();
173         if ($this->profile->isAdmin($this->group)) {
174             $this->out->text(' ');
175             $this->out->element('span', 'role', _('Admin'));
176         }
177     }
178
179     function showActions()
180     {
181         $this->startActions();
182         if (Event::handle('StartProfileListItemActionElements', array($this))) {
183             $this->showSubscribeButton();
184             $this->showMakeAdminForm();
185             $this->showGroupBlockForm();
186             Event::handle('EndProfileListItemActionElements', array($this));
187         }
188         $this->endActions();
189     }
190
191     function showMakeAdminForm()
192     {
193         $user = common_current_user();
194
195         if (!empty($user) &&
196             $user->id != $this->profile->id &&
197             ($user->isAdmin($this->group) || $user->hasRight(Right::MAKEGROUPADMIN)) &&
198             !$this->profile->isAdmin($this->group)) {
199             $this->out->elementStart('li', 'entity_make_admin');
200             $maf = new MakeAdminForm($this->out, $this->profile, $this->group,
201                                      array('action' => 'groupmembers',
202                                            'nickname' => $this->group->nickname));
203             $maf->show();
204             $this->out->elementEnd('li');
205         }
206
207     }
208     function showGroupBlockForm()
209     {
210         $user = common_current_user();
211
212         if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
213             $this->out->elementStart('li', 'entity_block');
214             $bf = new GroupBlockForm($this->out, $this->profile, $this->group,
215                                 array('action' => 'groupmembers',
216                                       'nickname' => $this->group->nickname));
217             $bf->show();
218             $this->out->elementEnd('li');
219         }
220
221     }
222 }
223
224 /**
225  * Form for blocking a user from a group
226  *
227  * @category Form
228  * @package  StatusNet
229  * @author   Evan Prodromou <evan@status.net>
230  * @author   Sarven Capadisli <csarven@status.net>
231  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
232  * @link     http://status.net/
233  *
234  * @see      BlockForm
235  */
236
237 class GroupBlockForm extends Form
238 {
239     /**
240      * Profile of user to block
241      */
242
243     var $profile = null;
244
245     /**
246      * Group to block the user from
247      */
248
249     var $group = null;
250
251     /**
252      * Return-to args
253      */
254
255     var $args = null;
256
257     /**
258      * Constructor
259      *
260      * @param HTMLOutputter $out     output channel
261      * @param Profile       $profile profile of user to block
262      * @param User_group    $group   group to block user from
263      * @param array         $args    return-to args
264      */
265
266     function __construct($out=null, $profile=null, $group=null, $args=null)
267     {
268         parent::__construct($out);
269
270         $this->profile = $profile;
271         $this->group   = $group;
272         $this->args    = $args;
273     }
274
275     /**
276      * ID of the form
277      *
278      * @return int ID of the form
279      */
280
281     function id()
282     {
283         // This should be unique for the page.
284         return 'block-' . $this->profile->id;
285     }
286
287     /**
288      * class of the form
289      *
290      * @return string class of the form
291      */
292
293     function formClass()
294     {
295         return 'form_group_block';
296     }
297
298     /**
299      * Action of the form
300      *
301      * @return string URL of the action
302      */
303
304     function action()
305     {
306         return common_local_url('groupblock');
307     }
308
309     /**
310      * Legend of the Form
311      *
312      * @return void
313      */
314     function formLegend()
315     {
316         $this->out->element('legend', null, _('Block user from group'));
317     }
318
319     /**
320      * Data elements of the form
321      *
322      * @return void
323      */
324
325     function formData()
326     {
327         $this->out->hidden('blockto-' . $this->profile->id,
328                            $this->profile->id,
329                            'blockto');
330         $this->out->hidden('blockgroup-' . $this->group->id,
331                            $this->group->id,
332                            'blockgroup');
333         if ($this->args) {
334             foreach ($this->args as $k => $v) {
335                 $this->out->hidden('returnto-' . $k, $v);
336             }
337         }
338     }
339
340     /**
341      * Action elements
342      *
343      * @return void
344      */
345
346     function formActions()
347     {
348         $this->out->submit('submit', _('Block'), 'submit', null, _('Block this user'));
349     }
350 }
351
352 /**
353  * Form for making a user an admin for a group
354  *
355  * @category Form
356  * @package  StatusNet
357  * @author   Evan Prodromou <evan@status.net>
358  * @author   Sarven Capadisli <csarven@status.net>
359  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
360  * @link     http://status.net/
361  */
362
363 class MakeAdminForm extends Form
364 {
365     /**
366      * Profile of user to block
367      */
368
369     var $profile = null;
370
371     /**
372      * Group to block the user from
373      */
374
375     var $group = null;
376
377     /**
378      * Return-to args
379      */
380
381     var $args = null;
382
383     /**
384      * Constructor
385      *
386      * @param HTMLOutputter $out     output channel
387      * @param Profile       $profile profile of user to block
388      * @param User_group    $group   group to block user from
389      * @param array         $args    return-to args
390      */
391
392     function __construct($out=null, $profile=null, $group=null, $args=null)
393     {
394         parent::__construct($out);
395
396         $this->profile = $profile;
397         $this->group   = $group;
398         $this->args    = $args;
399     }
400
401     /**
402      * ID of the form
403      *
404      * @return int ID of the form
405      */
406
407     function id()
408     {
409         // This should be unique for the page.
410         return 'makeadmin-' . $this->profile->id;
411     }
412
413     /**
414      * class of the form
415      *
416      * @return string class of the form
417      */
418
419     function formClass()
420     {
421         return 'form_make_admin';
422     }
423
424     /**
425      * Action of the form
426      *
427      * @return string URL of the action
428      */
429
430     function action()
431     {
432         return common_local_url('makeadmin', array('nickname' => $this->group->nickname));
433     }
434
435     /**
436      * Legend of the Form
437      *
438      * @return void
439      */
440
441     function formLegend()
442     {
443         $this->out->element('legend', null, _('Make user an admin of the group'));
444     }
445
446     /**
447      * Data elements of the form
448      *
449      * @return void
450      */
451
452     function formData()
453     {
454         $this->out->hidden('profileid-' . $this->profile->id,
455                            $this->profile->id,
456                            'profileid');
457         $this->out->hidden('groupid-' . $this->group->id,
458                            $this->group->id,
459                            'groupid');
460         if ($this->args) {
461             foreach ($this->args as $k => $v) {
462                 $this->out->hidden('returnto-' . $k, $v);
463             }
464         }
465     }
466
467     /**
468      * Action elements
469      *
470      * @return void
471      */
472
473     function formActions()
474     {
475         $this->out->submit('submit', _('Make Admin'), 'submit', null, _('Make this user an admin'));
476     }
477 }