Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Seeking applications ...
Author Message
jamdung92
New Member
New Member


Joined: Oct 22, 2003
Posts: 10

PostPosted: Wed Jan 14, 2004 9:39 am Reply with quote

I've been looking for something -- I guess it would be a hack -- that would automatically email members when a new news item is posted. My site is just a small family site, so people aren't in the habit of checking it frequently and therefore often don't know when something new is posted. I tried modifying the email that goes to the admin when news is posted -- I sent it to an email address that forwarded to all members. However, it's a cumbersome solution and people may get the email and try to check the site before I actually post the item. Ideally, the email would be sent when the story was approved and posted.

Any ideas whether this exists or is possible?

Thanks!
 
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17086

PostPosted: Wed Jan 14, 2004 11:11 am Reply with quote

Laughing - Have you seen the hack I'm testing right now? Read the new's story on the front page, if not. When I get that tweaked I will look into the other - it would really be easy to do.
 
View user's profile Send private message
jamdung92
PostPosted: Wed Jan 14, 2004 4:23 pm Reply with quote

I have seen the hack and I love it!

If you really are able to look at such a hack as described I would be thrilled.

Thanks for the response.
 
Raven
PostPosted: Wed Jan 14, 2004 4:28 pm Reply with quote

I'll try to get you your code tonight Smile
 
Raven
PostPosted: Thu Jan 15, 2004 5:43 am Reply with quote

I haven't forgotten about this Smile. I started working on it last night but ran out of time. I should be able to get to it some time today.
 
jamdung92
PostPosted: Thu Jan 15, 2004 2:56 pm Reply with quote

No worries. I can't thank you enough for being so willing to even think about taking a shot at this modification.

Thanks!
 
jamdung92
PostPosted: Sun Feb 01, 2004 2:05 am Reply with quote

I’m trying to alter the comment notification hack to send an email to all users on my site whenever a new news item is posted by the admin. I’d like users to be able to opt-in to this feature and so the easiest way seemed to be to use the “newsletter” field in the nuke_users table.

I patterned this after the comment notification hack by inserting the following code at about line 986 (in function postStory) in stories.php: @include('ravenHacks/newpostNotification/hack_postnews_email.php');

Then, in the file hack_postnews_email.php I modified Raven’s original script as follows:

The main changes I tried to make:
1. Pulled story subject and author variables from the _queue table
2. Deleted the “if” statements related to $NotifyPostedBy and $NotifyInformant since these only apply to comments
3. Added a qualifier to the for loop that pulls the email addresses to only pull users if the newsletter field is =1

I got this script to send the admin an email, but the email was blank. I don’t know what variable to pass to the $emailMsgPreTxt variable to get it to display the story author. In trying to fix that, I somehow broke it again so that it doesn’t send anything. When I select “post story” and “ok” in the admin menu, it just returns a blank page in my browser. I could never get it to send emails to the users with the newsletter option selected. I guess I didn’t correctly fill the array with email addresses from the users table.

In posting this code, I’m making the huge assumption that troubleshooting my attempted hack is easy for someone who knows php and nuke (the former of which I clearly don’t). If this is too hard to troubleshoot in a forum, my apologies in advance for consuming the space and time.

Here’s the code:
Code:


/****** CONFIGURABLE SETTINGS FOR NOTIFICATION MOD **********************************************/
      $adminGetsAll    = True; // Whether or not Admin receives notification on ALL new posts
      $notifyPostedBy  = FALSE; // Admin who posted the original News item
      $notifyInformant = FALSE; // User who submitted the orignal News item
      $notifyCommenter = FALSE; // User adding the current comment DON'T NEED
      $emailSubjectPre = 'mywebsite.net has been updated!'; // Prepended text to the subject
      $emailMsgPreTxt  = ''.$author.' has posted a news entry entitled --> '; //Prepended text to the actual comment */
      $emailMsgPostTxt = ''.".\n\nDo not reply to this message as the reply address is YOUR address.\n\n---------\n\n"; // Postpended text to the actual comment
      $emailFromTitle  = 'Updates@website.net'; // Displayed in the email FROM line
      $emailXMailer    = 'Updates@website.net'; // Only valid if $xMailer set to TRUE
      $viewTheArticle  = "---------\n\nView the new post:"; // Text to announce the Article link
      $viewTheComment  = "Visit irielife.net"; // text to announce the Comment link
      $xPriority       = FALSE; // Use Email Header X-Priority?
      $xMsMailPriority = FALSE; // Use Email Header X-MS-Mail_Priority?
      $xMailer         = TRUE; // Use Email Header X-Priority?
