X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FActivityPub%2FReceiver.php;h=88c23f2be63623989f6b782caae210faed72c5d8;hb=f09d9bc9cccd4d3875d8e66fe75cb7b948b5741f;hp=7a0a9c1f78e838a85ae8ca056db03c26fbe50be9;hpb=8e14836152e7047aaebd435342f29dcf4d8a905f;p=friendica.git diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 7a0a9c1f78..88c23f2be6 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -184,7 +184,7 @@ class Receiver * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - private static function prepareObjectData($activity, $uid, $push, &$trust_source) + public static function prepareObjectData($activity, $uid, $push, &$trust_source) { $actor = JsonLD::fetchElement($activity, 'as:actor', '@id'); if (empty($actor)) { @@ -227,6 +227,7 @@ class Receiver if ($type == 'as:Announce') { $trust_source = false; } + $object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source, $uid); if (empty($object_data)) { Logger::log("Object data couldn't be processed", Logger::DEBUG); @@ -337,7 +338,6 @@ class Receiver if (!JsonLD::fetchElement($activity, 'as:actor', '@id')) { Logger::log('Empty actor', Logger::DEBUG); return; - } // Don't trust the source if "actor" differs from "attributedTo". The content could be forged. @@ -374,7 +374,8 @@ class Receiver switch ($type) { case 'as:Create': if (in_array($object_data['object_type'], self::CONTENT_TYPES)) { - ActivityPub\Processor::createItem($object_data); + $item = ActivityPub\Processor::createItem($object_data); + ActivityPub\Processor::postItem($object_data, $item); } break; @@ -391,7 +392,8 @@ class Receiver // If this isn't set, then a single reshare appears on top. This is used for groups. $object_data['thread-completion'] = ($profile['type'] != 'Group'); - ActivityPub\Processor::createItem($object_data); + $item = ActivityPub\Processor::createItem($object_data); + ActivityPub\Processor::postItem($object_data, $item); // Add the bottom reshare information only for persons if ($profile['type'] != 'Group') { @@ -677,7 +679,7 @@ class Receiver return; } - if (Contact::updateFromProbe($cid, '', true)) { + if (Contact::updateFromProbe($cid)) { Logger::info('Update was successful', ['id' => $cid, 'uid' => $uid, 'url' => $url]); } @@ -877,7 +879,7 @@ class Receiver * * @param array $attachments Attachments in JSON-LD format * - * @return array with attachmants in a simplified format + * @return array Attachments in a simplified format */ private static function processAttachments(array $attachments) { @@ -925,6 +927,62 @@ class Receiver 'url' => JsonLD::fetchElement($attachment, 'as:href', '@id') ]; break; + case 'as:Image': + $mediaType = JsonLD::fetchElement($attachment, 'as:mediaType', '@value'); + $imageFullUrl = JsonLD::fetchElement($attachment, 'as:url', '@id'); + $imagePreviewUrl = null; + // Multiple URLs? + if (!$imageFullUrl && ($urls = JsonLD::fetchElementArray($attachment, 'as:url'))) { + $imageVariants = []; + $previewVariants = []; + foreach ($urls as $url) { + // Scalar URL, no discrimination possible + if (is_string($url)) { + $imageFullUrl = $url; + continue; + } + + // Not sure what to do with a different Link media type than the base Image, we skip + if ($mediaType != JsonLD::fetchElement($url, 'as:mediaType', '@value')) { + continue; + } + + $href = JsonLD::fetchElement($url, 'as:href', '@id'); + + // Default URL choice if no discriminating width is provided + $imageFullUrl = $href ?? $imageFullUrl; + + $width = intval(JsonLD::fetchElement($url, 'as:width', '@value') ?? 1); + + if ($href && $width) { + $imageVariants[$width] = $href; + // 632 is the ideal width for full screen frio posts, we compute the absolute distance to it + $previewVariants[abs(632 - $width)] = $href; + } + } + + if ($imageVariants) { + // Taking the maximum size image + ksort($imageVariants); + $imageFullUrl = array_pop($imageVariants); + + // Taking the minimum number distance to the target distance + ksort($previewVariants); + $imagePreviewUrl = array_shift($previewVariants); + } + + unset($imageVariants); + unset($previewVariants); + } + + $attachlist[] = [ + 'type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')), + 'mediaType' => $mediaType, + 'name' => JsonLD::fetchElement($attachment, 'as:name', '@value'), + 'url' => $imageFullUrl, + 'image' => $imagePreviewUrl !== $imageFullUrl ? $imagePreviewUrl : null, + ]; + break; default: $attachlist[] = [ 'type' => str_replace('as:', '', JsonLD::fetchElement($attachment, '@type')),