fix bugs in author menu
This commit is contained in:
Regular → Executable
@@ -470,6 +470,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals("Advanced Air and Ground Research Team", $authors[1]);
|
||||
$this->assertEquals("Foo Bar", $authors[2]);
|
||||
$this->assertEquals("J{\'e} Ko", $authors[3]);
|
||||
$this->assertEquals("Jé Ko", $entry->getFormattedAuthorsArray()[3]);
|
||||
}
|
||||
|
||||
function test_latex2html() {
|
||||
@@ -493,6 +494,20 @@ class BTBTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals('<a href="http://www.monperrus.net/martin">Monperrus, Martin</a>', $authors[2]);
|
||||
}
|
||||
|
||||
function test_author_index() {
|
||||
bibtexbrowser_configure('USE_FIRST_THEN_LAST', true);
|
||||
|
||||
$bibtex = "@string{hp_MartinMonperrus={http://www.monperrus.net/martin},hp_FooAcé={http://example.net/}},@article{aKey61,title={An article Book},author = {Martin Monperrus and Foo Ac\'e and Monperrus, Martin}}\n";
|
||||
$test_data = fopen('php://memory','x+');
|
||||
fwrite($test_data, $bibtex);
|
||||
fseek($test_data,0);
|
||||
$db = new BibDataBase();
|
||||
$db->update_internal("inline", $test_data);
|
||||
|
||||
$index = var_export($db->authorIndex(), true);
|
||||
$this->assertEquals("array (\n 'Foo Acé' => 'Foo Acé',\n 'Martin Monperrus' => 'Martin Monperrus',\n)", $index);
|
||||
}
|
||||
|
||||
function test_identity() {
|
||||
$btb = new BibDataBase();
|
||||
$btb->load('bibacid-utf8.bib');
|
||||
|
||||
+31
-24
@@ -1187,6 +1187,19 @@ class BibEntry {
|
||||
$this->setField(Q_KEY,str_replace('/','-',$value));
|
||||
}
|
||||
|
||||
function transformValue($value) {
|
||||
// trim space
|
||||
$value = xtrim($value);
|
||||
|
||||
// transform Latex markup to HTML entities (easier than a one to one mapping to each character)
|
||||
// HTML entity is an intermediate format
|
||||
$value = latex2html($value);
|
||||
|
||||
// transform to the target output encoding
|
||||
$value = html_entity_decode($value, ENT_QUOTES|ENT_XHTML, OUTPUT_ENCODING);
|
||||
return $value;
|
||||
}
|
||||
|
||||
/** Sets a field of this bib entry. */
|
||||
function setField($name, $value) {
|
||||
$name = strtolower($name);
|
||||
@@ -1197,16 +1210,9 @@ class BibEntry {
|
||||
// but instead could contain HTML code (with links using the character "~" for example)
|
||||
// so "comment" is not transformed too
|
||||
if ($name!='url' && $name!='comment') {
|
||||
// 1. trim space
|
||||
$value = xtrim($value);
|
||||
|
||||
if (c('BIBTEXBROWSER_USE_LATEX2HTML')) {
|
||||
// 2. transform Latex markup to HTML entities (easier than a one to one mapping to each character)
|
||||
// HTML entity is an intermediate format
|
||||
$value = latex2html($value);
|
||||
|
||||
// 3. transform to the target output encoding
|
||||
$value = html_entity_decode($value, ENT_QUOTES|ENT_XHTML, OUTPUT_ENCODING);
|
||||
$value = $this->transformValue($value);
|
||||
}
|
||||
|
||||
// 4. transform existing encoded character in the new format
|
||||
@@ -1442,16 +1448,20 @@ class BibEntry {
|
||||
* encoded in USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT and USE_INITIALS_FOR_NAMES
|
||||
*/
|
||||
function formatAuthor($author){
|
||||
$author = $this->transformValue($author);
|
||||
if (bibtexbrowser_configuration('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT')) {
|
||||
return $this->formatAuthorCommaSeparated($author);
|
||||
} else if (bibtexbrowser_configuration('USE_INITIALS_FOR_NAMES')) {
|
||||
}
|
||||
|
||||
if (bibtexbrowser_configuration('USE_INITIALS_FOR_NAMES')) {
|
||||
return $this->formatAuthorInitials($author);
|
||||
} else if (bibtexbrowser_configuration('USE_FIRST_THEN_LAST')) {
|
||||
}
|
||||
|
||||
if (bibtexbrowser_configuration('USE_FIRST_THEN_LAST')) {
|
||||
return $this->formatAuthorCanonical($author);
|
||||
}
|
||||
|
||||
// otherwise to formatting
|
||||
else return $author;
|
||||
return $author;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3718,24 +3728,21 @@ class BibDataBase {
|
||||
* and values <LastName, FirstName>.
|
||||
*/
|
||||
function authorIndex(){
|
||||
$result = array();
|
||||
$tmp = array();
|
||||
foreach ($this->bibdb as $bib) {
|
||||
foreach($bib->getRawAuthors() as $a){
|
||||
foreach($bib->getFormattedAuthorsArray() as $a){
|
||||
$a = strip_tags($a);
|
||||
//we use an array because several authors can have the same lastname
|
||||
@$result[$bib->getLastName($a)][$bib->formatAuthor($a)]++;
|
||||
@$tmp[$bib->getLastName($a)]=$a;
|
||||
}
|
||||
}
|
||||
ksort($result);
|
||||
|
||||
// now authors are sorted by last name
|
||||
// we rebuild a new array for having good keys in author page
|
||||
$realresult = array();
|
||||
foreach($result as $x) {
|
||||
ksort($x);
|
||||
foreach($x as $v => $tmp) $realresult[$v] = $v;
|
||||
ksort($tmp);
|
||||
$result=array();
|
||||
foreach ($tmp as $k=>$v) {
|
||||
$result[$v]=$v;
|
||||
}
|
||||
|
||||
return $realresult;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** Generates and returns an array consisting of all tags.
|
||||
|
||||
Reference in New Issue
Block a user