]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
Merge branch 'extprofile' into 0.9.x
[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-2009 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 GroupDesignAction
50 {
51     /** page we're viewing. */
52     var $page = null;
53
54     /**
55      * Is this page read-only?
56      *
57      * @return boolean true
58      */
59     function isReadOnly($args)
60     {
61         return true;
62     }
63
64     /**
65      * Title of the page
66      *
67      * @return string page title, with page number
68      */
69     function title()
70     {
71         $base = $this->group->getFancyName();
72
73         if ($this->page == 1) {
74             // TRANS: Page title for first group page. %s is a group name.
75             return sprintf(_('%s group'), $base);
76         } else {
77             // TRANS: Page title for any but first group page.
78             // TRANS: %1$s is a group name, $2$s is a page number.
79             return sprintf(_('%1$s group, page %2$d'),
80                            $base,
81                            $this->page);
82         }
83     }
84
85     /**
86      * Prepare the action
87      *
88      * Reads and validates arguments and instantiates the attributes.
89      *
90      * @param array $args $_REQUEST args
91      *
92      * @return boolean success flag
93      */
94     function prepare($args)
95     {
96         parent::prepare($args);
97
98         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
99
100         $nickname_arg = $this->arg('nickname');
101         $nickname = common_canonical_nickname($nickname_arg);
102
103         // Permanent redirect on non-canonical nickname
104
105         if ($nickname_arg != $nickname) {
106             $args = array('nickname' => $nickname);
107             if ($this->page != 1) {
108                 $args['page'] = $this->page;
109             }
110             common_redirect(common_local_url('showgroup', $args), 301);
111             return false;
112         }
113
114         if (!$nickname) {
115             // TRANS: Client error displayed if no nickname argument was given requesting a group page.
116             $this->clientError(_('No nickname.'), 404);
117             return false;
118         }
119
120         $local = Local_group::staticGet('nickname', $nickname);
121
122         if (!$local) {
123             $alias = Group_alias::staticGet('alias', $nickname);
124             if ($alias) {
125                 $args = array('id' => $alias->group_id);
126                 if ($this->page != 1) {
127                     $args['page'] = $this->page;
128                 }
129                 common_redirect(common_local_url('groupbyid', $args), 301);
130                 return false;
131             } else {
132                 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
133                 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
134                 $this->clientError(_('No such group.'), 404);
135                 return false;
136             }
137         }
138
139         $this->group = User_group::staticGet('id', $local->group_id);
140
141         if (!$this->group) {
142                 // TRANS: Client error displayed if no local group with a given name was found requesting group page.
143             $this->clientError(_('No such group.'), 404);
144             return false;
145         }
146
147         common_set_returnto($this->selfUrl());
148
149         return true;
150     }
151
152     /**
153      * Handle the request
154      *
155      * Shows a profile for the group, some controls, and a list of
156      * group notices.
157      *
158      * @return void
159      */
160     function handle($args)
161     {
162         $this->showPage();
163     }
164
165     /**
166      * Local menu
167      *
168      * @return void
169      */
170     function showLocalNav()
171     {
172         $nav = new GroupNav($this, $this->group);
173         $nav->show();
174     }
175
176     /**
177      * Show the page content
178      *
179      * Shows a group profile and a list of group notices
180      */
181     function showContent()
182     {
183         $this->showGroupProfile();
184         $this->showGroupActions();
185         $this->showGroupNotices();
186     }
187
188     /**
189      * Show the group notices
190      *
191      * @return void
192      */
193     function showGroupNotices()
194     {
195         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
196                                            NOTICES_PER_PAGE + 1);
197
198         $nl = new NoticeList($notice, $this);
199         $cnt = $nl->show();
200
201         $this->pagination($this->page > 1,
202                           $cnt > NOTICES_PER_PAGE,
203                           $this->page,
204                           'showgroup',
205                           array('nickname' => $this->group->nickname));
206     }
207
208     /**
209      * Show the group profile
210      *
211      * Information about the group
212      *
213      * @return void
214      */
215     function showGroupProfile()
216     {
217         $this->elementStart('div', array('id' => 'i',
218                                          'class' => 'entity_profile vcard author'));
219
220         if (Event::handle('StartGroupProfileElements', array($this, $this->group))) {
221
222             // TRANS: Group profile header (h2). Text hidden by default.
223             $this->element('h2', null, _('Group profile'));
224
225             $this->elementStart('dl', 'entity_depiction');
226             // TRANS: Label for group avatar (dt). Text hidden by default.
227             $this->element('dt', null, _('Avatar'));
228             $this->elementStart('dd');
229
230             $logo = ($this->group->homepage_logo) ?
231                 $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
232
233             $this->element('img', array('src' => $logo,
234                                         'class' => 'photo avatar',
235                                         'width' => AVATAR_PROFILE_SIZE,
236                                         'height' => AVATAR_PROFILE_SIZE,
237                                         'alt' => $this->group->nickname));
238             $this->elementEnd('dd');
239             $this->elementEnd('dl');
240
241             $this->elementStart('dl', 'entity_nickname');
242             // TRANS: Label for group nickname (dt). Text hidden by default.
243             $this->element('dt', null, _('Nickname'));
244             $this->elementStart('dd');
245             $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
246             $this->element('a', array('href' => $this->group->homeUrl(),
247                                       'rel' => 'me', 'class' => $hasFN),
248                            $this->group->nickname);
249             $this->elementEnd('dd');
250             $this->elementEnd('dl');
251
252             if ($this->group->fullname) {
253                 $this->elementStart('dl', 'entity_fn');
254                 // TRANS: Label for full group name (dt). Text hidden by default.
255                 $this->element('dt', null, _('Full name'));
256                 $this->elementStart('dd');
257                 $this->element('span', 'fn org', $this->group->fullname);
258                 $this->elementEnd('dd');
259                 $this->elementEnd('dl');
260             }
261
262             if ($this->group->location) {
263                 $this->elementStart('dl', 'entity_location');
264                 // TRANS: Label for group location (dt). Text hidden by default.
265                 $this->element('dt', null, _('Location'));
266                 $this->element('dd', 'label', $this->group->location);
267                 $this->elementEnd('dl');
268             }
269
270             if ($this->group->homepage) {
271                 $this->elementStart('dl', 'entity_url');
272                 // TRANS: Label for group URL (dt). Text hidden by default.
273                 $this->element('dt', null, _('URL'));
274                 $this->elementStart('dd');
275                 $this->element('a', array('href' => $this->group->homepage,
276                                           'rel' => 'me', 'class' => 'url'),
277                                $this->group->homepage);
278                 $this->elementEnd('dd');
279                 $this->elementEnd('dl');
280             }
281
282             if ($this->group->description) {
283                 $this->elementStart('dl', 'entity_note');
284                 // TRANS: Label for group description or group note (dt). Text hidden by default.
285                 $this->element('dt', null, _('Note'));
286                 $this->element('dd', 'note', $this->group->description);
287                 $this->elementEnd('dl');
288             }
289
290             if (common_config('group', 'maxaliases') > 0) {
291                 $aliases = $this->group->getAliases();
292
293                 if (!empty($aliases)) {
294                     $this->elementStart('dl', 'entity_aliases');
295                     // TRANS: Label for group aliases (dt). Text hidden by default.
296                     $this->element('dt', null, _('Aliases'));
297                     $this->element('dd', 'aliases', implode(' ', $aliases));
298                     $this->elementEnd('dl');
299                 }
300             }
301
302             Event::handle('EndGroupProfileElements', array($this, $this->group));
303         }
304
305         $this->elementEnd('div');
306     }
307
308     function showGroupActions()
309     {
310         $cur = common_current_user();
311         $this->elementStart('div', 'entity_actions');
312         // TRANS: Group actions header (h2). Text hidden by default.
313         $this->element('h2', null, _('Group actions'));
314         $this->elementStart('ul');
315         if (Event::handle('StartGroupActionsList', array($this, $this->group))) {
316             $this->elementStart('li', 'entity_subscribe');
317             if (Event::handle('StartGroupSubscribe', array($this, $this->group))) {
318                 if ($cur) {
319                     if ($cur->isMember($this->group)) {
320                         $lf = new LeaveForm($this, $this->group);
321                         $lf->show();
322                     } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
323                         $jf = new JoinForm($this, $this->group);
324                         $jf->show();
325                     }
326                 }
327                 Event::handle('EndGroupSubscribe', array($this, $this->group));
328             }
329             $this->elementEnd('li');
330             if ($cur && $cur->hasRight(Right::DELETEGROUP)) {
331                 $this->elementStart('li', 'entity_delete');
332                 $df = new DeleteGroupForm($this, $this->group);
333                 $df->show();
334                 $this->elementEnd('li');
335             }
336             Event::handle('EndGroupActionsList', array($this, $this->group));
337         }
338         $this->elementEnd('ul');
339         $this->elementEnd('div');
340     }
341
342     /**
343      * Get a list of the feeds for this page
344      *
345      * @return void
346      */
347     function getFeeds()
348     {
349         $url =
350           common_local_url('grouprss',
351                            array('nickname' => $this->group->nickname));
352
353         return array(new Feed(Feed::RSS1,
354                               common_local_url('grouprss',
355                                                array('nickname' => $this->group->nickname)),
356                               // TRANS: Tooltip for feed link. %s is a group nickname.
357                               sprintf(_('Notice feed for %s group (RSS 1.0)'),
358                                       $this->group->nickname)),
359                      new Feed(Feed::RSS2,
360                               common_local_url('ApiTimelineGroup',
361                                                array('format' => 'rss',
362                                                      'id' => $this->group->id)),
363                               // TRANS: Tooltip for feed link. %s is a group nickname.
364                               sprintf(_('Notice feed for %s group (RSS 2.0)'),
365                                       $this->group->nickname)),
366                      new Feed(Feed::ATOM,
367                               common_local_url('ApiTimelineGroup',
368                                                array('format' => 'atom',
369                                                      'id' => $this->group->id)),
370                               // TRANS: Tooltip for feed link. %s is a group nickname.
371                               sprintf(_('Notice feed for %s group (Atom)'),
372                                       $this->group->nickname)),
373                      new Feed(Feed::FOAF,
374                               common_local_url('foafgroup',
375                                                array('nickname' => $this->group->nickname)),
376                               // TRANS: Tooltip for feed link. %s is a group nickname.
377                               sprintf(_('FOAF for %s group'),
378                                        $this->group->nickname)));
379     }
380
381     /**
382      * Fill in the sidebar.
383      *
384      * @return void
385      */
386     function showSections()
387     {
388         $this->showMembers();
389         $this->showStatistics();
390         $this->showAdmins();
391         $cloud = new GroupTagCloudSection($this, $this->group);
392         $cloud->show();
393     }
394
395     /**
396      * Show mini-list of members
397      *
398      * @return void
399      */
400     function showMembers()
401     {
402         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
403
404         if (!$member) {
405             return;
406         }
407
408         $this->elementStart('div', array('id' => 'entity_members',
409                                          'class' => 'section'));
410
411         if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
412
413             // TRANS: Header for mini list of group members on a group page (h2).
414             $this->element('h2', null, _('Members'));
415
416             $gmml = new GroupMembersMiniList($member, $this);
417             $cnt = $gmml->show();
418             if ($cnt == 0) {
419                 // TRANS: Description for mini list of group members on a group page when the group has no members.
420                 $this->element('p', null, _('(None)'));
421             }
422
423             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
424             //              for example http://identi.ca/group/statusnet. Broken?
425             if ($cnt > MEMBERS_PER_SECTION) {
426                 $this->element('a', array('href' => common_local_url('groupmembers',
427                                                                      array('nickname' => $this->group->nickname))),
428                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
429                                _('All members'));
430             }
431
432             Event::handle('EndShowGroupMembersMiniList', array($this));
433         }
434
435         $this->elementEnd('div');
436     }
437
438     /**
439      * Show list of admins
440      *
441      * @return void
442      */
443     function showAdmins()
444     {
445         $adminSection = new GroupAdminSection($this, $this->group);
446         $adminSection->show();
447     }
448
449     /**
450      * Show some statistics
451      *
452      * @return void
453      */
454     function showStatistics()
455     {
456         $this->elementStart('div', array('id' => 'entity_statistics',
457                                          'class' => 'section'));
458
459         // TRANS: Header for group statistics on a group page (h2).
460         $this->element('h2', null, _('Statistics'));
461
462         $this->elementStart('dl', 'entity_created');
463         // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
464         // TRANS: Label for creation date in statistics on group page.
465         $this->element('dt', null, _m('LABEL','Created'));
466         $this->element('dd', null, date('j M Y',
467                                                  strtotime($this->group->created)));
468         $this->elementEnd('dl');
469
470         $this->elementStart('dl', 'entity_members');
471         // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
472         // TRANS: Label for member count in statistics on group page.
473         $this->element('dt', null, _m('LABEL','Members'));
474         $this->element('dd', null, $this->group->getMemberCount());
475         $this->elementEnd('dl');
476
477         $this->elementEnd('div');
478     }
479
480     function showAnonymousMessage()
481     {
482         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
483             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
484             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
485             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
486             // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
487             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
488             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
489                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
490                 'short messages about their life and interests. '.
491                 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
492                      $this->group->nickname);
493         } else {
494             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
495             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
496             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
497             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
498             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
499                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
500                 'short messages about their life and interests. '),
501                      $this->group->nickname);
502         }
503         $this->elementStart('div', array('id' => 'anon_notice'));
504         $this->raw(common_markup_to_html($m));
505         $this->elementEnd('div');
506     }
507 }
508
509 class GroupAdminSection extends ProfileSection
510 {
511     var $group;
512
513     function __construct($out, $group)
514     {
515         parent::__construct($out);
516         $this->group = $group;
517     }
518
519     function getProfiles()
520     {
521         return $this->group->getAdmins();
522     }
523
524     function title()
525     {
526         // TRANS: Header for list of group administrators on a group page (h2).
527         return _('Admins');
528     }
529
530     function divId()
531     {
532         return 'group_admins';
533     }
534
535     function moreUrl()
536     {
537         return null;
538     }
539 }
540
541 class GroupMembersMiniList extends ProfileMiniList
542 {
543     function newListItem($profile)
544     {
545         return new GroupMembersMiniListItem($profile, $this->action);
546     }
547 }
548
549 class GroupMembersMiniListItem extends ProfileMiniListItem
550 {
551     function linkAttributes()
552     {
553         $aAttrs = parent::linkAttributes();
554
555         if (common_config('nofollow', 'members')) {
556             $aAttrs['rel'] .= ' nofollow';
557         }
558
559         return $aAttrs;
560     }
561 }