]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
Merge commit 'refs/merge-requests/157' of git://gitorious.org/statusnet/mainline...
[quix0rs-gnu-social.git] / actions / showgroup.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Group main page
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  Group
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2008-2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/noticelist.php';
36 require_once INSTALLDIR.'/lib/feedlist.php';
37
38 define('MEMBERS_PER_SECTION', 27);
39
40 /**
41  * Group main page
42  *
43  * @category Group
44  * @package  StatusNet
45  * @author   Evan Prodromou <evan@status.net>
46  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47  * @link     http://status.net/
48  */
49 class ShowgroupAction extends Action
50 {
51     /** page we're viewing. */
52     var $page = null;
53     var $userProfile = null;
54     var $notice = null;
55
56     /**
57      * Is this page read-only?
58      *
59      * @return boolean true
60      */
61     function isReadOnly($args)
62     {
63         return true;
64     }
65
66     /**
67      * Title of the page
68      *
69      * @return string page title, with page number
70      */
71     function title()
72     {
73         $base = $this->group->getFancyName();
74
75         if ($this->page == 1) {
76             // TRANS: Page title for first group page. %s is a group name.
77             return sprintf(_('%s group'), $base);
78         } else {
79             // TRANS: Page title for any but first group page.
80             // TRANS: %1$s is a group name, $2$s is a page number.
81             return sprintf(_('%1$s group, page %2$d'),
82                            $base,
83                            $this->page);
84         }
85     }
86
87     /**
88      * Prepare the action
89      *
90      * Reads and validates arguments and instantiates the attributes.
91      *
92      * @param array $args $_REQUEST args
93      *
94      * @return boolean success flag
95      */
96     function prepare($args)
97     {
98         parent::prepare($args);
99
100         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
101
102         $nickname_arg = $this->arg('nickname');
103         $nickname = common_canonical_nickname($nickname_arg);
104
105         // Permanent redirect on non-canonical nickname
106
107         if ($nickname_arg != $nickname) {
108             $args = array('nickname' => $nickname);
109             if ($this->page != 1) {
110                 $args['page'] = $this->page;
111             }
112             common_redirect(common_local_url('showgroup', $args), 301);
113             return false;
114         }
115
116         if (!$nickname) {
117             // TRANS: Client error displayed if no nickname argument was given requesting a group page.
118             $this->clientError(_('No nickname.'), 404);
119             return false;
120         }
121
122         $local = Local_group::staticGet('nickname', $nickname);
123
124         if (!$local) {
125             $alias = Group_alias::staticGet('alias', $nickname);
126             if ($alias) {
127                 $args = array('id' => $alias->group_id);
128                 if ($this->page != 1) {
129                     $args['page'] = $this->page;
130                 }
131                 common_redirect(common_local_url('groupbyid', $args), 301);
132                 return false;
133             } else {
134                 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
135                 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
136                 $this->clientError(_('No such group.'), 404);
137                 return false;
138             }
139         }
140
141         $this->group = User_group::staticGet('id', $local->group_id);
142
143         if (!$this->group) {
144                 // TRANS: Client error displayed if no local group with a given name was found requesting group page.
145             $this->clientError(_('No such group.'), 404);
146             return false;
147         }
148
149         $this->userProfile = Profile::current();
150
151         $stream = new ThreadingGroupNoticeStream($this->group, $this->userProfile);
152
153         $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
154                                             NOTICES_PER_PAGE + 1);
155
156         common_set_returnto($this->selfUrl());
157
158         return true;
159     }
160
161     /**
162      * Handle the request
163      *
164      * Shows a profile for the group, some controls, and a list of
165      * group notices.
166      *
167      * @return void
168      */
169     function handle($args)
170     {
171         $this->showPage();
172     }
173
174     /**
175      * Local menu
176      *
177      * @return void
178      */
179     function showObjectNav()
180     {
181         $nav = new GroupNav($this, $this->group);
182         $nav->show();
183     }
184
185     /**
186      * Show the page content
187      *
188      * Shows a group profile and a list of group notices
189      */
190     function showContent()
191     {
192         $this->showGroupNotices();
193     }
194
195     /**
196      * Show the group notices
197      *
198      * @return void
199      */
200     function showGroupNotices()
201     {
202         $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
203         $cnt = $nl->show();
204
205         $this->pagination($this->page > 1,
206                           $cnt > NOTICES_PER_PAGE,
207                           $this->page,
208                           'showgroup',
209                           array('nickname' => $this->group->nickname));
210     }
211
212     /**
213      * Get a list of the feeds for this page
214      *
215      * @return void
216      */
217     function getFeeds()
218     {
219         $url =
220           common_local_url('grouprss',
221                            array('nickname' => $this->group->nickname));
222
223         return array(new Feed(Feed::JSON,
224                               common_local_url('ApiTimelineGroup',
225                                                array('format' => 'as',
226                                                      'id' => $this->group->id)),
227                               // TRANS: Tooltip for feed link. %s is a group nickname.
228                               sprintf(_('Notice feed for %s group (Activity Streams JSON)'),
229                                       $this->group->nickname)),
230                     new Feed(Feed::RSS1,
231                               common_local_url('grouprss',
232                                                array('nickname' => $this->group->nickname)),
233                               // TRANS: Tooltip for feed link. %s is a group nickname.
234                               sprintf(_('Notice feed for %s group (RSS 1.0)'),
235                                       $this->group->nickname)),
236                      new Feed(Feed::RSS2,
237                               common_local_url('ApiTimelineGroup',
238                                                array('format' => 'rss',
239                                                      'id' => $this->group->id)),
240                               // TRANS: Tooltip for feed link. %s is a group nickname.
241                               sprintf(_('Notice feed for %s group (RSS 2.0)'),
242                                       $this->group->nickname)),
243                      new Feed(Feed::ATOM,
244                               common_local_url('ApiTimelineGroup',
245                                                array('format' => 'atom',
246                                                      'id' => $this->group->id)),
247                               // TRANS: Tooltip for feed link. %s is a group nickname.
248                               sprintf(_('Notice feed for %s group (Atom)'),
249                                       $this->group->nickname)),
250                      new Feed(Feed::FOAF,
251                               common_local_url('foafgroup',
252                                                array('nickname' => $this->group->nickname)),
253                               // TRANS: Tooltip for feed link. %s is a group nickname.
254                               sprintf(_('FOAF for %s group'),
255                                        $this->group->nickname)));
256     }
257
258     /**
259      * Fill in the sidebar.
260      *
261      * @return void
262      */
263     function showSections()
264     {
265         $this->showMembers();
266         $this->showStatistics();
267         $this->showAdmins();
268         $cloud = new GroupTagCloudSection($this, $this->group);
269         $cloud->show();
270     }
271
272     /**
273      * Show mini-list of members
274      *
275      * @return void
276      */
277     function showMembers()
278     {
279         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
280
281         if (!$member) {
282             return;
283         }
284
285         $this->elementStart('div', array('id' => 'entity_members',
286                                          'class' => 'section'));
287
288         if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
289
290             // TRANS: Header for mini list of group members on a group page (h2).
291             $this->element('h2', null, _('Members'));
292
293             $gmml = new GroupMembersMiniList($member, $this);
294             $cnt = $gmml->show();
295             if ($cnt == 0) {
296                 // TRANS: Description for mini list of group members on a group page when the group has no members.
297                 $this->element('p', null, _('(None)'));
298             }
299
300             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
301             //              for example http://identi.ca/group/statusnet. Broken?
302             if ($cnt > MEMBERS_PER_SECTION) {
303                 $this->element('a', array('href' => common_local_url('groupmembers',
304                                                                      array('nickname' => $this->group->nickname))),
305                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
306                                _('All members'));
307             }
308
309             Event::handle('EndShowGroupMembersMiniList', array($this));
310         }
311
312         $this->elementEnd('div');
313     }
314
315     /**
316      * Show list of admins
317      *
318      * @return void
319      */
320     function showAdmins()
321     {
322         $adminSection = new GroupAdminSection($this, $this->group);
323         $adminSection->show();
324     }
325
326     /**
327      * Show some statistics
328      *
329      * @return void
330      */
331     function showStatistics()
332     {
333         $this->elementStart('div', array('id' => 'entity_statistics',
334                                          'class' => 'section'));
335
336         // TRANS: Header for group statistics on a group page (h2).
337         $this->element('h2', null, _('Statistics'));
338
339         $this->elementStart('dl');
340
341         // TRANS: Label for group creation date.
342         $this->element('dt', null, _m('LABEL','Created'));
343         $this->element('dd', 'entity_created', date('j M Y',
344                                                  strtotime($this->group->created)));
345         // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
346         // TRANS: Label for member count in statistics on group page.
347         $this->element('dt', null, _m('LABEL','Members'));
348         $this->element('dd', null, $this->group->getMemberCount());
349         $this->elementEnd('dl');
350
351         $this->elementEnd('div');
352     }
353
354     function showAnonymousMessage()
355     {
356         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
357             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
358             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
359             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
360             // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
361             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
362             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
363                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
364                 'short messages about their life and interests. '.
365                 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
366                      $this->group->nickname);
367         } else {
368             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
369             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
370             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
371             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
372             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
373                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
374                 'short messages about their life and interests. '),
375                      $this->group->nickname);
376         }
377         $this->elementStart('div', array('id' => 'anon_notice'));
378         $this->raw(common_markup_to_html($m));
379         $this->elementEnd('div');
380     }
381
382     function noticeFormOptions()
383     {
384         $options = parent::noticeFormOptions();
385         $cur = common_current_user();
386
387         if (!empty($cur) && $cur->isMember($this->group)) {
388             $options['to_group'] =  $this->group;
389         }
390
391         return $options;
392     }
393 }
394
395 class GroupAdminSection extends ProfileSection
396 {
397     var $group;
398
399     function __construct($out, $group)
400     {
401         parent::__construct($out);
402         $this->group = $group;
403     }
404
405     function getProfiles()
406     {
407         return $this->group->getAdmins();
408     }
409
410     function title()
411     {
412         // TRANS: Title for list of group administrators on a group page.
413         return _m('TITLE','Admins');
414     }
415
416     function divId()
417     {
418         return 'group_admins';
419     }
420
421     function moreUrl()
422     {
423         return null;
424     }
425 }
426
427 class GroupMembersMiniList extends ProfileMiniList
428 {
429     function newListItem($profile)
430     {
431         return new GroupMembersMiniListItem($profile, $this->action);
432     }
433 }
434
435 class GroupMembersMiniListItem extends ProfileMiniListItem
436 {
437     function linkAttributes()
438     {
439         $aAttrs = parent::linkAttributes();
440
441         if (common_config('nofollow', 'members')) {
442             $aAttrs['rel'] .= ' nofollow';
443         }
444
445         return $aAttrs;
446     }
447 }
448
449 class ThreadingGroupNoticeStream extends ThreadingNoticeStream
450 {
451     function __construct($group, $profile)
452     {
453         parent::__construct(new GroupNoticeStream($group, $profile));
454     }
455 }