Skip to content

Instantly share code, notes, and snippets.

@jsicot
Last active August 29, 2015 13:56
Show Gist options
  • Save jsicot/9093712 to your computer and use it in GitHub Desktop.
Save jsicot/9093712 to your computer and use it in GitHub Desktop.
<?php
$openurl = http_build_query($_GET, null, '&');
$ou = new openURLParser();
$ou->convertOpenURL($openurl);
$ou->parseData();
/* var_dump($ou->query); */
//Construct Query
if(($ou->query->dcidentifier != "") && ($ou->query->dctitle !="") && ($ou->query->dccreator !="")){
$query ='(dcidentifier:'.$ou->query->dcidentifier.' OR dclink:'.$ou->query->dcidentifier.' OR dcdocid:'.$ou->query->dcidentifier.' OR dcdoi:'.$ou->query->dcidentifier.') OR (dccreator:'.$ou->query->dccreator.' AND dctitle:'.$ou->query->dctitle.')';
}
elseif(($ou->query->dcidentifier == "") && ($ou->query->dctitle !="") && ($ou->query->dccreator !="")){
$query='(dccreator:'.$ou->query->dccreator.' AND dctitle:'.$ou->query->dctitle.')';
}
elseif(($ou->query->dcidentifier == "") && ($ou->query->dctitle !="") && ($ou->query->dccreator =="")){
$query='(dctitle:'.$ou->query->dctitle.')';
}
$url = 'http://api.base-search.net/cgi-bin/BaseHttpSearchInterface.fcgi?func=PerformSearch&query='.$query.'&hits=1&offset=0&format=json';
$json = file_get_contents($url);
header('Content-Type: text/javascript; charset=utf8');
header('Access-Control-Allow-Methods: GET, POST');
print $_GET['callback'].'('.$json.')' ; //callback is prepended for json-p
/** Parser OPENURL adapted from https://github.com/jessequinn/openURLParser **/
class openURLParser {
public $query;
private $metaDataObjects = array('rft_atitle=','rft_title=','rft_date=','rft_aufirst=','rft_aulast=','rft_au=','rft_genre=', 'rft_id=', 'rft_issue=', 'rft_volume=', 'rft_spage=', 'rft_epage=','rft_pub=','rft_issn=','rft_isbn=','SS_doi=','rft_externaldocid=');
private $coin;
public function __construct() {
// do nothing
}
public function convertOpenURL($openURL) {
$this->coin = $openURL;
$this->coin = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($this->coin));
$this->coin = html_entity_decode($this->coin,null,'UTF-8');
return $this->coin;
}
public function parseData() {
$pieces = explode("&", $this->coin);
foreach($pieces as $p) {
$p = str_replace("amp;", "", $p);
//rft_atitle
if(strpos($p, $this->metaDataObjects[0]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->dctitle = $p;
}
//rft_jtitle
if(strpos($p, $this->metaDataObjects[1]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->rftjtitle = $p;
}
//rft_date
if(strpos($p, $this->metaDataObjects[2]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->dcyear = $p;
}
//rft_au
if(strpos($p, $this->metaDataObjects[5]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->dccreator = $p ;
}
//rft_genre
if(strpos($p, $this->metaDataObjects[6]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->rftgenre = $p;
}
//rft_date
if(strpos($p, $this->metaDataObjects[2]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->dcyear = $p;
}
//rft_issue
if(strpos($p, $this->metaDataObjects[8]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->rftissue = $p;
}
//rft_volume
if(strpos($p, $this->metaDataObjects[9]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->rftvolume = $p;
}
//rft_spage
if(strpos($p, $this->metaDataObjects[10]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->rftspage = $p;
}
//rft_epage
if(strpos($p, $this->metaDataObjects[11]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->rftepage = $p;
}
//rft_pub
if(strpos($p, $this->metaDataObjects[12]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->rftpub = $p;
}
//rft_issn
if(strpos($p, $this->metaDataObjects[13]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->rftissn = $p;
}
//rft_isbn
if(strpos($p, $this->metaDataObjects[14]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->rftisbn = $p;
}
//SS_doi
if(strpos($p, $this->metaDataObjects[15]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->dcidentifier = $p;
}
//rft_externaldocid
if(strpos($p, $this->metaDataObjects[16]) !== false) {
$p = strstr($p, '=');
$p = str_replace('=', '', $p);
$p = str_replace('+', ' ', $p);
$this->query->rftdocid = $p;
}
}
}
}
?>
@kerphi
Copy link

kerphi commented Nov 29, 2014

Si je comprend bien, la ligne suivante est dépendante de la structure HTML de la page Web du résolveur de lien ?

var openurl = jQuery("#RefinerLink0 a").attr('href’); 

Mais à quoi correspond ce lien concrètement ? c'est un lien vers une des cibles que le résolveur de lien à réussi à trouver, donc potentiellement cliquable par l'utilisateur ? ou alors autre chose, mais quoi ?

@jsicot
Copy link
Author

jsicot commented Nov 29, 2014

C’est la requête open URL qui a été passée au résolveur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment