]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub.php
Merge pull request #8948 from annando/remove-gcontact
[friendica.git] / src / Protocol / ActivityPub.php
index 2f8c2f419e5d0cc5e87d453b561b7e0016ddc717..c04b9e592debc183f60930959c7e5b7b46086c24 100644 (file)
 
 namespace Friendica\Protocol;
 
-use Friendica\Util\JsonLD;
-use Friendica\Util\Network;
 use Friendica\Core\Protocol;
+use Friendica\Database\DBA;
+use Friendica\DI;
 use Friendica\Model\APContact;
 use Friendica\Model\User;
 use Friendica\Util\HTTPSignature;
+use Friendica\Util\JsonLD;
 
 /**
  * ActivityPub Protocol class
@@ -87,24 +88,23 @@ class ActivityPub
         * @return array
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function fetchContent($url, $uid = 0)
+       public static function fetchContent(string $url, int $uid = 0)
        {
-               if (!empty($uid)) {
-                       return HTTPSignature::fetch($url, $uid);
-               }
-
-               $curlResult = Network::curl($url, false, ['accept_content' => 'application/activity+json, application/ld+json']);
-               if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
-                       return false;
-               }
-
-               $content = json_decode($curlResult->getBody(), true);
+               if (empty($uid)) {
+                       $user = User::getFirstAdmin(['uid']);
+               
+                       if (empty($user['uid'])) {
+                               // When the system setup is missing an admin we just take the first user
+                               $condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
+                               $user = DBA::selectFirst('user', ['uid'], $condition);
+                       }
 
-               if (empty($content) || !is_array($content)) {
-                       return false;
+                       if (!empty($user['uid'])) {
+                               $uid = $user['uid'];
+                       }
                }
 
-               return $content;
+               return HTTPSignature::fetch($url, $uid);
        }
 
        private static function getAccountType($apcontact)