/** * Modifys the actual month configuration. * * @param \SimpleXMLElement $xml * @return \Geissler\CSL\Date\Month * @todo Create new StripPeriods object is necessary */ public function modify(\SimpleXMLElement $xml) { $this->stripPeriods->modify($xml); foreach ($xml->attributes() as $name => $value) { if ($name == 'form') { $this->form = (string) $value; break; } } return $this; }
/** * 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; }
/** * 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); }