refactored things rlated to name parsing and formatting
This commit is contained in:
+68
-52
@@ -943,21 +943,66 @@ class BibEntry {
|
|||||||
return $authors;
|
return $authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the authors of this entry as an array */
|
/**
|
||||||
|
* Returns the formated author name w.r.t to the user preference encoded in COMMA_NAMES
|
||||||
|
*/
|
||||||
|
function formatAuthor($author){
|
||||||
|
if (COMMA_NAMES) {
|
||||||
|
return $this->formatAuthorCommaSeparated($author);
|
||||||
|
}
|
||||||
|
else return $this->formatAuthorCanonical($author);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the formated author name as "FirstName LastName".
|
||||||
|
*/
|
||||||
|
function formatAuthorCanonical($author){
|
||||||
|
list($firstname, $lastname) = splitFullName($author);
|
||||||
|
if ($firstname!='') return $firstname.' '.$lastname;
|
||||||
|
else return $lastname;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the formated author name as "LastName, FirstName".
|
||||||
|
*/
|
||||||
|
function formatAuthorCommaSeparated($author){
|
||||||
|
list($firstname, $lastname) = splitFullName($author);
|
||||||
|
if ($firstname!='') return $lastname.', '.$firstname;
|
||||||
|
else return $lastname;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Returns the authors as a string depending on the configuration parameter COMMA_NAMES */
|
||||||
function getFormattedAuthors() {
|
function getFormattedAuthors() {
|
||||||
$authors = array();
|
$authors = array();
|
||||||
foreach ($this->getRawAuthors() as $author) {
|
foreach ($this->getRawAuthors() as $author) {
|
||||||
$authors[]=formatAuthor($author);
|
$authors[]=$this->formatAuthor($author);
|
||||||
}
|
}
|
||||||
return $authors;
|
return $authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @deprecated
|
||||||
|
* @see getFormattedAuthorsImproved()
|
||||||
|
*/
|
||||||
|
function formattedAuthors() { return $this->getFormattedAuthorsImproved(); }
|
||||||
|
|
||||||
|
/** Adds to getFormattedAuthors() the home page links and returns a string (not an array)
|
||||||
|
*/
|
||||||
|
function getFormattedAuthorsImproved() {
|
||||||
|
$array_authors = $this->getFormattedAuthors();
|
||||||
|
foreach ($array_authors as $k => $author) {
|
||||||
|
$array_authors[$k]=$this->addHomepageLink($author);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (COMMA_NAMES) {$sep = '; ';} else {$sep = ', ';}
|
||||||
|
return implode($sep ,$array_authors);
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the authors of this entry as an array in a canonical form */
|
/** Returns the authors of this entry as an array in a canonical form */
|
||||||
function getCanonicalAuthors() {
|
function getCanonicalAuthors() {
|
||||||
$authors = array();
|
$authors = array();
|
||||||
foreach ($this->getRawAuthors() as $author) {
|
foreach ($this->getRawAuthors() as $author) {
|
||||||
$authors[]=formatAuthorCanonical($author);
|
$authors[]=$this->formatAuthorCanonical($author);
|
||||||
}
|
}
|
||||||
return $authors;
|
return $authors;
|
||||||
}
|
}
|
||||||
@@ -966,11 +1011,22 @@ class BibEntry {
|
|||||||
function getArrayOfCommaSeparatedAuthors() {
|
function getArrayOfCommaSeparatedAuthors() {
|
||||||
$authors = array();
|
$authors = array();
|
||||||
foreach ($this->getRawAuthors() as $author) {
|
foreach ($this->getRawAuthors() as $author) {
|
||||||
$authors[]=formatAuthorCommaSeparated($author);
|
$authors[]=$this->formatAuthorCommaSeparated($author);
|
||||||
}
|
}
|
||||||
return $authors;
|
return $authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a compacted string form of author names by throwing away
|
||||||
|
* all author names except for the first one and appending ", et al."
|
||||||
|
*/
|
||||||
|
function getCompactedAuthors($author){
|
||||||
|
$authors = $this->getAuthors();
|
||||||
|
$etal = count($authors) > 1 ? ', et al.' : '';
|
||||||
|
return $this->formatAuthor($authors[0]) . $etal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** add the link to the homepage if it is defined in a string
|
/** add the link to the homepage if it is defined in a string
|
||||||
* e.g. @string{hp_MartinMonperrus="http://www.monperrus.net/martin"}
|
* e.g. @string{hp_MartinMonperrus="http://www.monperrus.net/martin"}
|
||||||
* The string is a concatenation of firstname, lastname, prefixed by hp_
|
* The string is a concatenation of firstname, lastname, prefixed by hp_
|
||||||
@@ -987,17 +1043,6 @@ class BibEntry {
|
|||||||
return $author;
|
return $author;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the authors as a string depending on the configuration parameter COMMA_NAMES */
|
|
||||||
function formattedAuthors() {
|
|
||||||
$array_authors = $this->getFormattedAuthors();
|
|
||||||
foreach ($array_authors as $k => $author) {
|
|
||||||
$array_authors[$k]=$this->addHomepageLink($author);
|
|
||||||
}
|
|
||||||
if (COMMA_NAMES) return implode('; ',$array_authors);
|
|
||||||
else return implode(', ',$array_authors);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Returns the editors of this entry as an arry */
|
/** Returns the editors of this entry as an arry */
|
||||||
function getEditors() {
|
function getEditors() {
|
||||||
@@ -1008,14 +1053,14 @@ class BibEntry {
|
|||||||
return $editors;
|
return $editors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Returns the editors of this entry as an arry */
|
||||||
* Returns a compacted string form of author names by throwing away
|
function getFormattedEditors() {
|
||||||
* all author names except for the first one and appending ", et al."
|
$editors = array();
|
||||||
*/
|
foreach ($this->getEditors() as $editor) {
|
||||||
function getCompactedAuthors($author){
|
$editors[]=$this->formatAuthor($editor);
|
||||||
$authors = $this->getAuthors();
|
}
|
||||||
$etal = count($authors) > 1 ? ', et al.' : '';
|
if (COMMA_NAMES) {$sep = '; ';} else {$sep = ', ';}
|
||||||
return formatAuthor($authors[0]) . $etal;
|
return implode($sep, $editors).', '.(count($editors)>1?'eds.':'ed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1274,35 +1319,6 @@ function splitFullName($author){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formated author name w.r.t to the user preference encoded in COMMA_NAMES
|
|
||||||
*/
|
|
||||||
function formatAuthor($author){
|
|
||||||
if (COMMA_NAMES) {
|
|
||||||
return formatAuthorCommaSeparated($author);
|
|
||||||
}
|
|
||||||
else return formatAuthorCanonical($author);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formated author name as "FirstName LastName".
|
|
||||||
*/
|
|
||||||
function formatAuthorCanonical($author){
|
|
||||||
list($firstname, $lastname) = splitFullName($author);
|
|
||||||
if ($firstname!='') return $firstname.' '.$lastname;
|
|
||||||
else return $lastname;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the formated author name as "LastName, FirstName".
|
|
||||||
*/
|
|
||||||
function formatAuthorCommaSeparated($author){
|
|
||||||
list($firstname, $lastname) = splitFullName($author);
|
|
||||||
if ($firstname!='') return $lastname.', '.$firstname;
|
|
||||||
else return $lastname;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** New undocumented feature, used by Benoit Baudry
|
/** New undocumented feature, used by Benoit Baudry
|
||||||
* see http://www.irisa.fr/triskell/perso_pro/bbaudry/publications.php
|
* see http://www.irisa.fr/triskell/perso_pro/bbaudry/publications.php
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user