2008-05-09 03:16:04 +01:00
|
|
|
<?php
|
2009-01-18 18:35:11 +00:00
|
|
|
/**
|
2009-08-25 23:12:20 +01:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2008-05-20 20:14:12 +01:00
|
|
|
*
|
2009-01-18 18:35:11 +00:00
|
|
|
* Show a single notice
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
2008-05-14 20:26:48 +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.
|
2008-05-20 20:14:12 +01:00
|
|
|
*
|
2008-05-14 20:26:48 +01:00
|
|
|
* 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.
|
2008-05-20 20:14:12 +01:00
|
|
|
*
|
2008-05-14 20:26:48 +01:00
|
|
|
* 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-18 18:35:11 +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>
|
2011-06-09 21:20:19 +01:00
|
|
|
* @copyright 2008-2011 StatusNet, Inc.
|
2009-01-18 18:35:11 +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-05-14 20:26:48 +01:00
|
|
|
*/
|
|
|
|
|
2014-05-01 13:28:18 +01:00
|
|
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
2008-05-09 03:16:04 +01:00
|
|
|
|
2009-01-18 18:35:11 +00:00
|
|
|
require_once INSTALLDIR.'/lib/noticelist.php';
|
2008-06-10 23:19:10 +01:00
|
|
|
|
2009-01-18 18:35:11 +00:00
|
|
|
/**
|
|
|
|
* Show a single notice
|
|
|
|
*
|
|
|
|
* @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-18 18:35:11 +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-18 18:35:11 +00:00
|
|
|
*/
|
2014-06-21 20:01:17 +01:00
|
|
|
class ShownoticeAction extends ManagedAction
|
2008-12-23 19:49:23 +00:00
|
|
|
{
|
2009-01-18 18:35:11 +00:00
|
|
|
/**
|
|
|
|
* Notice object to show
|
|
|
|
*/
|
2008-12-23 19:21:29 +00:00
|
|
|
var $notice = null;
|
2009-01-18 18:35:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Profile of the notice object
|
|
|
|
*/
|
2008-12-23 19:21:29 +00:00
|
|
|
var $profile = null;
|
2009-01-18 18:35:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Avatar of the profile of the notice object
|
|
|
|
*/
|
2008-12-23 19:21:29 +00:00
|
|
|
var $avatar = null;
|
2008-12-02 05:02:00 +00:00
|
|
|
|
2009-01-18 18:35:11 +00:00
|
|
|
/**
|
|
|
|
* Load attributes based on database arguments
|
|
|
|
*
|
|
|
|
* Loads all the DB stuff
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST array
|
|
|
|
*
|
|
|
|
* @return success flag
|
|
|
|
*/
|
2014-01-01 19:30:30 +00:00
|
|
|
protected function prepare(array $args=array())
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2008-12-23 19:19:07 +00:00
|
|
|
parent::prepare($args);
|
2011-03-14 20:44:39 +00:00
|
|
|
if ($this->boolean('ajax')) {
|
2015-02-27 11:44:15 +00:00
|
|
|
GNUsocial::setApi(true);
|
2011-03-14 20:44:39 +00:00
|
|
|
}
|
2008-12-02 04:12:43 +00:00
|
|
|
|
2011-03-30 00:58:15 +01:00
|
|
|
$this->notice = $this->getNotice();
|
2008-05-09 03:16:04 +01:00
|
|
|
|
2014-05-01 13:28:18 +01:00
|
|
|
if (!$this->notice->inScope($this->scoped)) {
|
2011-03-29 23:48:19 +01:00
|
|
|
// TRANS: Client exception thrown when trying a view a notice the user has no access to.
|
2015-01-31 15:27:21 +00:00
|
|
|
throw new ClientException(_('Access restricted.'), 403);
|
2011-03-29 03:21:41 +01:00
|
|
|
}
|
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$this->profile = $this->notice->getProfile();
|
2008-06-27 23:29:30 +01:00
|
|
|
|
2014-05-01 13:28:18 +01:00
|
|
|
if (!$this->profile instanceof Profile) {
|
2011-03-24 11:09:50 +00:00
|
|
|
// TRANS: Server error displayed trying to show a notice without a connected profile.
|
2010-04-09 23:58:57 +01:00
|
|
|
$this->serverError(_('Notice has no profile.'), 500);
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2008-05-20 20:14:12 +01:00
|
|
|
|
2014-05-01 13:28:18 +01:00
|
|
|
try {
|
|
|
|
$this->user = $this->profile->getUser();
|
|
|
|
} catch (NoSuchUserException $e) {
|
|
|
|
// FIXME: deprecate $this->user stuff in extended classes
|
|
|
|
$this->user = null;
|
|
|
|
}
|
2009-07-02 13:21:54 +01:00
|
|
|
|
2013-10-01 10:37:59 +01:00
|
|
|
try {
|
|
|
|
$this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->avatar = null;
|
|
|
|
}
|
2008-12-02 04:50:21 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-12-02 04:12:43 +00:00
|
|
|
|
2011-03-30 00:58:15 +01:00
|
|
|
/**
|
|
|
|
* Fetch the notice to show. This may be overridden by child classes to
|
|
|
|
* customize what we fetch without duplicating all of the prepare() method.
|
|
|
|
*
|
|
|
|
* @return Notice
|
|
|
|
*/
|
2014-01-01 19:30:30 +00:00
|
|
|
protected function getNotice()
|
2011-03-30 00:58:15 +01:00
|
|
|
{
|
|
|
|
$id = $this->arg('notice');
|
|
|
|
|
2013-08-18 12:04:58 +01:00
|
|
|
$notice = Notice::getKV('id', $id);
|
2014-06-01 23:20:27 +01:00
|
|
|
if ($notice instanceof Notice) {
|
|
|
|
// Alright, got it!
|
|
|
|
return $notice;
|
|
|
|
}
|
2011-03-30 00:58:15 +01:00
|
|
|
|
2014-06-01 23:20:27 +01:00
|
|
|
// Did we use to have it, and it got deleted?
|
|
|
|
$deleted = Deleted_notice::getKV('id', $id);
|
|
|
|
if ($deleted instanceof Deleted_notice) {
|
|
|
|
// TRANS: Client error displayed trying to show a deleted notice.
|
|
|
|
$this->clientError(_('Notice deleted.'), 410);
|
2011-03-30 00:58:15 +01:00
|
|
|
}
|
2014-06-01 23:20:27 +01:00
|
|
|
// TRANS: Client error displayed trying to show a non-existing notice.
|
|
|
|
$this->clientError(_('No such notice.'), 404);
|
2011-03-30 00:58:15 +01:00
|
|
|
}
|
|
|
|
|
2009-01-18 18:35:11 +00:00
|
|
|
/**
|
|
|
|
* Is this action read-only?
|
|
|
|
*
|
|
|
|
* @return boolean true
|
|
|
|
*/
|
2009-04-13 20:49:26 +01:00
|
|
|
function isReadOnly($args)
|
2009-01-18 18:35:11 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Last-modified date for page
|
|
|
|
*
|
|
|
|
* When was the content of this page last modified? Based on notice,
|
|
|
|
* profile, avatar.
|
|
|
|
*
|
|
|
|
* @return int last-modified date as unix timestamp
|
|
|
|
*/
|
|
|
|
function lastModified()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2009-05-31 02:45:11 +01:00
|
|
|
return max(strtotime($this->notice->modified),
|
2008-12-23 19:19:07 +00:00
|
|
|
strtotime($this->profile->modified),
|
|
|
|
($this->avatar) ? strtotime($this->avatar->modified) : 0);
|
|
|
|
}
|
2008-12-02 04:50:21 +00:00
|
|
|
|
2009-01-18 18:35:11 +00:00
|
|
|
/**
|
|
|
|
* An entity tag for this page
|
|
|
|
*
|
|
|
|
* Shows the ETag for the page, based on the notice ID and timestamps
|
|
|
|
* for the notice, profile, and avatar. It's weak, since we change
|
|
|
|
* the date text "one hour ago", etc.
|
|
|
|
*
|
|
|
|
* @return string etag
|
|
|
|
*/
|
2008-12-23 19:33:23 +00:00
|
|
|
function etag()
|
|
|
|
{
|
2009-01-18 18:35:11 +00:00
|
|
|
$avtime = ($this->avatar) ?
|
|
|
|
strtotime($this->avatar->modified) : 0;
|
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
return 'W/"' . implode(':', array($this->arg('action'),
|
2010-09-20 21:42:58 +01:00
|
|
|
common_user_cache_hash(),
|
2008-12-23 19:19:07 +00:00
|
|
|
common_language(),
|
|
|
|
$this->notice->id,
|
|
|
|
strtotime($this->notice->created),
|
|
|
|
strtotime($this->profile->modified),
|
2009-01-18 18:35:11 +00:00
|
|
|
$avtime)) . '"';
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2008-12-02 04:12:43 +00:00
|
|
|
|
2009-01-18 18:35:11 +00:00
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string title of the page
|
|
|
|
*/
|
|
|
|
function title()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2014-06-21 20:01:17 +01:00
|
|
|
return $this->notice->getTitle();
|
2009-01-18 18:35:11 +00:00
|
|
|
}
|
2008-05-20 20:14:12 +01:00
|
|
|
|
2009-01-18 18:35:11 +00:00
|
|
|
/**
|
|
|
|
* Fill the content area of the page
|
|
|
|
*
|
|
|
|
* Shows a single notice list item.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showContent()
|
|
|
|
{
|
2009-05-29 03:38:38 +01:00
|
|
|
$this->elementStart('ol', array('class' => 'notices xoxo'));
|
2011-03-14 20:05:30 +00:00
|
|
|
$nli = new NoticeListItem($this->notice, $this);
|
|
|
|
$nli->show();
|
2014-06-21 20:01:17 +01:00
|
|
|
$this->elementEnd('ol');
|
2011-03-14 20:05:30 +00:00
|
|
|
}
|
|
|
|
|
2009-01-19 17:12:35 +00:00
|
|
|
/**
|
2009-11-09 19:01:46 +00:00
|
|
|
* Don't show page notice
|
2009-01-19 17:12:35 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showPageNoticeBlock()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-09 19:01:46 +00:00
|
|
|
* Don't show aside
|
2009-01-19 17:12:35 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showAside() {
|
|
|
|
}
|
|
|
|
|
2009-01-18 18:35:11 +00:00
|
|
|
/**
|
|
|
|
* Extra <head> content
|
|
|
|
*
|
2015-07-14 15:52:20 +01:00
|
|
|
* Facebook OpenGraph metadata.
|
2009-01-18 18:35:11 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function extraHead()
|
|
|
|
{
|
2010-10-01 02:21:38 +01:00
|
|
|
// Extras to aid in sharing notices to Facebook
|
2013-10-01 10:37:59 +01:00
|
|
|
$avatarUrl = $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
|
2010-10-01 02:21:38 +01:00
|
|
|
$this->element('meta', array('property' => 'og:image',
|
|
|
|
'content' => $avatarUrl));
|
|
|
|
$this->element('meta', array('property' => 'og:description',
|
|
|
|
'content' => $this->notice->content));
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2008-05-09 03:16:04 +01:00
|
|
|
}
|