home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 September / PCWorld_2000-09_cd.bin / Software / Vyzkuste / cofee / CoffeeHTML85.exe / %MAINDIR% / cgi-bin / links / links.pl < prev    next >
Encoding:
Perl Script  |  2000-07-07  |  7.1 KB  |  186 lines

  1. #!/usr/local/bin/perl
  2. ##############################################################################
  3. # Free For All Link Page        Version 2.2                                  # 
  4. # Copyright 1996 Matt Wright    mattw@worldwidemart.com                      #
  5. # Created 5/14/95               Last Modified 7/17/96                        #
  6. # Scripts Archive at:           http://www.scriptarchive.com                 #
  7. ##############################################################################
  8. #         SEE README.TXT FILE THAT CAME WITH THIS SCRIPT FOR HELP            #
  9. #   OR: Consult the Matt's Script Archive Frequently Asked Questions if you  #
  10. #   are having any problems:                                                 #
  11. #   http://www.worldwidemart.com/scripts/faq/                                #
  12. ##############################################################################
  13. # COPYRIGHT NOTICE                                                           #
  14. # Copyright 1996 Matthew M. Wright  All Rights Reserved.                     #
  15. #                                                                            #
  16. # Free For All Links may be used and modified free of charge by anyone so    #
  17. # long as this copyright notice and the comments above remain intact.  By    #
  18. # using this this code you agree to indemnify Matthew M. Wright              #
  19. # and CoffeeCup Software from any liability that might arise from it's use.  #
  20. #                                                                            #
  21. # Selling the code for this program without prior written consent is         #
  22. # expressly forbidden.  In other words, please ask first before you try and  #
  23. # make money off of my program.                                              #
  24. #                                                                            #
  25. # Obtain permission before redistributing this software over the Internet or #
  26. # in any other medium.  In all cases copyright and header must remain intact.#
  27. ##############################################################################
  28. # Define Variables
  29.  
  30. $filename = "/mnt/web/guide/worldwidemart/scripts/demos/links/links.html";
  31. $linksurl = "http://worldwidemart.com/scripts/demos/links/links.html";
  32. $linkscgi = "http://worldwidemart.com/scripts/cgi-bin/demos/links.cgi";
  33. $linkstitle = "Matt's Script Archive: Free For All Demo";
  34. $database = "/mnt/web/guide/worldwidemart/scripts/demos/links/database.txt";
  35.  
  36. # Done
  37. ##############################################################################
  38.  
  39. # Get the input
  40. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  41.  
  42. # Split the name-value pairs
  43. @pairs = split(/&/, $buffer);
  44.  
  45. foreach $pair (@pairs) {
  46.    ($name, $value) = split(/=/, $pair);
  47.  
  48.    $value =~ tr/+/ /;
  49.    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  50.    $value =~ s/<([^>]|\n)*>//g;
  51.    $value =~ s/<//g;
  52.    $value =~ s/>//g;
  53.    $FORM{$name} = $value;
  54. }
  55.  
  56. if ($FORM{'url'} eq 'http://' || $FORM{'url'} !~ /^(f|ht)tp:\/\/\w+\.\w+/) { 
  57.    &no_url; 
  58. if (!($FORM{'title'})) {
  59.    &no_title;
  60. }
  61.  
  62. # Enter our tags and sections into an associative array
  63.  
  64. %sections = ("busi","Business","comp","Computers","educ","Education",
  65.          "ente","Entertainment","gove","Government",
  66.          "pers","Personal","misc","Miscellaneous");
  67.  
  68. # Suck previous link file into one big string
  69. open(FILE,"$filename");
  70. @lines = <FILE>;
  71. close(FILE);
  72.  
  73. $i=1;
  74. foreach $line (@lines) {    
  75.     if ($line =~ /\<li\>\<a href\=\"([^\"]+)\">([^<]+)<\/a>/) {
  76.         if ($FORM{'url'} eq $1) {
  77.             &repeat_url;
  78.         }
  79.         $i++;
  80.     }
  81. }
  82.  
  83. # Open Link File to Output
  84. open (FILE,">$filename");
  85.  
  86. foreach $line (@lines) { # For every line in our data
  87.  
  88.    if ($line =~ /<!--time-->/) {
  89.       @months = ('January','February','March','April','May','June',
  90.          'July','August','September','October','November','December');
  91.  
  92.       @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday',
  93.            'Friday','Saturday');
  94.  
  95.       ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
  96.       if ($sec < 10) { $sec = "0$sec"; }
  97.       if ($min < 10) { $min = "0$min"; }
  98.       if ($hour < 10) { $hour = "0$hour"; }
  99.       if ($mday < 10) { $mday = "0$mday"; }
  100.       $date = "on $days[$wday], $months[$mon] $mday, 19$year at $hour:$min:$sec";
  101.       print FILE "<!--time--><b>Last link was added $date</b><hr>\n";
  102.    }
  103.    elsif ($line =~ /<!--number-->/) {
  104.       print FILE "<!--number--><b>There are <i>$i</i> links on this ";
  105.       print FILE "page.</b><br>\n";
  106.    }
  107.    else {
  108.        print FILE $line;
  109.    }
  110.  
  111.    foreach $tag ( keys %sections) { # For every tag 
  112.       if ( ($FORM{'section'} eq $sections{$tag}) && 
  113.          ($line =~ /<!--$tag-->/) ) {
  114.  
  115.          print FILE "<li><a href=\"$FORM{'url'}\">$FORM{'title'}</a>\n"; 
  116.       }
  117.    }
  118. }
  119.  
  120. close (FILE);
  121.  
  122. # Return Link File
  123. print "Location: $linksurl\n\n";
  124.  
  125. if ($database ne '') {
  126.     open (DATABASE,">>$database");
  127.     print DATABASE "$FORM{'url'}\n";
  128.     close(DATABASE);
  129. }
  130.  
  131. sub no_url {
  132.    print "Content-type: text/html\n\n";
  133.    print "<html><head><title>ERROR: No URL</title></head>\n";
  134.    print "<body bgcolor=#FFFFFF text=#000000><center>";
  135.    print "<h1>No URL</h1></center>\n";
  136.    print "You forgot to enter a url you wanted added to the Free for ";  
  137.    print "all link page.  Another possible problem was that your link ";
  138.    print "was invalid.<p>\n";
  139.    print "<form method=POST action=\"$linkscgi\">\n";
  140.    print "<input type=hidden name=\"title\" value=\"$FORM{'title'}\">\n";
  141.    print "<input type=hidden name=\"section\""; 
  142.    print "value=\"$FORM{'section'}\">\n";
  143.    print "URL: <input type=text name=\"url\" size=50><p>\n";
  144.    print "<input type=submit> * <input type=reset>\n";
  145.    print "<hr>\n";
  146.    print "<a href=\"$linksurl\">$linkstitle</a>\n";
  147.    print "</form></body></html>\n";
  148.  
  149.    exit;
  150. }
  151.  
  152. sub no_title {
  153.    print "Content-type: text/html\n\n";
  154.    print "<html><head><title>ERROR: No Title</title></head>\n";
  155.    print "<body bgcolor=#FFFFFF text=#000000><center>";
  156.    print "<h1>No Title</h1></center>\n";
  157.    print "You forgot to enter a title you wanted added to the Free for ";
  158.    print "all link page.  Another possible problem is that you title ";
  159.    print "contained illegal characters.<p>\n";
  160.    print "<form method=POST action=\"$linkscgi\">\n";
  161.    print "<input type=hidden name=\"url\" value=\"$FORM{'url'}\">\n"; 
  162.    print "<input type=hidden name=\"section\"";
  163.    print "value=\"$FORM{'section'}\">\n";
  164.    print "TITLE: <input type=text name=\"title\" size=50><p>\n";
  165.    print "<input type=submit> * <input type=reset>\n";
  166.    print "<hr>\n";
  167.    print "<a href=\"$linksurl\">$linkstitle</a>\n";
  168.    print "</form></body></html>\n";
  169.  
  170.    exit;
  171. }
  172.  
  173. sub repeat_url {
  174.    print "Content-type: text/html\n\n";
  175.    print "<html><head><title>ERROR: Repeat URL</title></head>\n";
  176.    print "<body bgcolor=#FFFFFF text=#000000><center><h1>Repeat URL</h1></center>\n";
  177.    print "Sorry, this URL is already in the Free For All Link Page.\n";
  178.    print "You cannot add this URL to it again.  Sorry.<p>\n";
  179.    print "<a href=\"$linksurl\">$linkstitle</a>";
  180.    print "</body></html>\n";
  181.  
  182.    exit;
  183. }
  184.  
  185.