You are here

function biblio_parse_author in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 includes/biblio.contributors.inc \biblio_parse_author()
  2. 6 biblio.contributors.inc \biblio_parse_author()
  3. 7.2 includes/biblio.contributors.inc \biblio_parse_author()

Parameters

$author_array:

4 calls to biblio_parse_author()
BiblioContributorUnitTest::testBiblioParseAuthor in tests/BiblioContributorUnitTest.test
biblio_authors_add_etal in includes/biblio.contributors.inc
Add separate author named "et al" to the end of the author array.
csl_name::render in modules/CiteProc/CSL.inc
theme_biblio_format_authors in includes/biblio_theme.inc

File

includes/biblio.contributors.inc, line 525

Code

function biblio_parse_author($author_array, $cat = 0) {
  if (isset($author_array['auth_category']) && $author_array['auth_category'] == 5) {
    $author_array['firstname'] = '';
    $author_array['initials'] = '';
    $author_array['lastname'] = trim($author_array['name']);
    $author_array['prefix'] = '';
    $author_array['literal'] = 1;
  }
  else {
    $value = trim($author_array['name']);
    $appellation = $prefix = $surname = $firstname = $initials = '';
    $prefix = "";

    // Replace multiple white space by single space.
    $value = preg_replace("/\\s{2,}/", ' ', $value);
    $author = explode(",", $value);
    $size = count($author);

    // No commas therefore something like Mark Grimshaw, Mark Nicholas Grimshaw, M N Grimshaw, Mark N. Grimshaw.
    if ($size == 1) {

      // Is complete surname enclosed in {...}, unless the string starts with a backslash (\) because then it is
      // probably a special latex-sign..
      // 2006.02.11 DR: in the last case, any NESTED curly braces should also be taken into account! so second
      // clause rules out things such as author="a{\"{o}}"
      // .
      if (preg_match("/(.*) {([^\\\\].*)}/", $value, $matches) && !preg_match("/(.*) {\\\\.{.*}.*}/", $value, $matches2)) {
        $author = explode(" ", $matches[1]);
        $surname = $matches[2];
      }
      else {
        $author = explode(" ", $value);

        // Last of array is surname (no prefix if entered correctly)
        $surname = array_pop($author);
      }
    }
    elseif ($size == 2) {

      // First of array is surname (perhaps with prefix)
      list($surname, $prefix) = _grabSurname(array_shift($author));
    }
    else {

      // Middle of array is 'Jr.', 'IV' etc.
      $appellation = implode(' ', array_splice($author, 1, 1));

      // First of array is surname (perhaps with prefix)
      list($surname, $prefix) = _grabSurname(array_shift($author));
    }
    $remainder = implode(" ", $author);
    list($firstname, $initials, $prefix2) = _grabFirstnameInitials($remainder);
    if (!empty($prefix2)) {
      $prefix .= $prefix2;
    }

    // var_dump($prefix);
    // $surname = $surname . ' ' . $appellation;.
    $author_array['firstname'] = trim($firstname);
    $author_array['initials'] = strlen(trim($initials)) > 10 ? drupal_substr(trim($initials), 0, 10) : trim($initials);
    $author_array['lastname'] = trim($surname);
    $author_array['prefix'] = trim($prefix);
    $author_array['suffix'] = trim($appellation);
  }
  $author_array['md5'] = _md5sum($author_array);
  return $author_array;
}