X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FActivityPub.php;h=c3168f5509f98b3f5fc7ab6477f81cc32bb97d7e;hb=cc8491223ec17bd12b7f37d5b2cc16b58184291e;hp=522fee97eff2706023993de7261570cdad2b09e3;hpb=0447bb2769648eadd718e3dd9560ce2f480af8d8;p=friendica.git diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 522fee97ef..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/ @@ -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 *