You are here

public function biblio_handler_field_contributor::render_contriubutors in Bibliography Module 7

Same name and namespace in other branches
  1. 7.2 views/biblio_handler_field_contributor.inc \biblio_handler_field_contributor::render_contriubutors()
1 call to biblio_handler_field_contributor::render_contriubutors()
biblio_handler_field_contributor::render in views/biblio_handler_field_contributor.inc
Render the field.

File

views/biblio_handler_field_contributor.inc, line 161

Class

biblio_handler_field_contributor

Code

public function render_contriubutors($contributors) {
  $authors = array();
  if (!isset($this->alnum)) {
    list($this->alnum, $this->alpha, $this->cntrl, $this->dash, $this->digit, $this->graph, $this->lower, $this->print, $this->punct, $this->space, $this->upper, $this->word, $this->patternModifiers) = $this
      ->get_regex_patterns();
  }
  foreach ($contributors as $rank => $author) {
    $author = (object) $author;
    if ($author->literal == 1) {
      $authors[] = $author->name;
    }
    else {
      if (!empty($author->firstname) && $this->options['initialize'] == 1) {
        $author->firstname = preg_replace("/([{$this->upper}])[{$this->lower}]+/{$this->patternModifiers}", '\\1', $author->firstname);
        $author->firstname = preg_replace("/(?<=[-{$this->upper}]) +(?=[-{$this->upper}])/{$this->patternModifiers}", "", $author->firstname);
        $author->initials = $author->firstname . $author->initials;
      }
      if (isset($author->initials)) {

        // Within initials, remove any dots:
        $author->initials = preg_replace("/([{$this->upper}])\\.+/{$this->patternModifiers}", "\\1", $author->initials);

        // Within initials, remove any spaces *between* initials:
        $author->initials = preg_replace("/(?<=[-{$this->upper}]) +(?=[-{$this->upper}])/{$this->patternModifiers}", "", $author->initials);
        if ($this->options['initialize_with_hyphen'] === FALSE) {
          $author->initials = preg_replace("/-/", '', $author->initials);
        }

        // Within initials, add a space after a hyphen, but only if ...
        // ... the delimiter that separates initials ends with a space.
        if (preg_match("/ \$/", $this->options['initialize_with'])) {
          $author->initials = preg_replace("/-(?=[{$this->upper}])/{$this->patternModifiers}", "- ", $author->initials);
        }

        // then, separate initials with the specified delimiter:
        $init_sep = $this->options['initialize_with'];
        $author->initials = preg_replace("/([{$this->upper}])(?=[^{$this->lower}]+|\$)/{$this->patternModifiers}", "\\1{$init_sep}", $author->initials);

        // $shortenInitials = (isset($options['numberOfInitialsToKeep)) ? $options['numberOfInitialsToKeep : FALSE;
        //      if ($shortenInitials) $given = drupal_substr($given, 0, $shortenInitials);.
        if ($this->options['initialize'] == 1) {
          $author->firstname = $author->initials;

          // If ($shortenInitials) $author->firstname = drupal_substr($author->firstname, 0, $shortenInitials);.
        }
        elseif (!empty($author->firstname)) {
          $author->firstname = $author->firstname . ' ' . $author->initials;
        }
        elseif (empty($author->firstname)) {
          $author->firstname = $author->initials;
        }
      }
      if (isset($author->lastname)) {
        if ($this->options['short_form'] == 1) {
          $authors[] = $author->lastname;
        }
        else {
          switch ($this->options['name_order']) {
            case 'last-first':
              $authors[] = $author->lastname . $this->options['sort_separator'] . $author->firstname;
              break;
            default:
              $authors[] = $author->firstname . ' ' . $author->lastname;
          }
        }
      }
    }
  }
  return implode($this->options['separator'], $authors);
}