56 private $plural =
"contextual";
65 foreach ($node->attributes() as $attribute) {
66 switch ($attribute->getName()) {
68 $this->variable = (string) $attribute;
71 $this->form = (string) $attribute;
74 $this->plural = (string) $attribute;
79 $this->initFormattingAttributes($node);
80 $this->initAffixesAttributes($node);
81 $this->initTextCaseAttributes($node);
89 public function render($data, $citationNumber =
null)
91 $lang = (isset($data->language) && $data->language !=
'en') ? $data->language :
'en';
94 $variables = explode(
' ', $this->variable);
95 $form = !empty($this->form) ? $this->form :
'long';
98 if ($this->variable ===
"editortranslator") {
99 if (isset($data->editor) && isset($data->translator)) {
100 $plural = $this->
getPlural($data, $plural,
"editortranslator");
102 $pluralForm = $term->{$plural};
103 if (!empty($pluralForm)) {
108 foreach ($variables as $variable) {
109 if (isset($data->{$variable})) {
110 $plural = $this->
getPlural($data, $plural, $variable);
112 $pluralForm = $term->{$plural};
113 if (!empty($data->{$variable}) && !empty($pluralForm)) {
121 return $this->formatting($text, $lang);
129 private function evaluateStringPluralism($data, $variable)
131 $str = isset($data->{$variable}) ? $data->{$variable} :
'';
136 $pageRegex =
"/([a-zA-Z]*)([0-9]+)\s*(?:–|-)\s*([a-zA-Z]*)([0-9]+)/";
137 $err = preg_match($pageRegex, $str, $m);
138 if ($err !==
false &&
count($m) == 0) {
140 } elseif ($err !==
false &&
count($m)) {
141 $plural =
'multiple';
145 if (is_numeric($str)) {
146 return $str > 1 ?
'multiple' :
'single';
156 public function setVariable($variable)
158 $this->variable = $variable;
167 protected function getPlural($data, $plural, $variable)
170 if ($variable ===
"editortranslator" && isset($data->editor)) {
171 $var = $data->editor;
173 $var = $data->{$variable};
175 if (((!isset($this->plural) || empty($plural))) && !empty($var)) {
176 if (is_array($var)) {
177 $count = count($var);
181 } elseif ($count > 1) {
182 $plural =
'multiple';
187 return $this->evaluateStringPluralism($data, $variable);
190 if ($this->plural !=
"always") {
191 $plural = $this->evaluateStringPluralism($data, $variable);
219 protected function formatting($text, $lang)
224 if ($this->stripPeriods) {
225 $text = str_replace(
'.',
'', $text);
228 $text = preg_replace(
"/\s&\s/",
" & ", $text);
229 $text = $this->format($this->applyTextCase($text, $lang));
230 return $this->addAffixes($text);
236 protected function defaultPlural()
239 switch ($this->plural) {
244 $plural =
'multiple';