[-] BO : you can now have different mail topic for one mail template #PSCFV-9617

This commit is contained in:
Damien Metzger
2013-07-11 14:27:40 +02:00
parent d0e4e956c4
commit d772d97bfa
2 changed files with 51 additions and 46 deletions
@@ -937,7 +937,6 @@ class AdminTranslationsControllerCore extends AdminController
$this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad'] = html_entity_decode($GLOBALS[$name_var][$default_key], ENT_COMPAT, 'UTF-8'); $this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad'] = html_entity_decode($GLOBALS[$name_var][$default_key], ENT_COMPAT, 'UTF-8');
else else
{ {
//d(array($module_key, $default_key, $key, $GLOBALS[$name_var]));
$this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad'] = ''; $this->modules_translations[$theme_name][$module_name][$template_name][$key]['trad'] = '';
$this->missing_translations++; $this->missing_translations++;
} }
@@ -1471,12 +1470,10 @@ class AdminTranslationsControllerCore extends AdminController
$array_subjects = array(); $array_subjects = array();
if (($subjects = Tools::getValue('subject')) && is_array($subjects)) if (($subjects = Tools::getValue('subject')) && is_array($subjects))
{ {
$array_subjects['core_and_modules'] = array('translations'=>array(), 'path'=>$arr_mail_path['core_mail'].'lang.php'); $array_subjects['core_and_modules'] = array('translations' => array(), 'path' => $arr_mail_path['core_mail'].'lang.php');
foreach ($subjects as $subject_translation) foreach ($subjects as $subject_translation)
$array_subjects['core_and_modules']['translations'] = array_merge($array_subjects['core_and_modules']['translations'], $subject_translation); $array_subjects['core_and_modules']['translations'] = array_merge($array_subjects['core_and_modules']['translations'], $subject_translation);
} }
if (!empty($array_subjects)) if (!empty($array_subjects))
foreach ($array_subjects as $infos) foreach ($array_subjects as $infos)
$this->writeSubjectTranslationFile($infos['translations'], $infos['path']); $this->writeSubjectTranslationFile($infos['translations'], $infos['path']);
@@ -2149,32 +2146,37 @@ class AdminTranslationsControllerCore extends AdminController
<div name="mails_div" id="'.$id_html.'">'; <div name="mails_div" id="'.$id_html.'">';
if (!empty($mails['files'])) if (!empty($mails['files']))
{ {
$topic_already_displayed = array();
foreach ($mails['files'] as $mail_name => $mail_files) foreach ($mails['files'] as $mail_name => $mail_files)
{ {
if (array_key_exists('html', $mail_files) || array_key_exists('txt', $mail_files)) if (array_key_exists('html', $mail_files) || array_key_exists('txt', $mail_files))
{ {
if (array_key_exists($mail_name, $all_subject_mail)) if (array_key_exists($mail_name, $all_subject_mail))
{ {
$subject_mail = $all_subject_mail[$mail_name]; foreach ($all_subject_mail[$mail_name] as $subject_mail)
$value_subject_mail = isset($mails['subject'][$subject_mail]) ? $mails['subject'][$subject_mail] : ''; {
$str_return .= ' $subject_key = 'subject['.Tools::htmlentitiesUTF8($group_name).']['.Tools::htmlentitiesUTF8($subject_mail).']';
<div class="label-subject" style="text-align:center;"> if (in_array($subject_key, $topic_already_displayed))
<label style="text-align:right">'.sprintf($this->l('Subject for %s:'), '<em>'.$mail_name.'</em>').'</label> continue;
<div class="mail-form" style="text-align:left"> $topic_already_displayed[] = $subject_key;
<b>'.$subject_mail.'</b><br />'; $value_subject_mail = isset($mails['subject'][$subject_mail]) ? $mails['subject'][$subject_mail] : '';
if (isset($value_subject_mail['trad']) && $value_subject_mail['trad']) $str_return .= '
$str_return .= '<input type="text" name="subject['.$group_name.']['.$subject_mail.']" value="'.$value_subject_mail['trad'].'" />'; <div class="label-subject" style="text-align:center;">
else <label style="text-align:right">'.sprintf($this->l('Subject for %s:'), '<em>'.$mail_name.'</em>').'</label>
$str_return .= '<input type="text" name="subject['.$group_name.']['.$subject_mail.']" value="" />'; <div class="mail-form" style="text-align:left">
<b>'.$subject_mail.'</b><br />';
if (isset($value_subject_mail['trad']) && $value_subject_mail['trad'])
$str_return .= '<input type="text" name="subject['.Tools::htmlentitiesUTF8($group_name).']['.Tools::htmlentitiesUTF8($subject_mail).']" value="'.$value_subject_mail['trad'].'" />';
else
$str_return .= '<input type="text" name="subject['.Tools::htmlentitiesUTF8($group_name).']['.Tools::htmlentitiesUTF8($subject_mail).']" value="" />';
if (isset($value_subject_mail['use_sprintf']) && $value_subject_mail['use_sprintf']) if (isset($value_subject_mail['use_sprintf']) && $value_subject_mail['use_sprintf'])
{ $str_return .= '<a class="useSpecialSyntax" title="'.$this->l('This expression uses a special syntax:').' '.$value_subject_mail['use_sprintf'].'" style="cursor:pointer">
$str_return .= '<a class="useSpecialSyntax" title="'.$this->l('This expression uses a special syntax:').' '.$value_subject_mail['use_sprintf'].'" style="cursor:pointer"> <img src="'._PS_IMG_.'admin/error.png" alt="'.$value_subject_mail['use_sprintf'].'" />
<img src="'._PS_IMG_.'admin/error.png" alt="'.$value_subject_mail['use_sprintf'].'" /> </a>';
</a>';
}
$str_return .= '</div> $str_return .= '</div>
</div>'; </div>';
}
} }
else else
{ {
@@ -2196,12 +2198,11 @@ class AdminTranslationsControllerCore extends AdminController
} }
} }
else else
{ $str_return .= '<p class="error">
$str_return .= ' '.$this->l('There was a problem getting the mail files.').'<br />
<p class="error">'.$this->l('There was a problem getting the mail files.').'<br />' '.sprintf($this->l('English language files must exist in %s folder'), '<em>'.preg_replace('@/[a-z]{2}(/?)$@', '/en$1', $mails['directory']).'</em>').'
.sprintf($this->l('English language files must exist in %s folder'), '<em>'.$mails['directory'].'en</em>') </p>';
.'</p>';
}
$str_return .= ' $str_return .= '
</div><!-- #'.$id_html.' --> </div><!-- #'.$id_html.' -->
<div class="clear"></div> <div class="clear"></div>
@@ -2412,21 +2413,27 @@ class AdminTranslationsControllerCore extends AdminController
$content = file_get_contents($dir.'/'.$file); $content = file_get_contents($dir.'/'.$file);
$content = str_replace("\n", ' ', $content); $content = str_replace("\n", ' ', $content);
// Subject must match with a template, therefor we first grep the Mail::Send() function then the Mail::l() inside.
if (preg_match_all('/Mail::Send([^;]*);/si', $content, $tab)) if (preg_match_all('/Mail::Send([^;]*);/si', $content, $tab))
for ($i = 0; isset($tab[1][$i]); $i++) for ($i = 0; isset($tab[1][$i]); $i++)
{ {
$tab2 = explode(',', $tab[1][$i]); $tab2 = explode(',', $tab[1][$i]);
if (is_array($tab2)) if (is_array($tab2) && isset($tab2[1]))
if ($tab2 && isset($tab2[1])) {
{ $template = trim(str_replace('\'', '', $tab2[1]));
$tab2[1] = trim(str_replace('\'', '', $tab2[1])); foreach ($tab2 as $tab3)
if (preg_match('/Mail::l\(\''._PS_TRANS_PATTERN_.'\'/s', $tab2[2], $matches)) if (preg_match('/Mail::l\(\''._PS_TRANS_PATTERN_.'\'\)/Us', $tab3.')', $matches))
$subject_mail[$tab2[1]] = $matches[1]; {
} if (!isset($subject_mail[$template]))
$subject_mail[$template] = array();
if (!in_array($matches[1], $subject_mail[$template]))
$subject_mail[$template][] = $matches[1];
}
}
} }
if (!in_array($file, self::$ignore_folder) && is_dir($dir.'/'.$file)) if (!in_array($file, self::$ignore_folder) && is_dir($dir.'/'.$file))
$subject_mail = $this->getSubjectMail($dir, $file, $subject_mail); $subject_mail = $this->getSubjectMail($dir, $file, $subject_mail);
return $subject_mail; return $subject_mail;
} }
+8 -10
View File
@@ -180,14 +180,8 @@ class ContactControllerCore extends FrontController
$id_product = (int)Tools::getValue('id_product'); $id_product = (int)Tools::getValue('id_product');
if (isset($ct) && Validate::isLoadedObject($ct)) if (isset($ct) && Validate::isLoadedObject($ct) && $ct->id_order)
{ $id_order = $ct->id_order;
if ($ct->id_order)
$id_order = $ct->id_order;
$subject = sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token);
}
else
$subject = Mail::l('Your message has been correctly sent');
if ($id_order) if ($id_order)
{ {
@@ -203,14 +197,18 @@ class ContactControllerCore extends FrontController
$var_list['{product_name}'] = $product->name[Context::getContext()->language->id]; $var_list['{product_name}'] = $product->name[Context::getContext()->language->id];
} }
if (empty($contact->email)) if (empty($contact->email))
Mail::Send($this->context->language->id, 'contact_form', $subject, $var_list, $from, null, null, null, $fileAttachment); Mail::Send($this->context->language->id, 'contact_form', ((isset($ct) && Validate::isLoadedObject($ct)) ? sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token) : Mail::l('Your message has been correctly sent')), $var_list, $from, null, null, null, $fileAttachment);
else else
{ {
if (!Mail::Send($this->context->language->id, 'contact', Mail::l('Message from contact form').' [no_sync]', if (!Mail::Send($this->context->language->id, 'contact', Mail::l('Message from contact form').' [no_sync]',
$var_list, $contact->email, $contact->name, $from, ($customer->id ? $customer->firstname.' '.$customer->lastname : ''), $var_list, $contact->email, $contact->name, $from, ($customer->id ? $customer->firstname.' '.$customer->lastname : ''),
$fileAttachment) || $fileAttachment) ||
!Mail::Send($this->context->language->id, 'contact_form', $subject, $var_list, $from, null, $contact->email, $contact->name, $fileAttachment)) !Mail::Send($this->context->language->id, 'contact_form', ((isset($ct) && Validate::isLoadedObject($ct)) ? sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token) : Mail::l('Your message has been correctly sent')), $var_list, $from, null, $contact->email, $contact->name, $fileAttachment))
$this->errors[] = Tools::displayError('An error occurred while sending the message.'); $this->errors[] = Tools::displayError('An error occurred while sending the message.');
} }
} }