4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: x23piracy on November 18, 2010, 10:05:14 AM

Title: [MOD] Email when comment written all in one
Post by: x23piracy on November 18, 2010, 10:05:14 AM
Hi,

da es mich ziemlich nervt wenn man sich seine Infos aus etlichen Threads zusammensuchen muss,
hier mal die Zusammenfassung.

Die Änderung von Andi bzgl. des Datums ist hier schon eingeflossen


Email verschicken wenn ein Kommentar geschrieben wurde:

Schritt 1.

Suche in details.php:
if (!$error)  {
      $sql = "INSERT INTO ".COMMENTS_TABLE."
              (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date)
              VALUES
              ($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().")";
      $site_db->query($sql);
      $commentid = $site_db->get_insert_id();
      update_comment_count($id, $user_info['user_id']);
      $msg = $lang['comment_success'];
    }
  }
  unset($row);
  unset($spam_row);
}


Ersetze mit (wenn nur der User eine Email erhalten soll):
   if (!$error)  {
      $sql = "INSERT INTO ".COMMENTS_TABLE."
              (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date)
              VALUES
              ($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().")";
      $site_db->query($sql);
      $commentid = $site_db->get_insert_id();
      update_comment_count($id, $user_info['user_id']);
      $msg = $lang['comment_success'];
        $sql = "SELECT image_name FROM ".IMAGES_TABLE." WHERE image_id = $id";
    $image_name = $site_db->query($sql);
    $sql = "SELECT user_id FROM ".IMAGES_TABLE." WHERE image_id = $id";
    $user_id = $site_db->query($sql);
    
    $recipient_name = $image_row['user_name'];
    $recipient_email = $image_row['user_email'];
    $image_url = $script_url."/details.php?".URL_IMAGE_ID."=".$id."";

    
    // Start Emailer für comments
    include(ROOT_PATH.'includes/email.php');
    $site_email = new Email();
    $site_email->set_to($recipient_email);
    $site_email->set_from($config['site_email'], $config['site_name']);
    $site_email->set_subject("Neuer Kommentar zu deinem Bild");
    $site_email->register_vars(array(
      "user_name" => $image_row['user_name'],
      "recipient_name" => $recipient_name,
      "image_name" => $image_row['image_name'],
      "comment_date" => format_date($config['date_format']." ".$config['time_format'], time()),
      "site_name" => $config['site_name'],
      "image_url" => $image_url,
      "comment_text" =>$comment_text,
      "comment_headline"=>$comment_headline,
          ));
    $site_email->set_body("comment_email", $config['language_dir']);
    $site_email->send_email();
    }
  }
  unset($row);
  unset($spam_row);
}

oder...

Ersetze mit (wenn nur der Admin eine Email erhalten soll):
   if (!$error)  {
      $sql = "INSERT INTO ".COMMENTS_TABLE."
              (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date)
              VALUES
              ($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().")";
      $site_db->query($sql);
      $commentid = $site_db->get_insert_id();
      update_comment_count($id, $user_info['user_id']);
      $msg = $lang['comment_success'];
        $sql = "SELECT image_name FROM ".IMAGES_TABLE." WHERE image_id = $id";
    $image_name = $site_db->query($sql);
    $sql = "SELECT user_id FROM ".IMAGES_TABLE." WHERE image_id = $id";
    $user_id = $site_db->query($sql);
    
    $recipient_name = $image_row['user_name'];
    $recipient_email = $image_row['user_email'];
    $image_url = $script_url."/details.php?".URL_IMAGE_ID."=".$id."";
    
    // Start Admin-Mail
    $recipient_name = $config['site_name'];
    $recipient_email = $config['site_email'];

    $site_email = new Email();
    $site_email->set_to($recipient_email);
    $site_email->set_from($config['site_email'], $config['site_name']);
    $site_email->set_subject("Neuer Kommentar wurde geschrieben");
    $site_email->register_vars(array(
      "user_name" => $image_row['user_name'],
      "recipient_name" => $recipient_name,
      "image_name" => $image_row['image_name'],
      "comment_date" => format_date($config['date_format']." ".$config['time_format'], time()),
      "site_name" => $config['site_name'],
      "image_url" => $image_url,
      "comment_text" =>$comment_text,
      "comment_headline"=>$comment_headline,
          ));
    $site_email->set_body("comment_email", $config['language_dir']);
    $site_email->send_email();
    }
  }
  unset($row);
  unset($spam_row);
}

oder...

