You are here

function theme_biblio_format_authors in Bibliography Module 5

Same name and namespace in other branches
  1. 6.2 includes/biblio_theme.inc \theme_biblio_format_authors()
  2. 6 biblio_theme.inc \theme_biblio_format_authors()
  3. 7 includes/biblio_theme.inc \theme_biblio_format_authors()
  4. 7.2 includes/biblio.theme.inc \theme_biblio_format_authors()
4 theme calls to theme_biblio_format_authors()
biblio_style_ama in ./biblio_style_ama.inc
biblio_style_chicago in ./biblio_style_chicago.inc
Apply a bibliographic style to the node
biblio_style_mla in ./biblio_style_mla.inc
Apply a bibliographic style to the node
biblio_style_vancouver in ./biblio_style_vancouver.inc

File

./biblio.module, line 3974

Code

function theme_biblio_format_authors($contributors, $options, $inline = false) {
  if (empty($contributors)) {
    return;
  }
  $base = variable_get('biblio_base', 'biblio');
  $author_links = variable_get('biblio_author_links', 1);
  list($alnum, $alpha, $cntrl, $dash, $digit, $graph, $lower, $print, $punct, $space, $upper, $word, $patternModifiers) = _biblio_get_utf8_regex();
  $auth_array = split(';', $contributors);

  // get a list of all authors for this record
  $authorCount = count($auth_array);

  // check how many authors we have to deal with
  $output = "";

  // this variable will hold the final author string
  $includeStringAfterFirstAuthor = false;
  if (empty($options['numberOfAuthorsTriggeringEtAl'])) {
    $options['numberOfAuthorsTriggeringEtAl'] = $authorCount;
  }
  if (empty($options['includeNumberOfAuthors'])) {
    $options['includeNumberOfAuthors'] = $authorCount;
  }
  $i = 0;
  foreach ($auth_array as $rank => $author) {
    $singleAuthorArray = split($options['oldAuthorsInitialsDelim'], $author);

    // for each author, extract author name & initials to separate list items
    //      if (!$familyNameFirst) // if the family name comes *after* the given name (or initials) in the source string, put array elements in reverse order:
    //        $singleAuthorArray = array_reverse($singleAuthorArray); // (Note: this only works, if the array has only *two* elements, i.e., one containing the author's name and one holding the initials!)
    if (isset($singleAuthorArray[1])) {
      if ($options['shortenGivenNames']) {

        // if we're supposed to abbreviate given names
        // within initials, reduce all full first names (-> defined by a starting uppercase character, followed by one ore more lowercase characters)
        // to initials, i.e., only retain their first character
        $singleAuthorArray[1] = preg_replace("/([{$upper}])[{$lower}]+/{$patternModifiers}", "\\1", $singleAuthorArray[1]);
      }

      // within initials, remove any dots:
      $singleAuthorArray[1] = preg_replace("/([{$upper}])\\.+/{$patternModifiers}", "\\1", $singleAuthorArray[1]);

      // within initials, remove any spaces *between* initials:
      $singleAuthorArray[1] = preg_replace("/(?<=[-{$upper}]) +(?=[-{$upper}])/{$patternModifiers}", "", $singleAuthorArray[1]);

      // within initials, add a space after a hyphen, but only if ...
      if (ereg(" \$", $options['betweenInitialsDelim'])) {

        // ... the delimiter that separates initials ends with a space
        $singleAuthorArray[1] = preg_replace("/-(?=[{$upper}])/{$patternModifiers}", "- ", $singleAuthorArray[1]);
      }

      // then, separate initials with the specified delimiter:
      $delim = $options['betweenInitialsDelim'];
      $singleAuthorArray[1] = preg_replace("/([{$upper}])(?=[^{$lower}]+|\$)/{$patternModifiers}", "\\1{$delim}", $singleAuthorArray[1]);
    }
    if ($i == 0 and $options['initialsBeforeAuthorFirstAuthor'] or $i > 0 and $options['initialsBeforeAuthorStandard']) {

      // put array elements in reverse order:
      $singleAuthorArray = array_reverse($singleAuthorArray);
    }

    // (Note: this only works, if the array has only *two* elements, i.e., one containing the author's name and one holding the initials!)
    // re-join author name & initials, using the specified delimiter, and copy the string to the end of an array:
    if ($i == 0) {

      // -> first author
      $singleAuthorString = implode($options['AuthorsInitialsDelimFirstAuthor'], $singleAuthorArray);
    }
    else {

      // $i > 0 // -> all authors except the first one
      $singleAuthorString = implode($options['AuthorsInitialsDelimStandard'], $singleAuthorArray);
    }
    if ($author_links) {
      $singleAuthorString = _biblio_single_author_link($singleAuthorString, $base, $inline);
    }

    // append this author to the final author string:
    if ($i == 0 or $i + 1 < $authorCount) {

      // -> first author, or (for multiple authors) all authors except the last one
      if ($i == 0) {

        // -> first author
        $output .= $singleAuthorString;
      }
      else {

        // -> for multiple authors, all authors except the first or the last one
        $output .= $options['BetweenAuthorsDelimStandard'] . $singleAuthorString;
      }

      // we'll append the string in '$customStringAfterFirstAuthors' to the number of authors given in '$includeNumberOfAuthors' if the total number of authors is greater than the number given in '$numberOfAuthorsTriggeringEtAl':
      if ($i + 1 == $options['includeNumberOfAuthors'] and $authorCount > $options['numberOfAuthorsTriggeringEtAl']) {
        if (ereg("__NUMBER_OF_AUTHORS__", $options['customStringAfterFirstAuthors'])) {
          $options['customStringAfterFirstAuthors'] = preg_replace("/__NUMBER_OF_AUTHORS__/", $authorCount - $options['includeNumberOfAuthors'], $options['customStringAfterFirstAuthors']);
        }

        // resolve placeholder
        $includeStringAfterFirstAuthor = true;
        break;
      }
    }
    elseif ($authorCount > 1 and $i + 1 == $authorCount) {

      // -> last author (if multiple authors)
      $output .= $options['BetweenAuthorsDelimLastAuthor'] . $singleAuthorString;
    }
    $i++;
  }

  // do some final clean up:
  if ($options['encodeHTML']) {

    //$output = encodeHTML($output); // HTML encode higher ASCII characters within the newly arranged author contents
    if ($includeStringAfterFirstAuthor) {
      $output .= $options['customStringAfterFirstAuthors'];
    }
  }

  // the custom string won't get HTML encoded so that it's possible to include HTML tags (such as '<i>') within the string
  $output = preg_replace("/  +/", " ", $output);

  // remove double spaces (which occur e.g., when both, $betweenInitialsDelim & $newAuthorsInitialsDelim..., end with a space)
  $output = preg_replace("/ +([,.;:?!()]|\$)/", "\\1", $output);

  // remove excess spaces before [,.;:?!()] and from the end of the author string
  return $output;
}