]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
f404c648d723f2ac938116938c54dc3dabaa4f5b
[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 /**
39  * Group main page
40  *
41  * @category Group
42  * @package  Laconica
43  * @author   Evan Prodromou <evan@controlyourself.ca>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://laconi.ca/
46  */
47
48 class ShowgroupAction extends Action
49 {
50     /** group we're viewing. */
51     var $group = null;
52     /** page we're viewing. */
53     var $page = null;
54
55     /**
56      * Is this page read-only?
57      *
58      * @return boolean true
59      */
60
61     function isReadOnly()
62     {
63         return true;
64     }
65
66     /**
67      * Title of the page
68      *
69      * @return string page title, with page number
70      */
71
72     function title()
73     {
74         if ($this->page == 1) {
75             return sprintf(_("%s group"), $this->group->nickname);
76         } else {
77             return sprintf(_("%s group, page %d"),
78                            $this->group->nickname,
79                            $this->page);
80         }
81     }
82
83     /**
84      * Prepare the action
85      *
86      * Reads and validates arguments and instantiates the attributes.
87      *
88      * @param array $args $_REQUEST args
89      *
90      * @return boolean success flag
91      */
92
93     function prepare($args)
94     {
95         parent::prepare($args);
96
97         if (!common_config('inboxes','enabled')) {
98             $this->serverError(_('Inboxes must be enabled for groups to work'));
99             return false;
100         }
101
102         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
103
104         $nickname_arg = $this->arg('nickname');
105         $nickname = common_canonical_nickname($nickname_arg);
106
107         // Permanent redirect on non-canonical nickname
108
109         if ($nickname_arg != $nickname) {
110             $args = array('nickname' => $nickname);
111             if ($this->page != 1) {
112                 $args['page'] = $this->page;
113             }
114             common_redirect(common_local_url('showgroup', $args), 301);
115             return false;
116         }
117
118         if (!$nickname) {
119             $this->clientError(_('No nickname'), 404);
120             return false;
121         }
122
123         $this->group = User_group::staticGet('nickname', $nickname);
124
125         if (!$this->group) {
126             $this->clientError(_('No such group'), 404);
127             return false;
128         }
129
130         return true;
131     }
132
133     /**
134      * Handle the request
135      *
136      * Shows a profile for the group, some controls, and a list of
137      * group notices.
138      *
139      * @return void
140      */
141
142     function handle($args)
143     {
144         $this->showPage();
145     }
146
147     /**
148      * Show the page content
149      *
150      * Shows a group profile and a list of group notices
151      */
152
153     function showContent()
154     {
155         $this->showGroupProfile();
156         $this->showGroupNotices();
157     }
158
159     /**
160      * Show the group notices
161      *
162      * @return void
163      */
164
165     function showGroupNotices()
166     {
167         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
168                                            NOTICES_PER_PAGE + 1);
169
170         $nl = new NoticeList($notice, $this);
171         $cnt = $nl->show();
172
173         $this->pagination($this->page > 1,
174                           $cnt > NOTICES_PER_PAGE,
175                           $this->page,
176                           'showgroup',
177                           array('nickname' => $this->group->nickname));
178     }
179
180     /**
181      * Show the group profile
182      *
183      * Information about the group
184      *
185      * @return void
186      */
187
188     function showGroupProfile()
189     {
190         $this->elementStart('div', array('id' => 'group_profile',
191                                          'class' => 'vcard author'));
192
193         $this->element('h2', null, _('Group profile'));
194
195         $this->elementStart('dl', 'group_depiction');
196         $this->element('dt', null, _('Photo'));
197         $this->elementStart('dd');
198
199         $logo = ($this->group->homepage_logo) ?
200           $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
201
202         $this->element('img', array('src' => $logo,
203                                     'class' => 'photo avatar',
204                                     'width' => AVATAR_PROFILE_SIZE,
205                                     'height' => AVATAR_PROFILE_SIZE,
206                                     'alt' => $this->group->nickname));
207         $this->elementEnd('dd');
208         $this->elementEnd('dl');
209
210         $this->elementStart('dl', 'group_nickname');
211         $this->element('dt', null, _('Nickname'));
212         $this->elementStart('dd');
213         $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn nickname url uid';
214         $this->element('a', array('href' => $this->group->homeUrl(),
215                                   'rel' => 'me', 'class' => $hasFN),
216                             $this->group->nickname);
217         $this->elementEnd('dd');
218         $this->elementEnd('dl');
219
220         if ($this->group->fullname) {
221             $this->elementStart('dl', 'group_fn');
222             $this->element('dt', null, _('Full name'));
223             $this->elementStart('dd');
224             $this->element('span', 'fn', $this->group->fullname);
225             $this->elementEnd('dd');
226             $this->elementEnd('dl');
227         }
228
229         if ($this->group->location) {
230             $this->elementStart('dl', 'group_location');
231             $this->element('dt', null, _('Location'));
232             $this->element('dd', 'location', $this->group->location);
233             $this->elementEnd('dl');
234         }
235
236         if ($this->group->homepage) {
237             $this->elementStart('dl', 'group_url');
238             $this->element('dt', null, _('URL'));
239             $this->elementStart('dd');
240             $this->element('a', array('href' => $this->group->homepage,
241                                       'rel' => 'me', 'class' => 'url'),
242                            $this->group->homepage);
243             $this->elementEnd('dd');
244             $this->elementEnd('dl');
245         }
246
247         if ($this->group->description) {
248             $this->elementStart('dl', 'group_note');
249             $this->element('dt', null, _('Note'));
250             $this->element('dd', 'note', $this->group->description);
251             $this->elementEnd('dl');
252         }
253
254         $this->elementEnd('div');
255
256         $this->elementStart('div', array('id' => 'group_actions'));
257         $this->element('h2', null, _('Group actions'));
258         $this->elementStart('ul');
259         $this->elementStart('li', array('id' => 'group_subscribe'));
260         $cur = common_current_user();
261         if ($cur) {
262             if ($cur->isMember($this->group)) {
263                 $lf = new LeaveForm($this, $this->group);
264                 $lf->show();
265                 if ($cur->isAdmin($this->group)) {
266                     $edit = common_local_url('editgroup',
267                                              array('nickname' => $this->group->nickname));
268                     $this->element('a',
269                                    array('href' => $edit,
270                                          'id' => 'group_admin'),
271                                    _('Admin'));
272                 }
273             } else {
274                 $jf = new JoinForm($this, $this->group);
275                 $jf->show();
276             }
277         }
278
279         $this->elementEnd('li');
280
281         $this->elementEnd('ul');
282         $this->elementEnd('div');
283     }
284
285     /**
286      * Show a list of links to feeds this page produces
287      *
288      * @return void
289      */
290
291     function showExportData()
292     {
293         $fl = new FeedList($this);
294         $fl->show(array(0=>array('href'=>common_local_url('grouprss',
295                                                           array('nickname' => $this->group->nickname)),
296                                  'type' => 'rss',
297                                  'version' => 'RSS 1.0',
298                                  'item' => 'notices')));
299     }
300
301     /**
302      * Show a list of links to feeds this page produces
303      *
304      * @return void
305      */
306
307     function showFeeds()
308     {
309         $url =
310           common_local_url('grouprss',
311                            array('nickname' => $this->group->nickname));
312
313         $this->element('link', array('rel' => 'alternate',
314                                      'href' => $url,
315                                      'type' => 'application/rss+xml',
316                                      'title' => sprintf(_('Notice feed for %s group'),
317                                                         $this->group->nickname)));
318     }
319 }