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