#!/usr/local/bin/perl # # search.pl - Written by John M. Hurt 12/5/00 # Public Domain Software - No Copyright # ######################################################################## # # How to Install This Program # # 1. Make sure you have a Perl interpreter on your webserver. # # 2. Make sure the path on the first line (#!/usr/local/bin/perl) # of the program correctly points to your interpreter. # # 3. Copy this program (search.pl) to your cgi-bin folder # or subfolder. Rename from search.txt to search.pl # # 4. If you do not want a counter to show up at the bottom # of the search page, comment out (#) or change the value # to "no" for the following variable: # $usecounter = 'yes'; # # 5. Create a file in the same cgi-bin folder named "counter.txt". # # 6. Type the number "0" in the counter.txt file and save it. # # 7. Set the permissions to allow the search.pl to execute # ( Unix _rwxr_xr_x command chmod 755 ). # # 8. Set the permission to allow the counter.txt file to be # updated by the internet # ( Unix _rw_rw_rw_ command chmod 666). # # 9. Comment out (#) or change the value to "no" for any of the # following versions you do not want to search or use: # (Example: #$kjv10search='yes'; or $kjv10search='no'; $kjv10search='yes'; $kjv20search='yes'; $kjv30search='yes'; $kjvlargesearch='yes'; $youngssearch='yes'; $parallelsearch='yes'; $greeksearch='yes'; $americanstdsearch='yes'; # 10. The search.pl program searches a delimited text file # to find the result. # Download the following files for the software you # intend to search: # # # King James Version 1.0, 2.0, 3.0, Large Print # www.htmlbible.com/searchindex/kjvindex.txt # # Youngs Literal Translation # www.htmlbible.com/searchindex/yngindex.txt # # Greek New Testament # www.htmlbible.com/searchindex/grkindex.txt # # American Standard Version # www.htmlbible.com/searchindex/asvindex.txt # # 11. Update the following path variables to point to where you have # saved the text file indexes. This is the path from # the search.pl Perl program to the text index files. # $kjvindexpath='../../searchindex/kjvindex.txt'; $youngsindexpath='../../searchindex/yngindex.txt'; $greekindexpath='../../searchindex/grkindex.txt'; $americanstdindexpath='../../searchindex/asvindex.txt'; # # Note: The '../' means to go up one directory. # # 12. In the upper left corner of the search page, # there will be an image that is hyper-linked from # the search program to the main book/chapter index page for # each version. Update the following variables to present these # images and links: $kjv10indexlink='http://www.htmlbible.com/kjv10/index.htm'; $kjv10indeximage='http://www.htmlbible.com/images/kjv10.jpg'; $kjv20indexlink='http://www.htmlbible.com/kjv20/index.htm'; $kjv20indeximage='http://www.htmlbible.com/images/kjv20.jpg'; $kjv30indexlink='http://www.htmlbible.com/kjv30/index.htm'; $kjv30indeximage='http://www.htmlbible.com/images/kjv30.jpg'; $kjvlargeindexlink='http://www.htmlbible.com/kjvlarge/index.htm'; $kjvlargeindeximage='http://www.htmlbible.com/images/kjvlarge.jpg'; $youngsindexlink='http://www.htmlbible.com/youngs/index.htm'; $youngsindeximage='http://www.htmlbible.com/images/youngs.jpg'; $parallelindexlink='http://www.htmlbible.com/parallel/index.htm'; $parallelindeximage='http://www.htmlbible.com/images/parallel.jpg'; $greekindexlink='http://www.htmlbible.com/greek/index.htm'; $greekindeximage='http://www.htmlbible.com/images/greek.jpg'; $americanstdindexlink='http://www.htmlbible.com/asv/index.htm'; $americanstdindeximage='http://www.htmlbible.com/images/asv.jpg'; # 13. Update the background image $backgroundimage='http://www.htmlbible.com/images/image1.jpg'; # 14. Update the name of the program, if you have renamed it. $cgi_location = "search.pl"; # 15. Update the "Send Comments To" at the bottom of the search # screen: $sendcommentsto = 'Send comments to webmaster@htmlbible.com'; # 16. Update the date the counter began to be incremented" $accessdate = '5/1/99'; # 17. Update the link and image back to your homepage: $homepagelink = 'http://www.htmlbible.com'; $homepageimage = 'http://www.htmlbible.com/images/homepage.jpg'; $homepagename = 'HTML Bible Homepage'; # 18. Update the Title on the Search Page: $searchtitle = 'HTML Bible Search'; # 19. If you have questions, there is limited support # for this free software at webmaster@htmlbible.com # If we can help, please contact us. # ######################################################################## # PERL code below this line. ######################################################################## # Process Input value pairs # This is used to split the name/value pairs. # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s///g; $value =~ s/<([^>]|\n)*>//g; $value =~ s/'|"|~|`|{|}//g; $FORM{$name} = $value; } # Read the "indata" variable from the form, and put it into $indata. $indata=$FORM{'indata'}; $version=$FORM{'version'}; $search=$FORM{'search'}; $first_match=$FORM{'first_match'}; $typeofsearch=$FORM{'typeofsearch'}; # Determine if we are using the counter or not if ($usecounter eq 'yes') { # Set our access counter file variable name to pull from the counter file. $counter="counter.txt"; # Open the counter data file, and assign a file handler name. open (cntr,$counter) || die "Can't open first $counter"; # Put the complete data file into array @innumbr. @innumbr=(); # Close counter list file. close(cntr); # Put the zero element (only element) into $access_counter. $access_counter = $innumbr[0]; # Get rid of new line /n chomp($access_counter); # Increment temporary num variable. $tempnum = $access_counter + 1; # Identify (same) file to replace.(>> = append, > = replace) $outnum=">counter.txt"; # Open File, assign file handler. open(cntrout, $outnum) || die "Can't open second $counter"; # Select that this is the file you want to print to. select(cntrout); # Print new Number to file. print "$tempnum"; # Close file. close(cntrout); # Add commas to number for readability. if (length($access_counter) > 3) { $ac_1_3 =substr($access_counter, -3); $ac_4 =substr($access_counter, -4, 1); } if (length($access_counter) > 4) { $ac_5 =substr($access_counter, -5, 1); } if (length($access_counter) > 5) { $ac_6 =substr($access_counter, -6, 1); } if (length($access_counter) > 6) { $ac_7 =substr($access_counter, -7, 1); } if (length($access_counter) > 7) { $ac_8 =substr($access_counter, -8, 1); } if (length($access_counter) > 8) { $ac_9 =substr($access_counter, -9, 1); } if ((length($access_counter) > 3) and (length($access_counter) < 7)) { $access_counter = "$ac_6$ac_5$ac_4,$ac_1_3"; } elsif ((length($access_counter) > 6) and (length($access_counter) < 10)) { $access_counter = "$ac_9$ac_8$ac_7,$ac_6$ac_5$ac_4,$ac_1_3"; } # End determine if $usecounter or not } # Check for first time through selection list. # If first time, set $version to "King James Version 3.x" so SELECT will not bomb. if ($version eq "") { $version = "King James Version 3.x"; } # Check for first time through list. if ($typeofsearch eq "") { $typeofsearch = "all"; } # Set Index Link if ($version eq "King James Version 3.x") { $indexlink = $kjv30indexlink; $indeximage = $kjv30indeximage; } if ($version eq "King James Version 2.0") { $indexlink = $kjv20indexlink; $indeximage = $kjv20indeximage; } if ($version eq "King James Version 1.0") { $indexlink = $kjv10indexlink; $indeximage = $kjv10indeximage; } if ($version eq "Youngs Literal Translation") { $indexlink = $youngsindexlink; $indeximage = $youngsindeximage; } if ($version eq "Parallel - Greek") { $indexlink = $parallelindexlink; $indeximage = $parallelindeximage; } if ($version eq "Parallel - Youngs Literal") { $indexlink = $parallelindexlink; $indeximage = $parallelindeximage; } if ($version eq "Parallel - King James") { $indexlink = $parallelindexlink; $indeximage = $parallelindeximage; } if ($version eq "Parallel - American Standard") { $indexlink = $parallelindexlink; $indeximage = $parallelindeximage; } if ($version eq "Greek New Testament") { $indexlink = $greekindexlink; $indeximage = $greekindeximage; } if ($version eq "Large King James Version") { $indexlink = $kjvlargeindexlink; $indeximage = $kjvlargeindeximage; } if ($version eq "American Standard Version") { $indexlink = $americanstdindexlink; $indeximage = $americanstdindeximage; } # Check for first time through selection list. # If first time, set $search to "Search Entire Bible" so SELECT will not bomb. if ($search eq "") { $search = "Search Entire Bible"; } # If first time, set $first_match to 1 if (($first_match == "") or ($first_match < 1)) { $first_match = 1; } # Initialize last_match variable. $last_match = $first_match + 24; # If the input data is not empty, then process. if ($indata ne "") { # Set $bible variable file name to pull from appropriate data file. if ($version eq "King James Version 3.x") { $bible=$kjvindexpath; } if ($version eq "King James Version 2.0") { $bible=$kjvindexpath; } if ($version eq "King James Version 1.0") { $bible=$kjvindexpath; } if ($version eq "Youngs Literal Translation") { $bible=$youngsindexpath; } if ($version eq "Parallel - Greek") { $bible=$greekindexpath; } if ($version eq "Parallel - Youngs Literal") { $bible=$youngsindexpath; } if ($version eq "Parallel - King James") { $bible=$kjvindexpath; } if ($version eq "Parallel - American Standard") { $bible=$americanstdindexpath; } if ($version eq "Greek New Testament") { $bible=$greekindexpath; } if ($version eq "Large King James Version") { $bible=$kjvindexpath; } if ($version eq "American Standard Version") { $bible=$americanstdindexpath; } # Open the bible data file, and assign a file handler name. open (list,$bible) || die; # Put the complete list into array @inlist. @inlist = (); # Close bible file. close(list); # Break $indata input text string into 5 possible search names. ($firstin, $midin, $lastin, $fourthin, $fifthin)=split(' ', $indata); # Preserve uppercase for bold and underline on printout. $firstin2 = $firstin; $midin2 = $midin; $lastin2 = $lastin; $fourthin2 = $fourthin; $fifthin2 = $fifthin; # Make $indata names into lower case for matching purposes. $firstin = lc($firstin); $midin = lc($midin); $lastin = lc($lastin); $fourthin = lc($fourthin); $fifthin = lc($fifthin); # End If Statement "If the input data is not empty, then process." } # Select to print to screen. select(STDOUT); # Return the MIME type to show that HTML is to be displayed. # The two "\n" make sure there is a blank line after MIME type. print "Content-type: text/html\n\n"; # Print results, start HTML. print "\n"; print "$searchtitle"; print "\n"; print "
"; print ""; print ""; print "
$homepagename
"; print "

