#!/usr/bin/perl ############################################################################## # PROGRAM : iLink Search Engine # # VERSION : 3.33 # # # # NOTES : # ############################################################################## # All source code, images, programs, files included in this distribution # # Copyright (c) 1996 -> 2014 # # John C. Cokos, The CCS Network, The Interactive Web # # All Rights Reserved. # ############################################################################## # # # ------ DO NOT MODIFY ANYTHING BELOW THIS POINT !!! ------- # # # ############################################################################## require ("freeware.pm"); &parse_form; ################################################################### ## See what the user sent as variables and take action # ################################################################### ## Number of hits per page shown (make this 1 less than you want) $Hits_So_Far = 0; $Hits_Sent = 0; $Hits_Per_Page = 25; #### Buttons and HTML file locations $help_file = $html_dir."/ilink.htm"; $manual = $html_dir."/ilink.htm"; $SmallFolder = ""; $powered_by = "pb_hyperseek.jpg"; #### File names / etc sent from html $engine_data = "$data_dir/ilink/hyperseek.dat"; $engine_temp = "$data_dir/ilink/hyperseek.temp"; $category_main = "$data_dir/ilink/categories.dat"; $category = $input{'category'}; $sub_category = $input{'sub_category'}; $ReqCategory = $input{'Category'}; &ReadCategories; $action = $input{'action'}; if (! $ReqCategory) { $template = "ilink"; } else { $template = $ReqCategory; $template =~ s/\|/_/g; $template =~ s/ /_/g; if (! -e "$data_dir/templates/$template.txt") { $template = "ilink"; } } &Page_Header($template); exit 0; sub Body { $OUT .= "
\n"; $OUT .= "
\n"; $OUT .= "\n"; $OUT .= "Search for: \n"; $OUT .= "\n"; $OUT .= "
\n"; if ($action eq "Search") { &Search; } elsif ($action eq "Add_Link") { &Add_Form; } elsif ($action eq "post_new") { &Post_New; } else { &Category_Listings; } } sub Category_Listings { $CAT = $input{'Category'}; $OUT .= "\n"; $OUT .= "\n"; } sub Search { $terms = $input{'Terms'}; $terms = lc($terms); $terms =~ s/\'//; $Encoded_Terms = &urlencode($terms); $Saved_Terms = $terms; # $search_method = $input{'Algorithm'}; if($terms !~ /( and )|( or )|( not )|\*|\+|\-|\"/) { $search_method = "Simple"; } elsif ($terms =~ /\*/) { $search_method = "Partial"; } else { $search_method = "Advanced"; } $terms = " " . $terms . " "; $terms =~ s/\s+/ /g; @Raw_Terms = split(/\"/,$terms); $grp = $Raw_Terms[0]; $grp =~ s/(\*+)//g; $terms = ""; foreach $term (@Raw_Terms) { if ($i == 1){$i--;} else {$i++;} $term =~ s/ /_/g unless $i; $terms .= $term; } if ($search_method ne "Simple") { $terms =~ s/ not / -/ig; $terms =~ s/ and / \+/ig; $terms =~ s/ or / \|/ig; } ## If they type "and" or "+", then we need to require everything... if ($terms =~ /\+/) { $Range="All"; } $star = "\\b"; $terms =~ s/(\*+)/$star/g; @terms = split(/\s+/,$terms); foreach $term (@terms) { next if ($term eq ""); # if ($search_method eq "Simple" && $DB_Format ne "IWeb") { ## For simple searches, append / prepend with * ## Also, remove "ing", "ies", and other plurals # if ( substr($term,-3) eq "ing" ) { substr($term,-3)=""; } # if ( substr($term,-3) eq "ies" ) { substr($term,-3)=""; } # if ( substr($term,-1) eq "s" ) { substr($term,-1)=""; } # $term = $star . $term . $star; # } $term =~ s/_/ /g; if ($term =~ /^-/) { $FT .= $term . " "; $is_forbid=1; $term =~ s/\|//g; $term =~ s/\+//g; $term =~ s/\-//g; if ($forbid_reg) { $forbid_reg .= "|($term)";} else { $forbid_reg = "($term)";} } elsif (($term =~ /^\|/) || (($Range eq "Any") && ($term !~ /^\+/))) { $OT .= $term . " "; $term =~ s/\|//g; $term =~ s/\+//g; $term =~ s/\-//g; if ($opt_reg) { $opt_reg .= "|($term)";} else { $opt_reg = "($term)";} } else { $RT .= $term . " "; $term =~ s/\|//g; $term =~ s/\+//g; $term =~ s/\-//g; $is_required=1; if ($req_reg) { $req_reg .= "|($term)";} else { $req_reg = "($term)";} } } $IT =~ s/\\b/\*/g; $IT =~ s/ (\"?)\+/ $1/g; $IT =~ s/ (\"?)\|/ $1/g; $FT =~ s/\\b/\*/g; $FT =~ s/ (\"?)\+/ $1/g; $FT =~ s/ (\"?)\|/ $1/g; $OT =~ s/\\b/\*/g; $OT =~ s/ (\"?)\+/ $1/g; $OT =~ s/ (\"?)\|/ $1/g; $RT =~ s/\\b/\*/g; $RT =~ s/ (\"?)\+/ $1/g; $RT =~ s/ (\"?)\|/ $1/g; $delimiter = '|'; open(ALLFILE,"$engine_data"); foreach $LINE () { ($ID,$Category,$SubCategory,$Cool,$Qualifier,$Email,$Title,$URL,$Description,$Keys,$filler1,$filler2,$filler3,$filler4) = split(/\|/,$LINE); $string = lc($LINE); chomp($string); ## Re-Set matched flags; $optional_matches = 0; $required_matches = 0; $LinkScore = 0; if ($is_forbid) { if ($string =~ /$forbid_reg/) { $screened++; next; } } if ($is_required) { $bad=0; foreach $req(split(/\|/,$req_reg)) { if ($string !~ /$req/) { $bad++; } } if(! $bad) {$LinkScore+=3; $required_total++; $required_matches++;} } if($opt_reg) { if ($string =~ /$opt_reg/) { $LinkScore+=1; $optional_total++; $optional_matches++; } } if ($optional_matches || $required_matches) { $matched++; &Keep_It; } } close(ALLFILE); $search_message = ""; $search_message .= "Ignored: $IT
" if($IT); $search_message .= "You Searched For: $RT
" if($RT); $search_message .= "Optional: $OT
" if($OT); $search_message .= "Screened: $FT
" if($FT); $Remaining = ($hitcount - $rank) - ($Hits_Per_Page - 1); if ($Remaining >= $Hits_Per_Page) { $Next = $Hits_Per_Page; $New_Rank = $rank + $Hits_Per_Page; } elsif ($Remaining > 0) { $Next = $Remaining % $Hits_Per_Page; $New_Rank = $rank + $Hits_Per_Page; } else { $New_Rank = $hitcount + 1; } $summary .= "Listing Matches " . $rank . "- " . ($New_Rank - 1); $summary .= " of $hitcount.
\n"; $OUT .= "\n"; $OUT .= "
Search Results....
\n"; $OUT .= "$search_message

