3 * @file src/Util/JsonLD.php
5 namespace Friendica\Util;
7 use Friendica\Core\Cache;
8 use digitalbazaar\jsonld as DBJsonLD;
11 * @brief This class contain methods to work with JsonLD data
15 public static function documentLoader($url)
19 $x = debug_backtrace();
22 if ($n['function'] === __FUNCTION__) {
29 logger('jsonld bomb detected at: ' . $url);
33 $result = Cache::get('documentLoader:' . $url);
34 if (!is_null($result)) {
38 $data = jsonld_default_document_loader($url);
39 Cache::set('documentLoader:' . $url, $data, CACHE_DAY);
43 public static function normalize($json)
45 jsonld_set_document_loader('Friendica\Util\JsonLD::documentLoader');
47 $jsonobj = json_decode(json_encode($json));
49 return jsonld_normalize($jsonobj, array('algorithm' => 'URDNA2015', 'format' => 'application/nquads'));
52 public static function compact($json)
54 jsonld_set_document_loader('Friendica\Util\JsonLD::documentLoader');
56 $context = (object)['as' => 'https://www.w3.org/ns/activitystreams',
57 'w3sec' => 'https://w3id.org/security',
58 'ostatus' => (object)['@id' => 'http://ostatus.org#', '@type' => '@id'],
59 'vcard' => (object)['@id' => 'http://www.w3.org/2006/vcard/ns#', '@type' => '@id'],
60 'uuid' => (object)['@id' => 'http://schema.org/identifier', '@type' => '@id']];
62 $jsonobj = json_decode(json_encode($json));
64 $compacted = jsonld_compact($jsonobj, $context);
66 return json_decode(json_encode($compacted), true);