소스 검색

Started organising the bibliographic details response from OPS API

main
Simon Bowie 3 년 전
부모
커밋
6ed5d292da
2개의 변경된 파일54개의 추가작업 그리고 8개의 파일을 삭제
  1. +27
    -6
      site/ops_api.php
  2. +27
    -2
      site/public/index.php

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

@@ -48,19 +48,40 @@ function get_publication_details($document_reference) {
$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"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $access_token", "Accept: application/json"));

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

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

print_r($response);
//var_dump($xml->{'exchange-documents'}->{'exchange-document'}->{'bibliographic-data'}->{'invention-title'}['lang']);
//print_r($xml->xpath('//*'));
//print_r($xml);
// Turn the API response into useful Json
$json = json_decode($response);

// For each invention title, check if it's in the original language
foreach ($json->{'ops:world-patent-data'}->{'exchange-documents'}->{'exchange-document'}->{'bibliographic-data'}->{'invention-title'} as $invention_title){

if ($invention_title->{'@lang'} === 'ol'){

$output['original_title'] = $invention_title->{'$'};

}

}

// For each abstract, check if it's in the original language
foreach ($json->{'ops:world-patent-data'}->{'exchange-documents'}->{'exchange-document'}->{'abstract'} as $abstract){

if ($abstract->{'@lang'} === 'ol'){

$output['original_abstract'] = $abstract->p->{'$'};

}

}

return $output;

}


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

@@ -73,15 +73,40 @@ $random_record = random_record();
?>

<?php
if (get_publication_details($random_record['doc_ref'])):
$publication_details = get_publication_details($random_record['doc_ref']);

if ($publication_details['original_title']):
?>

<br><br>
Original language title:

<?php
echo $publication_details['original_title'];
?>

<br><br>

<?php
endif;
?>

<?php
if ($publication_details['original_abstract']):
?>

Original language abstract:

<?php
echo $publication_details['original_abstract'];
?>

<br><br>

<?php
endif;
?>


<?php
if (check_for_images($random_record['doc_ref'])):
?>

Loading…
취소
저장