Browse Source

fix #72

pull/81/merge
Martin Monperrus 8 years ago
parent
commit
8bc8f77665
  1. 27
      bibtexbrowser-test.php
  2. 18
      bibtexbrowser.php

27
bibtexbrowser-test.php

@ -90,6 +90,16 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('<a class="bibanchor" name=""></a>',$first_entry->anchor());
}
function extract_css_classes($str) {
$xml = new SimpleXMLElement($str);
$css_classes = array();
foreach($xml->xpath('//node()/@class') as $v) {
$css_classes[] = $v->__toString();
};
sort($css_classes);
return $css_classes;
}
function test_bibentry_to_html_article() {
$btb = $this->createDB();
$first_entry=$btb->getEntryByKey('aKeyA');
@ -99,21 +109,28 @@ class BTBTest extends PHPUnit_Framework_TestCase {
// default style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','DefaultBibliographyStyle');
$this->assertEquals("An Article (Foo Bar and Jane Doe), In New Results, volume 5, 2009. [bibtex]",strip_tags($first_entry->toHTML()));
$this->assertEquals('<span itemscope="" itemtype="http://schema.org/ScholarlyArticle"><span class="bibtitle" itemprop="name">An Article</span> (<span class="bibauthor"><span itemprop="author" itemtype="http://schema.org/Person">Foo Bar</span> and <span itemprop="author" itemtype="http://schema.org/Person">Jane Doe</span></span>), <span class="bibbooktitle">In <span itemprop="isPartOf">New Results</span></span>, volume 5, <span itemprop="datePublished">2009</span>.<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.atitle=An+Article&amp;rft.jtitle=New+Results&amp;rft.volume=5&amp;rft.issue=&amp;rft.pub=&amp;rfr_id=info%3Asid%2F%3A&amp;rft.date=2009&amp;rft.au=Foo+Bar&amp;rft.au=Jane+Doe"></span></span> <span class="bibmenu"><a class="biburl" title="aKeyA" href="bibtexbrowser.php?key=aKeyA&amp;bib=inline">[bibtex]</a></span>',$first_entry->toHTML());
bibtexbrowser_configure('BIBTEXBROWSER_LINK_STYLE','nothing');
$this->assertEquals("An Article (Foo Bar and Jane Doe), In New Results, volume 5, 2009. ",strip_tags($first_entry->toHTML()));
$this->assertEquals('<span itemscope="" itemtype="http://schema.org/ScholarlyArticle"><span class="bibtitle" itemprop="name">An Article</span> (<span class="bibauthor"><span itemprop="author" itemtype="http://schema.org/Person">Foo Bar</span> and <span itemprop="author" itemtype="http://schema.org/Person">Jane Doe</span></span>), <span class="bibbooktitle">In <span itemprop="isPartOf">New Results</span></span>, volume 5, <span itemprop="datePublished">2009</span>.<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.atitle=An+Article&amp;rft.jtitle=New+Results&amp;rft.volume=5&amp;rft.issue=&amp;rft.pub=&amp;rfr_id=info%3Asid%2F%3A&amp;rft.date=2009&amp;rft.au=Foo+Bar&amp;rft.au=Jane+Doe"></span></span> ',$first_entry->toHTML());
// listing the CSS classes
$css_classes_before = $this->extract_css_classes($first_entry->toHTML());
// IEEE style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','JanosBibliographyStyle');
$this->assertEquals("Foo Bar and Jane Doe, \"An Article\", In New Results, vol. 5, pp. 1-2, 2009.\n [bibtex]",strip_tags($first_entry->toHTML()));
$this->assertEquals("Foo Bar and Jane Doe, \"An Article\", In New Results, vol. 5, pp. 1-2, 2009.\n ",strip_tags($first_entry->toHTML()));
$css_classes_after = $this->extract_css_classes($first_entry->toHTML());
// contract: make sure the Janos style and default style use the same CSS classes
$this->assertEquals($css_classes_before, $css_classes_after);
// Vancouver style
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','VancouverBibliographyStyle');
$this->assertEquals("Foo Bar and Jane Doe. An Article. New Results. 2009;5:1-2.\n [bibtex]",strip_tags($first_entry->toHTML()));
$this->assertEquals("Foo Bar and Jane Doe. An Article. New Results. 2009;5:1-2.\n ",strip_tags($first_entry->toHTML()));
// changing the target
bibtexbrowser_configure('BIBLIOGRAPHYSTYLE','DefaultBibliographyStyle');
bibtexbrowser_configure('BIBTEXBROWSER_LINKS_TARGET','_top');
$this->assertEquals('<span itemscope="" itemtype="http://schema.org/ScholarlyArticle"><span class="bibtitle" itemprop="name">An Article</span> (<span class="bibauthor"><span itemprop="author" itemtype="http://schema.org/Person">Foo Bar</span> and <span itemprop="author" itemtype="http://schema.org/Person">Jane Doe</span></span>), <span class="bibbooktitle">In <span itemprop="isPartOf">New Results</span></span>, volume 5, <span itemprop="datePublished">2009</span>.<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.atitle=An+Article&amp;rft.jtitle=New+Results&amp;rft.volume=5&amp;rft.issue=&amp;rft.pub=&amp;rfr_id=info%3Asid%2F%3A&amp;rft.date=2009&amp;rft.au=Foo+Bar&amp;rft.au=Jane+Doe"></span></span> <span class="bibmenu"><a target="_top" class="biburl" title="aKeyA" href="bibtexbrowser.php?key=aKeyA&amp;bib=inline">[bibtex]</a></span>',$first_entry->toHTML());
$this->assertEquals('<span itemscope="" itemtype="http://schema.org/ScholarlyArticle"><span class="bibtitle" itemprop="name">An Article</span> (<span class="bibauthor"><span itemprop="author" itemtype="http://schema.org/Person">Foo Bar</span> and <span itemprop="author" itemtype="http://schema.org/Person">Jane Doe</span></span>), <span class="bibbooktitle">In <span itemprop="isPartOf">New Results</span></span>, volume 5, <span itemprop="datePublished">2009</span>.<span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.atitle=An+Article&amp;rft.jtitle=New+Results&amp;rft.volume=5&amp;rft.issue=&amp;rft.pub=&amp;rfr_id=info%3Asid%2F%3A&amp;rft.date=2009&amp;rft.au=Foo+Bar&amp;rft.au=Jane+Doe"></span></span> ',$first_entry->toHTML());
}

18
bibtexbrowser.php

@ -118,7 +118,7 @@ if (defined('ENCODING')) {
@define('BIBTEXBROWSER_NO_DEFAULT', false);
// BIBTEXBROWSER_LINK_STYLE defines which function to use to display the links of a bibtex entry
@define('BIBTEXBROWSER_LINK_STYLE','bib2links_default');
@define('BIBTEXBROWSER_LINK_STYLE','bib2links_default'); // can be 'nothing' (a function that does nothing)
// do we add [bibtex] links ?
@define('BIBTEXBROWSER_BIBTEX_LINKS',true);
@ -241,6 +241,8 @@ define('Q_INNER_TYPE', 'x-bibtex-type');// used for representing the type of the
@ini_set("session.use_trans_sid",0);
@ini_set("url_rewriter.tags","");
function nothing() {}
function config_value($key) {
global $CONFIGURATION;
if (isset($CONFIGURATION[$key])) { return $CONFIGURATION[$key]; }
@ -2019,7 +2021,7 @@ function bib2html($bibentry) {
/** this function encapsulates the user-defined name for bib2links */
function bib2links($bibentry) {
$function = BIBTEXBROWSER_LINK_STYLE;
$function = c('BIBTEXBROWSER_LINK_STYLE');
return $function($bibentry);
}
@ -2357,11 +2359,11 @@ function JanosBibliographyStyle($bibentry) {
// author
if ($bibentry->hasField('author')) {
$entry[] = $bibentry->getFormattedAuthorsString();
$entry[] = '<span class="bibauthor">'.$bibentry->getFormattedAuthorsString().'</span>';
}
// title
$title = '"'.$title.'"';
$title = '"'.'<span class="bibtitle">'.$title.'</span>'.'"';
if ($bibentry->hasField('url')) $title = ' <a'.get_target().' href="'.$bibentry->getField('url').'">'.$title.'</a>';
$entry[] = $title;
@ -2374,15 +2376,15 @@ function JanosBibliographyStyle($bibentry) {
}
if ($type=="inproceedings" && $bibentry->hasField(BOOKTITLE)) {
$booktitle = 'In '.$bibentry->getField(BOOKTITLE);
$booktitle = '<span class="bibbooktitle">'.'In '.$bibentry->getField(BOOKTITLE).'</span>';
}
if ($type=="incollection" && $bibentry->hasField(BOOKTITLE)) {
$booktitle = 'Chapter in '.$bibentry->getField(BOOKTITLE);
$booktitle = '<span class="bibbooktitle">'.'Chapter in '.$bibentry->getField(BOOKTITLE).'</span>';
}
if ($type=="article" && $bibentry->hasField("journal")) {
$booktitle = 'In '.$bibentry->getField("journal");
$booktitle = '<span class="bibbooktitle">'.'In '.$bibentry->getField("journal").'</span>';
}
@ -2435,7 +2437,7 @@ function JanosBibliographyStyle($bibentry) {
// add the Coin URL
$result .= "\n".$bibentry->toCoins();
return $result;
return '<span itemscope="" itemtype="http://schema.org/ScholarlyArticle">'.$result.'</span>';
}

Loading…
Cancel
Save