scriptygoddess

04 May, 2002

Subscribe to comments (in MT): Call for help

Posted by: Jennifer In: Projects

Ok.. this CAN be done… I KNOW it can… I'm close… but not quite there… Here's my "plan" for the code:

Create an intermediate "processing" file that will be the "action" instead of the mt-comments.cgi. On this page I will:
1) see if a "subsribe email list" file exists.
2) if so, parse it into an array
3) iterate through the array sending emails to each person's email (that's whats in the array – it's an array of emails of people who have subscribed to the comments for that post) with just the Author and text of the comment
5) We'll load all the values of the comment form (from the previous page) into hidden form elements.
4) Then onLoad, we'll submit the form like normal – to mt-comments.cgi so that the comment is logged, and the blog author gets their comment notification, etc.

Creating a "subscribe to comments" form has still yet to be completed, but that, I would imagine would be pretty simple… on the page itself create a secondary form – creating that subscribe email list (with the post ID in the filename to seperate it from other posts).

Ok, here's where I am, and here's the problems I'm having: (Everyone and anyone is free to comment and help out with the script! This is all in the name of fun and learning, and all are welcome to participate!!!)

Here's the code I came up with… it's not really complete… but you get the idea…

<?
$fileString = "/honme/PATH_TO_COMMENTSUBSCRIBE_FOLDER/commentsubscribe/";
$fileString .= "$entry_id";
$fileString .= "email.ini";
if (file_exists($fileString)) {
$emailList = parse_ini_file("$fileString");
$count = count($emailList);
}
if (!strcasecmp($isSent, "false")) {
for ($i = 0; $i < $count; $i++) {
mail("$emailList[$i]", "New Comment on $entry_id", "Author: $author\ncomment: $text", "From: scriptyATscriptygoddessDOTcom");
}
$submitForm = "document.comments_form.submit()";
$isSent = true;
} else {
$submitForm = "document.location='YOUR_HOME_PAGE'";
/*
I put this here in case someone tried to reload THIS page…
that way the $isSent variable is set to true (at the bottom)…
and the form won't process again post the comment again
and annoy people with bogus emails
*/
}
?>
<html><head><title></title></head><body onLoad="<? echo $submitForm ?>">
<form method="post" action="PATH_TO_YOUR_MTCOMMENTSFILE/mt-comments.cgi" name="comments_form">
<input type="hidden" name="static" value="<? echo $static ?>" />
<input type="hidden" name="entry_id" value="<? echo $entry_id ?>" />
<input type="hidden" name="ipadd" value="<? echo $ip ?>" />
<input type="hidden" name="author" value="<? echo $author ?>" />
<input type="hidden" name="email" value="<? echo $email ?>" />
<input type="hidden" name="url" value="<? echo $url ?>" />
<input type="hidden" name="text" value="<? echo $text ?>" />
<input type="hidden" name="post" value="submit" />
</form>
<?
$isSent = "true";
?>
</body>

Problem #1:
That $isSent failover… doesn't work.. it processes the comment again
Problem #2:
I did some bug-testing feedback thingys and it doesn't seem to be parsing the email list file (I set up a temporary one manually)

However, the comment DOES go through… so once we get this page working, it should work!

Thoughts? Comments? Ideas???

13 Responses to "Subscribe to comments (in MT): Call for help"

1 | Lynda

May 4th, 2002 at 2:48 pm

Avatar

Okay. I setup a test page to submit the form – I assume we have the comments form submit to the php page using the above code INSTEAD OF mt-comments.cgi??

Doing that I got the php page with the form to display all the right fields, but not send the email. There were also no comments submitted to mt-comments.cgi. Is that where I should be at? I just want to make sure we're on the same page before I start. lol.

If so, we need to figure out why exactly the file isn't being parsed correctly and how to pass the comment information along to mt-comments.cgi ?

2 | Lynda

May 4th, 2002 at 2:57 pm

Avatar

Okay, I got the email list file to be READ by just doing this:

$emailList = file("$fileString");

