]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/groupaction.php
39d48044812326786527945915cdab52afa37a89
[quix0rs-gnu-social.git] / lib / groupaction.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Base class for group actions
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  Action
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2009-2011 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('GNUSOCIAL')) { exit(1); }
31
32 define('MEMBERS_PER_SECTION', 27);
33
34 /**
35  * Base class for group actions, similar to ProfileAction
36  *
37  * @category Action
38  * @package  StatusNet
39  * @author   Zach Copley <zach@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  */
43 class GroupAction extends Action
44 {
45     protected $group;
46
47     protected function prepare(array $args=array())
48     {
49         parent::prepare($args);
50
51         $nickname_arg = $this->arg('nickname');
52         $nickname = common_canonical_nickname($nickname_arg);
53
54         // Permanent redirect on non-canonical nickname
55
56         if ($nickname_arg != $nickname) {
57             $args = array('nickname' => $nickname);
58             if ($this->page != 1) {
59                 $args['page'] = $this->page;
60             }
61             common_redirect(common_local_url('showgroup', $args), 301);
62         }
63
64         if (!$nickname) {
65             // TRANS: Client error displayed if no nickname argument was given requesting a group page.
66             $this->clientError(_('No nickname.'), 404);
67         }
68
69         $local = Local_group::getKV('nickname', $nickname);
70
71         if (!$local) {
72             $alias = Group_alias::getKV('alias', $nickname);
73             if ($alias) {
74                 $args = array('id' => $alias->group_id);
75                 if ($this->page != 1) {
76                     $args['page'] = $this->page;
77                 }
78                 common_redirect(common_local_url('groupbyid', $args), 301);
79             } else {
80                 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
81                 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
82                 $this->clientError(_('No such group.'), 404);
83             }
84         }
85
86         $this->group = User_group::getKV('id', $local->group_id);
87
88         if (!$this->group) {
89             // TRANS: Client error displayed if no local group with a given name was found requesting group page.
90             $this->clientError(_('No such group.'), 404);
91         }
92     }
93
94     function showProfileBlock()
95     {
96         $block = new GroupProfileBlock($this, $this->group);
97         $block->show();
98     }
99
100     /**
101      * Fill in the sidebar.
102      *
103      * @return void
104      */
105     function showSections()
106     {
107         $this->showMembers();
108         $cur = common_current_user();
109         if ($cur && $cur->isAdmin($this->group)) {
110             $this->showPending();
111             $this->showBlocked();
112         }
113
114         $this->showAdmins();
115
116         if (!common_config('performance', 'high')) {
117             $cloud = new GroupTagCloudSection($this, $this->group);
118             $cloud->show();
119         }
120     }
121
122     /**
123      * Show mini-list of members
124      *
125      * @return void
126      */
127     function showMembers()
128     {
129         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
130
131         if (!$member) {
132             return;
133         }
134
135         $this->elementStart('div', array('id' => 'entity_members',
136                                          'class' => 'section'));
137
138         if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
139             $this->elementStart('h2');
140
141             $this->element('a', array('href' => common_local_url('groupmembers', array('nickname' =>
142                                                                                        $this->group->nickname))),
143                            // TRANS: Header for mini list of group members on a group page (h2).
144                            _('Members'));
145
146             $this->text(' ');
147
148             $this->text($this->group->getMemberCount());
149
150             $this->elementEnd('h2');
151
152             $gmml = new GroupMembersMiniList($member, $this);
153             $cnt = $gmml->show();
154             if ($cnt == 0) {
155                 // TRANS: Description for mini list of group members on a group page when the group has no members.
156                 $this->element('p', null, _('(None)'));
157             }
158
159             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
160             //              for example http://identi.ca/group/statusnet. Broken?
161             if ($cnt > MEMBERS_PER_SECTION) {
162                 $this->element('a', array('href' => common_local_url('groupmembers',
163                                                                      array('nickname' => $this->group->nickname))),
164                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
165                                _('All members'));
166             }
167
168             Event::handle('EndShowGroupMembersMiniList', array($this));
169         }
170
171         $this->elementEnd('div');
172     }
173
174     function showPending()
175     {
176         if ($this->group->join_policy != User_group::JOIN_POLICY_MODERATE) {
177             return;
178         }
179
180         $pending = $this->group->getQueueCount();
181
182         if (!$pending) {
183             return;
184         }
185
186         $request = $this->group->getRequests(0, MEMBERS_PER_SECTION);
187
188         if (!$request) {
189             return;
190         }
191
192         $this->elementStart('div', array('id' => 'entity_pending',
193                                          'class' => 'section'));
194
195         if (Event::handle('StartShowGroupPendingMiniList', array($this))) {
196
197             $this->elementStart('h2');
198
199             $this->element('a', array('href' => common_local_url('groupqueue', array('nickname' =>
200                                                                                      $this->group->nickname))),
201                            // TRANS: Header for mini list of users with a pending membership request on a group page (h2).
202                            _('Pending'));
203
204             $this->text(' ');
205
206             $this->text($pending);
207
208             $this->elementEnd('h2');
209
210             $gmml = new ProfileMiniList($request, $this);
211             $gmml->show();
212
213             Event::handle('EndShowGroupPendingMiniList', array($this));
214         }
215
216         $this->elementEnd('div');
217     }
218
219     function showBlocked()
220     {
221         $blocked = $this->group->getBlocked(0, MEMBERS_PER_SECTION);
222
223         $this->elementStart('div', array('id' => 'entity_blocked',
224                                          'class' => 'section'));
225
226         if (Event::handle('StartShowGroupBlockedMiniList', array($this))) {
227
228             $this->elementStart('h2');
229
230             $this->element('a', array('href' => common_local_url('blockedfromgroup', array('nickname' =>
231                                                                                            $this->group->nickname))),
232                            // TRANS: Header for mini list of users that are blocked in a group page (h2).
233                            _('Blocked'));
234
235             $this->text(' ');
236
237             $this->text($this->group->getBlockedCount());
238
239             $this->elementEnd('h2');
240
241             $gmml = new GroupBlockedMiniList($blocked, $this);
242             $cnt = $gmml->show();
243             if ($cnt == 0) {
244                 // TRANS: Description for mini list of group members on a group page when the group has no members.
245                 $this->element('p', null, _('(None)'));
246             }
247
248             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
249             //              for example http://identi.ca/group/statusnet. Broken?
250             if ($cnt > MEMBERS_PER_SECTION) {
251                 $this->element('a', array('href' => common_local_url('blockedfromgroup',
252                                                                      array('nickname' => $this->group->nickname))),
253                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
254                                _('All members'));
255             }
256
257             Event::handle('EndShowGroupBlockedMiniList', array($this));
258         }
259
260         $this->elementEnd('div');
261     }
262
263     /**
264      * Show list of admins
265      *
266      * @return void
267      */
268     function showAdmins()
269     {
270         $adminSection = new GroupAdminSection($this, $this->group);
271         $adminSection->show();
272     }
273
274     function noticeFormOptions()
275     {
276         $options = parent::noticeFormOptions();
277         $cur = common_current_user();
278
279         if (!empty($cur) && $cur->isMember($this->group)) {
280             $options['to_group'] =  $this->group;
281         }
282
283         return $options;
284     }
285
286     function getGroup()
287     {
288         return $this->group;
289     }
290 }