+
+ /**
+ * 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): array
+ {
+ $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
+ *
+ * @param string $url profile url
+ * @param boolean $update true = always update, false = never update, null = update when not found or outdated
+ * @return boolean
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ public static function isSupportedByContactUrl(string $url, $update = null): bool
+ {
+ return !empty(APContact::getByURL($url, $update));
+ }
+
+ public static function isAcceptedRequester(int $uid = 0): bool
+ {
+ $called_by = System::callstack(1);
+
+ $signer = HTTPSignature::getSigner('', $_SERVER);
+ if (!$signer) {
+ Logger::debug('No signer or invalid signature', ['uid' => $uid, 'agent' => $_SERVER['HTTP_USER_AGENT'] ?? '', 'called_by' => $called_by]);
+ return false;
+ }
+
+ $apcontact = APContact::getByURL($signer);
+ if (empty($apcontact)) {
+ Logger::info('APContact not found', ['uid' => $uid, 'handle' => $signer, 'called_by' => $called_by]);
+ return false;
+ }
+
+ if (empty($apcontact['gsid'] || empty($apcontact['baseurl']))) {
+ Logger::debug('No server found', ['uid' => $uid, 'signer' => $signer, 'called_by' => $called_by]);
+ return false;
+ }
+
+ $contact = Contact::getByURL($signer, false, ['id', 'baseurl', 'gsid']);
+ if (!empty($contact) && Contact\User::isBlocked($contact['id'], $uid)) {
+ Logger::info('Requesting contact is blocked', ['uid' => $uid, 'id' => $contact['id'], 'signer' => $signer, 'baseurl' => $contact['baseurl'], 'called_by' => $called_by]);
+ return false;
+ }
+
+ // @todo Look for user blocked domains
+
+ Logger::debug('Server is an accepted requester', ['uid' => $uid, 'id' => $apcontact['gsid'], 'url' => $apcontact['baseurl'], 'signer' => $signer, 'called_by' => $called_by]);
+
+ return true;
+ }