コード例 #1
0
 function __construct($query, $request_type = 'issn', $sr_api_key = '')
 {
     $query_string = 'versions=all&' . $request_type . '=' . urlencode($query);
     if ($sr_api_key) {
         $query_string .= '&ak=' . $sr_api_key;
     }
     $client = new Zend_HTTP_Client();
     $client->setUri('http://www.sherpa.ac.uk/romeo/api29.php?' . $query_string);
     $response = $client->request();
     if ($response->getStatus() == 200) {
         $sr = $response->getBody();
         $sr_xml = new DOMDocument();
         $sr_xml->loadXML($sr);
         $this->num_hits = $sr_xml->getElementsByTagName('numhits')->item(0)->nodeValue;
         $this->issn = $sr_xml->getElementsByTagName('issn')->item(0)->nodeValue;
         $this->jtitle = $sr_xml->getElementsByTagName('jtitle')->item(0)->nodeValue;
         $pubs = $sr_xml->getElementsByTagName('publisher');
         for ($i = 0; $i < $pubs->length; $i++) {
             $id = $pubs->item($i)->getAttribute('id');
             $name = $pubs->item($i)->getElementsByTagName('name')->item(0)->nodeValue;
             $p = new Publisher($id, $name);
             $p->setPrearchiving($pubs->item($i)->getElementsByTagName('prearchiving')->item(0)->nodeValue);
             $p->setPostarchiving($pubs->item($i)->getElementsByTagName('postarchiving')->item(0)->nodeValue);
             $p->setPdfarchiving($pubs->item($i)->getElementsByTagName('pdfarchiving')->item(0)->nodeValue);
             $prerestrictions_xml = $pubs->item($i)->getElementsByTagName('prerestriction');
             $prerestrictions = array();
             for ($j = 0; $j < $prerestrictions_xml->length; $j++) {
                 $prerestrictions[] = strip_tags(trim($prerestrictions_xml->item($j)->nodeValue));
             }
             $p->setPrerestrictions($prerestrictions);
             $postrestrictions_xml = $pubs->item($i)->getElementsByTagName('postrestriction');
             $postrestrictions = array();
             for ($j = 0; $j < $postrestrictions_xml->length; $j++) {
                 $postrestrictions[] = strip_tags(trim($postrestrictions_xml->item($j)->textContent));
             }
             $p->setPostrestrictions($postrestrictions);
             $pdfrestrictions_xml = $pubs->item($i)->getElementsByTagName('pdfrestriction');
             $pdfrestrictions = array();
             for ($j = 0; $j < $pdfrestrictions_xml->length; $j++) {
                 $pdfrestrictions[] = strip_tags(trim($pdfrestrictions_xml->item($j)->nodeValue));
             }
             $p->setPdfrestrictions($pdfrestrictions);
             $conditions_xml = $pubs->item($i)->getElementsByTagName('condition');
             $conditions = array();
             for ($j = 0; $j < $conditions_xml->length; $j++) {
                 $conditions[] = $conditions_xml->item($j)->nodeValue;
             }
             $p->setConditions($conditions);
             $this->publishers[$id] = $p;
         }
     }
 }
コード例 #2
0
<?php

//set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/Zend/library');
require_once 'Zend/Http/Client.php';
require_once 'SherpaRomeo.php';
if (!isset($argv[1]) || !isset($argv[2])) {
    echo "Not enough parameters\n";
    usage();
    exit;
}
$userid = $argv[1];
$zotero_key = $argv[2];
$sherpa_romeo_key = $argv[3];
$url_base = 'https://api.zotero.org/users/' . $userid . '/';
$client = new Zend_HTTP_Client();
$client->setUri($url_base . 'items/?key=' . $zotero_key . '&itemType=journalArticle&content=json');
$response = $client->request();
if (200 != $response->getStatus()) {
    echo "Failed to get items (" . $response->getStatus() . ")\n";
    exit;
}
$items = $response->getBody();
$items_xml = new DOMDocument();
$items_xml->loadXML($items);
$item_list = $items_xml->getElementsByTagName('entry');
$sr_responses = array();
foreach ($item_list as $item) {
    $content = $item->getElementsByTagName('content')->item(0);
    $content_json = json_decode($content->nodeValue);
    $etag = $content->getAttribute('zapi:etag');
    $item_key = $item->getElementsByTagNameNS('http://zotero.org/ns/api', 'key')->item(0)->nodeValue;