Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [MOD] sending email on new comment... (sNews 1.4)  (Read 6070 times)

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[MOD] sending email on new comment... (sNews 1.4)
« on: March 18, 2006, 07:58:42 pm »

I don't know if it exists already but this little mod allows you to receive an email when there is a new comment for an article. I use it with sNews 1.4.

The comment function modified:

Code: [Select]
if (isset($_POST['comment']) AND strlen($_POST['name']) > 2 AND strlen($_POST['comment']) > 5) {
echo "

". l('comment_sent') ."

";
if ($go_to_page > 1) { echo "

". l('backarticle'). "

"; }
else { echo "

". l('backarticle'). "

"; }
$name = $_POST['name'];
$comment = $_POST['text'];
$time = date('Y-m-d H:i:s');
            $time_date = date('d-m-Y');
$time_hours = date('H:i:s');
$articleid = $_POST['id'];
 
/////////// added code //////////////////////
           $message = "There is a new comment from $name on your site for the fallowing article: ".s('website') .$_POST['category']. "/" .$_POST['article']. "/";
           mail('email@domain.com','New Comment On Your Site!',$message);
///////////////////////////////////////////////


        mysql_query("INSERT INTO ". s('prefix')."comments(articleid,name,comment,time) VALUES('$articleid', '$name', '$comment', '$time')");
    } else if (isset($_POST['comment'])) {


Does somebody know if that poses problems of security?




Logged

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[MOD] sending email on new comment... (sNews 1.4)
« Reply #1 on: March 18, 2006, 08:47:44 pm »

a better code:

in  GLOBAL SETTINGS:
Code: [Select]
$s['email_on_comment'] = "YES"; // Send an email on new comment (YES OR NO)

and in the comment function:

Code: [Select]
...
//////////////////////////////////////////////
if(s('email_on_comment') == "YES") {
   $message = "There is a new comment from $name on your site for the fallowing article: ".s('website') .$_POST['category']. "/" .$_POST['article']. "/";
   mail(s('website_email'),'New Comment On Your Site!',$message);
}
///////////////////////////////////////////
...


Logged

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
[MOD] sending email on new comment... (sNews 1.4)
« Reply #2 on: March 18, 2006, 10:28:21 pm »

Great, Avenir, good job!  ;)
I've modified your code for better localization:

In LANGUAGE VARIABLES, add this:
Code: [Select]
$l['alert_comment_message'] = "There is a new comment from '" .$_POST['name']. "' on your site for the following article: ";
$l['subject_alert_comment'] = "New Comment On Your Site!";

And, In GLOBAL SETTINGS, add this:
Code: [Select]
$s['comment_sender'] = "from: sender@mail.com"; // Sender 'from:'. Replace 'sender@mail.com' by the mail that you need
 to use.

And, finally, the modified comment function:
Code: [Select]
// Send comments to mail ---------------------
if(s('email_on_comment') == "YES") {
   $message = l('alert_comment_message') .s('website') .$_POST['category']. "/" .$_POST['article']. "/";
   mail(s('website_email'),l('subject_alert_comment'),$message,s('comment_sender'));
}
// -------------------------------------------

I hope that helps for better localizations of sNews installations.  ;)
bram.



Quote from: avenir
a better code:

in  GLOBAL SETTINGS:
Code: [Select]
$s['email_on_comment'] = "YES"; // Send an email on new comment (YES OR NO)

and in the comment function:

Code: [Select]
...
//////////////////////////////////////////////
if(s('email_on_comment') == "YES") {
   $message = "There is a new comment from $name on your site for the fallowing article: ".s('website') .$_POST['category']. "/" .$_POST['article']. "/";
   mail(s('website_email'),'New Comment On Your Site!',$message);
}
///////////////////////////////////////////
...



Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Espaņol

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[MOD] sending email on new comment... (sNews 1.4)
« Reply #3 on: March 18, 2006, 10:36:21 pm »


Thanks bramsyuur for your improvements  ;)

Logged

Luka

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 36
  • Posts: 1717
    • http://www.snewscms.com
[MOD] sending email on new comment... (sNews 1.4)
« Reply #4 on: March 19, 2006, 01:01:47 pm »

This is a great mod! Maybe I should put this feature in standard release cause it's a small piece of code...
Logged

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
[MOD] sending email on new comment... (sNews 1.4)
« Reply #5 on: March 19, 2006, 01:19:58 pm »

Yes, this is a great piece of code, simple... like a sNews!  ;)
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Espaņol

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[MOD] sending email on new comment... (sNews 1.4)
« Reply #6 on: March 19, 2006, 04:00:39 pm »

