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