]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/shownotice.php
Merge branch '1.0.x' into people_tags_rebase
[quix0rs-gnu-social.git] / actions / shownotice.php
1 <?php
2 /**
3  * StatusNet, 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   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2008-2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !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  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
48 class ShownoticeAction extends OwnerDesignAction
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         if ($this->boolean('ajax')) {
82             StatusNet::setApi(true);
83         }
84
85         $id = $this->arg('notice');
86
87         $this->notice = Notice::staticGet($id);
88
89         if (empty($this->notice)) {
90             // Did we used to have it, and it got deleted?
91             $deleted = Deleted_notice::staticGet($id);
92             if (!empty($deleted)) {
93                 $this->clientError(_('Notice deleted.'), 410);
94             } else {
95                 $this->clientError(_('No such notice.'), 404);
96             }
97             return false;
98         }
99
100         $this->profile = $this->notice->getProfile();
101
102         if (empty($this->profile)) {
103             $this->serverError(_('Notice has no profile.'), 500);
104             return false;
105         }
106
107         $this->user = User::staticGet('id', $this->profile->id);
108
109         $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
110
111         return true;
112     }
113
114     /**
115      * Is this action read-only?
116      *
117      * @return boolean true
118      */
119
120     function isReadOnly($args)
121     {
122         return true;
123     }
124
125     /**
126      * Last-modified date for page
127      *
128      * When was the content of this page last modified? Based on notice,
129      * profile, avatar.
130      *
131      * @return int last-modified date as unix timestamp
132      */
133
134     function lastModified()
135     {
136         return max(strtotime($this->notice->modified),
137                    strtotime($this->profile->modified),
138                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
139     }
140
141     /**
142      * An entity tag for this page
143      *
144      * Shows the ETag for the page, based on the notice ID and timestamps
145      * for the notice, profile, and avatar. It's weak, since we change
146      * the date text "one hour ago", etc.
147      *
148      * @return string etag
149      */
150
151     function etag()
152     {
153         $avtime = ($this->avatar) ?
154           strtotime($this->avatar->modified) : 0;
155
156         return 'W/"' . implode(':', array($this->arg('action'),
157                                           common_user_cache_hash(),
158                                           common_language(),
159                                           $this->notice->id,
160                                           strtotime($this->notice->created),
161                                           strtotime($this->profile->modified),
162                                           $avtime)) . '"';
163     }
164
165     /**
166      * Title of the page
167      *
168      * @return string title of the page
169      */
170
171     function title()
172     {
173         $base = $this->profile->getFancyName();
174
175         return sprintf(_('%1$s\'s status on %2$s'),
176                        $base,
177                        common_exact_date($this->notice->created));
178     }
179
180     /**
181      * Handle input
182      *
183      * Only handles get, so just show the page.
184      *
185      * @param array $args $_REQUEST data (unused)
186      *
187      * @return void
188      */
189
190     function handle($args)
191     {
192         parent::handle($args);
193
194         if ($this->boolean('ajax')) {
195             $this->showAjax();
196         } else {
197             if ($this->notice->is_local == Notice::REMOTE_OMB) {
198                 if (!empty($this->notice->url)) {
199                     $target = $this->notice->url;
200                 } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
201                     // Old OMB posts saved the remote URL only into the URI field.
202                     $target = $this->notice->uri;
203                 } else {
204                     // Shouldn't happen.
205                     $target = false;
206                 }
207                 if ($target && $target != $this->selfUrl()) {
208                     common_redirect($target, 301);
209                     return false;
210                 }
211             }
212             $this->showPage();
213         }
214     }
215
216     /**
217      * Don't show local navigation
218      *
219      * @return void
220      */
221
222     function showLocalNavBlock()
223     {
224     }
225
226     /**
227      * Fill the content area of the page
228      *
229      * Shows a single notice list item.
230      *
231      * @return void
232      */
233
234     function showContent()
235     {
236         $this->elementStart('ol', array('class' => 'notices xoxo'));
237         $nli = new SingleNoticeItem($this->notice, $this);
238         $nli->show();
239         $this->elementEnd('ol');
240     }
241
242     function showAjax()
243     {
244         header('Content-Type: text/xml;charset=utf-8');
245         $this->xw->startDocument('1.0', 'UTF-8');
246         $this->elementStart('html');
247         $this->elementStart('head');
248         $this->element('title', null, _('Notice'));
249         $this->elementEnd('head');
250         $this->elementStart('body');
251         $nli = new NoticeListItem($this->notice, $this);
252         $nli->show();
253         $this->elementEnd('body');
254         $this->elementEnd('html');
255     }
256
257     /**
258      * Don't show page notice
259      *
260      * @return void
261      */
262
263     function showPageNoticeBlock()
264     {
265     }
266
267     /**
268      * Don't show aside
269      *
270      * @return void
271      */
272
273     function showAside() {
274     }
275
276     /**
277      * Extra <head> content
278      *
279      * We show the microid(s) for the author, if any.
280      *
281      * @return void
282      */
283
284     function extraHead()
285     {
286         $user = User::staticGet($this->profile->id);
287
288         if (!$user) {
289             return;
290         }
291
292         if ($user->emailmicroid && $user->email && $this->notice->uri) {
293             $id = new Microid('mailto:'. $user->email,
294                               $this->notice->uri);
295             $this->element('meta', array('name' => 'microid',
296                                          'content' => $id->toString()));
297         }
298
299         $this->element('link',array('rel'=>'alternate',
300             'type'=>'application/json+oembed',
301             'href'=>common_local_url(
302                 'oembed',
303                 array(),
304                 array('format'=>'json','url'=>$this->notice->uri)),
305             'title'=>'oEmbed'),null);
306         $this->element('link',array('rel'=>'alternate',
307             'type'=>'text/xml+oembed',
308             'href'=>common_local_url(
309                 'oembed',
310                 array(),
311                 array('format'=>'xml','url'=>$this->notice->uri)),
312             'title'=>'oEmbed'),null);
313
314         // Extras to aid in sharing notices to Facebook
315         $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
316         $avatarUrl = ($avatar) ?
317                      $avatar->displayUrl() :
318                      Avatar::defaultImage(AVATAR_PROFILE_SIZE);
319         $this->element('meta', array('property' => 'og:image',
320                                      'content' => $avatarUrl));
321         $this->element('meta', array('property' => 'og:description',
322                                      'content' => $this->notice->content));
323     }
324 }
325
326 class SingleNoticeItem extends DoFollowListItem
327 {
328     /**
329      * recipe function for displaying a single notice.
330      *
331      * We overload to show attachments.
332      *
333      * @return void
334      */
335
336     function show()
337     {
338         $this->showStart();
339         if (Event::handle('StartShowNoticeItem', array($this))) {
340             $this->showNotice();
341             $this->showNoticeAttachments();
342             $this->showNoticeInfo();
343             $this->showNoticeOptions();
344             Event::handle('EndShowNoticeItem', array($this));
345         }
346
347         $this->showEnd();
348     }
349
350     /**
351      * For our zoomed-in special case we'll use a fuller list
352      * for the attachment info.
353      */
354     function showNoticeAttachments() {
355         $al = new AttachmentList($this->notice, $this->out);
356         $al->show();
357     }
358
359     /**
360      * show the avatar of the notice's author
361      *
362      * We use the larger size for single notice page.
363      *
364      * @return void
365      */
366
367     function showAvatar()
368     {
369         $avatar_size = AVATAR_PROFILE_SIZE;
370
371         $avatar = $this->profile->getAvatar($avatar_size);
372
373         $this->out->element('img', array('src' => ($avatar) ?
374                                          $avatar->displayUrl() :
375                                          Avatar::defaultImage($avatar_size),
376                                          'class' => 'avatar photo',
377                                          'width' => $avatar_size,
378                                          'height' => $avatar_size,
379                                          'alt' =>
380                                          ($this->profile->fullname) ?
381                                          $this->profile->fullname :
382                                          $this->profile->nickname));
383     }
384 }