Quellcode durchsuchen

Added image retrieval from OPS API. Needs work.

main
Simon Bowie vor 3 Jahren
Ursprung
Commit
eac5681b7b
4 geänderte Dateien mit 134 neuen und 1 gelöschten Zeilen
  1. +2
    -0
      config.env.template
  2. +45
    -1
      site/ops_api.php
  3. +28
    -0
      site/public/index.php
  4. +59
    -0
      site/public/ops_image.php

+ 2
- 0
config.env.template Datei anzeigen

@@ -11,6 +11,8 @@ SOLR_CORE=
# OPS API variables
# Hostname for OPS API, usually https://ops.epo.org
OPS_URL=
# Hostname for OPS API for images, for some reason different to above
OPS_URL_IMAGES=
# API credentials from OPS https://developers.epo.org/
CONSUMER_KEY=
CONSUMER_SECRET=

+ 45
- 1
site/ops_api.php Datei anzeigen

@@ -42,7 +42,7 @@ function get_publication_details($document_reference) {
$access_token = get_access_token();

// OPS API credentials (details at http://documents.epo.org/projects/babylon/eponet.nsf/0/F3ECDCC915C9BCD8C1258060003AA712/$File/ops_v3.2_documentation_-_version_1.3.16_en.pdf)
$ops_url = $_ENV["OPS_URL"] . 'rest-services/published-data/publication/epodoc/' . $document_reference . '/biblio';
$ops_url = $_ENV["OPS_URL"] . 'rest-services/published-data/publication/epodoc/' . $document_reference . '/biblio,full-cycle';

// Set up API call
$ch = curl_init();
@@ -55,9 +55,53 @@ function get_publication_details($document_reference) {
curl_close($ch);

if (strpos($response,"No results found") === false ) {
$xml = new SimpleXMLElement($response);
print_r($response);
}

}

function get_images($document_reference) {

$access_token = get_access_token();

// OPS API credentials (details at http://documents.epo.org/projects/babylon/eponet.nsf/0/F3ECDCC915C9BCD8C1258060003AA712/$File/ops_v3.2_documentation_-_version_1.3.16_en.pdf)
$ops_url = $_ENV["OPS_URL"] . 'rest-services/published-data/publication/epodoc/' . $document_reference . '/images';

// Set up API call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ops_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token"));

// Give back curl result
$response = curl_exec($ch);
curl_close($ch);

if (strpos($response,"No results found") === false ) {

// Turn the API response into useful XML
$xml = new SimpleXMLElement($response);

// Retrieve image path from that XML
$drawings_url = $_ENV["OPS_URL_IMAGES"] . '3.2/rest-services/' . $xml->xpath("///ops:document-instance[@desc='Drawing']/@link")[0][0]->__toString() . '?Range=1';

// Set up API call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $drawings_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token"));

// Give back curl result
$response = curl_exec($ch);
curl_close($ch);

//Display the image in the browser
header('Content-type: image/jpeg');
echo $response;

}

}

?>

+ 28
- 0
site/public/index.php Datei anzeigen

@@ -58,6 +58,12 @@ echo $random_record['title'];

<br><br>

<?php

if ($random_record['abstract']):

?>

Abstract:

<?php
@@ -68,6 +74,10 @@ echo $random_record['abstract'];

<br><br>

<?
endif;
?>

<?php

if (get_publication_details($random_record['doc_ref'])):
@@ -79,3 +89,21 @@ echo $random_record['abstract'];
<?php
endif;
?>

<?php

//if (get_images($random_record['doc_ref'])):

?>

<!-- TO DO: RESOLVE WHY NGINX DOESN'T DISPLAY ANY OTHER PAGES IN THE PUBLIC DIRECTORY INCLUDING THESE TWO-->

<a href="./ops_image.php?doc_ref=<?php echo $random_record['doc_ref'] ?>">Click here for image</a>

<a href="./test.php">click</a>

<br><br>

<?php
//endif;
?>

+ 59
- 0
site/public/ops_image.php Datei anzeigen

@@ -0,0 +1,59 @@
<?php

# @name: ops_image.php
# @version: 0.1
# @creation_date: 2021-09-24
# @license: The MIT License <https://opensource.org/licenses/MIT>
# @author: Simon Bowie <ad7588@coventry.ac.uk>
# @purpose: Display images from OPS API image service
# @acknowledgements:
# OPS documented at https://www.epo.org/searching-for-patents/data/web-services/ops.html
# OPS RESTful API specification at http://documents.epo.org/projects/babylon/eponet.nsf/0/F3ECDCC915C9BCD8C1258060003AA712/$File/ops_v3.2_documentation_-_version_1.3.16_en.pdf
# OPS API functions list at https://developers.epo.org/ops-v3-2/apis

include '../ops_api.php';

if(isset($_GET["doc_ref"])){

$access_token = get_access_token();

// OPS API credentials (details at http://documents.epo.org/projects/babylon/eponet.nsf/0/F3ECDCC915C9BCD8C1258060003AA712/$File/ops_v3.2_documentation_-_version_1.3.16_en.pdf)
$ops_url = $_ENV["OPS_URL"] . 'rest-services/published-data/publication/epodoc/' . $document_reference . '/images';

// Set up API call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ops_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token"));

// Give back curl result
$response = curl_exec($ch);
curl_close($ch);

if (strpos($response,"No results found") === false ) {

// Turn the API response into useful XML
$xml = new SimpleXMLElement($response);

// Retrieve image path from that XML
$drawings_url = $_ENV["OPS_URL_IMAGES"] . '3.2/rest-services/' . $xml->xpath("///ops:document-instance[@desc='Drawing']/@link")[0][0]->__toString() . '?Range=1';

// Set up API call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $drawings_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token"));

// Give back curl result
$response = curl_exec($ch);
curl_close($ch);

//Display the image in the browser
header('Content-type: image/jpeg');
echo $response;

}

}

?>

Laden…
Abbrechen
Speichern