[-] BO : fixed bug in contact message with html

This commit is contained in:
vAugagneur
2012-02-28 11:05:21 +00:00
parent 46eb7645df
commit e061e9a49c
7 changed files with 140 additions and 43 deletions
@@ -48,7 +48,7 @@
<div class="infoCustomer">
{if !empty($message.id_customer) && empty($message.id_employee)}
<dl>
<dt>{l s='Customer ID:'}&#32;:</dd>
<dt>{l s='Customer ID:'}</dd>
<dd><a href="index.php?tab=AdminCustomers&id_customer={$message.id_customer}&viewcustomer&token={getAdminToken tab='AdminCustomers'}" title="{l s='View customer'}">
{$message.id_customer} <img src="../img/admin/search.gif" alt="{l s='view'}" />
</a>
@@ -57,21 +57,21 @@
{/if}
<dl>
<dt>{l s='Sent on:'}&#32;:</dt>
<dt>{l s='Sent on:'}</dt>
<dd>{$message.date_add}</dd>
</dl>
{if empty($message.id_employee)}
<dl>
<dt>{l s='Browser:'}&#32;:</dt>
<dt>{l s='Browser:'}</dt>
<dd>{$message.user_agent}</dd>
</dl>
{/if}
{if !empty($message.file_name) && $file_name}
<dl>
<dt>{l s='File attachment'}&#32;:</dt>
<dt>{l s='File attachment'}</dt>
<dd><a href="index.php?tab=AdminCustomerThreads&id_customer_thread={$message.id_customer_thread}&viewcustomer_thread&token={getAdminToken tab='AdminCustomerThreads'}&filename={$message.file_name}"
title="{l s='View file'}">
<img src="../img/admin/search.gif" alt="{l s='view'}" />
@@ -82,7 +82,7 @@
{if !empty($message.id_order) && empty($message.id_employee)}
<dl>
<dt>{l s='Order #'}&#32;:</dt>
<dt>{l s='Order #'}</dt>
<dd><a href="index.php?tab=AdminOrders&id_order={$message.id_order}&vieworder&token={getAdminToken tab='AdminOrders'}" title="{l s='View order'}">
{$message.id_order} <img src="../img/admin/search.gif" alt="{l s='view'}" />
</a></dd>
@@ -91,7 +91,7 @@
{if !empty($message.id_product) && empty($message.id_employee)}
<dl>
<dt>{l s='Product #'}&#32;:</dt>
<dt>{l s='Product #'}</dt>
<dd><a href="index.php?tab=AdminOrders&id_order={$id_order_product}&vieworder&token={getAdminToken tab='AdminOrders'}" title="{l s='View order'}">
{$message.id_product} <img src="../img/admin/search.gif" alt="{l s='view'}" />
</a></dd>
@@ -143,16 +143,16 @@
{/if}
<dl>
<dt>{l s='Thread ID:'}&#32;:</dt>
<dt>{l s='Thread ID:'}</dt>
<dd>{$message.id_customer_thread}</dd>
</dl>
<dl>
<dt>{l s='Message ID:'}&#32;:</dt>
<dt>{l s='Message ID:'}</dt>
<dd>{$message.id_customer_message}</dd>
</dl>
<dl>
<dt>{l s='Message:'}&#32;:</dt>
<dd>{$message.message}</dd>
<dt>{l s='Message:'}</dt>
<dd>{$message.message|nl2br}</dd>
</dl>
</div>
+18 -12
View File
@@ -32,19 +32,25 @@ include_once(_PS_SWIFT_DIR_.'Swift/Plugin/Decorator.php');
class MailCore
{
const TYPE_HTML = 1;
const TYPE_TEXT = 2;
const TYPE_BOTH = 3;
public static function Send($id_lang, $template, $subject, $templateVars, $to,
$toName = null, $from = null, $fromName = null, $fileAttachment = null, $modeSMTP = null, $templatePath = _PS_MAIL_DIR_, $die = false)
{
$configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL',
'PS_MAIL_METHOD',
'PS_MAIL_SERVER',
'PS_MAIL_USER',
'PS_MAIL_PASSWD',
'PS_SHOP_NAME',
'PS_MAIL_SMTP_ENCRYPTION',
'PS_MAIL_SMTP_PORT',
'PS_MAIL_METHOD',
'PS_MAIL_TYPE'));
$configuration = Configuration::getMultiple(array(
'PS_SHOP_EMAIL',
'PS_MAIL_METHOD',
'PS_MAIL_SERVER',
'PS_MAIL_USER',
'PS_MAIL_PASSWD',
'PS_SHOP_NAME',
'PS_MAIL_SMTP_ENCRYPTION',
'PS_MAIL_SMTP_PORT',
'PS_MAIL_METHOD',
'PS_MAIL_TYPE'
));
if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) $configuration['PS_MAIL_SMTP_ENCRYPTION'] = 'off';
if (!isset($configuration['PS_MAIL_SMTP_PORT'])) $configuration['PS_MAIL_SMTP_PORT'] = 'default';
@@ -192,9 +198,9 @@ class MailCore
$templateVars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME'));
$templateVars['{shop_url}'] = Tools::getShopDomain(true, true).__PS_BASE_URI__;
$swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');
if ($configuration['PS_MAIL_TYPE'] == 3 || $configuration['PS_MAIL_TYPE'] == 2)
if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT)
$message->attach(new Swift_Message_Part($templateTxt, 'text/plain', '8bit', 'utf-8'));
if ($configuration['PS_MAIL_TYPE'] == 3 || $configuration['PS_MAIL_TYPE'] == 1)
if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML)
$message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
if ($fileAttachment && isset($fileAttachment['content']) && isset($fileAttachment['name']) && isset($fileAttachment['mime']))
$message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
@@ -319,7 +319,7 @@ class AdminCustomerThreadsControllerCore extends AdminController
if ($id_employee && $employee && Validate::isLoadedObject($employee))
{
$params = array(
'{messages}' => $output,
'{messages}' => Tools::nl2br(stripslashes($output)),
'{employee}' => $current_employee->firstname.' '.$current_employee->lastname,
'{comment}' => stripslashes($_POST['message_forward']));
@@ -341,7 +341,7 @@ class AdminCustomerThreadsControllerCore extends AdminController
else if ($email && Validate::isEmail($email))
{
$params = array(
'{messages}' => $output,
'{messages}' => Tools::nl2br(stripslashes($output)),
'{employee}' => $current_employee->firstname.' '.$current_employee->lastname,
'{comment}' => stripslashes($_POST['message_forward']));
+100 -10
View File
@@ -42,9 +42,36 @@ class AdminEmailsControllerCore extends AdminController
'title' => $this->l('E-mail'),
'icon' => 'email',
'fields' => array(
'PS_MAIL_EMAIL_MESSAGE' => array('title' => $this->l('Send e-mail to:'), 'desc' => $this->l('When customers send message from order page'), 'validation' => 'isUnsignedId', 'type' => 'select', 'cast' => 'intval', 'identifier' => 'email_message', 'list' => $arr),
'PS_MAIL_METHOD' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(1 => $this->l('Use PHP mail() function. Recommended; works in most cases'), 2 => $this->l('Set my own SMTP parameters. For advanced users ONLY')), 'js' => array(1 => 'onclick="$(\'#smtp\').slideUp();"', 2 => 'onclick="$(\'#smtp\').slideDown();"'), 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(1 => $this->l('Send e-mail as HTML'), 2 => $this->l('Send e-mail as Text'), 3 => $this->l('Both'))),
'PS_MAIL_EMAIL_MESSAGE' => array(
'title' => $this->l('Send e-mail to:'),
'desc' => $this->l('When customers send message from order page'),
'validation' => 'isUnsignedId',
'type' => 'select',
'cast' => 'intval',
'identifier' => 'email_message',
'list' => $arr
),
'PS_MAIL_METHOD' => array(
'title' => '',
'validation' => 'isGenericName',
'type' => 'radio',
'required' => true,
'choices' => array(
1 => $this->l('Use PHP mail() function. Recommended; works in most cases'),
2 => $this->l('Set my own SMTP parameters. For advanced users ONLY')
),
'js' => array(
1 => 'onclick="$(\'#smtp\').slideUp();"',
2 => 'onclick="$(\'#smtp\').slideDown();"'
),
'visibility' => Shop::CONTEXT_ALL
),
'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(
Mail::TYPE_HTML => $this->l('Send e-mail as HTML'),
Mail::TYPE_TEXT => $this->l('Send e-mail as Text'),
Mail::TYPE_BOTH => $this->l('Both')
)
),
),
'submit' => array()
),
@@ -54,12 +81,70 @@ class AdminEmailsControllerCore extends AdminController
'top' => '<div id="smtp" style="display: '.((Configuration::get('PS_MAIL_METHOD') == 2) ? 'block' : 'none').';">',
'bottom' => '</div>',
'fields' => array(
'PS_MAIL_DOMAIN' => array('title' => $this->l('Mail domain:'), 'desc' => $this->l('Fully qualified domain name (keep it empty if you do not know)'), 'empty' => true, 'validation' => 'isUrl', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_SERVER' => array('title' => $this->l('SMTP server:'), 'desc' => $this->l('IP or server name (e.g., smtp.mydomain.com)'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_USER' => array('title' => $this->l('SMTP user:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_PASSWD' => array('title' => $this->l('SMTP password:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isAnything', 'size' => 30, 'type' => 'password', 'visibility' => Shop::CONTEXT_ALL, 'autocomplete' => false),
'PS_MAIL_SMTP_ENCRYPTION' => array('title' => $this->l('Encryption:'), 'desc' => $this->l('Use an encrypt protocol'), 'type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => array(array('mode' => 'off', 'name' => $this->l('None')), array('mode' => 'tls', 'name' => $this->l('TLS')), array('mode' => 'ssl', 'name' => $this->l('SSL'))), 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_SMTP_PORT' => array('title' => $this->l('Port:'), 'desc' => $this->l('Number of port to use'), 'validation' => 'isInt', 'size' => 5, 'type' => 'text', 'cast' => 'intval', 'visibility' => Shop::CONTEXT_ALL),
'PS_MAIL_DOMAIN' => array(
'title' => $this->l('Mail domain:'),
'desc' => $this->l('Fully qualified domain name (keep it empty if you do not know)'),
'empty' => true, 'validation' =>
'isUrl', 'size' => 30,
'type' => 'text',
'visibility' => Shop::CONTEXT_ALL
),
'PS_MAIL_SERVER' => array(
'title' => $this->l('SMTP server:'),
'desc' => $this->l('IP or server name (e.g., smtp.mydomain.com)'),
'validation' => 'isGenericName',
'size' => 30,
'type' => 'text',
'visibility' => Shop::CONTEXT_ALL
),
'PS_MAIL_USER' => array(
'title' => $this->l('SMTP user:'),
'desc' => $this->l('Leave blank if not applicable'),
'validation' => 'isGenericName',
'size' => 30,
'type' => 'text',
'visibility' => Shop::CONTEXT_ALL
),
'PS_MAIL_PASSWD' => array(
'title' => $this->l('SMTP password:'),
'desc' => $this->l('Leave blank if not applicable'),
'validation' => 'isAnything',
'size' => 30,
'type' => 'password',
'visibility' => Shop::CONTEXT_ALL,
'autocomplete' => false
),
'PS_MAIL_SMTP_ENCRYPTION' => array(
'title' => $this->l('Encryption:'),
'desc' => $this->l('Use an encrypt protocol'),
'type' => 'select',
'cast' => 'strval',
'identifier' => 'mode',
'list' => array(
array(
'mode' => 'off',
'name' => $this->l('None')
),
array(
'mode' => 'tls',
'name' => $this->l('TLS')
),
array(
'mode' => 'ssl',
'name' => $this->l('SSL')
)
),
'visibility' => Shop::CONTEXT_ALL
),
'PS_MAIL_SMTP_PORT' => array(
'title' => $this->l('Port:'),
'desc' => $this->l('Number of port to use'),
'validation' => 'isInt',
'size' => 5,
'type' => 'text',
'cast' => 'intval',
'visibility' => Shop::CONTEXT_ALL
),
),
'submit' => array()
),
@@ -67,7 +152,12 @@ class AdminEmailsControllerCore extends AdminController
'title' => $this->l('Test your e-mail configuration'),
'icon' => 'email',
'fields' => array(
'PS_SHOP_EMAIL' => array('title' => $this->l('Send a test e-mail to'), 'type' => 'text', 'size' => 40, 'id' => 'testEmail'),
'PS_SHOP_EMAIL' => array(
'title' => $this->l('Send a test e-mail to'),
'type' => 'text',
'size' => 40,
'id' => 'testEmail'
),
),
'bottom' => '<div class="margin-form"><input type="button" class="button" name="btEmailTest" id="btEmailTest" value="'.$this->l('Send an e-mail test').'" onclick="verifyMail();" /><br />
<p id="mailResultCheck" style="display:none;"></p></div>',
+1 -1
View File
@@ -345,7 +345,7 @@ class AdminOrdersControllerCore extends AdminController
else
{
$message = $customer_message->message;
if (Configuration::get('PS_MAIL_TYPE') != 2)
if (Configuration::get('PS_MAIL_TYPE') != Mail::TYPE_TEXT)
$message = Tools::nl2br($customer_message->message);
$varsTpl = array(
+2 -2
View File
@@ -50,7 +50,7 @@ class ContactControllerCore extends FrontController
$message = Tools::htmlentitiesUTF8(Tools::getValue('message'));
if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from))
$this->errors[] = Tools::displayError('Invalid e-mail address');
else if (!($message = Tools::nl2br($message)))
else if (!$message)
$this->errors[] = Tools::displayError('Message cannot be blank');
else if (!Validate::isCleanHtml($message))
$this->errors[] = Tools::displayError('Invalid message');
@@ -119,7 +119,7 @@ class ContactControllerCore extends FrontController
{
$mail_var_list = array(
'{email}' => $from,
'{message}' => stripslashes($message),
'{message}' => Tools::nl2br(stripslashes($message)),
'{id_order}' => (int)Tools::getValue('id_order'),
'{attached_file}' => $_FILES['fileUpload']['name'] ? $_FILES['fileUpload']['name'] : '');
+7 -6
View File
@@ -86,7 +86,7 @@ class OrderDetailControllerCore extends FrontController
else
$ct = new CustomerThread((int)$id_customer_thread);
$cm->id_customer_thread = $ct->id;
$cm->message = Tools::htmlentitiesutf8(Tools::nl2br($msgText));
$cm->message = Tools::htmlentitiesutf8($msgText);
$cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']);
$cm->add();
@@ -103,11 +103,12 @@ class OrderDetailControllerCore extends FrontController
if (Validate::isLoadedObject($customer))
Mail::Send($this->context->language->id, 'order_customer_comment', Mail::l('Message from a customer'),
array(
'{lastname}' => $customer->lastname,
'{firstname}' => $customer->firstname,
'{email}' => $customer->email,
'{id_order}' => (int)($order->id),
'{message}' => $msgText),
'{lastname}' => $customer->lastname,
'{firstname}' => $customer->firstname,
'{email}' => $customer->email,
'{id_order}' => (int)($order->id),
'{message}' => Tools::nl2br($msgText)
),
$to, $toName, $customer->email, $customer->firstname.' '.$customer->lastname);
if (Tools::getValue('ajax') != 'true')