aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-09-19 19:15:15 -0700
committerzotlabs <mike@macgirvin.com>2017-09-19 19:15:15 -0700
commitb0cdec0c35136db8cbb0cf13135a1f5cc8d1bc05 (patch)
tree0c2848bc523b48e3f64c282e04a49b16bb8a7ce6
parent373af6d4f4afe8599f45764d5b289f714b84f630 (diff)
downloadvolse-hubzilla-b0cdec0c35136db8cbb0cf13135a1f5cc8d1bc05.tar.gz
volse-hubzilla-b0cdec0c35136db8cbb0cf13135a1f5cc8d1bc05.tar.bz2
volse-hubzilla-b0cdec0c35136db8cbb0cf13135a1f5cc8d1bc05.zip
perform caching of jsonld schemas
-rw-r--r--Zotlabs/Lib/LDSignatures.php2
-rw-r--r--include/network.php31
2 files changed, 33 insertions, 0 deletions
diff --git a/Zotlabs/Lib/LDSignatures.php b/Zotlabs/Lib/LDSignatures.php
index fa2758044..77e2ef332 100644
--- a/Zotlabs/Lib/LDSignatures.php
+++ b/Zotlabs/Lib/LDSignatures.php
@@ -82,6 +82,8 @@ class LDSignatures {
if(! is_object($data))
return '';
+ jsonld_set_document_loader('jsonld_document_loader');
+
return jsonld_normalize($data,[ 'algorithm' => 'URDNA2015', 'format' => 'application/nquads' ]);
}
diff --git a/include/network.php b/include/network.php
index da1afc3ac..7e2dbf4cf 100644
--- a/include/network.php
+++ b/include/network.php
@@ -1943,4 +1943,35 @@ function getBestSupportedMimeType($mimeTypes = null, $acceptedTypes = false) {
}
// no mime-type found
return null;
+}
+
+
+function jsonld_document_loader($url) {
+
+ // perform caching for jsonld normaliser
+
+ require_once('library/jsonld/jsonld.php');
+
+ $cachepath = 'store/[data]/ldcache';
+ if(! is_dir($cachepath))
+ os_mkdir($cachepath,STORAGE_DEFAULT_PERMISSIONS,true);
+
+ $filename = $cachepath . '/' . urlencode($url);
+ if(file_exists($filename) && filemtime($filename) > time() - (12 * 60 * 60)) {
+ return json_decode(file_get_contents($filename));
+ }
+
+ $r = jsonld_default_document_loader($url);
+ if($r) {
+ file_put_contents($filename,json_encode($r));
+ return $r;
+ }
+
+ logger('not found');
+ if(file_exists($filename)) {
+ return json_decode(file_get_contents($filename));
+ }
+
+ return [];
+
} \ No newline at end of file