WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: Argos on November 10, 2010, 01:39:04 PM

Title: Droplet or snippet request for notification when news is commented
Post by: Argos on November 10, 2010, 01:39:04 PM
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 https://forum.WebsiteBaker.org/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!
Title: Re: Droplet or snippet request for notification when news is commented
Post by: pcwacht 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
Title: Re: Droplet or snippet request for notification when news is commented
Post by: Argos 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);
Title: Re: Droplet or snippet request for notification when news is commented
Post by: pcwacht 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.
Title: Re: Droplet or snippet request for notification when news is commented
Post by: Argos 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.
Title: Re: Droplet or snippet request for notification when news is commented
Post by: pcwacht 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
Title: Re: Droplet or snippet request for notification when news is commented
Post by: nuke 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);
Title: Re: Droplet or snippet request for notification when news is commented
Post by: snark 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
Title: Re: Droplet or snippet request for notification when news is commented
Post by: pcwacht 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
Title: Re: Droplet or snippet request for notification when news is commented
Post by: snark on March 01, 2011, 01:12:10 PM
you will receive it today

Title: Re: Droplet or snippet request for notification when news is commented
Post by: CaptainRob 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
Title: Re: Droplet or snippet request for notification when news is commented
Post by: marmot 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
Title: Re: Droplet or snippet request for notification when news is commented
Post by: CaptainRob 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
Title: Re: Droplet or snippet request for notification when news is commented
Post by: Boudi 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?
Title: Re: Droplet or snippet request for notification when news is commented
Post by: Boudi 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.

Title: Re: Droplet or snippet request for notification when news is commented
Post by: DarkViper 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
Title: Re: Droplet or snippet request for notification when news is commented
Post by: Gast 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 (http://forum.WebsiteBaker.org/index.php/topic,28760.msg201484/boardseen.html#new) after line 160 and for line 161
Title: Re: Droplet or snippet request for notification when news is commented
Post by: Boudi on November 16, 2015, 08:53:42 AM
Hi folks :)

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