BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

doi.php 853B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. declare(strict_types=1);
  3. $ENV = ENV::go();
  4. if (!$_GET['doi']) {
  5. json_error('expected doi param');
  6. } elseif (!preg_match("/$ENV->DOI_REGEX/", strtoupper($_GET['doi']))) {
  7. json_error('expected valid doi');
  8. } else {
  9. $DOI = $_GET['doi'];
  10. }
  11. # https://weichie.com/blog/curl-api-calls-with-php/
  12. $curl = curl_init();
  13. curl_setopt($curl, CURLOPT_URL, "$ENV->SS/$DOI");
  14. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  15. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  16. $output = curl_exec($curl);
  17. curl_close($curl);
  18. # I don't like this nested json_*code() business
  19. # It's slow and unnecesary since SS already outputs JSON
  20. # todo: At least cache the response, then refactor
  21. print
  22. json_encode(
  23. [
  24. 'status' => 'success',
  25. 'response' => json_decode($output, true),
  26. ],
  27. JSON_UNESCAPED_SLASHES
  28. );