#!/usr/bin/perl #!/usr/local/bin/perl # ------------- # Links # ------------- # Links Manager # # File: suchen.cgi # Beschreibung: Searches the database and produces a list of results. If no options are # given, the script will produce a search form found in site_html.pl. # Author: Alex Krohn # Email: alex@gossamer-threads.com # Web: http://www.gossamer-threads.com/ # Version: 2.01 # # (c) 1998 Gossamer Threads Inc. # # This script is not freeware! Please read the README for full details # on registration and terms of use. # # Form Input: # 'type' : can be either 'keyword' or 'phrase'. # 'bool' : can be either 'and' or 'or'. # 'mh' : the maximum number of hits, can be either 10, 25, 50, 100. # 'nh' : the page hit we are on. # # Setup: # Make sure the require statement below points to the config file. # # # German Translation by Nicky # http://www.nicky.net # Deutsches Forum http://forum.nicky.net # Required Librariers # -------------------------------------------------------- eval { ($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX / ($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \ require "admin/links.cfg"; # Ändern Sie dieses zum vollen Pfad zu links.cfg, wenn Sie Probleme haben sollten. require "$db_lib_path/db_utils.pl"; require "$db_lib_path/links.def"; $build_use_templates ? require "$db_lib_path/site_html_templates.pl" : require "$db_lib_path/site_html.pl"; }; if ($@) { print "Content-type: text/plain\n\n"; print "Fehler beim einlesen von dazugehörigen Bibliothek Dateien: $@\n"; print "Überprüfen Sie ob diese existieren, Pfade richtig eingestellt sind, und ob die Dateien richtig CHMOD-ed sind."; exit; } # ======================================================== eval { &main; }; if ($@) { &cgierr("Allgemeiner Fehler: $@"); } exit; sub main { # -------------------------------------------------------- %in = &parse_form(); (keys %in <= 0) and &site_html_search_form() and return; local $maxhits = 25; if ($in{'mh'} && (($in{'mh'} == 10) || ($in{'mh'} == 25) || ($in{'mh'} == 50) || ($in{'mh'} = 100))) { $maxhits = $in{'mh'}; } my @search_terms = (); ($in{'type'} eq 'phrase') ? (@search_terms = ($in{'query'})) : (@search_terms = split (/\s/, $in{'query'})); my $bool = $in{'bool'} || 'and'; my $nh = $in{'nh'} || 1; local (%link_results, @category_results); local (@categories, @category_search_fields); open (DB, "<$db_category_name") or &cgierr("Fehler. Kann die Datei bzw. Verzeichnis nicht öffnen: $db_file_name. Grund: $!"); @categories = ; close DB; @category_search_fields = (1,2,4,5,8); my $status = &search (\@search_terms, $bool); if ($status ne "ok") { &site_html_search_failure ($status); return; } ((keys %link_results > 0) or ($#category_results >= 0)) or &site_html_search_failure ("keine Einträge gefunden") and return; local ($cat_hits, $link_hits, $category_results, $link_results, $next); foreach $category (@category_results) { if ($nh == 1) { $cat_clean = &build_clean($category); $linked_title = &build_linked_title_mb ($category); $category_results .= qq|
  • $linked_title\n|; } $cat_hits++; } $cat_hits ||= 0; $lowrange = ($nh-1) * $maxhits + 1; $highrange = $nh * $maxhits; SETOFLINKS: foreach $setoflinks (sort keys %link_results) { my $hits = ($#{$link_results{$setoflinks}} + 1) / ($#db_cols+1); LINK: for ($i = 0; $i < $hits; $i++) { $link_hits++; if (($link_hits <= $highrange) && ($link_hits >= $lowrange)) { %tmp = &array_to_hash ($i, @{$link_results{$setoflinks}}); $link_output{$setoflinks} .= &site_html_link (%tmp) . "\n"; } } } foreach $setoflinks (sort keys %link_output) { $cat_clean = &build_clean ($setoflinks); $title_linked = &build_linked_title_mb ($setoflinks); $link_results .= qq|

    $title_linked\n|; $link_results .= $link_output{$setoflinks}; } if ($search_bold) { foreach $term (@search_terms) { $link_results =~ s,(<[^>]+>)|(\Q$term\E),defined($1) ? $1 : "$2",gie; $category_results =~ s,(<[^>]+>)|(\Q$term\E),defined($1) ? $1 : "$2",gie; } } my ($next_hit, $prev_hit, $next_url, $left, $right, $lower, $upper, $i); if ($link_hits > $maxhits) { $next_url = $ENV{'QUERY_STRING'}; $next_url =~ s/\&nh=\d+//; $next_hit = $nh + 1; $prev_hit = $nh - 1; $left = $nh; $right = int($numhits/$maxhits) - $nh; ($left > 7) ? ($lower = $left - 7) : ($lower = 1); ($right > 7) ? ($upper = $nh + 7) : ($upper = int($link_hits/$maxhits) + 1); (7 - $nh >= 0) and ($upper = $upper + (8 - $nh)); ($nh > ($link_hits/$maxhits - 7)) and ($lower = $lower - ($nh - int($link_hits/$maxhits - 7) - 1)); $next = ""; ($nh > 1) and ($next .= qq~[<<] ~); for ($i = 1; $i <= int($link_hits/$maxhits) + 1; $i++) { if ($i < $lower) { $next .= " ... "; $i = ($lower-1); next; } if ($i > $upper) { $next .= " ... "; last; } ($i == $nh) ? ($next .= qq~$i ~) : ($next .= qq~$i ~); (($i * $maxhits) >= $link_hits) and last; } $next .= qq~[>>] ~ unless ($nh == $i); } &site_html_search_results; } sub search { # -------------------------------------------------------- my ($search_terms, $bool) = @_; my ($regexp, @values, $grand_total, $match, $andmatch, $field, $or_match, %seen, $link, $tmp); $or_match = $bool ne 'and'; if ($or_match) { for (0 .. $#{$search_terms}) { next if (length ${$search_terms}[$_] < 2); $tmp .= "m/\Q${$search_terms}[$_]\E/io ||"; } } else { for (0 .. $#{$search_terms}) { next if (length ${$search_terms}[$_] < 2); $tmp .= "m/\Q${$search_terms}[$_]\E/io &&"; } } chop ($tmp); chop ($tmp); my @field_search; for (0 .. $#db_cols) { exists $in{$db_cols[$_]} and (push (@field_search, $_)); } if (!$tmp and !@field_search) { return ("Geben Sie bitte ein oder mehrere Begriffe ein."); } if ($tmp) { $regexp = eval "sub { $tmp }"; $@ and &cgierr ("Allgemeiner Fehler: $tmp! Grund: $@");} open (DB, "<$db_file_name") or &cgierr("Fehler. Kann die Datei bzw. Verzeichnis nicht öffnen: $db_file_name. Grund: $!"); flock (DB, 1) if ($db_use_flock); LINE: while () { /^#/ and next LINE; /^\s*$/ and next LINE; chomp; @values = &split_decode($_); $grand_total++; $match = 0; $andmatch = 1; if ($regexp) { FIELD: foreach $field (@search_fields) { $_ = $values[$field]; $or_match ? ($match = $match || &{$regexp}) : ($match = &{$regexp}); last FIELD if ($match); } } if ($or_match || $match || !$regexp) { FIELD: foreach $field (@field_search) { if ($or_match) { $match = $match || ($in{$db_cols[$field]} eq $values[$field]); $match and last FIELD; } else { $match = ($in{$db_cols[$field]} eq $values[$field]); $match or last FIELD; } } } $andmatch = $andmatch && $match; if (($or_match && $match) or $andmatch) { push (@{$link_results{$values[$db_category]}}, @values); $numhits++; } } close DB; CATEGORY: foreach $category (@categories) { if ($category =~ /^#/) { next CATEGORY; } if ($category =~ /^\s*$/) { next CATEGORY; } chomp; @values = &split_decode($category); if (!(grep $_ eq $values[1], @category_results)) { $match = 0; $andmatch = 1; if ($regexp) { FIELD: foreach $field (@category_search_fields) { $_ = $values[$field]; $or_match ? ($match = $match || &{$regexp}) : ($match = &{$regexp}); last FIELD if ($match); } } $andmatch = $andmatch && $match; if (($or_match && $match) or $andmatch) { $numcat++; push (@category_results, $values[1]); } } } if (($numhits > 50) and (($grand_total * 0.75) < $numhits)) { return "Dieses Begriff hat fast jede URL !"; } foreach $link ( keys %link_results ) { @{$link_results{$link}} = &build_sorthit (@{$link_results{$link}}); } @category_results = sort @category_results; return "ok"; } sub build_linked_title { # -------------------------------------------------------- my ($input) = shift; my ($dir, $output, $path, $last); foreach $dir ((split m!/!, $input)) { $path .= "/$dir"; $dir = &build_clean ($dir); $output .= qq|$dir:|; } chop ($output); return $output; } sub build_linked_title_mb { # -------------------------------------------------------- my ($input) = $_[0]; my (@dirs, $dir, $output, $path, $nonenglish, $category, @fields, @descs, $desc); @dirs = split (/\//, $input); $nonenglish = ""; CATEGORY: foreach $category (@categories) { if ($category =~ /^#/) { next CATEGORY; } chomp ($category); @fields = &split_decode ($category); if ($fields[1] eq $input) { $nonenglish = $fields[8]; last CATEGORY; } } if ($nonenglish eq "") { @descs = @dirs; } else { @descs = split (/\\/, $nonenglish); } foreach $dir (@dirs) { $path .= "/$dir"; $desc = shift (@descs); $output .= qq|$desc:|; } chop ($output); return $output; }