]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/JsonLD.php
Fixing double encoding here as well
[friendica.git] / src / Util / JsonLD.php
index bed7a67d60a01eeccf58bc6a312f6f363541f4b6..cd3a6ec2708899d49483a7bfb3c73a92c7d762cf 100644 (file)
@@ -90,10 +90,16 @@ class JsonLD
                        'dfrn' => (object)['@id' => 'http://purl.org/macgirvin/dfrn/1.0/', '@type' => '@id'],
                        'diaspora' => (object)['@id' => 'https://diasporafoundation.org/ns/', '@type' => '@id'],
                        'ostatus' => (object)['@id' => 'http://ostatus.org#', '@type' => '@id'],
-                       'dc' => (object)['@id' => 'http://purl.org/dc/terms/', '@type' => '@id']];
+                       'dc' => (object)['@id' => 'http://purl.org/dc/terms/', '@type' => '@id'],
+                       'toot' => (object)['@id' => 'http://joinmastodon.org/ns#', '@type' => '@id']];
 
-               $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
+               // Trying to avoid memory problems with large content fields
+               if (!empty($json['object']['source']['content'])) {
+                       $content = $json['object']['source']['content'];
+                       $json['object']['source']['content'] = '';
+               }
 
+               $jsonobj = json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
 
                try {
                        $compacted = jsonld_compact($jsonobj, $context);
@@ -103,7 +109,13 @@ class JsonLD
                        Logger::log('compacting error:' . print_r($e, true), Logger::DEBUG);
                }
 
-               return json_decode(json_encode($compacted, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true);
+               $json = json_decode(json_encode($compacted, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), true);
+
+               if (isset($json['as:object']['as:source']['as:content']) && !empty($content)) {
+                       $json['as:object']['as:source']['as:content'] = $content;
+               }
+
+               return $json;
        }
 
        /**