2008-05-09 11:16:04 +09:00
|
|
|
<?php
|
2009-01-19 03:35:11 +09:00
|
|
|
/**
|
2009-08-26 07:12:20 +09:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2008-05-21 04:14:12 +09:00
|
|
|
*
|
2009-01-19 03:35:11 +09:00
|
|
|
* Show a single notice
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
2008-05-15 04:26:48 +09: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-21 04:14:12 +09:00
|
|
|
*
|
2008-05-15 04:26:48 +09: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-21 04:14:12 +09:00
|
|
|
*
|
2008-05-15 04:26:48 +09: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-19 03:35:11 +09:00
|
|
|
*
|
|
|
|
* @category Personal
|
2009-08-26 07:12:20 +09:00
|
|
|
* @package StatusNet
|
2009-08-26 07:19:04 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2011-06-10 05:20:19 +09:00
|
|
|
* @copyright 2008-2011 StatusNet, Inc.
|
2009-01-19 03:35:11 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-26 07:16:46 +09:00
|
|
|
* @link http://status.net/
|
2008-05-15 04:26:48 +09:00
|
|
|
*/
|
|
|
|
|
2009-08-26 23:41:36 +09:00
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
2009-01-19 03:35:11 +09:00
|
|
|
exit(1);
|
|
|
|
}
|
2008-05-09 11:16:04 +09:00
|
|
|
|
2009-01-19 03:35:11 +09:00
|
|
|
require_once INSTALLDIR.'/lib/personalgroupnav.php';
|
|
|
|
require_once INSTALLDIR.'/lib/noticelist.php';
|
|
|
|
require_once INSTALLDIR.'/lib/feedlist.php';
|
2008-06-11 07:19:10 +09:00
|
|
|
|
2009-01-19 03:35:11 +09:00
|
|
|
/**
|
|
|
|
* Show a single notice
|
|
|
|
*
|
|
|
|
* @category Personal
|
2009-08-26 07:12:20 +09:00
|
|
|
* @package StatusNet
|
2009-08-26 07:19:04 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-01-19 03:35:11 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-26 07:16:46 +09:00
|
|
|
* @link http://status.net/
|
2009-01-19 03:35:11 +09:00
|
|
|
*/
|
2011-06-10 05:20:19 +09:00
|
|
|
class ShownoticeAction extends Action
|
2008-12-24 04:49:23 +09:00
|
|
|
{
|
2009-01-19 03:35:11 +09:00
|
|
|
/**
|
|
|
|
* Notice object to show
|
|
|
|
*/
|
2008-12-24 04:21:29 +09:00
|
|
|
var $notice = null;
|
2009-01-19 03:35:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Profile of the notice object
|
|
|
|
*/
|
2008-12-24 04:21:29 +09:00
|
|
|
var $profile = null;
|
2009-01-19 03:35:11 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Avatar of the profile of the notice object
|
|
|
|
*/
|
2008-12-24 04:21:29 +09:00
|
|
|
var $avatar = null;
|
2008-12-02 14:02:00 +09:00
|
|
|
|
2009-01-19 03:35:11 +09:00
|
|
|
/**
|
|
|
|
* Load attributes based on database arguments
|
|
|
|
*
|
|
|
|
* Loads all the DB stuff
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST array
|
|
|
|
*
|
|
|
|
* @return success flag
|
|
|
|
*/
|
2014-01-02 04:30:30 +09:00
|
|
|
protected function prepare(array $args=array())
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::prepare($args);
|
2011-03-15 05:44:39 +09:00
|
|
|
if ($this->boolean('ajax')) {
|
|
|
|
StatusNet::setApi(true);
|
|
|
|
}
|
2008-12-02 13:12:43 +09:00
|
|
|
|
2011-03-30 08:58:15 +09:00
|
|
|
$this->notice = $this->getNotice();
|
2008-05-09 11:16:04 +09:00
|
|
|
|
2011-03-29 11:21:41 +09:00
|
|
|
$cur = common_current_user();
|
|
|
|
|
|
|
|
if (!empty($cur)) {
|
|
|
|
$curProfile = $cur->getProfile();
|
|
|
|
} else {
|
|
|
|
$curProfile = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->notice->inScope($curProfile)) {
|
2011-03-30 07:48:19 +09:00
|
|
|
// TRANS: Client exception thrown when trying a view a notice the user has no access to.
|
2011-03-29 11:21:41 +09:00
|
|
|
throw new ClientException(_('Not available.'), 403);
|
|
|
|
}
|
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
$this->profile = $this->notice->getProfile();
|
2008-06-28 07:29:30 +09:00
|
|
|
|
2009-07-02 21:21:54 +09:00
|
|
|
if (empty($this->profile)) {
|
2011-03-24 20:09:50 +09:00
|
|
|
// TRANS: Server error displayed trying to show a notice without a connected profile.
|
2010-04-10 07:58:57 +09:00
|
|
|
$this->serverError(_('Notice has no profile.'), 500);
|
2008-12-24 04:19:07 +09:00
|
|
|
return false;
|
|
|
|
}
|
2008-05-21 04:14:12 +09:00
|
|
|
|
2013-08-18 20:04:58 +09:00
|
|
|
$this->user = User::getKV('id', $this->profile->id);
|
2009-07-02 21:21:54 +09:00
|
|
|
|
2013-10-01 18:37:59 +09:00
|
|
|
try {
|
|
|
|
$this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->avatar = null;
|
|
|
|
}
|
2008-12-02 13:50:21 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
return true;
|
|
|
|
}
|
2008-12-02 13:12:43 +09:00
|
|
|
|
2011-03-30 08:58:15 +09: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-02 04:30:30 +09:00
|
|
|
protected function getNotice()
|
2011-03-30 08:58:15 +09:00
|
|
|
{
|
|
|
|
$id = $this->arg('notice');
|
|
|
|
|
2013-08-18 20:04:58 +09:00
|
|
|
$notice = Notice::getKV('id', $id);
|
2011-03-30 08:58:15 +09:00
|
|
|
|
2014-01-02 04:30:30 +09:00
|
|
|
if (!$notice instanceof Notice) {
|
2011-03-30 08:58:15 +09:00
|
|
|
// Did we used to have it, and it got deleted?
|
2013-08-18 20:04:58 +09:00
|
|
|
$deleted = Deleted_notice::getKV($id);
|
2014-01-02 04:30:30 +09:00
|
|
|
if ($deleted instanceof Deleted_notice) {
|
2011-03-30 08:58:15 +09:00
|
|
|
// TRANS: Client error displayed trying to show a deleted notice.
|
|
|
|
$this->clientError(_('Notice deleted.'), 410);
|
|
|
|
} else {
|
|
|
|
// TRANS: Client error displayed trying to show a non-existing notice.
|
|
|
|
$this->clientError(_('No such notice.'), 404);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $notice;
|
|
|
|
}
|
|
|
|
|
2009-01-19 03:35:11 +09:00
|
|
|
/**
|
|
|
|
* Is this action read-only?
|
|
|
|
*
|
|
|
|
* @return boolean true
|
|
|
|
*/
|
2009-04-14 04:49:26 +09:00
|
|
|
function isReadOnly($args)
|
2009-01-19 03:35:11 +09: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-24 04:33:23 +09:00
|
|
|
{
|
2009-05-31 10:45:11 +09:00
|
|
|
return max(strtotime($this->notice->modified),
|
2008-12-24 04:19:07 +09:00
|
|
|
strtotime($this->profile->modified),
|
|
|
|
($this->avatar) ? strtotime($this->avatar->modified) : 0);
|
|
|
|
}
|
2008-12-02 13:50:21 +09:00
|
|
|
|
2009-01-19 03:35:11 +09: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-24 04:33:23 +09:00
|
|
|
function etag()
|
|
|
|
{
|
2009-01-19 03:35:11 +09:00
|
|
|
$avtime = ($this->avatar) ?
|
|
|
|
strtotime($this->avatar->modified) : 0;
|
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
return 'W/"' . implode(':', array($this->arg('action'),
|
2010-09-21 05:42:58 +09:00
|
|
|
common_user_cache_hash(),
|
2008-12-24 04:19:07 +09:00
|
|
|
common_language(),
|
|
|
|
$this->notice->id,
|
|
|
|
strtotime($this->notice->created),
|
|
|
|
strtotime($this->profile->modified),
|
2009-01-19 03:35:11 +09:00
|
|
|
$avtime)) . '"';
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-12-02 13:12:43 +09:00
|
|
|
|
2009-01-19 03:35:11 +09:00
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string title of the page
|
|
|
|
*/
|
|
|
|
function title()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2010-11-04 05:10:42 +09:00
|
|
|
$base = $this->profile->getFancyName();
|
2009-07-02 21:21:54 +09:00
|
|
|
|
2011-03-24 20:09:50 +09:00
|
|
|
// TRANS: Title of the page that shows a notice.
|
|
|
|
// TRANS: %1$s is a user name, %2$s is the notice creation date/time.
|
2009-01-19 03:35:11 +09:00
|
|
|
return sprintf(_('%1$s\'s status on %2$s'),
|
2009-07-02 21:21:54 +09:00
|
|
|
$base,
|
2009-01-19 03:35:11 +09:00
|
|
|
common_exact_date($this->notice->created));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle input
|
|
|
|
*
|
|
|
|
* Only handles get, so just show the page.
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST data (unused)
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-01-02 04:30:30 +09:00
|
|
|
protected function handle()
|
2009-01-19 03:35:11 +09:00
|
|
|
{
|
2014-01-02 04:30:30 +09:00
|
|
|
parent::handle();
|
2008-12-02 13:12:43 +09:00
|
|
|
|
2011-03-15 05:05:30 +09:00
|
|
|
if ($this->boolean('ajax')) {
|
|
|
|
$this->showAjax();
|
|
|
|
} else {
|
2011-07-16 04:13:57 +09:00
|
|
|
if ($this->notice->is_local == Notice::REMOTE) {
|
2011-03-15 05:05:30 +09:00
|
|
|
if (!empty($this->notice->url)) {
|
|
|
|
$target = $this->notice->url;
|
|
|
|
} else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
|
|
|
|
// Old OMB posts saved the remote URL only into the URI field.
|
|
|
|
$target = $this->notice->uri;
|
|
|
|
} else {
|
|
|
|
// Shouldn't happen.
|
|
|
|
$target = false;
|
|
|
|
}
|
|
|
|
if ($target && $target != $this->selfUrl()) {
|
|
|
|
common_redirect($target, 301);
|
|
|
|
return false;
|
|
|
|
}
|
2009-03-20 00:36:24 +09:00
|
|
|
}
|
2011-03-15 05:05:30 +09:00
|
|
|
$this->showPage();
|
2009-03-20 00:36:24 +09:00
|
|
|
}
|
2009-01-19 03:35:11 +09:00
|
|
|
}
|
2008-05-21 04:14:12 +09:00
|
|
|
|
2009-01-19 03:35:11 +09:00
|
|
|
/**
|
|
|
|
* Fill the content area of the page
|
|
|
|
*
|
|
|
|
* Shows a single notice list item.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showContent()
|
|
|
|
{
|
2009-05-29 11:38:38 +09:00
|
|
|
$this->elementStart('ol', array('class' => 'notices xoxo'));
|
2009-06-23 23:25:18 +09:00
|
|
|
$nli = new SingleNoticeItem($this->notice, $this);
|
2008-12-12 08:12:52 +09:00
|
|
|
$nli->show();
|
2009-05-29 11:38:38 +09:00
|
|
|
$this->elementEnd('ol');
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-05-21 04:14:12 +09:00
|
|
|
|
2011-03-15 05:05:30 +09:00
|
|
|
function showAjax()
|
|
|
|
{
|
2013-09-24 08:17:04 +09:00
|
|
|
$this->startHTML('text/xml;charset=utf-8');
|
2011-03-15 05:05:30 +09:00
|
|
|
$this->elementStart('head');
|
2011-03-24 20:09:50 +09:00
|
|
|
// TRANS: Title for page that shows a notice.
|
|
|
|
$this->element('title', null, _m('TITLE','Notice'));
|
2011-03-15 05:05:30 +09:00
|
|
|
$this->elementEnd('head');
|
|
|
|
$this->elementStart('body');
|
|
|
|
$nli = new NoticeListItem($this->notice, $this);
|
|
|
|
$nli->show();
|
|
|
|
$this->elementEnd('body');
|
2013-09-24 08:17:04 +09:00
|
|
|
$this->endHTML();
|
2011-03-15 05:05:30 +09:00
|
|
|
}
|
|
|
|
|
2009-01-20 02:12:35 +09:00
|
|
|
/**
|
2009-11-10 04:01:46 +09:00
|
|
|
* Don't show page notice
|
2009-01-20 02:12:35 +09:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showPageNoticeBlock()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-10 04:01:46 +09:00
|
|
|
* Don't show aside
|
2009-01-20 02:12:35 +09:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showAside() {
|
|
|
|
}
|
|
|
|
|
2009-01-19 03:35:11 +09:00
|
|
|
/**
|
|
|
|
* Extra <head> content
|
|
|
|
*
|
|
|
|
* We show the microid(s) for the author, if any.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function extraHead()
|
|
|
|
{
|
2013-08-18 20:04:58 +09:00
|
|
|
$user = User::getKV($this->profile->id);
|
2008-12-02 13:12:43 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
if (!$user) {
|
|
|
|
return;
|
|
|
|
}
|
2008-12-02 13:12:43 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
if ($user->emailmicroid && $user->email && $this->notice->uri) {
|
2009-01-19 03:35:11 +09:00
|
|
|
$id = new Microid('mailto:'. $user->email,
|
|
|
|
$this->notice->uri);
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->element('meta', array('name' => 'microid',
|
2009-01-19 03:35:11 +09:00
|
|
|
'content' => $id->toString()));
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-12-02 13:12:43 +09:00
|
|
|
|
2009-07-16 04:11:29 +09:00
|
|
|
$this->element('link',array('rel'=>'alternate',
|
|
|
|
'type'=>'application/json+oembed',
|
|
|
|
'href'=>common_local_url(
|
2009-08-12 10:15:42 +09:00
|
|
|
'oembed',
|
|
|
|
array(),
|
|
|
|
array('format'=>'json','url'=>$this->notice->uri)),
|
2009-07-16 04:11:29 +09:00
|
|
|
'title'=>'oEmbed'),null);
|
|
|
|
$this->element('link',array('rel'=>'alternate',
|
|
|
|
'type'=>'text/xml+oembed',
|
|
|
|
'href'=>common_local_url(
|
2009-08-12 10:15:42 +09:00
|
|
|
'oembed',
|
|
|
|
array(),
|
|
|
|
array('format'=>'xml','url'=>$this->notice->uri)),
|
2009-07-16 04:11:29 +09:00
|
|
|
'title'=>'oEmbed'),null);
|
2010-10-01 10:21:38 +09:00
|
|
|
|
|
|
|
// Extras to aid in sharing notices to Facebook
|
2013-10-01 18:37:59 +09:00
|
|
|
$avatarUrl = $this->profile->avatarUrl(AVATAR_PROFILE_SIZE);
|
2010-10-01 10:21:38 +09:00
|
|
|
$this->element('meta', array('property' => 'og:image',
|
|
|
|
'content' => $avatarUrl));
|
|
|
|
$this->element('meta', array('property' => 'og:description',
|
|
|
|
'content' => $this->notice->content));
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-05-09 11:16:04 +09:00
|
|
|
}
|
2009-06-23 23:25:18 +09:00
|
|
|
|
2011-03-24 20:09:50 +09:00
|
|
|
// @todo FIXME: Class documentation missing.
|
2010-10-19 00:29:52 +09:00
|
|
|
class SingleNoticeItem extends DoFollowListItem
|
2009-06-23 23:25:18 +09:00
|
|
|
{
|
2011-04-21 02:39:23 +09:00
|
|
|
function avatarSize()
|
2010-11-09 03:08:59 +09:00
|
|
|
{
|
2011-04-21 04:47:44 +09:00
|
|
|
return AVATAR_STREAM_SIZE;
|
2010-11-09 03:08:59 +09:00
|
|
|
}
|
2009-06-23 23:25:18 +09:00
|
|
|
}
|