]> 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         $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                                      array('action' => 'groupmembers',
209                                            'nickname' => $this->group->nickname));
210             $maf->show();
211             $this->out->elementEnd('li');
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                                 array('action' => 'groupmembers',
223                                       'nickname' => $this->group->nickname));
224             $bf->show();
225             $this->out->elementEnd('li');
226         }
227
228     }
229 }
230
231 /**
232  * Form for blocking a user from a group
233  *
234  * @category Form
235  * @package  StatusNet
236  * @author   Evan Prodromou <evan@status.net>
237  * @author   Sarven Capadisli <csarven@status.net>
238  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
239  * @link     http://status.net/
240  *
241  * @see      BlockForm
242  */
243
244 class GroupBlockForm extends Form
245 {
246     /**
247      * Profile of user to block
248      */
249
250     var $profile = null;
251
252     /**
253      * Group to block the user from
254      */
255
256     var $group = null;
257
258     /**
259      * Return-to args
260      */
261
262     var $args = null;
263
264     /**
265      * Constructor
266      *
267      * @param HTMLOutputter $out     output channel
268      * @param Profile       $profile profile of user to block
269      * @param User_group    $group   group to block user from
270      * @param array         $args    return-to args
271      */
272
273     function __construct($out=null, $profile=null, $group=null, $args=null)
274     {
275         parent::__construct($out);
276
277         $this->profile = $profile;
278         $this->group   = $group;
279         $this->args    = $args;
280     }
281
282     /**
283      * ID of the form
284      *
285      * @return int ID of the form
286      */
287
288     function id()
289     {
290         // This should be unique for the page.
291         return 'block-' . $this->profile->id;
292     }
293
294     /**
295      * class of the form
296      *
297      * @return string class of the form
298      */
299
300     function formClass()
301     {
302         return 'form_group_block';
303     }
304
305     /**
306      * Action of the form
307      *
308      * @return string URL of the action
309      */
310
311     function action()
312     {
313         return common_local_url('groupblock');
314     }
315
316     /**
317      * Legend of the Form
318      *
319      * @return void
320      */
321     function formLegend()
322     {
323         $this->out->element('legend', null, _('Block user from group'));
324     }
325
326     /**
327      * Data elements of the form
328      *
329      * @return void
330      */
331
332     function formData()
333     {
334         $this->out->hidden('blockto-' . $this->profile->id,
335                            $this->profile->id,
336                            'blockto');
337         $this->out->hidden('blockgroup-' . $this->group->id,
338                            $this->group->id,
339                            'blockgroup');
340         if ($this->args) {
341             foreach ($this->args as $k => $v) {
342                 $this->out->hidden('returnto-' . $k, $v);
343             }
344         }
345     }
346
347     /**
348      * Action elements
349      *
350      * @return void
351      */
352
353     function formActions()
354     {
355         $this->out->submit('submit', _('Block'), 'submit', null, _('Block this user'));
356     }
357 }
358
359 /**
360  * Form for making a user an admin for a group
361  *
362  * @category Form
363  * @package  StatusNet
364  * @author   Evan Prodromou <evan@status.net>
365  * @author   Sarven Capadisli <csarven@status.net>
366  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
367  * @link     http://status.net/
368  */
369
370 class MakeAdminForm extends Form
371 {
372     /**
373      * Profile of user to block
374      */
375
376     var $profile = null;
377
378     /**
379      * Group to block the user from
380      */
381
382     var $group = null;
383
384     /**
385      * Return-to args
386      */
387
388     var $args = null;
389
390     /**
391      * Constructor
392      *
393      * @param HTMLOutputter $out     output channel
394      * @param Profile       $profile profile of user to block
395      * @param User_group    $group   group to block user from
396      * @param array         $args    return-to args
397      */
398
399     function __construct($out=null, $profile=null, $group=null, $args=null)
400     {
401         parent::__construct($out);
402
403         $this->profile = $profile;
404         $this->group   = $group;
405         $this->args    = $args;
406     }
407
408     /**
409      * ID of the form
410      *
411      * @return int ID of the form
412      */
413
414     function id()
415     {
416         // This should be unique for the page.
417         return 'makeadmin-' . $this->profile->id;
418     }
419
420     /**
421      * class of the form
422      *
423      * @return string class of the form
424      */
425
426     function formClass()
427     {
428         return 'form_make_admin';
429     }
430
431     /**
432      * Action of the form
433      *
434      * @return string URL of the action
435      */
436
437     function action()
438     {
439         return common_local_url('makeadmin', array('nickname' => $this->group->nickname));
440     }
441
442     /**
443      * Legend of the Form
444      *
445      * @return void
446      */
447
448     function formLegend()
449     {
450         $this->out->element('legend', null, _('Make user an admin of the group'));
451     }
452
453     /**
454      * Data elements of the form
455      *
456      * @return void
457      */
458
459     function formData()
460     {
461         $this->out->hidden('profileid-' . $this->profile->id,
462                            $this->profile->id,
463                            'profileid');
464         $this->out->hidden('groupid-' . $this->group->id,
465                            $this->group->id,
466                            'groupid');
467         if ($this->args) {
468             foreach ($this->args as $k => $v) {
469                 $this->out->hidden('returnto-' . $k, $v);
470             }
471         }
472     }
473
474     /**
475      * Action elements
476      *
477      * @return void
478      */
479
480     function formActions()
481     {
482         $this->out->submit('submit', _('Make Admin'), 'submit', null, _('Make this user an admin'));
483     }
484 }