You are here

function csl_format::format in Bibliography Module 7.2

Same name and namespace in other branches
  1. 6.2 modules/CiteProc/CSL.inc \csl_format::format()
  2. 7 modules/CiteProc/CSL.inc \csl_format::format()

Overrides csl_collection::format

10 calls to csl_format::format()
csl_bibliography::render in modules/CiteProc/CSL.inc
csl_citation::render in modules/CiteProc/CSL.inc
csl_date::render in modules/CiteProc/CSL.inc
csl_date_part::render in modules/CiteProc/CSL.inc
csl_group::render in modules/CiteProc/CSL.inc

... See full list

1 method overrides csl_format::format()
csl_name::format in modules/CiteProc/CSL.inc

File

modules/CiteProc/CSL.inc, line 291

Class

csl_format

Code

function format($text) {
  if (empty($text) || $this->no_op) {
    return $text;
  }
  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 . $this->quotes['open-quote'];
  $suffix = $this->suffix;
  if ($this->quotes['close-quote'] && !empty($suffix) && $this->quotes['punctuation-in-quote']) {
    if (strpos($suffix, '.') !== FALSE || strpos($suffix, ',') !== FALSE) {
      $suffix = $suffix . $this->quotes['close-quote'];
    }
  }
  elseif ($this->quotes['close-quote']) {
    $suffix = $this->quotes['close-quote'] . $suffix;
  }
  if (!empty($suffix)) {

    // gaurd against repeaded suffixes...
    $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 ' . $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;
}