| 
									
										
										
										
											2008-09-17 13:47:41 -04:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Laconica, the distributed open-source microblogging tool | 
					
						
							| 
									
										
										
										
											2008-09-17 13:47:41 -04:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |  * Show a single message | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * PHP version 5 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * LICENCE: This program is free software: you can redistribute it and/or modify | 
					
						
							| 
									
										
										
										
											2008-09-17 13:47:41 -04:00
										 |  |  |  * it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @category  Personal | 
					
						
							|  |  |  |  * @package   Laconica | 
					
						
							|  |  |  |  * @author    Evan Prodromou <evan@controlyourself.ca> | 
					
						
							|  |  |  |  * @copyright 2008-2009 Control Yourself, Inc. | 
					
						
							|  |  |  |  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 | 
					
						
							|  |  |  |  * @link      http://laconi.ca/ | 
					
						
							| 
									
										
										
										
											2008-09-17 13:47:41 -04:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  | if (!defined('LACONICA')) {  | 
					
						
							|  |  |  |     exit(1);  | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-09-17 13:47:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  | require_once INSTALLDIR.'/lib/mailbox.php'; | 
					
						
							| 
									
										
										
										
											2008-09-17 13:47:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Show a single message | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * // XXX: It is totally weird how this works!
 | 
					
						
							|  |  |  |  *  | 
					
						
							|  |  |  |  * @category Personal | 
					
						
							|  |  |  |  * @package  Laconica | 
					
						
							|  |  |  |  * @author   Evan Prodromou <evan@controlyourself.ca> | 
					
						
							|  |  |  |  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 | 
					
						
							|  |  |  |  * @link     http://laconi.ca/ | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-09-17 13:47:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:49:23 -05:00
										 |  |  | class ShowmessageAction extends MailboxAction | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Message object to show | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2008-09-17 13:47:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |     var $message = null; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * The current user | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     var $user = null; | 
					
						
							| 
									
										
										
										
											2008-09-17 13:47:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Load attributes based on database arguments | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Loads all the DB stuff | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param array $args $_REQUEST array | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return success flag | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2008-09-17 13:47:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |     function prepare($args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         parent::prepare($args); | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         $this->page = 1; | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         $id            = $this->trimmed('message'); | 
					
						
							|  |  |  |         $this->message = Message::staticGet('id', $id); | 
					
						
							| 
									
										
										
										
											2008-09-17 13:47:41 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |         if (!$this->message) { | 
					
						
							| 
									
										
										
										
											2009-01-15 23:03:38 +00:00
										 |  |  |             $this->clientError(_('No such message.'), 404); | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |             return false; | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->user = common_current_user(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function handle($args) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         Action::handle($args); | 
					
						
							|  |  |  |                          | 
					
						
							|  |  |  |         if ($this->user && ($this->user->id == $this->message->from_profile ||  | 
					
						
							|  |  |  |             $this->user->id == $this->message->to_profile)) { | 
					
						
							|  |  |  |                 $this->showPage(); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |             $this->clientError(_('Only the sender and recipient ' . | 
					
						
							|  |  |  |                 'may read this message.'), 403); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |     function title() | 
					
						
							|  |  |  |     {                         | 
					
						
							|  |  |  |         if ($this->user->id == $this->message->from_profile) { | 
					
						
							|  |  |  |             $to = $this->message->getTo(); | 
					
						
							|  |  |  |             return sprintf(_("Message to %1\$s on %2\$s"), | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |                              $to->nickname, | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |                              common_exact_date($this->message->created)); | 
					
						
							|  |  |  |         } else if ($this->user->id == $this->message->to_profile) { | 
					
						
							|  |  |  |             $from = $this->message->getFrom(); | 
					
						
							|  |  |  |             return sprintf(_("Message from %1\$s on %2\$s"), | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |                              $from->nickname, | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |                              common_exact_date($this->message->created)); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |          | 
					
						
							|  |  |  |     function getMessages()  | 
					
						
							|  |  |  |     {     | 
					
						
							|  |  |  |         $message     = new Message(); | 
					
						
							|  |  |  |         $message->id = $this->message->id; | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         $message->find(); | 
					
						
							|  |  |  |         return $message; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |     function getMessageProfile() | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |         if ($this->user->id == $this->message->from_profile) { | 
					
						
							|  |  |  |             return $this->message->getTo(); | 
					
						
							|  |  |  |         } else if ($this->user->id == $this->message->to_profile) { | 
					
						
							|  |  |  |             return $this->message->getFrom(); | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |             // This shouldn't happen
 | 
					
						
							| 
									
										
										
										
											2008-12-23 14:21:29 -05:00
										 |  |  |             return null; | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Don't show local navigation | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function showLocalNavBlock() | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Don't show page notice | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function showPageNoticeBlock() | 
					
						
							| 
									
										
										
										
											2008-12-23 14:33:23 -05:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-12-23 14:19:07 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-20 19:16:52 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Don't show aside | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function showAside()  | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Don't show any instructions | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |       | 
					
						
							|  |  |  |     function getInstructions() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return ''; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-01-23 09:15:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-13 15:49:26 -04:00
										 |  |  |     function isReadOnly($args) | 
					
						
							| 
									
										
										
										
											2009-01-23 09:15:15 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |