Page 1 of 3
Use Events to Send an Email when a Page is Edited?
Posted: Thu Jul 05, 2007 6:12 pm
by monghidi
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 ~!
Re: Use Events to Send an Email when a Page is Edited?
Posted: Fri Jul 06, 2007 11:48 am
by stopsatgreen
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?
Posted: Fri Jul 06, 2007 11:51 am
by cyberman
Re: Use Events to Send an Email when a Page is Edited?
Posted: Fri Jul 06, 2007 12:00 pm
by stopsatgreen
If I understood how to use them, I would; unfortunately, there is no documentation...
Catch 22.
Re: Use Events to Send an Email when a Page is Edited?
Posted: Fri Jul 06, 2007 12:34 pm
by monghidi
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.
Re: Use Events to Send an Email when a Page is Edited?
Posted: Fri Jul 13, 2007 6:04 am
by FantomCircuit
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:
Code: Select all
mail('my@email.com.au','page updated','the page has been updated');
(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.
Re: Use Events to Send an Email when a Page is Edited?
Posted: Fri Jul 13, 2007 2:07 pm
by monghidi
Wow, thanks -- I will give this a shot and report back with the findings!
Re: Use Events to Send an Email when a Page is Edited?
Posted: Tue Jul 24, 2007 11:34 pm
by stopsatgreen
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.
Re: Use Events to Send an Email when a Page is Edited?
Posted: Tue Jul 24, 2007 11:37 pm
by FantomCircuit
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)
Re: Use Events to Send an Email when a Page is Edited?
Posted: Wed Jul 25, 2007 3:00 pm
by stopsatgreen
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.
Re: Use Events to Send an Email when a Page is Edited?
Posted: Wed Jul 25, 2007 8:48 pm
by calguy1000
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
Re: Use Events to Send an Email when a Page is Edited?
Posted: Thu Jul 26, 2007 2:08 pm
by monghidi
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

Re: Use Events to Send an Email when a Page is Edited?
Posted: Thu Jul 26, 2007 6:17 pm
by calguy1000
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):
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();
Re: Use Events to Send an Email when a Page is Edited?
Posted: Fri Jul 27, 2007 11:05 pm
by monghidi
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):
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();
The email is successfully sent when I Submit a page after an edit. But the email looks like this:
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: '.();
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...
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

Re: Use Events to Send an Email when a Page is Edited?
Posted: Fri Jul 27, 2007 11:17 pm
by FantomCircuit
I think your quotation marks are a little mixed up.
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();
";
You should have
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()."
";
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.