Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1] 2 3   Go Down

Author Topic: MOD: Email Notification to members on Comment (UPDATED 12-29-05)  (Read 56388 times)

0 Members and 1 Guest are viewing this topic.

fcarentz

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 24
MOD: Email Notification to members on Comment (UPDATED 12-29-05)
« on: December 29, 2005, 05:41:56 am »

I will be updating this First post with all the updates for this Mod as I complete them or add in fixes, enhancements etc. Thus please use whatever is in this first post for your 1.4.2 Gallery. A word of caution to this tale...this is my first Coppermine Mod so please leave feedback, suggestions etc... and be merciful please. :)

Also thanks to Nibbler for stepping me in the right direction.

Purpose of the Mod: Enable your gallery users to receive notifications via email when other users leave them comments.


Updates:
12-29-05: Added Database support. Now on a picture by picture basis users can choose whether or not to be notified. This option defaults to Yes when the picture is submitted, so your users will have to edit their pics and Uncheck the notifications if they dont want to be notified.
12-29-05: Added Flood Protection. Users will only be notified once until they return to the gallery to view their comments.


(Please make sure you back up EVERYTHING before testing this Mod)


Step 1: First we have to update our Database table. To do this Run this mySQL command. This will be used to let users decide whether or not to be notified on a picture by picture basis.
Code: [Select]
ALTER TABLE `gal_pictures` ADD `notify` ENUM( 'Yes', 'No' ) DEFAULT 'Yes' NOT NULL ;
ALTER TABLE `gal_pictures` ADD `sent` INT( 11 ) NOT NULL ;



Changes in lang/english.php


Step 2:Open /lang/english.php (english in my case...you might use a different language file remember)

FIND THIS (/lang/english.php)
Code: [Select]
  'forb_ext' => 'Forbidden file extension.',//cpg1.4
AFTER IT ADD THIS
Code: [Select]
'notify_comm' => 'Notify me of comments.',//cpg1.4


Changes in editOnePic.php

Step 3: Open editOnePic.php

FIND THIS
Code: [Select]
$del_comments = isset($_POST['del_comments']) || $delete;
AFTER IT ADD THIS
Code: [Select]
$notify = isset($_POST['notify']);
NEXT FIND THIS
Code: [Select]
if ($reset_votes) $update .= ", pic_rating = '0', votes = '0'";
AFTER IT ADD THIS
Code: [Select]
if($notify) {
$update .= ", notify = 'Yes'";
}else{
$update .= ", notify = 'No'";
}


NEXT FIND THIS
Code: [Select]
// If this is the users gallery icon then check it
$isgalleryicon_selected = ($CURRENT_PIC['galleryicon']) ? 'checked="checked" ': '';
$isgalleryicon_disabled = ($CURRENT_PIC['category'] < FIRST_USER_CAT)? 'disabled="disabled" ':'';

AFTER IT ADD THIS
Code: [Select]
// If the user is being notfied already then check it.
$isnotified = ($CURRENT_PIC['notify']) == "Yes" ? 'checked="checked" ': '';


NEXT FIND THIS
Code: [Select]
<tr>
           <td width="20%" align="center"><input type="checkbox" name="galleryicon" {$isgalleryicon_selected}{$isgalleryicon_disabled}value="{$CURRENT_PIC['pid']}" class="checkbox" />{$lang_editpics_php['gallery_icon']}</td>
          <td width="20%" align="center"><input type="checkbox" name="read_exif" value="1" class="checkbox" />{$lang_editpics_php['read_exif']}</td>
          <td width="20%" align="center"><input type="checkbox" name="reset_vcount" value="1" class="checkbox" />{$lang_editpics_php['reset_view_count']}</td>
          <td width="20%" align="center"><input type="checkbox" name="reset_votes" value="1" class="checkbox" />{$lang_editpics_php['reset_votes']}</td>
          <td width="20%" align="center"><input type="checkbox" name="del_comments" value="1" class="checkbox" />{$lang_editpics_php['del_comm']}</td>
</tr>

