You are here

function biblio_parse_author in Bibliography Module 7.2

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 includes/biblio.contributors.inc \biblio_parse_author()

Parameters

$contributor Contributor entity object:

Return value

unknown_type

7 calls to biblio_parse_author()
BiblioContributorUnitTest::testBiblioParseAuthor in tests/contributor.test
biblio_admin_author_edit_form_submit in includes/biblio.admin.inc
biblio_authors_add_etal in includes/biblio.contributors.inc
Add separate author named "et al" to the end of the author array
biblio_contributor_pre_save in includes/biblio.contributors.inc
Perform actions to a contributor object before saving
biblio_parse_contributors in includes/biblio.contributors.inc
Parse initial contributor array and augment with additional info

... See full list

File

includes/biblio.contributors.inc, line 299

Code

function biblio_parse_author($contributor) {
  $wrapper = biblio_wrapper($contributor, 'biblio_contributor');
  $name = $wrapper->biblio_contributor_name
    ->value();
  if (isset($category) && $category == 5) {
    $author_object->firstname = '';
    $author_object->initials = '';
    $author_object->lastname = trim($author_object->name);
    $author_object->prefix = '';
    $author_object->literal = 1;
  }
  else {
    $value = trim($name);
    $appellation = $prefix = $surname = $firstname = $initials = '';
    $prefix = "";
    $value = preg_replace("/\\s{2,}/", ' ', $value);

    // replace multiple white space by single space
    $author = explode(",", $value);
    $size = sizeof($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);
      }
    }
    else {
      if ($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;
    $initials = strlen(trim($initials)) > 10 ? drupal_substr(trim($initials), 0, 10) : trim($initials);
    $wrapper->biblio_contributor_first_name = empty($firstname) ? NULL : trim($firstname);
    $wrapper->biblio_contributor_initials = empty($initials) ? NULL : $initials;
    $wrapper->biblio_contributor_last_name = empty($surname) ? NULL : trim($surname);
    $wrapper->biblio_contributor_prefix = empty($prefix) ? NULL : trim($prefix);
    $wrapper->biblio_contributor_suffix = empty($appellation) ? NULL : trim($appellation);
  }

  // @todo: get hashing working for contributors
  // $author_object->md5 =  _md5sum($author_object);
  return $contributor;
}