2011-02-09 01:11:21 +09:00
|
|
|
<?php
|
2019-08-20 06:51:51 +09:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2011-02-09 01:11:21 +09:00
|
|
|
/**
|
2019-08-20 06:51:51 +09:00
|
|
|
* GNUsocial implementation of Direct Messages
|
2011-02-09 01:11:21 +09:00
|
|
|
*
|
2019-08-20 06:51:51 +09:00
|
|
|
* @package GNUsocial
|
|
|
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2011-02-09 01:11:21 +09:00
|
|
|
*/
|
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
defined('GNUSOCIAL') || die();
|
2011-02-09 01:11:21 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A single item in a message list
|
|
|
|
*
|
2019-08-20 06:51:51 +09:00
|
|
|
* @category Plugin
|
|
|
|
* @package GNUsocial
|
2011-02-09 01:11:21 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2019-08-20 06:51:51 +09:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2011-02-09 01:11:21 +09:00
|
|
|
*/
|
|
|
|
abstract class MessageListItem extends Widget
|
|
|
|
{
|
2019-08-20 06:51:51 +09:00
|
|
|
protected $message;
|
2011-02-09 01:11:21 +09:00
|
|
|
|
|
|
|
/**
|
2019-08-20 06:51:51 +09:00
|
|
|
* Constructor.
|
2011-02-09 01:11:21 +09:00
|
|
|
*
|
|
|
|
* @param HTMLOutputter $out Output context
|
2019-08-20 06:51:51 +09:00
|
|
|
* @param Notice $message Message to show
|
2011-02-09 01:11:21 +09:00
|
|
|
*/
|
2019-08-20 06:51:51 +09:00
|
|
|
function __construct(HTMLOutputter $out, $message)
|
2011-02-09 01:11:21 +09:00
|
|
|
{
|
|
|
|
parent::__construct($out);
|
|
|
|
$this->message = $message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-20 06:51:51 +09:00
|
|
|
* Show the widget.
|
2011-02-09 01:11:21 +09:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function show()
|
|
|
|
{
|
|
|
|
$profile = $this->getMessageProfile();
|
2019-08-20 06:51:51 +09:00
|
|
|
if (is_null($profile)) {
|
|
|
|
// null most probably because there are no attention profiles and
|
|
|
|
// the UI below isn't ready for that, yet.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->out->elementStart('li', ['class' => 'h-entry notice',
|
|
|
|
'id' => 'message-' . $this->message->getID()]);
|
2011-02-09 01:11:21 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
$this->out->elementStart('a', ['href' => $profile->getUrl(),
|
|
|
|
'class' => 'p-author']);
|
2013-10-01 18:37:59 +09:00
|
|
|
$avatarUrl = $profile->avatarUrl(AVATAR_STREAM_SIZE);
|
2019-08-20 06:51:51 +09:00
|
|
|
$this->out->element('img', ['src' => $avatarUrl,
|
|
|
|
'class' => 'avatar u-photo',
|
|
|
|
'width' => AVATAR_STREAM_SIZE,
|
|
|
|
'height' => AVATAR_STREAM_SIZE,
|
|
|
|
'alt' => $profile->getBestName()]);
|
|
|
|
$this->out->element('span', ['class' => 'nickname fn'], $profile->getNickname());
|
2011-02-09 01:11:21 +09:00
|
|
|
$this->out->elementEnd('a');
|
|
|
|
|
|
|
|
// FIXME: URL, image, video, audio
|
2019-08-20 06:51:51 +09:00
|
|
|
$this->out->elementStart('div', ['class' => 'e-content']);
|
|
|
|
$this->out->raw($this->message->getRendered());
|
2011-02-09 01:11:21 +09:00
|
|
|
$this->out->elementEnd('div');
|
|
|
|
|
|
|
|
$messageurl = common_local_url('showmessage',
|
2019-08-20 06:51:51 +09:00
|
|
|
['message' => $this->message->getID()]);
|
2011-02-09 01:11:21 +09:00
|
|
|
|
2014-06-22 04:01:17 +09:00
|
|
|
$this->out->elementStart('div', 'entry-metadata');
|
2019-08-20 06:51:51 +09:00
|
|
|
$this->out->elementStart('a', ['rel' => 'bookmark',
|
|
|
|
'class' => 'timestamp',
|
|
|
|
'href' => $messageurl]);
|
|
|
|
$dt = common_date_iso8601($this->message->getCreated());
|
|
|
|
$this->out->element('time',
|
|
|
|
['class' => 'dt-published',
|
|
|
|
'datetime' => common_date_iso8601($this->message->getCreated()),
|
|
|
|
// TRANS: Timestamp title (tooltip text) for NoticeListItem
|
|
|
|
'title' => common_exact_date($this->message->getCreated())],
|
|
|
|
common_date_string($this->message->getCreated()));
|
2011-02-09 01:11:21 +09:00
|
|
|
$this->out->elementEnd('a');
|
|
|
|
|
|
|
|
if ($this->message->source) {
|
|
|
|
$this->out->elementStart('span', 'source');
|
|
|
|
// FIXME: bad i18n. Device should be a parameter (from %s).
|
2011-04-03 08:09:02 +09:00
|
|
|
// TRANS: Followed by notice source (usually the client used to send the notice).
|
2011-02-09 01:11:21 +09:00
|
|
|
$this->out->text(_('from'));
|
2011-02-09 01:32:35 +09:00
|
|
|
$this->showSource($this->message->source);
|
2011-02-09 01:11:21 +09:00
|
|
|
$this->out->elementEnd('span');
|
|
|
|
}
|
|
|
|
$this->out->elementEnd('div');
|
|
|
|
|
|
|
|
$this->out->elementEnd('li');
|
|
|
|
}
|
|
|
|
|
2011-04-03 08:09:02 +09:00
|
|
|
/**
|
|
|
|
* Dummy method. Serves no other purpose than to make strings available used
|
|
|
|
* in self::showSource() through xgettext.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function messageListItemDummyMessages()
|
|
|
|
{
|
|
|
|
// A dummy array with messages. These will get extracted by xgettext and
|
|
|
|
// are used in self::showSource().
|
2019-08-20 06:51:51 +09:00
|
|
|
$dummy_messages = [
|
2011-04-03 08:09:02 +09:00
|
|
|
// TRANS: A possible notice source (web interface).
|
|
|
|
_m('SOURCE','web'),
|
|
|
|
// TRANS: A possible notice source (XMPP).
|
|
|
|
_m('SOURCE','xmpp'),
|
|
|
|
// TRANS: A possible notice source (e-mail).
|
|
|
|
_m('SOURCE','mail'),
|
|
|
|
// TRANS: A possible notice source (OpenMicroBlogging).
|
|
|
|
_m('SOURCE','omb'),
|
|
|
|
// TRANS: A possible notice source (Application Programming Interface).
|
2019-08-20 06:51:51 +09:00
|
|
|
_m('SOURCE','api')
|
|
|
|
];
|
2011-04-03 08:09:02 +09:00
|
|
|
}
|
2011-02-09 01:32:35 +09:00
|
|
|
|
|
|
|
/**
|
2019-08-20 06:51:51 +09:00
|
|
|
* Show the source of the message.
|
2011-02-09 01:32:35 +09:00
|
|
|
*
|
|
|
|
* Returns either the name (and link) of the API client that posted the notice,
|
|
|
|
* or one of other other channels.
|
|
|
|
*
|
|
|
|
* @param string $source the source of the message
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-08-20 06:51:51 +09:00
|
|
|
function showSource(string $source)
|
2011-02-09 01:32:35 +09:00
|
|
|
{
|
2011-04-03 08:09:02 +09:00
|
|
|
$source_name = _m('SOURCE',$source);
|
2011-02-09 01:32:35 +09:00
|
|
|
switch ($source) {
|
|
|
|
case 'web':
|
|
|
|
case 'xmpp':
|
|
|
|
case 'mail':
|
|
|
|
case 'omb':
|
|
|
|
case 'api':
|
|
|
|
$this->out->element('span', 'device', $source_name);
|
|
|
|
break;
|
|
|
|
default:
|
2013-08-18 20:04:58 +09:00
|
|
|
$ns = Notice_source::getKV($source);
|
2011-02-09 01:32:35 +09:00
|
|
|
if ($ns) {
|
|
|
|
$this->out->elementStart('span', 'device');
|
2019-08-20 06:51:51 +09:00
|
|
|
$this->out->element('a',
|
|
|
|
['href' => $ns->url,
|
|
|
|
'rel' => 'external'],
|
2011-02-09 01:32:35 +09:00
|
|
|
$ns->name);
|
|
|
|
$this->out->elementEnd('span');
|
|
|
|
} else {
|
|
|
|
$this->out->element('span', 'device', $source_name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-09 01:11:21 +09:00
|
|
|
/**
|
2019-08-20 06:51:51 +09:00
|
|
|
* Return the profile to show in the message item.
|
|
|
|
*
|
|
|
|
* Overridden in sub-classes to show sender, receiver, or whatever.
|
2011-02-09 01:11:21 +09:00
|
|
|
*
|
|
|
|
* @return Profile profile to show avatar and name of
|
|
|
|
*/
|
2019-08-20 06:51:51 +09:00
|
|
|
abstract function getMessageProfile(): ?Profile;
|
2011-02-09 01:11:21 +09:00
|
|
|
}
|