bibtex.cgi 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/usr/bin/perl
  2. #######################################################
  3. # Copyright 2013 Sam Flint,
  4. # Project: bibtexonline
  5. # File: bibtex.cgi
  6. #
  7. # Licensed the GNU GPL v3 or later
  8. #
  9. #
  10. #
  11. #######################################################
  12. #use YAML qw/LoadFile DumpFile/;
  13. use CGI;
  14. use BibTeX::Parser;
  15. use IO::File;
  16. $cgi = CGI->new();
  17. $file = IO::File->new("./library.bib");
  18. $parser = BibTeX::Parser->new($file);
  19. if ($cgi->param('search')) {
  20. print $cgi->header();
  21. print <<eohtml;
  22. <html>
  23. <head>
  24. <title>BibTeX Web interface</title>
  25. </head>
  26. <body>
  27. <h1>BibTeX Web Interface</h1>
  28. <table width="100%">
  29. <tr>
  30. <td align="left"><a href="bibtex.cgi">Main Listing</a></td>
  31. <td align="left"><a href="bibtex.cgi?page=search">Advanced Search</a></td>
  32. <td align="left"><a href="bibtex.cgi?page=about">About</a></td>
  33. <td align="right"><form action="bibtex.cgi" method="get">Quick Search:<input type="text" name="query" value="Search Here" /> <select name="search"><option value="all">All</option><option value="ByID">By ID</option><option value="author">Author</option><option value="title">Title</option></select> Regex? <input type="checkbox" name="regex" value="yes" /> <input type="submit" value="Search" /></form></td>
  34. </tr>
  35. </table>
  36. <hr />
  37. eohtml
  38. if ($cgi->param('search') eq "all") {
  39. searchall();
  40. }elsif ($cgi->param('search') eq "ByID") {
  41. searchbyid();
  42. }elsif ($cgi->param('search') eq "author") {
  43. searchauthor();
  44. }elsif ($cgi->param('search') eq "title") {
  45. searchtitle();
  46. }
  47. print <<eohtml;
  48. Powered by BibTex.cgi
  49. </body>
  50. </html>
  51. eohtml
  52. }elsif ($cgi->param('page')) {
  53. print $cgi->header();
  54. print <<eohtml;
  55. <html>
  56. <head>
  57. <title>BibTeX Web interface</title>
  58. </head>
  59. <body>
  60. <h1>BibTeX Web Interface</h1>
  61. <table width="100%">
  62. <tr>
  63. <td align="left"><a href="bibtex.cgi">Main Listing</a></td>
  64. <td align="left"><a href="bibtex.cgi?page=search">Advanced Search</a></td>
  65. <td align="left"><a href="bibtex.cgi?page=about">About</a></td>
  66. <td align="right"><form action="bibtex.cgi" method="get">Quick Search:<input type="text" name="query" value="Search Here" /> <select name="search"><option value="all">All</option><option value="ByID">By ID</option><option value="author">Author</option><option value="title">Title</option></select> Regex? <input type="checkbox" name="regex" value="yes" /> <input type="submit" value="Search" /></form></td>
  67. </tr>
  68. </table>
  69. <hr />
  70. eohtml
  71. if ($cgi->param("page") eq "search") {
  72. }elsif ($cgi->param("page") eq "about") {
  73. }else {
  74. print "<h1>404: Page Not Found</h1><br /><br /><br /><br /><br /><br /><br /></hr>";
  75. }
  76. print <<eohtml;
  77. Powered by BibTex.cgi
  78. </body>
  79. </html>
  80. eohtml
  81. #}elsif ($cgi->param('search')) {
  82. }else {
  83. print $cgi->header();
  84. print <<eohtml;
  85. <html>
  86. <head>
  87. <title>BibTeX Web interface</title>
  88. </head>
  89. <body>
  90. <h1>BibTeX Web Interface</h1>
  91. <table width="100%">
  92. <tr>
  93. <td align="left"><a href="bibtex.cgi">Main Listing</a></td>
  94. <td align="left"><a href="bibtex.cgi?page=search">Advanced Search</a></td>
  95. <td align="left"><a href="bibtex.cgi?page=about">About</a></td>
  96. <td align="right"><form action="bibtex.cgi" method="get">Quick Search:<input type="text" name="query" value="Search Here" /> <select name="search"><option value="all">All</option><option value="ByID">By ID</option><option value="author">Author</option><option value="title">Title</option></select> Regex? <input type="checkbox" name="regex" value="yes" /> <input type="submit" value="Search" /></form></td>
  97. </tr>
  98. </table>
  99. <hr />
  100. eohtml
  101. while ($entry = $parser->next) {
  102. print <<eohtml;
  103. <h3>Key: <a href="bibtex.cgi?search=ByID&query=$entry->key()">$entry->jkey()</a></h3>
  104. <table>
  105. <tr><td>Type</td><td>$entry->type()</td></tr>
  106. <tr><td>Author</td><td>$entry->field("author")</td></tr>
  107. <tr><td>Title</td><td>$entry->field("title")</td></tr>
  108. <tr><td>Year</td><td>$entry->field("year")</td></tr>
  109. </table>
  110. <hr />
  111. eohtml
  112. }
  113. print <<eohtml;
  114. Powered by BibTex.cgi
  115. </body>
  116. </html>
  117. eohtml
  118. }
  119. sub searchall{
  120. while ($entry = $parser->next()) {
  121. if ($entry->raw_bibtex() ~= /$cgi->param("query")/g) {
  122. print <<eohtml;
  123. <h3>Key: <a href="bibtex.cgi?search=ByID&query=$entry->key()">$entry->jkey()</a></h3>
  124. <table>
  125. <tr><td>Type</td><td>$entry->type()</td></tr>
  126. <tr><td>Author</td><td>$entry->field("author")</td></tr>
  127. <tr><td>Title</td><td>$entry->field("title")</td></tr>
  128. <tr><td>Year</td><td>$entry->field("year")</td></tr>
  129. </table>
  130. <hr />
  131. eohtml
  132. }else {
  133. next;
  134. }
  135. }
  136. }
  137. sub searchbyid{
  138. while ($entry = $parser->next()) {
  139. if ($entry->key() eq $cgi->param("query")) {
  140. print <<eohtml;
  141. <h3>Key: <a href="bibtex.cgi?search=ByID&query=$entry->key()">$entry->jkey()</a></h3>
  142. <table>
  143. <tr><td>Type</td><td>$entry->type()</td></tr>
  144. <tr><td>Author</td><td>$entry->field("author")</td></tr>
  145. <tr><td>Title</td><td>$entry->field("title")</td></tr>
  146. <tr><td>Year</td><td>$entry->field("year")</td></tr>
  147. </table>
  148. <hr />
  149. eohtml
  150. }else {
  151. next;
  152. }
  153. }
  154. }
  155. sub searchauthor{
  156. while ($entry = $parser->next()) {
  157. if ($entry->field("author") ~= /$cgi->param(query)/gi {
  158. print <<eohtml;
  159. <h3>Key: <a href="bibtex.cgi?search=ByID&query=$entry->key()">$entry->jkey()</a></h3>
  160. <table>
  161. <tr><td>Type</td><td>$entry->type()</td></tr>
  162. <tr><td>Author</td><td>$entry->field("author")</td></tr>
  163. <tr><td>Title</td><td>$entry->field("title")</td></tr>
  164. <tr><td>Year</td><td>$entry->field("year")</td></tr>
  165. </table>
  166. <hr />
  167. eohtml
  168. }else {
  169. next;
  170. }
  171. }
  172. }
  173. sub searchtitle{
  174. while ($entry = $parser->next()) {
  175. if ($entry->field("title") ~= /$cgi->param(query)/gi {
  176. print <<eohtml;
  177. <h3>Key: <a href="bibtex.cgi?search=ByID&query=$entry->key()">$entry->jkey()</a></h3>
  178. <table>
  179. <tr><td>Type</td><td>$entry->type()</td></tr>
  180. <tr><td>Author</td><td>$entry->field("author")</td></tr>
  181. <tr><td>Title</td><td>$entry->field("title")</td></tr>
  182. <tr><td>Year</td><td>$entry->field("year")</td></tr>
  183. </table>
  184. <hr />
  185. eohtml
  186. }else {
  187. next;
  188. }
  189. }
  190. }
  191. __END__