$summary\n"; if ($hitcount > 0) { $OUT .= "\n"; $i = 0; $OUT .= "

Category Matches...

\n"; foreach $key (reverse sort keys %CATS) { ($ID,$Cat,$Sub,$Cool,$Qualifier,$Email,$Title,$URL,$Description,$Keys)=split(/\|/,$CATS{$key}); $LINK = "$Cat|$Sub"; $LINK =~ s/ /_/g; $OUT .= "$Cat :: $Sub

\n"; } $OUT .= "

$summary

\n"; foreach $key (keys %HITS) { @{$records[$count++]}{qw(ID Cat Sub Cool Qualifier Email Title URL Description Keys)}=split(/\|/,$HITS{$key}); } @links = sort { $b->{'Title'} <=> $a->{'Title'} } @records; $OUT .= "\n"; $OUT .= "Listings " . $rank . "- " . ($New_Rank - 1); $OUT .= " of $hitcount displayed.
\n"; $OUT .= "
\n"; } else { $OUT .= "\n"; $OUT .= $No_Documents_Found; } $OUT .= "
\n"; $Saved_Terms =~ s/\"/\"/g; } sub Keep_It { $CATS{"$Category$SubCategory"} = $LINE; $HITS{"$URL"} = $LINE; $hitcount++; } sub Categories { @C = split(/\|/,$input{'Category'}); $CAT = $C[0]; $CAT =~ s/_/ /g; $OUT .= "\n"; # Put Option List Together $x = 0; $LastCategory = ""; for $i (0 .. $#categories ) { if ( $action ne "Search" && ($CAT eq $categories[$i]{'Category'} || $CAT eq "") ) { $ThisCategory = $categories[$i]{'Category'}; if ($ThisCategory ne $LastCategory) { $LastCategory = $ThisCategory ; if($TableIndex==0) { $OUT .= "\n"; } $OUT .= " \n"; $TableIndex++; if( $TableIndex>=$is_menu_columns ) { $OUT .= "\n"; $OUT .= "\n"; $TableIndex=0; } $x ++; } } } $OUT .= "
\n"; $OUT .= " \n"; $LINK = "$categories[$i]{'Category'}"; $LINK =~ s/ /+/g; $OUT .= "$categories[$i]{'Category'}
\n"; $OUT .= " \n"; if ($is_show_all eq "SUB") { for $j(0 .. $#categories) { if ($categories[$j]{'Category'} eq $ThisCategory) { $link = "$categories[$j]{'Category'}|$categories[$j]{'SubCategory'}"; $link =~ s/ /_/g; $OUT .= "  \n"; $OUT .= "$categories[$j]{'SubCategory'} ($categories[$j]{'Count'})
\n"; } } } else { $Number_Shown = 0; if ($CAT) { $MAX = 500; } else {$MAX = 3;} for $j(0 .. $#categories) { if ($categories[$j]{'Category'} eq $ThisCategory && $Number_Shown <= $MAX) { $Number_Shown++; $link = "$categories[$j]{'Category'}|$categories[$j]{'SubCategory'}"; $link =~ s/ /_/g; $OUT .= " $categories[$j]{'SubCategory'}($categories[$j]{'Count'}),\n"; } } if($MAX < 100) { $OUT .= "..."; } } $OUT .= "
\n"; } sub CategorySelectList { $CAT = $input{'Category'}; $OUT .= "Category:
\n"; } sub ReadCategories { open (CNT,"$category_main"); while ( ) { $tmp_cats={}; foreach $rec(split /\n/,join '',){ (undef, @{$tmp_cats[$cat_count++]}{qw(Category SubCategory Count Description)})=split(/\|/,$rec,5); } } close (CNT); @categories = sort { $a->{'Category'} cmp $b->{'Category'} or $a->{'SubCategory'} cmp $b->{'SubCategory'} } @tmp_cats; } sub Powered_By { $OUT .= "

