namespace Friendica\Protocol;
use Friendica\Core\Protocol;
+use Friendica\Database\DBA;
+use Friendica\DI;
use Friendica\Model\APContact;
use Friendica\Model\User;
-use Friendica\Network\HTTPRequest;
use Friendica\Util\HTTPSignature;
use Friendica\Util\JsonLD;
* @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 = HTTPRequest::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)