mirror of
https://code.castopod.org/adaures/castopod
synced 2025-05-11 16:55:46 +00:00

- get avatar and cover urls from entity: if no image exists, retrieve the default ones. - always set icon and image in actor object: set the default ones if podcast hasn't set them. fixes #111
121 lines
2.9 KiB
PHP
121 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @copyright 2021 Podlibre
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
* @link https://castopod.org/
|
|
*/
|
|
|
|
namespace ActivityPub\Entities;
|
|
|
|
use CodeIgniter\Entity;
|
|
|
|
class Actor extends Entity
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $key_id;
|
|
|
|
/**
|
|
* @var \ActivityPub\Entities\Actor[]
|
|
*/
|
|
protected $followers;
|
|
|
|
/**
|
|
* @var boolean
|
|
*/
|
|
protected $is_local;
|
|
|
|
protected $casts = [
|
|
'id' => 'integer',
|
|
'uri' => 'string',
|
|
'username' => 'string',
|
|
'domain' => 'string',
|
|
'display_name' => 'string',
|
|
'summary' => '?string',
|
|
'private_key' => '?string',
|
|
'public_key' => '?string',
|
|
'avatar_image_url' => '?string',
|
|
'avatar_image_mimetype' => '?string',
|
|
'cover_image_url' => '?string',
|
|
'cover_image_mimetype' => '?string',
|
|
'inbox_url' => 'string',
|
|
'outbox_url' => '?string',
|
|
'followers_url' => '?string',
|
|
'followers_count' => 'integer',
|
|
'notes_count' => 'integer',
|
|
'is_blocked' => 'boolean',
|
|
];
|
|
|
|
public function getKeyId()
|
|
{
|
|
return $this->uri . '#main-key';
|
|
}
|
|
|
|
public function getIsLocal()
|
|
{
|
|
if (!$this->is_local) {
|
|
$uri = current_url(true);
|
|
|
|
$this->is_local =
|
|
$this->domain ===
|
|
$uri->getHost() .
|
|
($uri->getPort() ? ':' . $uri->getPort() : '');
|
|
}
|
|
|
|
return $this->is_local;
|
|
}
|
|
|
|
public function getFollowers()
|
|
{
|
|
if (empty($this->id)) {
|
|
throw new \RuntimeException(
|
|
'Actor must be created before getting followers.',
|
|
);
|
|
}
|
|
|
|
if (empty($this->followers)) {
|
|
$this->followers = model('ActorModel')->getFollowers($this->id);
|
|
}
|
|
|
|
return $this->followers;
|
|
}
|
|
|
|
public function getAvatarImageUrl()
|
|
{
|
|
if (empty($this->attributes['avatar_image_url'])) {
|
|
return base_url(config('ActivityPub')->defaultAvatarImagePath);
|
|
}
|
|
|
|
return $this->attributes['avatar_image_url'];
|
|
}
|
|
|
|
public function getAvatarImageMimetype()
|
|
{
|
|
if (empty($this->attributes['avatar_image_mimetype'])) {
|
|
return config('ActivityPub')->defaultAvatarImageMimetype;
|
|
}
|
|
|
|
return $this->attributes['avatar_image_mimetype'];
|
|
}
|
|
|
|
public function getCoverImageUrl()
|
|
{
|
|
if (empty($this->attributes['cover_image_url'])) {
|
|
return base_url(config('ActivityPub')->defaultCoverImagePath);
|
|
}
|
|
|
|
return $this->attributes['cover_image_url'];
|
|
}
|
|
|
|
public function getCoverImageMimetype()
|
|
{
|
|
if (empty($this->attributes['cover_image_mimetype'])) {
|
|
return config('ActivityPub')->defaultCoverImageMimetype;
|
|
}
|
|
|
|
return $this->attributes['cover_image_mimetype'];
|
|
}
|
|
}
|