|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* citeproc-php |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://github.com/seboettg/citeproc-php for the source repository |
|
6
|
|
|
* @copyright Copyright (c) 2016 Sebastian Böttger. |
|
7
|
|
|
* @license https://opensource.org/licenses/MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Seboettg\CiteProc\Style; |
|
11
|
|
|
|
|
12
|
|
|
use Seboettg\CiteProc\CiteProc; |
|
13
|
|
|
use Seboettg\CiteProc\Config\RenderingMode; |
|
14
|
|
|
use Seboettg\CiteProc\Data\DataList; |
|
15
|
|
|
use Seboettg\CiteProc\Exception\InvalidStylesheetException; |
|
16
|
|
|
use Seboettg\CiteProc\Rendering\Layout; |
|
17
|
|
|
use Seboettg\CiteProc\Root\Root; |
|
18
|
|
|
use Seboettg\CiteProc\Style\Options\BibliographyOptions; |
|
19
|
|
|
use Seboettg\CiteProc\Style\Options\NameOptions; |
|
20
|
|
|
use Seboettg\CiteProc\Style\Sort\Sort; |
|
21
|
|
|
use SimpleXMLElement; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class Bibliography |
|
25
|
|
|
* |
|
26
|
|
|
* The cs:bibliography element describes the formatting of bibliographies, which list one or more bibliographic sources. |
|
27
|
|
|
* The required cs:layout child element describes how each bibliographic entry should be formatted. cs:layout may be |
|
28
|
|
|
* preceded by a cs:sort element, which can be used to specify how references within the bibliography should be sorted |
|
29
|
|
|
* (see Sorting). |
|
30
|
|
|
* |
|
31
|
|
|
* @package Seboettg\CiteProc |
|
32
|
|
|
* |
|
33
|
|
|
* @author Sebastian Böttger <[email protected]> |
|
34
|
|
|
*/ |
|
35
|
|
|
class Bibliography extends StyleElement |
|
36
|
|
|
{ |
|
37
|
|
|
|
|
38
|
|
|
/** @var BibliographyOptions */ |
|
39
|
|
|
private $bibliographyOptions; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param SimpleXMLElement $node |
|
43
|
|
|
* @param Root $parent |
|
44
|
|
|
* @return Bibliography |
|
45
|
|
|
* @throws InvalidStylesheetException |
|
46
|
|
|
*/ |
|
47
|
87 |
|
public static function factory(SimpleXMLElement $node, Root $parent): Bibliography |
|
48
|
|
|
{ |
|
49
|
87 |
|
$nameOptions = NameOptions::updateNameOptions($node); |
|
50
|
87 |
|
CiteProc::getContext()->setNameOptions($nameOptions, RenderingMode::BIBLIOGRAPHY()); |
|
51
|
|
|
/* cs:citation and cs:bibliography may include a cs:sort child element before the cs:layout element to |
|
52
|
|
|
* specify the sorting order of respectively cites within citations, and bibliographic entries within |
|
53
|
|
|
* the bibliography. In the absence of cs:sort, cites and bibliographic entries appear in the order in |
|
54
|
|
|
* which they are cited. |
|
55
|
|
|
*/ |
|
56
|
|
|
//$sorting = new Sort($node->children()['sort']); |
|
57
|
87 |
|
$sorting = Sort::factory($node->sort); |
|
58
|
87 |
|
CiteProc::getContext()->setSorting(RenderingMode::BIBLIOGRAPHY(), $sorting); |
|
59
|
|
|
|
|
60
|
87 |
|
$bibliographyOptions = BibliographyOptions::factory($node); |
|
61
|
87 |
|
CiteProc::getContext()->setBibliographySpecificOptions($bibliographyOptions); |
|
62
|
|
|
|
|
63
|
87 |
|
$bibliography = new Bibliography($nameOptions, $bibliographyOptions); |
|
64
|
87 |
|
$layout = Layout::factory($node->layout); |
|
65
|
87 |
|
if (null !== $layout) { |
|
66
|
87 |
|
$layout->setParent($bibliography); |
|
67
|
87 |
|
$layout->setSorting($sorting); |
|
68
|
87 |
|
$layout->setStyleOptions($bibliographyOptions); |
|
69
|
|
|
} |
|
70
|
87 |
|
$bibliography->setLayout($layout); |
|
71
|
87 |
|
$bibliography->setParent($parent); |
|
72
|
87 |
|
return $bibliography; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Bibliography constructor. |
|
77
|
|
|
* @param NameOptions $nameOptions |
|
78
|
|
|
* @param BibliographyOptions $bibliographyOptions |
|
79
|
|
|
*/ |
|
80
|
87 |
|
protected function __construct(NameOptions $nameOptions, BibliographyOptions $bibliographyOptions) |
|
81
|
|
|
{ |
|
82
|
87 |
|
$this->nameOptions = $nameOptions; |
|
83
|
87 |
|
$this->bibliographyOptions = $bibliographyOptions; |
|
84
|
87 |
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param array|DataList $data |
|
88
|
|
|
* @param int|null $citationNumber |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
80 |
|
public function render($data, $citationNumber = null) |
|
92
|
|
|
{ |
|
93
|
80 |
|
$subsequentAuthorSubstitute = $this->bibliographyOptions->getSubsequentAuthorSubstitute(); |
|
94
|
|
|
|
|
95
|
80 |
|
$subsequentAuthorSubstituteRule = $this->bibliographyOptions->getSubsequentAuthorSubstituteRule(); |
|
96
|
|
|
|
|
97
|
80 |
|
if ($subsequentAuthorSubstitute !== null && !empty($subsequentAuthorSubstituteRule)) { |
|
98
|
13 |
|
CiteProc::getContext() |
|
99
|
13 |
|
->getCitationData() |
|
100
|
13 |
|
->setSubsequentAuthorSubstitute($subsequentAuthorSubstitute); |
|
101
|
13 |
|
CiteProc::getContext() |
|
102
|
13 |
|
->getCitationData() |
|
103
|
13 |
|
->setSubsequentAuthorSubstituteRule($subsequentAuthorSubstituteRule); |
|
104
|
|
|
} |
|
105
|
80 |
|
return $this->layout->render($data, $citationNumber); |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|