Skip to content

Commit

Permalink
feat: check if a url contains a DOI
Browse files Browse the repository at this point in the history
  • Loading branch information
Chloe070196 committed Dec 3, 2024
1 parent 27ebf39 commit 8575fa4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions code/web/Drivers/LibKeyDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

class LibKeyDriver {
public function getLibKeyLink(string $doiUrl): string | null {
if (!$this->containsDoi($doiUrl)) {
return null;
}
require_once ROOT_DIR . '/sys/LibKey/LibKeySetting.php';
$activeLibrary = Library::getActiveLibrary();
$settings = new LibKeySetting();
Expand All @@ -20,4 +23,7 @@ public function extractDoi(string $url): string {
$doi = str_replace(["https://doi.org/", "http://"], "", $url);
return $doi;
}
public function containsDoi(string $url): bool {
return preg_match('/10.\d{4,9}\/[-._;()\/:A-Z0-9]/', $url);
}
}

0 comments on commit 8575fa4

Please sign in to comment.