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