// fix bug AdminTranslationsController

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10456 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
lLefevre
2011-11-22 17:14:11 +00:00
parent cbea65eb66
commit a848e82ae9
2 changed files with 64 additions and 56 deletions
+3
View File
@@ -79,6 +79,8 @@ class AdminControllerCore extends Controller
public $tpl_option_vars = array(); public $tpl_option_vars = array();
public $tpl_view_vars = array(); public $tpl_view_vars = array();
public $base_tpl_view = null;
/** @var bool if you want more fieldsets in the form */ /** @var bool if you want more fieldsets in the form */
public $multiple_fieldsets = false; public $multiple_fieldsets = false;
@@ -1376,6 +1378,7 @@ class AdminControllerCore extends Controller
$helper = new HelperView($this); $helper = new HelperView($this);
$this->setHelperDisplay($helper); $this->setHelperDisplay($helper);
$helper->tpl_vars = $this->tpl_view_vars; $helper->tpl_vars = $this->tpl_view_vars;
!is_null($this->base_tpl_view) ? $helper->base_tpl = $this->base_tpl_view : '';
$view = $helper->generateView(); $view = $helper->generateView();
$this->toolbar_fix = false; $this->toolbar_fix = false;
@@ -113,7 +113,8 @@ class AdminTranslationsControllerCore extends AdminController
); );
$this->toolbar_fix = false; $this->toolbar_fix = false;
return parent::initView('main.tpl'); $this->base_tpl_view = 'main.tpl';
return parent::initView();
} }
/** /**
@@ -402,7 +403,7 @@ class AdminTranslationsControllerCore extends AdminController
} }
} }
} }
if (isset($_cache_file[($is_default ? self::DEFAULT_THEME_NAME : $theme_name).'-'.$file_name]) AND $str_write != "<?php\n\nglobal \$_MODULE;\n\$_MODULE = array();\n") if (isset($_cache_file[($is_default ? self::DEFAULT_THEME_NAME : $theme_name).'-'.$file_name]) && $str_write != "<?php\n\nglobal \$_MODULE;\n\$_MODULE = array();\n")
file_put_contents($file_name, $str_write); file_put_contents($file_name, $str_write);
} }
public function clearModuleFiles($files, $type_clear = 'file', $path = '') public function clearModuleFiles($files, $type_clear = 'file', $path = '')
@@ -411,9 +412,9 @@ class AdminTranslationsControllerCore extends AdminController
$arr_good_ext = array('.tpl', '.php'); $arr_good_ext = array('.tpl', '.php');
foreach ($files as $key => $file) foreach ($files as $key => $file)
{ {
if ($file{0} === '.' || in_array(substr($file, 0, strrpos($file,'.')), $this->all_iso_lang)) if ($file{0} === '.' || in_array(substr($file, 0, strrpos($file, '.')), $this->all_iso_lang))
unset($files[$key]); unset($files[$key]);
else if ($type_clear === 'file' && !in_array(substr($file, strrpos($file,'.')), $arr_good_ext)) else if ($type_clear === 'file' && !in_array(substr($file, strrpos($file, '.')), $arr_good_ext))
unset($files[$key]); unset($files[$key]);
else if ($type_clear === 'directory' && (!is_dir($path.$file) || in_array($file, $arr_exclude))) else if ($type_clear === 'directory' && (!is_dir($path.$file) || in_array($file, $arr_exclude)))
unset($files[$key]); unset($files[$key]);
@@ -465,7 +466,8 @@ class AdminTranslationsControllerCore extends AdminController
foreach ($matches[1] as $key) foreach ($matches[1] as $key)
{ {
$module_key = ($is_default ? self::DEFAULT_THEME_NAME : '').'<{'.Tools::strtolower($module_name).'}'.strtolower($is_default ? 'prestashop' : $theme_name).'>'.Tools::strtolower($template_name).'_'.md5($key); $module_key = ($is_default ? self::DEFAULT_THEME_NAME : '').'<{'.Tools::strtolower($module_name).'}'.
strtolower($is_default ? 'prestashop' : $theme_name).'>'.Tools::strtolower($template_name).'_'.md5($key);
// to avoid duplicate entry // to avoid duplicate entry
if (!in_array($module_key, $array_check_duplicate)) if (!in_array($module_key, $array_check_duplicate))
{ {
@@ -576,9 +578,7 @@ class AdminTranslationsControllerCore extends AdminController
else if (Tools::isSubmit('submitTranslationsMails') || Tools::isSubmit('submitTranslationsMailsAndStay')) else if (Tools::isSubmit('submitTranslationsMails') || Tools::isSubmit('submitTranslationsMailsAndStay'))
{ {
if ($this->tabAccess['edit'] === '1' && ($id_lang = Language::getIdByIso(Tools::getValue('lang'))) > 0) if ($this->tabAccess['edit'] === '1' && ($id_lang = Language::getIdByIso(Tools::getValue('lang'))) > 0)
{
$this->submitTranslationsMails($id_lang); $this->submitTranslationsMails($id_lang);
}
else else
$this->_errors[] = Tools::displayError('You do not have permission to edit here.'); $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
} }
@@ -608,7 +608,7 @@ class AdminTranslationsControllerCore extends AdminController
$arr_find_and_write = array_merge($arr_find_and_write, $arr_files); $arr_find_and_write = array_merge($arr_find_and_write, $arr_files);
} }
foreach ($arr_find_and_write as $key=>$value) foreach ($arr_find_and_write as $key => $value)
$this->findAndWriteTranslationsIntoFile($value['file_name'], $value['files'], $value['theme'], $value['module'], $value['dir']); $this->findAndWriteTranslationsIntoFile($value['file_name'], $value['files'], $value['theme'], $value['module'], $value['dir']);
Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token);
} }
@@ -640,36 +640,40 @@ class AdminTranslationsControllerCore extends AdminController
* *
* @param int $id_lang * @param int $id_lang
*/ */
protected function submitTranslationsMails ($id_lang) protected function submitTranslationsMails($id_lang)
{ {
$obj_lang = new Language($id_lang); $obj_lang = new Language($id_lang);
$params_redirect = (Tools::isSubmit('submitTranslationsMailsAndStay') ? '&lang='.Tools::getValue('lang').'&type='.Tools::getValue('type') : ''); $params_redirect = (Tools::isSubmit('submitTranslationsMailsAndStay') ? '&lang='.Tools::getValue('lang').'&type='.Tools::getValue('type') : '');
$arr_mail_content = array(); $arr_mail_content = array();
$arr_mail_path = array(); $arr_mail_path = array();
if (Tools::getValue('core_mail')) { if (Tools::getValue('core_mail'))
{
$arr_mail_content['core_mail'] = Tools::getValue('core_mail'); $arr_mail_content['core_mail'] = Tools::getValue('core_mail');
$arr_mail_path['core_mail'] = _PS_MAIL_DIR_.$obj_lang->iso_code.'/'; $arr_mail_path['core_mail'] = _PS_MAIL_DIR_.$obj_lang->iso_code.'/';
} }
if (Tools::getValue('module_mail')) { if (Tools::getValue('module_mail'))
{
$arr_mail_content['module_mail'] = Tools::getValue('module_mail'); $arr_mail_content['module_mail'] = Tools::getValue('module_mail');
$arr_mail_path['module_mail'] = _PS_MODULE_DIR_.'{module}'.'/mails/'.$obj_lang->iso_code.'/'; $arr_mail_path['module_mail'] = _PS_MODULE_DIR_.'{module}'.'/mails/'.$obj_lang->iso_code.'/';
} }
if (Tools::getValue('theme_mail')) { if (Tools::getValue('theme_mail'))
{
$arr_mail_content['theme_mail'] = Tools::getValue('theme_mail'); $arr_mail_content['theme_mail'] = Tools::getValue('theme_mail');
$arr_mail_path['theme_mail'] = _PS_THEME_DIR_.'mails/'.$obj_lang->iso_code.'/'; $arr_mail_path['theme_mail'] = _PS_THEME_DIR_.'mails/'.$obj_lang->iso_code.'/';
} }
if (Tools::getValue('theme_module_mail')) { if (Tools::getValue('theme_module_mail'))
{
$arr_mail_content['theme_module_mail'] = Tools::getValue('theme_module_mail'); $arr_mail_content['theme_module_mail'] = Tools::getValue('theme_module_mail');
$arr_mail_path['theme_module_mail'] = _PS_THEME_DIR_.'modules/{module}'.'/mails/'.$obj_lang->iso_code.'/'; $arr_mail_path['theme_module_mail'] = _PS_THEME_DIR_.'modules/{module}'.'/mails/'.$obj_lang->iso_code.'/';
} }
// Save each mail content // Save each mail content
foreach ($arr_mail_content as $group_name=>$all_content) foreach ($arr_mail_content as $group_name => $all_content)
{ {
foreach ($all_content as $type_content=>$mails) foreach ($all_content as $type_content => $mails)
{ {
foreach ($mails as $mail_name=>$content) foreach ($mails as $mail_name => $content)
{ {
$module_name = false; $module_name = false;
@@ -677,7 +681,7 @@ class AdminTranslationsControllerCore extends AdminController
if ($module_name_pipe_pos) if ($module_name_pipe_pos)
{ {
$module_name = substr($mail_name, 0, $module_name_pipe_pos); $module_name = substr($mail_name, 0, $module_name_pipe_pos);
$mail_name = substr($mail_name, $module_name_pipe_pos+1); $mail_name = substr($mail_name, $module_name_pipe_pos + 1);
} }
if ($type_content == 'html') if ($type_content == 'html')
@@ -689,9 +693,7 @@ class AdminTranslationsControllerCore extends AdminController
$title = ''; $title = '';
if (Tools::getValue('title_'.$group_name.'_'.$mail_name)) if (Tools::getValue('title_'.$group_name.'_'.$mail_name))
{
$title = Tools::getValue('title_'.$group_name.'_'.$mail_name); $title = Tools::getValue('title_'.$group_name.'_'.$mail_name);
}
$string_mail = $this->getMailPattern(); $string_mail = $this->getMailPattern();
$content = str_replace(array('#title', '#content'), array($title, $content), $string_mail); $content = str_replace(array('#title', '#content'), array($title, $content), $string_mail);
@@ -708,16 +710,14 @@ class AdminTranslationsControllerCore extends AdminController
chmod($path.$mail_name.'.'.$type_content, 0777); chmod($path.$mail_name.'.'.$type_content, 0777);
} }
else else
{
$this->_errors[] = Tools::displayError('HTML e-mail templates cannot contain JavaScript code.'); $this->_errors[] = Tools::displayError('HTML e-mail templates cannot contain JavaScript code.');
}
} }
} }
} }
// Update subjects // Update subjects
$array_subjects = array(); $array_subjects = array();
if ($subjects = Tools::getValue('subject') AND 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');
if (isset($arr_mail_path['theme_mail'])) if (isset($arr_mail_path['theme_mail']))
@@ -725,23 +725,21 @@ class AdminTranslationsControllerCore extends AdminController
foreach ($subjects as $group => $subject_translation) foreach ($subjects as $group => $subject_translation)
{ {
if ($group == 'core_mail' || $group == 'module_mail') { if ($group == 'core_mail' || $group == 'module_mail')
$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);
}
else if ( isset($array_subjects['themes_and_modules']) && ($group == 'theme_mail' || $group == 'theme_module_mail')) { else if ( isset($array_subjects['themes_and_modules']) && ($group == 'theme_mail' || $group == 'theme_module_mail')) {
$array_subjects['themes_and_modules']['translations'] = array_merge($array_subjects['themes_and_modules']['translations'], $subject_translation); $array_subjects['themes_and_modules']['translations'] = array_merge($array_subjects['themes_and_modules']['translations'], $subject_translation);
} }
} }
} }
if (!empty($array_subjects)) { if (!empty($array_subjects))
foreach ($array_subjects as $type=>$infos) { foreach ($array_subjects as $type => $infos)
$this->writeSubjectTranslationFile($infos['translations'], $infos['path']); $this->writeSubjectTranslationFile($infos['translations'], $infos['path']);
}
}
if (count($this->_errors) == 0) if (count($this->_errors) == 0)
Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token.$params_redirect); Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token.$params_redirect);
} }
/** include file $dir/$file and return the var $var declared in it. /** include file $dir/$file and return the var $var declared in it.
* This create the file if not exists * This create the file if not exists
* @param string $dir * @param string $dir
@@ -790,13 +788,13 @@ class AdminTranslationsControllerCore extends AdminController
public function displayAutoTranslate() public function displayAutoTranslate()
{ {
$languageCode = Tools::htmlentitiesUTF8(Language::getLanguageCodeByIso(Tools::getValue('lang'))); $language_code = Tools::htmlentitiesUTF8(Language::getLanguageCodeByIso(Tools::getValue('lang')));
return ' return '
<input type="button" class="button" onclick="translateAll();" value="'.$this->l('Translate with Google (experimental)').'" /> <input type="button" class="button" onclick="translateAll();" value="'.$this->l('Translate with Google (experimental)').'" />
<script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript"> <script type="text/javascript">
var gg_translate = { var gg_translate = {
language_code : \''.$languageCode.'\', language_code : \''.$language_code.'\',
not_available : \''.addslashes(html_entity_decode($this->l('this language is not available on Google Translate API'), ENT_QUOTES, 'utf-8')).'\', not_available : \''.addslashes(html_entity_decode($this->l('this language is not available on Google Translate API'), ENT_QUOTES, 'utf-8')).'\',
tooltip_title : \''.addslashes(html_entity_decode($this->l('Google translate suggests :'), ENT_QUOTES, 'utf-8')).'\' tooltip_title : \''.addslashes(html_entity_decode($this->l('Google translate suggests :'), ENT_QUOTES, 'utf-8')).'\'
}; };
@@ -846,10 +844,10 @@ class AdminTranslationsControllerCore extends AdminController
public function displayLimitPostWarning($count) public function displayLimitPostWarning($count)
{ {
$str_output = ''; $str_output = '';
if ((ini_get('suhosin.post.max_vars') AND ini_get('suhosin.post.max_vars') < $count) if ((ini_get('suhosin.post.max_vars') && ini_get('suhosin.post.max_vars') < $count)
OR (ini_get('suhosin.request.max_vars') AND ini_get('suhosin.request.max_vars') < $count)) || (ini_get('suhosin.request.max_vars') && ini_get('suhosin.request.max_vars') < $count))
{ {
if (ini_get('suhosin.post.max_vars') < $count OR ini_get('suhosin.request.max_vars') < $count) if (ini_get('suhosin.post.max_vars') < $count || ini_get('suhosin.request.max_vars') < $count)
{ {
$this->suhosin_limit_exceed = true; $this->suhosin_limit_exceed = true;
$str_output .= '<div class="warning">'.$this->l('Warning, your hosting provider is using the suhosin patch for PHP, which limits the maximum number of fields to post in a form:').'<br/>' $str_output .= '<div class="warning">'.$this->l('Warning, your hosting provider is using the suhosin patch for PHP, which limits the maximum number of fields to post in a form:').'<br/>'
@@ -873,10 +871,10 @@ class AdminTranslationsControllerCore extends AdminController
$count = 0; $count = 0;
$tabs_array = array(); $tabs_array = array();
foreach ($templates as $template) foreach ($templates as $template)
if (preg_match('/^(.*).tpl$/', $template) AND (file_exists($tpl = _PS_THEME_DIR_.$template) OR file_exists($tpl = _PS_ALL_THEMES_DIR_.$template))) if (preg_match('/^(.*).tpl$/', $template) && (file_exists($tpl = _PS_THEME_DIR_.$template) || file_exists($tpl = _PS_ALL_THEMES_DIR_.$template)))
{ {
$prefix_key = substr(basename($template), 0, -4); $prefix_key = substr(basename($template), 0, -4);
$newLang = array(); $new_lang = array();
$fd = fopen($tpl, 'r'); $fd = fopen($tpl, 'r');
$content = fread($fd, filesize($tpl)); $content = fread($fd, filesize($tpl));
@@ -890,17 +888,17 @@ class AdminTranslationsControllerCore extends AdminController
if (empty($key)) if (empty($key))
{ {
$this->_errors[] = $this->l('Empty string found, please edit:').' <br />'._PS_THEME_DIR_.''.$template; $this->_errors[] = $this->l('Empty string found, please edit:').' <br />'._PS_THEME_DIR_.''.$template;
$newLang[$key] = ''; $new_lang[$key] = '';
} }
else else
{ {
// Caution ! front has underscore between prefix key and md5, back has not // Caution ! front has underscore between prefix key and md5, back has not
if (isset($_LANG[$prefix_key.'_'.md5($key)])) if (isset($_LANG[$prefix_key.'_'.md5($key)]))
// @todo check if stripslashes is needed, it wasn't present in 1.4 // @todo check if stripslashes is needed, it wasn't present in 1.4
$newLang[$key] = stripslashes(html_entity_decode($_LANG[$prefix_key.'_'.md5($key)], ENT_COMPAT, 'UTF-8')); $new_lang[$key] = stripslashes(html_entity_decode($_LANG[$prefix_key.'_'.md5($key)], ENT_COMPAT, 'UTF-8'));
else else
{ {
$newLang[$key] = ''; $new_lang[$key] = '';
if (!isset($missing_translations[$prefix_key])) if (!isset($missing_translations[$prefix_key]))
$missing_translations[$prefix_key] = 1; $missing_translations[$prefix_key] = 1;
else else
@@ -908,8 +906,8 @@ class AdminTranslationsControllerCore extends AdminController
} }
} }
} }
$tabs_array[$prefix_key] = $newLang; $tabs_array[$prefix_key] = $new_lang;
$count += count($newLang); $count += count($new_lang);
} }
$this->tpl_view_vars = array( $this->tpl_view_vars = array(
@@ -928,7 +926,8 @@ class AdminTranslationsControllerCore extends AdminController
); );
$this->initToolbar(); $this->initToolbar();
return parent::initView('translation_form.tpl'); $this->base_tpl_view = 'translation_form.tpl';
return parent::initView();
} }
public function initFormBack($lang) public function initFormBack($lang)
@@ -1018,7 +1017,7 @@ class AdminTranslationsControllerCore extends AdminController
$prefix_key = 'AdminTab'; $prefix_key = 'AdminTab';
// and helpers in helper // and helpers in helper
$newLang = array(); $new_lang = array();
$fd = fopen($tpl, 'r'); $fd = fopen($tpl, 'r');
$content = fread($fd, filesize($tpl)); $content = fread($fd, filesize($tpl));
@@ -1032,7 +1031,7 @@ class AdminTranslationsControllerCore extends AdminController
if (empty($english_string)) if (empty($english_string))
{ {
$this->_errors[] = $this->l('Error in template - Empty string found, please edit:').' <br />'.$tpl; $this->_errors[] = $this->l('Error in template - Empty string found, please edit:').' <br />'.$tpl;
$newLang[$english_string] = ''; $new_lang[$english_string] = '';
} }
else else
{ {
@@ -1040,11 +1039,11 @@ class AdminTranslationsControllerCore extends AdminController
if (isset($_LANGADM[$trans_key])) if (isset($_LANGADM[$trans_key]))
{ {
$newLang[$english_string] = html_entity_decode($_LANGADM[$trans_key], ENT_COMPAT, 'UTF-8'); $new_lang[$english_string] = html_entity_decode($_LANGADM[$trans_key], ENT_COMPAT, 'UTF-8');
} }
else else
{ {
$newLang[$english_string] = ''; $new_lang[$english_string] = '';
if (!isset($missing_translations[$prefix_key])) if (!isset($missing_translations[$prefix_key]))
$missing_translations[$prefix_key] = 1; $missing_translations[$prefix_key] = 1;
else else
@@ -1052,11 +1051,11 @@ class AdminTranslationsControllerCore extends AdminController
} }
} }
} }
if ( isset($tabs_array[$prefix_key])) if (isset($tabs_array[$prefix_key]))
$tabs_array[$prefix_key] = array_merge($tabs_array[$prefix_key], $newLang); $tabs_array[$prefix_key] = array_merge($tabs_array[$prefix_key], $new_lang);
else else
$tabs_array[$prefix_key] = $newLang; $tabs_array[$prefix_key] = $new_lang;
$count += count($newLang); $count += count($new_lang);
} }
// with php then tpl files, order can be a mess // with php then tpl files, order can be a mess
asort($tabs_array); asort($tabs_array);
@@ -1077,7 +1076,8 @@ class AdminTranslationsControllerCore extends AdminController
); );
$this->initToolbar(); $this->initToolbar();
return parent::initView('translation_form.tpl'); $this->base_tpl_view = 'translation_form.tpl';
return parent::initView();
} }
public function initFormErrors($lang) public function initFormErrors($lang)
@@ -1132,7 +1132,8 @@ class AdminTranslationsControllerCore extends AdminController
); );
$this->initToolbar(); $this->initToolbar();
return parent::initView('translation_errors.tpl'); $this->base_tpl_view = 'translation_errors.tpl';
return parent::initView();
} }
public function initFormFields($lang) public function initFormFields($lang)
@@ -1196,7 +1197,8 @@ class AdminTranslationsControllerCore extends AdminController
); );
$this->initToolbar(); $this->initToolbar();
return parent::initView('translation_form.tpl'); $this->base_tpl_view = 'translation_form.tpl';
return parent::initView();
} }
/** /**
@@ -1545,7 +1547,8 @@ class AdminTranslationsControllerCore extends AdminController
); );
$this->initToolbar(); $this->initToolbar();
return parent::initView('translation_mails.tpl'); $this->base_tpl_view = 'translation_mails.tpl';
return parent::initView();
} }
protected static function getSubjectMail($directory, $subject_mail) protected static function getSubjectMail($directory, $subject_mail)
@@ -1731,7 +1734,8 @@ class AdminTranslationsControllerCore extends AdminController
); );
$this->initToolbar(); $this->initToolbar();
return parent::initView('translation_modules.tpl'); $this->base_tpl_view = 'translation_modules.tpl';
return parent::initView();
} }
} }
@@ -1830,7 +1834,8 @@ class AdminTranslationsControllerCore extends AdminController
); );
$this->initToolbar(); $this->initToolbar();
return parent::initView('translation_form.tpl'); $this->base_tpl_view = 'translation_form.tpl';
return parent::initView();
} }
/** /**