From 71a4e373d197c69a09fb6aa8cc116058c0bf55f1 Mon Sep 17 00:00:00 2001 From: veselcraft Date: Sun, 13 Feb 2022 22:07:49 +0300 Subject: [PATCH] ActivityPub: [Post] add attachment support and Smithereen's target field for wall support --- Web/Models/Entities/Photo.php | 7 +++++++ Web/Presenters/WallPresenter.php | 35 +++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Web/Models/Entities/Photo.php b/Web/Models/Entities/Photo.php index ecda93f6..6c7942b1 100644 --- a/Web/Models/Entities/Photo.php +++ b/Web/Models/Entities/Photo.php @@ -59,4 +59,11 @@ class Photo extends Media return $photo; } + + function getDimentions() + { + $hash = $this->getRecord()->hash; + + return getimagesize($this->pathFromHash($hash)); + } } diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index 973584a7..a560a6ad 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -311,6 +311,12 @@ final class WallPresenter extends OpenVKPresenter if($this->isActivityPubClient()) { $objPost = array( + "@context" => [ + "https://www.w3.org/ns/activitystreams", + (object) array( + "sensitive" => "as:sensitive" + ) + ], "type" => "Note", "id" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $wall . "_" . $post_id, "attributedTo" => $post->getOwner()->getFullURL(true), @@ -335,15 +341,30 @@ final class WallPresenter extends OpenVKPresenter ] ], "sensitive" => false, - "likes" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $wall . "_" . $post_id . "/likes", - "@context" => [ - "https://www.w3.org/ns/activitystreams", - (object) array( - "sensitive" => "as:sensitive" - ) - ] + "likes" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $wall . "_" . $post_id . "/likes" ); + if($post->getTargetWall() != $post->getOwner()) + { + $objPost["target"] = array( + "type" => "Collection", + "id" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $post->getTargetWall(), + "attributedTo" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . ($post->getTargetWall() > 0 ? "/id" . $post->getTargetWall() : "club" . abs($post->getTargetWall())) + ); + } + + foreach($post->getChildren() as $attachment) { + if($attachment instanceof \openvk\Web\Models\Entities\Photo) { + $objPost["attachment"][] = array( + "type" => "Image", + "mediaType" => "image/jpeg", + "width" => $attachment->getDimentions()[0], + "height" => $attachment->getDimentions()[1], + "url" => $attachment->getURL() + ); + } + } + $this->returnJson($objPost, CT_AP); }