Yes it's a small piece of code...but it is very useful for me   :)
Logged

Tjobbe

  • Full Member
  • ***
  • Karma: 0
  • Posts: 112
    • http://www.farstyle.com
[MOD] sending email on new comment... (sNews 1.4)
« Reply #7 on: March 31, 2006, 11:16:32 am »

I added Bramsyuurs code but I'm not getting any notifications by email, I changed the "sender@mail.com" to ym email address and added the three sections in the relevant sections but not getting any emails? I'll try avenirs code!
Logged

Tjobbe

  • Full Member
  • ***
  • Karma: 0
  • Posts: 112
    • http://www.farstyle.com
[MOD] sending email on new comment... (sNews 1.4)
« Reply #8 on: March 31, 2006, 11:26:06 am »

@ bramsyuur

I just added the modified comment function at the end of the comments part of the snews.php file, after the three closing }}} brackets, was I right?

Reason I ask is because I'm not receiving any notifications.

If I use Avenirs script, I get multiple emails (about 30 before I stopped it!)
Logged

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[MOD] sending email on new comment... (sNews 1.4)
« Reply #9 on: March 31, 2006, 12:21:05 pm »

Hi Tjobbe,

Place the code in if (isset($_POST['comment']) AND strlen($_POST['name']) > 2 AND strlen($_POST['comment']) > 5) section.

Logged

Tjobbe

  • Full Member
  • ***
  • Karma: 0
  • Posts: 112
    • http://www.farstyle.com
[MOD] sending email on new comment... (sNews 1.4)
« Reply #10 on: March 31, 2006, 02:08:38 pm »

Thanks avenir! It works now.

Heres what I had to do, to stop any confusion:

ADD:
Code: [Select]
$s['comment_sender'] = "from: sender@mail.com"; // Sender 'from:'. Replace 'sender@mail.com' by the mail that you need to use.
$s['email_on_comment'] = "YES"; // Send an email on new comment (YES OR NO)

at the end of the GLOBAL settings.

ADD:
Code: [Select]
$l['alert_comment_message'] = "There is a new comment from '" .$_POST['name']. "' on your site for the following article: ";
$l['subject_alert_comment'] = "New Comment On Your Site!";

at the end of the Language Variables.

ADD:
Code: [Select]
// Send comments to mail ---------------------
if(s('email_on_comment') == "YES") {
   $message = l('alert_comment_message') .s('website') .$_POST['category']. "/" .$_POST['article']. "/";
   mail(s('website_email'),l('subject_alert_comment'),$message,s('comment_sender'));
}
// -------------------------------------------

Inte //COMMENTS section, directly after the following:

Code: [Select]
if ($commentspage == 0) { $commentspage = 1; }
if (isset($_POST['comment']) AND strlen($_POST['name']) > 2 AND strlen($_POST['comment']) > 5) {
echo "

". l('comment_sent') ."

";

and that worked fine for me
Logged

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
[MOD] sending email on new comment... (sNews 1.4)
« Reply #11 on: March 31, 2006, 06:29:46 pm »

@Tjobbe:
Sorry for my delay to reply your question.
I've time right now...
Good, I've look that your get it working!  ;)
bram.
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Espaņol

bryn

  • Hero Member
  • *****
  • Karma: 2
  • Posts: 934
    • http://www.cssugly.com
[MOD] sending email on new comment... (sNews 1.4)
« Reply #12 on: April 01, 2006, 08:34:43 am »

excellent work guys! very neat and useful ;D
Logged
Over 1,000 posts of joy, sNews is not only brilliant, but fun too! thanks guys :D

Alien

  • Newbie
  • *
  • Karma: 0
  • Posts: 26
[MOD] sending email on new comment... (sNews 1.4)
« Reply #13 on: April 02, 2006, 06:09:15 pm »

Brilliant guys, thanks for your efforts; this works great and just what I needed!  ;D 8)

What I'd love to see in future options is the ability to preview (e.g. a 'pre-moderation') the comment first and then delete/edit before publishing if not appropriate.  :)
Logged

Jochum Meester

  • Sr. Member
  • ****
  • Karma: 1
  • Posts: 309
    • JochumMeester.com
[MOD] sending email on new comment... (sNews 1.4)
« Reply #14 on: April 05, 2006, 11:33:03 pm »

You should make that suggestion in the right forum (I hope that's the right one hehe), that would be a nice suggestion by the way! One that could be forked into/from moderating-articles with multiple users! :P

Can this email-on-new-comment be integrated in the Installer? I was going to try myself but the PHP is still too hard for me  :-[
Logged