-
Notifications
You must be signed in to change notification settings - Fork 4
/
doi_csl.php
122 lines (110 loc) · 3.94 KB
/
doi_csl.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
$doi = (isset($_GET["doi"]) && $_GET["doi"] != "" ? $_GET["doi"] : "10.1037/0022-3514.65.6.1190");
$debug = (isset($_GET["debug"]) ? true : false);
$selected_style = (isset($_GET["style"]) && $_GET["style"] != "" ? $_GET["style"] : "council-of-science-editors");
function doi_url($doi)
{
return "http://dx.doi.org/" . $doi;
// return "http://data.crossref.org/" . $doi;
}
function get_curl($url, $selected_style)
{
$curl = curl_init();
$header[0] = "Accept: text/x-bibliography; style=" . $selected_style;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com');
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
$citation_string = curl_exec($curl);
curl_close($curl);
return $citation_string;
}
function format_citation($citation_string, $selected_style)
{
$formatted_citation = "<p class=\"" . $selected_style . "\">";
$formatted_citation .= $citation_string;
$formatted_citation .= "</p>";
return $formatted_citation;
}
$style_array = [
"american-chemical-society" => "ACS",
"american-medical-association" => "AMA",
"apa" => "APA",
"american-physics-society" => "APS",
"american-sociological-association" => "ASA",
"chicago-annotated-bibliography" => "Chicago",
"council-of-science-editors" => "CSE",
"ieee" => "IEEE",
"mla" => "MLA"
];
function select_styles($style_array, $selected_style)
{
$style_string = "<select name=\"style\">\n";
foreach ($style_array as $style => $name) {
$style_string .= " <option value=\"$style\"";
if ($selected_style == $style) { $style_string .= " selected"; }
$style_string .= ">$name</option>\n";
}
$style_string .= "</select>\n";
return $style_string;
}
$doi_url = doi_url($doi);
$citation_string = get_curl($doi_url, $selected_style);
$formatted_citation = format_citation($citation_string, $selected_style);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DOI Citation Generator</title>
<style>
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }
html { font-size: 1em; margin: 2em; font-family: Verdana; }
input[type="text"] { width: 20em; }
h3 { text-indent: 0.75em; font-weight: normal; }
.ama, .chicago { max-width: 65%; }
.nav { max-width: 25%; float: right; font-size: 0.85em; }
.hangingindent { margin-left: 1em; padding-left: 2em ; text-indent: -2em ; }
ol.chicago li { text-indent: 2em; }
.json_array { }
.cf:before, .cf:after { content: " "; display: table; }
.cf:after { clear: both; }
.cf { *zoom: 1; }
</style>
</head>
<body>
<div class="nav">
<h2>Examples</h2>
<div><a href="?doi=10.1037%2F0022-3514.65.6.1190<?php
echo "&style=$selected_style";
?>">10.1037/0022-3514.65.6.1190</a></div>
<div><a href="?doi=10.1016%2Fj.jip.2014.01.003<?php
echo "&style=$selected_style";
?>">10.1016/j.jip.2014.01.003</a></div>
<div><a href="?doi=10.1155%2F2014%2F683757<?php
echo "&style=$selected_style";
?>">10.1155/2014/683757</a></div>
<div><a href="?doi=10.1016%2Fj.quaint.2013.12.014<?php
echo "&style=$selected_style";
?>">10.1016/j.quaint.2013.12.014</a></div>
</div>
<h1>DOI → CSL Citation</h1>
<form method="get" action="">
<input type="text" name="doi" value="<?php echo $doi ?>">
<input type="submit" value="Search DOI">
<?php echo select_styles($style_array, $selected_style); ?>
</form>
<section class="cf">
<?php echo $formatted_citation . "\n"; ?>
<p>
<small>
Form uses selected <a href="https://github.com/citation-style-language/styles" target="_blank">Citation Style Language</a> style profiles to format citations.
</small>
</p>
</section>
</body>
</html>