Email notification of new comments
crazyknicksfan
![]()
Joined: 2003-01-09
Posts: 32 |
![]() |
Hi everyone, I was just wondering if there are any plans currently to add a feature that would allow users to have gallery email them whenever someone leaves a comment in their album. This would be very useful for helping to keep users returning to the site so they would be interested in posting more pictures. Sometimes people tend to forget and then the gallery albums basically become stagnant. Just a thought, I guess. Dunno if this has already been suggested but I think probably yes. Hopefully it will be possible in the next installment of gallery2. -Thanks |
|
mindless
![]()
Joined: 2004-01-04
Posts: 8601 |
![]() |
we'll gladly provide guidance to anyone who wants to work on an email notification module... we don't have the resources to work on it now. |
|
stoffer
![]()
Joined: 2005-02-10
Posts: 75 |
![]() |
Ahhh, an email notification module would be awesome. I envision a module where the user can get an email when some of the albums are updated with new photos or comments. It could also entail a newsletter of sorts. Sorry I can't help with any coding at all, but I just wanted to shown that it would be a great addition down the road. |
|
jeffchau
Joined: 2005-04-22
Posts: 18 |
![]() |
It's not necessary to write a module. I think that it should be a comment module enhancement instead. If you don't need fancy stuff, such as customizing email message in site admin, the following bit of code will do. This simple bit of code will e-mail to the album owner once the comment is added. But can anyone help me? I dunno how to get the URL from an items using CoreApi Add them inside the handleRequest method of AddComment.inc, $ownerId = $item->getOwnerId(); list ($ret, $owner) = GalleryCoreApi::loadEntitiesById($ownerId); if ($ret->isError()) { $emailSubj = 'Comment has been added.'; mail($owner->getEmail(),$emailSubj,$emailContent,"From: $from\nX-Mailer: PHP/ . $phpversion()", "-f $from"); |
|
mindless
![]()
Joined: 2004-01-04
Posts: 8601 |
![]() |
that certainly works, but it may be nicer in the long run to centralize email notifications.. make an event for anything we may want to send email about and then the email notification module can listen for those events and send email for anything that has been configured. then in site admin you could say things like: email all site administrators when a new album is created, email the item owner when a comment is added, etc. |
|
haggis
![]()
Joined: 2004-05-27
Posts: 17 |
![]() |
mindless wrote:
we'll gladly provide guidance to anyone who wants to work on an email notification module... we don't have the resources to work on it now. Note: This also refers to http://gallery.menalto.com/index.php?name=PNphpBB2&file=viewtopic&t=30011 Ultimately you be happy you suggested that...if we can get past the toddling stage and onwards to walking :D OK, I read the module development article in the wiki, and some of it is beginning to make sense. So...off we go I guess. The Plan When 'poll/notify' is used, it reads: Am I on the right track here? If not, can anyone suggest a more efficient/robust/logical schema than the this? Regards & TIA, |
|
bharat
![]()
Joined: 2002-05-21
Posts: 7994 |
![]() |
We have a simpler mechanism for this. Whenever an item is saved, it generates an event, and you can create module which listens for those events. You can take your own action at that time, whatever action you want. Look at modules/sizelimit/module.inc for the handleEvent method. It looks for the GalleryEvent::save event meaning that we're saving an item. It then checks to see if the item being saved is a new GalleryAlbumItem, and if it's being newly created then it takes an action. You can do the same -- create a module that listens for newly created GalleryComment instances and fires off an email to your list of people. Start by creating a new module that just has an event listener that uses GalleryCoreApi::sendTemplatedEmail() to send a test email whenever a comment is added. Once you have that going, we can build on it together. |
|
haggis
![]()
Joined: 2004-05-27
Posts: 17 |
![]() |
Wow I'll report back with a (hopefully) working first version This is scary and also wildly exciting!! I never envisioned myself working on a Gallery module (or any other darned coding project either, come to think of it!) |
|
haggis
![]()
Joined: 2004-05-27
Posts: 17 |
![]() |
If anyone is interested, I've done a project document outlining goals and scope of the "notify" module. |
|
swordfish
![]()
Joined: 2004-10-01
Posts: 388 |
![]() |
haggis wrote:
If anyone is interested, I've done a project document outlining goals and scope of the "notify" module. Very cool 8). When you think you have a Alpha or beta version ready I'd be very interested in testing it out. |
|
raph
Joined: 2005-02-08
Posts: 6 |
![]() |
Haggis, Just wondering if you're still working on this module or have other duties taken over. Been on to your website link for the project outline but nothings appears to have happened since mid May. |
|
haggis
![]()
Joined: 2004-05-27
Posts: 17 |
![]() |
raph wrote:
Haggis, I need to get back to work on this module, but I've been up to my ears in a project at work (which has been more or less a 24/7 thing). I think we're done in about a week and hope to resume work on the module shortly thereafter. I need to contact Bharat when the time comes, since he was in effect "steering" me through the process. My apologies to the comunity in general, this project came at us right out of the blue and buried everyone bigtime, leaving literally no time in a day for any other "desireable" activities. For yrs truly, that means messing with G2! :lol: |
|
Budgregor
![]()
Joined: 2005-07-23
Posts: 1 |
![]() |
haggis wrote:
I need to get back to work on this module, but I've been up to my ears in a project at work (which has been more or less a 24/7 thing). We trust in you ;=) Hope you can find some time in this. I agree to the first posting. This is a method to bring the use back to the site. The user has to be informed when something is new or has changed. Thank you for your support. And Gallery (including G2) is great. Regards, Gregor. |
|
Florie
Joined: 2005-05-22
Posts: 11 |
![]() |
Hi, I have troubles getting the code above into the AddComment.inc Could you just tell me, where I have to past it. Thx a lot! |
|
Anonymous
|
![]() |
Haggis, any news on the module? |
|
id01
Joined: 2005-11-07
Posts: 62 |
![]() |
I have trouble with the code as well, but that idea doesn't work very well becasue it will force every owner to recieve e-mail upon comment. Modulizes seem best, but a e-mail handler module might be a little too much for use to tackles. Especially for people who just want the old features in G1 to work again so they can upgrade at last. I still think to developement team should first fix most of the performance issue, then match all the features so they can moves more developing power into G2 from G1 and become more foucsed, however, I guess they don't have time for either really. ^^; |
|
MRiedl
Joined: 2006-01-08
Posts: 9 |
![]() |
As I have trouble with the code too I tried to get it to work. list ($ret, $item) = GalleryCoreApi::loadEntitiesById($itemId); list ($ret, $owner) = GalleryCoreApi::loadEntitiesById($item->getOwnerId()); $ownerName = $owner->getFullName(); list ($ret, $user) = GalleryCoreApi::loadEntitiesById($gallery->getActiveUserId()); $userName = $user->getFullName(); $emailSubj = '[Homepage] New picture comment'; $emailContent = 'Greetings '.$ownerName.'!'."\n\n". 'New comment from user: '.$userName."\n". 'Subject: '.$form['subject']."\n". 'Comment: '.$form['comment']."\n". 'URL: http://www.your-page.com/wp-gallery2.php?g2_view=core.ShowItem&g2_itemId='.$itemId."\n\n". 'This is an automatic mail.!'; $from = 'email@host.de'; mail($owner->getEmail(),$emailSubj,$emailContent, "From: $from\nX-Mailer: PHP/ . $phpversion()", "-f $from"); Add the code above line: /* Send the user to a confirmation page, for now */ greetings riedl |
|
nicheplayer
Joined: 2005-08-03
Posts: 35 |
![]() |
riedl, can you say exactly where you added this code? Was it in AddComment.inc? Thank you for your work! |
|
MRiedl
Joined: 2006-01-08
Posts: 9 |
![]() |
Yes, in AddComment.inc. I added the code (in class AddCommentController, function handleRequest) between this lines ... $ret = $comment->save(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } INSERT THE CODE HERE /* Send the user to a confirmation page, for now */ $redirect['view'] = 'comment.CommentChangeConfirmation'; ...
Take care that if you want to test the function you use a picture you are the owner of |
|
torres11
Joined: 2006-01-11
Posts: 9 |
![]() |
Quote:
Take care that if you want to test the function you use a picture you are the owner of Does this Only send you an Email if you are the owner of the picture? Is there a way you can change it to email you if a comment is left on any picture in the gallery? |
|
MRiedl
Joined: 2006-01-08
Posts: 9 |
![]() |
assumed that you don't mind to whom the mail addresses just add another line like (if the mail $from is yours): |
|
torres11
Joined: 2006-01-11
Posts: 9 |
![]() |
Here I am again asking another question? but how can I have it send me the Users Ip address also? I mean I have an idea how but I just dont even know where you guys get all these codes from? like the .$from .$phpversion or these codes from? Can someone help me out. Or at least tell me what the code is for asking for the userIP Thanks |
|
MRiedl
Joined: 2006-01-08
Posts: 9 |
![]() |
just edit one line, e.g. phpversion is a php function. |
|
shyzer
Joined: 2005-12-01
Posts: 3 |
![]() |
Ried, I just wanted to say thanks for writing this. I've been looking for some sort of notification system for comments and it looks like this is gonna do the trick! So again, thanks! |
|
nicheplayer
Joined: 2005-08-03
Posts: 35 |
![]() |
I can't believe this feature still didn't make the cut for Gallery 2.1. |
|
LFrank
Joined: 2005-02-19
Posts: 1023 |
![]() |
line 144:
$ret = $comment->save();
if ($ret) {
return array($ret->wrap(__FILE__, __LINE__), null);
}
/* added eMail Notification based on MRiedl's modification */
list ($ret, $item) = GalleryCoreApi::loadEntitiesById($itemId);
list ($ret, $owner) = GalleryCoreApi::loadEntitiesById($item->getOwnerId());
$ownerName = $owner->getFullName();
list ($ret, $user) = GalleryCoreApi::loadEntitiesById($gallery->getActiveUserId());
$userName = $user->getFullName();
$emailSubj = 'GALLERY2 - New picture comment added';
$emailContent = 'Greetings '.$ownerName.'!'."\n\n".
'New comment from user: '.$userName." (".GalleryUtilities::getRemoteHostAddress().") \n".
'Subject: '.$form['subject']."\n".
'Comment: '.$form['comment']."\n".
'URL: http://YOUR-GALLERY-PATH/main.php?g2_view&g2_itemId='.$itemId."\n\n".
'[ this is an automatic mail, generated by Gallery 2.1 !]';
$from = 'SENDER@MAIL.COM';
mail("FROM@MAIL.COM",$emailSubj,$emailContent, "From: $from\nX-Mailer: PHP/ . $phpversion()", "-f $from");
/* Send the user to a confirmation page, for now */
$redirect['view'] = 'comment.CommentChangeConfirmation';
$redirect['itemId'] = (int)$itemId;
$status['added'] = 1;
Thanks MRiedl, I very slightly adjusted some code to fit normal Gallery 2.1 setups.Simply adjust the SENDER@MAIL.COM, FROM@MAIL.COM and YOUR-GALLERY-PATH. Thanks again, Gallery version = 2.1 core 1.1.0 |
|
mindless
![]()
Joined: 2004-01-04
Posts: 8601 |
![]() |
code review: |
|
nicheplayer
Joined: 2005-08-03
Posts: 35 |
![]() |
So, we should wait before modifying AddComment.inc with this code, then? Thanks, LFrank, for your modifications. And here I was thinking you were merely a PGTheme genius. Looks like this feature is coming closer to reality all the time. |
|
mindless
![]()
Joined: 2004-01-04
Posts: 8601 |
![]() |
nicheplayer, other than the "FROM@MAIL.COM" error the code above can work.. you're welcome you use it (at your own risk of course) until this feature is added.. the above review is what is needed to get this ready for CVS. |
|
LFrank
Joined: 2005-02-19
Posts: 1023 |
![]() |
mindless, OOps - that was a typo - I meant TO with FROM (have it hardcoded in my localized version) Gallery version = 2.1 core 1.1.0 |
|
ngotau
Joined: 2006-04-25
Posts: 1 |
![]() |
Hi, I am a newbie, just starting up a personal gallery. I have tried the above code. It works fine for the first test. Hope there will be no serious bug. ---------------------------------------- |
|
Steel Rat
![]()
Joined: 2006-06-24
Posts: 100 |
![]() |
Actually the code listed by LFrank does NOT have $owner->getEmail(); IT would need to be added to work without a hardcoded email addressee. Would be nice if someone could polish this up to make it friendlier for Gallery. Steel Rat |
|
Captenaj
Joined: 2006-03-27
Posts: 43 |
![]() |
This is exactly the functionality I have been looking for. But what the heck are you guys talking about? I get the basic idea that some code has to be modified somewhere. Can someone help out a newbie with what I do with all that code? Let's back up. How do I find out what version of Gallery I'm running? Then what do I do with the code? Thanks to all who worked on this. |
|
LFrank
Joined: 2005-02-19
Posts: 1023 |
![]() |
@Steel Rat: the $owner->getEmail() did for some reason -I don't know why - not work on my system ... that's the reason I'ver coded it the way listed. @Captenaj: you need to modify the AddComment.inc (from \modules\comment) around line 144 and change some placeholder to your configuration. CU Gallery version = 2.2-svn core 1.1.16 |
|
Captenaj
Joined: 2006-03-27
Posts: 43 |
![]() |
Thanks for your response, LFrank. I found the file and made a copy (for when I mess up and have to upload the original again). Am I to understand that I replace the code: $ret = $comment->save(); /* Send the user to a confirmation page, for now */ with the code you have supplied above? It seems that the line "if ($ret->isError()) {" will then be replaced by "if ($ret) {". Is that OK or am I not understanding something? Thank you again. |
|
Captenaj
Joined: 2006-03-27
Posts: 43 |
![]() |
Quote:
(And don't forget to protect the "AddComment.inc" against CVS updates ;)) Good advice! Er... what does this mean (I don't really need to know) and how do I do this? Thanks. |
|
LFrank
Joined: 2005-02-19
Posts: 1023 |
![]() |
Captenaj, put/insert the new lines in front of the "Send to confirmation page" ... there should nothing to be deleted. It simply adds to the existing code. ... $comment->setComment($form['comment']); $comment->setDate(time()); $ret = $comment->save(); if ($ret) { return array($ret, null); } /* added eMail Notification based on MRiedl's modification */ list ($ret, $item) = GalleryCoreApi::loadEntitiesById($itemId); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } list ($ret, $owner) = GalleryCoreApi::loadEntitiesById($item->getOwnerId()); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } $ownerName = $owner->getFullName(); $ownerEMail = $owner->getEmail(); list ($ret, $user) = GalleryCoreApi::loadEntitiesById($gallery->getActiveUserId()); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } $userName = $user->getFullName(); $emailSubj = 'GALLERY2 - New picture comment added'; $emailContent = 'Greetings '.$ownerName.'!'."\n\n". 'New comment from user: '.$userName." (".GalleryUtilities::getRemoteHostAddress().") \n". 'Subject: '.$form['subject']."\n". 'Comment: '.$form['comment']."\n". 'URL: http://localmail.dynip.com/GALLERY2/main.php?g2_view=core.ShowItem&g2_itemId='.$itemId."\n\n". '[this is an automatic mail, generated by Gallery !]'; $from = 'cps@lf-photodesign.de'; mail("cps@lf-photodesign.de",$emailSubj,$emailContent, "From: $from\nX-Mailer: PHP/ . $phpversion()", "-f $from"); /* Send the user to a confirmation page, for now */ $redirect['view'] = 'comment.CommentChangeConfirmation'; $redirect['itemId'] = (int)$itemId; $status['added'] = 1; } ... Btw. SVN is more clever than CVS ... it merges the change locally ;) - you only need to think about if you update from nightly archives (there was a switch from CVS to SVN sometimes ago - no need to bother any longer). I've attached my "AddComments.inc" for your reference (don't forget to adjust your e-mails and gallery path). Gallery version = 2.2-svn core 1.1.16 |
|
Captenaj
Joined: 2006-03-27
Posts: 43 |
![]() |
Thanks, LFrank. I appreciate your help. What is my gallery path? Is it just http://www.elliottsnest.net/photos? Or is it supposed ot have some of that main.php?g2_view=core stuff on it too? Sorry to be so dumb about this. I appreciate your time. |
|
LFrank
Joined: 2005-02-19
Posts: 1023 |
![]() |
Captemaj, just replace "http://localmail.dynip.com/GALLERY2/" with your "http://www.elliottsnest.net/photos/" and leave the main.php? stuff ... Gallery version = 2.2-svn core 1.1.16 |
|
Captenaj
Joined: 2006-03-27
Posts: 43 |
![]() |
Thank you again for your response. When the line in question reads I get the following error: Parse error: syntax error, unexpected T_ELSE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/.calico/pamwoman/elliottsnest.net/photos/modules/comment/AddComment.inc on line 144 Line 144 is: $redirect['itemId'] = (int)$itemId; |
|
LFrank
Joined: 2005-02-19
Posts: 1023 |
![]() |
Hmm. it looks like something got 'lost' ... the $redirect should be after the inserted lines, can you attach your file to have a look? Gallery version = 2.2-svn core 1.1.16 |
|
Captenaj
Joined: 2006-03-27
Posts: 43 |
![]() |
I have attached the file. Thank you. |
|
LFrank
Joined: 2005-02-19
Posts: 1023 |
![]() |
Captenaj, you have the "/* Send user to confirmation page, for now */" twice and therefore a "}" too much, remove lines 142 to 146 (these are duplicates to 134-138). And line 91-99 (these wouldn't cause an error - but will be better to have them out I assume). Gallery version = 2.2-svn core 1.1.16 |
|
Captenaj
Joined: 2006-03-27
Posts: 43 |
![]() |
I see that. Thank you. I took the offending code out (actually, I modified the original document with your changes once again) and I am able to leave a comment but I get a new error message. I do not get a confirmation email. The error message is: Error Back to the Gallery Error Detail - |
|
LFrank
Joined: 2005-02-19
Posts: 1023 |
![]() |
Hmm, I know it running with 2.1 and newer ... why don't you update from 2.03? Gallery version = 2.2-svn core 1.1.16 |
|
Captenaj
Joined: 2006-03-27
Posts: 43 |
![]() |
OK, if you think that may help I'll give it a go. I'll read over the documentation and update it tonight after work. Thank you for all your help. I'll let you know how it turns out. |
|
LFrank
Joined: 2005-02-19
Posts: 1023 |
![]() |
OK, I'll keep fingers crossed ... Gallery version = 2.2-svn core 1.1.16 |
|
Captenaj
Joined: 2006-03-27
Posts: 43 |
![]() |
No go. I successfully upgraded to Gallery 2.1 core 1.1.0. If I run Gallery with the original AddComment.inc file it works fine. When I change the file as specified above, I get the following error: Fatal error: Call to a member function on a non-object in /home/ccc/xmen/yoururl.com/photos/modules/comment/AddComment.inc on line 179 Line 179 & 180 are: if ($ret->isError()) { The text right before the addition of the new code is $ret = $comment->save(); in my original AddComment.inc file but is $ret = $comment->save(); in the sample code I copied from above. Does that matter. Attached in my latest version of my AddComment.inc file. Thank you again (and again) for your help. |
|
Captenaj
Joined: 2006-03-27
Posts: 43 |
![]() |
Oh no! Now I can't get it to work at all. I WAS working with the new version of Gallery. I swear it was. I re-uploaded my original AddComment.inc file and now I get the error: Fatal error: Call to a member function on a non-object in /home/ccc/xmen/yoururl.com/photos/modules/comment/AddComment.inc on line 145 With line 145 being the same one as I quoted in my previous posting. What have I done????? Thanks. |
|
mindless
![]()
Joined: 2004-01-04
Posts: 8601 |
![]() |
$ret->isError() is 2.0.x code. |
|
Captenaj
Joined: 2006-03-27
Posts: 43 |
![]() |
That would explain it. I think I must have deleted the AddComment.inc file that came with the upgraded version of Gallery. How can I get another copy? Can someone give me a copy of theirs or can I download it from gallery somewhere? If I uninstall and then reinstall the module, will that work? Will it delete all my old comments? Thanks. |
|