A search interface for data from the Politics of Patents case study (part of Copim WP6): this parses data from the archive of RTF files and provides additional data from the European Patent Office API. https://patents.copim.ac.uk
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.

60 lines
2.0KB

  1. <?php
  2. # @name: ops_image.php
  3. # @version: 0.1
  4. # @creation_date: 2021-09-24
  5. # @license: The MIT License <https://opensource.org/licenses/MIT>
  6. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  7. # @purpose: Display images from OPS API image service
  8. # @acknowledgements:
  9. # OPS documented at https://www.epo.org/searching-for-patents/data/web-services/ops.html
  10. # 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
  11. # OPS API functions list at https://developers.epo.org/ops-v3-2/apis
  12. include '../ops_api.php';
  13. if(isset($_GET["doc_ref"])){
  14. $access_token = get_access_token();
  15. // 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)
  16. $ops_url = $_ENV["OPS_URL"] . 'rest-services/published-data/publication/epodoc/' . $document_reference . '/images';
  17. // Set up API call
  18. $ch = curl_init();
  19. curl_setopt($ch, CURLOPT_URL, $ops_url);
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  21. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token"));
  22. // Give back curl result
  23. $response = curl_exec($ch);
  24. curl_close($ch);
  25. if (strpos($response,"No results found") === false ) {
  26. // Turn the API response into useful XML
  27. $xml = new SimpleXMLElement($response);
  28. // Retrieve image path from that XML
  29. $drawings_url = $_ENV["OPS_URL_IMAGES"] . '3.2/rest-services/' . $xml->xpath("///ops:document-instance[@desc='Drawing']/@link")[0][0]->__toString() . '?Range=1';
  30. // Set up API call
  31. $ch = curl_init();
  32. curl_setopt($ch, CURLOPT_URL, $drawings_url);
  33. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  34. curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token"));
  35. // Give back curl result
  36. $response = curl_exec($ch);
  37. curl_close($ch);
  38. //Display the image in the browser
  39. header('Content-type: image/jpeg');
  40. echo $response;
  41. }
  42. }
  43. ?>