]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
Minor markup fix
[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', 81);
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 Action
51 {
52     /** group we're viewing. */
53     var $group = null;
54     /** page we're viewing. */
55     var $page = null;
56
57     /**
58      * Is this page read-only?
59      *
60      * @return boolean true
61      */
62
63     function isReadOnly()
64     {
65         return true;
66     }
67
68     /**
69      * Title of the page
70      *
71      * @return string page title, with page number
72      */
73
74     function title()
75     {
76         if ($this->page == 1) {
77             return sprintf(_("%s group"), $this->group->nickname);
78         } else {
79             return sprintf(_("%s group, page %d"),
80                            $this->group->nickname,
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
95     function prepare($args)
96     {
97         parent::prepare($args);
98
99         if (!common_config('inboxes','enabled')) {
100             $this->serverError(_('Inboxes must be enabled for groups to work'));
101             return false;
102         }
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         $this->group = User_group::staticGet('nickname', $nickname);
126
127         if (!$this->group) {
128             $this->clientError(_('No such group'), 404);
129             return false;
130         }
131
132         return true;
133     }
134
135     /**
136      * Handle the request
137      *
138      * Shows a profile for the group, some controls, and a list of
139      * group notices.
140      *
141      * @return void
142      */
143
144     function handle($args)
145     {
146         $this->showPage();
147     }
148
149     /**
150      * Local menu
151      *
152      * @return void
153      */
154
155     function showLocalNav()
156     {
157         $nav = new GroupNav($this, $this->group);
158         $nav->show();
159     }
160
161     /**
162      * Show the page content
163      *
164      * Shows a group profile and a list of group notices
165      */
166
167     function showContent()
168     {
169         $this->showGroupProfile();
170         $this->showGroupNotices();
171     }
172
173     /**
174      * Show the group notices
175      *
176      * @return void
177      */
178
179     function showGroupNotices()
180     {
181         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
182                                            NOTICES_PER_PAGE + 1);
183
184         $nl = new NoticeList($notice, $this);
185         $cnt = $nl->show();
186
187         $this->pagination($this->page > 1,
188                           $cnt > NOTICES_PER_PAGE,
189                           $this->page,
190                           'showgroup',
191                           array('nickname' => $this->group->nickname));
192     }
193
194     /**
195      * Show the group profile
196      *
197      * Information about the group
198      *
199      * @return void
200      */
201
202     function showGroupProfile()
203     {
204         $this->elementStart('div', 'entity_profile vcard author');
205
206         $this->element('h2', null, _('Group profile'));
207
208         $this->elementStart('dl', 'entity_depiction');
209         $this->element('dt', null, _('Avatar'));
210         $this->elementStart('dd');
211
212         $logo = ($this->group->homepage_logo) ?
213           $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
214
215         $this->element('img', array('src' => $logo,
216                                     'class' => 'photo avatar',
217                                     'width' => AVATAR_PROFILE_SIZE,
218                                     'height' => AVATAR_PROFILE_SIZE,
219                                     'alt' => $this->group->nickname));
220         $this->elementEnd('dd');
221         $this->elementEnd('dl');
222
223         $this->elementStart('dl', 'entity_nickname');
224         $this->element('dt', null, _('Nickname'));
225         $this->elementStart('dd');
226         $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
227         $this->element('a', array('href' => $this->group->homeUrl(),
228                                   'rel' => 'me', 'class' => $hasFN),
229                             $this->group->nickname);
230         $this->elementEnd('dd');
231         $this->elementEnd('dl');
232
233         if ($this->group->fullname) {
234             $this->elementStart('dl', 'entity_fn');
235             $this->element('dt', null, _('Full name'));
236             $this->elementStart('dd');
237             $this->element('span', 'fn org', $this->group->fullname);
238             $this->elementEnd('dd');
239             $this->elementEnd('dl');
240         }
241
242         if ($this->group->location) {
243             $this->elementStart('dl', 'entity_location');
244             $this->element('dt', null, _('Location'));
245             $this->element('dd', 'location', $this->group->location);
246             $this->elementEnd('dl');
247         }
248
249         if ($this->group->homepage) {
250             $this->elementStart('dl', 'entity_url');
251             $this->element('dt', null, _('URL'));
252             $this->elementStart('dd');
253             $this->element('a', array('href' => $this->group->homepage,
254                                       'rel' => 'me', 'class' => 'url'),
255                            $this->group->homepage);
256             $this->elementEnd('dd');
257             $this->elementEnd('dl');
258         }
259
260         if ($this->group->description) {
261             $this->elementStart('dl', 'entity_note');
262             $this->element('dt', null, _('Note'));
263             $this->element('dd', 'note', $this->group->description);
264             $this->elementEnd('dl');
265         }
266
267         $this->elementEnd('div');
268
269         $this->elementStart('div', 'entity_actions');
270         $this->element('h2', null, _('Group actions'));
271         $this->elementStart('ul');
272         $this->elementStart('li', array('id' => 'entity_subscribe'));
273         $cur = common_current_user();
274         if ($cur) {
275             if ($cur->isMember($this->group)) {
276                 if (!$cur->isAdmin($this->group)) {
277                     $lf = new LeaveForm($this, $this->group);
278                     $lf->show();
279                 }
280             } else {
281                 $jf = new JoinForm($this, $this->group);
282                 $jf->show();
283             }
284         }
285
286         $this->elementEnd('li');
287
288         $this->elementEnd('ul');
289         $this->elementEnd('div');
290     }
291
292     /**
293      * Show a list of links to feeds this page produces
294      *
295      * @return void
296      */
297
298     function showExportData()
299     {
300         $fl = new FeedList($this);
301         $fl->show(array(0=>array('href'=>common_local_url('grouprss',
302                                                           array('nickname' => $this->group->nickname)),
303                                  'type' => 'rss',
304                                  'version' => 'RSS 1.0',
305                                  'item' => 'notices')));
306     }
307
308     /**
309      * Show a list of links to feeds this page produces
310      *
311      * @return void
312      */
313
314     function showFeeds()
315     {
316         $url =
317           common_local_url('grouprss',
318                            array('nickname' => $this->group->nickname));
319
320         $this->element('link', array('rel' => 'alternate',
321                                      'href' => $url,
322                                      'type' => 'application/rss+xml',
323                                      'title' => sprintf(_('Notice feed for %s group'),
324                                                         $this->group->nickname)));
325     }
326
327     /**
328      * Fill in the sidebar.
329      *
330      * @return void
331      */
332
333     function showSections()
334     {
335         $this->showMembers();
336         $cloud = new GroupTagCloudSection($this, $this->group);
337         $cloud->show();
338     }
339
340     /**
341      * Show mini-list of members
342      *
343      * @return void
344      */
345
346     function showMembers()
347     {
348         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
349
350         if (!$member) {
351             return;
352         }
353
354         $this->elementStart('div', array('id' => 'entity_members',
355                                          'class' => 'section'));
356
357         $this->element('h2', null, _('Members'));
358
359         if ($member) {
360             $pml = new ProfileMiniList($member, null, $this);
361             $cnt = $pml->show();
362             if ($cnt == 0) {
363                 $this->element('p', null, _('(None)'));
364             }
365         }
366
367         if ($cnt == MEMBERS_PER_SECTION) {
368             $this->element('a', array('href' => common_local_url('groupmembers',
369                                                                  array('nickname' => $this->group->nickname))),
370                            _('All members'));
371         }
372
373         $this->elementEnd('div');
374     }
375 }