AFTER IT ADD THIS
Code: [Select]
<tr>
        <td width="100%" align="center" colspan="5"><input type="checkbox" name="notify" value="1" {$isnotified} class="checkbox" />{$lang_editpics_php['notify_comm']}</td>
</tr>



Changes in db_input.php

Step 4: Open db_input.php

Open db_input.php and find (around line 165)
Code: [Select]
                  if (!USER_ID) { // Anonymous users, we need to use META refresh to save the cookie

Right before/Above it Add this:
Code: [Select]

//Start New User Notification Code
                                 $result = cpg_db_query("SELECT owner_id, notify, sent  FROM {$CONFIG['TABLE_PICTURES']} WHERE pid=".$pid);
                                 list($uid, $notify, $sent) = mysql_fetch_row($result);

                                // We can't send an email if this pic was uploaded by a guest
                                //User must request notification.
                                if ($uid && $notify == "Yes"){

                                                // This can get the right info if the bridge is enabled or not.
                                               $picture_owner_data = $cpg_udb->get_user_infos($uid);

                                               //make sure we don't email ourself and that we arent being flooded
                                                if(USER_ID != $uid  && !$sent){
                                                                // check the user has specified an email address
                                                                if ($picture_owner_data['user_email']){
                                                                                $subject = "TMV: New Gallery Comment by ".USER_NAME;
                                                                                $mail_body  = "Hi ".$picture_owner_data['user_name']."!!<br />\n".USER_NAME." just wrote a comment on one of your photos, click the link below to read and reply to it.<br /><br />\n";
                                                                                $mail_body .= $CONFIG['site_url'] . "displayimage.php?pos=-".$pid."<br /><br />\n";
                                                                                $mail_body .= "More comments may be posted, but you won't receive any more notifications until you read them.<br />\n";
                                                                                $mail_body .= "Thanks,<br />{$CONFIG['gallery_name']} Team.";
                                                                                cpg_mail($picture_owner_data['user_email'], $subject, $mail_body);
                                                                }
                                                               //Mark that we've sent a notification so the pic owner doesnt get flooded.
                                                               if(!$sent){
                                                                           $result = cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET sent = 1  WHERE pid=".$pid);
                                                               }
                                              }
                                }
// End User Notification Code.




Changes in displayimage.php

Step 4: Open displayimage.php

Open displayimage.php and find (around line 76)
Code: [Select]
<a href="javascript:;" onclick="return MM_openBrWindow('picEditor.php?id={$CURRENT_PIC_DATA['pid']}','Crop_Picture','scrollbars=yes,toolbar=no,status=yes,resizable=yes')" class="admin_menu" >{$lang_display_image_php['crop_pic']}</a> <a href="editOnePic.php?id={$CURRENT_PIC_DATA['pid']}&amp;what=picture"  class="admin_menu">{$lang_display_image_php['edit_pic']}</a> <a href="delete.php?id={$CURRENT_PIC_DATA['pid']}&amp;what=picture"  class="admin_menu" onclick="return confirm('{$lang_display_image_php['confirm_del']}'); return false; ">{$lang_display_image_php['del_pic']}</a>
EOT;

AFTER IT ADD
Code: [Select]
//Email Notification Flood Protection.
                if($CURRENT_PIC_DATA['sent']==1){
                $result = cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET sent = 0 WHERE pid = '".$CURRENT_PIC_DATA['pid']."'");
                }
//End Email Notification Flood Protection.

Nibbler

  • Guest
Re: Notify Members on Comment
« Reply #1 on: December 29, 2005, 05:50:45 am »

Hmm, you must be using SMF integration. That should be cpg_db_query instead of db_query.
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: HACK: Notify Members on Comment
« Reply #2 on: December 29, 2005, 05:53:08 am »

coolio... this would be a useful mod.
Logged

fcarentz

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 24
Re: Notify Members on Comment
« Reply #3 on: December 29, 2005, 05:55:02 am »

Hmm, you must be using SMF integration. That should be cpg_db_query instead of db_query.

Yes I am...why will this Hack only work for SMF?

While looking at the  udb_base.inc.php it seemed like they would all share the same information for this set up and that it would work across the board...Let me know what the differences are if you please I would be very happy to make this as generic as possible.

Going to edit that query now. Thanks!

Is there any documentation on the coding for Coppermine, I am VERY new.

fcarentz

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 24
Re: HACK: Notify Members on Comment
« Reply #4 on: December 29, 2005, 05:57:37 am »

coolio... this would be a useful mod.

Thanks, I thought so as well!

Nibbler

  • Guest
Re: HACK: Notify Members on Comment
« Reply #5 on: December 29, 2005, 06:01:32 am »

db_query() was renamed cpg_db_query() in 1.4 because it conflicted with other apps (particularly SMF) that have a function of the same name. That's the only reason the hack works for you - it is in fact using SMF's database functions and not Coppermine's.

I'll post a tidied up version, there are several problems with this hack. :)
Logged

fcarentz

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 24
Re: HACK: Notify Members on Comment
« Reply #6 on: December 29, 2005, 06:03:23 am »

db_query() was renamed cpg_db_query() in 1.4 because it conflicted with other apps (particularly SMF) that have a function of the same name. That's the only reason the hack works for you - it is in fact using SMF's database functions and not Coppermine's.

I'll post a tidied up version, there are several problems with this hack. :)

Thanks Nibbler...
Like I was saying I would be very interested in any coding documentation that there may be available.

Nibbler

  • Guest
Re: HACK: Notify Members on Comment
« Reply #7 on: December 29, 2005, 06:10:28 am »

Here's the more generic version, db_input.php:

Find:

Code: [Select]
        if (!USER_ID) { // Anonymous users, we need to use META refresh to save the cookie
Above/before that, add

Code: [Select]
//Start New User Notification Code
$result = cpg_db_query("SELECT owner_id  FROM {$CONFIG['TABLE_PICTURES']} WHERE pid=".$pid);
list($uid) = mysql_fetch_row($result);

// We can't send an email if this pic was uploaded by a guest
if ($uid){

// This can get the right info if the bridge is enabled or not.
$picture_owner_data = $cpg_udb->get_user_infos($uid);

//make sure we don't email ourself.
if(USER_ID != $uid){

// check the user has specified an email address
if ($picture_owner_data['user_email']){
$subject = "New Gallery Comment by ".USER_NAME." at  {$CONFIG['gallery_name']} ";
$mail_body  = "Hi ".$picture_owner_data['user_name']."!\n\n".USER_NAME." just wrote a comment on one of your photos, click the link below to read and reply to it.\n";
$mail_body .= $CONFIG['site_url'] . "displayimage.php?pos=-".$pid;
cpg_mail($picture_owner_data['user_email'], $subject, $mail_body);
}
}
}
// End User Notification Code.

There is no coding documentation available, you just have to learn by reading the code :)
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: HACK: Notify Members on Comment
« Reply #8 on: December 29, 2005, 06:29:16 am »

I'm not sure if it's in the code, but does the picture owner have an option not to receive notification, as they can do for forum post notifications?
Logged

Nibbler

  • Guest
Re: HACK: Notify Members on Comment
« Reply #9 on: December 29, 2005, 06:32:58 am »

No, but it could be added.
Logged

fcarentz

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 24
Re: HACK: Notify Members on Comment
« Reply #10 on: December 29, 2005, 07:21:01 am »

I'm not sure if it's in the code, but does the picture owner have an option not to receive notification, as they can do for forum post notifications?

That was going to be my next step or attempt with learning the Coppermine system. Only problem is I'm not sure where to put the clickable option...Should it be on a picture by picture basis? or an over all option. Also if its an over all option and you are using an integration such as SMF the option would have to be in the Profile which would require updating the SMF profile file...so not sure how to handle that...IF its an option you set on each individual picture it would seem to be a bit easier to handle especially since coppermine can be integrated with so many systems.

fcarentz

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 24
Re: HACK: Notify Members on Comment
« Reply #11 on: December 29, 2005, 08:53:14 am »

No, but it could be added.

Oh its added. I really needed this feature for my site, so I figured a lot of other people probably would to. Hope this is a step in the right direction here.

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: MOD: Email Notification to members on Comment
« Reply #12 on: December 29, 2005, 06:59:18 pm »

It seems that there is no check to see if the member has seen the comment... So let's say they don't view comment #1. Then comments 2-10 arrive with notifications each? Is it possible to make it like forums where the user doesn't get notified again until they view the image? It's probably a bit difficult, but this would minimize emails people get.

Thanks for your work on this.

disclaimer: I personally don't need this (now) because I don't have other people uploading pictures and such, so I'm just trying to help those who would be using it.
Logged

fcarentz

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 24
Re: MOD: Email Notification to members on Comment
« Reply #13 on: December 29, 2005, 07:03:58 pm »

Can it be done, well sure it can the forums do it. But I've never looked into how they track that. I would guess that it just checks to see if the previous post was by the owner

Thats how it seems to work on my forums...If i want to continue to be notified I have to keep replying...but I only get notified on the first post following mine. Then I wont get an email again until I respond.

at least thats how I think it works on the forums...I'm not competely sure. If someone knows different please speak up and I will see what I can do with this MOD to make that part of it.

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: MOD: Email Notification to members on Comment
« Reply #14 on: December 29, 2005, 07:10:00 pm »

I think -- and I might be wrong -- but forums I've used (phpbb and smf) track by simple viewing. That's how they know if there are new posts for us to read.

This would require a second mod, it seems. One that tracks the user's views. This has been requested before, I think.
Logged

fcarentz

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 24
Re: MOD: Email Notification to members on Comment
« Reply #15 on: December 29, 2005, 07:53:22 pm »

It appears that SMF uses a seperate table called smf_log_notify to see whether or not an email has already been sent. Now I just need to find where/how they change the value back to NULL once I look at it.

I am guessing that would be somewhere in the Display section.

fcarentz

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 24
Re: MOD: Email Notification to members on Comment
« Reply #16 on: December 29, 2005, 10:03:08 pm »

That should do it....Flood Protection has been added.

If you have already used this mod you just need to add the New mySQL Alter Table to add the sent column to the pictures table. Also you will have to reupdate your db_input.php file again and then do the changes to your displayimage.php

I think this makes it much nicer and wasn't that big of a Mod at all. I originally thought it was going to be much more complex. Happy to give something back to the community for making such a great gallery available for free!

Question, comments, suggestions, wants or needs? Post em!

nitram

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: MOD: Email Notification to members on Comment (UPDATED 12-29-05)
« Reply #17 on: December 31, 2005, 04:01:35 pm »

I use version 1.4.2 but in my editOnePic.php i don't find this parts:

// If this is the users gallery icon then check it
$isgalleryicon_selected = ($CURRENT_PIC['galleryicon']) ? 'checked="checked" ': '';
$isgalleryicon_disabled = ($CURRENT_PIC['category'] < FIRST_USER_CAT)? 'disabled="disabled" ':'';


and

<tr>
           <td width="20%" align="center"><input type="checkbox" name="galleryicon" {$isgalleryicon_selected}{$isgalleryicon_disabled}value="{$CURRENT_PIC['pid']}" class="checkbox" />{$lang_editpics_php['gallery_icon']}</td>
          <td width="20%" align="center"><input type="checkbox" name="read_exif" value="1" class="checkbox" />{$lang_editpics_php['read_exif']}</td>
          <td width="20%" align="center"><input type="checkbox" name="reset_vcount" value="1" class="checkbox" />{$lang_editpics_php['reset_view_count']}</td>
          <td width="20%" align="center"><input type="checkbox" name="reset_votes" value="1" class="checkbox" />{$lang_editpics_php['reset_votes']}</td>
          <td width="20%" align="center"><input type="checkbox" name="del_comments" value="1" class="checkbox" />{$lang_editpics_php['del_comm']}</td>
</tr>


Why not?  ???
Logged

fcarentz

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 24
Re: MOD: Email Notification to members on Comment (UPDATED 12-29-05)
« Reply #18 on: January 01, 2006, 01:10:24 am »

This is on/around line 374
Code: [Select]
// If this is the users gallery icon then check it
$isgalleryicon_selected = ($CURRENT_PIC['galleryicon']) ? 'checked="checked" ': '';
$isgalleryicon_disabled = ($CURRENT_PIC['category'] < FIRST_USER_CAT)? 'disabled="disabled" ':'';

and is immediately followed by

Code: [Select]
<tr>
           <td width="20%" align="center"><input type="checkbox" name="galleryicon" {$isgalleryicon_selected}{$isgalleryicon_disabled}value="{$CURRENT_PIC['pid']}" class="checkbox" />{$lang_editpics_php['gallery_icon']}</td>
          <td width="20%" align="center"><input type="checkbox" name="read_exif" value="1" class="checkbox" />{$lang_editpics_php['read_exif']}</td>
          <td width="20%" align="center"><input type="checkbox" name="reset_vcount" value="1" class="checkbox" />{$lang_editpics_php['reset_view_count']}</td>
          <td width="20%" align="center"><input type="checkbox" name="reset_votes" value="1" class="checkbox" />{$lang_editpics_php['reset_votes']}</td>
          <td width="20%" align="center"><input type="checkbox" name="del_comments" value="1" class="checkbox" />{$lang_editpics_php['del_comm']}</td>
</tr>

Are you using an upgraded version? Not why you wouldnt have that in your file. All my changes have been done on a new install.

AWJunkies

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 130
Re: MOD: Email Notification to members on Comment (UPDATED 12-29-05)
« Reply #19 on: March 29, 2006, 10:01:55 pm »

I changed the code around to add the comment and the picture within the E-mail. This makes a HUGE difference to me and maybe some other people. Please just change a few of the variables in the E-mail from website to what your site realy is. I also am adding code into editpics.php to make it so you can click all photos to not recieve comments within an album or indevidualy click on and off within that.

Code: [Select]
//Start New User Notification Code
                                 $result = cpg_db_query("SELECT owner_id, filename, filepath, notify, sent, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']} WHERE pid=".$pid);
                                 list($uid, $filename, $filepath, $notify, $sent, $pwidth, $pheight) = mysql_fetch_row($result);

                                // We can't send an email if this pic was uploaded by a guest
                                //User must request notification.
                                if ($uid && $notify == "Yes"){

                                                // This can get the right info if the bridge is enabled or not.
                                               $picture_owner_data = $cpg_udb->get_user_infos($uid);

                                               //make sure we don't email ourself and that we arent being flooded
                                                if(USER_ID != $uid  && !$sent){
                                                                // check the user has specified an email address
if ($CONFIG['make_intermediate'] && max($pwidth, $pheight) > $CONFIG['picture_width']) {
$picture_url = normal_;
    } else {
    $picture_url = '';
}
                                                                // send an email to the owner of the picture
                                                                if ($picture_owner_data['user_email']){
                                                                                $subject = "New website Comment by ".USER_NAME;
                                                                                $mail_body  = "Hi <b>".$picture_owner_data['user_name']."!</b>\n\n".USER_NAME." just wrote a comment on one of your photos:<br /><b>".$_POST['msg_body']."</b><br /><br /><a href='$CONFIG[site_url]displayimage.php?pos=-$pid'><img src='$CONFIG[site_url]albums/".$filepath."".$picture_url."$filename'></img></a><br />Click the image above to reply to the comment or click <a href='$CONFIG[site_url]displayimage.php?pos=-$pid'><b>HERE</b></a>.<br />\n";
                                                                                $mail_body .= "More comments may be posted, but you won't receive any more notifications until you read them.<br />\n";
                                                                                cpg_mail($picture_owner_data['user_email'], $subject, make_clickable($mail_body), 'text/plain', "website", 'name@website.com');
                                                                }
                                                               //Mark that we've sent a notification so the pic owner doesnt get flooded.
                                                               if(!$sent){
                                                                           $result = cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET sent = 1  WHERE pid=".$pid);
                                                               }
                                              }
                                }
// End User Notification Code.
Logged
Pages: [1] 2 3   Go Up
 

Page created in 0.031 seconds with 20 queries.