]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/shownotice.php
Better exception handling in index
[quix0rs-gnu-social.git] / actions / shownotice.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * Show a single notice
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  * Show a single notice
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 ShownoticeAction extends Action
49 {
50     /**
51      * Notice object to show
52      */
53
54     var $notice = null;
55
56     /**
57      * Profile of the notice object
58      */
59
60     var $profile = null;
61
62     /**
63      * Avatar of the profile of the notice object
64      */
65
66     var $avatar = null;
67
68     /**
69      * Load attributes based on database arguments
70      *
71      * Loads all the DB stuff
72      *
73      * @param array $args $_REQUEST array
74      *
75      * @return success flag
76      */
77
78     function prepare($args)
79     {
80         parent::prepare($args);
81
82         $id = $this->arg('notice');
83
84         $this->notice = Notice::staticGet($id);
85
86         if (!$this->notice) {
87             $this->clientError(_('No such notice.'), 404);
88             return false;
89         }
90
91         $this->profile = $this->notice->getProfile();
92
93         if (!$this->profile) {
94             $this->serverError(_('Notice has no profile'), 500);
95             return false;
96         }
97
98         $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
99
100         return true;
101     }
102
103     /**
104      * Is this action read-only?
105      *
106      * @return boolean true
107      */
108
109     function isReadOnly()
110     {
111         return true;
112     }
113
114     /**
115      * Last-modified date for page
116      *
117      * When was the content of this page last modified? Based on notice,
118      * profile, avatar.
119      *
120      * @return int last-modified date as unix timestamp
121      */
122
123     function lastModified()
124     {
125         return max(strtotime($this->notice->created),
126                    strtotime($this->profile->modified),
127                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
128     }
129
130     /**
131      * An entity tag for this page
132      *
133      * Shows the ETag for the page, based on the notice ID and timestamps
134      * for the notice, profile, and avatar. It's weak, since we change
135      * the date text "one hour ago", etc.
136      *
137      * @return string etag
138      */
139
140     function etag()
141     {
142         $avtime = ($this->avatar) ?
143           strtotime($this->avatar->modified) : 0;
144
145         return 'W/"' . implode(':', array($this->arg('action'),
146                                           common_language(),
147                                           $this->notice->id,
148                                           strtotime($this->notice->created),
149                                           strtotime($this->profile->modified),
150                                           $avtime)) . '"';
151     }
152
153     /**
154      * Title of the page
155      *
156      * @return string title of the page
157      */
158
159     function title()
160     {
161         return sprintf(_('%1$s\'s status on %2$s'),
162                        $this->profile->nickname,
163                        common_exact_date($this->notice->created));
164     }
165
166     /**
167      * Handle input
168      *
169      * Only handles get, so just show the page.
170      *
171      * @param array $args $_REQUEST data (unused)
172      *
173      * @return void
174      */
175
176     function handle($args)
177     {
178         parent::handle($args);
179
180         $this->showPage();
181     }
182
183
184     /**
185      * Don't show local navigation
186      *
187      * @return void
188      */
189
190     function showLocalNavBlock()
191     {
192     }
193
194
195     /**
196      * Fill the content area of the page
197      *
198      * Shows a single notice list item.
199      *
200      * @return void
201      */
202
203     function showContent()
204     {
205         $this->elementStart('ul', array('class' => 'notices'));
206         $nli = new NoticeListItem($this->notice, $this);
207         $nli->show();
208         $this->elementEnd('ul');
209     }
210
211
212
213     /**
214      * Don't show page notice
215      *
216      * @return void
217      */
218
219     function showPageNoticeBlock()
220     {
221     }
222
223
224     /**
225      * Don't show aside
226      *
227      * @return void
228      */
229
230     function showAside() {
231     }
232
233
234     /**
235      * Extra <head> content
236      *
237      * We show the microid(s) for the author, if any.
238      *
239      * @return void
240      */
241
242     function extraHead()
243     {
244         $user = User::staticGet($this->profile->id);
245
246         if (!$user) {
247             return;
248         }
249
250         if ($user->emailmicroid && $user->email && $this->notice->uri) {
251             $id = new Microid('mailto:'. $user->email,
252                               $this->notice->uri);
253             $this->element('meta', array('name' => 'microid',
254                                          'content' => $id->toString()));
255         }
256
257         if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
258             $id = new Microid('xmpp:', $user->jabber,
259                               $this->notice->uri);
260             $this->element('meta', array('name' => 'microid',
261                                          'content' => $id->toString()));
262         }
263     }
264 }