| } | } | ||||
| 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(); | $access_token = get_access_token(); | ||||
| $ch = curl_init(); | $ch = curl_init(); | ||||
| curl_setopt($ch, CURLOPT_URL, $drawings_url); | curl_setopt($ch, CURLOPT_URL, $drawings_url); | ||||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 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 | // Give back curl result | ||||
| $response = curl_exec($ch); | $response = curl_exec($ch); | ||||
| curl_close($ch); | curl_close($ch); | ||||
| //Display the image in the browser | |||||
| header('Content-type: image/jpeg'); | |||||
| echo $response; | |||||
| // Return the PDF response | |||||
| return $response; | |||||
| } | } | ||||
| <?php | <?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> | <a href="./ops_image.php?doc_ref=<?php echo $random_record['doc_ref'] ?>">Click here for image</a> | ||||
| <br><br> | <br><br> | ||||
| <?php | <?php | ||||
| //endif; | |||||
| endif; | |||||
| ?> | ?> |
| if(isset($_GET["doc_ref"])){ | 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; | |||||
| } | } | ||||