Created
October 3, 2012 21:47
-
-
Save crstn/3830081 to your computer and use it in GitHub Desktop.
MUSIL publications list
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
<html xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
xmlns:foaf="http://xmlns.com/foaf/0.1/" | |
xmlns:bibo="http://purl.org/ontology/bibo/"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html" /> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> | |
</head> | |
<body> | |
<h1>MUSIL Publications</h1> | |
<?php | |
$query = " | |
prefix dct: <http://purl.org/dc/terms/> | |
prefix bibo: <http://purl.org/ontology/bibo/> | |
prefix foaf: <http://xmlns.com/foaf/0.1/> | |
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | |
SELECT DISTINCT ?publication ?title ?year ?firstAuthor ?secondAuthor ?thirdAuthor ?doi ?pdf WHERE { | |
<http://data.uni-muenster.de/context/cris/organization/musil> foaf:member ?member . | |
?member ^bibo:producer ?publication. | |
?publication dct:title ?title; | |
dct:issued ?year; | |
bibo:authorlist ?authors. | |
?authors rdf:_1 ?fa. | |
?fa foaf:name ?firstAuthor . | |
OPTIONAL {?publication foaf:homepage ?pdf} | |
OPTIONAL {?publication bibo:doi ?doi} | |
OPTIONAL {?authors rdf:_2 ?fb. | |
?fb foaf:name ?secondAuthor .} | |
OPTIONAL {?authors rdf:_3 ?fc. | |
?fc foaf:name ?thirdAuthor .} | |
Filter regex(str(?publication),'http://data.uni-muenster.de/context/cris/publication/') | |
} | |
ORDER BY DESC(?year) ?firstAuthor | |
"; | |
$endpoint = 'http://data.uni-muenster.de/sparql'; | |
// query via cURL, because we have to send the password along: | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $endpoint.'?query='.urlencode($query)); | |
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/sparql-results+json')); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
$response = curl_exec($curl); | |
curl_close($curl); | |
$results = json_decode($response, true); | |
$year = 'x'; | |
if(count($results['results']['bindings']) > 0){ | |
foreach ($results['results']['bindings'] as $index => $result) { | |
if($year != $result['year']['value']){ | |
if($year != 'x'){ | |
echo '</ul>'; | |
} | |
$year = $result['year']['value']; | |
echo '<b>'.$year.'</b><ul>'; | |
} | |
if(isset($result['secondAuthor']) && !isset($result['thirdAuthor'])){ | |
$author = $result['firstAuthor']['value'].' & '.$result['secondAuthor']['value']; | |
}else if (isset($result['secondAuthor']) && isset($result['thirdAuthor'])){ | |
$author = $result['firstAuthor']['value'].' et al.'; | |
}else{ | |
$author = $result['firstAuthor']['value']; | |
} | |
if(isset($result['doi'])){ | |
$details = ' <a href="http://dx.doi.org/'.$result['doi']['value'].'">Details</a>'; | |
}else{ | |
$details = ' <a href="'.$result['publication']['value'].'">Details</a>'; | |
} | |
if(isset($result['pdf'])){ | |
$details .= ' | <a href="'.$result['pdf']['value'].'">PDF</a> '; | |
} | |
echo '<li>'.$author.' <em>'.$result['title']['value'].'</em> ['.$details.']</li>'; | |
} | |
echo '</ul>'; | |
} else { | |
echo 'No results.'; | |
} | |
?> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment