/** * Retrieve a variable from the actual entry. * * @param string $name * @return string|integer|null */ public function getVariable($name) { if (isset($this->data[$this->position]) == true && array_key_exists($name, $this->data[$this->position]) == true) { $return = $this->data[$this->position][$name]; if (Container::getAbbreviation() !== false && Container::getAbbreviation()->get($name, $return) !== null) { return Container::getAbbreviation()->get($name, $return); } return $return; } elseif ($name == 'citation-number') { if (Container::getContext()->in('sort') == true) { // index (starting at 1) of the cited reference in the bibliography (generated by the CSL processor) $number = Container::getData()->getPosition(); if (Container::getContext()->get('sort') == 'descending') { $number = Container::getData()->getLength() - $number; } else { $number++; } $this->setVariable('citation-number', (int) $number); return (int) $number; } else { // return position in bibliography if no citation-number is set return (int) $this->position + 1; } } return null; }
/** * Renders the variable. * * @param string $data * @return string */ public function render($data) { if ($this->form !== '') { $return = Container::getData()->getVariable($this->name . '-' . $this->form); if ($return !== null) { return $return; } if (is_object(Container::getAbbreviation()) == true) { $return = Container::getAbbreviation()->get($this->name, $this->form); } if ($return !== null) { return $return; } } // special cases switch ($this->name) { case 'title-short': $return = Container::getData()->getVariable('shortTitle'); if ($return !== null) { return $return; } break; case 'title': if ($this->form == 'short') { $return = Container::getData()->getVariable('shortTitle'); if ($return !== null) { return $return; } } break; case 'citation-label': $return = Container::getData()->getVariable($this->name); if ($return !== null) { return $return; } // first 4 letters from the first two author family names and last to year digits $authors = Container::getData()->getVariable('author'); $format = new Format(); if (isset($authors[0]['family']) == true && $format->format('issued') == true) { $year = $format->getData(); if (isset($year[0]['year']) == true) { switch (count($authors)) { case 1: $author = substr($authors[0]['family'], 0, 4); break; case 2: $author = substr($authors[0]['family'], 0, 2) . substr($authors[1]['family'], 0, 2); break; default: $author = ''; for ($i = 0; $i < 4; $i++) { if (preg_match('/[A-Z]/', $authors[$i]['family'], $match) == 1) { $author .= $match[0]; } } break; } $length = strlen($year[0]['year']); return $author . substr($year[0]['year'], $length - 2, $length); } } break; case 'page': $format = Container::getContext()->getValue('pageRangeFormat'); if (is_object($format) == true) { return $format->format(Container::getData()->getVariable($this->name)); } break; case 'first-reference-note-number': // number of a preceding note containing the first reference to the item if (Container::getCitationItem()->get('noteIndex') !== null || Container::getCitationItem()->get('index') !== null) { $first = Container::getRendered()->getPositionOfFirstId(Container::getActualId()); if ($first !== null && $first < Container::getRendered()->getLength()) { return $first; } } break; } $return = Container::getData()->getVariable($this->name); if ($return !== null) { return $return; } // retrieve variables form citations if (Container::getContext()->getName() == 'citation' && Container::getCitationItem() !== false) { $return = Container::getCitationItem()->get($this->name); if ($return !== null) { return $return; } } return ''; }