Use Events to Send an Email when a Page is Edited?
Use Events to Send an Email when a Page is Edited?
Hello everyone,
I have searched and read many posts having to do with Events and UDTs, including the ones on this forum and the wiki handbook.
Still, I cannot figure out how to send an email when a page is edited.
I have a friendly supervisor who just wants to check for spelling errors, etc. whenever his assistant makes a page update. He would like to receive an email message basically saying, "page so-and-so has been edited". Such an example seems like it would be very common and useful.
I know that I need to write a UDT to perform this, and then link it on the admin side, but I am at a loss. Has anyone accomplished this? If so, would you be so kind as to show us how?
Thank you, THANK YOU, if you would help on this ~!
I have searched and read many posts having to do with Events and UDTs, including the ones on this forum and the wiki handbook.
Still, I cannot figure out how to send an email when a page is edited.
I have a friendly supervisor who just wants to check for spelling errors, etc. whenever his assistant makes a page update. He would like to receive an email message basically saying, "page so-and-so has been edited". Such an example seems like it would be very common and useful.
I know that I need to write a UDT to perform this, and then link it on the admin side, but I am at a loss. Has anyone accomplished this? If so, would you be so kind as to show us how?
Thank you, THANK YOU, if you would help on this ~!
-
- Power Poster
- Posts: 322
- Joined: Sat Feb 04, 2006 1:24 am
- Location: London, England
Re: Use Events to Send an Email when a Page is Edited?
Events documentation is almost non-existent, making them, IMHO, useless to the average user. It's a shame they can't be added as an additional module rather than being included in the core.
Re: Use Events to Send an Email when a Page is Edited?
You are invited to add some useful informations here 
http://wiki.cmsmadesimple.org/index.php ... ts_Manager

http://wiki.cmsmadesimple.org/index.php ... ts_Manager
-
- Power Poster
- Posts: 322
- Joined: Sat Feb 04, 2006 1:24 am
- Location: London, England
Re: Use Events to Send an Email when a Page is Edited?
If I understood how to use them, I would; unfortunately, there is no documentation... 
Catch 22.

