You are here

function _biblio_parse_authors in Bibliography Module 5

Same name and namespace in other branches
  1. 6.2 biblio.install \_biblio_parse_authors()
6 calls to _biblio_parse_authors()
biblio_show_node in ./biblio.module
biblio_style_apa in ./biblio_style_apa.inc
Apply a bibliographic style to the node
biblio_style_classic in ./biblio_style_classic.inc
Apply a bibliographic style to the node
biblio_style_cse in ./biblio_style_cse.inc
Apply a bibliographic style to the node
biblio_style_ieee in ./biblio_style_ieee.inc
Apply a bibliographic style to the node

... See full list

File

./biblio.module, line 3196

Code

function _biblio_parse_authors($authors) {
  $and = array(
    " and ",
    " And ",
    " AND ",
  );
  $etal = "";
  $author_array = array();
  if (strpos($authors, 'et al')) {
    if (strpos($authors, 'et al.')) {
      $authors = str_replace('et al.', "", $authors);
    }
    else {
      $authors = str_replace('et al', "", $authors);
    }
    $etal = 'et al.';
  }
  $authors = str_replace($and, "; ", $authors);

  // change the word "and" to a comma
  $authors = str_replace(" ,", ",", $authors);

  // fix some potential typos
  $authors = str_replace(",,", ",", $authors);

  // ditto
  // $authors = str_replace(";",",",$authors);
  $chunks = explode(";", $authors);

  // split the authors on the semicolon
  $num_chunks = count($chunks);
  foreach ($chunks as $chunk) {
    if (strlen(trim($chunk))) {
      $suffix = _biblio_get_suffix($chunk);

      // get and strip out the suffix
      $prefix = _biblio_get_prefix($chunk);

      // get and strip out the prefix
      if (strstr($chunk, ",")) {

        // we probably have lastname first
        $subchunks = explode(",", trim($chunk));
        $lastname = $subchunks[0];
        $subchunks = explode(" ", trim($subchunks[1]));
        $initials = "";
        for ($j = 0; $j < count($subchunks); $j++) {
          if (substr_count($subchunks[$j], '.')) {
            $initials .= $subchunks[$j];
          }
          else {
            $initials .= drupal_substr($subchunks[$j], 0, 1) . ".";
          }
        }
      }
      else {

        // we have some form of firstname first (Fistname I. Lastname)
        $subchunks = explode(" ", trim($chunk));
        $lastname = end($subchunks);
        $initials = "";
        for ($j = 0; $j < count($subchunks) - 1; $j++) {
          if (substr_count($subchunks[$j], '.')) {
            $initials .= $subchunks[$j];
          }
          else {
            $initials .= drupal_substr($subchunks[$j], 0, 1) . ".";
          }
        }
      }
      $author_array[] = trim($prefix . $lastname . ', ' . $initials . ' ' . $suffix);
    }
  }
  return implode("; ", $author_array) . " {$etal}";
}