From f0bf2da7e33a1a6097004fd3c272a807603fb5e5 Mon Sep 17 00:00:00 2001 From: rGaillard Date: Fri, 28 Sep 2012 13:08:48 +0000 Subject: [PATCH] // Fix #PSCFV-4468 --- classes/Cookie.php | 8 +++++--- classes/controller/AdminController.php | 4 ++-- classes/controller/Controller.php | 6 ++++++ classes/controller/FrontController.php | 18 +++++++++--------- controllers/admin/AdminCartsController.php | 2 +- controllers/admin/AdminModulesController.php | 2 +- controllers/front/OrderReturnController.php | 2 +- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/classes/Cookie.php b/classes/Cookie.php index 3f032f5f4..18f21c3fa 100644 --- a/classes/Cookie.php +++ b/classes/Cookie.php @@ -318,8 +318,7 @@ class CookieCore public function __destruct() { - if ($this->_modified) - $this->write(); + $this->write(); } /** @@ -327,6 +326,9 @@ class CookieCore */ public function write() { + if (!$this->_modified || headers_sent()) + return; + $cookie = ''; /* Serialize cookie content */ @@ -336,7 +338,7 @@ class CookieCore /* Add checksum to cookie */ $cookie .= 'checksum|'.crc32($this->_iv.$cookie); - + $this->_modified = false; /* Cookies are encrypted for evident security reasons */ return $this->_setcookie($cookie); } diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index faeb9290f..5814aeaf4 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -1160,10 +1160,10 @@ class AdminControllerCore extends Controller $this->context->smarty->assign('page', Tools::jsonEncode($page)); else $this->context->smarty->assign('page', $page); - - $this->context->smarty->display($this->layout); + $this->smartyOutputContent($this->layout); } + /** * add a warning message to display at the top of the page * diff --git a/classes/controller/Controller.php b/classes/controller/Controller.php index 17d420008..a33e7c20d 100644 --- a/classes/controller/Controller.php +++ b/classes/controller/Controller.php @@ -347,4 +347,10 @@ abstract class ControllerCore { return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); } + + protected function smartyOutputContent($content) + { + $this->context->cookie->write(); + $this->context->smarty->display($content); + } } diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index 3fb38dd26..b34fe517c 100755 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -497,7 +497,7 @@ class FrontControllerCore extends Controller $this->context->smarty->assign('js_files', array_unique($this->js_files)); $this->display_header = $display; - $this->context->smarty->display(_PS_THEME_DIR_.'header.tpl'); + $this->smartyOutputContent(_PS_THEME_DIR_.'header.tpl'); } @@ -508,7 +508,7 @@ class FrontControllerCore extends Controller { // This method will be removed in 1.6 Tools::displayAsDeprecated(); - $this->context->smarty->display(_PS_THEME_DIR_.'footer.tpl'); + $this->smartyOutputContent(_PS_THEME_DIR_.'footer.tpl'); } public function initCursedPage() @@ -572,28 +572,28 @@ class FrontControllerCore extends Controller ob_clean(); $this->context->smarty->assign('template', $template); } - $this->context->smarty->display($layout); + $this->smartyOutputContent($layout); } else { // BEGIN - 1.4 retrocompatibility - will be removed in 1.6 Tools::displayAsDeprecated('layout.tpl is missing in your theme directory'); if ($this->display_header) - $this->context->smarty->display(_PS_THEME_DIR_.'header.tpl'); + $this->smartyOutputContent(_PS_THEME_DIR_.'header.tpl'); if ($this->template) - $this->context->smarty->display($this->template); + $this->smartyOutputContent($this->template); else // For retrocompatibility with 1.4 controller $this->displayContent(); if ($this->display_footer) - $this->context->smarty->display(_PS_THEME_DIR_.'footer.tpl'); + $this->smartyOutputContent(_PS_THEME_DIR_.'footer.tpl'); // live edit if (Tools::isSubmit('live_edit') && ($ad = Tools::getValue('ad')) && Tools::getAdminToken('AdminModulesPositions'.(int)Tab::getIdFromClassName('AdminModulesPositions').(int)Tools::getValue('id_employee'))) { $this->context->smarty->assign(array('ad' => $ad, 'live_edit' => true)); - $this->context->smarty->display(_PS_ALL_THEMES_DIR_.'live_edit.tpl'); + $this->smartyOutputContent(_PS_ALL_THEMES_DIR_.'live_edit.tpl'); } // END - 1.4 retrocompatibility - will be removed in 1.6 } @@ -613,7 +613,7 @@ class FrontControllerCore extends Controller $this->context->smarty->assign('favicon_url', _PS_IMG_.Configuration::get('PS_FAVICON')); $template_dir = ($this->context->getMobileDevice() == true ? _PS_THEME_MOBILE_DIR_ : _PS_THEME_DIR_); - $this->context->smarty->display($template_dir.'maintenance.tpl'); + $this->smartyOutputContent($template_dir.'maintenance.tpl'); exit; } } @@ -624,7 +624,7 @@ class FrontControllerCore extends Controller { header('HTTP/1.1 503 temporarily overloaded'); $this->context->smarty->assign('favicon_url', _PS_IMG_.Configuration::get('PS_FAVICON')); - $this->context->smarty->display(_PS_THEME_DIR_.'restricted-country.tpl'); + $this->smartyOutputContent(_PS_THEME_DIR_.'restricted-country.tpl'); exit; } diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 22c0a9eca..bc4325f04 100755 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -295,7 +295,7 @@ class AdminCartsControllerCore extends AdminController $this->initFooter(); $this->context->smarty->assign(array('customization_errors' => implode('
', $errors), 'css_files' => $this->css_files)); - return $this->context->smarty->display('controllers/orders/form_customization_feedback.tpl'); + return $this->smartyOutputContent('controllers/orders/form_customization_feedback.tpl'); } } diff --git a/controllers/admin/AdminModulesController.php b/controllers/admin/AdminModulesController.php index bc824d5ff..7cc18254d 100644 --- a/controllers/admin/AdminModulesController.php +++ b/controllers/admin/AdminModulesController.php @@ -222,7 +222,7 @@ class AdminModulesControllerCore extends AdminController Configuration::updateValue('PS_SHOW_CAT_MODULES_'.(int)$this->id_employee, ''); $this->initContent(); - $this->context->smarty->display('controllers/modules/list.tpl'); + $this->smartyOutputContent('controllers/modules/list.tpl'); exit; } diff --git a/controllers/front/OrderReturnController.php b/controllers/front/OrderReturnController.php index 4335a68e1..cc6f6a5f0 100644 --- a/controllers/front/OrderReturnController.php +++ b/controllers/front/OrderReturnController.php @@ -89,7 +89,7 @@ class OrderReturnControllerCore extends FrontController public function displayAjax() { - $this->context->smarty->display($this->template); + $this->smartyOutputContent($this->template); } }