Ersetze mit (wenn sowohl der Admin als auch der User eine Email erhalten sollen):
   if (!$error)  {
      $sql = "INSERT INTO ".COMMENTS_TABLE."
              (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date)
              VALUES
              ($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().")";
      $site_db->query($sql);
      $commentid = $site_db->get_insert_id();
      update_comment_count($id, $user_info['user_id']);
      $msg = $lang['comment_success'];
        $sql = "SELECT image_name FROM ".IMAGES_TABLE." WHERE image_id = $id";
    $image_name = $site_db->query($sql);
    $sql = "SELECT user_id FROM ".IMAGES_TABLE." WHERE image_id = $id";
    $user_id = $site_db->query($sql);
    
    $recipient_name = $image_row['user_name'];
    $recipient_email = $image_row['user_email'];
    $image_url = $script_url."/details.php?".URL_IMAGE_ID."=".$id."";

    
    // Start Emailer für comments
    include(ROOT_PATH.'includes/email.php');
    $site_email = new Email();
    $site_email->set_to($recipient_email);
    $site_email->set_from($config['site_email'], $config['site_name']);
    $site_email->set_subject("Neuer Kommentar zu deinem Bild");
    $site_email->register_vars(array(
      "user_name" => $image_row['user_name'],
      "recipient_name" => $recipient_name,
      "image_name" => $image_row['image_name'],
      "comment_date" => format_date($config['date_format']." ".$config['time_format'], time()),
      "site_name" => $config['site_name'],
      "image_url" => $image_url,
      "comment_text" =>$comment_text,
      "comment_headline"=>$comment_headline,
          ));
    $site_email->set_body("comment_email", $config['language_dir']);
    $site_email->send_email();
    
    // Start Admin-Mail
    $recipient_name = $config['site_name'];
    $recipient_email = $config['site_email'];

    $site_email = new Email();
    $site_email->set_to($recipient_email);
    $site_email->set_from($config['site_email'], $config['site_name']);
    $site_email->set_subject("Neuer Kommentar wurde geschrieben");
    $site_email->register_vars(array(
      "user_name" => $image_row['user_name'],
      "recipient_name" => $recipient_name,
      "image_name" => $image_row['image_name'],
      "comment_date" => format_date($config['date_format']." ".$config['time_format'], time()),  
      "site_name" => $config['site_name'],
      "image_url" => $image_url,
      "comment_text" =>$comment_text,
      "comment_headline"=>$comment_headline,
          ));
    $site_email->set_body("comment_email", $config['language_dir']);
    $site_email->send_email();
    }
  }
  unset($row);
  unset($spam_row);
}



Schritt 2.

Erstelle in Verzeichnis ../lang/[deine Sprache]/email/ die Datei "comment_email.html"

Diese Datei stellt den Mail Body also die Nachricht dar, innerhalb dieser Datei können
folgende Variablen verwendet werden:


Ein fertiges Beispiel für ein Email Template wäre z.B.:

Code: [Select]
Hallo {recipient_name},

{user_name} gab einen Kommentar zu deinem Bild "{image_name}" ab in {site_name}.

Kommentar:

{comment_headline}

{comment_text}

Hier kannst du den Kommentar ansehen: {image_url}

Datum: {comment_date}

------
Mit freundlichen Grüssen,
{site_name}


Schritt 3 (optional)

Wer seinen Usern noch anbieten möchte selbst zu entscheiden ob Sie bei neuen Kommentaren
zu Ihren Bildern eine Email wünschen ist folgendes notwendig:

Datenbank erweitern:

Code: [Select]
ALTER TABLE 4images_users ADD (user_mail_text INT UNSIGNED);
UPDATE 4images_users SET user_mail_text =1;

Datenbankfeld bekannt machen:

Ergänze in db_field_definitions.php:
Code: [Select]
$additional_user_fields['user_mail_text'] = array($lang['mail_text'], "radio", 0);
Ergänze in member_editprofile.html:

Code: [Select]
<!-- Mod Mail -->
<tr>
            <td class="row2"><b>Benachrichtigung bei Kommentar</b></td>
            <td class="row2">
              <input type="radio" name="user_mail_text" value="1"{user_mail_text_yes} />
              {lang_yes}&nbsp;&nbsp;&nbsp;
              <input type="radio" name="user_mail_text" value="0"{user_mail_text_no} />
              {lang_no}
            </td>
          </tr>
<!-- Mod Mail -->


Tweaks:

Wer seine User nicht zwingen möchte einen Kommentar-Betreff zu schreiben macht folgendes:

in der details.php löschen/auskommentieren:
Code: [Select]
if ($comment_headline == "")  {
  $msg .= (($msg != "") ? "<br />" : "").$lang['headline_required'];
  $error = 1;
}


Um auch im ACP Bereich davon befreit zu sein:

in der admin/comments.php löschen/auskommentieren:
Code: [Select]
 if ($comment_headline == "") {
    $error['comment_headline'] = 1;
  }


Falls diese Art von zusammentragen auf Freude stößt verschiebt das ganze ein Mod ins richtige Forum.


Gruß Jens