Instead of parse_ini_file. Does that get us any closer? It still isn't sending the mail out – off to tackle that battle next with my trusty old friend php.net. hehe

So close and yet so far!

GREAT job on this Jenn. I wish I had your brain. :)

3 | Lynda

May 4th, 2002 at 3:05 pm

Avatar

Okay – next. I got emails to be sent to me from the list by replacing this:

if (!strcasecmp($isSent, "false")) {

with this:

if (!isset($isSent)) {

I'm not sure if that's the effect you wanted, but basically mine says "If the value isSent has not been assigned yet, do this"

I'm getting two emails per "comment" though – one from lynda@digitalwoe.com with "New Comment on 1356" in the subject and one from "Nobody" with nothing at all in the subject, but both the Subject: and From: fields INSIDE the email.

I think we might be getting closer?

4 | Lynda

May 4th, 2002 at 3:21 pm

Avatar

Okay, woo, I'm an idiot. :)

I had it going to two of my email addresses. For some reason, when I send it FROM lynda@digitalwoe.com, it comes up with all that blank stuff, but if I make up an address, it works fine. It probably has something to do with my server though, not the script.

Okay, on to how to get it all to post to MT. :)

5 | Lynda

May 4th, 2002 at 3:22 pm

Avatar

what a moron am I? That's what the body onload thing is. I took that out for testing purposes. hehe. Let's add that back and see what we get..

6 | Lynda

May 4th, 2002 at 3:23 pm

Avatar

IT WORKS IT WORKS IT WORKS!!!!!!!

7 | Lynda

May 4th, 2002 at 3:29 pm

Avatar

Okay, since we're posting to this intermediate form, we can also add some hidden fields that contains the title of the post or other goodies (even maybe the post itself or an excerpt from the post) to be included in the email.

"New Comments on Project: Subscribe to comments (in MT): Call for help" (while it's long, heh) would be a bit better than New Comments on 1356.

:)

When this is ready for release, I would also recommend people spruce up their intermediate page as well (such as "Your comment is now being posted. Thanks for caring!" or something so people have something to look at for that half second they're on that page.

So I guess now what's left to do is create a script to:

1) check to see if the subscription page exists
2) if not, create it and add the email address to it
3) if so, open it, append it to add the email address to it
4) close the file and send the user back to another page.

This is so exciting! Jenn, you ROCK.

8 | Lynda

May 4th, 2002 at 4:50 pm

Avatar

Okay, I changed things around a bit as far as the file that's called up just because I didn't see any sense in breaking it up and ini files scare me. I assume these can be changed back. Otherwise, everything works!

Here's what I have for the subscribe script:

%lt;?
$fileString = "/home/pathto/comment_subscribe_folder/$entry_id.txt";
$file = fopen("$fileString", "a+");
if ($file) {
fputs($file, $email);
fputs($file, "\n");
fclose($file);
}
?%gt;

It will try to open the file and if it doesn't exist, it will create it. Then it will put the email address and a line break in there before closing the file.

The good thing about this is you can create a separate subscription.php or whatever for people who don't want to leave comments to subscribe to the thread

*AND* you can put another line in your comments form like this:

<input type="checkbox" name="subscribe" value="yes" /> <span>Subscribe to comments?</span>

