Format code + fixing title and sender mail see BT#8960

1.9.x
Julio Montoya 11 years ago
parent 73f25bb25a
commit fa8f1b51f4
  1. 12
      main/inc/lib/mail.lib.inc.php
  2. 133
      main/inc/lib/notification.lib.php

@ -118,15 +118,18 @@ function api_mail_html(
$senderName = !empty($senderName) ? $senderName : $defaultEmail;
$senderEmail = !empty($senderEmail) ? $senderEmail : $defaultName;
$mail->SetFrom($senderEmail, $senderName, false);
// Reply to first
if (isset($extra_headers['reply_to'])) {
$mail->AddReplyTo(
$extra_headers['reply_to']['mail'],
$extra_headers['reply_to']['name']
);
$mail->Sender = $extra_headers['reply_to']['mail'];
unset($extra_headers['reply_to']);
}
$mail->SetFrom($senderEmail, $senderName);
$mail->Subject = $subject;
$mail->AltBody = strip_tags(
str_replace('<br />', "\n", api_html_entity_decode($message))
@ -204,11 +207,6 @@ function api_mail_html(
case 'content-type':
$mail->ContentType = $value;
break;
case 'reply_to':
if (isset($value['mail']) && isset($value['name'])) {
$mail->AddReplyTo($value['mail'], $value['name']);
}
break;
default:
$mail->AddCustomHeader($key.':'.$value);
break;

@ -27,8 +27,8 @@ class Notification extends Model
/* message, invitation, group messages */
public $type;
public $admin_name;
public $admin_email;
public $adminName;
public $adminEmail;
//mail_notify_message ("At once", "Daily", "No")
const NOTIFY_MESSAGE_AT_ONCE = 1;
const NOTIFY_MESSAGE_DAILY = 8;
@ -57,13 +57,13 @@ class Notification extends Model
{
$this->table = Database::get_main_table(TABLE_NOTIFICATION);
$this->admin_email = api_get_setting('noreply_email_address');
$this->admin_name = api_get_setting('siteName');
$this->adminEmail = api_get_setting('noreply_email_address');
$this->adminName = api_get_setting('siteName');
// If no-reply email doesn't exist use the admin email
if (empty($this->admin_email)) {
$this->admin_email = api_get_setting('emailAdministrator');
$this->admin_name = api_get_person_name(
if (empty($this->adminEmail)) {
$this->adminEmail = api_get_setting('emailAdministrator');
$this->adminName = api_get_person_name(
api_get_setting('administratorName'),
api_get_setting('administratorSurname'),
null,
@ -77,7 +77,7 @@ class Notification extends Model
*/
public function getDefaultPlatformSenderEmail()
{
return $this->admin_email;
return $this->adminEmail;
}
/**
@ -85,7 +85,7 @@ class Notification extends Model
*/
public function getDefaultPlatformSenderName()
{
return $this->admin_name;
return $this->adminName;
}
/**
@ -107,8 +107,8 @@ class Notification extends Model
$item_to_send['dest_mail'],
Security::filter_terms($item_to_send['title']),
Security::filter_terms($item_to_send['content']),
$this->admin_name,
$this->admin_email
$this->adminName,
$this->adminEmail
);
if ($this->debug) {
error_log('Sending message to: '.$item_to_send['dest_mail']);
@ -124,6 +124,59 @@ class Notification extends Model
}
}
/**
* @param string $title
* @param array $senderInfo
*/
public function formatTitle($title, $senderInfo)
{
$newTitle = '';
switch ($this->type) {
case self::NOTIFICATION_TYPE_MESSAGE:
if (!empty($sender_info)) {
$sender_name = api_get_person_name(
$senderInfo['firstname'],
$senderInfo['lastname'],
null,
PERSON_NAME_EMAIL_ADDRESS
);
$newTitle = sprintf(get_lang('YouHaveANewMessageFromX'), $sender_name);
}
break;
case self::NOTIFICATION_TYPE_INVITATION:
if (!empty($sender_info)) {
$sender_name = api_get_person_name(
$senderInfo['firstname'],
$senderInfo['lastname'],
null,
PERSON_NAME_EMAIL_ADDRESS
);
$newTitle = sprintf(get_lang('YouHaveANewInvitationFromX'), $sender_name);
}
break;
case self::NOTIFICATION_TYPE_GROUP:
if (!empty($sender_info)) {
$sender_name = $sender_info['group_info']['name'];
$newTitle = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $sender_name);
$sender_name = api_get_person_name(
$senderInfo['user_info']['firstname'],
$senderInfo['user_info']['lastname'],
null,
PERSON_NAME_EMAIL_ADDRESS
);
$sender_name = Display::url(
$sender_name,
api_get_path(WEB_CODE_PATH).'social/profile.php?'.$sender_info['user_info']['user_id']
);
$newTitle .= '<br />'.get_lang('User').': '.$sender_name;
}
break;
}
return $newTitle;
}
/**
* Save message notification
* @param int $type message type
@ -141,10 +194,11 @@ class Notification extends Model
$user_list,
$title,
$content,
$sender_info = array()
$senderInfo = array()
) {
$this->type = intval($type);
$content = $this->format_content($content, $sender_info);
$content = $this->formatContent($content, $senderInfo);
$titleToNotification = $this->formatTitle($title, $senderInfo);
$setting_to_check = '';
$avoid_my_self = false;
@ -152,20 +206,23 @@ class Notification extends Model
switch ($this->type) {
case self::NOTIFICATION_TYPE_MESSAGE:
$setting_to_check = 'mail_notify_message';
$default_status = self::NOTIFY_MESSAGE_AT_ONCE;
$defaultStatus = self::NOTIFY_MESSAGE_AT_ONCE;
break;
case self::NOTIFICATION_TYPE_INVITATION:
$setting_to_check = 'mail_notify_invitation';
$default_status = self::NOTIFY_INVITATION_AT_ONCE;
$defaultStatus = self::NOTIFY_INVITATION_AT_ONCE;
break;
case self::NOTIFICATION_TYPE_GROUP:
$setting_to_check = 'mail_notify_group_message';
$default_status = self::NOTIFY_GROUP_AT_ONCE;
$defaultStatus = self::NOTIFY_GROUP_AT_ONCE;
$avoid_my_self = true;
break;
default:
$defaultStatus = self::NOTIFY_MESSAGE_AT_ONCE;
break;
}
$setting_info = UserManager::get_extra_field_information_by_name($setting_to_check);
$settingInfo = UserManager::get_extra_field_information_by_name($setting_to_check);
if (!empty($user_list)) {
foreach ($user_list as $user_id) {
@ -174,18 +231,18 @@ class Notification extends Model
continue;
}
}
$user_info = api_get_user_info($user_id);
$userInfo = api_get_user_info($user_id);
// Extra field was deleted or removed? Use the default status.
if (empty($setting_info)) {
$user_setting = $default_status;
if (empty($settingInfo)) {
$userSetting = $defaultStatus;
} else {
$extra_data = UserManager::get_extra_user_data($user_id);
$user_setting = $extra_data[$setting_to_check];
$userSetting = $extra_data[$setting_to_check];
}
$sendDate = null;
switch ($user_setting) {
switch ($userSetting) {
// No notifications
case self::NOTIFY_MESSAGE_NO:
case self::NOTIFY_INVITATION_NO:
@ -195,21 +252,23 @@ class Notification extends Model
case self::NOTIFY_MESSAGE_AT_ONCE:
case self::NOTIFY_INVITATION_AT_ONCE:
case self::NOTIFY_GROUP_AT_ONCE:
$extra_headers = array();
$sender_info['complete_name'] = $this->admin_name;
$sender_info['email'] = $this->admin_email;
$extra_headers['reply_to']['name'] = $user_info['complete_name'];
$extra_headers['reply_to']['mail'] = $user_info['email'];
if (!empty($user_info['email'])) {
$extraHeaders = array(
'reply_to' => array(
'name' => $senderInfo['complete_name'],
'mail' => $senderInfo['email']
)
);
if (!empty($userInfo['email'])) {
api_mail_html(
$user_info['complete_name'],
$user_info['mail'],
Security::filter_terms($title),
$userInfo['complete_name'],
$userInfo['mail'],
Security::filter_terms($titleToNotification),
Security::filter_terms($content),
$sender_info['complete_name'],
$sender_info['email'],
$extra_headers
$this->adminName,
$this->adminEmail,
$extraHeaders
);
}
$sendDate = api_get_utc_datetime();
@ -219,10 +278,10 @@ class Notification extends Model
$params = array();
$params['sent_at'] = $sendDate;
$params['dest_user_id'] = $user_id;
$params['dest_mail'] = $user_info['email'];
$params['dest_mail'] = $userInfo['email'];
$params['title'] = $title;
$params['content'] = cut($content, $this->max_content_length);
$params['send_freq'] = $user_setting;
$params['send_freq'] = $userSetting;
$this->save($params);
}
}
@ -236,7 +295,7 @@ class Notification extends Model
* GroupPortalManager:get_group_data()
* @return string
* */
public function format_content($content, $sender_info)
public function formatContent($content, $sender_info)
{
$new_message_text = $link_to_new_message = '';

Loading…
Cancel
Save