]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showmessage.php
5d23fb13f3e1eb2b016ab1bdc8295e84c476e4df
[quix0rs-gnu-social.git] / actions / showmessage.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show a single message
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 if (!defined('STATUSNET')) { 
30     exit(1); 
31 }
32
33 require_once INSTALLDIR.'/lib/mailbox.php';
34
35 /**
36  * Show a single message
37  *
38  * // XXX: It is totally weird how this works!
39  * 
40  * @category Personal
41  * @package  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://status.net/
45  */
46
47 class ShowmessageAction extends MailboxAction
48 {
49     /**
50      * Message object to show
51      */
52
53     var $message = null;
54     
55     /**
56      * The current user
57      */
58     
59     var $user = null;
60
61     /**
62      * Load attributes based on database arguments
63      *
64      * Loads all the DB stuff
65      *
66      * @param array $args $_REQUEST array
67      *
68      * @return success flag
69      */
70
71     function prepare($args)
72     {
73         parent::prepare($args);
74         
75         $this->page = 1;
76         
77         $id            = $this->trimmed('message');
78         $this->message = Message::staticGet('id', $id);
79
80         if (!$this->message) {
81             $this->clientError(_('No such message.'), 404);
82             return false;
83         }
84
85         $this->user = common_current_user();
86
87         return true;
88     }
89
90     function handle($args)
91     {
92         Action::handle($args);
93                         
94         if ($this->user && ($this->user->id == $this->message->from_profile || 
95             $this->user->id == $this->message->to_profile)) {
96                 $this->showPage();
97         } else {
98             $this->clientError(_('Only the sender and recipient ' .
99                 'may read this message.'), 403);
100             return;
101         }
102     }
103     
104     function title()
105     {                        
106         if ($this->user->id == $this->message->from_profile) {
107             $to = $this->message->getTo();
108             return sprintf(_("Message to %1\$s on %2\$s"),
109                              $to->nickname,
110                              common_exact_date($this->message->created));
111         } else if ($this->user->id == $this->message->to_profile) {
112             $from = $this->message->getFrom();
113             return sprintf(_("Message from %1\$s on %2\$s"),
114                              $from->nickname,
115                              common_exact_date($this->message->created));
116         }
117     }
118         
119     function getMessages() 
120     {    
121         $message     = new Message();
122         $message->id = $this->message->id;
123         $message->find();
124         return $message;
125     }
126     
127     function getMessageProfile()
128     {
129         if ($this->user->id == $this->message->from_profile) {
130             return $this->message->getTo();
131         } else if ($this->user->id == $this->message->to_profile) {
132             return $this->message->getFrom();
133         } else {
134             // This shouldn't happen
135             return null;
136         }
137     }
138     
139     /**
140      * Don't show local navigation
141      *
142      * @return void
143      */
144
145     function showLocalNavBlock()
146     {
147     }
148     
149     /**
150      * Don't show page notice
151      *
152      * @return void
153      */
154
155     function showPageNoticeBlock()
156     {
157     }
158
159     /**
160      * Don't show aside
161      *
162      * @return void
163      */
164
165     function showAside() 
166     {
167     }
168  
169     /**
170      * Don't show any instructions
171      *
172      * @return string
173      */
174      
175     function getInstructions()
176     {
177         return '';
178     }
179
180     function isReadOnly($args)
181     {
182         return true;
183     }
184 }