]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/groupqueue.php
XSS vulnerability when remote-subscribing
[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 GroupAction
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     protected function prepare(array $args=array())
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         }
73
74         if (!$nickname) {
75             // TRANS: Client error displayed when trying to view group members without providing a group nickname.
76             $this->clientError(_('No nickname.'), 404);
77         }
78
79         $local = Local_group::getKV('nickname', $nickname);
80
81         if (!$local) {
82             // TRANS: Client error displayed when trying to view group members for a non-existing group.
83             $this->clientError(_('No such group.'), 404);
84         }
85
86         $this->group = User_group::getKV('id', $local->group_id);
87
88         if (!$this->group) {
89             // TRANS: Client error displayed when trying to view group members for an object that is not a group.
90             $this->clientError(_('No such group.'), 404);
91         }
92
93         $cur = common_current_user();
94         if (!$cur || !$cur->isAdmin($this->group)) {
95             // TRANS: Client error displayed when trying to approve group applicants without being a group administrator.
96             $this->clientError(_('Only the group admin may approve users.'));
97         }
98         return true;
99     }
100
101     function title()
102     {
103         if ($this->page == 1) {
104             // TRANS: Title of the first page showing pending group members still awaiting approval to join the group.
105             // TRANS: %s is the name of the group.
106             return sprintf(_('%s group members awaiting approval'),
107                            $this->group->nickname);
108         } else {
109             // TRANS: Title of all but the first page showing pending group members still awaiting approval to join the group.
110             // TRANS: %1$s is the name of the group, %2$d is the page number of the members list.
111             return sprintf(_('%1$s group members awaiting approval, page %2$d'),
112                            $this->group->nickname,
113                            $this->page);
114         }
115     }
116
117     protected function handle()
118     {
119         parent::handle();
120         $this->showPage();
121     }
122
123     function showPageNotice()
124     {
125         $this->element('p', 'instructions',
126                        // TRANS: Page notice for group members page.
127                        _('A list of users awaiting approval to join this group.'));
128     }
129
130     function showContent()
131     {
132         $offset = ($this->page-1) * PROFILES_PER_PAGE;
133         $limit =  PROFILES_PER_PAGE + 1;
134
135         $cnt = 0;
136
137         $members = $this->group->getRequests($offset, $limit);
138
139         if ($members) {
140             // @fixme change!
141             $member_list = new GroupQueueList($members, $this->group, $this);
142             $cnt = $member_list->show();
143         }
144
145         $members->free();
146
147         $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
148                           $this->page, 'groupqueue',
149                           array('nickname' => $this->group->nickname));
150     }
151 }
152
153 // @todo FIXME: documentation missing.
154 class GroupQueueList extends GroupMemberList
155 {
156     function newListItem($profile)
157     {
158         return new GroupQueueListItem($profile, $this->group, $this->action);
159     }
160 }
161
162 // @todo FIXME: documentation missing.
163 class GroupQueueListItem extends GroupMemberListItem
164 {
165     function showActions()
166     {
167         $this->startActions();
168         if (Event::handle('StartProfileListItemActionElements', array($this))) {
169             $this->showApproveButtons();
170             Event::handle('EndProfileListItemActionElements', array($this));
171         }
172         $this->endActions();
173     }
174
175     function showApproveButtons()
176     {
177         $this->out->elementStart('li', 'entity_approval');
178         $form = new ApproveGroupForm($this->out, $this->group, $this->profile);
179         $form->show();
180         $this->out->elementEnd('li');
181     }
182 }