Title: Re: [MOD] Email when comment written all in one
Post by: Sunny C. on November 25, 2010, 08:45:03 PM
In 1.7.9 läuft es nicht!
Der Code der ersetzt wird, ist anders und sieht so aus:
    if (!$error)  {
      $sql = "INSERT INTO ".COMMENTS_TABLE."
              (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date)
              VALUES
              ($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().")";
      $site_db->query($sql);
      $commentid = $site_db->get_insert_id();
      update_comment_count($id, $user_info['user_id']);
      $msg = $lang['comment_success'];
      $site_sess->set_session_var("msgdetails", $msg);
      redirect(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&mode=".$mode : "").(($page > 1) ? "&page=".$page : ""));
    }
  }
  unset($row);
  unset($spam_row);
}

Ich habe das so abgeändert.... aber bekomme kein Mail
   if (!$error)  {
      $sql = "INSERT INTO ".COMMENTS_TABLE."
              (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date)
              VALUES
              ($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().")";
      $site_db->query($sql);
      $commentid = $site_db->get_insert_id();
      update_comment_count($id, $user_info['user_id']);
      $msg = $lang['comment_success'];
      $site_sess->set_session_var("msgdetails", $msg);
      redirect(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&mode=".$mode : "").(($page > 1) ? "&page=".$page : ""));
        $sql = "SELECT image_name FROM ".IMAGES_TABLE." WHERE image_id = $id";
    $image_name = $site_db->query($sql);
    $sql = "SELECT user_id FROM ".IMAGES_TABLE." WHERE image_id = $id";
    $user_id = $site_db->query($sql);
   
    $recipient_name = $image_row['user_name'];
    $recipient_email = $image_row['user_email'];
    $site_sess->set_session_var("msgdetails", $msg);
    redirect(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&mode=".$mode : "").(($page > 1) ? "&page=".$page : ""));

   
    // Start Emailer für comments
    include(ROOT_PATH.'includes/email.php');
    $site_email = new Email();
    $site_email->set_to($recipient_email);
    $site_email->set_from($config['site_email'], $config['site_name']);
    $site_email->set_subject("Neuer Kommentar zu deinem Bild");
    $site_email->register_vars(array(
      "user_name" => $image_row['user_name'],
      "recipient_name" => $recipient_name,
      "image_name" => $image_row['image_name'],
      "comment_date" => format_date($config['date_format']." ".$config['time_format'], time()),
      "site_name" => $config['site_name'],
      "image_url" => $image_url,
      "comment_text" =>$comment_text,
      "comment_headline"=>$comment_headline,
          ));
    $site_email->set_body("comment_email", $config['language_dir']);
    $site_email->send_email();
   
    // Start Admin-Mail
    $recipient_name = $config['site_name'];
    $recipient_email = $config['site_email'];

    $site_email = new Email();
    $site_email->set_to($recipient_email);
    $site_email->set_from($config['site_email'], $config['site_name']);
    $site_email->set_subject("Neuer Kommentar wurde geschrieben");
    $site_email->register_vars(array(
      "user_name" => $image_row['user_name'],
      "recipient_name" => $recipient_name,
      "image_name" => $image_row['image_name'],
      "comment_date" => format_date($config['date_format']." ".$config['time_format'], time()), 
      "site_name" => $config['site_name'],
      "image_url" => $image_url,
      "comment_text" =>$comment_text,
      "comment_headline"=>$comment_headline,
          ));
    $site_email->set_body("comment_email", $config['language_dir']);
    $site_email->send_email();
    }
  }
  unset($row);
  unset($spam_row);
}
Title: Re: [MOD] Email when comment written all in one
Post by: x23piracy on November 25, 2010, 10:16:40 PM
Hi,

ich hab das in 1.7.9 am laufen!... komisch
mailing generell i.O.?


Gruß Jens
Title: Re: [MOD] Email when comment written all in one
Post by: Sunny C. on November 26, 2010, 05:59:35 PM
Mailing ist genrell in Ordnung

Generell findet man den Code so
if (!$error)  {
      $sql = "INSERT INTO ".COMMENTS_TABLE."
              (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date)
              VALUES
              ($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().")";
      $site_db->query($sql);
      $commentid = $site_db->get_insert_id();
      update_comment_count($id, $user_info['user_id']);
      $msg = $lang['comment_success'];
    }
  }
  unset($row);
  unset($spam_row);
}
in der details.php nicht
Title: Re: [MOD] Email when comment written all in one
Post by: Scarala on November 15, 2012, 08:04:43 AM
Ich hab das selbe Problem wie Sumale.nin

Hab alles so eingebaut wie im ersten posting beschrieben, nur halt das selbe wie bei Sumale.nin, das der code in der details.php anders aussieht.

nachdem ich die Zeilen

      $site_sess->set_session_var("msgdetails", $msg);
      redirect(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&mode=".$mode : "").(($page > 1) ? "&page=".$page : ""));

gelöscht habe, funktionierte alles fehlerfrei.