]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/groupqueue.php
Merge branch 'master' into 1.0.x
[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     // @todo 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         $cur = common_current_user();
98         if (!$cur || !$cur->isAdmin($this->group)) {
99             // TRANS: Client error displayed when trying to approve group applicants without being a group administrator.
100             $this->clientError(_('Only the group admin may approve users.'));
101             return false;
102         }
103         return true;
104     }
105
106     function title()
107     {
108         if ($this->page == 1) {
109             // TRANS: Title of the first page showing pending group members still awaiting approval to join the group.
110             // TRANS: %s is the name of the group.
111             return sprintf(_('%s group members awaiting approval'),
112                            $this->group->nickname);
113         } else {
114             // TRANS: Title of all but the first page showing pending group members still awaiting approval to join the group.
115             // TRANS: %1$s is the name of the group, %2$d is the page number of the members list.
116             return sprintf(_('%1$s group members awaiting approval, page %2$d'),
117                            $this->group->nickname,
118                            $this->page);
119         }
120     }
121
122     function handle($args)
123     {
124         parent::handle($args);
125         $this->showPage();
126     }
127
128     function showPageNotice()
129     {
130         $this->element('p', 'instructions',
131                        // TRANS: Page notice for group members page.
132                        _('A list of users awaiting approval to join this group.'));
133     }
134
135     function showObjectNav()
136     {
137         $nav = new GroupNav($this, $this->group);
138         $nav->show();
139     }
140
141     function showContent()
142     {
143         $offset = ($this->page-1) * PROFILES_PER_PAGE;
144         $limit =  PROFILES_PER_PAGE + 1;
145
146         $cnt = 0;
147
148         $members = $this->group->getRequests($offset, $limit);
149
150         if ($members) {
151             // @fixme change!
152             $member_list = new GroupQueueList($members, $this->group, $this);
153             $cnt = $member_list->show();
154         }
155
156         $members->free();
157
158         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
159                           $this->page, 'groupqueue',
160                           array('nickname' => $this->group->nickname));
161     }
162 }
163
164 // @todo FIXME: documentation missing.
165 class GroupQueueList extends GroupMemberList
166 {
167     function newListItem($profile)
168     {
169         return new GroupQueueListItem($profile, $this->group, $this->action);
170     }
171 }
172
173 // @todo FIXME: documentation missing.
174 class GroupQueueListItem extends GroupMemberListItem
175 {
176     function showActions()
177     {
178         $this->startActions();
179         if (Event::handle('StartProfileListItemActionElements', array($this))) {
180             $this->showApproveButtons();
181             Event::handle('EndProfileListItemActionElements', array($this));
182         }
183         $this->endActions();
184     }
185
186     function showApproveButtons()
187     {
188         $this->out->elementStart('li', 'entity_approval');
189         $form = new ApproveGroupForm($this->out, $this->group, $this->profile);
190         $form->show();
191         $this->out->elementEnd('li');
192     }
193 }