1 (edited by 2008-08-12 19:26:53)

Topic: [HACK] Mail On Comments

Name: Mail On Comments
Author: NyNe
CuteNews Compatibility: 1.3.6  (higher version have this option build in)
Description: Whenever someone makes a comment, you'll receive an email.
Requirements: CuteMail Hack
Instructions:

open ./inc/options.mdu
find:
[code]     $registrationdate
     </tr>[/code]
add below:
[code]<!--// MailOnComment v1.1 - Start AddBlock-->
"; if(trim($member_db[10]) == 1){ $mail_com = "checked"; }
if($member_db[1] != 4){echo"<tr>
<td height=\"21\" width=\"200\" bgcolor=#F7F6F4>
              mail on comments
<td height=\"21\" width=\"400\" bgcolor=#F7F6F4 >
<input type=checkbox value=\"1\" name=change_mail_on_comment $mail_com>    when someone comments you will recieve an e-mail
</tr>"; }else{ $bg = "bgcolor=#F7F6F4"; } echo "
<!--// MailOnComment v1.1 - End AddBlock-->[/code]
find:
[code]        showRow("Admin Email", "used as sender of mail, if blank mail will be from webmaster@yourdomain", "<input type=text style=\"text-align: center;\"  name='save_con[mail_admin_address]' value='$config_mail_admin_address' size=40>");[/code]
add below:
[code]// MailOnComment v1.1 - Start AddBlock
        showRow("Admin MailOnComment", "admin should always recieve mail when any user comments", makeDropDown(array("yes"=>"Yes","no"=>"No"), "save_con[mail_admin_comments]", "$config_mail_admin_comments"));
// MailOnComment v1.1 - End AddBlock[/code]

open ./inc/addnews.mdu
find:
[code]<input style=\"border:0; background-color:transparent\" type=checkbox value=\"yes\" name=\"if_convert_new_lines\" checked> Convert new lines to
[/code]
add in front of it: (so you get the    on the same line - it might already be there)
[code]<!--// MailOnComment v1.1 - Start AddBlock-->
"; if(trim($member_db[10]) == 1){ $mail_com = "checked"; } echo "
  <input style=\"border:0; background-color:transparent\" type=checkbox value=\"1\" name=\"mail_on_comment\" $mail_com> Recieve mail when this post is commented on

<!--// MailOnComment v1.1 - End AddBlock-->
  [/code]
find:
[code]fwrite($news_file, "$added_time|$member_db[2]|$title|$short_story|$full_story|$manual_avatar|$category||\n");[/code]
replace with:
[code]// MailOnComment v1.1 - Start ChangeBlock
if ($mail_on_comment != 1) $mail_on_comment = 0;
fwrite($news_file, "$added_time|$member_db[2]|$title|$short_story|$full_story|$manual_avatar|$category|$mail_on_comment||\n");
// MailOnComment v1.1 - End ChangeBlock[/code]

open ./inc/editnews.mdu
find:
[code]fwrite($new_db,"$old_db_arr[0]|$old_db_arr[1]|$title|$short_story|$full_story|$editavatar|$category||\n");[/code]
replace with:
[code]   // MailOnComment v1.1 - Start ChangeBlock
   if ($mail_on_comment != 1) $mail_on_comment = 0;
   fwrite($new_db,"$old_db_arr[0]|$old_db_arr[1]|$title|$short_story|$full_story|$editavatar|$category|$mail_on_comment||\n");
   // MailOnComment v1.1 - End ChangeBlock[/code]
find:
[code]<option title="delete all selected news" value="mass_delete">Delete</option>[/code]
add below:
[code]<!--// MailOnComment v1.1 - Start AddBlock-->
<option title="enable/disable mail on comments for selected news" value="mass_mail_comments">Enable/Disable Mail on Comments</option>
<!--// MailOnComment v1.1 - End AddBlock-->[/code]
find:
[code]<input style=\"border:0; background-color:transparent\" type=checkbox value=\"yes\" name=\"if_convert_new_lines\" checked> Convert new lines to
[/code]
add in front of it: (so you get the    on the same line - it might already be there)
[code]<!--// MailOnComment v1.1 - Start AddBlock-->
"; if(trim($item_db[7]) == 1){ $mail_com = "checked"; } echo "
  <input style=\"border:0; background-color:transparent\" type=checkbox value=\"1\" name=\"mail_on_comment\" $mail_com> Recieve mail when this post is commented on

<!--// MailOnComment v1.1 - End AddBlock-->
  [/code]

open ./inc/massactions.mdu
find:
[code]/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  If No Action Is Choosed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */[/code]
add above:
[code]/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Mass MailOnComments v1.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
elseif($action == "mass_mail_comments"){

if(!$selected_news){ msg("error", "Error", "You have not specified any articles", "$PHP_SELF?mod=editnews&action=list&source=$source"); }

echoheader("options", "Enable/Disable Mail On Comments");

echo "<form action=\"$PHP_SELF\" method=post><table border=0 cellpading=0 cellspacing=0 width=100% height=100%><tr><td><select name=mail_comments><option value=\"1\">Enable</option><option value=\"0\">Enable</option></select> mail on comments for these ".count($selected_news)." posts?";

foreach($selected_news as $null => $newsid){
    echo "<input type=hidden name=selected_news[] value=\"$newsid\">";
}

echo " <input type=hidden name=action value=\"do_mass_mail_comments\"><input type=hidden name=source value=\"$source\"><input type=hidden name=mod value=\"massactions\"> <input type=submit value=\"Change\"></td></tr></table></form>";

echofooter();
exit;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  DO Mass MailOnComments 1.1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
elseif($action == "do_mass_mail_comments"){
if(!$selected_news){ msg("error", "Error", "You have not specified any articles", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
if($source == ""){ $news_file = "./data/news.txt";}
else{ $news_file = "./data/archives/$source.news.arch"; }
    $changed_articles = 0;
    $old_db = file("$news_file");
    $new_db = fopen("$news_file", w);
    foreach($old_db as $null => $old_db_line){
  $old_db_arr = explode("|", $old_db_line);
  if(@!in_array($old_db_arr[0], $selected_news)){
   fwrite($new_db,"$old_db_line");
         }
         else
            {
    $have_perm = 0;
       if(($member_db[1] == 1) or ($member_db[1] == 2)){$have_perm = 1;}
       elseif($member_db[1] == 3 and $old_db_arr[1] == $member_db[2]) {$have_perm = 1;}
    if(!$have_perm){ fwrite($new_db,"$old_db_line"); }
                else{
                 fwrite($new_db,"$old_db_arr[0]|$old_db_arr[1]|$old_db_arr[2]|$old_db_arr[3]|$old_db_arr[4]|$old_db_arr[5]|$old_db_arr[6]|$mail_comments||\n");
                 $changed_articles ++;
                }
   }
    }
    fclose($new_db);
if(count($selected_news) == $changed_articles){ msg("info", "News Changed", "All articles that you selected ($changed_articles) were changed successfully", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
else{ msg("error", "News Changed (with errors)", "Only $changed_articles of ".count($selected_news)." articles that you selected were changed successfully", "$PHP_SELF?mod=editnews&action=list&source=$source"); }
}[/code]

open ./inc/shows.inc.php
find:
[code]//################################################################################
####################################
//                         Add Comment
//################################################################################
####################################[/code]
add above:
[code]//################################################################################
####################################
//                         Check for MailOnComment v1.1
//################################################################################
####################################
$all_news = file("$news_file");
    while (list(, $news_data) = each($all_news)){
    $news_data = explode("|",$news_data);
    if(($id == $news_data[0]) && ($news_data[7] == 1)){
  $mail_on_comment_run = TRUE;
  while (list(, $user) = each($all_users)){
   $user_arr = explode("|",$user);
   if ($news_data[1] == $user_arr[2]) {
    $mail_on_comment_address = $user_arr[5];
   }
  }
    }
}[/code]
find:
[code]            $found = TRUE;
        }else{
                        fwrite($new_comments, $old_comments_line);[/quote]
add above:
[code]// MailOnComment v1.1 - Start AddBlock
if ($mail_on_comment_run == true) {
$all_news = file("$news_file");
while (list(, $news_data) = each($all_news)){
    $news_arr = explode("|",$news_data);
    if ($news_arr[0] == $old_comments_arr[0] && isset($news_arr[2]) && $news_arr[2] != "") {
  $mail_comment = html_entity_decode(preg_replace(array("'
'", "'
'", "'|'", "'\\''"), array("\n", "\n", "|", "\'"), $comments), ENT_QUOTES);
  $mail_name = html_entity_decode(preg_replace(array("'|'", "'\\''"), array("|", "\'"), $name), ENT_QUOTES);
  $mail_title = html_entity_decode(preg_replace(array("'|'", "'\\''"), array("|", "\'"), $news_arr[2]), ENT_QUOTES);
  $send_them_mail = "";
  if(preg_match("/^[\.A-z0-9_\-]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $mail)){ $send_them_mail = "\n Send them mail: $mail"; }
  cute_mail($mail_on_comment_address, "Your post has received a comment", "$mail_name has commented on your post: \n $mail_title $send_them_mail \n\n Comment: \n $mail_comment");
  if ($config_mail_admin_comments == "yes") { cute_mail($config_mail_admin_address, "$news_arr[1]'s post has received a comment", "$mail_name has commented on $news_arr[1]'s post: \n $mail_title $send_them_mail \n\n Comment: \n $mail_comment"); }
    }
}}
// MailOnComment v1.1 - End AddBlock[/code]