citations-tools/citations-tools.php

170 lines
4.0 KiB
PHP
Raw Normal View History

2018-02-01 00:19:54 +01:00
<?php
/*
2020-07-17 12:26:45 +02:00
Plugin Name: Citations tools
2018-02-07 01:11:30 +01:00
Description: Some tools for scientific and editorial bloggers.
2020-07-07 22:52:35 +02:00
Version: 0.3.2
2018-02-01 00:19:54 +01:00
Author: Gianluigi Filippelli
Author URI: http://dropseaofulaula.blogspot.it/
2018-02-07 01:11:30 +01:00
Plugin URI: https://ulaulaman.github.io/citations-tools/
2018-02-01 00:19:54 +01:00
License: GPLv2 or later
*/
/* ------------------------------------------------------ */
# ---------------------------------------------------------
# doi
2018-02-04 13:46:14 +01:00
add_shortcode('ctdoi', 'ctdoi');
2018-02-01 00:19:54 +01:00
2018-02-04 13:46:14 +01:00
function ctdoi ($atts, $content = null) {
2018-02-01 00:19:54 +01:00
extract(
shortcode_atts(
array(
'code' => null
),
$atts
)
);
2018-02-09 12:46:00 +01:00
$link = '<a href="https://dx.doi.org/'.$code.'" target="doi">'.$content.'</a>';
2018-02-01 00:19:54 +01:00
return $link;
}
2018-02-07 01:11:30 +01:00
# doi resolver
2018-02-04 13:46:14 +01:00
add_shortcode('ctdoiresolve', 'ctdoiresolve');
2018-02-01 00:19:54 +01:00
2018-02-04 13:46:14 +01:00
function ctdoiresolve ($atts, $content = null) {
2018-02-01 00:19:54 +01:00
extract(
shortcode_atts(
array(
'code' => null,
'arxiv' => null,
'pdfurl' => null,
'archiveurl' => null
2018-02-01 00:19:54 +01:00
),
$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'];
2018-02-07 01:11:30 +01:00
$citation = '<div class="paperbox">'.$fullCitation.' doi:<a href="https://dx.doi.org/'.$code.'" target="doi">'.$code.'</a>';
2018-02-01 00:19:54 +01:00
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;}
if ( $archiveurl <> null )
{$citation = $citation.' (<a href="'.$archiveurl.'" target="archive">archive.org</a>)';}
else
{$citation = $citation;}
2018-02-07 01:11:30 +01:00
$results = $citation.'</div>';
2018-02-01 00:19:54 +01:00
return $results;
}
2018-02-07 01:11:30 +01:00
# paperdata
add_shortcode('paperdata', 'paperdata');
function paperdata ($atts, $content = null) {
extract(
shortcode_atts(
array(
'auth' => null,
'year' => null,
'title' => null,
'journal' => null,
'vol' => null,
'issue' => null,
'pages' => null,
'code' => null,
'arxiv' => null,
'pdfurl' => null,
'archiveurl' => null
),
$atts
)
);
$fullcitation = null;
if ( $auth <> null )
{$fullcitation = $fullcitation.$auth;}
else
{$fullcitation = $fullcitation;}
if ( $year <> null )
{$fullcitation = $fullcitation.', '.$year;}
else
{$fullcitation = $fullcitation;}
if ( $title <> null )
{$fullcitation = $fullcitation.', '.$title;}
else
{$fullcitation = $fullcitation;}
if ( $journal <> null )
{$fullcitation = $fullcitation.', <em>'.$journal.'</em>';}
else
{$fullcitation = $fullcitation;}
if ( $vol <> null )
{$fullcitation = $fullcitation.', vol.'.$vol;}
else
{$fullcitation = $fullcitation;}
if ( $issue <> null )
{$fullcitation = $fullcitation.', n.'.$issue;}
else
{$fullcitation = $fullcitation;}
if ( $pages <> null )
{$fullcitation = $fullcitation.', pp. '.$pages;}
else
{$fullcitation = $fullcitation;}
$citation = '<div class="paperbox">'.$fullcitation;
if ( $code <> null )
{$citation = $citation.' doi:<a href="https://dx.doi.org/'.$code.'" target="doi">'.$code.'</a>';}
else
{$citation = $citation;}
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;}
if ( $archiveurl <> null )
{$citation = $citation.' (<a href="'.$archiveurl.'" target="archive">archive.org</a>)';}
else
{$citation = $citation;}
$results = $citation.'</div>';
return $results;
}
2018-02-01 00:19:54 +01:00
/* ------------------------------------------------------ */