]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/groupaction.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[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         $this->showStatistics();
130         $this->showAdmins();
131         $cloud = new GroupTagCloudSection($this, $this->group);
132         $cloud->show();
133     }
134
135     /**
136      * Show mini-list of members
137      *
138      * @return void
139      */
140     function showMembers()
141     {
142         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
143
144         if (!$member) {
145             return;
146         }
147
148         $this->elementStart('div', array('id' => 'entity_members',
149                                          'class' => 'section'));
150
151         if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
152
153             // TRANS: Header for mini list of group members on a group page (h2).
154             $this->element('h2', null, _('Members'));
155
156             $gmml = new GroupMembersMiniList($member, $this);
157             $cnt = $gmml->show();
158             if ($cnt == 0) {
159                 // TRANS: Description for mini list of group members on a group page when the group has no members.
160                 $this->element('p', null, _('(None)'));
161             }
162
163             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
164             //              for example http://identi.ca/group/statusnet. Broken?
165             if ($cnt > MEMBERS_PER_SECTION) {
166                 $this->element('a', array('href' => common_local_url('groupmembers',
167                                                                      array('nickname' => $this->group->nickname))),
168                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
169                                _('All members'));
170             }
171
172             Event::handle('EndShowGroupMembersMiniList', array($this));
173         }
174
175         $this->elementEnd('div');
176     }
177
178     /**
179      * Show list of admins
180      *
181      * @return void
182      */
183     function showAdmins()
184     {
185         $adminSection = new GroupAdminSection($this, $this->group);
186         $adminSection->show();
187     }
188
189     /**
190      * Show some statistics
191      *
192      * @return void
193      */
194     function showStatistics()
195     {
196         $this->elementStart('div', array('id' => 'entity_statistics',
197                                          'class' => 'section'));
198
199         // TRANS: Header for group statistics on a group page (h2).
200         $this->element('h2', null, _('Statistics'));
201
202         $this->elementStart('dl');
203
204         // TRANS: Label for group creation date.
205         $this->element('dt', null, _m('LABEL','Created'));
206         $this->element('dd', 'entity_created', date('j M Y',
207                                                  strtotime($this->group->created)));
208         // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
209         // TRANS: Label for member count in statistics on group page.
210         $this->element('dt', null, _m('LABEL','Members'));
211         $this->element('dd', null, $this->group->getMemberCount());
212         $this->elementEnd('dl');
213
214         $this->elementEnd('div');
215     }
216
217
218     function noticeFormOptions()
219     {
220         $options = parent::noticeFormOptions();
221         $cur = common_current_user();
222
223         if (!empty($cur) && $cur->isMember($this->group)) {
224             $options['to_group'] =  $this->group;
225         }
226
227         return $options;
228     }
229 }
230
231 class GroupAdminSection extends ProfileSection
232 {
233     var $group;
234
235     function __construct($out, $group)
236     {
237         parent::__construct($out);
238         $this->group = $group;
239     }
240
241     function getProfiles()
242     {
243         return $this->group->getAdmins();
244     }
245
246     function title()
247     {
248         // TRANS: Title for list of group administrators on a group page.
249         return _m('TITLE','Admins');
250     }
251
252     function divId()
253     {
254         return 'group_admins';
255     }
256
257     function moreUrl()
258     {
259         return null;
260     }
261 }
262
263 class GroupMembersMiniList extends ProfileMiniList
264 {
265     function newListItem($profile)
266     {
267         return new GroupMembersMiniListItem($profile, $this->action);
268     }
269 }
270
271 class GroupMembersMiniListItem extends ProfileMiniListItem
272 {
273     function linkAttributes()
274     {
275         $aAttrs = parent::linkAttributes();
276
277         if (common_config('nofollow', 'members')) {
278             $aAttrs['rel'] .= ' nofollow';
279         }
280
281         return $aAttrs;
282     }
283 }
284
285 class ThreadingGroupNoticeStream extends ThreadingNoticeStream
286 {
287     function __construct($group, $profile)
288     {
289         parent::__construct(new GroupNoticeStream($group, $profile));
290     }
291 }
292