Author Topic: Droplet or snippet request for notification when news is commented  (Read 11720 times)

Offline Argos

  • Posts: 2542
  • Gender: Male
    • Argos Media
I tried to implement a function that sends an email notification when a news item is commented. There is a topic that has code, but I can't get it to work. See http://www.websitebaker2.org/forum/index.php/topic,4699.0.html

Ideal would be a droplet that I can just put in the settings of the news module, but code snippet to put in a php file would be okay as well. Can anyone help? Thanks in advance!
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Offline pcwacht

  • Posts: 2923
  • Gender: Male
    • Dutch ICT info
Re: Droplet or snippet request for notification when news is commented
« Reply #1 on: November 10, 2010, 02:00:17 PM »
Hoi Argos,

Can't be done with a droplet in settings.

You need extra code wich mail a warning when and only when a submission is made, therefore the best option is to add that code to submit_comment.php,
search for: around line 121,
   // Insert the comment into db
A few lines later, right before the header statement this code can be added.

   // Sending the email
               $mail_to = 'address@tosendmail.to';
               $mail_subject = 'A comment has been made';
               $mail_message = 'One newsitem has been commented on this page: '.$wb->page_link($page['link']).'?post_id='.$post_id.' !';
   $wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message);

Didn't test it!! but think it'll get you started ;)

Have fun,
John
http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....

Offline Argos

  • Posts: 2542
  • Gender: Male
    • Argos Media
Re: Droplet or snippet request for notification when news is commented
« Reply #2 on: November 10, 2010, 02:09:56 PM »
Works right away John, thank you very much!  :-D

I'll post a reference in the other topic.

I have edited the snippet to contain a working link and the comment itself:

 
Code: [Select]
$mail_to = 'address@tosendmail.to';
   $mail_subject = 'A comment has been made';
   $mail_message = 'One newsitem has been commented on this page: <a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a>
   
   Comment:
   '.$comment.'' ;
   
   $wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message);
« Last Edit: November 10, 2010, 02:25:16 PM by Argos »
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Offline pcwacht

  • Posts: 2923
  • Gender: Male
    • Dutch ICT info
Re: Droplet or snippet request for notification when news is commented
« Reply #3 on: November 10, 2010, 03:09:40 PM »
Cool to know I can still make working code without testing ;)

PS Will be incoörporated in articles.
http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....

Offline Argos

  • Posts: 2542
  • Gender: Male
    • Argos Media
Re: Droplet or snippet request for notification when news is commented
« Reply #4 on: November 10, 2010, 03:13:33 PM »
Cool to know I can still make working code without testing ;)
I'm jealous  :wink:
Quote
PS Will be incoörporated in articles.
Nice. Maybe you can use language variables instead of the hardcoded English text lines.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

Offline pcwacht

  • Posts: 2923
  • Gender: Male
    • Dutch ICT info
Re: Droplet or snippet request for notification when news is commented
« Reply #5 on: November 10, 2010, 03:20:18 PM »
will be in settings
adminsettings, use comments? use mail notification?
settings - comments, comment layout template and email template if the above is true

Will be a heap of settings ;)

John
http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....

Offline nuke

  • Posts: 31
Re: Droplet or snippet request for notification when news is commented
« Reply #6 on: February 24, 2011, 09:33:14 PM »
Thanks for this Argos and John - this works great, just what I was looking for =)

-Mike

Works right away John, thank you very much!  :-D

I'll post a reference in the other topic.

I have edited the snippet to contain a working link and the comment itself:

 
Code: [Select]
$mail_to = 'address@tosendmail.to';
   $mail_subject = 'A comment has been made';
   $mail_message = 'One newsitem has been commented on this page: <a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a>
   
   Comment:
   '.$comment.'' ;
   
   $wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message);

snark

  • Guest
Re: Droplet or snippet request for notification when news is commented
« Reply #7 on: February 27, 2011, 08:53:14 PM »
@pcwacht

Any progress on the articles module yet?

What i saw à while ago was very promising, i have made quite some additions to the news3,5 newsmodule, I will include the commentnotification and send you a version

Offline pcwacht

  • Posts: 2923
  • Gender: Male
    • Dutch ICT info
Re: Droplet or snippet request for notification when news is commented
« Reply #8 on: February 28, 2011, 08:43:37 AM »
Please do.

Artcles is still an ongoing work in progress. The progress is being slowed down cause of the promised 2.9, ,  allso I was/am bizzy with some other modules needed for work. And work itself.
Allso had some operation on my hip last september, I needed a new one wich slowed me down as well.

Am coding articles when I have some spare time left wich is rarely the case ;)


John
http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....

snark

  • Guest
Re: Droplet or snippet request for notification when news is commented
« Reply #9 on: March 01, 2011, 01:12:10 PM »
you will receive it today


Offline CaptainRob

  • Posts: 118
  • Gender: Male
