/** * . * * @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; }
/** * Apply the formatting options on a date/date-part element. * * @param string $value * @return string */ protected function format($value) { $value = $this->formatting->render($value); $value = $this->textCase->render($value); // Attributes for affixes are allowed, unless cs:date calls a localized date format if (Container::getContext()->get('form', 'date') !== '') { return $value; } return $this->affix->render($value); }
/** * Renders the name part. * * @param array $data * @return string */ public function render($data) { $isInverted = $this->isInverted($data); if ($this->name == 'given') { if (isset($data['given']) == true) { $data['given'] = $this->formating->render($data['given']); $data['given'] = $this->textCase->render($data['given']); } if (isset($data['dropping-particle']) == true) { $data['dropping-particle'] = $this->formating->render($data['dropping-particle']); $data['dropping-particle'] = $this->textCase->render($data['dropping-particle']); } // Affixes surround the "given" name-part, enclosing any demoted name particles for inverted names. $return = array(); $found = false; foreach ($data as $name => $value) { if ($name == 'given') { $return[] = $value; $found = true; } elseif ($found == true && $isInverted == true && ($name == 'non-dropping-particle' || $name == 'dropping-particle')) { $return[] = $value; } } return $this->affix->render(implode(' ', $return)); } else { if (isset($data['family']) == true) { $data['family'] = $this->formating->render($data['family']); $data['family'] = $this->textCase->render($data['family']); } if (isset($data['non-dropping-particle']) == true) { $data['non-dropping-particle'] = $this->formating->render($data['non-dropping-particle']); $data['non-dropping-particle'] = $this->textCase->render($data['non-dropping-particle']); } // Affixes surround the "family" name-part, enclosing any preceding name particles, as well as // the "suffix" name-part for non-inverted names. $return = array(); $found = false; foreach ($data as $name => $value) { if ($found == false && $isInverted == false && ($name == 'non-dropping-particle' || $name == 'dropping-particle')) { $return[] = $value; } elseif ($found == true && $isInverted == false && $name == 'suffix') { $return[] = $value; } elseif ($name == 'family') { $return[] = $value; $found = true; } } return $this->affix->render(implode(' ', $return)); } }
/** * 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); }
/** * Renders the label. * * @param string|array $data * @return string * @throws \ErrorException If the variable parameter is not set */ public function render($data) { if (isset($this->variable) == false) { throw new \ErrorException('variable is not set!'); } $content = Container::getData()->getVariable($this->variable); $variable = $this->variable; if ($this->variable == 'locator') { // Must be accompanied in the input data by a label indicating the locator type, which determines which // term is rendered by cs:label when the "locator" variable is selected if (is_object(Container::getCitationItem()) == true && Container::getCitationItem()->get('label') !== null) { $variable = Container::getCitationItem()->get('label'); $content = Container::getCitationItem()->get('locator'); } else { return ''; } } // The term is only rendered if the selected variable is non-empty. if ($content == '' && $variable !== 'editortranslator') { return ''; } $plural = 'single'; switch ($this->plural) { case 'contextual': if (is_array($content) == true) { if (count($content) > 1) { $plural = 'multiple'; } } elseif (($this->variable == 'number-of-pages' || $this->variable == 'number-of-volumes') && preg_match_all('/([0-9])/', $content) > 1) { $plural = 'multiple'; } elseif (preg_match('/^[0-9]+$/', $content, $match) == 0) { $plural = 'multiple'; } break; case 'always': case 'multiple': $plural = 'multiple'; break; } $form = ''; if ($this->form !== 'long') { $form = $this->form; } $return = Container::getLocale()->getTerms($variable, $form, $plural); if ($return !== '') { $return = $this->formatting->render($return); $return = $this->textCase->render($return); $return = $this->stripPeriods->render($return); $return = $this->affix->render($return, true); } return $return; }
/** * Renders the date part, if a value is set. * * @param array $data Array with the keys: month, day, year * @return string */ public function render($data) { if (isset($data[$this->name]) == false || $data[$this->name] == '') { return ''; } $value = $this->render->render($data[$this->name]); $value = $this->formatting->render($value); $value = $this->textCase->render($value); // Attributes for affixes are allowed, unless cs:date calls a localized date format if (Container::getContext()->get('form', 'date') !== '') { $value = $this->affix->render($value); } return $value; }
/** * Apply additional formatting and remove duplicated spaces and dots. * * @param $data * @return string */ private function format($data) { $data = preg_replace('/[ ][ ]+/', ' ', $data); $data = preg_replace('/[\\.][\\.]+/', '.', $data); $data = preg_replace('/( ,)/', ',', $data); $data = preg_replace('/[;|,]([;|,])/', '$1', $data); $data = preg_replace('/\\.(<\\/[a-z]+>)\\./', '.$1', $data); $data = $this->expand->render($data); if (Container::getCitationItem() !== false) { // suppress affixes if author-only is set and there is only one cite in the actual citation $ids = Container::getRendered()->getIdByValue($data); Container::getCitationItem()->moveTo($ids['id'], $ids['citationId']); if (Container::getCitationItem()->get('author-only') == 1) { return $data; } } $data = $this->affix->render($data, true); return $this->formatting->render($data); }
/** * 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 names. * * @param array $data * @return string */ public function render($data) { $this->apply(); $names = array(); $length = count($data); if ($length == 0) { return ''; } for ($i = 0; $i < $length; $i++) { $names[] = $this->formatName($data[$i], $i); } $etAl = false; $etAlUseFirst = $this->etAlUseFirst; $etAlMin = $this->etAlMin; // If used, the values of these attributes replace those of respectively et-al-min and et-al-use-first // for subsequent cites (cites referencing earlier cited items) if (Container::getRendered()->get(Container::getActualId(), Container::getActualCitationId()) !== false) { if ($this->etAlSubsequentMin > 0) { $etAlMin = $this->etAlSubsequentMin; } if ($this->etAlSubsequentUseFirst !== '') { $etAlUseFirst = $this->etAlSubsequentUseFirst; } } if ($etAlMin > 0 && $length > 1 && $etAlMin <= $length && $etAlUseFirst < $length) { $etAl = true; } $namesAndSplitter = array(); $and = $this->getAndDelimiter(); $countNames = 0; for ($i = 0; $i < $length; $i++) { $namesAndSplitter[] = $names[$i]; $countNames++; if ($etAl == true && $i == $etAlUseFirst - 1) { switch ($this->delimiterPrecedesEtAl) { case 'contextual': if ($etAlUseFirst >= 2) { $namesAndSplitter[] = $this->delimiter; } break; case 'after-inverted-name': if ($this->nameAsSortOrder == 'first') { $namesAndSplitter[] = $this->delimiter; } break; case 'always': $namesAndSplitter[] = $this->delimiter; break; } // et-al Term $namesAndSplitter[] = ' '; $namesAndSplitter[] = Container::getLocale()->getTerms('et-al'); break; } // The delimiter between the second to last and last name of the names in a name variable if ($i == $length - 2 && $and !== '' && in_array($names[$i], $this->literals) == false) { switch ($this->delimiterPrecedesLast) { case 'contextual': if ($length >= 3) { $namesAndSplitter[] = $this->delimiter; } break; case 'after-inverted-name': if ($this->nameAsSortOrder == 'first') { $namesAndSplitter[] = $this->delimiter; } break; case 'always': $namesAndSplitter[] = $this->delimiter; break; case 'never': break; } if ($this->and !== '') { $namesAndSplitter[] = ' '; $namesAndSplitter[] = $and; $namesAndSplitter[] = ' '; } } elseif ($i < $length - 1) { $namesAndSplitter[] = $this->delimiter; } } // returns the total number of names that would otherwise be rendered if ($this->form == 'count') { return (int) $countNames; } $return = str_replace(' ', ' ', implode('', $namesAndSplitter)); // do not connect literals with an and if (count($this->literals) > 0) { $and = $and . ' '; foreach ($this->literals as $literal) { $return = str_replace($and . $literal, $literal, $return); } } // name lists truncated by et-al abbreviation are followed by the name delimiter, the ellipsis character, // and the last name of the original name list. if ($this->etAlUseLast == true && count($names) + 2 >= $countNames) { $return = str_replace(Container::getLocale()->getTerms('et-al'), ' … ' . end($names), $return); } // no formatting while sorting if (Container::getContext()->in('sort') == true) { return $return; } // no formatting while author-only is set for actual cite if (Container::getCitationItem() !== false && Container::getCitationItem()->get('author-only') == 1) { return $this->affix->render($return, true); } $return = $this->formatting->render($return); return $this->affix->render($return, true); }
/** * 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; }