/** * 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 ''; }
/** * Render the element. * * @param string $data * @return string */ public function render($data) { switch ($this->variable) { case 'author': case 'collection-editor': case 'composer': case 'container-author': case 'director': case 'editor': case 'editorial-director': case 'illustrator': case 'interviewer': case 'original-author': case 'recipient': case 'reviewed-author': case 'translator': $name = new Name(new \SimpleXMLElement('<name form="long" name-as-sort-order="all"/>')); return $name->render(Container::getData()->getVariable($this->variable)); break; case 'accessed': case 'container': case 'event-date': case 'issued': case 'original-date': case 'submitted': // 00000000 represent the first date and if existing a second date of a date range $format = new Format(); if ($format->format($this->variable) == true) { $data = $format->getData(); $first = $this->formatDate($data[0]); $second = '00000000'; if (isset($data[1]) == true) { $second = $this->formatDate($data[1]); if ($second < $first) { return $second . $first; } return $first . $second; } return $first . $second; } // put empty dates in bibliographies at the end if (Container::getContext()->getName() == 'bibliography') { return ''; } return '0000000000000000'; break; case 'chapter-number': case 'collection-number': case 'edition': case 'issue': case 'number': case 'number-of-pages': case 'number-of-volumes': case 'volume': return (int) Container::getData()->getVariable($this->variable); break; default: return preg_replace('/(<.*?>)(.*?)(<\\/.*?>)/', '$2', Container::getData()->getVariable($this->variable)); break; } }
/** * Parses the date-values. * @return boolean */ private function formatDate() { $format = new Format(); if ($format->format($this->variable) == true) { $this->data = $format->getData(); return true; } return false; }