function csl_names::render in Bibliography Module 6.2
Same name and namespace in other branches
- 7 modules/CiteProc/CSL.inc \csl_names::render()
- 7.2 modules/CiteProc/CSL.inc \csl_names::render()
Overrides csl_rendering_element::render
File
- modules/
CiteProc/ CSL.inc, line 830
Class
Code
function render($data, $mode = NULL) {
$matches = array();
$variable_parts = array();
if (!isset($this->delimiter)) {
$style_delimiter = $this->citeproc->style->{'names-delimiter'};
$mode_delimiter = $this->citeproc->{$mode}->{'names-delimiter'};
$this->delimiter = isset($mode_delimiter) ? $mode_delimiter : (isset($style_delimiter) ? $style_delimiter : '');
}
$variables = explode(' ', $this->variable);
foreach ($variables as $var) {
if (in_array($var, $this->citeproc->quash)) {
continue;
}
list($contributor, $type) = explode(':', $var);
if (!empty($type) && isset($data->{$contributor}[$type]) && !empty($data->{$contributor}[$type])) {
$matches[] = $var;
}
}
if (empty($matches)) {
// we don't have any primary suspects, so lets check the substitutes...
if (isset($this->substitutes)) {
foreach ($this->substitutes->elements as $element) {
if ($element instanceof csl_names) {
//test to see if any of the other names variables has content
$sub_variables = explode(' ', $element->variable);
foreach ($sub_variables as $var) {
list($contributor, $type) = explode(':', $var);
if (!empty($type) && isset($data->{$contributor}[$type]) && !empty($data->{$contributor}[$type])) {
$matches[] = $var;
$this->citeproc->quash[] = $var;
}
}
}
else {
// if it's not a "names" element, just render it
$text = $element
->render($data, $mode);
$this->citeproc->quash[] = isset($element->variable) ? $element->variable : $element->var;
if (!empty($text)) {
$variable_parts[] = $text;
}
}
if (!empty($matches)) {
break;
}
}
}
}
foreach ($matches as $var) {
if (in_array($var, $this->citeproc->quash) && in_array($var, $variables)) {
continue;
}
$text = '';
list($contributor, $type) = explode(':', $var);
if (!empty($type) && isset($data->{$contributor}[$type]) && !empty($data->{$contributor}[$type])) {
foreach ($this->elements as $element) {
if (is_a($element, 'csl_label')) {
$element->variable = $this
->_get_csl_name_variable($type);
$text .= $element
->render($data->{$contributor}[$type], $mode);
}
elseif (is_a($element, 'csl_name')) {
$text .= $element
->render($data->{$contributor}[$type], $mode);
}
}
}
if (!empty($text)) {
$variable_parts[] = $text;
}
}
if (!empty($variable_parts)) {
$text = implode($this->delimiter, $variable_parts);
return $this
->format($text);
}
return;
}