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