]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
530deff622ff21a8b0cdf1668afb3245cbcb59a0
[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::RSS1,
224                               common_local_url('grouprss',
225                                                array('nickname' => $this->group->nickname)),
226                               // TRANS: Tooltip for feed link. %s is a group nickname.
227                               sprintf(_('Notice feed for %s group (RSS 1.0)'),
228                                       $this->group->nickname)),
229                      new Feed(Feed::RSS2,
230                               common_local_url('ApiTimelineGroup',
231                                                array('format' => 'rss',
232                                                      'id' => $this->group->id)),
233                               // TRANS: Tooltip for feed link. %s is a group nickname.
234                               sprintf(_('Notice feed for %s group (RSS 2.0)'),
235                                       $this->group->nickname)),
236                      new Feed(Feed::ATOM,
237                               common_local_url('ApiTimelineGroup',
238                                                array('format' => 'atom',
239                                                      'id' => $this->group->id)),
240                               // TRANS: Tooltip for feed link. %s is a group nickname.
241                               sprintf(_('Notice feed for %s group (Atom)'),
242                                       $this->group->nickname)),
243                      new Feed(Feed::FOAF,
244                               common_local_url('foafgroup',
245                                                array('nickname' => $this->group->nickname)),
246                               // TRANS: Tooltip for feed link. %s is a group nickname.
247                               sprintf(_('FOAF for %s group'),
248                                        $this->group->nickname)));
249     }
250
251     /**
252      * Fill in the sidebar.
253      *
254      * @return void
255      */
256     function showSections()
257     {
258         $this->showMembers();
259         $this->showStatistics();
260         $this->showAdmins();
261         $cloud = new GroupTagCloudSection($this, $this->group);
262         $cloud->show();
263     }
264
265     /**
266      * Show mini-list of members
267      *
268      * @return void
269      */
270     function showMembers()
271     {
272         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
273
274         if (!$member) {
275             return;
276         }
277
278         $this->elementStart('div', array('id' => 'entity_members',
279                                          'class' => 'section'));
280
281         if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
282
283             // TRANS: Header for mini list of group members on a group page (h2).
284             $this->element('h2', null, _('Members'));
285
286             $gmml = new GroupMembersMiniList($member, $this);
287             $cnt = $gmml->show();
288             if ($cnt == 0) {
289                 // TRANS: Description for mini list of group members on a group page when the group has no members.
290                 $this->element('p', null, _('(None)'));
291             }
292
293             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
294             //              for example http://identi.ca/group/statusnet. Broken?
295             if ($cnt > MEMBERS_PER_SECTION) {
296                 $this->element('a', array('href' => common_local_url('groupmembers',
297                                                                      array('nickname' => $this->group->nickname))),
298                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
299                                _('All members'));
300             }
301
302             Event::handle('EndShowGroupMembersMiniList', array($this));
303         }
304
305         $this->elementEnd('div');
306     }
307
308     /**
309      * Show list of admins
310      *
311      * @return void
312      */
313     function showAdmins()
314     {
315         $adminSection = new GroupAdminSection($this, $this->group);
316         $adminSection->show();
317     }
318
319     /**
320      * Show some statistics
321      *
322      * @return void
323      */
324     function showStatistics()
325     {
326         $this->elementStart('div', array('id' => 'entity_statistics',
327                                          'class' => 'section'));
328
329         // TRANS: Header for group statistics on a group page (h2).
330         $this->element('h2', null, _('Statistics'));
331
332         $this->elementStart('dl');
333
334         // TRANS: Label for group creation date.
335         $this->element('dt', null, _m('LABEL','Created'));
336         $this->element('dd', 'entity_created', date('j M Y',
337                                                  strtotime($this->group->created)));
338         // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
339         // TRANS: Label for member count in statistics on group page.
340         $this->element('dt', null, _m('LABEL','Members'));
341         $this->element('dd', null, $this->group->getMemberCount());
342         $this->elementEnd('dl');
343
344         $this->elementEnd('div');
345     }
346
347     function showAnonymousMessage()
348     {
349         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
350             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
351             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
352             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
353             // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
354             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
355             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
356                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
357                 'short messages about their life and interests. '.
358                 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
359                      $this->group->nickname);
360         } else {
361             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
362             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
363             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
364             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
365             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
366                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
367                 'short messages about their life and interests. '),
368                      $this->group->nickname);
369         }
370         $this->elementStart('div', array('id' => 'anon_notice'));
371         $this->raw(common_markup_to_html($m));
372         $this->elementEnd('div');
373     }
374
375     function noticeFormOptions()
376     {
377         $options = parent::noticeFormOptions();
378         $cur = common_current_user();
379
380         if (!empty($cur) && $cur->isMember($this->group)) {
381             $options['to_group'] =  $this->group;
382         }
383
384         return $options;
385     }
386 }
387
388 class GroupAdminSection extends ProfileSection
389 {
390     var $group;
391
392     function __construct($out, $group)
393     {
394         parent::__construct($out);
395         $this->group = $group;
396     }
397
398     function getProfiles()
399     {
400         return $this->group->getAdmins();
401     }
402
403     function title()
404     {
405         // TRANS: Title for list of group administrators on a group page.
406         return _m('TITLE','Admins');
407     }
408
409     function divId()
410     {
411         return 'group_admins';
412     }
413
414     function moreUrl()
415     {
416         return null;
417     }
418 }
419
420 class GroupMembersMiniList extends ProfileMiniList
421 {
422     function newListItem($profile)
423     {
424         return new GroupMembersMiniListItem($profile, $this->action);
425     }
426 }
427
428 class GroupMembersMiniListItem extends ProfileMiniListItem
429 {
430     function linkAttributes()
431     {
432         $aAttrs = parent::linkAttributes();
433
434         if (common_config('nofollow', 'members')) {
435             $aAttrs['rel'] .= ' nofollow';
436         }
437
438         return $aAttrs;
439     }
440 }
441
442 class ThreadingGroupNoticeStream extends ThreadingNoticeStream
443 {
444     function __construct($group, $profile)
445     {
446         parent::__construct(new GroupNoticeStream($group, $profile));
447     }
448 }