/** * . * * @param string|array $data * @return string|array */ public function render($data) { $variable = Container::getData()->getVariable($this->variable); $isNumeric = new IsNumeric($this->variable); if ($isNumeric->validate() == true) { $variable = $this->formatDelimiter($variable); switch ($this->form) { case 'numeric': $return = $variable; break; case 'ordinal': $return = Ordinal::render($variable); break; case 'long-ordinal': $return = Ordinal::renderLong($variable); break; case 'roman': if (preg_match('/[A-z]/', $variable) == 0) { $return = $this->calcRoman($variable); } else { $return = $variable; } break; } $return = $this->affix->render($return); $return = $this->display->render($return); $return = $this->formating->render($return); return $this->textCase->render($return); } return $variable; }
/** * Render the names. * * @param string|array $data * @return string */ public function render($data) { $returns = array(); $compare = array(); $lastSubstitute = Container::getContext()->getSubstitute()->getVariable(); foreach ($this->variables as $variable) { // don't render if variable is already used as substitute value if ($lastSubstitute === $variable) { return ''; } $names = Container::getData()->getVariable($variable); $content = $this->name->render($names); // et-al if (isset($this->etAl) == true && Container::getContext()->getValue('etAlMin', Container::getContext()->getName()) !== null && Container::getContext()->getValue('etAlMin', Container::getContext()->getName()) <= count($names)) { $content = $this->etAl->render($content); } if ($content !== '') { $compare[$variable] = $content; } // use substitute if ($content == '' && isset($this->substitute) == true) { $content = $this->substitute->render(''); if (Container::getContext()->getSubstitute()->getVariable() !== '') { $variable = Container::getContext()->getSubstitute()->getVariable(); } } if ($content !== '' && isset($this->label) == true && Container::getContext()->in('sort') == false) { $this->label->setVariable($variable); if ($this->labelBeforeName == false) { $content .= $this->label->render($content); } else { $content = $this->label->render($content) . $content; } } if ($content !== '') { $returns[] = $content; } } // The one exception: when the selection consists of "editor" and "translator", and when the contents // of these two name variables is identical, then the contents of only one name variable is rendered. if (in_array('editor', $this->variables) == true && in_array('translator', $this->variables) == true && isset($compare['editor']) == true && $compare['editor'] == $compare['translator']) { $editorTrans = $compare['translator']; if (isset($this->label) == true) { $plural = 'singular'; if (count(Container::getData()->getVariable('editor')) > 1 || count(Container::getData()->getVariable('translator')) > 1) { $plural = 'multiple'; } $this->label->setVariable('editortranslator')->setPlural($plural); $editorTrans .= $this->label->render(''); } $returns = array($editorTrans); } $return = implode($this->delimiter, $returns); // no formatting while author-only is set for actual cite if (Container::getCitationItem() == false || Container::getCitationItem()->get('author-only') == 0 || Container::getCitationItem()->get('author-only') === null) { $return = $this->formatting->render($return); } $return = $this->display->render($return); return $this->affix->render($return); }
/** * Render all child elements of the group. * * @return string */ private function renderGroup() { $toRender = $this->discretionary->getRenderClasses($this->children); $result = array(); foreach ($toRender as $element) { $rendered = $element->render(''); if ($rendered !== '') { $result[] = $rendered; } } $this->renderedGroup = implode($this->delimiter, $result); $this->renderedGroup = preg_replace('/[' . preg_quote($this->delimiter, '/') . '][' . preg_quote($this->delimiter, '/') . ']+/', $this->delimiter, $this->renderedGroup); if (Container::getContext()->in('sort') == true) { return $this->renderedGroup; } $this->renderedGroup = $this->display->render($this->renderedGroup); $this->renderedGroup = $this->formatting->render($this->renderedGroup); $this->renderedGroup = $this->affix->render($this->renderedGroup); return $this->renderedGroup; }
/** * Display text value. * * @param string|array $data * @return string */ public function render($data) { // if part of macro in sorting context, test if text should be rendered if (Container::getContext()->get('renderJust', 'sort') !== null && in_array('', Container::getContext()->get('renderJust', 'sort')) == false) { return ''; } $data = $this->render->render($data); // no formatting while sorting if (Container::getContext()->in('sort') == true) { return $data; } if ($data !== '') { $data = $this->textCase->render($data); $data = $this->stripPeriods->render($data); $data = $this->display->render($data); $data = $this->quotes->render($data); $data = $this->formatting->render($data); } return $this->affix->render($data); }
/** * Renders the date. * * @param string $data * @return string */ public function render($data) { if ($this->formatDate() == false) { return ''; } // for sorting use numeric date if (Container::getContext()->in('sort') == true) { $return = array(); foreach ($this->dateParts as $datePart) { $object = $datePart['datepart']; $return[] = $object->render($this->data[0]); } return implode('', $return); } // enter date context Container::getContext()->enter('date', array('form' => $this->form)); if (count($this->data) == 2) { // date range $result = array(); $delimiter = '–'; $delimiterFrom = $this->partWithMaxDiff(); for ($i = 0; $i < 2; $i++) { $return = array(); foreach ($this->dateParts as $datePart) { $object = $datePart['datepart']; $return[] = $object->render($this->data[$i]); // get special delimiter if ($datePart['name'] == $delimiterFrom && $object->getRangeDelimiter() !== '') { $delimiter = $object->getRangeDelimiter(); } } $result[] = $return; } // drop equal values $length = count($result[0]); for ($i = 0; $i < $length; $i++) { if ($result[0][$i] == $result[1][$i]) { $result[0][$i] = ''; } } $result[0] = trim(implode($this->delimiter, $result[0])); $result[1] = trim(implode($this->delimiter, $result[1])); $value = implode($delimiter, $result); } elseif (isset($this->data[0]['raw']) == true) { // prefer raw date over full date $value = $this->data[0]['raw']; } else { $return = array(); foreach ($this->dateParts as $datePart) { $object = $datePart['datepart']; $return[] = $object->render($this->data[0]); } $value = implode($this->delimiter, $return); // catch non-date dates if ($value == '' && isset($this->data[0]['literal']) == true) { $value = $this->data[0]['literal']; } } if ($value == '') { $value = $this->renderSeason(); } // add year-suffix for disambiguation if ($this->addYearSuffix == true) { $value .= Container::getData()->getVariable('year-suffix'); } $value = $this->affix->render($value); $value = $this->display->render($value); $value = $this->formatting->render($value); $value = $this->textCase->render($value); Container::getContext()->leave(); return $value; }