]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
Merge branch '0.8.x' into group-rss-empty
[quix0rs-gnu-social.git] / actions / showgroup.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @author    Sarven Capadisli <csarven@controlyourself.ca>
26  * @copyright 2008-2009 Control Yourself, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!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  Laconica
45  * @author   Evan Prodromou <evan@controlyourself.ca>
46  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47  * @link     http://laconi.ca/
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(_("%s group, page %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         if (!common_config('inboxes','enabled')) {
105             $this->serverError(_('Inboxes must be enabled for groups to work'));
106             return false;
107         }
108
109         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
110
111         $nickname_arg = $this->arg('nickname');
112         $nickname = common_canonical_nickname($nickname_arg);
113
114         // Permanent redirect on non-canonical nickname
115
116         if ($nickname_arg != $nickname) {
117             $args = array('nickname' => $nickname);
118             if ($this->page != 1) {
119                 $args['page'] = $this->page;
120             }
121             common_redirect(common_local_url('showgroup', $args), 301);
122             return false;
123         }
124
125         if (!$nickname) {
126             $this->clientError(_('No nickname'), 404);
127             return false;
128         }
129
130         $this->group = User_group::staticGet('nickname', $nickname);
131
132         if (!$this->group) {
133             $this->clientError(_('No such group'), 404);
134             return false;
135         }
136
137         common_set_returnto($this->selfUrl());
138
139         return true;
140     }
141
142     /**
143      * Handle the request
144      *
145      * Shows a profile for the group, some controls, and a list of
146      * group notices.
147      *
148      * @return void
149      */
150
151     function handle($args)
152     {
153         $this->showPage();
154     }
155
156     /**
157      * Local menu
158      *
159      * @return void
160      */
161
162     function showLocalNav()
163     {
164         $nav = new GroupNav($this, $this->group);
165         $nav->show();
166     }
167
168     /**
169      * Show the page content
170      *
171      * Shows a group profile and a list of group notices
172      */
173
174     function showContent()
175     {
176         $this->showGroupProfile();
177         $this->showGroupNotices();
178     }
179
180     /**
181      * Show the group notices
182      *
183      * @return void
184      */
185
186     function showGroupNotices()
187     {
188         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
189                                            NOTICES_PER_PAGE + 1);
190
191         $nl = new NoticeList($notice, $this);
192         $cnt = $nl->show();
193
194         $this->pagination($this->page > 1,
195                           $cnt > NOTICES_PER_PAGE,
196                           $this->page,
197                           'showgroup',
198                           array('nickname' => $this->group->nickname));
199     }
200
201     /**
202      * Show the group profile
203      *
204      * Information about the group
205      *
206      * @return void
207      */
208
209     function showGroupProfile()
210     {
211         $this->elementStart('div', 'entity_profile vcard author');
212
213         $this->element('h2', null, _('Group profile'));
214
215         $this->elementStart('dl', 'entity_depiction');
216         $this->element('dt', null, _('Avatar'));
217         $this->elementStart('dd');
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',
224                                     'width' => AVATAR_PROFILE_SIZE,
225                                     'height' => AVATAR_PROFILE_SIZE,
226                                     'alt' => $this->group->nickname));
227         $this->elementEnd('dd');
228         $this->elementEnd('dl');
229
230         $this->elementStart('dl', 'entity_nickname');
231         $this->element('dt', null, _('Nickname'));
232         $this->elementStart('dd');
233         $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
234         $this->element('a', array('href' => $this->group->homeUrl(),
235                                   'rel' => 'me', 'class' => $hasFN),
236                             $this->group->nickname);
237         $this->elementEnd('dd');
238         $this->elementEnd('dl');
239
240         if ($this->group->fullname) {
241             $this->elementStart('dl', 'entity_fn');
242             $this->element('dt', null, _('Full name'));
243             $this->elementStart('dd');
244             $this->element('span', 'fn org', $this->group->fullname);
245             $this->elementEnd('dd');
246             $this->elementEnd('dl');
247         }
248
249         if ($this->group->location) {
250             $this->elementStart('dl', 'entity_location');
251             $this->element('dt', null, _('Location'));
252             $this->element('dd', 'label', $this->group->location);
253             $this->elementEnd('dl');
254         }
255
256         if ($this->group->homepage) {
257             $this->elementStart('dl', 'entity_url');
258             $this->element('dt', null, _('URL'));
259             $this->elementStart('dd');
260             $this->element('a', array('href' => $this->group->homepage,
261                                       'rel' => 'me', 'class' => 'url'),
262                            $this->group->homepage);
263             $this->elementEnd('dd');
264             $this->elementEnd('dl');
265         }
266
267         if ($this->group->description) {
268             $this->elementStart('dl', 'entity_note');
269             $this->element('dt', null, _('Note'));
270             $this->element('dd', 'note', $this->group->description);
271             $this->elementEnd('dl');
272         }
273
274         if (common_config('group', 'maxaliases') > 0) {
275             $aliases = $this->group->getAliases();
276
277             if (!empty($aliases)) {
278                 $this->elementStart('dl', 'entity_aliases');
279                 $this->element('dt', null, _('Aliases'));
280                 $this->element('dd', 'aliases', implode(' ', $aliases));
281                 $this->elementEnd('dl');
282             }
283         }
284
285         $this->elementEnd('div');
286
287         $this->elementStart('div', 'entity_actions');
288         $this->element('h2', null, _('Group actions'));
289         $this->elementStart('ul');
290         $this->elementStart('li', 'entity_subscribe');
291         $cur = common_current_user();
292         if ($cur) {
293             if ($cur->isMember($this->group)) {
294                 $lf = new LeaveForm($this, $this->group);
295                 $lf->show();
296             } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
297                 $jf = new JoinForm($this, $this->group);
298                 $jf->show();
299             }
300         }
301
302         $this->elementEnd('li');
303
304         $this->elementEnd('ul');
305         $this->elementEnd('div');
306     }
307
308     /**
309      * Get a list of the feeds for this page
310      *
311      * @return void
312      */
313
314     function getFeeds()
315     {
316         $url =
317           common_local_url('grouprss',
318                            array('nickname' => $this->group->nickname));
319
320         return array(new Feed(Feed::RSS1, $url, sprintf(_('Notice feed for %s group'),
321                                                         $this->group->nickname)));
322     }
323
324     /**
325      * Fill in the sidebar.
326      *
327      * @return void
328      */
329
330     function showSections()
331     {
332         $this->showMembers();
333         $this->showStatistics();
334         $cloud = new GroupTagCloudSection($this, $this->group);
335         $cloud->show();
336     }
337
338     /**
339      * Show mini-list of members
340      *
341      * @return void
342      */
343
344     function showMembers()
345     {
346         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
347
348         if (!$member) {
349             return;
350         }
351
352         $this->elementStart('div', array('id' => 'entity_members',
353                                          'class' => 'section'));
354
355         $this->element('h2', null, _('Members'));
356
357         $pml = new ProfileMiniList($member, $this);
358         $cnt = $pml->show();
359         if ($cnt == 0) {
360              $this->element('p', null, _('(None)'));
361         }
362
363         if ($cnt > MEMBERS_PER_SECTION) {
364             $this->element('a', array('href' => common_local_url('groupmembers',
365                                                                  array('nickname' => $this->group->nickname))),
366                            _('All members'));
367         }
368
369         $this->elementEnd('div');
370     }
371
372     /**
373      * Show some statistics
374      *
375      * @return void
376      */
377
378     function showStatistics()
379     {
380         // XXX: WORM cache this
381         $members = $this->group->getMembers();
382         $members_count = 0;
383         /** $member->count() doesn't work. */
384         while ($members->fetch()) {
385             $members_count++;
386         }
387
388         $this->elementStart('div', array('id' => 'entity_statistics',
389                                          'class' => 'section'));
390
391         $this->element('h2', null, _('Statistics'));
392
393         $this->elementStart('dl', 'entity_created');
394         $this->element('dt', null, _('Created'));
395         $this->element('dd', null, date('j M Y',
396                                                  strtotime($this->group->created)));
397         $this->elementEnd('dl');
398
399         $this->elementStart('dl', 'entity_members');
400         $this->element('dt', null, _('Members'));
401         $this->element('dd', null, (is_int($members_count)) ? $members_count : '0');
402         $this->elementEnd('dl');
403
404         $this->elementEnd('div');
405     }
406
407     function showAnonymousMessage()
408     {
409         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
410             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
411                 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
412                 'short messages about their life and interests. '.
413                 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
414                      $this->group->nickname);
415         } else {
416             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
417                 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
418                 'short messages about their life and interests. '),
419                      $this->group->nickname);
420         }
421         $this->elementStart('div', array('id' => 'anon_notice'));
422         $this->raw(common_markup_to_html($m));
423         $this->elementEnd('div');
424     }
425 }