/****** YOU SHOULDN'T HAVE TO CHANGE ANYTHING BELOW THIS LINE *************************************/
global $nukeurl, $adminmail;
/* Select story, admin who posted, story author, and title of the story */
/* Original $sql statement: $sql = "SELECT aid, informant, title FROM ".$prefix."_stories WHERE sid='$sid'"; */
       $sql             = "SELECT uid, uname, subject FROM ".$prefix."_queue WHERE qid='$qid'";
       $result          = $db->sql_query($sql);
       $row             = $db->sql_fetchrow($result);
       $usrid           = $row['uid'];
       $uname           = $row['uname'];
       $subject         = $row['subject'];
        $msg             = $emailMsgPreTxt.$subject.$emailMsgPostTxt;
        $msg            .= "\n\n$viewTheArticle\n$nukeurl/modules.php?name=News";
/************************************/
       $notify          = Array();
      if ($adminGetsAll) $notify[] = $adminmail;
       for ($i=0;$i<count($row);$i++) {
/* I think this next line is where I need a qualifier to send the email only to users who have opted to receive the newsletter  */
         $sql = "SELECT username, user_email FROM ".$prefix."_users WHERE username='".$row[$i][0]."' AND newsletter =1";
         $result = $db->sql_query($sql);
         $row1 = $db->sql_fetchrow($result);
         if (!$notifyCommenter) if (strtolower($name)==strtolower($row1['username'])) continue;
         if (in_array($row1['user_email'],$notify)) continue;
         if (strstr($row1['user_email'],'@')&&strstr($row1['user_email'],'.')) $notify[] = addslashes($row1['user_email']);
      }
/* The following appears to be the routine that sends an email to each username in the comment chain */
      for ($i=0;$i<count($notify);$i++) {
         $to = $notify[$i];
         $headers  = "From: $emailFromTitle <$to>\n";
         $headers .= "Reply-To: $to\n";
         if ($xPriority) $headers .= "X-Priority: 1\n";
         if ($xMsMailPriority) $headers .= "X-MSMail-Priority: High\n";
         if ($xMailer) $headers .= "X-Mailer: $emailXMailer\n";
         mail($to, $emailSubjectPre.$subject, $msg, $headers);
      }
     /********** END   Raven's hack to notify those who have replied to this article ***********/
?>
 
Raven
PostPosted: Sun Feb 01, 2004 8:27 am Reply with quote

The story author is the 'informant' variable.
 
jamdung92
PostPosted: Mon Feb 02, 2004 12:34 am Reply with quote

Thanks for the response. I got all the formatting working and it now sends an email to the $adminmail address with no problem, as long as the 'mail' statement is "mail($adminmail).

When I add in the code from the commentNotification hack for the 'for' loops (the ones that pull usernames/emails from the _users table and the one that assigns email addresses to the '$to' variable), it never sends out any emails. I think the error has something to do with the code used to identify the total number of members in the _users table, from which I am trying in the loop to select out the ones with a newsletter=1.

Here's the section of code that doesn't seem to work:

Code:


