PageRenderTime 63ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/contrib/biblio/bibtexParse/PARSEENTRIES.php

https://github.com/scf/scf
PHP | 639 lines | 415 code | 17 blank | 207 comment | 89 complexity | 4225547dddd03bf3d1215df3224418af MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. v21
  4. Inspired by an awk BibTeX parser written by Nelson H. F. Beebe over 20 years ago although
  5. little of that remains.
  6. Released through http://bibliophile.sourceforge.net under the GPL licence.
  7. Do whatever you like with this -- some credit to the author(s) would be appreciated.
  8. A collection of PHP classes to manipulate bibtex files.
  9. If you make improvements, please consider contacting the administrators at bibliophile.sourceforge.net
  10. so that your improvements can be added to the release package.
  11. Mark Grimshaw 2006
  12. http://bibliophile.sourceforge.net
  13. (Amendments to file reading Daniel Pozzi for v1.1)
  14. 11/June/2005 - v1.53 Mark Grimshaw: Stopped expansion of @string when entry is enclosed in {...} or "..."
  15. 21/08/2004 v1.4 Guillaume Gardey, Added PHP string parsing and expand macro features.
  16. Fix bug with comments, strings macro.
  17. expandMacro = FALSE/TRUE to expand string macros.
  18. loadStringMacro($bibtex_string) to load a string. (array of lines)
  19. 22/08/2004 v1.4 Mark Grimshaw - a few adjustments to Guillaume's code.
  20. 28/04/2005 v1.5 Mark Grimshaw - a little debugging for @preamble
  21. 02/05/2005 G. Gardey - Add support for @string macro defined by curly brackets:
  22. @string{M12 = {December}}
  23. - Don't expand macro for bibtexCitation and bibtexEntryType
  24. - Better support for fields like journal = {Journal of } # JRNL23
  25. 03/05/2005 G. Gardey - Fix wrong field value parsing when an entry ends by
  26. someField = {value}}
  27. v2 ****************************************** v2
  28. 30/01/2006 v2.0 Esteban Zimanyi
  29. - Add support for @string defined by other strings as in @string( AA = BB # " xx " # C }
  30. - Add support for comments as defined in Bibtex, i.e., ignores everything that is outside
  31. entries delimited by '@' and the closing delimiter. In particular, comments in Bibtex do not
  32. necessarily have a % at the begining of the line !
  33. This required a complete rewrite of many functions as well as writing new ones !
  34. 31/01/2006 Mark Grimshaw
  35. - Ensured that @comment{...} is ignored in parseEntry().
  36. - Modified extractEntries() to ensure that entries where the start brace/parenthesis is on a
  37. new line are properly parsed.
  38. 10/02/2006 Mark Grimshaw
  39. - A 4th array, $this->undefinedStrings, is now returned that holds field values that are judged to be undefined strings.
  40. i.e. they are a non-numeric value that is not defined in a @string{...} entry and not enclosed by braces or double-quotes.
  41. This array will be empty unless the following condition is met:
  42. ($this->removeDelimit || $this->expandMacro && $this->fieldExtract)
  43. 24/04/2006 Esteban Zimanyi
  44. - When an undefined string is found in function removeDelimiters return the empty string
  45. - Return $this->undefinedStrings in the last position to allow compatibility with previous versions
  46. - Fix management of preamble in function returnArrays
  47. */
  48. // For a quick command-line test (php -f PARSEENTRIES.php) after installation, uncomment these lines:
  49. require_once(drupal_get_path('module', 'biblio') . '/biblio.contributors.inc');
  50. /*************************
  51. // Parse a file
  52. $parse = NEW PARSEENTRIES();
  53. $parse->expandMacro = TRUE;
  54. // $array = array("RMP" =>"Rev., Mod. Phys.");
  55. // $parse->loadStringMacro($array);
  56. // $parse->removeDelimit = FALSE;
  57. // $parse->fieldExtract = FALSE;
  58. $parse->openBib("bib.bib");
  59. $parse->extractEntries();
  60. $parse->closeBib();
  61. list($preamble, $strings, $entries, $undefinedStrings) = $parse->returnArrays();
  62. print_r($preamble);
  63. print "\n";
  64. print_r($strings);
  65. print "\n";
  66. print_r($entries);
  67. print "\n\n";
  68. *************************/
  69. /************************
  70. // Parse a bibtex PHP string
  71. $bibtex_data = <<< END
  72. @STRING{three = "THREE"}
  73. @STRING{two = "TWO"}
  74. @string{JRNL23 = {NatLA 23 } # " " # two # " " # three}
  75. @article{klitzing.1,
  76. author = "v. Klitzing and Dorda and Pepper",
  77. title = "New method for high mark@sirfragalot.com accuracy determination of fine structure constant based on quantized hall resistance",
  78. volume = "45",
  79. journal = {Journal of } # JRNL23,
  80. pages = "494",
  81. citeulike-article-id = {12222
  82. }
  83. ,
  84. ignoreMe = {blah}, }
  85. @article
  86. {
  87. klitzing.2,
  88. author = "Klaus von Klitzing",
  89. title = "The Quantized Hall Effect",
  90. volume = "58",
  91. journal = two,
  92. pages = "519",
  93. }
  94. END;
  95. $parse = NEW PARSEENTRIES();
  96. $parse->expandMacro = TRUE;
  97. // $parse->removeDelimit = FALSE;
  98. // $parse->fieldExtract = FALSE;
  99. $array = array("RMP" =>"Rev., Mod. Phys.");
  100. $parse->loadStringMacro($array);
  101. $parse->loadBibtexString($bibtex_data);
  102. $parse->extractEntries();
  103. list($preamble, $strings, $entries, $undefinedStrings) = $parse->returnArrays();
  104. print_r($preamble);
  105. print "\n";
  106. print_r($strings);
  107. print "\n";
  108. print_r($entries);
  109. print "\n\n";
  110. **********************/
  111. class PARSEENTRIES
  112. {
  113. /**
  114. * @return unknown_type
  115. */
  116. function PARSEENTRIES()
  117. {
  118. require_once(drupal_get_path('module', 'biblio') . '/bibtexParse/transtab_latex_unicode.inc.php');
  119. $this->preamble = $this->strings = $this->undefinedStrings = $this->entries = array();
  120. $this->count = 0;
  121. $this->fieldExtract = TRUE;
  122. $this->removeDelimit = TRUE;
  123. $this->expandMacro = FALSE;
  124. $this->parseFile = TRUE;
  125. $this->outsideEntry = TRUE;
  126. $this->translate_latex = TRUE;
  127. }
  128. // Open bib file
  129. /**
  130. * @param $file
  131. * @return none
  132. */
  133. function openBib($file)
  134. {
  135. if(!is_file($file))
  136. die;
  137. $this->fid = fopen ($file,'r');
  138. $this->parseFile = TRUE;
  139. }
  140. // Load a bibtex string to parse it
  141. function loadBibtexString($bibtex_string)
  142. {
  143. if(is_string($bibtex_string)) {
  144. //$bibtex_string = $this->searchReplaceText($this->transtab_latex_unicode, $bibtex_string, false);
  145. $this->bibtexString = explode("\n",$bibtex_string);
  146. } else {
  147. $this->bibtexString = $bibtex_string;
  148. }
  149. $this->parseFile = FALSE;
  150. $this->currentLine = 0;
  151. }
  152. function searchReplaceText($searchReplaceActionsArray, $sourceString, $includesSearchPatternDelimiters=FALSE)
  153. {
  154. // apply the search & replace actions defined in '$searchReplaceActionsArray' to the text passed in '$sourceString':
  155. foreach ($searchReplaceActionsArray as $searchString => $replaceString)
  156. {
  157. if (!$includesSearchPatternDelimiters)
  158. $searchString = "/" . $searchString . "/"; // add search pattern delimiters
  159. if (preg_match($searchString, $sourceString))
  160. $sourceString = preg_replace($searchString, $replaceString, $sourceString);
  161. }
  162. return $sourceString;
  163. }
  164. // Set strings macro
  165. function loadStringMacro($macro_array)
  166. {
  167. $this->userStrings = $macro_array;
  168. }
  169. // Close bib file
  170. function closeBib()
  171. {
  172. fclose($this->fid);
  173. }
  174. // Get a non-empty line from the bib file or from the bibtexString
  175. function getLine()
  176. {
  177. if($this->parseFile)
  178. {
  179. if(!feof($this->fid))
  180. {
  181. do
  182. {
  183. $line = trim(fgets($this->fid));
  184. }
  185. while(!feof($this->fid) && !$line);
  186. return $line;
  187. }
  188. return FALSE;
  189. }
  190. else
  191. {
  192. do
  193. {
  194. $line = trim($this->bibtexString[$this->currentLine]);
  195. $this->currentLine++;
  196. }
  197. while($this->currentLine < count($this->bibtexString) && !$line);
  198. return $line;
  199. }
  200. }
  201. // Extract value part of @string field enclosed by double-quotes or braces.
  202. // The string may be expanded with previously-defined strings
  203. function extractStringValue($string)
  204. {
  205. // $string contains a end delimiter, remove it
  206. $string = trim(substr($string,0,strlen($string)-1));
  207. // remove delimiters and expand
  208. $string = $this->removeDelimitersAndExpand($string);
  209. return $string;
  210. }
  211. // Extract a field
  212. function fieldSplit($seg)
  213. {
  214. // echo "**** ";print_r($seg);echo "<BR>";
  215. // handle fields like another-field = {}
  216. $array = preg_split("/,\s*([-_.:,a-zA-Z0-9]+)\s*={1}\s*/U", $seg, PREG_SPLIT_DELIM_CAPTURE);
  217. // echo "**** ";print_r($array);echo "<BR>";
  218. //$array = preg_split("/,\s*(\w+)\s*={1}\s*/U", $seg, PREG_SPLIT_DELIM_CAPTURE);
  219. if(!array_key_exists(1, $array))
  220. return array($array[0], FALSE);
  221. return array($array[0], $array[1]);
  222. }
  223. // Extract and format fields
  224. function reduceFields($oldString)
  225. {
  226. // 03/05/2005 G. Gardey. Do not remove all occurences, juste one
  227. // * correctly parse an entry ended by: somefield = {aValue}}
  228. $lg = strlen($oldString);
  229. if($oldString[$lg-1] == "}" || $oldString[$lg-1] == ")" || $oldString[$lg-1] == ",")
  230. $oldString = substr($oldString,0,$lg-1);
  231. // $oldString = rtrim($oldString, "}),");
  232. $split = preg_split("/=/", $oldString, 2);
  233. $string = $split[1];
  234. while($string)
  235. {
  236. list($entry, $string) = $this->fieldSplit($string);
  237. $values[] = $entry;
  238. }
  239. foreach($values as $value)
  240. {
  241. $pos = strpos($oldString, $value);
  242. $oldString = substr_replace($oldString, '', $pos, strlen($value));
  243. }
  244. $rev = strrev(trim($oldString));
  245. if($rev{0} != ',')
  246. $oldString .= ',';
  247. $keys = preg_split("/=,/", $oldString);
  248. // 22/08/2004 - Mark Grimshaw
  249. // I have absolutely no idea why this array_pop is required but it is. Seems to always be
  250. // an empty key at the end after the split which causes problems if not removed.
  251. array_pop($keys);
  252. foreach($keys as $key)
  253. {
  254. $value = trim(array_shift($values));
  255. $rev = strrev($value);
  256. // remove any dangling ',' left on final field of entry
  257. if($rev{0} == ',')
  258. $value = rtrim($value, ",");
  259. if(!$value)
  260. continue;
  261. // 21/08/2004 G.Gardey -> expand macro
  262. // Don't remove delimiters now needs to know if the value is a string macro
  263. // $this->entries[$this->count][strtolower(trim($key))] = trim($this->removeDelimiters(trim($value)));
  264. $key = strtolower(trim($key));
  265. $value = trim($value);
  266. $this->entries[$this->count][$key] = $value;
  267. }
  268. // echo "**** ";print_r($this->entries[$this->count]);echo "<BR>";
  269. }
  270. // Start splitting a bibtex entry into component fields.
  271. // Store the entry type and citation.
  272. function fullSplit($entry)
  273. {
  274. $matches = preg_split("/@(.*)[{(](.*),/U", $entry, 2, PREG_SPLIT_DELIM_CAPTURE);
  275. $this->entries[$this->count]['bibtexEntryType'] = strtolower(trim($matches[1]));
  276. // sometimes a bibtex entry will have no citation key
  277. if(preg_match("/=/", $matches[2])) // this is a field
  278. $matches = preg_split("/@(.*)\s*[{(](.*)/U", $entry, 2, PREG_SPLIT_DELIM_CAPTURE);
  279. // print_r($matches); print "<P>";
  280. $this->entries[$this->count]['bibtexCitation'] = $matches[2];
  281. $this->reduceFields($matches[3]);
  282. }
  283. // Grab a complete bibtex entry
  284. function parseEntry($entry)
  285. {
  286. set_time_limit(30); // reset the script timer to avoid timeouts
  287. $entry = $this->translate_latex ? $this->searchReplaceText($this->transtab_latex_unicode, $entry, false) : $entry;
  288. $count = 0;
  289. $lastLine = FALSE;
  290. if(preg_match("/@(.*)([{(])/U", preg_quote($entry), $matches))
  291. {
  292. if(!array_key_exists(1, $matches))
  293. return $lastLine;
  294. if(preg_match("/string/i", trim($matches[1])))
  295. $this->strings[] = $entry;
  296. else if(preg_match("/preamble/i", trim($matches[1])))
  297. $this->preamble[] = $entry;
  298. else if(preg_match("/comment/i", $matches[1])); // MG (31/Jan/2006) -- ignore @comment
  299. else
  300. {
  301. if($this->fieldExtract)
  302. $this->fullSplit($entry);
  303. else
  304. $this->entries[$this->count] = $entry;
  305. $this->count++;
  306. }
  307. return $lastLine;
  308. }
  309. }
  310. // Remove delimiters from a string
  311. function removeDelimiters($string)
  312. {
  313. if($string && ($string{0} == "\""))
  314. {
  315. $string = substr($string, 1);
  316. $string = substr($string, 0, -1);
  317. }
  318. else if($string && ($string{0} == "{"))
  319. {
  320. if(strlen($string) > 0 && $string[strlen($string)-1] == "}")
  321. {
  322. $string = substr($string, 1);
  323. $string = substr($string, 0, -1);
  324. }
  325. }
  326. else if(!is_numeric($string) && !array_key_exists($string, $this->strings)
  327. && (array_search($string, $this->undefinedStrings) === FALSE))
  328. {
  329. $this->undefinedStrings[] = $string; // Undefined string that is not a year etc.
  330. return '';
  331. }
  332. return $string;
  333. }
  334. // This function works like explode('#',$val) but has to take into account whether
  335. // the character # is part of a string (i.e., is enclosed into "..." or {...} )
  336. // or defines a string concatenation as in @string{ "x # x" # ss # {xx{x}x} }
  337. function explodeString($val)
  338. {
  339. $openquote = $bracelevel = $i = $j = 0;
  340. while ($i < strlen($val))
  341. {
  342. if ($val[$i] == '"')
  343. $openquote = !$openquote;
  344. elseif ($val[$i] == '{')
  345. $bracelevel++;
  346. elseif ($val[$i] == '}')
  347. $bracelevel--;
  348. elseif ( $val[$i] == '#' && !$openquote && !$bracelevel )
  349. {
  350. $strings[] = substr($val,$j,$i-$j);
  351. $j=$i+1;
  352. }
  353. $i++;
  354. }
  355. $strings[] = substr($val,$j);
  356. return $strings;
  357. }
  358. // This function receives a string and a closing delimiter '}' or ')'
  359. // and looks for the position of the closing delimiter taking into
  360. // account the following Bibtex rules:
  361. // * Inside the braces, there can arbitrarily nested pairs of braces,
  362. // but braces must also be balanced inside quotes!
  363. // * Inside quotes, to place the " character it is not sufficient
  364. // to simply escape with \": Quotes must be placed inside braces.
  365. function closingDelimiter($val,$delimitEnd)
  366. {
  367. // echo "####>$delimitEnd $val<BR>";
  368. $openquote = $bracelevel = $i = $j = 0;
  369. while ($i < strlen($val))
  370. {
  371. // a '"' found at brace level 0 defines a value such as "ss{\"o}ss"
  372. if ($val[$i] == '"' && !$bracelevel)
  373. $openquote = !$openquote;
  374. elseif ($val[$i] == '{')
  375. $bracelevel++;
  376. elseif ($val[$i] == '}')
  377. $bracelevel--;
  378. if ( $val[$i] == $delimitEnd && !$openquote && !$bracelevel )
  379. return $i;
  380. $i++;
  381. }
  382. // echo "--> $bracelevel, $openquote";
  383. return 0;
  384. }
  385. // Remove enclosures around entry field values. Additionally, expand macros if flag set.
  386. function removeDelimitersAndExpand($string, $inpreamble = FALSE)
  387. {
  388. // only expand the macro if flag set, if strings defined and not in preamble
  389. if(!$this->expandMacro || empty($this->strings) || $inpreamble)
  390. $string = $this->removeDelimiters($string);
  391. else
  392. {
  393. $stringlist = $this->explodeString($string);
  394. $string = "";
  395. foreach ($stringlist as $str)
  396. {
  397. // trim the string since usually # is enclosed by spaces
  398. $str = trim($str);
  399. // replace the string if macro is already defined
  400. // strtolower is used since macros are case insensitive
  401. if (isset($this->strings[strtolower($str)]))
  402. $string .= $this->strings[strtolower($str)];
  403. else
  404. $string .= $this->removeDelimiters(trim($str));
  405. }
  406. }
  407. return $string;
  408. }
  409. // This function extract entries taking into account how comments are defined in BibTeX.
  410. // BibTeX splits the file in two areas: inside an entry and outside an entry, the delimitation
  411. // being indicated by the presence of a @ sign. When this character is met, BibTex expects to
  412. // find an entry. Before that sign, and after an entry, everything is considered a comment!
  413. function extractEntries()
  414. {
  415. $inside = $possibleEntryStart = FALSE;
  416. $entry="";
  417. while($line=$this->getLine())
  418. {
  419. if($possibleEntryStart)
  420. $line = $possibleEntryStart . $line;
  421. if (!$inside && strchr($line,"@"))
  422. {
  423. // throw all characters before the '@'
  424. $line=strstr($line,'@');
  425. if(!strchr($line, "{") && !strchr($line, "("))
  426. $possibleEntryStart = $line;
  427. elseif(preg_match("/@.*([{(])/U", preg_quote($line), $matches))
  428. {
  429. $inside = TRUE;
  430. if ($matches[1] == '{')
  431. $delimitEnd = '}';
  432. else
  433. $delimitEnd = ')';
  434. $possibleEntryStart = FALSE;
  435. }
  436. }
  437. if ($inside)
  438. {
  439. $entry .= " ".$line;
  440. if ($j=$this->closingDelimiter($entry,$delimitEnd))
  441. {
  442. // all characters after the delimiter are thrown but the remaining
  443. // characters must be kept since they may start the next entry !!!
  444. $lastLine = substr($entry,$j+1);
  445. $entry = substr($entry,0,$j+1);
  446. // Strip excess whitespaces from the entry
  447. $entry = preg_replace('/\s\s+/', ' ', $entry);
  448. $this->parseEntry($entry);
  449. $entry = strchr($lastLine,"@");
  450. if ($entry)
  451. $inside = TRUE;
  452. else
  453. $inside = FALSE;
  454. }
  455. }
  456. }
  457. }
  458. // Return arrays of entries etc. to the calling process.
  459. function returnArrays()
  460. {
  461. global $transtab_latex_unicode; // defined in 'transtab_latex_unicode.inc.php'
  462. foreach($this->preamble as $value)
  463. {
  464. preg_match("/.*?[{(](.*)/", $value, $matches);
  465. $preamble = substr($matches[1], 0, -1);
  466. $preambles['bibtexPreamble'] = trim($this->removeDelimitersAndExpand(trim($preamble), TRUE));
  467. }
  468. if(isset($preambles))
  469. $this->preamble = $preambles;
  470. if($this->fieldExtract)
  471. {
  472. // Next lines must take into account strings defined by previously-defined strings
  473. $strings = $this->strings;
  474. // $this->strings is initialized with strings provided by user if they exists
  475. // it is supposed that there are no substitutions to be made in the user strings, i.e., no #
  476. $this->strings = isset($this->userStrings) ? $this->userStrings : array() ;
  477. foreach($strings as $value)
  478. {
  479. // changed 21/08/2004 G. Gardey
  480. // 23/08/2004 Mark G. account for comments on same line as @string - count delimiters in string value
  481. $value = trim($value);
  482. $matches = preg_split("/@\s*string\s*([{(])/i", $value, 2, PREG_SPLIT_DELIM_CAPTURE);
  483. $delimit = $matches[1];
  484. $matches = preg_split("/=/", $matches[2], 2, PREG_SPLIT_DELIM_CAPTURE);
  485. // macros are case insensitive
  486. $this->strings[strtolower(trim($matches[0]))] = $this->extractStringValue($matches[1]);
  487. }
  488. }
  489. // changed 21/08/2004 G. Gardey
  490. // 22/08/2004 Mark Grimshaw - stopped useless looping.
  491. // removeDelimit and expandMacro have NO effect if !$this->fieldExtract
  492. if($this->removeDelimit || $this->expandMacro && $this->fieldExtract)
  493. {
  494. for($i = 0; $i < count($this->entries); $i++)
  495. {
  496. foreach($this->entries[$i] as $key => $value)
  497. // 02/05/2005 G. Gardey don't expand macro for bibtexCitation
  498. // and bibtexEntryType
  499. if($key != 'bibtexCitation' && $key != 'bibtexEntryType')
  500. $this->entries[$i][$key] = trim($this->removeDelimitersAndExpand($this->entries[$i][$key]));
  501. }
  502. }
  503. // EZ: Remove this to be able to use the same instance for parsing several files,
  504. // e.g., parsing a entry file with its associated abbreviation file
  505. // if(empty($this->preamble))
  506. // $this->preamble = FALSE;
  507. // if(empty($this->strings))
  508. // $this->strings = FALSE;
  509. // if(empty($this->entries))
  510. // $this->entries = FALSE;
  511. return array($this->preamble, $this->strings, $this->entries, $this->undefinedStrings);
  512. }
  513. function bib2node($terms = array(), $batch = FALSE, $session_id = NULL, $save = TRUE, $start = 0, $limit = 0){
  514. //list($preamble, $strings, $entries, $undefinedStrings) = $this->returnArrays();
  515. $limit = ($limit) ? $limit : count($this->entries);
  516. if (($start + $limit) > count($this->entries)) $limit = count($this->entries) - $start;
  517. for ($i = $start; $i < $limit; $i++)
  518. {
  519. $node = array();
  520. $entry = $this->entries[$i];
  521. if($this->removeDelimit || $this->expandMacro && $this->fieldExtract)
  522. {
  523. foreach($entry as $key => $value)
  524. {
  525. if($key != 'bibtexCitation' && $key != 'bibtexEntryType') {
  526. $entry[$key] = trim($this->removeDelimitersAndExpand($entry[$key]));
  527. }
  528. }
  529. }
  530. //foreach($entries as $entry){
  531. $node['biblio_contributors'] = array();
  532. $node['biblio_type'] = $this->bibtex_type_map($entry['bibtexEntryType']);
  533. switch ($entry['bibtexEntryType']){
  534. case mastersthesis:
  535. $node['biblio_type_of_work'] = 'masters';
  536. break;
  537. case phdthesis:
  538. $node['biblio_type_of_work'] = 'phd';
  539. break;
  540. }
  541. if (!empty($entry['author'])){
  542. // split on ' and '
  543. $authorArray = preg_split("/\s(and|&)\s/i", trim($entry['author']));
  544. foreach ($authorArray as $key => $author)
  545. {
  546. $node['biblio_contributors'][1][]= array('name' => $author, 'auth_type' => _biblio_get_auth_type(1, $node['biblio_type']));
  547. }
  548. }
  549. $node['biblio_citekey'] = (!empty($entry['bibtexCitation'])) ? $entry['bibtexCitation'] : NULL;
  550. if (!empty($entry['editor']))
  551. {
  552. $authorArray = preg_split("/\s(and|&)\s/i", trim($entry['editor']));
  553. foreach ($authorArray as $key => $author)
  554. {
  555. $node['biblio_contributors'][2][]= array('name' => $author, 'auth_type' => _biblio_get_auth_type(2, $node['biblio_type']));
  556. }
  557. }
  558. $node['biblio_secondary_title'] = (!empty($entry['journal'])) ? $entry['journal'] : NULL;
  559. if (!empty($entry['booktitle'])) $node['biblio_secondary_title'] = $entry['booktitle'];
  560. if (!empty($entry['series'])) $node['biblio_tertiary_title'] = $entry['series'];
  561. $node['biblio_volume'] = (!empty($entry['volume'])) ? $entry['volume'] : NULL;
  562. $node['biblio_number'] = (!empty($entry['number'])) ? $entry['number'] : NULL;
  563. $node['biblio_year'] = (!empty($entry['year'])) ? $entry['year'] : NULL;
  564. $node['biblio_notes'] = (!empty($entry['note'])) ? $entry['note'] : NULL;
  565. $node['biblio_date'] = (!empty($entry['month'])) ? $entry['month'] : NULL;
  566. $node['biblio_pages'] = (!empty($entry['pages'])) ? $entry['pages'] : NULL;
  567. $node['biblio_publisher'] = (!empty($entry['publisher'])) ? $entry['publisher'] : NULL;
  568. if (!empty($entry['organization'])) $node['biblio_publisher'] = $entry['organization'];
  569. if (!empty($entry['school'])) $node['biblio_publisher'] = $entry['school'];
  570. if (!empty($entry['institution'])) $node['biblio_publisher'] = $entry['institution'];
  571. $node['title'] = (!empty($entry['title'])) ? $entry['title'] : NULL;
  572. $node['biblio_type_of_work'] .= (!empty($entry['type'])) ? $entry['type'] : NULL;
  573. $node['biblio_edition'] = (!empty($entry['edition'])) ? $entry['edition'] : NULL;
  574. $node['biblio_section'] = (!empty($entry['chapter'])) ? $entry['chapter'] : NULL;
  575. $node['biblio_place_published'] = (!empty($entry['address'])) ? $entry['address'] : NULL;
  576. $node['biblio_abst_e'] = (!empty($entry['abstract'])) ? $entry['abstract'] : NULL;
  577. if (!empty($entry['keywords'])){
  578. if (strpos($entry['keywords'],';')) $entry['keywords'] = str_replace(';',',',$entry['keywords']);
  579. $node['biblio_keywords'] = explode(',', $entry['keywords']);
  580. }
  581. $node['biblio_isbn'] = (!empty($entry['isbn'])) ? $entry['isbn'] : NULL;
  582. $node['biblio_issn'] = (!empty($entry['issn'])) ? $entry['issn'] : NULL;
  583. $node['biblio_url'] = (!empty($entry['url'])) ? $entry['url'] : NULL;
  584. $node['biblio_doi'] = (!empty($entry['doi'])) ? $entry['doi'] : NULL;
  585. if (!empty($terms)) {
  586. if (!isset($node['taxonomy'])) $node['taxonomy'] = array();
  587. $node['taxonomy'] = array_merge($terms,$node['taxonomy']);
  588. }
  589. $nids[] = biblio_save_node($node, $batch, $session_id, $save);
  590. }
  591. return (!empty($nids)) ? $nids : NULL;
  592. }
  593. function bibtex_type_map($type) {
  594. static $map = array();
  595. if (empty($map)) {
  596. module_load_include('inc', 'biblio', 'biblio.type.mapper');
  597. $map = biblio_get_type_map('bibtex');
  598. }
  599. return (isset($map[$type])) ? $map[$type] : 129; //return the biblio type or 129 (Misc) if type not found
  600. }
  601. }