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