/* Count number of rows in users table to set index in the for loop below */   
      $sql              = SELECT user_id FROM ".$prefix."_users";
      $result       = $db->sql_query($sql);
      $members       = $db->sql_numrows($result);

      $notify      = Array();
        if ($adminGetsAll) $notify[] = $adminmail;
       for ($i=0;$i < $members;$i++) {
          $sql = "SELECT username, user_email FROM ".$prefix."_users WHERE username='".$row[$i][0]."' AND newsletter =1";
          $result = $db->sql_query($sql);
          $row1 = $db->sql_fetchrow($result);
          if (strtolower($name)==strtolower($row1['username'])) continue;
          if (in_array($row1['user_email'],$notify)) continue;
          if (strstr($row1['user_email'],'@')&&strstr($row1['user_email'],'.')) $notify[] = addslashes($row1['user_email']);
      }
       for ($i=0;$i<count($notify);$i++) {
         $to = $notify[$i];
         $headers  = "From: $emailFromTitle <$to>\n";
         $headers .= "Reply-To: $to\n";
         mail($to, $emailSubject, $msg, $headers);
?>


Does anyone have any suggestions for how to fix this to correctly email users who subscribe to the newsletter?

Thanks!
 
Raven
PostPosted: Mon Feb 02, 2004 6:03 am Reply with quote

If that is really all of your code, you are missing a closing } in your last 'for' loop.
 
jamdung92
PostPosted: Mon Feb 02, 2004 7:12 am Reply with quote

Unfortunately, that didn't fix it. The purposes of original hack and the one I was trying to make seemed so similar that I thought I could basically paste the for loops, but perhaps I misunderstand the purposes of these loops?

For what its worth, the only other code I had besides in my last post is included below.

Code:


<?
/* modified Raven's commentNotification hack to email users who subscribe to newsletter whenever new news is posted */
      $emailFromTitle  = 'mysite.net Updates';
      $emailSubject    = 'mysite.net Has Been Updated!';
      $emailMsgPreTxt  = ''.$author.' has posted a new family news item entitled:';
      $emailMsgPreTxt2 = $subject;
      $emailMsgPreTxt3 = 'on the mysite.net website.';
      $viewTheArticle  = "---------\n\nView the Article:";
          global $nukeurl, $adminmail;
         $msg             = "\n\n$emailMsgPreTxt\n\n$emailMsgPreTxt2\n\n$emailMsgPreTxt3";
         $msg          .= "\n\n$viewTheArticle\n$nukeurl/modules.php?name=News";
          $headers  = "From: $emailFromTitle <$adminmail>\n";
          $headers .= "Reply-To: $adminmail\n";
/* Works if the following statement is used, but email only goes to admin */
/*       mail($adminmail, $emailSubject, $msg, $headers);                */
/* Everything above here did not break the code as of 2/1/2004            */

/* Using the following code from Raven's hack results in no emails being sent   */
   $adminGetsAll   = TRUE;
/* Count number of rows in users table to set index in the for loop below */
 
jamdung92
PostPosted: Sat Feb 07, 2004 12:11 am Reply with quote

Well, it's finally working. If anyone is interested I'd be happy to share it.

Thanks again for the help, and for releasing the original hack!
 
sqzdog
Involved
Involved


Joined: Sep 22, 2003
Posts: 252

PostPosted: Mon Apr 26, 2004 6:43 pm Reply with quote

I'd like the hack!
 
View user's profile Send private message Send e-mail
jamdung92
PostPosted: Mon Apr 26, 2004 9:31 pm Reply with quote

I'd be happy to send it to you. I just need to add some documentation to it and I'll send it to you.
 
MickP
Hangin' Around


Joined: Sep 17, 2003
Posts: 31
Location: Australia

PostPosted: Thu Apr 29, 2004 3:00 am Reply with quote

I would also like a look at this hack, as I may be able to modify it further for something I am working on, whereby members can "opt in" for news sent in ONLY from members they select, so that they can be informed when their fav submitters post anything new. (I have 6500 members at the mo!)

Mick
 
View user's profile Send private message Visit poster's website
sqzdog
PostPosted: Sat Aug 27, 2005 9:51 am Reply with quote

Was this hack ever released?
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Seeking applications ...

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©