2008-09-17 18:47:41 +01:00
|
|
|
<?php
|
2009-01-21 03:16:52 +00:00
|
|
|
/**
|
2009-08-25 23:12:20 +01:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2008-09-17 18:47:41 +01:00
|
|
|
*
|
2009-01-21 03:16:52 +00:00
|
|
|
* Show a single message
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
2008-09-17 18:47:41 +01: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-21 03:16:52 +00:00
|
|
|
*
|
|
|
|
* @category Personal
|
2009-08-25 23:12:20 +01:00
|
|
|
* @package StatusNet
|
2009-08-25 23:19:04 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-08-25 23:12:20 +01:00
|
|
|
* @copyright 2008-2009 StatusNet, Inc.
|
2009-01-21 03:16:52 +00:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-25 23:16:46 +01:00
|
|
|
* @link http://status.net/
|
2008-09-17 18:47:41 +01:00
|
|
|
*/
|
2010-10-31 00:16:59 +01:00
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
|
|
|
exit(1);
|
2009-01-21 03:16:52 +00:00
|
|
|
}
|
2008-09-17 18:47:41 +01:00
|
|
|
|
2009-01-21 03:16:52 +00:00
|
|
|
/**
|
|
|
|
* Show a single message
|
|
|
|
*
|
|
|
|
* @category Personal
|
2009-08-25 23:12:20 +01:00
|
|
|
* @package StatusNet
|
2009-08-25 23:19:04 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-01-21 03:16:52 +00:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-25 23:16:46 +01:00
|
|
|
* @link http://status.net/
|
2009-01-21 03:16:52 +00:00
|
|
|
*/
|
2011-02-08 16:33:36 +00:00
|
|
|
|
|
|
|
class ShowmessageAction extends Action
|
2008-12-23 19:49:23 +00:00
|
|
|
{
|
2009-01-21 03:16:52 +00:00
|
|
|
/**
|
|
|
|
* Message object to show
|
|
|
|
*/
|
|
|
|
var $message = null;
|
2010-10-31 00:16:59 +01:00
|
|
|
|
2009-01-21 03:16:52 +00:00
|
|
|
/**
|
|
|
|
* The current user
|
|
|
|
*/
|
2010-10-31 00:16:59 +01:00
|
|
|
|
2009-01-21 03:16:52 +00:00
|
|
|
var $user = null;
|
2008-09-17 18:47:41 +01:00
|
|
|
|
2009-01-21 03:16:52 +00:00
|
|
|
/**
|
|
|
|
* Load attributes based on database arguments
|
|
|
|
*
|
|
|
|
* Loads all the DB stuff
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST array
|
|
|
|
*
|
|
|
|
* @return success flag
|
|
|
|
*/
|
2016-06-01 03:21:50 +01:00
|
|
|
function prepare(array $args = array())
|
2009-01-21 03:16:52 +00:00
|
|
|
{
|
|
|
|
parent::prepare($args);
|
2010-10-31 00:16:59 +01:00
|
|
|
|
2009-01-21 03:16:52 +00:00
|
|
|
$this->page = 1;
|
2010-10-31 00:16:59 +01:00
|
|
|
|
2009-01-21 03:16:52 +00:00
|
|
|
$id = $this->trimmed('message');
|
2013-08-18 12:04:58 +01:00
|
|
|
$this->message = Message::getKV('id', $id);
|
2008-09-17 18:47:41 +01:00
|
|
|
|
2009-01-21 03:16:52 +00:00
|
|
|
if (!$this->message) {
|
2010-10-31 00:16:59 +01:00
|
|
|
// TRANS: Client error displayed requesting a single message that does not exist.
|
2009-01-15 23:03:38 +00:00
|
|
|
$this->clientError(_('No such message.'), 404);
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2009-01-21 03:16:52 +00:00
|
|
|
|
|
|
|
$this->user = common_current_user();
|
|
|
|
|
2011-02-08 16:33:36 +00:00
|
|
|
if (empty($this->user) ||
|
|
|
|
($this->user->id != $this->message->from_profile &&
|
|
|
|
$this->user->id != $this->message->to_profile)) {
|
|
|
|
// TRANS: Client error displayed requesting a single direct message the requesting user was not a party in.
|
|
|
|
throw new ClientException(_('Only the sender and recipient ' .
|
|
|
|
'may read this message.'), 403);
|
|
|
|
}
|
|
|
|
|
2009-01-21 03:16:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-01 03:05:11 +01:00
|
|
|
function handle()
|
2009-01-21 03:16:52 +00:00
|
|
|
{
|
2011-02-08 16:33:36 +00:00
|
|
|
$this->showPage();
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2010-10-31 00:16:59 +01:00
|
|
|
|
2009-01-21 03:16:52 +00:00
|
|
|
function title()
|
2010-10-31 00:16:59 +01:00
|
|
|
{
|
2009-01-21 03:16:52 +00:00
|
|
|
if ($this->user->id == $this->message->from_profile) {
|
|
|
|
$to = $this->message->getTo();
|
2010-10-31 00:16:59 +01:00
|
|
|
// @todo FIXME: Might be nice if the timestamp could be localised.
|
|
|
|
// TRANS: Page title for single direct message display when viewing user is the sender.
|
|
|
|
// TRANS: %1$s is the addressed user's nickname, $2$s is a timestamp.
|
|
|
|
return sprintf(_('Message to %1$s on %2$s'),
|
2008-12-23 19:19:07 +00:00
|
|
|
$to->nickname,
|
2009-01-21 03:16:52 +00:00
|
|
|
common_exact_date($this->message->created));
|
|
|
|
} else if ($this->user->id == $this->message->to_profile) {
|
|
|
|
$from = $this->message->getFrom();
|
2010-10-31 00:16:59 +01:00
|
|
|
// @todo FIXME: Might be nice if the timestamp could be localised.
|
|
|
|
// TRANS: Page title for single message display.
|
|
|
|
// TRANS: %1$s is the sending user's nickname, $2$s is a timestamp.
|
|
|
|
return sprintf(_('Message from %1$s on %2$s'),
|
2008-12-23 19:19:07 +00:00
|
|
|
$from->nickname,
|
2009-01-21 03:16:52 +00:00
|
|
|
common_exact_date($this->message->created));
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-31 00:16:59 +01:00
|
|
|
|
|
|
|
|
2011-02-08 16:33:36 +00:00
|
|
|
function showContent()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2011-02-08 16:33:36 +00:00
|
|
|
$this->elementStart('ul', 'notices messages');
|
|
|
|
$ml = new ShowMessageListItem($this, $this->message, $this->user);
|
|
|
|
$ml->show();
|
|
|
|
$this->elementEnd('ul');
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2010-10-31 00:16:59 +01:00
|
|
|
|
2011-02-08 16:33:36 +00:00
|
|
|
function isReadOnly($args)
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2011-02-08 16:33:36 +00:00
|
|
|
return true;
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2009-01-21 03:16:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Don't show aside
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-02-08 16:33:36 +00:00
|
|
|
|
|
|
|
function showAside() {
|
2009-01-21 03:16:52 +00:00
|
|
|
}
|
2011-02-08 16:33:36 +00:00
|
|
|
}
|
2010-10-31 00:16:59 +01:00
|
|
|
|
2011-02-08 16:33:36 +00:00
|
|
|
class ShowMessageListItem extends MessageListItem
|
|
|
|
{
|
|
|
|
var $user;
|
|
|
|
|
|
|
|
function __construct($out, $message, $user)
|
2009-01-21 03:16:52 +00:00
|
|
|
{
|
2011-02-08 16:33:36 +00:00
|
|
|
parent::__construct($out, $message);
|
|
|
|
$this->user = $user;
|
2009-01-21 03:16:52 +00:00
|
|
|
}
|
2009-01-23 09:15:15 +00:00
|
|
|
|
2011-02-08 16:33:36 +00:00
|
|
|
function getMessageProfile()
|
2009-01-23 09:15:15 +00:00
|
|
|
{
|
2011-02-08 16:33:36 +00: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();
|
|
|
|
} else {
|
|
|
|
// This shouldn't happen
|
|
|
|
return null;
|
|
|
|
}
|
2009-01-23 09:15:15 +00:00
|
|
|
}
|
|
|
|
}
|