]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/replies.php
Merge branch 'dev-0.7.x' into link-rel-paginate
[quix0rs-gnu-social.git] / actions / replies.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * List of replies
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  Personal
23  * @package   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @copyright 2008-2009 Control Yourself, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/personalgroupnav.php';
35 require_once INSTALLDIR.'/lib/noticelist.php';
36 require_once INSTALLDIR.'/lib/feedlist.php';
37
38 /**
39  * List of replies
40  *
41  * @category Personal
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 RepliesAction extends Action
49 {
50     var $user = null;
51     var $page = null;
52
53     /**
54      * Prepare the object
55      *
56      * Check the input values and initialize the object.
57      * Shows an error page on bad input.
58      *
59      * @param array $args $_REQUEST data
60      *
61      * @return boolean success flag
62      */
63
64     function prepare($args)
65     {
66         parent::prepare($args);
67
68         $nickname = common_canonical_nickname($this->arg('nickname'));
69
70         $this->user = User::staticGet('nickname', $nickname);
71
72         if (!$this->user) {
73             $this->clientError(_('No such user.'));
74             return false;
75         }
76
77         $profile = $this->user->getProfile();
78
79         if (!$profile) {
80             $this->serverError(_('User has no profile.'));
81             return false;
82         }
83
84         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
85
86         common_set_returnto($this->selfUrl());
87         
88         return true;
89     }
90
91     /**
92      * Handle a request
93      *
94      * Just show the page. All args already handled.
95      *
96      * @param array $args $_REQUEST data
97      *
98      * @return void
99      */
100
101     function handle($args)
102     {
103         parent::handle($args);
104         $this->showPage();
105     }
106
107     /**
108      * Title of the page
109      *
110      * Includes name of user and page number.
111      *
112      * @return string title of page
113      */
114
115     function title()
116     {
117         if ($this->page == 1) {
118             return sprintf(_("Replies to %s"), $this->user->nickname);
119         } else {
120             return sprintf(_("Replies to %s, page %d"),
121                            $this->user->nickname,
122                            $this->page);
123         }
124     }
125
126     /**
127      * Feeds for the <head> section
128      *
129      * @return void
130      */
131
132     function showFeeds()
133     {
134         $rssurl   = common_local_url('repliesrss',
135                                      array('nickname' => $this->user->nickname));
136         $rsstitle = sprintf(_('Feed for replies to %s'), $this->user->nickname);
137
138         $this->element('link', array('rel' => 'alternate',
139                                      'href' => $rssurl,
140                                      'type' => 'application/rss+xml',
141                                      'title' => $rsstitle));
142     }
143
144     /**
145      * Output document relationship links
146      *
147      * @return void
148      */
149     function showRelationshipLinks()
150     {
151         // Machine-readable pagination
152         if ($this->page > 1) {
153             $this->element('link', array('rel' => 'next',
154                                          'href' => common_local_url('replies',
155                                                                     array('nickname' => $this->user->nickname,
156                                                                           'page' => $this->page - 1)),
157                                          'title' => _('Next Notices')));
158         }
159         $this->element('link', array('rel' => 'prev',
160                                      'href' => common_local_url('replies',
161                                                                 array('nickname' => $this->user->nickname,
162                                                                       'page' => $this->page + 1)),
163                                      'title' => _('Previous Notices')));
164     }
165
166     /**
167      * show the personal group nav
168      *
169      * @return void
170      */
171
172     function showLocalNav()
173     {
174         $nav = new PersonalGroupNav($this);
175         $nav->show();
176     }
177
178     /**
179      * Show the replies feed links
180      *
181      * @return void
182      */
183
184     function showExportData()
185     {
186         $fl = new FeedList($this);
187
188         $rssurl = common_local_url('repliesrss',
189                                    array('nickname' => $this->user->nickname));
190
191         $fl->show(array(0=>array('href'=> $rssurl,
192                                  'type' => 'rss',
193                                  'version' => 'RSS 1.0',
194                                  'item' => 'repliesrss')));
195     }
196
197     /**
198      * Show the content
199      *
200      * A list of notices that are replies to the user, plus pagination.
201      *
202      * @return void
203      */
204
205     function showContent()
206     {
207         $notice = $this->user->getReplies(($this->page-1) * NOTICES_PER_PAGE,
208                                           NOTICES_PER_PAGE + 1);
209
210         $nl = new NoticeList($notice, $this);
211
212         $cnt = $nl->show();
213
214         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
215                           $this->page, 'replies',
216                           array('nickname' => $this->user->nickname));
217     }
218
219     function isReadOnly()
220     {
221         return true;
222     }
223 }