#!/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 "

$filename


\n"; open(MYFILE, $filename) || die ("Could not open file $filename"); $line = ; while ($line ne "" && $returen_cnt != $row_count) { #if ($debug = 1) {print "debug: returen_cnt== row_count $returen_cnt $row_count
\n";} chop($line); # Chop off extraneous newline # if ($debug = 1) {print "debug:line $line
\n";} if ($line =~ /$query/) { push(@database_rows,$line); $row_count++; } $line = ; } #($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst) = localtime(); #print "localtime() $sec
\n"; close (MYFILE); return($row_count); } # End of submit query ############################################################################ # output_html_query_form ############################################################################ sub output_html_query_form { print <<__END_OF_HTML__; מנוע החיפוש לפותר תשבצים בעברית

תירבעב םיצבשת רתופל שופיחה עונמ


:הלימ י/שקה
ה?ג?ד : המגודל











:עונמב שמתשהל דציכ

,תשפיחש הלימה תא אצמל ה/לוכי ךניאו ,ץחשת וא ץבשתב תעקתנ םא
."?" י/בתכ ,ת/עדוי ךניאש תוא לכ םוקמבו ,ךל שיש תויתואה תא י/בתכ
.וז הלימ לש םיירשפאה םיפוריצה לכ םע הלבט ךל גצותו שופיחה רותפכ לע י/ץחל
.תומאות םילימ $returen_cnt -ל לבגומ התליאשל הנעמה :הרעה



םילימ תפסוה
 




הרזח


__END_OF_HTML__ 1; }; ################################################################# # search_results_header Subroutine # ################################################################# sub search_results_header { # print qq~ Search results
~; foreach $key (keys(%db)) { if ($form_data{$key} ne "") { print qq~ ~; } } } ################################################################# # search_results_body Subroutine # ################################################################# sub search_results_body { # Notice that in this subroutine we have access to the # $total_row_count hits variable if we want to display it. # print qq~ םילימ $total_row_count ואצמנ

:תומאות םילימ

~; # Basically, we will display a simple HTML table to show # all of the rows which satisfied the search criteria # entered by the user. # # The idea is this. We will go through the @database_rows # (which was given to us by db-lib.pl and contains all of # the hits) one element at a time and convert the pipe # delimited database row into an HTML row. foreach $row (@database_rows) { print ""; print "\n"; } # End of foreach print ""; print "
$row
"; } ################################################################# # search_results_footer Subroutine # ################################################################# sub search_results_footer { print qq~
~; # In this subroutine we can include just a little bit of # logic in order to create a "See more hits button" # # The besic logic is that they either 1) still have more # than the $max_rows_returned hits to see, 2) have only 1 # more hit to see, 3) have less than $max_rows_returned # but more than 1 hit to see, or 4) have no hits left to # see. # # These cases are handled in three if tests (the 4th case, # in which there are no more hits to see just defaults to # the tags since no submit button need be # created.) #1 if (($total_row_count >= $new_hits_seen) && (($total_row_count-$new_hits_seen) > $max_rows)) { print qq~

~; # VALUE = "המילים הבאות $max_rows הצג את">~; # VALUE = "See the next $max_rows hits">~; if ($row_count == $returen_cnt) { print "
Maxsimun row can returen is $returen_cnt\n
"; } } #2 elsif (($total_row_count-$new_hits_seen) == 1) { $rows_left_to_view = $total_row_count-$new_hits_seen; print qq~

~; # VALUE = "See the next $rows_left_to_view hit">~; } #3 elsif ((($total_row_count-$new_hits_seen) < $max_rows) && (($total_row_count-$new_hits_seen) > 0)) { $rows_left_to_view = $total_row_count-$new_hits_seen; print qq~

~; } #4 # else { # print qq~ # Back
# Back
# ~; # } print qq~

~; } ################################################################# # no_hits_message Subroutine # ################################################################# sub no_hits_message { print qq~
! התליאשל תומאותה םילימ ואצמנ אל םירעטצמ
~; } ########################################################################### # ## Main function for Hebrew conversion of a line ## sub hebline { my($line) =@_; $line1=""; $ostr1=""; $flag=0; # # Reverse the entire line # $str=$line; $line=reverse($str); # # for each char in $line # for ($i=0;$i<=length($line);$i++) { $ch=substr($line,$i,1); $ch1=substr($line,$i+1,1); #if flag=true then htp.print('+'); ## ## if a number or a-z,A-Z => flag=1 ## #NBif (($ch ge '0' && $ch le '9') || ($ch ge 'a' && $ch le 'z') || #NB ($ch ge 'A' && $ch le 'Z')) if ( $ch =~ /[0-9a-zA-Z]/o ) { $ostr1=$ostr1.$ch; $flag=1; } else { ## ## If previous char was [()[]{}] and the current ## is regular number or a-z ## #NBif ($flag==1 && $ch ne '(' && $ch ne ')' && $ch ne'[' && #NB $ch ne ']' && $ch ne '{' && $ch ne'}' && #NB (($ch1 ge '0' && $ch1 le '9') || #NB ($ch1 ge 'a' && $ch1 le 'z') ||($ch1 ge 'A' && $ch1 le 'Z'))) # if (($flag == 1) && ($ch =~ /![\(\)\[\]\{\}]/o) && ($ch1 =~ /[0-9a-zA-Z]/o)) { $ostr1=$ostr1.$ch; } else { ## ## Handle the % case ## #NB if ($ch eq '%' && ($ch1 ge '0' && $ch1 le '9')) if ($ch eq '%' && ($ch1 =~ /[0-9]/o)) { $ostr1=$ostr1.$ch; } else ## ## All the other cases fall here ## { if ($ostr1) { $str=$ostr1; $ostr1=reverse($str); $line1=$line1.$ostr1; $ostr1=""; } $flag=0; $line1=$line1.$ch; } } } } #$str=$ostr1; #$ostr1=reverse($str); $ostr1=reverse($ostr1); $line1=$line1.$ostr1; $rev=$line1; $line1=&reverse_brackets() if ($rev =~ /[\)\(]/); $line1; #NB$line1=$line1; # print "NEW2: $line1\n"; } ######################################################################### sub reverse_brackets { $rev1=""; for ($k=0;$k<=length($rev);$k++) { $ch2=substr($rev,$k,1); if ( $ch2 eq '(' ) { $ch2=')'; } elsif ( $ch2 eq ')' ) { $ch2='('; } $rev1=$rev1.$ch2; } $rev1=$rev1; }