#!/usr/bin/perl
#######################################################################################################
BEGIN {
use FindBin qw($Bin $Script);
use lib "$Bin/../lib";
}
#######################################################################################################
#use strict;
use CGI qw(:all);
use CGI ();
use CGI::Carp qw(fatalsToBrowser);
use vars qw($query);
$query = new CGI;
my $sendnow = $query->param('sendnow');
# change these paths when needed
my $mailprog = '/usr/sbin/sendmail';
my $fullpathtoscript = 'http://www.rightathomedaily.com/cgi-bin/sendarticle.cgi';
my $serverpath = '/u230/bwolf12/';
my $httpserver = 'http://www.rightathomedaily.com/';
my $referringurl = $ENV{'HTTP_REFERER'};
my $begintag = '';
my $endtag = '';
#######################################################################################################
my $filetosend = $referringurl;
$filetosend =~ s/$httpserver/$serverpath/g;
if ($filetosend =~ /html/oi){ }else{$filetosend = $filetosend . 'index.html';}
my $RECIPIENT= $query->param('recipient');# REQUIRED
my $MESSAGE= $query->param('message');
my $EMAIL= $query->param('email');
#######################################################################################################
if (!$sendnow) {
&print_out_form;
}
else{
$filetosend = $query->param('filetosend');
$referringurl = $query->param('referringurl');
# check to see data was entered correctly ... if not give errors back
#&make_sure_everything_is_ok;
# parse out article the file and take only the portion designated by the ARTICLE TAG
my $article = parse_article();
# send out the email with the article
&send_email;
}
#######################################################################################################
sub send_email{
open(MAIL,"|$mailprog -t");
print MAIL "To: $RECIPIENT\n";
print MAIL "From: $EMAIL\n";
print MAIL "Subject: Completely At Home.\n\n";
print MAIL "$EMAIL thought you would be interested in this article from Completely At Home.\nCompletely At Home is an editorial program sponsored by Studio One Networks (http://www.studioonenetworks.com/). \n";
print MAIL "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
print MAIL "$MESSAGE\n";
print MAIL "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
print MAIL "\n".$article."\n\n";
print MAIL "This article can be found on-line at:\n";
print MAIL "$referringurl\n";
print MAIL "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
print MAIL "Completely At Home is an editorial program made possible by the sponsorship of Studio One \n";
close(MAIL);
#print "Content-type: text/html\n\n
Send Article THANKS\n";
print "Location: $referringurl \n\n";
exit;
}#end send email
#######################################################################################################
sub parse_article{
# open up the file
open(TEXT,$filetosend); # Open the datafile
# read in the file
while() # Loop through every line in the file
{ $longstring .= $_;}
close(TEXT);
my $foundarticletag = 0;
@lines = split( /\n/, $longstring);
# go through the lines append if part of the article
foreach $line (@lines){
# look for TAG
if($line =~ m/$begintag/){$foundarticletag = 1;}
# look for TAG
if($line =~ m/$endtag/){$foundarticletag = 0;}
if($foundarticletag){ $article = $article . $line . ' ';}
}# end of foreach line
$misc = 'Send this article';
$misc1= 'to a friend';
$misc2= 'Print this article';
if ($sendnow){
# convert line breaks and paragraph breaks
$article =~ s/\n/ /g;
$article =~ s/\r/ /g;
$article =~ s/\t/ /g;
$article =~ s//\n\t/g;
$article =~ s//\n\t/g;
$article =~ s/<\/ul>/\n/g;
$article =~ s/<\/UL>/\n/g;
$article =~ s/
/\n/g;
$article =~ s/
/\n/g;
$article =~ s//\n\n/g;
$article =~ s/
/\n\n/g;
$article =~ s/$misc/ /g;
$article =~ s/$misc1/ /g;
$article =~ s/$misc2/ /g;
# parse all the fuct up html out
$article =~ s/<([^>]|\n)*>//g;
}
# send $article back
return $article;
}# end parse article
#######################################################################################################
sub print_out_form{
my $article = parse_article();
# convert line breaks and paragraph breaks
#$article =~ s/\n/ /g;
#$article =~ s/\r/ /g;
#$article =~ s/\t/ /g;
$article =~ s/
/\n - /g;
$article =~ s//\n - /g;
$article =~ s/<\/ul>/\n /g;
$article =~ s/<\/UL>/\n /g;
$article =~ s/
/\n/g;
$article =~ s/
/\n/g;
$article =~ s//\n\n /g;
$article =~ s/
/\n\n /g;
$article =~ s/$misc/ /g;
$article =~ s/$misc1/ /g;
$article =~ s/$misc2/ /g;
# parse all the fuct up html out
$article =~ s/<([^>]|\n)*>//g;
$article =~ s/\n/
/g;
print <<"END_PAGE";
Content-type: text/html
Completely At Home
Mail Article to a Friend
$article
|
END_PAGE
exit;
}#end print out form
#######################################################################################################