#!/usr/bin/perl
#!/usr/local/bin/perl
#######################################################################
$debug = 1;
#if ($debug = 1) {print "debug:2
\n";}
#######################################################################
# parameters
# returen_cnt how many word the system can return
$returen_cnt = 50;
# Maximum number of answers per screen
$max_rows = 10;
# dic/db files
#$dic_filename = "c:/devel/perl/wordf/";
$dic_filename = "/home/sites/site11/web/cgi-bin/wordf/";
#######################################################################
# Flush the Perl Buffer. #
#######################################################################
# The script begins by telling the Perl interpreter that
# it should continuously flush its buffer so that text
# from this script is sent directly to the Web Browser.
# We do this to streamline debugging and make sure that
# the script operates with the flow we want it to.
$| = 1;
# Also, send out the http header early for easy debugging
# and so that the server will not time us out if we take a
# while to process.
print "Content-type: text/html\n\n";
#######################################################################
# Read and Parse Form Data #
#######################################################################
# Next, the ReadParse subroutine in cgi-lib.pl is used to
# read the incoming form data. However, the subroutine is
# sent "form_data" as a parameter so that the associative
# array of form keys/values comes back with a descriptinve
# name rather than just %in.
require "./Library/cgi-lib.pl";
&ReadParse(*form_data);
#######################################################################
# Display Search Screen #
#######################################################################
if ($form_data{'submit_search'} eq "")
{
&output_html_query_form; # the 1st time
### Start link exchange code
# THE FOLLOWING BLOCK IS USED TO RETRIEVE AND DISPLAY LINK INFORMATION.
# PLACE THIS ENTIRE BLOCK IN THE AREA YOU WANT THE DATA TO BE DISPLAYED.
# MODIFY THE VARIABLES BELOW:
# The following variable defines whether links are opened in a new window
# (1 = Yes, 0 = No)
my $OpenInNewWindow = "1";
# DO NOT MODIFY ANYTHING ELSE BELOW THIS LINE!
# ----------------------------------------------
my $UserKey = "04LH-6KAU-D481";
use LWP::Simple;
use URI::Escape;
my $QueryString;
$QueryString = "LinkUrl=".uri_escape((($ENV{'HTTPS'} eq 'on')?'https://':'http://').$ENV{'HTTP_HOST'}.$ENV{'REQUEST_URI'});
$QueryString .= "&Key=" .uri_escape($UserKey);
$QueryString .= "&OpenInNewWindow=" .uri_escape($OpenInNewWindow);
#Make request
my $backlinks_content = get("http://www.backlinks.com/engine.php?".$QueryString);
if($backlinks_content) {
print $backlinks_content;
}
### End link exchange code
exit;
}
#######################################################################
# Search the Database #
#######################################################################
else # search results
{
&search_results_header;
@database_rows = ();
$hits_seen = $form_data{'new_hits_seen'};
($total_row_count) = &submit_query(*database_rows);
if ($total_row_count < 1)
{
&no_hits_message;
exit;
}
# Now the script will go through and remove from
# @database_rows all of the rows that have already been
# seen by shifting off (remove from the front of
# the array) one element up to the value of $hits_seen
for ($i = 1;$i <= $hits_seen;$i++)
{
$seen_row = shift (@database_rows);
}
# Then we need to remove all of the rows from
# @database_rows that will not be shown to the user quite
# yet because we are only allowed to display
# max_rows at any one time.
#
# To do this we will first figure out how many elements
# are left in the array. Then, we will pop out (remove
# from the end of the list) all of the extra rows.
$length_of_database_rows = @database_rows;
for ($i = $length_of_database_rows-1;$i >= $max_rows;$i--)
{
$extra_row = pop (@database_rows);
}
# Now we will reset $new_hits_seen so that we can
# incorporate this value in the hidden form tag generated
# by &search_results_footer so that the next time we come
# to this routine, we can give the user the next set of
# hits.
$new_hits_seen = $hits_seen + $max_rows;
# Now we will actually send the results of the search to
# the user as well as send the HTML footer. And that,
# they say, is that.
&search_results_body;
&search_results_footer;
exit;
}
#################################################################
# submit_query Subroutine #
#################################################################
# This subroutine is the primary interface for your main
# program. The following sections explain how youcall the
# subroutine and what you should expect in response.
#
# Usage: ($row_count) = &submit_query(*db_rows);
#
# Parameters:
#
# *db_rows = an empty array is passed by reference
# so that it can be filled with the contents of
# the rows that satisfy the query.
#
# Output:
#
# $row_count = amount of rows that satisfied query
# even if the count exceeded the maximum allowed.
# This row count will never actually exceed
# 1 above the row count in the flat file version
# of this routine because it is inefficient to
# keep reading a text file if we do not
# intend to present the user with the subsequent
# information.
#
# *db_rows = an array where each row is a row that
# satisfied the results of the query. The rows
# stop being added to this array if $max_rows
# setup variable is exceeded.
#
sub submit_query
{
# The subroutine begins by defining variables that we will
# be using within this subroutine. We will define them as
# local so that this subroutine will not affect variables
# used in the main routine.
#
# database_rows will be an array which will point back to
# the array given to us by the main routine when it called
# us. We are going to fill that array with the actual
# database rows which were determined to be "hits".
#
# @fields will be an array that we will use to temporarily
# use to hold database fields while we are working.
#
# $row_count is used to keep track of how many rows are
# hits so that we can cut off processing when we have
# reached the limit of rows to be returned defined in the
# setup file.
#
# @not_found_criteria will be an array we will use to keep
# track of whether or not we have completely satisfied the
# search term(s) submitted by the user.
#
# $line will be used as a temporary storage variable for
# the current line in the database that we are reading.
local(*database_rows) = @_;
local($row_count);
local($line);
# Now that it has set up its working space, the script
# initializes row count to 0.
$row_count = 0;
$query = $form_data{'wordinput'};
# if not
if (!($hits_seen > 0)) {
$query = &hebline($query);
}
$query =~ tr/\?םךףןץ/\.מכפנצ/;
#print "new string: $query
\n";
#print("length() ",length($query),"\n");
#($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime();
#print "localtime() $sec
\n";
#$filename = join ("",$dic_filename,"word",length($query)-1,".dat");
$filename = join ("",$dic_filename,"word",length($query),".dat");
#print "
תירבעב םיצבשת רתופל שופיחה עונמ