From 64f170b8a3a93713180564ec82cf61bd80252ac7 Mon Sep 17 00:00:00 2001 From: Paal Joergensen Date: Thu, 24 Aug 2017 12:40:53 +0200 Subject: [PATCH] Define H5P Hub endpoints one place in code --- h5p.classes.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 7c0e546..0e7f5d9 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1715,6 +1715,12 @@ abstract class H5PDisplayOptionBehaviour { abstract class H5PHubEndpoints { const CONTENT_TYPES = 'api.h5p.org/v1/content-types/'; + const SITES = 'api.h5p.org/v1/sites'; + + public static function createURL($endpoint) { + $protocol = (extension_loaded('openssl') ? 'https' : 'http'); + return "{$protocol}://{$endpoint}"; + } } /** @@ -2451,9 +2457,7 @@ class H5PCore { // Register site if it is not registered if (empty($uuid)) { - $protocol = (extension_loaded('openssl') ? 'https' : 'http'); - $endpoint = 'api.h5p.org/v1/sites'; - $registration = $this->h5pF->fetchExternalData("{$protocol}://{$endpoint}", $registrationData); + $registration = $this->h5pF->fetchExternalData(H5PHubEndpoints::createURL(H5PHubEndpoints::SITES), $registrationData); // Failed retrieving uuid if (!$registration) { @@ -2860,9 +2864,7 @@ class H5PCore { $postData['current_cache'] = $this->h5pF->getOption('content_type_cache_updated_at', 0); - $protocol = (extension_loaded('openssl') ? 'https' : 'http'); - $endpoint = H5PHubEndpoints::CONTENT_TYPES; - $data = $interface->fetchExternalData("{$protocol}://{$endpoint}", $postData); + $data = $interface->fetchExternalData(H5PHubEndpoints::createURL(H5PHubEndpoints::CONTENT_TYPES), $postData); if (! $this->h5pF->getOption('hub_is_enabled', TRUE)) { return TRUE;