X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FJsonLD.php;h=0a4d5a0b55bf40808e891f81a1d832e0377ca3c1;hb=2b3c1972db987ee2396e528476739f4cec4e8972;hp=1200a9cbed4a4c1a273e181646a15c042a8ac096;hpb=8cc362fb8b053b2c04ba02d2a6c2aac39ec2d9a0;p=friendica.git diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 1200a9cbed..0a4d5a0b55 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -1,6 +1,6 @@ $url]); @@ -140,7 +140,7 @@ class JsonLD * @return array Compacted JSON array * @throws Exception */ - public static function compact($json, bool $logfailed = true) + public static function compact($json, bool $logfailed = true): array { jsonld_set_document_loader('Friendica\Util\JsonLD::documentLoader'); @@ -157,6 +157,8 @@ class JsonLD 'sc' => (object)['@id' => 'http://schema.org#', '@type' => '@id'], 'pt' => (object)['@id' => 'https://joinpeertube.org/ns#', '@type' => '@id'], 'mobilizon' => (object)['@id' => 'https://joinmobilizon.org/ns#', '@type' => '@id'], + 'fedibird' => (object)['@id' => 'http://fedibird.com/ns#', '@type' => '@id'], + 'misskey' => (object)['@id' => 'https://misskey-hub.net/ns#', '@type' => '@id'], ]; $orig_json = $json; @@ -175,8 +177,21 @@ class JsonLD if (!in_array('https://w3id.org/security/v1', $json['@context'])) { $json['@context'][] = 'https://w3id.org/security/v1'; } + + // Issue 12419: Workaround for GoToSocial + $pos = array_search('http://joinmastodon.org/ns', $json['@context']); + if (is_int($pos)) { + $json['@context'][$pos] = ['toot' => 'http://joinmastodon.org/ns#']; + } } + // Bookwyrm transmits "id" fields with "null", which isn't allowed. + array_walk_recursive($json, function (&$value, $key) { + if ($key == 'id' && is_null($value)) { + $value = ''; + } + }); + $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); try { @@ -194,6 +209,11 @@ class JsonLD $json = json_decode(json_encode($compacted, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true); + if ($json === false) { + Logger::notice('JSON encode->decode failed', ['orig_json' => $orig_json, 'compacted' => $compacted]); + $json = []; + } + return $json; }