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