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