123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- #!/usr/bin/perl
- #######################################################
- # Copyright 2013 Sam Flint,
- # Project: bibtexonline
- # File: bibtex.cgi
- #
- # Licensed the GNU GPL v3 or later
- #
- #
- #
- #######################################################
- #use YAML qw/LoadFile DumpFile/;
- use CGI;
- use BibTeX::Parser;
- use IO::File;
- $cgi = CGI->new();
- $file = IO::File->new("./library.bib");
- $parser = BibTeX::Parser->new($file);
- if ($cgi->param('search')) {
- print $cgi->header();
- print <<eohtml;
- <html>
- <head>
- <title>BibTeX Web interface</title>
- </head>
- <body>
- <h1>BibTeX Web Interface</h1>
- <table width="100%">
- <tr>
- <td align="left"><a href="bibtex.cgi">Main Listing</a></td>
- <td align="left"><a href="bibtex.cgi?page=search">Advanced Search</a></td>
- <td align="left"><a href="bibtex.cgi?page=about">About</a></td>
- <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>
- </tr>
- </table>
- <hr />
- eohtml
- if ($cgi->param('search') eq "all") {
- searchall();
- }elsif ($cgi->param('search') eq "ByID") {
- searchbyid();
- }elsif ($cgi->param('search') eq "author") {
- searchauthor();
- }elsif ($cgi->param('search') eq "title") {
- searchtitle();
- }
- print <<eohtml;
- Powered by BibTex.cgi
- </body>
- </html>
- eohtml
- }elsif ($cgi->param('page')) {
- print $cgi->header();
- print <<eohtml;
- <html>
- <head>
- <title>BibTeX Web interface</title>
- </head>
- <body>
- <h1>BibTeX Web Interface</h1>
- <table width="100%">
- <tr>
- <td align="left"><a href="bibtex.cgi">Main Listing</a></td>
- <td align="left"><a href="bibtex.cgi?page=search">Advanced Search</a></td>
- <td align="left"><a href="bibtex.cgi?page=about">About</a></td>
- <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>
- </tr>
- </table>
- <hr />
- eohtml
- if ($cgi->param("page") eq "search") {
- }elsif ($cgi->param("page") eq "about") {
- }else {
- print "<h1>404: Page Not Found</h1><br /><br /><br /><br /><br /><br /><br /></hr>";
- }
- print <<eohtml;
- Powered by BibTex.cgi
- </body>
- </html>
- eohtml
- #}elsif ($cgi->param('search')) {
- }else {
- print $cgi->header();
- print <<eohtml;
- <html>
- <head>
- <title>BibTeX Web interface</title>
- </head>
- <body>
- <h1>BibTeX Web Interface</h1>
- <table width="100%">
- <tr>
- <td align="left"><a href="bibtex.cgi">Main Listing</a></td>
- <td align="left"><a href="bibtex.cgi?page=search">Advanced Search</a></td>
- <td align="left"><a href="bibtex.cgi?page=about">About</a></td>
- <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>
- </tr>
- </table>
- <hr />
- eohtml
- while ($entry = $parser->next) {
- print <<eohtml;
- <h3>Key: <a href="bibtex.cgi?search=ByID&query=$entry->key()">$entry->jkey()</a></h3>
- <table>
- <tr><td>Type</td><td>$entry->type()</td></tr>
- <tr><td>Author</td><td>$entry->field("author")</td></tr>
- <tr><td>Title</td><td>$entry->field("title")</td></tr>
- <tr><td>Year</td><td>$entry->field("year")</td></tr>
- </table>
- <hr />
- eohtml
- }
- print <<eohtml;
- Powered by BibTex.cgi
- </body>
- </html>
- eohtml
- }
- sub searchall{
- while ($entry = $parser->next()) {
- if ($entry->raw_bibtex() ~= /$cgi->param("query")/g) {
- print <<eohtml;
- <h3>Key: <a href="bibtex.cgi?search=ByID&query=$entry->key()">$entry->jkey()</a></h3>
- <table>
- <tr><td>Type</td><td>$entry->type()</td></tr>
- <tr><td>Author</td><td>$entry->field("author")</td></tr>
- <tr><td>Title</td><td>$entry->field("title")</td></tr>
- <tr><td>Year</td><td>$entry->field("year")</td></tr>
- </table>
- <hr />
- eohtml
- }else {
- next;
- }
- }
- }
- sub searchbyid{
- while ($entry = $parser->next()) {
- if ($entry->key() eq $cgi->param("query")) {
- print <<eohtml;
- <h3>Key: <a href="bibtex.cgi?search=ByID&query=$entry->key()">$entry->jkey()</a></h3>
- <table>
- <tr><td>Type</td><td>$entry->type()</td></tr>
- <tr><td>Author</td><td>$entry->field("author")</td></tr>
- <tr><td>Title</td><td>$entry->field("title")</td></tr>
- <tr><td>Year</td><td>$entry->field("year")</td></tr>
- </table>
- <hr />
- eohtml
- }else {
- next;
- }
- }
- }
- sub searchauthor{
- while ($entry = $parser->next()) {
- if ($entry->field("author") ~= /$cgi->param(query)/gi {
- print <<eohtml;
- <h3>Key: <a href="bibtex.cgi?search=ByID&query=$entry->key()">$entry->jkey()</a></h3>
- <table>
- <tr><td>Type</td><td>$entry->type()</td></tr>
- <tr><td>Author</td><td>$entry->field("author")</td></tr>
- <tr><td>Title</td><td>$entry->field("title")</td></tr>
- <tr><td>Year</td><td>$entry->field("year")</td></tr>
- </table>
- <hr />
- eohtml
- }else {
- next;
- }
- }
- }
- sub searchtitle{
- while ($entry = $parser->next()) {
- if ($entry->field("title") ~= /$cgi->param(query)/gi {
- print <<eohtml;
- <h3>Key: <a href="bibtex.cgi?search=ByID&query=$entry->key()">$entry->jkey()</a></h3>
- <table>
- <tr><td>Type</td><td>$entry->type()</td></tr>
- <tr><td>Author</td><td>$entry->field("author")</td></tr>
- <tr><td>Title</td><td>$entry->field("title")</td></tr>
- <tr><td>Year</td><td>$entry->field("year")</td></tr>
- </table>
- <hr />
- eohtml
- }else {
- next;
- }
- }
- }
- __END__
|