You are here

function PARSECREATORS::parseAuthor in Bibliography Module 6

Same name and namespace in other branches
  1. 6.2 modules/bibtexParse/PARSECREATORS.php \PARSECREATORS::parseAuthor()
  2. 7.3 plugins/biblio_style/bibtex/PARSECREATORS.php \PARSECREATORS::parseAuthor()
  3. 7 modules/bibtexParse/PARSECREATORS.php \PARSECREATORS::parseAuthor()
  4. 7.2 modules/bibtexParse/PARSECREATORS.php \PARSECREATORS::parseAuthor()
3 calls to PARSECREATORS::parseAuthor()
Creators::setCreator in bibtexParse/PARSECREATORS.php
Creators::setCreators in bibtexParse/PARSECREATORS.php
update object with an array of authors
PARSECREATORS::parseArray in bibtexParse/PARSECREATORS.php

File

bibtexParse/PARSECREATORS.php, line 205

Class

PARSECREATORS

Code

function parseAuthor($value, $type = 'author') {
  $appellation = $prefix = $surname = $firstname = $initials = '';
  $this->prefix = array();
  $author = explode(",", preg_replace("/\\s{2,}/", ' ', trim($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 = split(" ", $matches[1]);
      $surname = $matches[2];
    }
    else {
      $author = split(" ", $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) = $this
        ->grabSurname(array_shift($author));
    }
    else {

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

      // first of array is surname (perhaps with prefix)
      list($surname, $prefix) = $this
        ->grabSurname(array_shift($author));
    }
  }
  $remainder = join(" ", $author);
  list($firstname, $initials) = $this
    ->grabFirstnameInitials($remainder);
  if (!empty($this->prefix)) {
    $prefix = join(' ', $this->prefix);
  }
  $surname = $surname . ' ' . $appellation;
  $creator = array(
    'firstname' => utf8_encode(trim($firstname)),
    'initials' => utf8_encode(trim($initials)),
    'lastname' => utf8_encode(trim($surname)),
    'prefix' => trim($prefix),
  );
  if (isset($creator)) {
    $creator['type'] = $this->typeMap[$type];
    $creator['md5'] = $this
      ->md5sum($creator);
    return $creator;
  }
  return FALSE;
}