|
|
|
|
@ -62,14 +62,32 @@ class CiteprocPhpInline extends BibCiteProcessorBase implements BibCiteProcessor
|
|
|
|
|
*/ |
|
|
|
|
public function render($data, $csl, $lang) { |
|
|
|
|
$cite_proc = new CiteProc($csl, $lang); |
|
|
|
|
$mode = !empty($data['mode']) ? $data['mode'] : NULL; |
|
|
|
|
|
|
|
|
|
if (!$data instanceof \stdClass) { |
|
|
|
|
$data = json_decode(json_encode($data)); |
|
|
|
|
// Default to bibliography when no mode is specified. |
|
|
|
|
$mode = !empty($data['mode']) ? $data['mode'] : 'bibliography'; |
|
|
|
|
|
|
|
|
|
// CiteProc expects an array of citation objects. |
|
|
|
|
if ($data instanceof \stdClass) { |
|
|
|
|
$data = [$data]; |
|
|
|
|
} |
|
|
|
|
elseif (is_array($data)) { |
|
|
|
|
if (array_is_list($data)) { |
|
|
|
|
$data = array_map( |
|
|
|
|
static fn($item) => is_array($item) |
|
|
|
|
? json_decode(json_encode($item)) |
|
|
|
|
: $item, |
|
|
|
|
$data |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
$data = [json_decode(json_encode($data))]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($data)) { |
|
|
|
|
return $cite_proc->render($data, $mode); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|