then include the snippet in the sendcomments.php file like so (this is my entire file, to show all the changes I've made):

<?
$fileString = "/home/lynda/public_html/posh/$entry_id.txt";

if ($subscribe) {
$file = fopen("$fileString", "a+");
if ($file) {
fputs($file, $email);
fputs($file, "\n");
fclose($file);
}
}

if (file_exists($fileString)) {
$emailList = file("$fileString");
$count = count($emailList);
}
if (!isset($isSent)) {

for ($i = 0; $i < $count; $i++) {
mail("$emailList[$i]", "New Comment on $entry_id", "Author: $author\ncomment: $text", "From: comments@digitalwoe.com");
}

$submitForm = "document.comments_form.submit()";
$isSent = true;
} else {
$submitForm = "document.location='http://posh.digitalwoe.com'";
/*
I put this here in case someone tried to reload THIS page…
that way the $isSent variable is set to true (at the bottom)…
and the form won't process again post the comment again
and annoy people with bogus emails
*/
}
?>
<html><head><title></title></head><body onLoad="<? echo $submitForm ?>">

<form method="post" action="http://www.digitalwoe.com/cgi-bin/mt-comments.cgi" name="comments_form">
<input type="hidden" name="static" value="<? echo $static ?>" />
<input type="hidden" name="entry_id" value="<? echo $entry_id ?>" />
<input type="hidden" name="ipadd" value="<? echo $ip ?>" />
<input type="hidden" name="author" value="<? echo $author ?>" />
<input type="hidden" name="email" value="<? echo $email ?>" />
<input type="hidden" name="url" value="<? echo $url ?>" />
<input type="hidden" name="text" value="<? echo $text ?>" />
<input type="hidden" name="post" value="submit" />
</form>
<?
$isSent = "true";
?>
</body>

===========================

There's one problem I forsee – how to let users unsubscribe?

I assume it is possible to create a script to:
1) open a file
2) search the file for the string (the email address)
3) remove the string from the file
4) close the file

Once we do the unsubscribe, this will be a very functional script! Greymatter users will be able to use it as well!!! Perhaps once we get this rock solid, I'll write up GM specific directions.

Awesome, awesome. (I know, I was being a spoiled sport before. lol)

9 | Lynda

May 4th, 2002 at 4:51 pm

Avatar

lol. the subscribe script should obviously have php openers and closers to it. I accidentally replaced the ampersand with the % and that didn't come out right.

10 | Lynda

May 4th, 2002 at 8:45 pm

Avatar

Okay, woot! I got the meat of the subscribe/unsubscribe. One more thing I'd like to add to the subscribe is to check for duplicates and eliminate them. There's a unique array function, but I haven't fiddled with it yet.

Here's what I have so far – you can put the subscribe.php script inside the sendcomment script and execute the ability to subscribe/unsubscribe to comments either WHEN someone posts and also separately.

<?
$fileString = "/home/pathto/comment_folder/$entry_id.txt";

###################
/* This code, line for line says that if the variable equals subscribe, then open up the above file in APPEND mode (make additions). If the file doesn't exist, create one. Trim the email address, then put it at the end of the file and include a line break, then close the file. */
###################

if ($subscribe)
{
$file = fopen($fileString, "a");
if ($file)
{
$email = trim($email);
fputs($file, "$email\n");
fclose($file);
}
}

###################
/* This code, line for line says that if the above file exists (otherwise it gives me errors) and then if the variable equals unsubscribe, then put the file into an array. Then open up the file in WRITE mode (overwrite previous file). If that array exists, then reassign the array to a new varaible, $oldemail. Trim the oldemail varable to remove the line breaks. Then if the oldemail address does NOT equal the unsubscription email address, write it to the file, then close the file. This basically just rewrites the entire file MINUS the unsubsription address. Probably not the best method of doing things. Any improvements would be appreciated. */
###################

if (file_exists($fileString))
{
if ($unsubscribe)
{
$array = file($fileString);
$file = fopen($fileString, "w");
if ($array)
{
foreach($array as $oldemail)
{
$oldemail = trim($oldemail);
if ($oldemail != $email) fputs($file, "$oldemail\n");
}
fclose ($file);
}
}
}
?>

11 | Jennifer

May 4th, 2002 at 9:21 pm

Avatar

LOL!! I go out for an afternoon… and look at all that you did!! DAMN! NICE job!!!

I'm going to read through all this and see where we are (and if it's working implement it here on scriptygoddess) 😀

12 | Lynda

May 4th, 2002 at 9:30 pm

Avatar

I must have left an h3 tag open.

I got it to work fully with my test runs, so if you come into any problems, please let me know. :)

13 | オンラインカジノ

May 16th, 2004 at 1:47 am

Avatar

I had it going to two of my email addresses. For some reason, when I send it FROM lynda@digitalwoe.com, it comes up with all that blank stuff, but if I make up an address, it works fine. It probably has something to do with my server though, not the script.

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements