From 410e768c65802c8af8e4d6672519de427397bb21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20Zermatten?= Date: Tue, 17 Dec 2024 15:30:39 +0000 Subject: [PATCH 1/5] DIS-138 feat: libkey link for EBSCO host records --- code/web/Drivers/LibKeyDriver.php | 40 ++++++++++++++----- .../EBSCOhost/result-tools-horizontal.tpl | 5 +++ .../sys/SearchObject/EbscohostSearcher.php | 18 ++++++--- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/code/web/Drivers/LibKeyDriver.php b/code/web/Drivers/LibKeyDriver.php index cc2fa3563c..7a46bb506b 100644 --- a/code/web/Drivers/LibKeyDriver.php +++ b/code/web/Drivers/LibKeyDriver.php @@ -1,10 +1,7 @@ containsDoi($doiUrl)) { - return null; - } + public function getLibKeyLink($data): string | null { require_once ROOT_DIR . '/sys/LibKey/LibKeySetting.php'; $activeLibrary = Library::getActiveLibrary(); $settings = new LibKeySetting(); @@ -13,16 +10,41 @@ public function getLibKeyLink(string $doiUrl): string | null { return null; } $curlWrapper = new CurlWrapper; - $response = $curlWrapper->curlGetPage("https://public-api.thirdiron.com/public/v1/libraries/" . $settings->libraryId . "/articles/doi/" . $this->extractDoi($doiUrl) . "?access_token=" . $settings->apiKey); + $doi = $this->getDoi($data); + if (!$doi) { + return null; + } + $response = $curlWrapper->curlGetPage("https://public-api.thirdiron.com/public/v1/libraries/" . $settings->libraryId . "/articles/doi/" . $doi . "?access_token=" . $settings->apiKey); if (empty($response)) { return null; } - return json_decode($response, true)["data"]["bestIntegratorLink"]["bestLink"]; + $result = json_decode($response, true)["data"]["bestIntegratorLink"]["bestLink"]; + return $result; } - public function extractDoi(string $url): string { - $doi = str_replace(["https://doi.org/", "http://"], "", $url); - return $doi; + + private function getDoi($data): string | null { + if (!is_object($data)) { + if (!$this->containsDoi($data)) { + return null; + } + return $this->extractDoiFromUrl($data); + } + return $this->findDoiInArray((array) $data); } + + private function findDoiInArray(array $uiList): string | null { + foreach ($uiList as $ui) { + if (!is_array($ui) && !is_object($ui) && $this->containsDoi($ui)) { + return $ui; + } + } + return null; + } + + private function extractDoiFromUrl(string $url): string { + return str_replace(["https://doi.org/", "http://"], "", $url); + } + public function containsDoi(string $url): bool { return preg_match('/10.\d{4,9}\/[-._;()\/:A-Za-z0-9]/', $url); } diff --git a/code/web/interface/themes/responsive/EBSCOhost/result-tools-horizontal.tpl b/code/web/interface/themes/responsive/EBSCOhost/result-tools-horizontal.tpl index a74bbea439..72a928af58 100644 --- a/code/web/interface/themes/responsive/EBSCOhost/result-tools-horizontal.tpl +++ b/code/web/interface/themes/responsive/EBSCOhost/result-tools-horizontal.tpl @@ -3,6 +3,11 @@