From 35547e28ea4680866d234e12e0f36fe721da83c8 Mon Sep 17 00:00:00 2001 From: tenma Date: Tue, 31 Mar 2020 08:07:35 +0100 Subject: [PATCH] [LRDD] Add a new method for grabing profile aliases --- plugins/LRDD/LRDDPlugin.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugins/LRDD/LRDDPlugin.php b/plugins/LRDD/LRDDPlugin.php index 549d331bf2..bd023b00d5 100644 --- a/plugins/LRDD/LRDDPlugin.php +++ b/plugins/LRDD/LRDDPlugin.php @@ -65,4 +65,27 @@ class LRDDPlugin extends Plugin return true; } + + /** + * Fetch all the aliases of some remote profile + * + * @param string $uri profile's URI + * @return array|null aliases + * @throws Exception (If the Discovery's HTTP requests fail) + * @author Bruno Casteleiro + */ + public static function grab_profile_aliases(string $uri): ?array + { + $disco = new Discovery(); + $xrd = $disco->lookup($uri); + + $all_ids = array_merge([$xrd->subject], $xrd->aliases); + + if (!in_array($uri, $all_ids)) { + $this->log(LOG_INFO, 'The original URI was not listed itself when doing discovery on it!'); + return null; + } + + return $all_ids; + } }