1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* citeproc-php |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/seboettg/citeproc-php for the source repository |
6
|
|
|
* @copyright Copyright (c) 2017 Sebastian Böttger. |
7
|
|
|
* @license https://opensource.org/licenses/MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Seboettg\CiteProc\Util; |
11
|
|
|
|
12
|
|
|
use Seboettg\CiteProc\CiteProc; |
13
|
|
|
use stdClass; |
14
|
|
|
|
15
|
|
|
class CiteProcHelper |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Applies additional functions for markup extension |
20
|
|
|
* |
21
|
|
|
* @param stdClass $dataItem the actual item |
22
|
|
|
* @param string $valueToRender value the has to apply on |
23
|
|
|
* @param string $renderedText actual by citeproc rendered text |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
public static function applyAdditionMarkupFunction($dataItem, $valueToRender, $renderedText) |
27
|
|
|
{ |
28
|
|
|
$markupExtension = CiteProc::getContext()->getMarkupExtension(); |
29
|
|
|
if (array_key_exists($valueToRender, $markupExtension)) { |
30
|
|
|
if (is_array($markupExtension[$valueToRender]) && array_key_exists('function', $markupExtension[$valueToRender])) { |
31
|
|
|
$function = $markupExtension[$valueToRender]['function']; |
32
|
|
|
} else { |
33
|
|
|
$function = $markupExtension[$valueToRender]; |
34
|
|
|
} |
35
|
|
|
if (is_callable($function)) { |
36
|
|
|
$renderedText = $function($dataItem, $renderedText); |
37
|
|
|
} |
38
|
|
|
} elseif (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) { |
39
|
|
|
if (array_key_exists($valueToRender, $markupExtension[$mode])) { |
40
|
|
|
if (is_array($markupExtension[$mode][$valueToRender]) && array_key_exists('function', $markupExtension[$mode][$valueToRender])) { |
41
|
|
|
$function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]['function']; |
42
|
|
|
} else { |
43
|
|
|
$function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]; |
44
|
|
|
} |
45
|
|
|
if (is_callable($function)) { |
46
|
|
|
$renderedText = $function($dataItem, $renderedText); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
return $renderedText; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array $array |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public static function cloneArray(array $array) |
58
|
|
|
{ |
59
|
|
|
$newArray = []; |
60
|
|
|
foreach ($array as $key => $value) { |
61
|
|
|
$newArray[$key] = clone $value; |
62
|
|
|
} |
63
|
|
|
return $newArray; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param stdClass $dataItem the actual item |
68
|
|
|
* @param string $valueToRender value the has to apply on |
69
|
|
|
* @return bool |
70
|
|
|
*/ |
71
|
|
|
public static function isUsingAffixesByMarkupExtentsion($dataItem, $valueToRender) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$markupExtension = CiteProc::getContext()->getMarkupExtension(); |
74
|
|
|
if (array_key_exists($valueToRender, $markupExtension)) { |
75
|
|
|
if (is_array($markupExtension[$valueToRender]) && array_key_exists('affixes', $markupExtension[$valueToRender])) { |
76
|
|
|
return $markupExtension[$valueToRender]['affixes']; |
77
|
|
|
} |
78
|
|
|
} elseif (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) { |
79
|
|
|
if (array_key_exists($valueToRender, $markupExtension[$mode])) { |
80
|
|
|
if (is_array($markupExtension[$mode][$valueToRender]) && array_key_exists('affixes', $markupExtension[$mode][$valueToRender])) { |
81
|
|
|
return CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]['affixes']; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return false; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.