class csl_format in Bibliography Module 7
Same name and namespace in other branches
- 6.2 modules/CiteProc/CSL.inc \csl_format
- 7.2 modules/CiteProc/CSL.inc \csl_format
Hierarchy
- class \csl_collection
- class \csl_element
- class \csl_rendering_element
- class \csl_format
- class \csl_rendering_element
- class \csl_element
Expanded class hierarchy of csl_format
File
- modules/
CiteProc/ CSL.inc, line 352 - CiteProc-PHP.
View source
class csl_format extends csl_rendering_element {
protected $no_op;
protected $format;
/**
*
*/
public function __construct($dom_node = NULL, $citeproc = NULL) {
parent::__construct($dom_node, $citeproc);
$this
->init_formatting();
}
/**
*
*/
public function init_formatting() {
$this->no_op = TRUE;
$this->format = '';
if (isset($this->quotes) && strtolower($this->quotes) == "true") {
$this->quotes = array();
$this->quotes['punctuation-in-quote'] = $this->citeproc
->get_locale('style_option', 'punctuation-in-quote');
$this->quotes['open-quote'] = $this->citeproc
->get_locale('term', 'open-quote');
$this->quotes['close-quote'] = $this->citeproc
->get_locale('term', 'close-quote');
$this->quotes['open-inner-quote'] = $this->citeproc
->get_locale('term', 'open-inner-quote');
$this->quotes['close-inner-quote'] = $this->citeproc
->get_locale('term', 'close-inner-quote');
$this->no_op = FALSE;
}
if (isset($this->{'prefix'})) {
$this->no_op = FALSE;
}
if (isset($this->{'suffix'})) {
$this->no_op = FALSE;
}
if (isset($this->{'display'})) {
$this->no_op = FALSE;
}
$this->format .= isset($this->{'font-style'}) ? 'font-style: ' . $this->{'font-style'} . ';' : '';
$this->format .= isset($this->{'font-family'}) ? 'font-family: ' . $this->{'font-family'} . ';' : '';
$this->format .= isset($this->{'font-weight'}) ? 'font-weight: ' . $this->{'font-weight'} . ';' : '';
$this->format .= isset($this->{'font-variant'}) ? 'font-variant: ' . $this->{'font-variant'} . ';' : '';
$this->format .= isset($this->{'text-decoration'}) ? 'text-decoration: ' . $this->{'text-decoration'} . ';' : '';
$this->format .= isset($this->{'vertical-align'}) ? 'vertical-align: ' . $this->{'vertical-align'} . ';' : '';
// $this->format .= (isset($this->{'display'}) && $this->{'display'} == 'indent') ? 'padding-left: 25px;' : '';.
if (isset($this->{'text-case'}) || !empty($this->format) || !empty($this->span_class) || !empty($this->div_class)) {
$this->no_op = FALSE;
}
}
/**
*
*/
public function format($text) {
if (empty($text) || $this->no_op) {
return $text;
}
$quotes = $this->quotes;
$quotes = is_array($quotes) ? $quotes : array();
if (isset($this->{'text-case'})) {
switch ($this->{'text-case'}) {
case 'uppercase':
$text = drupal_strtoupper($text);
break;
case 'lowercase':
$text = drupal_strtolower($text);
break;
case 'capitalize-all':
case 'title':
$text = mb_convert_case($text, MB_CASE_TITLE);
break;
case 'capitalize-first':
$text = drupal_ucfirst($text);
break;
}
}
$prefix = $this->prefix;
$prefix .= isset($quotes['open-quote']) ? $quotes['open-quote'] : '';
$suffix = $this->suffix;
if (isset($quotes['close-quote']) && !empty($suffix) && isset($quotes['punctuation-in-quote'])) {
if (strpos($suffix, '.') !== FALSE || strpos($suffix, ',') !== FALSE) {
$suffix = $suffix . $quotes['close-quote'];
}
}
elseif (isset($quotes['close-quote'])) {
$suffix = $quotes['close-quote'] . $suffix;
}
// Gaurd against repeaded suffixes...
if (!empty($suffix)) {
$no_tags = strip_tags($text);
if (strlen($no_tags) && $no_tags[strlen($no_tags) - 1] == $suffix[0]) {
$suffix = substr($suffix, 1);
}
}
if (!empty($this->format) || !empty($this->span_class)) {
$style = !empty($this->format) ? 'style="' . $this->format . '"' : '';
$class = !empty($this->span_class) ? 'class="' . $this->span_class . '"' : '';
$text = '<span ' . implode(' ', array(
$class,
$style,
)) . '>' . $text . '</span>';
}
$div_class = $div_style = '';
if (!empty($this->div_class)) {
$div_class = !empty($this->div_class) ? 'class="' . $this->div_class . '"' : '';
}
if ($this->display == 'indent') {
$div_style = 'style="text-indent: 0px; padding-left: 45px;"';
}
if ($div_class || $div_style) {
return '<div ' . $div_class . $div_style . '>' . $prefix . $text . $suffix . '</div>';
}
return $prefix . $text . $suffix;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
csl_collection:: |
protected | property | ||
csl_collection:: |
public | function | ||
csl_element:: |
protected | property | ||
csl_element:: |
protected | property | ||
csl_element:: |
public | function | ||
csl_element:: |
public | function | ||
csl_element:: |
public | function | 5 | |
csl_element:: |
public | function | ||
csl_element:: |
public | function | ||
csl_element:: |
public | function | ||
csl_element:: |
public | function | ||
csl_element:: |
public | function | ||
csl_element:: |
public | function | ||
csl_format:: |
protected | property | 1 | |
csl_format:: |
protected | property | ||
csl_format:: |
public | function |
Overrides csl_collection:: |
1 |
csl_format:: |
public | function | 5 | |
csl_format:: |
public | function |
Overrides csl_element:: |
2 |
csl_rendering_element:: |
public | function |
Overrides csl_collection:: |
11 |