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