/** * 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); }
/** * Render citations with citations or citation-items data. * * @param string|array $data * @return array */ private function citation($data) { Container::getContext()->addOption('layout', 'delimiter', $this->delimiter); Container::getCitationItem()->moveToFirst(); $result = array(); do { $group = array(); do { $id = Container::getActualId(); $citationId = Container::getActualCitationId(); if ($id !== null && $citationId !== null) { Container::getData()->moveToId($id); // store rendered citation Container::getRendered()->set($id, $citationId, $this->renderJustActualEntry($data)); $group[] = $id . '#' . $citationId; } } while (Container::getCitationItem()->nextInGroup() == true); $result[] = $group; } while (Container::getCitationItem()->next() == true); return explode("\n", $this->applyCitationOptions($result, "\n")); }