class csl_label in Bibliography Module 6.2
Same name and namespace in other branches
- 7 modules/CiteProc/CSL.inc \csl_label
- 7.2 modules/CiteProc/CSL.inc \csl_label
Hierarchy
- class \csl_collection
- class \csl_element
- class \csl_rendering_element
- class \csl_format
- class \csl_label
- class \csl_format
- class \csl_rendering_element
- class \csl_element
Expanded class hierarchy of csl_label
1 string reference to 'csl_label'
- csl_names::render in modules/
CiteProc/ CSL.inc
File
- modules/
CiteProc/ CSL.inc, line 1199
View source
class csl_label extends csl_format {
private $plural;
function render($data, $mode = NULL) {
$text = '';
$variables = explode(' ', $this->variable);
$form = ($form = $this->form) ? $form : 'long';
switch ($this->plural) {
case 'never':
$plural = 'single';
break;
case 'always':
$plural = 'multiple';
break;
case 'contextual':
default:
}
foreach ($variables as $variable) {
$field = $this->citeproc
->map_field($variable);
if (isset($data->{$field}) && !empty($data->{$field})) {
if (!isset($this->plural) && empty($plural) && is_array($data->{$field})) {
$count = count($data->{$field});
if ($count == 1) {
$plural = 'single';
}
elseif ($count > 1) {
$plural = 'multiple';
}
}
else {
$plural = $this
->evaluateStringPluralism($data, $variable);
}
if ($term = $this->citeproc
->get_locale('term', $variable, $form, $plural)) {
$text = $term;
break;
}
}
}
if (empty($text)) {
return;
}
if ($this->{'strip-periods'}) {
$text = str_replace('.', '', $text);
}
return $this
->format($text);
}
function evaluateStringPluralism($data, $variable) {
$field = $this->citeproc
->map_field($variable);
$str = $data->{$field};
$plural = 'single';
if (!empty($str)) {
// $regex = '/(?:[0-9],\s*[0-9]|\s+and\s+|&|([0-9]+)\s*[\-\x2013]\s*([0-9]+))/';
switch ($variable) {
case 'page':
$page_regex = "/([a-zA-Z]*)([0-9]+)\\s*(?:–|-)\\s*([a-zA-Z]*)([0-9]+)/";
$err = preg_match($page_regex, $str, $m);
if ($err !== FALSE && count($m) == 0) {
$plural = 'single';
}
elseif ($err !== FALSE && count($m)) {
$plural = 'multiple';
}
break;
default:
}
}
return $plural;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
csl_collection:: |
protected | property | ||
csl_collection:: |
function | |||
csl_element:: |
protected | property | ||
csl_element:: |
protected | property | ||
csl_element:: |
function | |||
csl_element:: |
function | |||
csl_element:: |
function | 5 | ||
csl_element:: |
function | |||
csl_element:: |
function | |||
csl_element:: |
function | |||
csl_element:: |
function | |||
csl_element:: |
function | |||
csl_element:: |
function | |||
csl_format:: |
protected | property | 1 | |
csl_format:: |
protected | property | ||
csl_format:: |
function |
Overrides csl_collection:: |
1 | |
csl_format:: |
function | 5 | ||
csl_format:: |
function |
Overrides csl_element:: |
2 | |
csl_label:: |
private | property | ||
csl_label:: |
function | |||
csl_label:: |
function |
Overrides csl_rendering_element:: |