]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/shownotice.php
end ETag with quotes
[quix0rs-gnu-social.git] / actions / shownotice.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/stream.php');
23
24 class ShownoticeAction extends StreamAction {
25
26         function init($args) {
27
28                 parent::init($args);
29
30                 $id = $this->arg('notice');
31                 $this->notice = Notice::staticGet($id);
32
33                 if (!$this->notice) {
34                         $this->client_error(_('No such notice.'), 404);
35                         return false;
36                 }
37
38                 $this->profile = $this->notice->getProfile();
39
40                 if (!$this->profile) {
41                         $this->server_error(_('Notice has no profile'), 500);
42                         return false;
43                 }
44
45                 $this->avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
46
47                 return true;
48         }
49
50         function last_modified() {
51                 return max(strtotime($this->notice->created),
52                                    strtotime($this->profile->modified),
53                                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
54         }
55
56         function etag() {
57                 return 'W/"' . implode(':', array($this->arg('action'),
58                                                                                   common_language(),
59                                                                                   $this->notice->id,
60                                                                                   strtotime($this->notice->created),
61                                                                                   strtotime($this->profile->modified),
62                                                                                   ($this->avatar) ? strtotime($this->avatar->modified) : 0)) . '"';
63         }
64
65         function handle($args) {
66
67                 parent::handle($args);
68
69                 common_show_header(sprintf(_('%1$s\'s status on %2$s'),
70                                                                    $this->profile->nickname,
71                                                                    common_exact_date($this->notice->created)),
72                                                    array($this, 'show_header'), NULL,
73                                                    array($this, 'show_top'));
74
75                 common_element_start('ul', array('id' => 'notices'));
76                 $this->show_notice($this->notice);
77                 common_element_end('ul');
78
79                 common_show_footer();
80         }
81
82         function show_header() {
83
84                 $user = User::staticGet($this->profile->id);
85
86                 if (!$user) {
87                         return;
88                 }
89
90                 if ($user->emailmicroid && $user->email && $this->notice->uri) {
91                         common_element('meta', array('name' => 'microid',
92                                                                                  'content' => "mailto+http:sha1:" . sha1(sha1('mailto:' . $user->email) . sha1($this->notice->uri))));
93                 }
94
95                 if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
96                         common_element('meta', array('name' => 'microid',
97                                                                                  'content' => "xmpp+http:sha1:" . sha1(sha1('xmpp:' . $user->jabber) . sha1($this->notice->uri))));
98                 }
99         }
100
101         function show_top() {
102                 $cur = common_current_user();
103                 if ($cur && $cur->id == $this->profile->id) {
104                         common_notice_form();
105                 }
106         }
107
108         function no_such_notice() {
109                 common_user_error(_('No such notice.'));
110         }
111 }