Exemplo n.º 1
0
function display_formatted_citation($id, $style)
{
    global $config;
    global $couch;
    $reference = null;
    // grab JSON from CouchDB
    $couch_id = $id;
    $resp = $couch->send("GET", "/" . $config['couchdb_options']['database'] . "/" . urlencode($couch_id));
    $reference = json_decode($resp);
    if (isset($reference->error)) {
        $html = "Oops";
    } else {
        if ($style == 'ris') {
            $html = '<pre>' . reference_to_ris($reference) . '</pre>';
        } else {
            $citeproc_obj = reference_to_citeprocjs($reference);
            $json = json_encode($citeproc_obj);
            $citeproc_obj = json_decode($json);
            //echo $json;
            $cslfilename = dirname(__FILE__) . '/style/';
            switch ($style) {
                case 'apa':
                case 'bibtex':
                case 'wikipedia':
                case 'zookeys':
                case 'zootaxa':
                    $cslfilename .= $style . '.csl';
                    break;
                default:
                    $cslfilename .= 'apa.csl';
                    break;
            }
            $csl = file_get_contents($cslfilename);
            $citeproc = new citeproc($csl);
            $html = $citeproc->render($citeproc_obj, 'bibliography');
        }
    }
    echo $html;
}
Exemplo n.º 2
0
//			$ordered[$key] = $array[$key];
//			unset($array[$key]);
//		}
//	}
//	return $ordered + $array;
//}
//$new_array = sortArrayByArray($input_data, $sort);
//print_r($sort); exit();
//print_r($new_array); exit();
//array_multisort($sortarray, SORT_ASC, SORT_STRING);
//print_r($sortarray); exit();
//$data = $input_data;
#print_r($input_data); exit();
//print_r(json_decode(utf8_encode($input['input'])));exit();
// CSL-Prozessor instanziieren
$citeproc = new citeproc($csl_data);
// Fuer jeden Metadatensatz ein gerenderter Zitationsstring
foreach ($input_data as $data) {
    //echo $citeproc->render($data).'<br>';
    $data->csl_citations[$input['style']] = $citeproc->render($data);
    // print_r($data->csl_citations[$input['style']]);
    // if ('html' !== $input['format']) {
    if ('html' === $input['format']) {
        $ersetzung['bold'] = '__HTML_STRONG_START__$1__HTML_STRONG_END__';
        $ersetzung['italic'] = '__HTML_EM_START__$1__HTML_EM_END__';
        $ersetzung['normal'] = '$1';
        $ersetzung['div'] = '__HTML_DIV_START__$1__HTML_DIV_MID__$2__HTML_DIV_END__';
        $ersetzung['span'] = '__HTML_SPAN_START__$1__HTML_SPAN_MID__$2__HTML_SPAN_END__';
    } elseif ('plain' === $input['format']) {
        $ersetzung['italic'] = '/$1/';
        $ersetzung['bold'] = '*$1*';
Exemplo n.º 3
0
function CiteReferenceRenderParserFunction($parser, $ref_key, $ref_style = 'b')
{
    global $wgWikiCiteLinkerURL;
    global $wgWikiCiteZoteroGroupID;
    $link_data = json_decode(file_get_contents($wgWikiCiteLinkerURL . '/wikicite_api.php?wiki_id=' . $ref_key));
    //$parser->disableCache();
    // The input parameters are wikitext with templates expanded.
    // The output should be wikitext too.
    //
    $output = "*  ";
    if ($ref_style == "b") {
        $data = json_decode(file_get_contents('https://api.zotero.org/groups/' . $wgWikiCiteZoteroGroupID . '/items/' . $link_data->{'zotero_id'}));
        $first = True;
        foreach ($data->{'data'}->{'creators'} as $author) {
            if (!$first) {
                $output .= ", ";
            }
            $first = False;
            if (!property_exists($author, "lastName") || !property_exists($author, "firstName")) {
                if (property_exists($author, "name")) {
                    $output .= $author->{'name'} . " ";
                } else {
                    $output .= "Unknown author ";
                }
            } else {
                $output .= $author->{'lastName'} . ", " . $author->{'firstName'} . " ";
            }
        }
        $output .= " (";
        $output .= $data->{'data'}->{'date'};
        $output .= "). ";
        $output .= $data->{'data'}->{'title'};
        $output .= "\n";
    } else {
        if (!property_exists($link_data, 'zotero_id')) {
            $output .= $ref_key . " could not be found";
        } else {
            $data = json_decode(file_get_contents('https://api.zotero.org/groups/' . $wgWikiCiteZoteroGroupID . '/items/' . $link_data->{'zotero_id'} . '?format=csljson'));
            if (!property_exists($data->items[0]->issued, "date-parts") && property_exists($data->items[0]->issued, "raw")) {
                if (is_numeric($data->items[0]->issued->raw)) {
                    $data->items[0]->issued->{'date-parts'}[0][0] = $data->items[0]->issued->raw;
                } else {
                    $data->items[0]->issued->{'date-parts'}[0][0] = date_parse($data->items[0]->issued->raw)["year"];
                    $data->items[0]->issued->{'date-parts'}[0][1] = date_parse($data->items[0]->issued->raw)["month"];
                }
            }
            $ref_style = preg_replace("([^a-zA-Z-])", '', $ref_style);
            $csl = file_get_contents(__DIR__ . '/csl/' . $ref_style . '.csl');
            $citeproc = new citeproc($csl);
            $output .= $citeproc->render($data->items[0], "bibliography");
        }
    }
    return array($output, 'noparse' => false);
    //    return $output;
}
<?php

include './CiteProc.php';
$dir_handle = opendir('./tests');
while (FALSE !== ($filename = readdir($dir_handle))) {
    if (!is_dir('./tests/' . $filename) && $filename[0] != '.') {
        $json_data = file_get_contents('./tests/' . $filename);
        $json_data = substr($json_data, strpos($json_data, '*/{') + 2);
        $test_data = json_decode($json_data);
        if ($test_data->mode != 'bibliography') {
            $citeproc = new citeproc($test_data->csl);
            $input_data = (array) $test_data->input;
            $count = count($input_data);
            $output = '';
            foreach ($input_data as $data) {
                $output .= $citeproc->render($data, $test_data->mode);
            }
            //print '<html><body>';
            if ($output != $test_data->result) {
                print './tests/' . $filename . " FAILED\n";
                print $output . " !=  <br>\n" . $test_data->result . "<br><br>\n\n";
            } else {
                print './tests/' . $filename . " PASSED\n";
            }
        }
    }
}
//print '</body></html>';
//print($csl_parse);