]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/groupaction.php
remove group nav
[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('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 define('MEMBERS_PER_SECTION', 27);
35
36 /**
37  * Base class for group actions, similar to ProfileAction
38  *
39  * @category Action
40  * @package  StatusNet
41  * @author   Zach Copley <zach@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  *
45  */
46 class GroupAction extends Action
47 {
48     protected $group;
49
50     function prepare($args)
51     {
52         parent::prepare($args);
53
54         $nickname_arg = $this->arg('nickname');
55         $nickname = common_canonical_nickname($nickname_arg);
56
57         // Permanent redirect on non-canonical nickname
58
59         if ($nickname_arg != $nickname) {
60             $args = array('nickname' => $nickname);
61             if ($this->page != 1) {
62                 $args['page'] = $this->page;
63             }
64             common_redirect(common_local_url('showgroup', $args), 301);
65             return false;
66         }
67
68         if (!$nickname) {
69             // TRANS: Client error displayed if no nickname argument was given requesting a group page.
70             $this->clientError(_('No nickname.'), 404);
71             return false;
72         }
73
74         $local = Local_group::staticGet('nickname', $nickname);
75
76         if (!$local) {
77             $alias = Group_alias::staticGet('alias', $nickname);
78             if ($alias) {
79                 $args = array('id' => $alias->group_id);
80                 if ($this->page != 1) {
81                     $args['page'] = $this->page;
82                 }
83                 common_redirect(common_local_url('groupbyid', $args), 301);
84                 return false;
85             } else {
86                 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
87                 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
88                 $this->clientError(_('No such group.'), 404);
89                 return false;
90             }
91         }
92
93         $this->group = User_group::staticGet('id', $local->group_id);
94
95         if (!$this->group) {
96                 // TRANS: Client error displayed if no local group with a given name was found requesting group page.
97             $this->clientError(_('No such group.'), 404);
98             return false;
99         }
100     }
101
102     function showProfileBlock()
103     {
104         $block = new GroupProfileBlock($this, $this->group);
105         $block->show();
106     }
107
108     /**
109      * Fill in the sidebar.
110      *
111      * @return void
112      */
113     function showSections()
114     {
115         $this->showMembers();
116         $cur = common_current_user();
117         if ($cur && $cur->isAdmin($this->group)) {
118             $this->showPending();
119             $this->showBlocked();
120         }
121         $this->showAdmins();
122         $cloud = new GroupTagCloudSection($this, $this->group);
123         $cloud->show();
124     }
125
126     /**
127      * Show mini-list of members
128      *
129      * @return void
130      */
131     function showMembers()
132     {
133         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
134
135         if (!$member) {
136             return;
137         }
138
139         $this->elementStart('div', array('id' => 'entity_members',
140                                          'class' => 'section'));
141
142         if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
143              
144             // TRANS: Header for mini list of group members on a group page (h2).
145             $this->elementStart('h2');
146
147             $this->element('a', array('href' => common_local_url('groupmembers', array('nickname' =>
148                                                                                        $this->group->nickname))),
149                            _('Members'));
150
151             $this->text(' ');
152
153             $this->text($this->group->getMemberCount());
154             
155             $this->elementEnd('h2');
156
157             $gmml = new GroupMembersMiniList($member, $this);
158             $cnt = $gmml->show();
159             if ($cnt == 0) {
160                 // TRANS: Description for mini list of group members on a group page when the group has no members.
161                 $this->element('p', null, _('(None)'));
162             }
163
164             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
165             //              for example http://identi.ca/group/statusnet. Broken?
166             if ($cnt > MEMBERS_PER_SECTION) {
167                 $this->element('a', array('href' => common_local_url('groupmembers',
168                                                                      array('nickname' => $this->group->nickname))),
169                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
170                                _('All members'));
171             }
172
173             Event::handle('EndShowGroupMembersMiniList', array($this));
174         }
175
176         $this->elementEnd('div');
177     }
178
179
180     function showPending()
181     {
182         if ($this->group->join_policy != User_group::JOIN_POLICY_MODERATE) {
183             return;
184         }
185
186         $pending = $this->group->getQueueCount();
187
188         if (!$pending) {
189             return;
190         }
191
192         $request = $this->group->getRequests(0, MEMBERS_PER_SECTION);
193
194         if (!$request) {
195             return;
196         }
197
198         $this->elementStart('div', array('id' => 'entity_pending',
199                                          'class' => 'section'));
200
201         if (Event::handle('StartShowGroupPendingMiniList', array($this))) {
202              
203             $this->elementStart('h2');
204
205             $this->element('a', array('href' => common_local_url('groupqueue', array('nickname' =>
206                                                                                      $this->group->nickname))),
207                            _('Pending'));
208
209             $this->text(' ');
210
211             $this->text($pending);
212             
213             $this->elementEnd('h2');
214
215             $gmml = new ProfileMiniList($request, $this);
216             $gmml->show();
217
218             Event::handle('EndShowGroupPendingMiniList', array($this));
219         }
220
221         $this->elementEnd('div');
222     }
223
224     function showBlocked()
225     {
226         $blocked = $this->group->getBlocked(0, MEMBERS_PER_SECTION);
227
228         if (!$blocked) {
229             return;
230         }
231
232         $this->elementStart('div', array('id' => 'entity_blocked',
233                                          'class' => 'section'));
234
235         if (Event::handle('StartShowGroupBlockedMiniList', array($this))) {
236              
237             $this->elementStart('h2');
238
239             $this->element('a', array('href' => common_local_url('blockedfromgroup', array('nickname' =>
240                                                                                            $this->group->nickname))),
241                            _('Blocked'));
242
243             $this->text(' ');
244
245             $this->text($this->group->getBlockedCount());
246             
247             $this->elementEnd('h2');
248
249             $gmml = new GroupBlockedMiniList($blocked, $this);
250             $cnt = $gmml->show();
251             if ($cnt == 0) {
252                 // TRANS: Description for mini list of group members on a group page when the group has no members.
253                 $this->element('p', null, _('(None)'));
254             }
255
256             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
257             //              for example http://identi.ca/group/statusnet. Broken?
258             if ($cnt > MEMBERS_PER_SECTION) {
259                 $this->element('a', array('href' => common_local_url('blockedfromgroup',
260                                                                      array('nickname' => $this->group->nickname))),
261                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
262                                _('All members'));
263             }
264
265             Event::handle('EndShowGroupBlockedMiniList', array($this));
266         }
267
268         $this->elementEnd('div');
269     }
270
271     /**
272      * Show list of admins
273      *
274      * @return void
275      */
276     function showAdmins()
277     {
278         $adminSection = new GroupAdminSection($this, $this->group);
279         $adminSection->show();
280     }
281
282
283     function noticeFormOptions()
284     {
285         $options = parent::noticeFormOptions();
286         $cur = common_current_user();
287
288         if (!empty($cur) && $cur->isMember($this->group)) {
289             $options['to_group'] =  $this->group;
290         }
291
292         return $options;
293     }
294 }
295
296 class GroupAdminSection extends ProfileSection
297 {
298     var $group;
299
300     function __construct($out, $group)
301     {
302         parent::__construct($out);
303         $this->group = $group;
304     }
305
306     function getProfiles()
307     {
308         return $this->group->getAdmins();
309     }
310
311     function title()
312     {
313         // TRANS: Title for list of group administrators on a group page.
314         return _m('TITLE','Admins');
315     }
316
317     function divId()
318     {
319         return 'group_admins';
320     }
321
322     function moreUrl()
323     {
324         return null;
325     }
326 }
327
328 class GroupMembersMiniList extends ProfileMiniList
329 {
330     function newListItem($profile)
331     {
332         return new GroupMembersMiniListItem($profile, $this->action);
333     }
334 }
335
336 class GroupMembersMiniListItem extends ProfileMiniListItem
337 {
338     function linkAttributes()
339     {
340         $aAttrs = parent::linkAttributes();
341
342         if (common_config('nofollow', 'members')) {
343             $aAttrs['rel'] .= ' nofollow';
344         }
345
346         return $aAttrs;
347     }
348 }
349
350 class GroupBlockedMiniList extends ProfileMiniList
351 {
352     function newListItem($profile)
353     {
354         return new GroupBlockedMiniListItem($profile, $this->action);
355     }
356 }
357
358 class GroupBlockedMiniListItem extends ProfileMiniListItem
359 {
360     function linkAttributes()
361     {
362         $aAttrs = parent::linkAttributes();
363
364         if (common_config('nofollow', 'members')) {
365             $aAttrs['rel'] .= ' nofollow';
366         }
367
368         return $aAttrs;
369     }
370 }
371
372 class ThreadingGroupNoticeStream extends ThreadingNoticeStream
373 {
374     function __construct($group, $profile)
375     {
376         parent::__construct(new GroupNoticeStream($group, $profile));
377     }
378 }
379