]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
remove extraneous <dl> and <dt> tags
[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->showGroupNotices();
185     }
186
187     /**
188      * Show the group notices
189      *
190      * @return void
191      */
192     function showGroupNotices()
193     {
194         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
195                                            NOTICES_PER_PAGE + 1);
196
197         $nl = new NoticeList($notice, $this);
198         $cnt = $nl->show();
199
200         $this->pagination($this->page > 1,
201                           $cnt > NOTICES_PER_PAGE,
202                           $this->page,
203                           'showgroup',
204                           array('nickname' => $this->group->nickname));
205     }
206
207     /**
208      * Show the group profile
209      *
210      * Information about the group
211      *
212      * @return void
213      */
214     function showGroupProfile()
215     {
216         $this->elementStart('div', array('id' => 'i',
217                                          'class' => 'entity_profile vcard author'));
218
219         $logo = ($this->group->homepage_logo) ?
220           $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
221
222         $this->element('img', array('src' => $logo,
223                                     'class' => 'photo avatar entity_depiction',
224                                     'width' => AVATAR_PROFILE_SIZE,
225                                     'height' => AVATAR_PROFILE_SIZE,
226                                     'alt' => $this->group->nickname));
227
228         $hasFN = ($this->group->fullname) ? 'entity_nickname nickname url uid' :
229             'entity_nickname fn org nickname url uid';
230         $this->element('a', array('href' => $this->group->homeUrl(),
231                                   'rel' => 'me', 'class' => $hasFN),
232                             $this->group->nickname);
233
234         if ($this->group->fullname) {
235             $this->element('div', 'entity_fn fn org', $this->group->fullname);
236         }
237
238         if ($this->group->location) {
239             $this->element('div', 'entity_location label', $this->group->location);
240         }
241
242         if ($this->group->homepage) {
243             $this->element('a', array('href' => $this->group->homepage,
244                                       'rel' => 'me',
245                                       'class' => 'url entity_url'),
246                            $this->group->homepage);
247         }
248
249         if ($this->group->description) {
250             $this->element('div', 'note entity_note', $this->group->description);
251         }
252
253         if (common_config('group', 'maxaliases') > 0) {
254             $aliases = $this->group->getAliases();
255
256             if (!empty($aliases)) {
257                 $this->element('div',
258                                'aliases entity_aliases',
259                                implode(' ', $aliases));
260             }
261         }
262
263         $this->elementEnd('div');
264
265         $cur = common_current_user();
266         $this->elementStart('div', 'entity_actions');
267         // TRANS: Group actions header (h2). Text hidden by default.
268         $this->element('h2', null, _('Group actions'));
269         $this->elementStart('ul');
270         $this->elementStart('li', 'entity_subscribe');
271         if (Event::handle('StartGroupSubscribe', array($this, $this->group))) {
272             if ($cur) {
273                 if ($cur->isMember($this->group)) {
274                     $lf = new LeaveForm($this, $this->group);
275                     $lf->show();
276                 } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
277                     $jf = new JoinForm($this, $this->group);
278                     $jf->show();
279                 }
280             }
281             Event::handle('EndGroupSubscribe', array($this, $this->group));
282         }
283         $this->elementEnd('li');
284         if ($cur && $cur->hasRight(Right::DELETEGROUP)) {
285             $this->elementStart('li', 'entity_delete');
286             $df = new DeleteGroupForm($this, $this->group);
287             $df->show();
288             $this->elementEnd('li');
289         }
290         $this->elementEnd('ul');
291         $this->elementEnd('div');
292     }
293
294     /**
295      * Get a list of the feeds for this page
296      *
297      * @return void
298      */
299     function getFeeds()
300     {
301         $url =
302           common_local_url('grouprss',
303                            array('nickname' => $this->group->nickname));
304
305         return array(new Feed(Feed::RSS1,
306                               common_local_url('grouprss',
307                                                array('nickname' => $this->group->nickname)),
308                               // TRANS: Tooltip for feed link. %s is a group nickname.
309                               sprintf(_('Notice feed for %s group (RSS 1.0)'),
310                                       $this->group->nickname)),
311                      new Feed(Feed::RSS2,
312                               common_local_url('ApiTimelineGroup',
313                                                array('format' => 'rss',
314                                                      'id' => $this->group->id)),
315                               // TRANS: Tooltip for feed link. %s is a group nickname.
316                               sprintf(_('Notice feed for %s group (RSS 2.0)'),
317                                       $this->group->nickname)),
318                      new Feed(Feed::ATOM,
319                               common_local_url('ApiTimelineGroup',
320                                                array('format' => 'atom',
321                                                      'id' => $this->group->id)),
322                               // TRANS: Tooltip for feed link. %s is a group nickname.
323                               sprintf(_('Notice feed for %s group (Atom)'),
324                                       $this->group->nickname)),
325                      new Feed(Feed::FOAF,
326                               common_local_url('foafgroup',
327                                                array('nickname' => $this->group->nickname)),
328                               // TRANS: Tooltip for feed link. %s is a group nickname.
329                               sprintf(_('FOAF for %s group'),
330                                        $this->group->nickname)));
331     }
332
333     /**
334      * Fill in the sidebar.
335      *
336      * @return void
337      */
338     function showSections()
339     {
340         $this->showMembers();
341         $this->showStatistics();
342         $this->showAdmins();
343         $cloud = new GroupTagCloudSection($this, $this->group);
344         $cloud->show();
345     }
346
347     /**
348      * Show mini-list of members
349      *
350      * @return void
351      */
352     function showMembers()
353     {
354         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
355
356         if (!$member) {
357             return;
358         }
359
360         $this->elementStart('div', array('id' => 'entity_members',
361                                          'class' => 'section'));
362
363         if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
364
365             // TRANS: Header for mini list of group members on a group page (h2).
366             $this->element('h2', null, _('Members'));
367
368             $gmml = new GroupMembersMiniList($member, $this);
369             $cnt = $gmml->show();
370             if ($cnt == 0) {
371                 // TRANS: Description for mini list of group members on a group page when the group has no members.
372                 $this->element('p', null, _('(None)'));
373             }
374
375             // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
376             //              for example http://identi.ca/group/statusnet. Broken?
377             if ($cnt > MEMBERS_PER_SECTION) {
378                 $this->element('a', array('href' => common_local_url('groupmembers',
379                                                                      array('nickname' => $this->group->nickname))),
380                                // TRANS: Link to all group members from mini list of group members if group has more than n members.
381                                _('All members'));
382             }
383
384             Event::handle('EndShowGroupMembersMiniList', array($this));
385         }
386
387         $this->elementEnd('div');
388     }
389
390     /**
391      * Show list of admins
392      *
393      * @return void
394      */
395     function showAdmins()
396     {
397         $adminSection = new GroupAdminSection($this, $this->group);
398         $adminSection->show();
399     }
400
401     /**
402      * Show some statistics
403      *
404      * @return void
405      */
406     function showStatistics()
407     {
408         $this->elementStart('div', array('id' => 'entity_statistics',
409                                          'class' => 'section'));
410
411         // TRANS: Header for group statistics on a group page (h2).
412         $this->element('h2', null, _('Statistics'));
413
414         $this->elementEnd('dl');
415         $this->element('dt', null, _m('LABEL','Created'));
416         $this->element('dd', 'entity_created', date('j M Y',
417                                                  strtotime($this->group->created)));
418         // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
419         // TRANS: Label for member count in statistics on group page.
420         $this->element('dt', null, _m('LABEL','Members'));
421         $this->element('dd', null, $this->group->getMemberCount());
422         $this->elementEnd('dl');
423
424         $this->elementEnd('div');
425     }
426
427     function showAnonymousMessage()
428     {
429         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
430             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
431             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
432             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
433             // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
434             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
435             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
436                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
437                 'short messages about their life and interests. '.
438                 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
439                      $this->group->nickname);
440         } else {
441             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
442             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
443             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
444             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
445             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
446                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
447                 'short messages about their life and interests. '),
448                      $this->group->nickname);
449         }
450         $this->elementStart('div', array('id' => 'anon_notice'));
451         $this->raw(common_markup_to_html($m));
452         $this->elementEnd('div');
453     }
454 }
455
456 class GroupAdminSection extends ProfileSection
457 {
458     var $group;
459
460     function __construct($out, $group)
461     {
462         parent::__construct($out);
463         $this->group = $group;
464     }
465
466     function getProfiles()
467     {
468         return $this->group->getAdmins();
469     }
470
471     function title()
472     {
473         // TRANS: Header for list of group administrators on a group page (h2).
474         return _('Admins');
475     }
476
477     function divId()
478     {
479         return 'group_admins';
480     }
481
482     function moreUrl()
483     {
484         return null;
485     }
486 }
487
488 class GroupMembersMiniList extends ProfileMiniList
489 {
490     function newListItem($profile)
491     {
492         return new GroupMembersMiniListItem($profile, $this->action);
493     }
494 }
495
496 class GroupMembersMiniListItem extends ProfileMiniListItem
497 {
498     function linkAttributes()
499     {
500         $aAttrs = parent::linkAttributes();
501
502         if (common_config('nofollow', 'members')) {
503             $aAttrs['rel'] .= ' nofollow';
504         }
505
506         return $aAttrs;
507     }
508 }