home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 March / Chip_2000-03_cd.bin / tema / Globe / jak_na_to / search.pl < prev    next >
Encoding:
Perl Script  |  2000-01-25  |  6.5 KB  |  204 lines

  1. #!/usr/bin/perl
  2. ##############################################################################
  3. # Simple Search                 Version 1.0                                  #
  4. # Copyright 1996 Matt Wright    mattw@worldwidemart.com                      #
  5. # Created 12/16/95              Last Modified 12/16/95                       #
  6. # Scripts Archive at:           http://www.worldwidemart.com/scripts/        #
  7. ##############################################################################
  8. # COPYRIGHT NOTICE                                                           #
  9. # Copyright 1996 Matthew M. Wright  All Rights Reserved.                     #
  10. #                                                                            #
  11. # Simple Search may be used and modified free of charge by anyone so long as #
  12. # this copyright notice and the comments above remain intact.  By using this #
  13. # code you agree to indemnify Matthew M. Wright from any liability that      #
  14. # might arise from it's use.                                                 #
  15. #                                                                            #
  16. # Selling the code for this program without prior written consent is         #
  17. # expressly forbidden.  In other words, please ask first before you try and  #
  18. # make money off of my program.                                              #
  19. #                                                                            #
  20. # Obtain permission before redistributing this software over the Internet or #
  21. # in any other medium.  In all cases copyright and header must remain intact.#
  22. ##############################################################################
  23. # Define Variables                                 #
  24.  
  25. $basedir = '/www/doc/servery/';
  26. $baseurl = 'http://servery.cz/';
  27. #@files = ('*.shtml','demos/links/*.html','demos/guest/*.html');
  28. @files = ('*.html','faq/*.html','gesto/*.html','help/*.html','navod/*.html');
  29. $title = "SERVERY.CZ";
  30. $title_url = 'http://servery.cz/navod/';
  31. $search_url = 'http://servery.cz/navod/search.html';
  32.  
  33. # Done                                         #
  34. ##############################################################################
  35.  
  36. # Parse Form Search Information
  37. &parse_form;
  38.  
  39. # Get Files To Search Through
  40. &get_files;
  41.  
  42. # Search the files
  43. &search;
  44.  
  45. # Print Results of Search
  46. &return_html;
  47.  
  48.  
  49. sub parse_form {
  50.  
  51.    # Get the input
  52.    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  53.  
  54.    # Split the name-value pairs
  55.    @pairs = split(/&/, $buffer);
  56.  
  57.    foreach $pair (@pairs) {
  58.       ($name, $value) = split(/=/, $pair);
  59.  
  60.       $value =~ tr/+/ /;
  61.       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  62.  
  63.       $FORM{$name} = $value;
  64.    }
  65. }
  66.  
  67. sub get_files {
  68.  
  69.    chdir($basedir);
  70.    foreach $file (@files) {
  71.       $ls = `ls $file`;
  72.       @ls = split(/\s+/,$ls);
  73.       foreach $temp_file (@ls) {
  74.          if (-d $file) {
  75.             $filename = "$file$temp_file";
  76.             if (-T $filename) {
  77.                push(@FILES,$filename);
  78.             }
  79.          }
  80.          elsif (-T $temp_file) {
  81.             push(@FILES,$temp_file);
  82.          }
  83.       }
  84.    }
  85. }
  86.  
  87. sub search {
  88.  
  89.    @terms = split(/\s+/, $FORM{'terms'});
  90.  
  91.    foreach $FILE (@FILES) {
  92.  
  93.       open(FILE,"$FILE");
  94.       @LINES = <FILE>;
  95.       close(FILE);
  96.  
  97.       $string = join(' ',@LINES);
  98.       $string =~ s/\n//g;
  99.       if ($FORM{'boolean'} eq 'AND') {
  100.          foreach $term (@terms) {
  101.             if ($FORM{'case'} eq 'Insensitive') {
  102.                if (!($string =~ /$term/i)) {
  103.                   $include{$FILE} = 'no';
  104.             last;
  105.                }
  106.                else {
  107.                   $include{$FILE} = 'yes';
  108.                }
  109.             }
  110.             elsif ($FORM{'case'} eq 'Sensitive') {
  111.                if (!($string =~ /$term/)) {
  112.                   $include{$FILE} = 'no';
  113.                   last;
  114.                }
  115.                else {
  116.                   $include{$FILE} = 'yes';
  117.                }
  118.             }
  119.          }
  120.       }
  121.       elsif ($FORM{'boolean'} eq 'OR') {
  122.          foreach $term (@terms) {
  123.             if ($FORM{'case'} eq 'Insensitive') {
  124.                if ($string =~ /$term/i) {
  125.                   $include{$FILE} = 'yes';
  126.                   last;
  127.                }
  128.                else {
  129.                   $include{$FILE} = 'no';
  130.                }
  131.             }
  132.             elsif ($FORM{'case'} eq 'Sensitive') {
  133.                if ($string =~ /$term/) {
  134.           $include{$FILE} = 'yes';
  135.                   last;
  136.                }
  137.                else {
  138.                   $include{$FILE} = 'no';
  139.                }
  140.             }
  141.          }
  142.       }
  143.       if ($string =~ /<title>(.*)<\/title>/i) {
  144.          $titles{$FILE} = "$1";
  145.       }
  146.       else {
  147.          $titles{$FILE} = "$FILE";
  148.       }
  149.    }
  150. }
  151.  
  152. sub return_html {
  153.    print "Content-type: text/html\n\n";
  154.    print "<html>\n <head>\n  <title>SERVERY.CZ - V²sledky hledßnφ</title>\n </head>\n";
  155.    print "<BODY background=\"img/o5.gif\" bgcolor=\"#FFE7A2\" text=\"#271E9F\" link=\"#846300\" vlink=\"gray\" alink=\"red\">\n <center>\n  <FONT FACE=\"Arial CE\"><br><blockquote><h1>V²sledky hledßnφ na $title</h1>\n </center></blockquote><FONT SIZE=\"-1\">\n";
  156.    print "<br><hr width=75%>\n";
  157.    print "<blockquote><ul>\n";
  158.    foreach $key (keys %include) {
  159.       if ($include{$key} eq 'yes') {
  160.          print "<li><a href=\"$baseurl$key\">$titles{$key}</a>\n";
  161.       }
  162.    }
  163.    print "</ul></blockquote>\n";
  164.  
  165.    ##########
  166.    ##########
  167.  
  168.     print "<hr width=75%><blockquote>\n";
  169.     print "Vyhledßno podle:<p>\n";
  170.     print "<ul>\n";
  171.     print "<li><b>V²raz:</b> ";
  172.     $i = 0;
  173.     foreach $term (@terms) {
  174.        print "$term";
  175.        $i++;
  176.        if (!($i == @terms)) {
  177.           print ", ";
  178.        }
  179.     }
  180.     print "\n";
  181.     print "<li><b>Logika:</b> $FORM{'boolean'}\n";
  182.     print "<li><b>VELK┴/malß pφsmena:</b> $FORM{'case'}\n";
  183.     print "</ul></blockquote>\n";
  184.  
  185.    #print "</ul><br><hr width=75%><P>\n";
  186.    #print "<ul>\n<li><a href=\"$search_url\">Back to Search Page</a>\n";
  187.    #print "<li><a href=\"$title_url\">$title</a>\n";
  188.    #print "</ul></blockquote>\n";
  189.    #print "<hr width=75%>\n";
  190.    #print "Search Script written by Matt Wright and can be found at <a href=\"http://www.worldwidemart.com/scripts/\">Matt's Script Archive</a>\n";
  191.  
  192.    ##########
  193.    ##########
  194.  
  195.  
  196.   print "<HR width=75%><blockquote><FONT SIZE=\"-1\" FACE=\"Arial CE\">Tento vyhledßvacφ script je";
  197.   print " souΦßstφ standardnφho scriptovΘho vybavenφ dodßvanΘho zßkaznφkum slu₧by SERVERY.CZ\n";
  198.   print "</FONT></blockquote></center><CENTER><A HREF=\"http://www.globe.cz\" target=\"_blank\">";
  199.   print "<IMG SRC=\"img/globelogo.gif\"border=0 ALT=\"Globe Internet, s.r.o.\"></A></CENTER>";
  200.  
  201.    print "</body>\n</html>\n";
  202. }
  203.  
  204.