Changeset 2598817
- Timestamp:
- 09/14/2021 04:07:51 PM (5 years ago)
- File:
-
- 1 edited
-
wp-publications/trunk/bibtexbrowser.php (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-publications/trunk/bibtexbrowser.php
r1830364 r2598817 4 4 Questions & Bug Reports: https://github.com/monperrus/bibtexbrowser/issues 5 5 6 (C) 2012-20 17Github contributors7 (C) 2006-20 17Martin Monperrus6 (C) 2012-2020 Github contributors 7 (C) 2006-2020 Martin Monperrus 8 8 (C) 2014 Markus Jochim 9 9 (C) 2013 Matthieu Guillaumin … … 47 47 // the changes that require existing bibtexbrowser symbols should be in bibtexbrowser.after.php (included at the end of this file) 48 48 // per bibtex file configuration 49 @include( @$_GET[Q_FILE].'.local.php');49 @include('bibtexbrowser.local.php'); 50 50 @include(preg_replace('/\.php$/','.local.php',__FILE__)); 51 51 … … 124 124 @define('BIBTEXBROWSER_BIBTEX_LINKS',true); 125 125 // do we add [pdf] links ? 126 // if the file extention is not .pdf, the field name (pdf, url, or file) is used instead 126 127 @define('BIBTEXBROWSER_PDF_LINKS',true); 127 128 // do we add [doi] links ? … … 169 170 @define('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT',false);// output authors in a comma separated form, e.g. "Meyer, H"? 170 171 @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? 172 173 @define('FORCE_NAMELIST_SEPARATOR', ''); // if non-empty, use this to separate multiple names regardless of USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT 173 174 @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 174 176 175 177 @define('TYPES_SIZE',10); // number of entry types per table … … 230 232 @define('BIBTEXBROWSER_URL',basename(__FILE__)); 231 233 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 232 241 // *************** END CONFIGURATION 233 242 … … 298 307 299 308 $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 308 310 // default bib file, if no file is specified in the query string. 309 311 if (!isset($bibtex_filenames) || $bibtex_filenames == "") { … … 323 325 $ext = pathinfo($bib, PATHINFO_EXTENSION); 324 326 // 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)) { 326 328 // to automate dectection of faulty links with tools such as webcheck 327 329 header('HTTP/1.1 404 Not found'); … … 354 356 // for sake of performance, once the bibtex file is parsed 355 357 // 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'; 357 359 358 360 $parse=filemtime(__FILE__)>@filemtime($compiledbib); … … 819 821 $this->filename = $bibfilename; 820 822 if ($handle == NULL) { 821 $handle = fopen( $bibfilename, "r");823 $handle = fopen(DATA_DIR.$bibfilename, "r"); 822 824 } 823 825 … … 1027 1029 1028 1030 $line = char2html($line,"'",'a',"acute"); 1031 $line = char2html($line,"'",'c',"acute"); 1029 1032 $line = char2html($line,"'",'e',"acute"); 1030 1033 $line = char2html($line,"'",'i',"acute"); … … 1061 1064 1062 1065 $line = char2html($line,'c','c',"cedil"); 1066 $line = char2html($line,'c','s',"cedil"); 1063 1067 $line = char2html($line,'v','s',"caron"); 1064 1068 … … 1075 1079 $line = str_replace('\\k{a}','ą',$line); 1076 1080 $line = str_replace('\\\'{c}','ć',$line); 1081 1082 $line = str_replace('\\v{c}','č',$line); 1083 $line = str_replace('\\v{C}','Č',$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); 1077 1090 1078 1091 if ($do_clean_extra_bracket) { … … 1304 1317 } 1305 1318 1306 /** same as `getPdfLink`,kept for backward compatibility */1307 function get UrlLink($iconurl, $label) {1308 return $this->get PdfLink($iconurl, $label);1319 /** kept for backward compatibility */ 1320 function getPdfLink($iconurl = NULL, $label = NULL) { 1321 return $this->getUrlLink($iconurl); 1309 1322 } 1310 1323 1311 1324 /** returns a "[pdf]" link for the entry, if possible. 1312 1325 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. 1313 1328 */ 1314 function get PdfLink($iconurl = NULL, $label = 'pdf') {1329 function getUrlLink($iconurl = NULL) { 1315 1330 if ($this->hasField('pdf')) { 1316 return $this->get Link('pdf', $iconurl, $label);1331 return $this->getAndRenameLink('pdf', $iconurl); 1317 1332 } 1318 1333 if ($this->hasField('url')) { 1319 return $this->get Link('url', $iconurl, $label);1334 return $this->getAndRenameLink('url', $iconurl); 1320 1335 } 1321 1336 // Adding link to PDF file exported by Zotero 1322 1337 // ref: https://github.com/monperrus/bibtexbrowser/pull/14 1323 1338 if ($this->hasField('file')) { 1324 return $this->get Link('file', $iconurl, $label);1339 return $this->getAndRenameLink('file', $iconurl); 1325 1340 } 1326 1341 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 } 1327 1356 } 1328 1357 … … 1392 1421 function getAuthor() { 1393 1422 if (array_key_exists(AUTHOR, $this->fields)) { 1394 return getFormattedAuthorsString();1423 return $this->getFormattedAuthorsString(); 1395 1424 } 1396 1425 // 2010-03-02: commented the following, it results in misleading author lists … … 1442 1471 1443 1472 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]); 1445 1474 $res = array(); 1446 1475 // we merge the remaining ones … … 1560 1589 $result .= $authors[$i].$sep; 1561 1590 } 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]; 1563 1598 return $result; 1564 1599 } … … 1580 1615 } 1581 1616 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 */ 1583 1620 function getArrayOfCommaSeparatedAuthors() { 1584 1621 $authors = array(); 1585 1622 foreach ($this->getRawAuthors() as $author) { 1623 $author = $this->transformValue($author); 1586 1624 $authors[]=$this->formatAuthorCommaSeparated($author); 1587 1625 } … … 1985 2023 1986 2024 if (BIBTEXBROWSER_PDF_LINKS) { 1987 $link = $bibentry->get PdfLink();2025 $link = $bibentry->getUrlLink(); 1988 2026 if ($link != '') { $links[] = $link; }; 1989 2027 } … … 2067 2105 function compare_bib_entry_by_year($a, $b) 2068 2106 { 2069 $yearA = (int) $a->getYear(); 2107 $yearA = (int) $a->getYear(); // 0 if no year 2070 2108 $yearB = (int) $b->getYear(); 2071 2109 … … 2411 2449 } 2412 2450 if ($type=="techreport") { 2413 $publisher = 'Technical report'; 2451 $publisher = 'Technical report, '; 2452 $publisher .=$bibentry->getField("institution"); 2414 2453 if ($bibentry->hasField("number")) { 2415 $publisher = $bibentry->getField("number"); 2416 } 2417 $publisher .=', '.$bibentry->getField("institution"); 2454 $publisher .= ' '.$bibentry->getField("number"); 2455 } 2418 2456 } 2419 2457 if ($bibentry->hasField("publisher")) { … … 2423 2461 if ($publisher!='') $entry[] = $publisher; 2424 2462 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 } 2427 2467 2428 2468 if ($bibentry->hasField('address')) $entry[] = $bibentry->getField("address"); … … 3083 3123 3084 3124 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 3085 3131 function incHeadingLevel ($by=1) { 3086 3132 $this->headingLevel += $by; … … 3104 3150 /** sets the entries to be shown */ 3105 3151 function setEntries($entries) { 3106 $this->entries = $entries;3152 $this->entries = array_values($entries); 3107 3153 } 3108 3154 … … 3162 3208 /** Displays a set of bibtex entries in an HTML table */ 3163 3209 function display() { 3164 3165 uasort($this->entries, 'compare_bib_entries'); 3210 usort($this->entries, 'compare_bib_entries'); 3166 3211 3167 3212 // now that the entries are sorted, setting the index of entries … … 3182 3227 } 3183 3228 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 // } 3193 3238 print_header_layout(); 3194 3239 … … 4166 4211 echo poweredby(); 4167 4212 4168 if ( BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT) {4213 if (c('BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT')) { 4169 4214 javascript(); 4170 4215 } … … 4191 4236 function NoWrapper($content) { 4192 4237 echo $content->display(); 4238 if (c('BIBTEXBROWSER_USE_PROGRESSIVE_ENHANCEMENT')) { 4239 javascript(); 4240 } 4193 4241 } 4194 4242
Note: See TracChangeset
for help on using the changeset viewer.