Last active
August 29, 2015 13:56
-
-
Save jsicot/9093712 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} | |
} | |
} | |
?> |
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 ?
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
Comment ça marche
En gros lorsqu’une requête est envoyée à notre résolveur, par exemple :
http://mz8cl4dl5q.search.serialssolutions.com/?paramdict=fr-fr&genre=article&spage=5&SS_issnh=0003-066X&SS_eissnh=1935-990X&SS_sid=info%3Asid%2Fsummon.serialssolutions.com&issn=0003066X&SS_referer=http%3A%2F%2Fcatalogue.bu.univ-rennes2.fr%2Fcgi-bin%2Fkoha%2Fopac-combined-search.pl%3Fidx%3Dti%26q%3Dpsychology%2Bpositive%26searchOn%3Don&issue=1&date=2000&externaldbid=n%2Fa&externaldocid=10_1037__0003_066X_55_1_5&aulast=P&atitle=Positive+psychology%3A+An+introduction&title=American+Psychologist&eissn=1935990X&localeid=1036&aufirst=Seligman%2C+Martin+E.¶mdict=fr-fr&jtitle=American+Psychologist&SS_LibHash=MZ8CL4DL5Q&sid=info%3Asid%2Fsummon.serialssolutions.com&SS_authors=Seligman%2C+Martin+E.+P%3BCsikszentmihalyi%2C+Mihaly&SS_source=56&l=MZ8CL4DL5Q&SS_ReferentFormat=JournalFormat&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&au=Seligman%2C+Martin+E.+P&PP=true&volume=55&SS_RequestType=1&epage=14&&SS_PostParamDict=disableOneClick
Je récupère via un sélecteur jquery une sorte de lien openurl/coins qui est encapsulé dans la page.
En jquery ça ressemble à ça :
Traduction => récupère la valeur de l’attribut href du lien qui se trouve dans la div avec l’id « RefinerLink0 »
La valeur récupérée :
?SS_Page=refiner&SS_styleselector=0&SS_LibHash=MZ8CL4DL5Q&url_ver=Z39.88-2004&rfr_id=info:sid/sersol:RefinerQuery&rft_val_fmt=info:ofi/fmt:kev:mtx:journal&SS_ReferentFormat=JournalFormat&SS_formatselector=radio&rft.genre=article&SS_genreselector=1&rft.aulast=Earl&rft.aufirst=R&rft.date=2003-04&rft.issue=4&rft.volume=84&SS_doi=10.1016/S1537-5110(03)00004-7&rft.atitle=Soil+Factors+and+their+Influence+on+Within-field+Crop+Variability%2C+Part+I%3A+Field+Observation+of+Soil+Variation&rft.spage=425&rft.title=Biosystems+engineering&rft.issn=1537-5110&SS_issnh=1537-5110&rft.isbn=&SS_isbnh=&rft.au=Earl%2C+R&rft.pub=Academic+Press¶mdict=fr-fr
Ces métadonnées encapsulées sont ensuite envoyées au script php ci-dessus.
Ce dernier va alors parser ces dernières et les utiliser pour interroger le webservice de BASE Search
La réponse retournée est en json, il me suffit alors d'exploiter ce flux de données dans la page de mon résolveur.
Le script Javascript (requête ajax) :