-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcitoid_ref.php
47 lines (44 loc) · 1.14 KB
/
citoid_ref.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
include_once 'reference.php';
/**
*
*/
class citoidRef extends reference
{
const CITOID = 'https://en.wikipedia.org/api/rest_v1/data/citation/wikibase/';
function __construct($url)
{
if(filter_var($url, FILTER_VALIDATE_URL)){
$authors = array();
$test = get_headers($url, 1)[0];
if ($test != 'HTTP/1.1 404 Not Found'){
self::setURL($url);
$response = file_get_contents(self::CITOID.urlencode($url));
$response = json_decode($response,true);
if (count($response) == 1){
$response = $response[0];
// echo json_encode($response);die;
if (isset($response['language'])){
self::setLanguage($response['language']);
}
if (isset($response['title'])){
self::setTitle($response['title']);
}
if (isset($response["creators"])){
foreach ($response['creators'] as $value) {
$author = trim(strip_tags($value['firstName']." ".$value['lastName']));
if (!strtotime($author)){
$authors[] = $author;
}
}
}
self::setAuthors($authors);
if (isset($response['date'])){
self::setPubDate($response['date']);
}
}
}
}
}
}
?>