Commit c4b925c7 authored by sylvieg's avatar sylvieg

messages mail in user charset and user language and correct uf8 header

parent 303a9307
......@@ -2960,6 +2960,7 @@ tiki/templates/mail/forum_post_notification.tpl -text
tiki/templates/mail/messu_message_notification.tpl -text
tiki/templates/mail/messu_message_notification_subject.tpl -text
tiki/templates/mail/new_user_notification.tpl -text
tiki/templates/mail/new_user_notification_subject.tpl -text
tiki/templates/mail/newsletter_byebye.tpl -text
tiki/templates/mail/newsletter_byebye_subject.tpl -text
tiki/templates/mail/newsletter_unsubscribe.tpl -text
......@@ -2969,6 +2970,7 @@ tiki/templates/mail/notification_subject.tpl -text
tiki/templates/mail/password_reminder.tpl -text
tiki/templates/mail/password_reminder_subject.tpl -text
tiki/templates/mail/submission_notification.tpl -text
tiki/templates/mail/submission_notification_subject.tpl -text
tiki/templates/mail/tracker_changed_notification.tpl -text
tiki/templates/mail/user_validation_mail.tpl -text
tiki/templates/mail/user_watch_blog_post.tpl -text
......
......@@ -184,10 +184,10 @@ class ArtLib extends TikiLib {
$query = "select max(`subId`) from `tiki_submissions` where `created` = ? and `title`=? and `hash`=?";
$id = $this->getOne($query,array((int) $now,$title,$hash));
$emails = $notificationlib->get_mail_events('article_submitted', '*');
$foo = parse_url($_SERVER["REQUEST_URI"]);
$machine = httpPrefix(). $foo["path"];
foreach ($emails as $email) {
if (count($emails)) {
include_once("lib/notifications/notificationemaillib.php");
$foo = parse_url($_SERVER["REQUEST_URI"]);
$machine = httpPrefix(). $foo["path"];
$smarty->assign('mail_site', $_SERVER["SERVER_NAME"]);
$smarty->assign('mail_user', $user);
......@@ -197,9 +197,7 @@ class ArtLib extends TikiLib {
$smarty->assign('mail_date', date("U"));
$smarty->assign('mail_machine', $machine);
$smarty->assign('mail_subId', $id);
$mail_data = $smarty->fetch('mail/submission_notification.tpl');
@mail($email, tra('New article submitted at '). $_SERVER["SERVER_NAME"], $mail_data,
"From: $sender_email\r\nContent-type: text/plain;charset=utf-8\r\n");
sendEmailNotification($emails, "email", "submission_notification_subject.tpl", $_SERVER["SERVER_NAME"], "submission_notification.tpl");
}
return $id;
......
<?php
require_once('lib/webmail/tikimaillib.php');
class BlogLib extends TikiLib {
function BlogLib($db) {
......@@ -369,41 +368,26 @@ class BlogLib extends TikiLib {
if ($feature_user_watches == 'y') {
$nots = $this->get_event_watches('blog_post', $blogId);
$isBuild = false;
foreach ($nots as $not) {
if (!$isBuild) {
$isBuild = true;
$smarty->assign('mail_site', $_SERVER["SERVER_NAME"]);
$smarty->assign('mail_title', $title);
$smarty->assign('mail_blogid', $blogId);
$smarty->assign('mail_postid', $id);
$smarty->assign('mail_date', date("U"));
$smarty->assign('mail_user', $user);
$smarty->assign('mail_data', $data);
$smarty->assign('mail_hash', $not['hash']);
$foo = parse_url($_SERVER["REQUEST_URI"]);
$machine = httpPrefix(). $foo["path"];
$smarty->assign('mail_machine', $machine);
$parts = explode('/', $foo['path']);
if (count($parts) > 1)
unset ($parts[count($parts) - 1]);
$smarty->assign('mail_machine_raw', httpPrefix(). implode('/', $parts));
$mail = new TikiMail();
}
global $language;// TODO: optimise by grouping user by language
$languageEmail = $this->get_user_preference($not['user'], "language", $language);
$mail->setUser($not['user']);
$mail_data = $smarty->fetchLang($languageEmail, 'mail/user_watch_blog_post_subject.tpl');
$mail->setSubject(sprintf($mail_data, $title));
$mail_data = $smarty->fetchLang($languageEmail, 'mail/user_watch_blog_post.tpl');
$mail->setText($mail_data);
$mail->buildMessage();
$mail->send(array($not['email']));
$mail_data = $smarty->fetch('mail/user_watch_blog_post.tpl');
//@mail($not['email'], tra('Blog post'). ' ' . $title, $mail_data, "From: $sender_email\r\nContent-type: text/plain;charset=utf-8\r\n");
if (count($nots)) {
include_once("lib/notifications/notificationemaillib.php");
$smarty->assign('mail_site', $_SERVER["SERVER_NAME"]);
$query = "select `title` from `tiki_blogs` where `blogId`=?";
$blogTitle = $this->getOne($query, array((int)$blogId));
$smarty->assign('mail_title', $blogTitle);
$smarty->assign('mail_blogid', $blogId);
$smarty->assign('mail_postid', $id);
$smarty->assign('mail_date', date("U"));
$smarty->assign('mail_user', $user);
$smarty->assign('mail_data', $data);
$foo = parse_url($_SERVER["REQUEST_URI"]);
$machine = httpPrefix(). $foo["path"];
$smarty->assign('mail_machine', $machine);
$parts = explode('/', $foo['path']);
if (count($parts) > 1)
unset ($parts[count($parts) - 1]);
$smarty->assign('mail_machine_raw', httpPrefix(). implode('/', $parts));
sendEmailNotification($nots, "watch", "user_watch_blog_post_subject.tpl", $_SERVER["SERVER_NAME"], "user_watch_blog_post.tpl");
//@mail($not['email'], tra('Blog post'). ' ' . $blogTitle, $mail_data, "From: $sender_email\r\nContent-type: text/plain;charset=utf-8\r\n");
}
}
......
<?php
include_once('lib/webmail/tikimaillib.php');
class Messu extends Tikilib {
var $db;
......@@ -42,6 +40,7 @@ class Messu extends Tikilib {
if ($this->get_user_preference($user, 'minPrio', 6) <= $priority) {
$email = $userlib->get_user_email($user);
if ($email) {
include_once('lib/webmail/tikimaillib.php');
$smarty->assign('mail_site', $_SERVER["SERVER_NAME"]);
$smarty->assign('mail_machine', $machine);
$smarty->assign('mail_date', date("U"));
......@@ -50,7 +49,7 @@ class Messu extends Tikilib {
$smarty->assign('mail_subject', stripslashes($subject));
$smarty->assign('mail_body', stripslashes($body));
$mail = new TikiMail($user);
$lg = $this->get_user_preference($user, 'language', $language);
$lg = $this->get_user_preference($user, 'language', $this->get_preference("language", "en"));
$s = $smarty->fetchLang($lg, 'mail/messu_message_notification_subject.tpl');
$mail->setSubject(sprintf($s, $_SERVER["SERVER_NAME"]));
$mail_data = $smarty->fetchLang($lg, 'mail/messu_message_notification.tpl');
......
......@@ -73,7 +73,7 @@ function sendForumEmailNotification($event, $object, $forum_info, $title, $data,
}
}
}
/** \brief send the email notifications dealing with the forum changes to
/** \brief send the email notifications dealing with wiki page changes to
* admin notification addresses + watching users addresses (except editor is configured)
* \$event: 'wiki_page_created'|'wiki_page_changed'
*/
......@@ -144,4 +144,52 @@ function sendWikiEmailNotification($event, $pageName, $edit_user, $edit_comment,
}
}
}
/** \brief Send email notification to a list of emails or a list of (email, user) in a charset+language associated with each email
* \param $list : emails list or (users, email) list
* \param $type: type of the list element = 'email'|'watch'
* \param $subjectTpl: subject template file or null (ex: "submission_notifcation.tpl")
* \param $subjectParam: le param to be inserted in the subject or null
* \param $txtTpl : texte template file (ex: "submission_notifcation.tpl")
* \ $smarty is supposed to be already built to fit $txtTpl
* \return the nb of sent emails
*/
function sendEmailNotification($list, $type, $subjectTpl, $subjectParam, $txtTpl) {
global $smarty, $tikilib, $userlib;
include_once('lib/webmail/tikimaillib.php');
$mail = new TikiMail();
$sent = 0;
$defaultLanguage = $tikilib->get_preference("language", "en");
$languageEmail = $defaultLanguage;
foreach ($list as $elt) {
if ($type == "watch") {
$email = $elt['email'];
$userEmail = $elt['user'];
$smarty->assign('mail_hash', $elt['hash']);
}
else {
$email = $elt;
$userEmail = $userlib->get_user_by_email($email);
}
if ($userEmail) {
$mail->setUser($userEmail);
$languageEmail = $tikilib->get_user_preference($userEmail, "language", $defaultLanguage);
}
else
$languageEmail = $defaultLanguage;
if ($subjectTpl) {
$mail_data = $smarty->fetchLang($languageEmail, "mail/".$subjectTpl);
if ($subjectParam)
$mail_data = sprintf($mail_data, $subjectParam);
$mail_data = ereg_replace("\%[sd]", "", $mail_data);// partial cleaning if param not supply and %s in text
$mail->setSubject($mail_data);
}
else
$mail->setSubject($subjectParam);
$mail->setText($smarty->fetchLang($languageEmail, "mail/".$txtTpl));
$mail->buildMessage();
if ($mail->send(array($email)))
$sent++;
}
return $sent;
}
?>
\ No newline at end of file
{tr}New user registration{/tr}
\ No newline at end of file
{tr}A new article was submitted by {$mail_user} to {$mail_site} at {$mail_date|tiki_short_datetime}{/tr}
{tr}You can edit the submission following this link:{/tr} {$mail_machine}?subId={$mail_subId}
{tr}Title:{/tr} {$mail_title}
......
{tr}New article submitted at %s{/tr}
\ No newline at end of file
{tr}New blog post: %s{/tr}
\ No newline at end of file
{tr}New blog post at %s{/tr}
\ No newline at end of file
......@@ -113,12 +113,14 @@ if(isset($_REQUEST["register"])) {
}
$emails = $notificationlib->get_mail_events('user_registers','*');
foreach($emails as $email) {
if (count($emails)) {
include_once("lib/notifications/notificationemaillib.php");
$smarty->assign('mail_user',$_REQUEST["name"]);
$smarty->assign('mail_date',date("U"));
$smarty->assign('mail_site',$_SERVER["SERVER_NAME"]);
$mail_data = $smarty->fetch('mail/new_user_notification.tpl');
mail($email, tra('New user registration'),$mail_data,"From: $sender_email\r\nContent-type: text/plain;charset=utf-8\r\n");
sendEmailNotification($emails, "email", "new_user_notification_subject.tpl", null, "new_user_notification.tpl");
//@mail($email, tra('New user registration'),$mail_data,"From: $sender_email\r\nContent-type: text/plain;charset=utf-8\r\n");
}
if($validateUsers == 'y' and $email_valid != 'no') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment