]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/groupaction.php
move pending queue to sidebar
[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      * Local menu
110      *
111      * @return void
112      */
113
114     function showObjectNav()
115     {
116         $nav = new GroupNav($this, $this->group);
117         $nav->show();
118     }
119
120
121     /**
122      * Fill in the sidebar.
123      *
124      * @return void
125      */
126     function showSections()
127     {
128         $this->showMembers();
129         $cur = common_current_user();
130         if ($cur && $cur->isAdmin($this->group)) {
131             $this->showPending();
132             $this->showBlocked();
133         }
134         $this->showAdmins();
135         $cloud = new GroupTagCloudSection($this, $this->group);
136         $cloud->show();
137     }
138
139     /**
140      * Show mini-list of members
141      *
142      * @return void
143      */
144     function showMembers()
145     {
146         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
147
148         if (!$member) {
149             return;
150         }
151
152         $this->elementStart('div', array('id' => 'entity_members',
153                                          'class' => 'section'));
154
155         if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
156              
157             // TRANS: Header for mini list of group members on a group page (h2).
158             $this->elementStart('h2');
159
160             $this->element('a', array('href' => common_local_url('groupmembers', array('nickname' =>
161                                                                                        $this->group->nickname))),
162                            _('Members'));
163
164             $this->text(' ');
165
166             $this->text($this->group->getMemberCount());
167             
168             $this->elementEnd('h2');
169
170             $gmml = new GroupMembersMiniList($member, $this);
171             $cnt = $gmml->show();
172             if ($cnt == 0) {
173                 // TRANS: Description for mini list of group members on a group page when the group has no members.
174                 $this->element('p', null, _('(None)'));
175             }
176
177             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
178             //              for example http://identi.ca/group/statusnet. Broken?
179             if ($cnt > MEMBERS_PER_SECTION) {
180                 $this->element('a', array('href' => common_local_url('groupmembers',
181                                                                      array('nickname' => $this->group->nickname))),
182                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
183                                _('All members'));
184             }
185
186             Event::handle('EndShowGroupMembersMiniList', array($this));
187         }
188
189         $this->elementEnd('div');
190     }
191
192
193     function showPending()
194     {
195         if ($this->group->join_policy != User_group::JOIN_POLICY_MODERATE) {
196             return;
197         }
198
199         $pending = $this->group->getQueueCount();
200
201         if (!$pending) {
202             return;
203         }
204
205         $request = $this->group->getRequests(0, MEMBERS_PER_SECTION);
206
207         if (!$request) {
208             return;
209         }
210
211         $this->elementStart('div', array('id' => 'entity_pending',
212                                          'class' => 'section'));
213
214         if (Event::handle('StartShowGroupPendingMiniList', array($this))) {
215              
216             $this->elementStart('h2');
217
218             $this->element('a', array('href' => common_local_url('groupqueue', array('nickname' =>
219                                                                                      $this->group->nickname))),
220                            _('Pending'));
221
222             $this->text(' ');
223
224             $this->text($pending);
225             
226             $this->elementEnd('h2');
227
228             $gmml = new ProfileMiniList($request, $this);
229             $gmml->show();
230
231             Event::handle('EndShowGroupPendingMiniList', array($this));
232         }
233
234         $this->elementEnd('div');
235     }
236
237     function showBlocked()
238     {
239         $blocked = $this->group->getBlocked(0, MEMBERS_PER_SECTION);
240
241         if (!$blocked) {
242             return;
243         }
244
245         $this->elementStart('div', array('id' => 'entity_blocked',
246                                          'class' => 'section'));
247
248         if (Event::handle('StartShowGroupBlockedMiniList', array($this))) {
249              
250             $this->elementStart('h2');
251
252             $this->element('a', array('href' => common_local_url('blockedfromgroup', array('nickname' =>
253                                                                                            $this->group->nickname))),
254                            _('Blocked'));
255
256             $this->text(' ');
257
258             $this->text($this->group->getBlockedCount());
259             
260             $this->elementEnd('h2');
261
262             $gmml = new GroupBlockedMiniList($blocked, $this);
263             $cnt = $gmml->show();
264             if ($cnt == 0) {
265                 // TRANS: Description for mini list of group members on a group page when the group has no members.
266                 $this->element('p', null, _('(None)'));
267             }
268
269             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
270             //              for example http://identi.ca/group/statusnet. Broken?
271             if ($cnt > MEMBERS_PER_SECTION) {
272                 $this->element('a', array('href' => common_local_url('blockedfromgroup',
273                                                                      array('nickname' => $this->group->nickname))),
274                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
275                                _('All members'));
276             }
277
278             Event::handle('EndShowGroupBlockedMiniList', array($this));
279         }
280
281         $this->elementEnd('div');
282     }
283
284     /**
285      * Show list of admins
286      *
287      * @return void
288      */
289     function showAdmins()
290     {
291         $adminSection = new GroupAdminSection($this, $this->group);
292         $adminSection->show();
293     }
294
295
296     function noticeFormOptions()
297     {
298         $options = parent::noticeFormOptions();
299         $cur = common_current_user();
300
301         if (!empty($cur) && $cur->isMember($this->group)) {
302             $options['to_group'] =  $this->group;
303         }
304
305         return $options;
306     }
307 }
308
309 class GroupAdminSection extends ProfileSection
310 {
311     var $group;
312
313     function __construct($out, $group)
314     {
315         parent::__construct($out);
316         $this->group = $group;
317     }
318
319     function getProfiles()
320     {
321         return $this->group->getAdmins();
322     }
323
324     function title()
325     {
326         // TRANS: Title for list of group administrators on a group page.
327         return _m('TITLE','Admins');
328     }
329
330     function divId()
331     {
332         return 'group_admins';
333     }
334
335     function moreUrl()
336     {
337         return null;
338     }
339 }
340
341 class GroupMembersMiniList extends ProfileMiniList
342 {
343     function newListItem($profile)
344     {
345         return new GroupMembersMiniListItem($profile, $this->action);
346     }
347 }
348
349 class GroupMembersMiniListItem extends ProfileMiniListItem
350 {
351     function linkAttributes()
352     {
353         $aAttrs = parent::linkAttributes();
354
355         if (common_config('nofollow', 'members')) {
356             $aAttrs['rel'] .= ' nofollow';
357         }
358
359         return $aAttrs;
360     }
361 }
362
363 class GroupBlockedMiniList extends ProfileMiniList
364 {
365     function newListItem($profile)
366     {
367         return new GroupBlockedMiniListItem($profile, $this->action);
368     }
369 }
370
371 class GroupBlockedMiniListItem extends ProfileMiniListItem
372 {
373     function linkAttributes()
374     {
375         $aAttrs = parent::linkAttributes();
376
377         if (common_config('nofollow', 'members')) {
378             $aAttrs['rel'] .= ' nofollow';
379         }
380
381         return $aAttrs;
382     }
383 }
384
385 class ThreadingGroupNoticeStream extends ThreadingNoticeStream
386 {
387     function __construct($group, $profile)
388     {
389         parent::__construct(new GroupNoticeStream($group, $profile));
390     }
391 }
392