diff --git a/.gitignore b/.gitignore index a5ef5550..6094400c 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,8 @@ cache/tcpdf/* !cache/tcpdf/index.php tools/smarty*/cache/*.php !tools/smarty*/cache/index.php +modules/privatesales/cache/* +!modules/privatesales/cache/index.php #### CONFIG #### config/settings.*.php diff --git a/modules/privatesales/cache/index.php b/modules/privatesales/cache/index.php new file mode 100644 index 00000000..e582afcc --- /dev/null +++ b/modules/privatesales/cache/index.php @@ -0,0 +1,36 @@ + +* @copyright 2007-2013 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; \ No newline at end of file diff --git a/modules/privatesales/controllers/front/home.php b/modules/privatesales/controllers/front/home.php index ad2dc9f1..8ce88b79 100644 --- a/modules/privatesales/controllers/front/home.php +++ b/modules/privatesales/controllers/front/home.php @@ -11,7 +11,7 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController { * */ public function init(){ - + if(Configuration::get('PRIVATESALES_COLUMN') == 0){ $this->display_column_left = false; $this->display_column_right = false; @@ -34,21 +34,32 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController { * */ public function initContent(){ - if(!$this->context->cookie->logged && !Configuration::get('PRIVATESALES_LISTING_PUBLIC')){ Tools::redirect($this->context->link->getPageLink('authentication',null,$this->context->cookie->id_lang,'ps=0&back='.$this->context->link->getModuleLink('privatesales', 'home'))); } - - parent::initContent(); - - $categories = SaleCategory::getCategory(); + $news = null; if(Tools::getValue('type') == "nouveautes"){ $news = 1; }else if(Tools::getValue('type') == "ventes"){ $news = 2; } + + parent::initContent(); + $this->setTemplate('privatesales-home.tpl'); + + // 12613 - Optimisation + $sale_cache = new SaleCache($this->context->smarty, ($news ? "home_".$news : 'home')); + if ($sale_cache->isCached($this->template)) { + $this->setCacheHtml($sale_cache->getCache()); + return; + } + // 12613 - End optimisation + + + $categories = SaleCategory::getCategory(); + if(Configuration::get('PRIVATESALES_FLASH')) $flashsales = SaleCore::getSales("current",0,TRUE,FALSE,TRUE,'position','ASC',FALSE,TRUE); else @@ -156,8 +167,8 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController { 'banner_concour_title_2' => Configuration::get('PRIVATESALES_BANNER_TITLE_CONCOURS_2'), 'banner_concour_link_active' => Configuration::get('PRIVATESALES_BANNER_LINK_CONCOURS_ACTIVE'), )); - - - $this->setTemplate('privatesales-home.tpl'); } + + + } \ No newline at end of file diff --git a/modules/privatesales/controllers/front/homecat.php b/modules/privatesales/controllers/front/homecat.php index 145e829c..3386195f 100644 --- a/modules/privatesales/controllers/front/homecat.php +++ b/modules/privatesales/controllers/front/homecat.php @@ -34,7 +34,7 @@ class privatesaleshomecatModuleFrontController extends ModuleFrontController { * */ public function initContent(){ - + $ajax = Tools::getValue('ajax'); if($ajax){ echo $this->ajaxProcessSubmitAlert(); @@ -59,7 +59,16 @@ class privatesaleshomecatModuleFrontController extends ModuleFrontController { } } - + $this->setTemplate('privatesales-home.tpl'); + + // 12613 - Optimisation + $sale_cache = new SaleCache($this->context->smarty, 'homecat'); + if ($sale_cache->isCached($this->template)) { + $this->setCacheHtml($sale_cache->getCache()); + return; + } + // 12613 - End optimisation + if(Configuration::get('PRIVATESALES_FLASH')) $flashsales = SaleCore::getSales("current",0,TRUE,FALSE,TRUE,'position','ASC',$id_category,TRUE); else @@ -108,7 +117,6 @@ class privatesaleshomecatModuleFrontController extends ModuleFrontController { 'link_img' => __PS_BASE_URI__.'modules/privatesales/img/', 'link_mod_img' => _PS_MODULE_DIR_.'modules/privatesales/img/' )); - $this->setTemplate('privatesales-home.tpl'); } public function ajaxProcessSubmitAlert(){ diff --git a/modules/privatesales/models/SaleCache.php b/modules/privatesales/models/SaleCache.php new file mode 100644 index 00000000..5dfa2386 --- /dev/null +++ b/modules/privatesales/models/SaleCache.php @@ -0,0 +1,51 @@ +cache_id = md5("private_sales_".$cache_prefix."_".$d->format('Ymd')); + $this->max_filemtime = $d->getTimestamp() - $lifetime; + $this->path_cache_file = __DIR__.'/../cache/'.$this->cache_id; + $this->smarty = $smarty; + } + + function __destruct() + { + if (!empty($this->template_path && $this->smarty)) { + file_put_contents($this->path_cache_file, $this->smarty->fetch($this->template_path)); + } + } + + function isCached($template_path) + { + if (file_exists($this->path_cache_file) && filemtime($this->path_cache_file) > $this->max_filemtime) { + return true; + } + + $this->template_path = $template_path; + return false; + } + + function getCache() + { + return file_get_contents($this->path_cache_file); + } + + static function clearAll() + { + foreach(glob(__DIR__.'/../cache/*') as $path_file) { + @unlink($path_file); + } + } +} \ No newline at end of file diff --git a/modules/privatesales/models/SaleCore.php b/modules/privatesales/models/SaleCore.php index 49f96233..3db7c9a7 100644 --- a/modules/privatesales/models/SaleCore.php +++ b/modules/privatesales/models/SaleCore.php @@ -268,6 +268,10 @@ class SaleCore extends ObjectModel{ $hist->add(); } + if ($update) { + SaleCache::clearAll(); + } + return $update; } /** @@ -909,8 +913,13 @@ class SaleCore extends ObjectModel{ AND `id_privatesales` = '.(int)$moved_privatesales['id_privatesales']; - return (Db::getInstance()->execute($sql) + $result = (Db::getInstance()->execute($sql) && Db::getInstance()->execute($sql2)); + + if ($result) { + SaleCache::clearAll(); + } + return $result; } diff --git a/modules/privatesales/privatesales.php b/modules/privatesales/privatesales.php index 99458037..4d91e38b 100644 --- a/modules/privatesales/privatesales.php +++ b/modules/privatesales/privatesales.php @@ -10,6 +10,7 @@ include_once(_PS_MODULE_DIR_.'privatesales/models/SaleAlertMail.php'); include_once(_PS_MODULE_DIR_.'privatesales/models/SaleAlertMailCat.php'); include_once(_PS_MODULE_DIR_.'privatesales/models/SaleCategory.php'); include_once(_PS_MODULE_DIR_.'privatesales/models/SaleHistorique.php'); +include_once(_PS_MODULE_DIR_.'privatesales/models/SaleCache.php'); class Privatesales extends Module { diff --git a/override/classes/controller/FrontController.php b/override/classes/controller/FrontController.php index ac36c7e8..8fcaf709 100644 --- a/override/classes/controller/FrontController.php +++ b/override/classes/controller/FrontController.php @@ -26,6 +26,8 @@ class FrontController extends FrontControllerCore { + private $_cache_html = null; + public $real_page_name = ''; public function setMedia() @@ -175,5 +177,73 @@ class FrontController extends FrontControllerCore $this->context->smarty->assign('link_conditions', $link_conditions); } + + + public function display() + { + Tools::safePostVars(); + + // assign css_files and js_files at the very last time + if ((Configuration::get('PS_CSS_THEME_CACHE') || Configuration::get('PS_JS_THEME_CACHE')) && is_writable(_PS_THEME_DIR_.'cache')) + { + // CSS compressor management + if (Configuration::get('PS_CSS_THEME_CACHE')) + $this->css_files = Media::cccCSS($this->css_files); + //JS compressor management + if (Configuration::get('PS_JS_THEME_CACHE') && !$this->useMobileTheme()) + $this->js_files = Media::cccJs($this->js_files); + } + + $this->context->smarty->assign(array( + 'css_files' => $this->css_files, + 'js_files' => ($this->getLayout() && (bool)Configuration::get('PS_JS_DEFER')) ? array() : $this->js_files, + 'js_defer' => (bool)Configuration::get('PS_JS_DEFER'), + 'errors' => $this->errors, + 'display_header' => $this->display_header, + 'display_footer' => $this->display_footer, + )); + $layout = $this->getLayout(); + if ($layout) + { + // 12613 - Optimisation + if ($this->_cache_html!==null) { + $template = $this->_cache_html; + } + // 12613 - End optimisation + else if ($this->template){ + $template = $this->context->smarty->fetch($this->template); + } + else // For retrocompatibility with 1.4 controller + { + ob_start(); + $this->displayContent(); + $template = ob_get_contents(); + ob_clean(); + + } + $template = $this->context->smarty->assign('template', $template); + $this->smartyOutputContent($layout); + } + else + { + Tools::displayAsDeprecated('layout.tpl is missing in your theme directory'); + if ($this->display_header) + $this->smartyOutputContent(_PS_THEME_DIR_.'header.tpl'); + + if ($this->template) + $this->smartyOutputContent($this->template); + else // For retrocompatibility with 1.4 controller + $this->displayContent(); + + if ($this->display_footer) + $this->smartyOutputContent(_PS_THEME_DIR_.'footer.tpl'); + } + return true; + } + // antadis 12613 + public function setCacheHtml($cache_html) + { + $this->_cache_html = $cache_html; + } } \ No newline at end of file diff --git a/themes/site/modules/privatesales/privatesales-home.tpl b/themes/site/modules/privatesales/privatesales-home.tpl index 75840b54..13063c98 100755 --- a/themes/site/modules/privatesales/privatesales-home.tpl +++ b/themes/site/modules/privatesales/privatesales-home.tpl @@ -30,13 +30,13 @@ $(document).ready(function() { {/capture}