#!/usr/bin/perl -w # # Recipe Gathering Program # use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); BEGIN { my $errorLog = "/home/mmtnsage/errors/rgather.log"; use CGI::Carp qw(carpout); open (LOG, ">> $errorLog") or die "Unable to append to $errorLog: $!\n"; carpout(*LOG); } BEGIN { unshift( @INC, "/home/mmtnsage/bin"); } use CGI::FastTemplate; my $base_dir = "/home/mmtnsage/public_html/recipes/store/"; my $html_base = "/cgi-local/rlink.cgi?"; my $openTitle = ""; my $closeTitle = ""; my $pattern = join(' ', @ARGV); if ($pattern eq "") { $pattern = param("search_text"); } #Bill added this $pattern =~ s/%(..)/pack("c",hex($1))/ge; my %recipes = (); open(FIND, "fgrep -li \"$pattern\" $base_dir/*.rcp | xargs fgrep -i \"\" | ") || die "Could'nt run find: $!\n"; my $data; my $filename; my $title; my $target; my $templateDir = "/home/mmtnsage/public_html/Templates"; my $recipeTemplate = "recipe.html"; while ($data = <FIND>) { $data =~ s/$base_dir//; ($filename, $title) = split(/:/, $data, 2); if ($title eq "") { $title = $filename; open(NAME, "find $base_dir -name \*.rcp | xargs fgrep -li \"$pattern\" | ") || die "Could'nt run find: $!\n"; $filename = <NAME>; $filename =~ s/$base_dir//; $filename =~ s/\n//; close(NAME); } $title =~ s/$openTitle//i; $title =~ s/$closeTitle//i; $title =~ s/^\s+//; $title =~ s/\n//; # print "Filename : $filename\n"; # print "Title : $title\n"; $recipes{$title} = $filename; } close(FIND); $title = "Recipes containing $pattern"; my $body = "<center><h1>Recipes containing $pattern</h1></center>\n"; $body .= "<hr>\n"; $body .= "<ul>\n"; foreach $target (reverse sort keys(%recipes)) { $body .= "<li><a href=\"$html_base$recipes{$target}\">$target</a><br>\n"; } $body .= "</ul>\n"; $body .= "<hr>\n"; my $tpl = new CGI::FastTemplate($templateDir); $tpl->define( main => $recipeTemplate ); $tpl->assign( TITLE => $title ); $tpl->assign( BODY => $body ); $tpl->parse( MAIN => "main" ); print header(); $tpl->print();