Viewing file: npa_email.pl (13.17 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
# E-mail Notification addon for NewsPro
push(@Addons_Loaded, 'E-Mail Notification');
$Addons_List{'E-Mail Notification 1.02'} = ['npa_email.pl', 'Allows news items to be sent via e-mail, either with each post or in batches. Also maintains a mailing list.', 'http://amphibian.gagames.com/addon.cgi?email&1.02'];
push(@Addons_SaveNews, 'Email_SaveNews');
push(@Addons_LoadHelp, 'Email_LoadHelp');
push(@Addons_PageHandler, 'Email_PageHandler');
push(@Addons_AdvancedSettingsLoad, 'AddEmailSettings');
push(@Addons_MainPage, 'Email_MainPage');
push(@Addons_NPHTMLFoot, 'Email_HTMLFoot');
$NPConfig{'EnableEmail'} = 1;
sub AddEmailSettings {
$AdvDescr{'SendmailPath'} = "Full path to sendmail, or a comparable program (i.e. qmail). Do not include any parameters (i.e. do NOT include a -t).";
$AdvDescr{'EmailFrom'} = "The address all e-mails sent will appear to be from.";
$AdvDescr{'EmailTo'} = "A single address that all emails will be sent to. Other addresses can be added to the e-mail list via the E-mail Notification section, however all e-mail will appear to be sent to this address.";
$AdvDescr{'EmailSubject'} = "The subject of your notification e-mails.";
push(@advancedsettings, 'draw_line', 'SendmailPath' , 'EmailFrom' , 'EmailTo', 'EmailSubject');
}
sub Email_HTMLFoot {
if ($up == 3) {
print qq~ <a href="$scripturl?emailmain" class="navlink">E-Mail Notification</a> |~;
}
}
sub Email_MainPage {
if ($up == 3) {
print qq~
<b><a href="$scripturl?emailmain">E-Mail Notification</a>:</b> Allows you to configure e-mail notification, send manual e-mails, and view/edit your e-mail address list.<br><br>
~;
}
}
sub Email_PageHandler {
# Main E-Mail Notification screen
if (query_string() eq "emailmain") {
&EmailMain;
exit;
}
# View e-mail list
if (query_string() eq "emaillist") {
&EmailList;
exit;
}
# Save e-mail list
if (query_string() eq "emaillistsave") {
&SaveEmailList;
exit;
}
# Save Immediate/Batch e-mail setting
if (query_string() eq "saveemailsetting") {
&SaveEmailMain;
exit;
}
# Display/Compose batch e-mail
if (query_string() eq "batchemail") {
&EmailBatch;
exit;
}
# Send batch e-mail
if (query_string() eq "sendbatchemail") {
&EmailBatchSend;
exit;
}
}
sub Email_SaveNews {
if ($NPConfig{'ImmediateEmail'}) {
require $ndisplaypl;
$newsdate = &GetTheDate($newstime);
if ($NPConfig{'WrapEmailText'}) {$newstext = &WrapText($newstext);}
&DoEmailText;
$emailtext = $newshtml;
# Remove some HTML from the text
$emailtext =~ s/<a href="(\S+?)".*?>/(link:$1)/gi;
$emailtext =~ s/<br>/\n/gi;
$emailtext =~ s/<p>/\n\n/gi;
$emailtext =~ s/<.+?>//g;
$emailtext =~ s/>/>/g;
$emailtext =~ s/</</g;
$emailtext =~ s/"/"/g;
&SendListEmail($emailtext);
}
}
sub Email_LoadHelp {
$Help{'emailmain'} = q~The main E-Mail Notification screen. Choose from the different options to select a task. At the top of this page, you can choose whether to send e-mail immediately or manually. If you choose Immediately, e-mail will be sent to everyone on the list every time a news item is submitted, automatically. If you select Manually, to send mail you must go to this page and choose the appropriate option (the second on the list below) to send your e-mail. At that point, NewsPro will generate an e-mail draft containing all the news since you last sent an e-mail notification, and you will be able to edit and then send this mail.~;
$Help{'emaillist'} = q~The list of e-mail addresses that notification will be sent to. Addresses must be one per line. To add an address, simply enter it on a new line in the text box; to remove an address delete it and the line it's on. If you find that you are entering addresses but they are not appearing next time you look, this is because the script checks for the validity of the addresses you enter. They must conform to a format like something@some.thing, otherwise they will automatically be rejected.~;
$Help{'saveemailsetting'} = q~The main E-Mail Notification screen. Choose from the different options to select a task. At the top of this page, you can choose whether to send e-mail immediately or manually. If you choose Immediately, e-mail will be sent to everyone on the list every time a news item is submitted, automatically. If you select Manually, to send mail you must go to this page and choose the appropriate option (the second on the list below) to send your e-mail. At that point, NewsPro will generate an e-mail draft containing all the news since you last sent an e-mail notification, and you will be able to edit and then send this mail.~;
$Help{'batchemail'} = q~On this screen, you can edit and then send a manual e-mail notification. NewsPro has automatically generated a draft e-mail of all the news since you last sent out an e-mail, based on the style in ndisplay.pl. You may edit this if you'd like, and then press the Send Mail button to send this to everyone on your e-mail list.~;
$Help{'sendbatchemail'} = q~Send the e-mail you submitted to everyone on your e-mail list.~;
$Help{'emaillist_addingusers'} = q~You can allow users to add or remove themselves from your e-mail notification list. To do this, you need to use the viewnews.cgi module (included in your NewsPro ZIP file), which is the script that users of your site use to interact with NewsPro. The simplest way to add a subscribe/unsubscribe form is to access http://your.server/viewnews.cgi?emaillistform (in fact, <a href="viewnews.cgi?emaillistform">this link</a> should bring you to the right place) and cut and paste the HTML it generates onto your web page. That's it! Users enter their e-mail address, click Subscribe or Unsubscribe, and it's taken care of. Of course, if the page with the signup form is in a different directory than viewnews.cgi, you'll need to change the action= part of the form tag.<p>
As well, by default viewnews.cgi will generate its own confirmation message when the user (un)subscribes, and you can customize the look of the page by editing viewnews.tmpl. However, you may want to create your own confirmation pages. To do so, just add two hidden form fields (i.e. <input type="hidden" name="successredirect" value="http://www.yahoo.com/">) to your form, called successredirect and failureredirect and with a value of the appropriate URL, and the script will redirect users to one of the URLs, depending on whether their submission failed or succeeded.~;
}
# Displays the main E-Mail Notification page.
sub EmailMain {
unless ($UserPermissions{$Cookies{'uname'}} eq "3") {
&NPdie("You are not authorized to access this.");
}
&NPHTMLHead("E-Mail Notification");
unless ($NPConfig{'SendmailPath'} && $NPConfig{'EmailTo'} && $NPConfig{'EmailFrom'}) {
print "You have not fully configured e-mail notification. Please go to Advanced Settings, and
make sure all of the following are set: SendmailPath, EmailTo, and EmailFrom.";
NPHTMLFoot();
exit;
}
if ($NPConfig{'ImmediateEmail'}) {
$Imm1 = "";
$Imm2 = "checked";
} else {
$Imm1 = "checked";
$Imm2 = "";
}
print qq~
<form action="$scripturl?saveemailsetting" method="post">
Welcome to the E-mail Notification section. Choose among the following options:<br><br>
<b>Send E-mail immediately?</b> You can either have an e-mail sent to everyone on the list each
time a news item is posted, or be able to manually choose when to send an e-mail which contains
all news items posted since the last e-mail notification.<br>
<input type="radio" name="ImmediateEmail" value="0" $Imm1> Send manually, in batches <input type="radio" name="ImmediateEmail" value="1" $Imm2> Send immediately, with each post.
<br> <input type="submit" name="submit" value="Submit Setting"></form>
<hr>
<a href="$scripturl?emaillist"><b>View/Modify E-mail List</b></a> View and modify your list of e-mail addresses to send notifications to.<br><br>
~;
unless ($NPConfig{'ImmediateEmail'}) {
print qq~
<a href="$scripturl?batchemail"><b>Send E-mail Notification</b></a>
~;
} else {
print qq~
<b>Send E-mail Notification (<font color="#ffffff">Disabled</font>)</b>
~;
}
print qq~
Compose and prepare to send an e-mail news update (provided you have not chosen to send notification immediately).<br><br>
<a href="$scripturl?helpemaillist_addingusers" target="_top"><b>List Setup Help</b></a> View information on how to allow users to (un)subscribe themselves from your e-mail notification list.
~;
NPHTMLFoot();
}
# Saves the ImmediateEmail settings
sub SaveEmailMain {
unless ($up == 3) {
&NPdie("You are not authorized to access this.");
}
$NPConfig{'ImmediateEmail'} = $in{'ImmediateEmail'};
$NPConfig{'EnableEmail'} = 1;
&WriteConfigInfo;
&EmailMain;
}
# Loads the e-mail list into @emaillist
sub LoadEmailList {
@emaillist = split(/~/, $NPConfig{'emaillist'});
}
# View/Edit the e-mail list
sub EmailList {
unless ($UserPermissions{$Cookies{'uname'}} eq "3") {
&NPdie("You are not authorized to access this.");
}
LoadEmailList();
NPHTMLHead("View/Modify E-mail Notification List");
$emailnum = @emaillist;
print qq~
Your e-mail notification list is below. You may add or remove addresses to/from the list; simply make sure that there is one address per line.
Note that the address specified in the EmailTo setting (currently $NPConfig{'EmailTo'}) will always receive a copy of any e-mails sent.
There are currently <b>$emailnum</b> people on your mailing list.
<div align="center"><p><form action="$scripturl?emaillistsave" method="post"><textarea name="emaillist" rows="10" cols="50">~;
foreach $i (@emaillist) {
print "$i\n";
}
print qq~</textarea></p> <input type=submit name=submit value="Save Changes"> </div></form>
~;
NPHTMLFoot();
}
# Save the e-mail list
sub SaveEmailList {
unless ($UserPermissions{$Cookies{'uname'}} eq "3") {
&NPdie("You are not authorized to access this.");
}
@emailtemp = split(/\n/, $in{'emaillist'});
foreach $i (@emailtemp) {
$i = lc $i;
$i =~ s/\n//g;
$i =~ s/\r//g;
$i =~ s/~/\Q%2E\E/g;
if ($i =~ m/.+\@.+\.\S+/) {
push (@emaillist, $i);
}
}
$NPConfig{'emaillist'} = join('~', @emaillist);
WriteConfigInfo();
NPHTMLHead("E-Mail List Saved");
print qq~ Your changes to the e-mail list have been saved. ~;
NPHTMLFoot();
}
# Prepare and allow user to edit the manual/batch e-mail
sub EmailBatch {
unless ($UserPermissions{$Cookies{'uname'}} eq "3") {
&NPdie("You are not authorized to access this.");
}
require $ndisplaypl;
&loadND;
$newsnum = @NewsData - 1;
$batchemailtext = " ";
while ($newsnum >= 0) {
&getNDvar($newsnum);
if ($newstime > $NPConfig{'BatchEmail_LastTime'}) {
if ($NPConfig{'WrapEmailText'}) {$newstext = &WrapText($newstext);}
push(@batchemailtimes, $newstime);
&DoEmailText;
$batchemailtext .= $newshtml;
}
$newsnum--;
}
if (@batchemailtimes > 1) {
@batchemailtimes = sort {$a <=> $b} @batchemailtimes;
}
$BELastTime = $batchemailtimes[@batchemailtimes - 1];
$batchemailtext =~ s/<a href="(\S+?)".*?>/(link:$1)/gi;
$batchemailtext =~ s/<br>/\n/gi;
$batchemailtext =~ s/<p>/\n\n/gi;
$batchemailtext =~ s/<.+?>//g;
$batchemailtext =~ s/>/>/g;
$batchemailtext =~ s/</</g;
$batchemailtext =~ s/"/"/g;
NPHTMLHead("Compose E-Mail Notification");
print qq~
Below, edit the text of the e-mail notification you'd like to send. When you click Send Mail below,
this message will be sent to everyone on your e-mail list as well as $NPConfig{'EmailTo'} (the address
set in EmailTo).
<p align="center"><form action="$scripturl?sendbatchemail" method="post"><input type="hidden" name="BELastTime" value="$BELastTime">
<textarea name="batchemailtext" rows="10" cols="80" wrap="virtual">$batchemailtext</textarea>
<br><br><input type="submit" name="submit" value="Send Mail"></p>
~;
&NPHTMLFoot;
}
# Internal sub to send an e-mail to everyone on the list.
# Does NOT send individual e-mails (too slow, would need an nph script)
# Instead, sends a single e-mail and Bcc's it to everyone else.
sub SendListEmail {
local ($emailtext) = @_;
&LoadEmailList;
$emailbcc = join(',', @emaillist);
my $mailprog = $NPConfig{'SendmailPath'};
$mailprog =~ s/;//g;
$mailprog =~ s/[ \-]//g;
open(MAILPROG, "|$mailprog -t") || &NPdie("Could not open $mailprog to send e-mail.");
print MAILPROG "To: $NPConfig{'EmailTo'}\n";
print MAILPROG "From: $NPConfig{'EmailFrom'}\n";
print MAILPROG "Reply-to: $NPConfig{'EmailFrom'}\n";
print MAILPROG "Bcc: $emailbcc\n";
print MAILPROG "Subject: $NPConfig{'EmailSubject'}\n\n";
print MAILPROG $emailtext;
close(MAILPROG);
}
# Sends the batch e-mail.
sub EmailBatchSend {
unless ($UserPermissions{$Cookies{'uname'}} eq "3") {
&NPdie("You are not authorized to access this.");
}
$NPConfig{'BatchEmail_LastTime'} = $in{'BELastTime'};
&WriteConfigInfo;
&SendListEmail($in{'batchemailtext'});
&NPHTMLHead("E-Mail Sent!");
print "Your e-mail has been sent.";
&NPHTMLFoot;
}
# Restricts text to 80-column lines, for UNIX mail clients.
# Currently semi-broken.
sub WrapText {
local ($thetext) = @_;
$wraptext = "";
while ($thetext =~ /(.{1,80})[\s\z]/g) {
$wraptext .= "$thetext\n";
}
return $wraptext;
}
1;
|