\n"; print "$searchtitle"; print "

"; print ""; print "
Return to Index
"; print "

"; print "
"; print "
\n"; print ""; if ($version eq "Large King James Version") { print ""; } print "Enter Words For Search: "; if ($version eq "Large King James Version") { print ""; } else {print ""; print "
"; print "";} print "
"; if ($version eq "Large King James Version") { print ""; } print "Version: "; print ""; print "
"; if ($version eq "Large King James Version") { print ""; } print ""; print ""; if ($version eq "Large King James Version") { print ""; } print " Search Criteria: "; print ""; print "
"; #print "
\n"; if ($version eq "Large King James Version") { print ""; } # If this is not the first time the form is displayed, # then print the search results. if ($indata ne "") { # Print title of search. print "

$version Search Results


"; print "
\n"; # Initilize counters. $total_records = 0; $matched_records = 0; # Process each record foreach $listrecord (@inlist) { # Increment counter for total number of records. $total_records++; # Make each $listrecord lower case for matching purposes. #$listrecord=lc($listrecord); # Break info into individual units. ($hyperlink, $reference, $textdata) =split('~', $listrecord); # Extract Book number from hyperlink $booknumber = substr($hyperlink,1,2); # Extract "Parallel" from Version $checkforparallel = substr($version,0,8); # Skip to next record if matched record is not in New Testament, Old Testament. if (($search eq "Search New Testament") or ($checkforparallel eq "Parallel")) { if ($booknumber < 40) { next; } } if ($search eq "Search Old Testament") { if ($booknumber > 39) { next; } } # Strip off newline character from last field. $textdata=~s"\n""g; #Preserve Upper Case charateristics for textdata $textdata2 = $textdata; #$textdata=~s",|.|(|)|!|'""g; # Make $textdata lower case for matching purposes $textdata = lc($textdata); $lcfirstin = lc($firstin); $lcmidin = lc($midin); $lclastin = lc($lastin); $lcfourthin = lc($fourthin); $lcfifthin = lc($fifthin); # Grep or "search data" based on search criteria. $grepfirstin=grep(/\b$lcfirstin\b/, $textdata); #underline and bold matched words $textdata2=~s"\b$firstin2\b"$firstin2"g; if ($midin ne "") {$grepmidin=grep(/\b$lcmidin\b/, $textdata); #underline and bold matched words $textdata2=~s"\b$midin2\b"$midin2"g;} if ($lastin ne "") {$greplastin=grep(/\b$lclastin\b/, $textdata); #underline and bold matched words $textdata2=~s"\b$lastin2\b"$lastin2"g;} if ($fourthin ne "") {$grepfourthin=grep(/\b$lcfourthin\b/, $textdata); #underline and bold matched words $textdata2=~s"\b$fourthin2\b"$fourthin2"g;} if ($fifthin ne "") {$grepfifthin=grep(/\b$lcfifthin\b/, $textdata); #underline and bold matched words $textdata2=~s"\b$fifthin2\b"$fifthin2"g;} # Determine if search was successful for each record processed. if ($typeofsearch eq 'all') { if (($grepfirstin eq "1") # Match on first element entered. and (($grepmidin eq "1") or ($midin eq "")) # Match middle if not blank and (($greplastin eq "1") or ($lastin eq "")) # Match last entered. and (($grepfourthin eq "1") or ($fourthin eq "")) # Match last entered. and (($grepfifthin eq "1") or ($fifthin eq ""))) # Match last entered. {$proceedwithmatch = 'yes';} } if ($typeofsearch eq 'any') { if (($grepfirstin eq "1") # Match on first element entered. or (($grepmidin eq "1") and ($midin ne "")) # Match middle if not blank or (($greplastin eq "1") and ($lastin ne "")) # Match last entered. or (($grepfourthin eq "1") and ($fourthin ne "")) # Match last entered. or (($grepfifthin eq "1") and ($fifthin ne ""))) # Match last entered. {$proceedwithmatch = 'yes';} } if ($typeofsearch eq 'phrase') { $lcindata = lc($indata); $lctextdata = lc($textdata); $grepphrase=grep(/\b$lcindata\b/, $lctextdata); if ($grepphrase eq "1") # Match on phrase. {$proceedwithmatch = 'yes';} } if ($proceedwithmatch eq 'yes') { $proceedwithmatch = 'no'; # Increment counter for number of records matched. $matched_records++; # Skip to next record if matched record is not within 25 selected. if ($matched_records < $first_match) { next; } # Exit foreach loop if match records are greater than upper limit if ($matched_records > $last_match) { last; } # Set Match Found flag for "No Match Found" message. $match_found = "yes"; # Set folder path for version if ($version eq "King James Version 3.x") {$versionpath = "kjv30";} if ($version eq "King James Version 2.0") {$versionpath = "kjv20";} if ($version eq "King James Version 1.0") {$versionpath = "kjv10";} if ($version eq "Youngs Literal Translation") {$versionpath = "youngs";} if ($checkforparallel eq "Parallel") {$versionpath = "parallel";} if ($version eq "Greek New Testament") {$versionpath = "greek";} if ($version eq "Large King James Version") {$versionpath = "kjvlarge";} if ($version eq "American Standard Version") {$versionpath = "asv";} # Only print records in match range. if (($matched_records >= $first_match) and ($matched_records <= $last_match)) { # Print to form. print ""; # End IF Statement "Only print records in match range." } # End IF Statement "If grepresult eq "1" } # End IF Statement "# Process each record." } print "
"; if ($version eq "Large King James Version") { print ""; } print "$matched_records "; print ""; print "$reference"; print ""; if ($version eq "Large King James Version") { print ""; } print "$textdata2
"; print "

\n"; if ($last_match < $matched_records) # More records available for viewing. { print "

\n"; print ""; print ""; print ""; # Increment $match. $first_match_plus_25 = ($first_match + 25); if ($version eq "Large King James Version") { print ""; } print ""; print "

More records available.


"; print " "; print ""; } if ($first_match > 1) # Previous records available for viewing. { print "
\n"; print ""; print ""; print ""; # Increment $match. $first_match_minus_25 = ($first_match - 25); print ""; if ($version eq "Large King James Version") { print ""; } print "
"; print ""; } if ($match_found ne "yes") { # Print no matches found message if $match_found flag ne "yes." print "

No Matches Found For Search Criteria

"; } # End print search data If Statement "if ($indata ne "")" } # End HTML print <<'ending_print_tag';
ending_print_tag print "$sendcommentsto"; if ($usecounter eq 'yes') { print "

This page has been accessed $access_counter times since $accessdate."; } print ""; print "

Bible Search Engine v1.2 by johnhurt.com"; print "

"; print "\n"