\n"; $OUT .= "\n"; $OUT .= "\"Powered
\n"; $OUT .= "Powered By iWeb\n"; } sub Add_Form { $OUT .= <
Add a link to the database...

DONE1 &CategorySelectList; $OUT .= <

   Contact Name:  
   Email:         
   Page Title:    
   URL:           
      (You HAVE to use 'http://...'
        or your link will NOT work)

   Description....
                  
Check the spelling of your entry?


DONE2 $OUT .= "
\n"; &Powered_By; $OUT .= "
\n"; } ############################################################################## # Get form input and post new message ############################################################################## sub Post_New { #### Variable names and values sent from html $do_spellcheck = $input{'do_spellcheck'}; $contact_name = $input{'a_name'}; $contact_email = $input{'a_email'}; $new_url = $input{'a_url'}; $new_title = $input{'a_title'}; $new_text = $input{'a_text'}; $cat = $input{'category'}; @entry = split(/\|/,$cat); $category = $entry[0]; $sub_category = $entry[1]; ## Eliminate SPAM... if ($yh_bad_words ne "") { if ( &Bad_Words_Present($new_text, "$data_dir/badwords.txt") ) { &ERROR("$Bad_Words_Message"); exit 0; } } $time = time; ## Validate Entries... $HTTP = "http://"; $check_url = $new_url; $check_url =~ s/$HTTP//g; $check_url =~ s/\///g; # The URL is a bit tricky, we need the http:// to validate it, but need to remove # the http:// to run it through the alpha screen, hence, we made a second variable... if( &Not_Valid_URL($new_url) ) { &ERROR("Invalid URL ($new_url) Entered

...check to make sure you have the "http://" in the URL"); exit 0; } if( &Not_Alpha($check_url)) { &ERROR("Non Alphanumeric Characters Found in the URL... Please Re-Enter."); exit 0; } if( &Not_Valid_Email($contact_email) ) { &ERROR("Invalid Email Address ($contact_email) Entered"); exit 0; } if( &Not_Alpha($new_title)) { &ERROR("Non Alphanumeric Characters Found in the Title... Please Re-Enter."); exit 0; } ## We need to remove HTML From the description and check it for other non-numerics. $new_text = &Remove_HTML_Tags($new_text); ## Check Spelling if($do_spellcheck) { if ( &Spelling_Errors($new_text, "$data_dir/dictionary") ) { &ERROR($Spelling_Error_Message); exit 0; } } if (! &lock("hyperseek")) { &ok_box("Server is Busy","Please Try again Later", "history.go(-1)"); exit 0; } open (MSG,">>$engine_temp"); print MSG "$time|"; print MSG "$category|"; print MSG "$sub_category|"; print MSG "1|"; print MSG "|"; print MSG "$contact_email|"; print MSG "$new_title|"; print MSG "$new_url|"; $new_text =~ s/\r\n/
/g; print MSG " $new_text |"; $new_xtra =~ s/\r\n/ /g; print MSG "|1|2|3|4|\n"; close(MSG); &unlock("hyperseek"); $ok_message = "
Your link has been added.

Thank You.
\n"; $click = "history.go(-1)"; $title = "Thank You."; &ok_box($title,$ok_message,$click); exit 0; }