]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/shownotice.php
abdaa72cacc4cac34c6cec3309ad6e9a553579cb
[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     var $notice = null;
27     var $profile = null;
28     var $avatar = null;
29
30     function prepare($args)
31     {
32
33         parent::prepare($args);
34
35         $id = $this->arg('notice');
36         $this->notice = Notice::staticGet($id);
37
38         if (!$this->notice) {
39             $this->client_error(_('No such notice.'), 404);
40             return false;
41         }
42
43         $this->profile = $this->notice->getProfile();
44
45         if (!$this->profile) {
46             $this->server_error(_('Notice has no profile'), 500);
47             return false;
48         }
49
50         $this->avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
51
52         return true;
53     }
54
55     function last_modified()
56     {
57         return max(strtotime($this->notice->created),
58                    strtotime($this->profile->modified),
59                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
60     }
61
62     function etag()
63     {
64         return 'W/"' . implode(':', array($this->arg('action'),
65                                           common_language(),
66                                           $this->notice->id,
67                                           strtotime($this->notice->created),
68                                           strtotime($this->profile->modified),
69                                           ($this->avatar) ? strtotime($this->avatar->modified) : 0)) . '"';
70     }
71
72     function handle($args)
73     {
74
75         parent::handle($args);
76
77         common_show_header(sprintf(_('%1$s\'s status on %2$s'),
78                                    $this->profile->nickname,
79                                    common_exact_date($this->notice->created)),
80                            array($this, 'show_header'), null,
81                            array($this, 'show_top'));
82
83         common_element_start('ul', array('id' => 'notices'));
84         $nli = new NoticeListItem($this->notice);
85         $nli->show();
86         common_element_end('ul');
87
88         common_show_footer();
89     }
90
91     function show_header()
92     {
93
94         $user = User::staticGet($this->profile->id);
95
96         if (!$user) {
97             return;
98         }
99
100         if ($user->emailmicroid && $user->email && $this->notice->uri) {
101             common_element('meta', array('name' => 'microid',
102                                          'content' => "mailto+http:sha1:" . sha1(sha1('mailto:' . $user->email) . sha1($this->notice->uri))));
103         }
104
105         if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
106             common_element('meta', array('name' => 'microid',
107                                          'content' => "xmpp+http:sha1:" . sha1(sha1('xmpp:' . $user->jabber) . sha1($this->notice->uri))));
108         }
109     }
110
111     function show_top()
112     {
113         $cur = common_current_user();
114         if ($cur && $cur->id == $this->profile->id) {
115             common_notice_form();
116         }
117     }
118
119     function no_such_notice()
120     {
121         common_user_error(_('No such notice.'));
122     }
123 }