소스 검색

Finishing up OPS image API integration to display PDF images

main
Simon Bowie 3 년 전
부모
커밋
1e33b342f4
3개의 변경된 파일33개의 추가작업 그리고 46개의 파일을 삭제
  1. +27
    -5
      site/ops_api.php
  2. +2
    -4
      site/public/index.php
  3. +4
    -37
      site/public/ops_image.php

+ 27
- 5
site/ops_api.php 파일 보기

@@ -61,7 +61,30 @@ function get_publication_details($document_reference) {

}

function get_images($document_reference) {
function check_for_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 ) {
return $response;
}

}

function get_images($document_reference){

$access_token = get_access_token();

@@ -90,15 +113,14 @@ function get_images($document_reference) {
$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"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token","Accept: application/pdf"));

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

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

}


+ 2
- 4
site/public/index.php 파일 보기

@@ -92,16 +92,14 @@ echo $random_record['abstract'];

<?php

//if (get_images($random_record['doc_ref'])):
if (check_for_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>

<br><br>

<?php
//endif;
endif;
?>

+ 4
- 37
site/public/ops_image.php 파일 보기

@@ -15,44 +15,11 @@ include '../ops_api.php';

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

$access_token = get_access_token();
$image_output = get_images($_GET["doc_ref"]);

// 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;

}
//Display the image in the browser
header('Content-type: application/pdf');
echo $image_output;

}


Loading…
취소
저장