X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FProtocol%2FActivityPub.php;h=c3168f5509f98b3f5fc7ab6477f81cc32bb97d7e;hb=dbad46c37847f894312c0f1318a21f5ce3606cb0;hp=3a8a5e5b12ab82c7552b86d72eb1fd4b0aed1816;hpb=8b344141da6dcc6b01b498637131822fadab24ff;p=friendica.git diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 3a8a5e5b12..c3168f5509 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -1,7 +1,24 @@ . + * */ + namespace Friendica\Protocol; use Friendica\Util\JsonLD; @@ -12,7 +29,8 @@ use Friendica\Model\User; use Friendica\Util\HTTPSignature; /** - * @brief ActivityPub Protocol class + * ActivityPub Protocol class + * * The ActivityPub Protocol is a message exchange protocol defined by the W3C. * https://www.w3.org/TR/activitypub/ * https://www.w3.org/TR/activitystreams-core/ @@ -57,8 +75,8 @@ class ActivityPub */ public static function isRequest() { - return stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/activity+json') || - stristr(defaults($_SERVER, 'HTTP_ACCEPT', ''), 'application/ld+json'); + return stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/activity+json') || + stristr($_SERVER['HTTP_ACCEPT'] ?? '', 'application/ld+json'); } /** @@ -173,7 +191,7 @@ class ActivityPub */ public static function fetchOutbox($url, $uid) { - $data = self::fetchContent($url); + $data = self::fetchContent($url, $uid); if (empty($data)) { return; } @@ -195,6 +213,37 @@ class ActivityPub } } + /** + * Fetch items from AP endpoints + * + * @param string $url Address of the endpoint + * @param integer $uid Optional user id + * @return array Endpoint items + */ + public static function fetchItems(string $url, int $uid = 0) + { + $data = self::fetchContent($url, $uid); + if (empty($data)) { + return []; + } + + if (!empty($data['orderedItems'])) { + $items = $data['orderedItems']; + } elseif (!empty($data['first']['orderedItems'])) { + $items = $data['first']['orderedItems']; + } elseif (!empty($data['first']) && is_string($data['first']) && ($data['first'] != $url)) { + return self::fetchItems($data['first'], $uid); + } else { + return []; + } + + if (!empty($data['next']) && is_string($data['next'])) { + $items = array_merge($items, self::fetchItems($data['next'], $uid)); + } + + return $items; + } + /** * Checks if the given contact url does support ActivityPub *