You are here

public function csl_format::format in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 modules/CiteProc/CSL.inc \csl_format::format()
  2. 7.2 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 408
CiteProc-PHP.

Class

csl_format

Code

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;
}