]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showmessage.php
generate an etag for shownotice
[quix0rs-gnu-social.git] / actions / showmessage.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/mailbox.php');
23
24 class ShowmessageAction extends MailboxAction {
25
26         function handle($args) {
27
28                 Action::handle($args);
29
30                 $message = $this->get_message();
31
32                 if (!$message) {
33                         $this->client_error(_('No such message.'), 404);
34                         return;
35                 }
36                 
37                 $cur = common_current_user();
38                 
39                 if ($cur && ($cur->id == $message->from_profile || $cur->id == $message->to_profile)) {
40                         $this->show_page($cur, 1);
41                 } else {
42                         $this->client_error(_('Only the sender and recipient may read this message.'), 403);
43                         return;
44                 }
45         }
46         
47         function get_message() {
48                 $id = $this->trimmed('message');
49                 $message = Message::staticGet('id', $id);
50                 return $message;
51         }
52         
53         function get_title($user, $page) {
54                 $message = $this->get_message();
55                 if (!$message) {
56                         return NULL;
57                 }
58                 
59                 if ($user->id == $message->from_profile) {
60                         $to = $message->getTo();
61                         $title = sprintf(_("Message to %1\$s on %2\$s"),
62                                                          $to->nickname,
63                                                          common_exact_date($message->created));
64                 } else if ($user->id == $message->to_profile) {
65                         $from = $message->getFrom();
66                         $title = sprintf(_("Message from %1\$s on %2\$s"),
67                                                          $from->nickname,
68                                                          common_exact_date($message->created));
69                 }
70                 return $title;
71         }
72
73         function get_messages($user, $page) {
74                 $message = new Message();
75                 $message->id = $this->trimmed('message');
76                 $message->find();
77                 return $message;
78         }
79         
80         function get_message_profile($message) {
81                 $user = common_current_user();
82                 if ($user->id == $message->from_profile) {
83                         return $message->getTo();
84                 } else if ($user->id == $message->to_profile) {
85                         return $message->getFrom();
86                 } else {
87                         # This shouldn't happen
88                         return NULL;
89                 }
90         }
91         
92         function get_instructions() {
93                 return '';
94         }
95         
96         function views_menu() {
97                 return;
98         }
99 }
100