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\Data\DataList; |
14
|
|
|
use Seboettg\CiteProc\Exception\InvalidStylesheetException; |
15
|
|
|
use Seboettg\CiteProc\Root\Root; |
16
|
|
|
use Seboettg\CiteProc\Style\Options\BibliographyOptions; |
17
|
|
|
use SimpleXMLElement; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Bibliography |
21
|
|
|
* |
22
|
|
|
* The cs:bibliography element describes the formatting of bibliographies, which list one or more bibliographic sources. |
23
|
|
|
* The required cs:layout child element describes how each bibliographic entry should be formatted. cs:layout may be |
24
|
|
|
* preceded by a cs:sort element, which can be used to specify how references within the bibliography should be sorted |
25
|
|
|
* (see Sorting). |
26
|
|
|
* |
27
|
|
|
* @package Seboettg\CiteProc |
28
|
|
|
* |
29
|
|
|
* @author Sebastian Böttger <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class Bibliography extends StyleElement |
32
|
|
|
{ |
33
|
|
|
private $node; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Bibliography constructor. |
37
|
|
|
* @param SimpleXMLElement $node |
38
|
|
|
* @param Root $parent |
39
|
|
|
* @throws InvalidStylesheetException |
40
|
|
|
*/ |
41
|
75 |
|
public function __construct(SimpleXMLElement $node, Root $parent) |
42
|
|
|
{ |
43
|
75 |
|
parent::__construct($node, $parent); |
44
|
75 |
|
$this->node = $node; |
45
|
75 |
|
$bibliographyOptions = new BibliographyOptions($node); |
46
|
75 |
|
CiteProc::getContext()->setBibliographySpecificOptions($bibliographyOptions); |
47
|
75 |
|
$this->initInheritableNameAttributes($node); |
48
|
75 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param array|DataList $data |
52
|
|
|
* @param int|null $citationNumber |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
68 |
|
public function render($data, $citationNumber = null) |
|
|
|
|
56
|
|
|
{ |
57
|
68 |
|
if (!$this->attributesInitialized) { |
58
|
|
|
$this->initInheritableNameAttributes($this->node); |
59
|
|
|
} |
60
|
68 |
|
$subsequentAuthorSubstitute = CiteProc::getContext() |
61
|
68 |
|
->getBibliographySpecificOptions() |
62
|
68 |
|
->getSubsequentAuthorSubstitute(); |
63
|
|
|
|
64
|
68 |
|
$subsequentAuthorSubstituteRule = CiteProc::getContext() |
65
|
68 |
|
->getBibliographySpecificOptions() |
66
|
68 |
|
->getSubsequentAuthorSubstituteRule(); |
67
|
|
|
|
68
|
68 |
|
if ($subsequentAuthorSubstitute !== null && !empty($subsequentAuthorSubstituteRule)) { |
69
|
12 |
|
CiteProc::getContext() |
70
|
12 |
|
->getCitationItems() |
71
|
12 |
|
->setSubsequentAuthorSubstitute($subsequentAuthorSubstitute); |
72
|
12 |
|
CiteProc::getContext() |
73
|
12 |
|
->getCitationItems() |
74
|
12 |
|
->setSubsequentAuthorSubstituteRule($subsequentAuthorSubstituteRule); |
75
|
|
|
} |
76
|
68 |
|
return $this->layout->render($data, $citationNumber); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|