15 use Seboettg\CiteProc\Styles\DelimiterTrait;
42 ConsecutivePunctuationCharacterTrait;
54 private $delimiter =
"";
61 private $renderedChildsWithVariable = [];
71 public function __construct(SimpleXMLElement $node, $parent)
73 $this->parent = $parent;
75 foreach ($node->children() as $child) {
78 $this->initDisplayAttributes($node);
79 $this->initAffixesAttributes($node);
80 $this->initDelimiterAttributes($node);
81 $this->initFormattingAttributes($node);
89 public function render($data, $citationNumber =
null)
92 $terms = $variables = $haveVariables = $elementCount = 0;
93 foreach ($this->children as $child) {
96 if (($child instanceof
Text)
97 && ($child->getSource() ==
'term'
98 || $child->getSource() ==
'value')
103 if (($child instanceof
Label)) {
106 if (method_exists($child,
"getSource") && $child->getSource() ==
'variable'
107 && !empty($child->getVariable()) && $child->getVariable() !=
"date"
108 && !empty($data->{$child->getVariable()})
113 $text = $child->render($data, $citationNumber);
114 $delimiter = $this->delimiter;
116 if ($delimiter && ($elementCount < count($this->children))) {
119 $stext = strip_tags(trim($text));
120 if ((strrpos($stext, $delimiter[0]) + 1) == strlen($stext) && strlen($stext) > 1) {
121 $text = str_replace($stext,
'----REPLACE----', $text);
122 $stext = substr($stext, 0, -1);
123 $text = str_replace(
'----REPLACE----', $stext, $text);
126 $textParts[] = $text;
128 if (method_exists($child,
"getSource") && $child->getSource() ==
'variable'
132 ) && $child->getVariable() !=
"date" && !empty($child->getVariable()))
137 if (method_exists($child,
"getSource") && $child->getSource() ==
'macro') {
142 return $this->
formatting($textParts, $variables, $haveVariables, $terms);
148 public function getParent()
150 return $this->parent;
160 protected function formatting($textParts, $variables, $haveVariables, $terms)
162 if (empty($textParts)) {
166 if ($variables && !$haveVariables) {
170 if (count($textParts) == $terms) {
177 return $this->wrapDisplayBlock($this->addAffixes($this->format(($text))));
186 public function hasDelimiter()
188 return !empty($this->delimiter);
194 public function getDelimiter()
196 return $this->delimiter;