Re: Droplet or snippet request for notification when news is commented
« Reply #10 on: November 09, 2012, 01:26:45 PM »
Hello,

For some time I added this code in my modules/news/submit_comment.php

Code: [Select]
$mail_to = 'mail1@tosendmail.to' . ', ';
$mail_to .= 'mail2@tosendmail.to';

   $mail_subject = 'A comment has been made';
   $mail_message = '<b> One item has been commented on this page: </b>
<a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a>

  <b> Title: </b>
'.$title.'

  <b> Comment: </b>
    '.$comment.'' ;
   
   $wb->mail(SERVER_EMAIL,$mail_to,$mail_subject,$mail_message);

That was working fine in WB 2.8.2 now I have updated to 2.8.3 it is not working any more.
With 1 email address it is working fine, but with 2 addresses nothing is happening.

So what must be changed to sent a notification mail to 2 email addresses?

Thanks,
Rob

Offline marmot

  • Posts: 1103
Re: Droplet or snippet request for notification when news is commented
« Reply #11 on: December 10, 2012, 09:49:38 PM »
Hi,

So what must be changed to sent a notification mail to 2 email addresses?
in wb 283 phpmailer was upgraded to version 5.2 which brings a validation function for email addresses. That's the reason why your solution doesn't work anymore ("email1, email2" is not a valid address).
So you could send mail by mail:
Code: [Select]
   $mail_subject = 'A comment has been made';
   $mail_message = '<b> One item has been commented on this page: </b>
<a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a>

  <b> Title: </b>
'.$title.'

  <b> Comment: </b>
    '.$comment.'' ;
   
  $wb->mail(SERVER_EMAIL,'mail1@tosendmail.to',$mail_subject,$mail_message);
  $wb->mail(SERVER_EMAIL,'mail2@tosendmail.to',$mail_subject,$mail_message);
if you really need to send only one mail with 2 recipients, the only possibility I see is to change the wb core. For example in class.wb.php ~line 418 you find:
Code: [Select]
$myMail->AddAddress($toaddress); change this to
Code: [Select]
$toaddresses = explode(', ',$toaddress);
foreach($toaddresses as $to)
$myMail->AddAddress($to);
none of these is tested so there is a good chance for errors in it  :wink:

regards

Offline CaptainRob

  • Posts: 118
  • Gender: Male
Re: Droplet or snippet request for notification when news is commented
« Reply #12 on: December 11, 2012, 05:30:12 PM »
Thank you for the solution Marmot.
It's correct, with your code WB is now sending two separate emails, but that's no problem for me.  :-)

Thanks,
Rob

Offline Boudi

  • Global Moderator
  • *****
  • Posts: 1190
  • Gender: Male
  • //o_-\\
    • Yze Webdesign
Re: Droplet or snippet request for notification when news is commented
« Reply #13 on: February 28, 2015, 11:37:29 AM »
Found this topic and this snippet code works well.

Any idea if a 'moderate' function is possible in the news mod?
...:: Bake the Unbakable ::...

Offline Boudi

  • Global Moderator
  • *****
  • Posts: 1190
  • Gender: Male
  • //o_-\\
    • Yze Webdesign
Re: Droplet or snippet request for notification when news is commented
« Reply #14 on: November 15, 2015, 10:04:58 PM »
I noticed that (in my case)

Code: [Select]
<a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a>
is not working properly any more and its output is: www.domain.com/pages.php instead of the specific url on where a comment was placed.

...:: Bake the Unbakable ::...

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 3028
  • Gender: Female
Re: Droplet or snippet request for notification when news is commented
« Reply #15 on: November 16, 2015, 12:22:54 AM »

Hi Boudi,

the wrong output of the Line <a href="'.$wb->page_link($page['link']).'">'.$wb->page_link($page['link']).'</a> is an effect only.
The reason of is an empty variable $page['link'].
So you must explore, where this VAR has been set and why it's empty.

Manuela
Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"You have to take the men as they are… but you can not leave them like that !" :-P
Das tägliche Stoßgebet: Oh Herr, wirf Hirn vom Himmel !

Offline jacobi22

  • Posts: 5890
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Droplet or snippet request for notification when news is commented
« Reply #16 on: November 16, 2015, 01:51:09 AM »
correct place for your code lines are after the insert and before the line with the header-location
in the actual SP5 Package after line 160 and for line 161
Wer nicht will, findet Gründe, wer will, findet Wege.

Offline Boudi

  • Global Moderator
  • *****
  • Posts: 1190
  • Gender: Male
  • //o_-\\
    • Yze Webdesign
Re: Droplet or snippet request for notification when news is commented
« Reply #17 on: November 16, 2015, 08:53:42 AM »
Hi folks :)

THnQ for your time and answers. They did the trick!  (Y)
...:: Bake the Unbakable ::...