citations-tools/citations-tools.php

75 lines
1.8 KiB
PHP
Raw Normal View History

2018-02-01 00:19:54 +01:00
<?php
/*
Plugin Name: Citations tools
Description: The plugin add some shortcodes add a link to a paper using the doi code or to resolve doi code and publish a full citation apa formatted.
2018-02-02 14:28:59 +01:00
Version: 0.2.4
2018-02-01 00:19:54 +01:00
Author: Gianluigi Filippelli
Author URI: http://dropseaofulaula.blogspot.it/
2018-02-02 14:28:59 +01:00
Plugin URI: https://github.com/ulaulaman/citations-tools
2018-02-01 00:19:54 +01:00
License: GPLv2 or later
*/
/* ------------------------------------------------------ */
# ---------------------------------------------------------
# doi
2018-02-02 14:28:59 +01:00
add_shortcode('cpdoi', 'cpdoi');
2018-02-01 00:19:54 +01:00
function doi ($atts, $content = null) {
extract(
shortcode_atts(
array(
'code' => null
),
$atts
)
);
$link = '<a href="https://dx.doi.org/'.$code.'/" target="doi">'.$content.'</a>';
return $link;
}
# doi resolve
2018-02-02 14:28:59 +01:00
add_shortcode('cpdoiresolve', 'cpdoiresolve');
2018-02-01 00:19:54 +01:00
function doiresolve ($atts, $content = null) {
extract(
shortcode_atts(
array(
'code' => null,
'arxiv' => null,
'pdfurl' => null
),
$atts
)
);
$fullCitation = null;
$getfile = 'https://search.crossref.org/dois?sort=score&page=1&rows=1&q='.$code;
$jsondata = file_get_contents($getfile);
$array = json_decode($jsondata,true);
$item=$array[0];
$doi = $item['doi'];
$coins = $item['coins'];
$fullCitation =$item['fullCitation'];
$citation = '<p>'.$fullCitation.' doi:<a href="https://dx.doi.org/'.$code.'" target="doi">'.$code.'</a>';
if ( $arxiv <> null )
{$citation = $citation.' (<a href="https://arxiv.org/abs/'.$arxiv.'" target="arxiv">arXiv</a>)';}
else
{$citation = $citation;}
if ( $pdfurl <> null )
{$citation = $citation.' (<a href="'.$pdfurl.'" target="pdf">pdf</a>)';}
else
{$citation = $citation;}
$results = $citation.'</p>';
return $results;
}
/* ------------------------------------------------------ */