You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.4 KiB

  1. <?php
  2. // Project: Web Reference Database (refbase) <http://www.refbase.net>
  3. // Copyright: Matthias Steffens <mailto:refbase@extracts.de> and the file's
  4. // original author.
  5. //
  6. // This code is distributed in the hope that it will be useful,
  7. // but WITHOUT ANY WARRANTY. Please see the GNU General Public
  8. // License for more details.
  9. //
  10. // File: ./contrib/endnote/endnote2mysql.php
  11. // Author: Richard Karnesky <mailto:karnesky@northwestern.edu>
  12. //
  13. // Created: 18-Mar-05, 17:10
  14. // Modified: 19-Mar-05, 13:50
  15. // WARNING
  16. // This hasn't been tested extensively & can cause weirdness. Give the data
  17. // a once over in a spreadsheet to confirm it looks OK before import!!!
  18. // This processes the text file produced by using refbase.ens in Endnote:
  19. // - Fixes linefeeds, which Endnote can't handle well:
  20. // - trims carriage returns
  21. // - replaces newlines with '\n'
  22. // - trims '<REFBASE>' from the start of each citation
  23. // - replaces '</REFBASE>' with a newline character
  24. // - Replaces '<REFBASE J/>' with 'Journal' (a Field Name in Endnote)
  25. // - Inserts '\N' between multiple tabs (to explicitly NULL empty fields)
  26. // - Replaces '<Go to ISI>://*\t' with '\N' (bad URLs in Endnote)
  27. // TODO:
  28. // - Tabs within fields aren't replaced! This can screw things up!
  29. // - Allow people to change import & export filenames
  30. // - More fields (particularly all dates, first author, number of authors)
  31. // - Better parsing of current fields (correct use of 'ed' vs 'eds)
  32. // - Automatically import via mysql (intentionally unimplemented for safety)
  33. // - Deprecate this whole darn mess by adding native import facilities ;-)
  34. $fin = file_get_contents('endnote.txt');
  35. if (!$fin) {
  36. echo "Error! Couldn't open endnote.txt.";
  37. }
  38. else {
  39. $fin = str_replace("\r","",$fin);
  40. $fin = str_replace("\n","\\n",$fin);
  41. $fin = str_replace("<REFBASE>","",$fin);
  42. $fin = str_replace("</REFBASE>\\n","\n",$fin);
  43. $fin = str_replace("<REFBASE J/>","Journal",$fin);
  44. $fin = preg_replace("/(?<=\t)(?=\t)/","\\N",$fin);
  45. $fin = preg_replace("/<Go to ISI>:\/\/\S*/","\\N",$fin);
  46. }
  47. do {
  48. if (!($fout = fopen('import.txt', "w"))) {
  49. $rc = 1; break;
  50. }
  51. if (!fwrite($fout, $fin)) {
  52. $rc = 2; break;
  53. }
  54. $rc = true;
  55. } while (0);
  56. if ($fout) {
  57. fclose($fout);
  58. }
  59. ?>