diff --git a/app/Config/ActivityPub.php b/app/Config/ActivityPub.php index 7f2ea61c18a08af3e0b3f1b950f7df86ff609824..062603dbc1d71fdb4efdcf7b193c9c970d058e5a 100644 --- a/app/Config/ActivityPub.php +++ b/app/Config/ActivityPub.php @@ -11,4 +11,15 @@ class ActivityPub extends ActivityPubBase */ public $actorObject = 'App\Libraries\PodcastActor'; public $noteObject = 'App\Libraries\NoteObject'; + + /** + * -------------------------------------------------------------------- + * Default avatar and cover images + * -------------------------------------------------------------------- + */ + public $defaultAvatarImagePath = 'assets/images/castopod-avatar-default.jpg'; + public $defaultAvatarImageMimetype = 'image/jpeg'; + + public $defaultCoverImagePath = 'assets/images/castopod-cover-default.jpg'; + public $defaultCoverImageMimetype = 'image/jpeg'; } diff --git a/app/Libraries/ActivityPub/Config/ActivityPub.php b/app/Libraries/ActivityPub/Config/ActivityPub.php index 199817af0fccee9689c9b3ba98484194afb6b5bd..0feb9f162f9e1a8eae2311c9f56e28d0c87c58f1 100644 --- a/app/Libraries/ActivityPub/Config/ActivityPub.php +++ b/app/Libraries/ActivityPub/Config/ActivityPub.php @@ -19,4 +19,15 @@ class ActivityPub extends BaseConfig */ public $actorObject = 'ActivityPub\Objects\ActorObject'; public $noteObject = 'ActivityPub\Objects\NoteObject'; + + /** + * -------------------------------------------------------------------- + * Default avatar and cover images + * -------------------------------------------------------------------- + */ + public $defaultAvatarImagePath = 'assets/images/avatar-default.jpg'; + public $defaultAvatarImageMimetype = 'image/jpeg'; + + public $defaultCoverImagePath = 'assets/images/cover-default.jpg'; + public $defaultCoverImageMimetype = 'image/jpeg'; } diff --git a/app/Libraries/ActivityPub/Database/Migrations/2018-01-01-010000_add_actors.php b/app/Libraries/ActivityPub/Database/Migrations/2018-01-01-010000_add_actors.php index 9e6ab14cbead2e4aa08f58caad91461eca6a9932..9e2b2f5c984a021a2fed7647ddca2f89ed215e55 100644 --- a/app/Libraries/ActivityPub/Database/Migrations/2018-01-01-010000_add_actors.php +++ b/app/Libraries/ActivityPub/Database/Migrations/2018-01-01-010000_add_actors.php @@ -54,12 +54,14 @@ class AddActors extends Migration 'avatar_image_url' => [ 'type' => 'VARCHAR', 'constraint' => 255, + 'null' => true, ], // constraint is 13 because the longest safe mimetype for images is image/svg+xml, // see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#image_types 'avatar_image_mimetype' => [ 'type' => 'VARCHAR', 'constraint' => 13, + 'null' => true, ], 'cover_image_url' => [ 'type' => 'VARCHAR', diff --git a/app/Libraries/ActivityPub/Entities/Actor.php b/app/Libraries/ActivityPub/Entities/Actor.php index 2d8d769dfaff3d30772c58abe96be2747829f771..acf73aa31e0a92d1ca0c4ee37b12afc2eeb61312 100644 --- a/app/Libraries/ActivityPub/Entities/Actor.php +++ b/app/Libraries/ActivityPub/Entities/Actor.php @@ -36,8 +36,8 @@ class Actor extends Entity 'summary' => '?string', 'private_key' => '?string', 'public_key' => '?string', - 'avatar_image_url' => 'string', - 'avatar_image_mimetype' => 'string', + 'avatar_image_url' => '?string', + 'avatar_image_mimetype' => '?string', 'cover_image_url' => '?string', 'cover_image_mimetype' => '?string', 'inbox_url' => 'string', @@ -81,4 +81,40 @@ class Actor extends Entity 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']; + } } diff --git a/app/Libraries/ActivityPub/Objects/ActorObject.php b/app/Libraries/ActivityPub/Objects/ActorObject.php index 5d9f07ee8521f55fcf4e8b23743d16db0d4ab83e..4fa0b8062f25e0d030ae0dd3d15a93e7c1e3c748 100644 --- a/app/Libraries/ActivityPub/Objects/ActorObject.php +++ b/app/Libraries/ActivityPub/Objects/ActorObject.php @@ -91,13 +91,12 @@ class ActorObject extends ObjectType $this->outbox = $actor->outbox_url; $this->followers = $actor->followers_url; - if ($actor->cover_image_url) { - $this->image = [ - 'type' => 'Image', - 'mediaType' => $actor->cover_image_mimetype, - 'url' => $actor->cover_image_url, - ]; - } + $this->image = [ + 'type' => 'Image', + 'mediaType' => $actor->cover_image_mimetype, + 'url' => $actor->cover_image_url, + ]; + $this->icon = [ 'type' => 'Image', 'mediaType' => $actor->avatar_image_mimetype, diff --git a/app/Models/PodcastModel.php b/app/Models/PodcastModel.php index 67b2ef8b671bf7af672196feec5e4f9338c50cdc..e533bbb71ea315a0d4c014d604b14ae4d1490bf9 100644 --- a/app/Models/PodcastModel.php +++ b/app/Models/PodcastModel.php @@ -297,12 +297,6 @@ class PodcastModel extends Model 'public_key' => $publickey, 'display_name' => $data['data']['title'], 'summary' => $data['data']['description_html'], - 'avatar_image_url' => '', - 'avatar_image_mimetype' => '', - 'cover_image_url' => base_url( - 'assets/images/castopod-cover-default.jpg', - ), - 'cover_image_mimetype' => 'image/jpeg', 'inbox_url' => url_to('inbox', $username), 'outbox_url' => url_to('outbox', $username), 'followers_url' => url_to('followers', $username), @@ -342,6 +336,7 @@ class PodcastModel extends Model $actor->display_name = $podcast->title; $actor->summary = $podcast->description_html; $actor->avatar_image_url = $podcast->image->thumbnail_url; + $actor->avatar_image_mimetype = $podcast->image_mimetype; if ($actor->hasChanged()) { $actorModel->update($actor->id, $actor); diff --git a/app/Views/_assets/images/castopod-avatar-default.jpg b/app/Views/_assets/images/castopod-avatar-default.jpg new file mode 100644 index 0000000000000000000000000000000000000000..644126c569b388f9d2ec614f32a41feecd8a088a Binary files /dev/null and b/app/Views/_assets/images/castopod-avatar-default.jpg differ diff --git a/app/Views/podcast/_partials/header.php b/app/Views/podcast/_partials/header.php index 1002dea9f9fa48629f158fe3b4e213cf333ed8ff..48ce183d12ed2bc867d4beabeb27c38c85f99602 100644 --- a/app/Views/podcast/_partials/header.php +++ b/app/Views/podcast/_partials/header.php @@ -1,10 +1,6 @@ <header id="main-header" class="fixed top-0 left-0 flex-col flex-shrink-0 h-screen transform -translate-x-full sm:left-auto sm:-translate-x-0 sm:sticky w-80 sm:w-64 lg:w-80 xl:w-112 sm:flex"> - <?php if ($podcast->actor->cover_image_url): ?> - <img src="<?= $podcast->actor - ->cover_image_url ?>" alt="" class="object-cover w-full h-48 bg-pine-900"/> - <?php else: ?> - <div class="w-full h-48 bg-pine-900"></div> - <?php endif; ?> + <img src="<?= $podcast->actor + ->cover_image_url ?>" alt="" class="object-cover w-full h-48 bg-pine-900"/> <div class="flex items-center justify-between px-4 py-2 mb-4 lg:px-6 -mt-14 lg:-mt-16 xl:-mt-20"> <img src="<?= $podcast->image ->thumbnail_url ?>" alt="<?= $podcast->title ?>" class="h-24 rounded-full shadow-xl xl:h-36 lg:h-28 ring-4 ring-pine-50" /> diff --git a/app/Views/podcast/follow.php b/app/Views/podcast/follow.php index 063367661c6aeee2676a12975c06106a8ab1d44a..8a564a2eecce827c89ac9b09ae808a3d8c065119 100644 --- a/app/Views/podcast/follow.php +++ b/app/Views/podcast/follow.php @@ -31,11 +31,7 @@ 'ActivityPub.follow.subtitle', ) ?></h1> <div class="flex flex-col w-full max-w-xs -mt-24 overflow-hidden bg-white shadow rounded-xl"> - <?php if ($actor->cover_image_url): ?> <img src="<?= $actor->cover_image_url ?>" alt="" class="object-cover w-full h-32 bg-pine-800" /> - <?php else: ?> - <div class="w-full h-32 bg-pine-800"></div> - <?php endif; ?> <div class="flex px-4 py-2"> <img src="<?= $actor->avatar_image_url ?>" alt="<?= $actor->display_name ?>" class="w-16 h-16 mr-4 -mt-8 rounded-full shadow-xl ring-2 ring-white" />