]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/groupqueue.php
Pending members queue list -- doesn't yet allow approval.
[quix0rs-gnu-social.git] / actions / groupqueue.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 class GroupqueueAction extends GroupDesignAction
47 {
48     var $page = null;
49
50     function isReadOnly($args)
51     {
52         return true;
53     }
54
55     // fixme most of this belongs in a base class, sounds common to most group actions?
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('groupqueue', $args), 301);
72             return false;
73         }
74
75         if (!$nickname) {
76             // TRANS: Client error displayed when trying to view group members without providing a group nickname.
77             $this->clientError(_('No nickname.'), 404);
78             return false;
79         }
80
81         $local = Local_group::staticGet('nickname', $nickname);
82
83         if (!$local) {
84             // TRANS: Client error displayed when trying to view group members for a non-existing group.
85             $this->clientError(_('No such group.'), 404);
86             return false;
87         }
88
89         $this->group = User_group::staticGet('id', $local->group_id);
90
91         if (!$this->group) {
92             // TRANS: Client error displayed when trying to view group members for an object that is not a group.
93             $this->clientError(_('No such group.'), 404);
94             return false;
95         }
96
97         return true;
98     }
99
100     function title()
101     {
102         if ($this->page == 1) {
103             // TRANS: Title of the page showing pending group members still awaiting approval to join the group.
104             // TRANS: %s is the name of the group.
105             return sprintf(_('%s group members awaiting approval'),
106                            $this->group->nickname);
107         } else {
108             // TRANS: Title of the page showing pending group members still awaiting approval to join the group.
109             // TRANS: %1$s is the name of the group, %2$d is the page number of the members list.
110             return sprintf(_('%1$s group members awaiting approval, page %2$d'),
111                            $this->group->nickname,
112                            $this->page);
113         }
114     }
115
116     function handle($args)
117     {
118         parent::handle($args);
119         $this->showPage();
120     }
121
122     function showPageNotice()
123     {
124         $this->element('p', 'instructions',
125                        // TRANS: Page notice for group members page.
126                        _('A list of users awaiting approval to join this group.'));
127     }
128
129     function showObjectNav()
130     {
131         $nav = new GroupNav($this, $this->group);
132         $nav->show();
133     }
134
135     function showContent()
136     {
137         $offset = ($this->page-1) * PROFILES_PER_PAGE;
138         $limit =  PROFILES_PER_PAGE + 1;
139
140         $cnt = 0;
141
142         $members = $this->group->getRequests($offset, $limit);
143
144         if ($members) {
145             // @fixme change!
146             $member_list = new GroupMemberList($members, $this->group, $this);
147             $cnt = $member_list->show();
148         }
149
150         $members->free();
151
152         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
153                           $this->page, 'groupmembers',
154                           array('nickname' => $this->group->nickname));
155     }
156 }
157
158 class GroupMemberList extends ProfileList
159 {
160     var $group = null;
161
162     function __construct($profile, $group, $action)
163     {
164         parent::__construct($profile, $action);
165
166         $this->group = $group;
167     }
168
169     function newListItem($profile)
170     {
171         return new GroupMemberListItem($profile, $this->group, $this->action);
172     }
173 }
174
175 class GroupMemberListItem extends ProfileListItem
176 {
177     var $group = null;
178
179     function __construct($profile, $group, $action)
180     {
181         parent::__construct($profile, $action);
182
183         $this->group = $group;
184     }
185
186     function showFullName()
187     {
188         parent::showFullName();
189         if ($this->profile->isAdmin($this->group)) {
190             $this->out->text(' '); // for separating the classes.
191             // TRANS: Indicator in group members list that this user is a group administrator.
192             $this->out->element('span', 'role', _('Admin'));
193         }
194     }
195
196     function showActions()
197     {
198         $this->startActions();
199         if (Event::handle('StartProfileListItemActionElements', array($this))) {
200             $this->showSubscribeButton();
201             $this->showMakeAdminForm();
202             $this->showGroupBlockForm();
203             Event::handle('EndProfileListItemActionElements', array($this));
204         }
205         $this->endActions();
206     }
207
208     function showMakeAdminForm()
209     {
210         $user = common_current_user();
211
212         if (!empty($user) &&
213             $user->id != $this->profile->id &&
214             ($user->isAdmin($this->group) || $user->hasRight(Right::MAKEGROUPADMIN)) &&
215             !$this->profile->isAdmin($this->group)) {
216             $this->out->elementStart('li', 'entity_make_admin');
217             $maf = new MakeAdminForm($this->out, $this->profile, $this->group,
218                                      $this->returnToArgs());
219             $maf->show();
220             $this->out->elementEnd('li');
221         }
222
223     }
224
225     function showGroupBlockForm()
226     {
227         $user = common_current_user();
228
229         if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
230             $this->out->elementStart('li', 'entity_block');
231             $bf = new GroupBlockForm($this->out, $this->profile, $this->group,
232                                      $this->returnToArgs());
233             $bf->show();
234             $this->out->elementEnd('li');
235         }
236     }
237
238     function linkAttributes()
239     {
240         $aAttrs = parent::linkAttributes();
241
242         if (common_config('nofollow', 'members')) {
243             $aAttrs['rel'] .= ' nofollow';
244         }
245
246         return $aAttrs;
247     }
248
249     function homepageAttributes()
250     {
251         $aAttrs = parent::linkAttributes();
252
253         if (common_config('nofollow', 'members')) {
254             $aAttrs['rel'] = 'nofollow';
255         }
256
257         return $aAttrs;
258     }
259
260     /**
261      * Fetch necessary return-to arguments for the profile forms
262      * to return to this list when they're done.
263      *
264      * @return array
265      */
266     protected function returnToArgs()
267     {
268         $args = array('action' => 'groupmembers',
269                       'nickname' => $this->group->nickname);
270         $page = $this->out->arg('page');
271         if ($page) {
272             $args['param-page'] = $page;
273         }
274         return $args;
275     }
276 }
277
278 /**
279  * Form for blocking a user from a group
280  *
281  * @category Form
282  * @package  StatusNet
283  * @author   Evan Prodromou <evan@status.net>
284  * @author   Sarven Capadisli <csarven@status.net>
285  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
286  * @link     http://status.net/
287  *
288  * @see      BlockForm
289  */
290 class GroupBlockForm extends Form
291 {
292     /**
293      * Profile of user to block
294      */
295
296     var $profile = null;
297
298     /**
299      * Group to block the user from
300      */
301
302     var $group = null;
303
304     /**
305      * Return-to args
306      */
307
308     var $args = null;
309
310     /**
311      * Constructor
312      *
313      * @param HTMLOutputter $out     output channel
314      * @param Profile       $profile profile of user to block
315      * @param User_group    $group   group to block user from
316      * @param array         $args    return-to args
317      */
318     function __construct($out=null, $profile=null, $group=null, $args=null)
319     {
320         parent::__construct($out);
321
322         $this->profile = $profile;
323         $this->group   = $group;
324         $this->args    = $args;
325     }
326
327     /**
328      * ID of the form
329      *
330      * @return int ID of the form
331      */
332     function id()
333     {
334         // This should be unique for the page.
335         return 'block-' . $this->profile->id;
336     }
337
338     /**
339      * class of the form
340      *
341      * @return string class of the form
342      */
343     function formClass()
344     {
345         return 'form_group_block';
346     }
347
348     /**
349      * Action of the form
350      *
351      * @return string URL of the action
352      */
353     function action()
354     {
355         return common_local_url('groupblock');
356     }
357
358     /**
359      * Legend of the Form
360      *
361      * @return void
362      */
363     function formLegend()
364     {
365         // TRANS: Form legend for form to block user from a group.
366         $this->out->element('legend', null, _('Block user from group'));
367     }
368
369     /**
370      * Data elements of the form
371      *
372      * @return void
373      */
374     function formData()
375     {
376         $this->out->hidden('blockto-' . $this->profile->id,
377                            $this->profile->id,
378                            'blockto');
379         $this->out->hidden('blockgroup-' . $this->group->id,
380                            $this->group->id,
381                            'blockgroup');
382         if ($this->args) {
383             foreach ($this->args as $k => $v) {
384                 $this->out->hidden('returnto-' . $k, $v);
385             }
386         }
387     }
388
389     /**
390      * Action elements
391      *
392      * @return void
393      */
394     function formActions()
395     {
396         $this->out->submit(
397             'submit',
398             // TRANS: Button text for the form that will block a user from a group.
399             _m('BUTTON','Block'),
400             'submit',
401             null,
402             // TRANS: Submit button title.
403             _m('TOOLTIP', 'Block this user'));
404     }
405 }
406
407 /**
408  * Form for making a user an admin for a group
409  *
410  * @category Form
411  * @package  StatusNet
412  * @author   Evan Prodromou <evan@status.net>
413  * @author   Sarven Capadisli <csarven@status.net>
414  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
415  * @link     http://status.net/
416  */
417 class MakeAdminForm extends Form
418 {
419     /**
420      * Profile of user to block
421      */
422     var $profile = null;
423
424     /**
425      * Group to block the user from
426      */
427     var $group = null;
428
429     /**
430      * Return-to args
431      */
432     var $args = null;
433
434     /**
435      * Constructor
436      *
437      * @param HTMLOutputter $out     output channel
438      * @param Profile       $profile profile of user to block
439      * @param User_group    $group   group to block user from
440      * @param array         $args    return-to args
441      */
442     function __construct($out=null, $profile=null, $group=null, $args=null)
443     {
444         parent::__construct($out);
445
446         $this->profile = $profile;
447         $this->group   = $group;
448         $this->args    = $args;
449     }
450
451     /**
452      * ID of the form
453      *
454      * @return int ID of the form
455      */
456     function id()
457     {
458         // This should be unique for the page.
459         return 'makeadmin-' . $this->profile->id;
460     }
461
462     /**
463      * class of the form
464      *
465      * @return string class of the form
466      */
467     function formClass()
468     {
469         return 'form_make_admin';
470     }
471
472     /**
473      * Action of the form
474      *
475      * @return string URL of the action
476      */
477     function action()
478     {
479         return common_local_url('makeadmin', array('nickname' => $this->group->nickname));
480     }
481
482     /**
483      * Legend of the Form
484      *
485      * @return void
486      */
487     function formLegend()
488     {
489         // TRANS: Form legend for form to make a user a group admin.
490         $this->out->element('legend', null, _('Make user an admin of the group'));
491     }
492
493     /**
494      * Data elements of the form
495      *
496      * @return void
497      */
498     function formData()
499     {
500         $this->out->hidden('profileid-' . $this->profile->id,
501                            $this->profile->id,
502                            'profileid');
503         $this->out->hidden('groupid-' . $this->group->id,
504                            $this->group->id,
505                            'groupid');
506         if ($this->args) {
507             foreach ($this->args as $k => $v) {
508                 $this->out->hidden('returnto-' . $k, $v);
509             }
510         }
511     }
512
513     /**
514      * Action elements
515      *
516      * @return void
517      */
518     function formActions()
519     {
520         $this->out->submit(
521           'submit',
522           // TRANS: Button text for the form that will make a user administrator.
523           _m('BUTTON','Make Admin'),
524           'submit',
525           null,
526           // TRANS: Submit button title.
527           _m('TOOLTIP','Make this user an admin'));
528     }
529 }