Catch 22.
Re: Use Events to Send an Email when a Page is Edited?
Thank you, we are seeking a step-by-step starter example. From there, we can all hack like crazy, yes? and add information to the wiki. I think sending a notification when a page is changed would be a good common usage and would like to accomplish it for all.
The trouble is, the examples that are available now are off the point or, frankly, too complex for me to grasp without a bit of hand-holding.
The trouble is, the examples that are available now are off the point or, frankly, too complex for me to grasp without a bit of hand-holding.
- FantomCircuit
- Forum Members
- Posts: 75
- Joined: Fri Nov 10, 2006 1:34 am
- Location: Gold Coast, Australia
Re: Use Events to Send an Email when a Page is Edited?
Ok, monghidi, I hve just discovered what events actually are (i never clicked the events link button for some reason)
To get CMSMS to send someone an email when a content page is updated, do the following:
1. Create a new user defined tag, and call it something like 'EmailEditor'. Put the following in the contents:
(replacing my@email.com.au with your email address of course)
Save the UDT.
2. Go to the Events page, and find the entry labelled "ContentEditPost" and click the edit button for it.
3. Select your UDT from the dropdown list (the one you called 'EmailEditor') and click add.
Thats it. Now whenever someone updates a page you will be sent an email.
Because the content object also gets passed to the UDT, you should be able to put the actual page contents / title / author / whatever into the email that gets sent.
You should also probably use the cms mailer function, rather than the built-in php one. This is only a proof of concept. I just did this in CMSMS 1.0.8 and it worked fine.
To get CMSMS to send someone an email when a content page is updated, do the following:
1. Create a new user defined tag, and call it something like 'EmailEditor'. Put the following in the contents:
Code: Select all
mail('my@email.com.au','page updated','the page has been updated');
Save the UDT.
2. Go to the Events page, and find the entry labelled "ContentEditPost" and click the edit button for it.
3. Select your UDT from the dropdown list (the one you called 'EmailEditor') and click add.
Thats it. Now whenever someone updates a page you will be sent an email.
Because the content object also gets passed to the UDT, you should be able to put the actual page contents / title / author / whatever into the email that gets sent.
You should also probably use the cms mailer function, rather than the built-in php one. This is only a proof of concept. I just did this in CMSMS 1.0.8 and it worked fine.
Last edited by FantomCircuit on Fri Jul 13, 2007 6:08 am, edited 1 time in total.
Re: Use Events to Send an Email when a Page is Edited?
Wow, thanks -- I will give this a shot and report back with the findings!
-
- Power Poster
- Posts: 322
- Joined: Sat Feb 04, 2006 1:24 am
- Location: London, England
Re: Use Events to Send an Email when a Page is Edited?
I quickly updated the Wiki with all the information I could find on Events:
http://wiki.cmsmadesimple.org/index.php ... ts_Manager
I still think this is for fairly advanced users who know how to write PHP, and is aimed at developers rather than end-users; IMHO, it should be available as a module, not installed in the core - or at least, be uninstallable.
http://wiki.cmsmadesimple.org/index.php ... ts_Manager
I still think this is for fairly advanced users who know how to write PHP, and is aimed at developers rather than end-users; IMHO, it should be available as a module, not installed in the core - or at least, be uninstallable.
- FantomCircuit
- Forum Members
- Posts: 75
- Joined: Fri Nov 10, 2006 1:34 am
- Location: Gold Coast, Australia
Re: Use Events to Send an Email when a Page is Edited?
stopsatgreen, Just wondering why you think it should be uninstallable? All it does is take up a little 10px high link in the extensions menu - plus I am starting to build a module that will rely heavily on events, and getting it to work with and without events would make it a huge headache to develop (so much so that I would probably not use events at all)
-
- Power Poster
- Posts: 322
- Joined: Sat Feb 04, 2006 1:24 am
- Location: London, England
Re: Use Events to Send an Email when a Page is Edited?
Just that, IMHO, it's not core. I'm sure it's useful to a small group of people, but not to the majority who don't know enough PHP to make good use of it. It's not a big deal, but it would help keep bloat to a minimum if it could be added on as a module rather than being part of the core.
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: Use Events to Send an Email when a Page is Edited?
Events are designed for people that have some knowledge of php. It's not designed (much) for end users. There is little an end user can do with events at this point.
However, events are used in the core modules already, and when the power of them comes out it'll make the website developers job much easier. and even further extend the usefulness of CMS Made Simple.
Unfortunately, I'm not a good document writer, I am (IMHO) a good developer. When I start working with events, the first thing I do is in my handler function dump out all of the input I am given to the screen so I can see what is there, and what I can work with. There is however, some primitive documentation for each event, that describes what it does.
So.... Sending an email on a page edit is a perfect example of how use events. Though, as mentioned above, I'd use CMSMailer instead of the mail function.
Just my $0.02
However, events are used in the core modules already, and when the power of them comes out it'll make the website developers job much easier. and even further extend the usefulness of CMS Made Simple.
Unfortunately, I'm not a good document writer, I am (IMHO) a good developer. When I start working with events, the first thing I do is in my handler function dump out all of the input I am given to the screen so I can see what is there, and what I can work with. There is however, some primitive documentation for each event, that describes what it does.
So.... Sending an email on a page edit is a perfect example of how use events. Though, as mentioned above, I'd use CMSMailer instead of the mail function.
Just my $0.02
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: Use Events to Send an Email when a Page is Edited?
Thank you both, this works fine! Good proof of concept and we appreciate your help and adding it to the wiki. Still, it is a bit too simple to really take off on.
Calguy1000 and FantomCircuit, you both mentioned that you would use "CMSMailer instead of the mail function." Also, you mentioned that we could include other elements, such as page title, content, etc.
Unfortunately the example given doesn't show how either of these might be done.
When you get the chance, would you explain further, please, or provide a more complete example?
I would like to follow your leads to know how to use CMSMailer to send an email that shows the URL and the Title of the page that was edited.
Thanks very much
Calguy1000 and FantomCircuit, you both mentioned that you would use "CMSMailer instead of the mail function." Also, you mentioned that we could include other elements, such as page title, content, etc.
Unfortunately the example given doesn't show how either of these might be done.
When you get the chance, would you explain further, please, or provide a more complete example?
I would like to follow your leads to know how to use CMSMailer to send an email that shows the URL and the Title of the page that was edited.
Thanks very much

