Plugin Directory

Changeset 2598817


Ignore:
Timestamp:
09/14/2021 04:07:51 PM (5 years ago)
Author:
monperrus
Message:

update with latest version of bibtexbrowser (112ceea5874532238589254bb686c62a3798bdfc)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-publications/trunk/bibtexbrowser.php

    r1830364 r2598817  
    44Questions & Bug Reports: https://github.com/monperrus/bibtexbrowser/issues
    55
    6 (C) 2012-2017 Github contributors
    7 (C) 2006-2017 Martin Monperrus
     6(C) 2012-2020 Github contributors
     7(C) 2006-2020 Martin Monperrus
    88(C) 2014 Markus Jochim
    99(C) 2013 Matthieu Guillaumin
     
    4747// the changes that require existing bibtexbrowser symbols should be in bibtexbrowser.after.php (included at the end of this file)
    4848// per bibtex file configuration
    49 @include(@$_GET[Q_FILE].'.local.php');
     49@include('bibtexbrowser.local.php');
    5050@include(preg_replace('/\.php$/','.local.php',__FILE__));
    5151
     
    124124@define('BIBTEXBROWSER_BIBTEX_LINKS',true);
    125125// do we add [pdf] links ?
     126// if the file extention is not .pdf, the field name (pdf, url, or file) is used instead
    126127@define('BIBTEXBROWSER_PDF_LINKS',true);
    127128// do we add [doi] links ?
     
    169170@define('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT',false);// output authors in a comma separated form, e.g. "Meyer, H"?
    170171@define('USE_INITIALS_FOR_NAMES',false); // use only initials for all first names?
    171 @define('USE_FIRST_THEN_LAST',false); // use only initials for all first names?
     172@define('USE_FIRST_THEN_LAST',false); // put first names before last names?
    172173@define('FORCE_NAMELIST_SEPARATOR', ''); // if non-empty, use this to separate multiple names regardless of USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT
    173174@define('LAST_AUTHOR_SEPARATOR',' and ');
     175@define('USE_OXFORD_COMMA',false); // adds an additional separator in addition to LAST_AUTHOR_SEPARATOR if there are more than two authors
    174176
    175177@define('TYPES_SIZE',10); // number of entry types per table
     
    230232@define('BIBTEXBROWSER_URL',basename(__FILE__));
    231233
     234// Specify the location of the cache file for servers that need temporary files written in a specific location
     235@define('CACHE_DIR','');
     236
     237// Specify the location of the bib file for servers that need do not allow slashes in URLs,
     238// where the bib file and bibtexbrowser.php are in different directories.
     239@define('DATA_DIR','');
     240
    232241// *************** END CONFIGURATION
    233242
     
    298307
    299308  $db = null;
    300   // Check if magic_quotes_runtime is active
    301   if(get_magic_quotes_runtime())
    302   {
    303       // Deactivate
    304       // otherwise it does not work
    305       set_magic_quotes_runtime(false);
    306   }
    307 
     309   
    308310  // default bib file, if no file is specified in the query string.
    309311  if (!isset($bibtex_filenames) || $bibtex_filenames == "") {
     
    323325    $ext = pathinfo($bib, PATHINFO_EXTENSION);
    324326    // this is a security protection
    325     if (BIBTEXBROWSER_LOCAL_BIB_ONLY && (!file_exists($bib) || strcasecmp($ext, 'bib') != 0)) {
     327    if (BIBTEXBROWSER_LOCAL_BIB_ONLY && (!file_exists(DATA_DIR.$bib) || strcasecmp($ext, 'bib') != 0)) {
    326328      // to automate dectection of faulty links with tools such as webcheck
    327329      header('HTTP/1.1 404 Not found');
     
    354356  // for sake of performance, once the bibtex file is parsed
    355357  // we try to save a "compiled" in a txt file
    356   $compiledbib = 'bibtexbrowser_'.md5($bibtex_filenames).'.dat';
     358  $compiledbib = CACHE_DIR.'bibtexbrowser_'.md5($bibtex_filenames).'.dat';
    357359
    358360  $parse=filemtime(__FILE__)>@filemtime($compiledbib);
     
    819821    $this->filename = $bibfilename;
    820822    if ($handle == NULL) {
    821       $handle = fopen($bibfilename, "r");
     823      $handle = fopen(DATA_DIR.$bibfilename, "r");
    822824    }
    823825
     
    10271029
    10281030  $line = char2html($line,"'",'a',"acute");
     1031  $line = char2html($line,"'",'c',"acute");
    10291032  $line = char2html($line,"'",'e',"acute");
    10301033  $line = char2html($line,"'",'i',"acute");
     
    10611064
    10621065  $line = char2html($line,'c','c',"cedil");
     1066  $line = char2html($line,'c','s',"cedil");
    10631067  $line = char2html($line,'v','s',"caron");
    10641068
     
    10751079  $line = str_replace('\\k{a}','&#261',$line);
    10761080  $line = str_replace('\\\'{c}','&#263',$line);
     1081
     1082  $line = str_replace('\\v{c}','&#269',$line);
     1083  $line = str_replace('\\v{C}','&#268',$line);
     1084 
     1085  // handling \textsuperscript{....} FAILS if there still are nested {}
     1086  $line = preg_replace('/\\\\textsuperscript\{(.*)\}/U','<sup>\\1</sup>', $line);
     1087 
     1088  // handling \textsubscript{....} FAILS if there still are nested {}
     1089  $line = preg_replace('/\\\\textsubscript\{(.*)\}/U','<sub>\\1</sub>', $line);
    10771090
    10781091  if ($do_clean_extra_bracket) {
     
    13041317  }
    13051318
    1306   /** same as `getPdfLink`, kept for backward compatibility */
    1307   function getUrlLink($iconurl, $label) {
    1308     return $this->getPdfLink($iconurl, $label);
     1319  /** kept for backward compatibility */
     1320  function getPdfLink($iconurl = NULL, $label = NULL) {
     1321    return $this->getUrlLink($iconurl);
    13091322  }
    13101323
    13111324  /** returns a "[pdf]" link for the entry, if possible.
    13121325      Tries to get the target URL from the 'pdf' field first, then from 'url' or 'file'.
     1326      Performs a sanity check that the file extension is 'pdf' or 'ps' and uses that as link label.
     1327      Otherwise (and if no explicit $label is set) the field name is used instead.
    13131328    */
    1314   function getPdfLink($iconurl = NULL, $label = 'pdf') {
     1329  function getUrlLink($iconurl = NULL) {
    13151330    if ($this->hasField('pdf')) {
    1316       return $this->getLink('pdf', $iconurl, $label);
     1331      return $this->getAndRenameLink('pdf', $iconurl);
    13171332    }
    13181333    if ($this->hasField('url')) {
    1319       return $this->getLink('url', $iconurl, $label);
     1334      return $this->getAndRenameLink('url', $iconurl);
    13201335    }
    13211336    // Adding link to PDF file exported by Zotero
    13221337    // ref: https://github.com/monperrus/bibtexbrowser/pull/14
    13231338    if ($this->hasField('file')) {
    1324       return $this->getLink('file', $iconurl, $label);
     1339      return $this->getAndRenameLink('file', $iconurl);
    13251340    }
    13261341    return "";
     1342  }
     1343
     1344  /** See description of 'getUrlLink'
     1345    */
     1346  function getAndRenameLink($bibfield, $iconurl=NULL) {
     1347    $extension = strtolower(pathinfo(parse_url($this->getField($bibfield),PHP_URL_PATH),PATHINFO_EXTENSION));
     1348    switch ($extension) {
     1349      // overriding the label if it's a known extension
     1350      case 'html': return $this->getLink($bibfield, $iconurl, 'html'); break;
     1351      case 'pdf': return $this->getLink($bibfield, $iconurl, 'pdf'); break;
     1352      case 'ps': return $this->getLink($bibfield, $iconurl, 'ps'); break;
     1353      default:
     1354        return $this->getLink($bibfield, $iconurl, $bibfield);
     1355    }
    13271356  }
    13281357
     
    13921421  function getAuthor() {
    13931422    if (array_key_exists(AUTHOR, $this->fields)) {
    1394       return getFormattedAuthorsString();
     1423      return $this->getFormattedAuthorsString();
    13951424    }
    13961425    // 2010-03-02: commented the following, it results in misleading author lists
     
    14421471
    14431472  function split_authors() {
    1444     $array = preg_split('/ and /i', @$this->raw_fields[Q_AUTHOR]);
     1473    $array = preg_split('/ and( |$)/ims', @$this->raw_fields[Q_AUTHOR]);
    14451474    $res = array();
    14461475    // we merge the remaining ones
     
    15601589      $result .= $authors[$i].$sep;
    15611590    }
    1562     $result .= $authors[count($authors)-2].bibtexbrowser_configuration('LAST_AUTHOR_SEPARATOR'). $authors[count($authors)-1];
     1591    $lastAuthorSeperator = bibtexbrowser_configuration('LAST_AUTHOR_SEPARATOR');
     1592    // add Oxford comma if there are more than 2 authors
     1593    if (bibtexbrowser_configuration('USE_OXFORD_COMMA') && count($authors)>2) {
     1594      $lastAuthorSeperator = $sep.$lastAuthorSeperator;
     1595      $lastAuthorSeperator = preg_replace("/ {2,}/", " ", $lastAuthorSeperator); // get rid of double spaces
     1596    }
     1597    $result .= $authors[count($authors)-2].$lastAuthorSeperator.$authors[count($authors)-1];
    15631598    return $result;
    15641599  }
     
    15801615  }
    15811616
    1582   /** Returns the authors of this entry as an array in a comma-separated form */
     1617  /** Returns the authors of this entry as an array in a comma-separated form
     1618   * Mostly used to create meta tags (eg <meta>
     1619   */
    15831620  function getArrayOfCommaSeparatedAuthors() {
    15841621    $authors = array();
    15851622    foreach ($this->getRawAuthors() as $author) {
     1623      $author = $this->transformValue($author);
    15861624      $authors[]=$this->formatAuthorCommaSeparated($author);
    15871625    }
     
    19852023
    19862024  if (BIBTEXBROWSER_PDF_LINKS) {
    1987     $link = $bibentry->getPdfLink();
     2025    $link = $bibentry->getUrlLink();
    19882026    if ($link != '') { $links[] = $link; };
    19892027  }
     
    20672105function compare_bib_entry_by_year($a, $b)
    20682106{
    2069   $yearA = (int) $a->getYear();
     2107  $yearA = (int) $a->getYear(); // 0 if no year
    20702108  $yearB = (int) $b->getYear();
    20712109
     
    24112449  }
    24122450  if ($type=="techreport") {
    2413       $publisher = 'Technical report';
     2451      $publisher = 'Technical report, ';
     2452      $publisher .=$bibentry->getField("institution");
    24142453      if ($bibentry->hasField("number")) {
    2415         $publisher = $bibentry->getField("number");
    2416       }
    2417       $publisher .=', '.$bibentry->getField("institution");
     2454        $publisher .= ' '.$bibentry->getField("number");
     2455      }
    24182456  }
    24192457  if ($bibentry->hasField("publisher")) {
     
    24232461  if ($publisher!='') $entry[] = $publisher;
    24242462
    2425   if ($bibentry->hasField('volume')) $entry[] =  "vol. ".$bibentry->getField("volume");
    2426   if ($bibentry->hasField('number')) $entry[] =  'no. '.$bibentry->getField("number");
     2463  if ($type=="article") {
     2464    if ($bibentry->hasField('volume')) $entry[] =  "vol. ".$bibentry->getField("volume");
     2465    if ($bibentry->hasField('number')) $entry[] =  'no. '.$bibentry->getField("number");
     2466  }
    24272467
    24282468  if ($bibentry->hasField('address')) $entry[] =  $bibentry->getField("address");
     
    30833123
    30843124  var $headingLevel = BIBTEXBROWSER_HTMLHEADINGLEVEL;
     3125
     3126  function __construct($db = NULL, $query = array()) {
     3127    if ($db == NULL) return;
     3128    $this->setEntries($db->multisearch($query));
     3129  }
     3130
    30853131  function incHeadingLevel ($by=1) {
    30863132    $this->headingLevel += $by;
     
    31043150  /** sets the entries to be shown */
    31053151  function setEntries($entries) {
    3106     $this->entries = $entries;
     3152    $this->entries = array_values($entries);
    31073153  }
    31083154
     
    31623208  /** Displays a set of bibtex entries in an HTML table */
    31633209  function display() {
    3164 
    3165     uasort($this->entries, 'compare_bib_entries');
     3210    usort($this->entries, 'compare_bib_entries');
    31663211
    31673212    // now that the entries are sorted, setting the index of entries
     
    31823227    }
    31833228
    3184     if ($this->headingLevel == BIBTEXBROWSER_HTMLHEADINGLEVEL) {
    3185       echo "\n".'<span class="count">';
    3186       if (count($this->entries) == 1) {
    3187         echo count ($this->entries).' '.__('result');
    3188       } else if (count($this->entries) != 0) {
    3189         echo count ($this->entries).' '.__('results');
    3190       }
    3191       echo "</span>\n";
    3192     }
     3229//     if ($this->headingLevel == BIBTEXBROWSER_HTMLHEADINGLEVEL) {
     3230//       echo "\n".'<span class="count">';
     3231//       if (count($this->entries) == 1) {
     3232//         echo count ($this->entries).' '.__('result');
     3233//       } else if (count($this->entries) != 0) {
     3234//         echo count ($this->entries).' '.__('results');
     3235//       }
     3236//       echo "</span>\n";
     3237//     }
    31933238    print_header_layout();
    31943239
     
    41664211  echo poweredby();
    41674212
    4168   if (BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT) {
     4213  if (c('BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT')) {
    41694214    javascript();
    41704215  }
     
    41914236function NoWrapper($content) {
    41924237  echo $content->display();
     4238  if (c('BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT')) {
     4239    javascript();
     4240  }
    41934241}
    41944242
Note: See TracChangeset for help on using the changeset viewer.