#!/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 = ) {
$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 = ;
$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 = "Recipes containing $pattern
\n";
$body .= "
\n";
$body .= "\n";
foreach $target (reverse sort keys(%recipes)) {
$body .= "- $target
\n";
}
$body .= "
\n";
$body .= "
\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();