-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: Use Events to Send an Email when a Page is Edited?
The ContentEditPost event sends a reference to the effected content object. So, you'll need to look up the properties of that object in lib/classes/class.content.inc.php
Then..... to use cmsmailer, you should look up the methods in modules/CMSMailer/CMSMailer.module.php. But first you need to get a pointer to the instance:
So.... in short, something like this should work (untested):
Then..... to use cmsmailer, you should look up the methods in modules/CMSMailer/CMSMailer.module.php. But first you need to get a pointer to the instance:
So.... in short, something like this should work (untested):
Code: Select all
$bodytext = '
A page has been changed.
Page ID: '.$content->Id().'
Page Name: '.$content->Name().'
Page Alias: '.$content->Alias().'
Page Type: '.$content->Type().'
Page Owner: '.$content->Owner().'
Created: '.$content->GetCreateDate().'
Modified: '.$content->GetModifiedDate();
global $gCms;
$cmsmailer =& $gCms->modules['CMSMailer']['object'];
$cmsmailer->AddAddress('somebody@somewhere.com');
$cmsmailer->SetBody($bodytext);
$cmsmailer->IsHTML(false);
$cmsmailer->SetSubject('Page Change Notification');
$cmsmailer->Send();
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: Use Events to Send an Email when a Page is Edited?
Dear Calguy1000, thank you , I studied your comments and made some attempts...we are ALMOST there...!
I spent the day trying dozens of different ways and have studied many posts on this forum about retrieving vars and page names, titles, content objects...using them in UDTs,...but still no luck. I'm back to your sample, which works as well as anything else I have tried.
Here is my UDT (slightly modified from your sample):
The email is successfully sent when I Submit a page after an edit. But the email looks like this:
ANy help from you or someone who has successfully pulled page info and URLs and used them in a UDT or Event?
Thank you VERY much in advance, if you can help!
PS>I appreciate that your example was untested
I spent the day trying dozens of different ways and have studied many posts on this forum about retrieving vars and page names, titles, content objects...using them in UDTs,...but still no luck. I'm back to your sample, which works as well as anything else I have tried.
Here is my UDT (slightly modified from your sample):
Code: Select all
global $gCms;
$bodytext = "
Page ID: '.$content->Id().'
Page Name: '.$content->Name().'
Page Alias: '.$content->Alias().'
Page Type: '.$content->Type().'
Page Owner: '.$content->Owner().'
Created: '.$content->GetCreateDate().'
Modified: '.$content->GetModifiedDate();
";
$cmsmailer =& $gCms->modules['CMSMailer']['object'];
$cmsmailer->AddAddress('emailaddress@anisp.com');
$cmsmailer->SetBody($bodytext);
$cmsmailer->IsHTML(false);
$cmsmailer->SetSubject('Page Change Notification');
$cmsmailer->Send();
So, how can we successfully populate these so they show up in the email body? Best scenario would be to include the URL of the updated page as well...from Update Notification
to recipient@anisp.com
date Jul 27, 2007 7:30 PM
subject Page Change Notification
Page ID: '.().'
Page Name: '.().'
Page Alias: '.().'
Page Type: '.().'
Page Owner: '.().'
Created: '.().'
Modified: '.();
ANy help from you or someone who has successfully pulled page info and URLs and used them in a UDT or Event?
Thank you VERY much in advance, if you can help!
PS>I appreciate that your example was untested

- FantomCircuit
- Forum Members
- Posts: 75
- Joined: Fri Nov 10, 2006 1:34 am
- Location: Gold Coast, Australia
Re: Use Events to Send an Email when a Page is Edited?
I think your quotation marks are a little mixed up. 
Instead of
You should have
Note how I have changed your single quotation marks (') to double quotation marks (")
try that and see how it goes. There might still be something else stopping it from working.

Instead of
Code: Select all
$bodytext = "
Page ID: '.$content->Id().'
Page Name: '.$content->Name().'
Page Alias: '.$content->Alias().'
Page Type: '.$content->Type().'
Page Owner: '.$content->Owner().'
Created: '.$content->GetCreateDate().'
Modified: '.$content->GetModifiedDate();
";
Code: Select all
$bodytext = "
Page ID: ".$content->Id()."
Page Name: ".$content->Name()."
Page Alias: ".$content->Alias()."
Page Type: ".$content->Type()."
Page Owner: ".$content->Owner()."
Created: ".$content->GetCreateDate()."
Modified: ".$content->GetModifiedDate()."
";
try that and see how it goes. There might still be something else stopping it from working.