X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FJsonLD.php;h=5bf6593aed447fca5a4b9d739ba061c5124911e9;hb=d4a5a8051ad34a7be72238967afb3e6b140afdc8;hp=25ce74fcc7c1c044cebc7843f953e361e0a4baac;hpb=1edcd65e0eaca54320a5f5cc170273b3ac29eaed;p=friendica.git diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 25ce74fcc7..5bf6593aed 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -1,6 +1,6 @@ $url]); @@ -140,7 +152,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'); @@ -159,6 +171,7 @@ class JsonLD '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'], + 'pixelfed' => (object)['@id' => 'http://pixelfed.org/ns#', '@type' => '@id'], ]; $orig_json = $json; @@ -196,13 +209,18 @@ class JsonLD Logger::notice('compacting error', ['msg' => $e->getMessage(), 'previous' => $e->getPrevious(), 'line' => $e->getLine()]); if ($logfailed && DI::config()->get('debug', 'ap_log_failure')) { $tempfile = tempnam(System::getTempPath(), 'failed-jsonld'); - file_put_contents($tempfile, json_encode(['json' => $orig_json, 'callstack' => System::callstack(20), 'msg' => $e->getMessage(), 'previous' => $e->getPrevious()], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); + file_put_contents($tempfile, json_encode(['json' => $orig_json, 'msg' => $e->getMessage(), 'previous' => $e->getPrevious()], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); Logger::notice('Failed message stored', ['file' => $tempfile]); } } $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; }