<?php
/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* @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');
'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;
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 {
$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;
}