home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / skeptic / bibliography / admin / convert.cgi < prev    next >
Text File  |  2009-08-26  |  4KB  |  166 lines

  1. #!/usr/bin/perl
  2.  
  3. # $rcs = ' $Id: convert.cgi,v 1.2 1998/06/20 04:00:04 fitz Exp $ ' ;
  4.  
  5. unshift(@INC, "../lib");
  6.  
  7. require 'config.pl';
  8. require 'bib.pl';
  9. require 'web.pl';
  10. require 'cgi-lib.pl';
  11.  
  12. %regexp =
  13.   (
  14.    #<strong>Title</strong>
  15.    #<blockquote>
  16.    # Author<br>
  17.    # Year, Publisher; Pages<br>
  18.    # <em>#Keyword#, ...</em>
  19.    #</blockquote>
  20.    #Review-Text<p>
  21.  
  22.    "book", # ($title, $author, $info, $keywords, $comment)
  23.    "<strong>(.*)</strong>.*<blockquote>(.*)<br>(.*)<br>.*<em>(.*)</em>.*</blockquote>(.*)",
  24.  
  25.    "internet", # $url, $title, $keywords, $comment
  26.    "<strong>.*href=\"?([^\"]+)\"?>(.*)</a></strong>.*<blockquote>.*<em>(.*)</em>.*</blockquote>(.*)",
  27.   );
  28.  
  29. print "Content-type: text/html\n\n";
  30. &ReadParse();
  31.  
  32. # Determine if we are running as an administrator
  33. unless ($ENV{SCRIPT_NAME} =~ /admin/)
  34. {
  35.     &error("This program must be run from the admin subdir.");
  36. }
  37.  
  38. if (! defined %in)
  39. {
  40.     print &bib::template("basic.html", "DATA",
  41.                          &bib::template("convert.html"));
  42.     exit 0;
  43. }
  44. else
  45. {
  46.     $MULTILINE_MATCHING = 1;
  47.  
  48.     $entry = $in{entry};
  49.     undef %in;
  50.  
  51.     $vars = "<FONT SIZE=2><PRE>" . &untaint($entry) . "</PRE></FONT>";
  52.  
  53.     $entry =~ s/\n/ /g;
  54.     $entry =~ s/\s+/ /g;
  55.  
  56.     # Try to figure out what kind of entry it is
  57.     if ($entry =~ /$regexp{book}/i)
  58.     {
  59.         $in{TITLE} = $1;
  60.         $in{AUTHOR} = $2;
  61.         $in{MISC} = $3;
  62.         $in{KEYWORDS} = $4;
  63.         $in{COMMENT} = $5;
  64.  
  65.         if ($in{MISC} =~ s/(19\d\d),?//i)
  66.         {
  67.             $in{YEAR} = $1;
  68.         }
  69.  
  70.         if ($in{MISC} =~ s/^(.*);//i)
  71.         {
  72.             $in{PUBLISHER} = $1;
  73.         }
  74.     }
  75.     elsif ($entry =~ /$regexp{internet}/i)
  76.     {
  77.         # $url, $title, $keywords, $comment
  78.         $in{URL} = $1;
  79.         $in{TITLE} = $2;
  80.         $in{KEYWORDS} = $3;
  81.         $in{COMMENT} = $4;
  82.         $in{CATEGORY} = "internet";
  83.     }
  84.     else
  85.     {
  86.         $in{COMMENT} = $entry;
  87.     }
  88.     $MULTILINE_MATCHING = 0;
  89.  
  90.     # Fix the inputs
  91.     @keywords = split(/\s*,\s*/, $in{KEYWORDS});
  92.     grep(s/^\s+//, @keywords);
  93.     grep(s/\s+$//, @keywords);
  94.     grep(s/\s+/_/g, @keywords);
  95.     grep(s/[^\w:-]//g, @keywords);
  96.     $in{KEYWORDS} = "@keywords";
  97.     $in{COMMENT} =~ s/<p>//i;
  98.  
  99.     %in = &remove_spaces(%in);
  100.  
  101.     &bib::load("CATEGORY", "KEYWORDS");
  102.  
  103.     # Get the categories
  104.     @categories = &bib::get_categories();
  105.     &error($bib::error) unless defined @categories;
  106.  
  107.     # Get the keywords
  108.     @keywords = &bib::get_keywords(1);
  109.     &error($bib::error) unless defined @keywords;
  110.  
  111.     # Construct a list of all current categories
  112.     # and make sure the correct one is selected
  113.     # if we are editing an existing entry
  114.     foreach $category (@categories)
  115.     {
  116.         $select = ($category eq $in{CATEGORY}) ? "SELECTED" : "";
  117.         $categories .= "<OPTION $select>$category";
  118.     }
  119.     $in{CATEGORY} = $categories;
  120.  
  121.     # Construct a list of all current keywords
  122.     # and make sure the correct ones are selected
  123.     # if we are editing an existing entry
  124.     foreach $keyword (@keywords)
  125.     {
  126.         #$select = ($in{KEYWORDS} =~ /\b$keyword\b/) ? "SELECTED" : "";
  127.         $keywords .= "<OPTION $select>$keyword";
  128.     }
  129.     $in{NEW_KEYWORDS} = $in{KEYWORDS};
  130.     $in{KEYWORDS} = $keywords;
  131.  
  132.     $data = &bib::template("edit.html", %in,
  133.  
  134.                            "FORM_ACTION",
  135.                            "ACTION=$bib::admin_cgi/edit.cgi",
  136.  
  137.                            "NEW_CATEGORY",
  138.                            "<INPUT NAME=NEW_CATEGORY VALUE=\"\">",
  139.  
  140.                            "REVERT",
  141.                            "<INPUT TYPE=reset VALUE=\"Erase Changes\">",
  142.  
  143.                            "VARS", $vars,
  144.                            "HEADING", "Create Entry",
  145.                           );
  146.     print &bib::template("basic.html",
  147.                          "TITLE", "Convert Old Entry",
  148.                          "DATA", $data);
  149. }
  150.  
  151. exit 0;
  152.  
  153.  
  154. sub remove_spaces
  155. {
  156.     my(%in) = @_;
  157.  
  158.     foreach (keys %in)
  159.     {
  160.         $in{$_} =~ s/^\s+//;
  161.         $in{$_} =~ s/\s+$//;
  162.         $in{$_} = &untaint($in{$_});
  163.     }
  164.     %in;
  165. }
  166.