]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
switch between conversation and stream for public and group
[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-2011 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 /**
39  * Group main page
40  *
41  * @category Group
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47 class ShowgroupAction extends GroupAction
48 {
49     /** page we're viewing. */
50     var $page = null;
51     var $userProfile = null;
52     var $notice = null;
53     var $mode = 'conversation';
54
55     /**
56      * Is this page read-only?
57      *
58      * @return boolean true
59      */
60     function isReadOnly($args)
61     {
62         return true;
63     }
64
65     /**
66      * Title of the page
67      *
68      * @return string page title, with page number
69      */
70     function title()
71     {
72         $base = $this->group->getFancyName();
73
74         if ($this->page == 1) {
75             // TRANS: Page title for first group page. %s is a group name.
76             return sprintf(_('%s group'), $base);
77         } else {
78             // TRANS: Page title for any but first group page.
79             // TRANS: %1$s is a group name, $2$s is a page number.
80             return sprintf(_('%1$s group, page %2$d'),
81                            $base,
82                            $this->page);
83         }
84     }
85
86     /**
87      * Prepare the action
88      *
89      * Reads and validates arguments and instantiates the attributes.
90      *
91      * @param array $args $_REQUEST args
92      *
93      * @return boolean success flag
94      */
95     function prepare($args)
96     {
97         parent::prepare($args);
98
99         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
100
101         $this->mode = $this->trimmed('mode', 'conversation');
102
103         $this->userProfile = Profile::current();
104
105         if ($this->mode == 'stream') {
106             $stream = new GroupNoticeStream($this->group, $this->userProfile);
107         } else {
108             $stream = new ThreadingGroupNoticeStream($this->group, $this->userProfile);
109         }
110
111         $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
112                                             NOTICES_PER_PAGE + 1);
113
114         common_set_returnto($this->selfUrl());
115
116         return true;
117     }
118
119     /**
120      * Handle the request
121      *
122      * Shows a profile for the group, some controls, and a list of
123      * group notices.
124      *
125      * @return void
126      */
127     function handle($args)
128     {
129         $this->showPage();
130     }
131
132     /**
133      * Show the page content
134      *
135      * Shows a group profile and a list of group notices
136      */
137     function showContent()
138     {
139         $this->showGroupNotices();
140     }
141
142     /**
143      * Show the group notices
144      *
145      * @return void
146      */
147     function showGroupNotices()
148     {
149         if ($this->mode == 'stream') {
150             $nl = new NoticeList($this->notice, $this);
151         } else {
152             $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
153         } 
154
155         $cnt = $nl->show();
156
157         $this->pagination($this->page > 1,
158                           $cnt > NOTICES_PER_PAGE,
159                           $this->page,
160                           'showgroup',
161                           array('nickname' => $this->group->nickname));
162     }
163
164     /**
165      * Get a list of the feeds for this page
166      *
167      * @return void
168      */
169     function getFeeds()
170     {
171         $url =
172           common_local_url('grouprss',
173                            array('nickname' => $this->group->nickname));
174
175         return array(new Feed(Feed::JSON,
176                               common_local_url('ApiTimelineGroup',
177                                                array('format' => 'as',
178                                                      'id' => $this->group->id)),
179                               // TRANS: Tooltip for feed link. %s is a group nickname.
180                               sprintf(_('Notice feed for %s group (Activity Streams JSON)'),
181                                       $this->group->nickname)),
182                     new Feed(Feed::RSS1,
183                               common_local_url('grouprss',
184                                                array('nickname' => $this->group->nickname)),
185                               // TRANS: Tooltip for feed link. %s is a group nickname.
186                               sprintf(_('Notice feed for %s group (RSS 1.0)'),
187                                       $this->group->nickname)),
188                      new Feed(Feed::RSS2,
189                               common_local_url('ApiTimelineGroup',
190                                                array('format' => 'rss',
191                                                      'id' => $this->group->id)),
192                               // TRANS: Tooltip for feed link. %s is a group nickname.
193                               sprintf(_('Notice feed for %s group (RSS 2.0)'),
194                                       $this->group->nickname)),
195                      new Feed(Feed::ATOM,
196                               common_local_url('ApiTimelineGroup',
197                                                array('format' => 'atom',
198                                                      'id' => $this->group->id)),
199                               // TRANS: Tooltip for feed link. %s is a group nickname.
200                               sprintf(_('Notice feed for %s group (Atom)'),
201                                       $this->group->nickname)),
202                      new Feed(Feed::FOAF,
203                               common_local_url('foafgroup',
204                                                array('nickname' => $this->group->nickname)),
205                               // TRANS: Tooltip for feed link. %s is a group nickname.
206                               sprintf(_('FOAF for %s group'),
207                                        $this->group->nickname)));
208     }
209
210     function showAnonymousMessage()
211     {
212         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
213             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
214             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
215             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
216             // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
217             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
218             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
219                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
220                 'short messages about their life and interests. '.
221                 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
222                      $this->group->nickname);
223         } else {
224             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
225             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
226             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
227             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
228             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
229                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
230                 'short messages about their life and interests. '),
231                      $this->group->nickname);
232         }
233         $this->elementStart('div', array('id' => 'anon_notice'));
234         $this->raw(common_markup_to_html($m));
235         $this->elementEnd('div');
236     }
237 }