From 83354b2b88218090988dd6e526b0a2505b57e0f1 Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Thu, 6 Apr 2023 22:18:28 +0200 Subject: Updated 5 files and added 1110 files (automated) --- includes/jobs/UpdateContactMethods.php | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 includes/jobs/UpdateContactMethods.php (limited to 'includes/jobs') diff --git a/includes/jobs/UpdateContactMethods.php b/includes/jobs/UpdateContactMethods.php new file mode 100644 index 0000000..2e9d27f --- /dev/null +++ b/includes/jobs/UpdateContactMethods.php @@ -0,0 +1,61 @@ + $method) { + if (isset($contacts[$id][$name])) { + echo("Contact makes use of $name, gathering information\n"); + + if (!isset($cache[$name])) $cache[$name] = []; + if (!isset($cache[$name][$contacts[$id][$name]])) $cache[$name][$contacts[$id][$name]] = [ + "data" => null, + "update" => 0 + ]; + + if (time() - $cache[$name][$contacts[$id][$name]]["update"] > 86400) { + echo(" Information is out of date, updating it\n"); + + $return = []; + $cmd = "cd \"$_SERVER[DOCUMENT_ROOT]/includes/external/addressbook\" && node \"$_SERVER[DOCUMENT_ROOT]/includes/external/addressbook/$name.js\" \"" . str_replace('"', "''", $contacts[$id][$name]) . "\""; + + exec($cmd, $return); + $json = trim(implode("\n", $return)); + + $cache[$name][$contacts[$id][$name]] = [ + "data" => json_decode($json), + "update" => time() + ]; + + echo(" Information updated\n"); + } else { + echo(" Information is up to date, not updating it\n"); + } + } else { + echo("Contact does not makes use of $name\n"); + } +} + +echo("Done!\n"); + +file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/addressbook/saved.json", json_encode($cache)); \ No newline at end of file -- cgit