]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/replies.php
Merge branch '0.8.x' into userdesign
[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 OwnerDesignAction
49 {
50     var $page = null;
51
52     /**
53      * Prepare the object
54      *
55      * Check the input values and initialize the object.
56      * Shows an error page on bad input.
57      *
58      * @param array $args $_REQUEST data
59      *
60      * @return boolean success flag
61      */
62
63     function prepare($args)
64     {
65         parent::prepare($args);
66
67         $nickname = common_canonical_nickname($this->arg('nickname'));
68
69         $this->user = User::staticGet('nickname', $nickname);
70
71         if (!$this->user) {
72             $this->clientError(_('No such user.'));
73             return false;
74         }
75
76         $profile = $this->user->getProfile();
77
78         if (!$profile) {
79             $this->serverError(_('User has no profile.'));
80             return false;
81         }
82
83         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
84
85         common_set_returnto($this->selfUrl());
86
87         return true;
88     }
89
90     /**
91      * Handle a request
92      *
93      * Just show the page. All args already handled.
94      *
95      * @param array $args $_REQUEST data
96      *
97      * @return void
98      */
99
100     function handle($args)
101     {
102         parent::handle($args);
103         $this->showPage();
104     }
105
106     /**
107      * Title of the page
108      *
109      * Includes name of user and page number.
110      *
111      * @return string title of page
112      */
113
114     function title()
115     {
116         if ($this->page == 1) {
117             return sprintf(_("Replies to %s"), $this->user->nickname);
118         } else {
119             return sprintf(_("Replies to %s, page %d"),
120                            $this->user->nickname,
121                            $this->page);
122         }
123     }
124
125     /**
126      * Feeds for the <head> section
127      *
128      * @return void
129      */
130
131     function getFeeds()
132     {
133         $rssurl   = common_local_url('repliesrss',
134                                      array('nickname' => $this->user->nickname));
135         $rsstitle = sprintf(_('Feed for replies to %s'), $this->user->nickname);
136
137         return array(new Feed(Feed::RSS1, $rssurl, $rsstitle));
138     }
139
140     /**
141      * show the personal group nav
142      *
143      * @return void
144      */
145
146     function showLocalNav()
147     {
148         $nav = new PersonalGroupNav($this);
149         $nav->show();
150     }
151
152     /**
153      * Show the content
154      *
155      * A list of notices that are replies to the user, plus pagination.
156      *
157      * @return void
158      */
159
160     function showContent()
161     {
162         $notice = $this->user->getReplies(($this->page-1) * NOTICES_PER_PAGE,
163                                           NOTICES_PER_PAGE + 1);
164
165         $nl = new NoticeList($notice, $this);
166
167         $cnt = $nl->show();
168         if (0 === $cnt) {
169             $this->showEmptyListMessage();
170         }
171
172         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
173                           $this->page, 'replies',
174                           array('nickname' => $this->user->nickname));
175     }
176
177     function showEmptyListMessage()
178     {
179         $message = sprintf(_('This is the timeline showing replies to %s but %s hasn\'t received a notice to his attention yet.'), $this->user->nickname, $this->user->nickname) . ' ';
180
181         if (common_logged_in()) {
182             $current_user = common_current_user();
183             if ($this->user->id === $current_user->id) {
184                 $message .= _('You can engage other users in a conversation, subscribe to more people or [join groups](%%action.groups%%).');
185             } else {
186                 $message .= sprintf(_('You can try to [nudge %s](../%s) or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname);
187             }
188         }
189         else {
190             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname);
191         }
192
193         $this->elementStart('div', 'guide');
194         $this->raw(common_markup_to_html($message));
195         $this->elementEnd('div');
196     }
197
198     function isReadOnly($args)
199     {
200         return true;
201     }
202 }