From 42f8a0a67a2c8fce9597aceff3224de73946c507 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 28 Jun 2013 12:19:02 +0200 Subject: [PATCH 01/12] [*] BO : improved unicode characters replacement in URLs --- classes/Tools.php | 89 ++++++++++++++++++++++++++++------------------- js/admin.js | 67 +++++++++++++++++++++++++---------- 2 files changed, 102 insertions(+), 54 deletions(-) diff --git a/classes/Tools.php b/classes/Tools.php index 10db11557..e6a1aea35 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -1025,47 +1025,66 @@ class ToolsCore */ public static function replaceAccentedChars($str) { + /* One source among others: + http://www.tachyonsoft.com/uc0000.htm + http://www.tachyonsoft.com/uc0001.htm + */ $patterns = array( + /* Lowercase */ - '/[\x{0105}\x{00E0}\x{00E1}\x{00E2}\x{00E3}\x{00E4}\x{00E5}]/u', - '/[\x{00E7}\x{010D}\x{0107}]/u', - '/[\x{010F}]/u', - '/[\x{00E8}\x{00E9}\x{00EA}\x{00EB}\x{011B}\x{0119}]/u', - '/[\x{00EC}\x{00ED}\x{00EE}\x{00EF}]/u', - '/[\x{011F}]/u', - '/[\x{0142}\x{013E}\x{013A}]/u', - '/[\x{00F1}\x{0148}]/u', - '/[\x{00F2}\x{00F3}\x{00F4}\x{00F5}\x{00F6}\x{00F8}]/u', - '/[\x{0159}\x{0155}]/u', - '/[\x{015B}\x{0161}\x{015F}]/u', - '/[\x{00DF}]/u', - '/[\x{0165}]/u', - '/[\x{00F9}\x{00FA}\x{00FB}\x{00FC}\x{016F}]/u', - '/[\x{00FD}\x{00FF}]/u', - '/[\x{017C}\x{017A}\x{017E}]/u', - '/[\x{00E6}]/u', - '/[\x{0153}]/u', + /* a */ '/[\x{00E0}\x{00E1}\x{00E2}\x{00E3}\x{00E4}\x{00E5}\x{0101}\x{0103}\x{0105}]/u', + /* c */ '/[\x{00E7}\x{0107}\x{0109}\x{010D}]/u', + /* d */ '/[\x{010F}\x{0111}]/u', + /* e */ '/[\x{00E8}\x{00E9}\x{00EA}\x{00EB}\x{0113}\x{0115}\x{0117}\x{0119}\x{011B}]/u', + /* g */ '/[\x{011F}\x{0121}\x{0123}]/u', + /* h */ '/[\x{0125}\x{0127}]/u', + /* i */ '/[\x{00EC}\x{00ED}\x{00EE}\x{00EF}\x{0129}\x{012B}\x{012D}\x{012F}\x{0131}]/u', + /* j */ '/[\x{0135}]/u', + /* k */ '/[\x{0137}\x{0138}]/u', + /* l */ '/[\x{013A}\x{013C}\x{013E}\x{0140}\x{0142}]/u', + /* n */ '/[\x{00F1}\x{0144}\x{0146}\x{0148}\x{0149}\x{014B}]/u', + /* o */ '/[\x{00F2}\x{00F3}\x{00F4}\x{00F5}\x{00F6}\x{00F8}\x{014D}\x{014F}\x{0151}]/u', + /* r */ '/[\x{0155}\x{0157}\x{0159}]/u', + /* s */ '/[\x{015B}\x{015D}\x{015F}\x{0161}]/u', + /* ss*/ '/[\x{00DF}]/u', + /* t */ '/[\x{0163}\x{0165}\x{0167}]/u', + /* u */ '/[\x{00F9}\x{00FA}\x{00FB}\x{00FC}\x{0169}\x{016B}\x{016D}\x{016F}\x{0171}\x{0173}]/u', + /* w */ '/[\x{0175}]/u', + /* y */ '/[\x{00FF}\x{0177}\x{00FD}]/u', + /* z */ '/[\x{017A}\x{017C}\x{017E}]/u', + /* ae*/ '/[\x{00E6}]/u', + /* oe*/ '/[\x{0153}]/u', /* Uppercase */ - '/[\x{0104}\x{00C0}\x{00C1}\x{00C2}\x{00C3}\x{00C4}\x{00C5}]/u', - '/[\x{00C7}\x{010C}\x{0106}]/u', - '/[\x{010E}]/u', - '/[\x{00C8}\x{00C9}\x{00CA}\x{00CB}\x{011A}\x{0118}]/u', - '/[\x{011E}]/u', - '/[\x{0141}\x{013D}\x{0139}]/u', - '/[\x{00D1}\x{0147}]/u', - '/[\x{00D3}]/u', - '/[\x{0158}\x{0154}]/u', - '/[\x{015A}\x{0160}\x{015E}]/u', - '/[\x{0164}]/u', - '/[\x{00D9}\x{00DA}\x{00DB}\x{00DC}\x{016E}]/u', - '/[\x{017B}\x{0179}\x{017D}]/u', - '/[\x{00C6}]/u', - '/[\x{0152}]/u'); + /* A */ '/[\x{0100}\x{0102}\x{0104}\x{00C0}\x{00C1}\x{00C2}\x{00C3}\x{00C4}\x{00C5}]/u', + /* C */ '/[\x{00C7}\x{0106}\x{0108}\x{010A}\x{010C}]/u', + /* D */ '/[\x{010E}\x{0110}]/u', + /* E */ '/[\x{00C8}\x{00C9}\x{00CA}\x{00CB}\x{0112}\x{0114}\x{0116}\x{0118}\x{011A}]/u', + /* G */ '/[\x{011C}\x{011E}\x{0120}\x{0122}]/u', + /* H */ '/[\x{0124}\x{0126}]/u', + /* I */ '/[\x{0128}\x{012A}\x{012C}\x{012E}\x{0130}]/u', + /* J */ '/[\x{0134}]/u', + /* K */ '/[\x{0136}]/u', + /* L */ '/[\x{0139}\x{013B}\x{013D}\x{0139}\x{0141}]/u', + /* N */ '/[\x{00D1}\x{0143}\x{0145}\x{0147}\x{014A}]/u', + /* O */ '/[\x{00D3}\x{014C}\x{014E}\x{0150}]/u', + /* R */ '/[\x{0154}\x{0156}\x{0158}]/u', + /* S */ '/[\x{015A}\x{015C}\x{015E}\x{0160}]/u', + /* T */ '/[\x{0162}\x{0164}\x{0166}]/u', + /* U */ '/[\x{00D9}\x{00DA}\x{00DB}\x{00DC}\x{0168}\x{016A}\x{016C}\x{016E}\x{0170}\x{0172}]/u', + /* W */ '/[\x{0174}]/u', + /* Y */ '/[\x{0176}]/u', + /* Z */ '/[\x{0179}\x{017B}\x{017D}]/u', + /* AE*/ '/[\x{00C6}]/u', + /* OE*/ '/[\x{0152}]/u'); + + // ö to oe + // å to aa + // ä to ae $replacements = array( - 'a', 'c', 'd', 'e', 'i', 'g', 'l', 'n', 'o', 'r', 's', 'ss', 't', 'u', 'y', 'z', 'ae', 'oe', - 'A', 'C', 'D', 'E', 'G', 'L', 'N', 'O', 'R', 'S', 'T', 'U', 'Z', 'AE', 'OE' + 'a', 'c', 'd', 'e', 'g', 'h', 'i', 'j', 'k', 'l', 'n', 'o', 'r', 's', 'ss', 't', 'u', 'y', 'w', 'z', 'ae', 'oe', + 'A', 'C', 'D', 'E', 'G', 'H', 'I', 'J', 'K', 'L', 'N', 'O', 'R', 'S', 'T', 'U', 'Z', 'AE', 'OE' ); return preg_replace($patterns, $replacements, $str); diff --git a/js/admin.js b/js/admin.js index 30e7dda61..d5ef76b71 100644 --- a/js/admin.js +++ b/js/admin.js @@ -35,25 +35,54 @@ function str2url(str, encoding, ucfirst) str = str.replace(/[^a-z0-9\s\'\:\/\[\]-]\\u00A1-\\uFFFF/g,''); else { - str = str.replace(/[\u0105\u0104\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5]/g,'a'); - str = str.replace(/[\u00E7\u010D\u0107\u0106]/g,'c'); - str = str.replace(/[\u010F]/g,'d'); - str = str.replace(/[\u00E8\u00E9\u00EA\u00EB\u011B\u0119\u0118\u0117]/g,'e'); - str = str.replace(/[\u00EC\u00ED\u00EE\u00EF\u012F]/g,'i'); - str = str.replace(/[\u0142\u0141]/g,'l'); - str = str.replace(/[\u00F1\u0148]/g,'n'); - str = str.replace(/[\u00F2\u00F3\u00F4\u00F5\u00F6\u00F8\u00D3]/g,'o'); - str = str.replace(/[\u0159]/g,'r'); - str = str.replace(/[\u015B\u015A\u0161]/g,'s'); - str = str.replace(/[\u00DF]/g,'ss'); - str = str.replace(/[\u0165]/g,'t'); - str = str.replace(/[\u00F9\u00FA\u00FB\u00FC\u016F\u016B\u0173]/g,'u'); - str = str.replace(/[\u00FD\u00FF]/g,'y'); - str = str.replace(/[\u017C\u017A\u017B\u0179\u017E]/g,'z'); - str = str.replace(/[\u00E6]/g,'ae'); - str = str.replace(/[\u0153]/g,'oe'); - str = str.replace(/[\u013E\u013A]/g,'l'); - str = str.replace(/[\u0155]/g,'r'); + /* Lowercase */ + str = str.replace(/[\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u0101\u0103\u0105]/g, 'a'); + str = str.replace(/[\u00E7\u0107\u0109\u010D]/g, 'c'); + str = str.replace(/[\u010F\u0111]/g, 'd'); + str = str.replace(/[\u00E8\u00E9\u00EA\u00EB\u0113\u0115\u0117\u0119\u011B]/g, 'e'); + str = str.replace(/[\u011F\u0121\u0123]/g, 'g'); + str = str.replace(/[\u0125\u0127]/g, 'h'); + str = str.replace(/[\u00EC\u00ED\u00EE\u00EF\u0129\u012B\u012D\u012F\u0131]/g, 'i'); + str = str.replace(/[\u0135]/g, 'j'); + str = str.replace(/[\u0137\u0138]/g, 'k'); + str = str.replace(/[\u013A\u013C\u013E\u0140\u0142]/g, 'l'); + str = str.replace(/[\u00F1\u0144\u0146\u0148\u0149\u014B]/g, 'n'); + str = str.replace(/[\u00F2\u00F3\u00F4\u00F5\u00F6\u00F8\u014D\u014F\u0151]/g, 'o'); + str = str.replace(/[\u0155\u0157\u0159]/g, 'r'); + str = str.replace(/[\u015B\u015D\u015F\u0161]/g, 's'); + str = str.replace(/[\u00DF]/g, 'ss'); + str = str.replace(/[\u0163\u0165\u0167]/g, 't'); + str = str.replace(/[\u00F9\u00FA\u00FB\u00FC\u0169\u016B\u016D\u016F\u0171\u0173]/g, 'u'); + str = str.replace(/[\u0175]/g, 'w'); + str = str.replace(/[\u00FF\u0177\u00FD]/g, 'y'); + str = str.replace(/[\u017A\u017C\u017E]/g, 'z'); + str = str.replace(/[\u00E6]/g, 'ae'); + str = str.replace(/[\u0153]/g, 'oe'); + + /* Uppercase */ + str = str.replace(/[\u0100\u0102\u0104\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5]/g, 'A'); + str = str.replace(/[\u00C7\u0106\u0108\u010A\u010C]/g, 'C'); + str = str.replace(/[\u010E\u0110]/g, 'D'); + str = str.replace(/[\u00C8\u00C9\u00CA\u00CB\u0112\u0114\u0116\u0118\u011A]/g, 'E'); + str = str.replace(/[\u011C\u011E\u0120\u0122]/g, 'G'); + str = str.replace(/[\u0124\u0126]/g, 'H'); + str = str.replace(/[\u0128\u012A\u012C\u012E\u0130]/g, 'I'); + str = str.replace(/[\u0134]/g, 'J'); + str = str.replace(/[\u0136]/g, 'K'); + str = str.replace(/[\u0139\u013B\u013D\u0139\u0141]/g, 'L'); + str = str.replace(/[\u00D1\u0143\u0145\u0147\u014A]/g, 'N'); + str = str.replace(/[\u00D3\u014C\u014E\u0150]/g, 'O'); + str = str.replace(/[\u0154\u0156\u0158]/g, 'R'); + str = str.replace(/[\u015A\u015C\u015E\u0160]/g, 'S'); + str = str.replace(/[\u0162\u0164\u0166]/g, 'T'); + str = str.replace(/[\u00D9\u00DA\u00DB\u00DC\u0168\u016A\u016C\u016E\u0170\u0172]/g, 'U'); + str = str.replace(/[\u0174]/g, 'W'); + str = str.replace(/[\u0176]/g, 'Y'); + str = str.replace(/[\u0179\u017B\u017D]/g, 'Z'); + str = str.replace(/[\u00C6]/g, 'AE'); + str = str.replace(/[\u0152]/g, 'OE'); + + str = str.toLowerCase(); str = str.replace(/[^a-z0-9\s\'\:\/\[\]-]/g,''); } From 8acf30863991ab885f2392e8368ac8b764af0600 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 28 Jun 2013 15:17:53 +0200 Subject: [PATCH 02/12] [*] FO : added smarty cache on blocknewproducts --- modules/blocknewproducts/blocknewproducts.php | 59 +++++++++++++++---- modules/blocknewproducts/config.xml | 2 +- .../blocknewproducts/upgrade/install-1.0.php | 9 +++ 3 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 modules/blocknewproducts/upgrade/install-1.0.php diff --git a/modules/blocknewproducts/blocknewproducts.php b/modules/blocknewproducts/blocknewproducts.php index 398ea29e2..4fa329db7 100644 --- a/modules/blocknewproducts/blocknewproducts.php +++ b/modules/blocknewproducts/blocknewproducts.php @@ -33,7 +33,7 @@ class BlockNewProducts extends Module { $this->name = 'blocknewproducts'; $this->tab = 'front_office_features'; - $this->version = 0.9; + $this->version = 1.0; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -45,9 +45,23 @@ class BlockNewProducts extends Module public function install() { - if (parent::install() == false || $this->registerHook('rightColumn') == false || $this->registerHook('header') == false || Configuration::updateValue('NEW_PRODUCTS_NBR', 5) == false) - return false; - return true; + if (!parent::install() + || !$this->registerHook('rightColumn') + || !$this->registerHook('header') + || !$this->registerHook('addproduct') + || !$this->registerHook('updateproduct') + || !$this->registerHook('deleteproduct') + || !Configuration::updateValue('NEW_PRODUCTS_NBR', 5) + ) + return false; + $this->_clearCache('blocknewproducts.tpl'); + return true; + } + + public function uninstall() + { + $this->_clearCache('blocknewproducts.tpl'); + return parent::uninstall(); } public function getContent() @@ -95,16 +109,25 @@ class BlockNewProducts extends Module public function hookRightColumn($params) { - $newProducts = Product::getNewProducts((int)($params['cookie']->id_lang), 0, (int)(Configuration::get('NEW_PRODUCTS_NBR'))); - if (!$newProducts && !Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY')) + if (!Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY')) return; - $this->smarty->assign(array( - 'new_products' => $newProducts, - 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), - )); + if (!$this->isCached('blocknewproducts.tpl', $this->getCacheId())) + { + if (!($newProducts = Product::getNewProducts((int)($params['cookie']->id_lang), 0, (int)Configuration::get('NEW_PRODUCTS_NBR')))) + return; - return $this->display(__FILE__, 'blocknewproducts.tpl'); + $this->smarty->assign(array( + 'new_products' => $newProducts, + 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), + )); + } + return $this->display(__FILE__, 'blocknewproducts.tpl', $this->getCacheId()); + } + + protected function getCacheId($name = null) + { + return parent::getCacheId('blocknewproducts|'.date('Ymd')); } public function hookLeftColumn($params) @@ -117,6 +140,18 @@ class BlockNewProducts extends Module $this->context->controller->addCSS(($this->_path).'blocknewproducts.css', 'all'); } -} + public function hookAddProduct($params) + { + $this->_clearCache('blocknewproducts.tpl'); + } + public function hookUpdateProduct($params) + { + $this->_clearCache('blocknewproducts.tpl'); + } + public function hookDeleteProduct($params) + { + $this->_clearCache('blocknewproducts.tpl'); + } +} \ No newline at end of file diff --git a/modules/blocknewproducts/config.xml b/modules/blocknewproducts/config.xml index f24ddb73f..6be6c8dd0 100755 --- a/modules/blocknewproducts/config.xml +++ b/modules/blocknewproducts/config.xml @@ -2,7 +2,7 @@ blocknewproducts - + diff --git a/modules/blocknewproducts/upgrade/install-1.0.php b/modules/blocknewproducts/upgrade/install-1.0.php new file mode 100644 index 000000000..ed388519f --- /dev/null +++ b/modules/blocknewproducts/upgrade/install-1.0.php @@ -0,0 +1,9 @@ +registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct')); +} From a387ff5e2fa8b4b96cbfd2d76e1f7538a4ca3c0d Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 28 Jun 2013 16:20:04 +0200 Subject: [PATCH 03/12] [-] FO : added smarty cache to blockcms --- modules/blockcms/BlockCMSModel.php | 1 + modules/blockcms/blockcms.php | 112 +++++++++++++---------- modules/blockcms/config.xml | 2 +- modules/blockcms/upgrade/install-1.2.php | 9 ++ 4 files changed, 74 insertions(+), 50 deletions(-) create mode 100644 modules/blockcms/upgrade/install-1.2.php diff --git a/modules/blockcms/BlockCMSModel.php b/modules/blockcms/BlockCMSModel.php index a6afd79ac..d0c63ee10 100644 --- a/modules/blockcms/BlockCMSModel.php +++ b/modules/blockcms/BlockCMSModel.php @@ -38,6 +38,7 @@ class BlockCMSModel extends ObjectModel const LEFT_COLUMN = 0; const RIGHT_COLUMN = 1; + const FOOTER = 2; /** * @see ObjectModel::$definition diff --git a/modules/blockcms/blockcms.php b/modules/blockcms/blockcms.php index 80fcb35e0..e71a05e1b 100755 --- a/modules/blockcms/blockcms.php +++ b/modules/blockcms/blockcms.php @@ -39,7 +39,7 @@ class BlockCms extends Module { $this->name = 'blockcms'; $this->tab = 'front_office_features'; - $this->version = '1.1.1'; + $this->version = '1.2'; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -52,14 +52,23 @@ class BlockCms extends Module public function install() { - if (!parent::install() || - !$this->registerHooks() || - !BlockCMSModel::createTables() || - !Configuration::updateValue('FOOTER_CMS', '') || - !Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', 1) || - !Configuration::updateValue('FOOTER_POWEREDBY', 1)) + if (!parent::install() + || !$this->registerHook('leftColumn') + || !$this->registerHook('rightColumn') + || !$this->registerHook('header') + || !$this->registerHook('footer') + || !$this->registerHook('actionObjectCmsUpdateAfter') + || !$this->registerHook('actionObjectCmsDeleteAfter') + || !$this->registerHook('actionShopDataDuplication') + || !BlockCMSModel::createTables() + || !Configuration::updateValue('FOOTER_CMS', '') + || !Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', 1) + || !Configuration::updateValue('FOOTER_POWEREDBY', 1) + ) return false; + $this->_clearCache('blockcms.tpl'); + // Install fixtures for blockcms $default = Db::getInstance()->insert('cms_block', array( 'id_cms_category' => 1, @@ -101,23 +110,16 @@ class BlockCms extends Module public function uninstall() { + $this->_clearCache('blockcms.tpl'); if (!parent::uninstall() || !BlockCMSModel::DropTables() || !Configuration::deleteByName('FOOTER_CMS') || !Configuration::deleteByName('FOOTER_BLOCK_ACTIVATION') || !Configuration::deleteByName('FOOTER_POWEREDBY')) return false; - return true; } - private function registerHooks() - { - return ( - $this->registerHook('leftColumn') && $this->registerHook('rightColumn') && - $this->registerHook('header') && $this->registerHook('footer') && $this->registerHook('actionShopDataDuplication')); - } - public function initToolbar() { $current_index = AdminController::$currentIndex; @@ -541,6 +543,8 @@ class BlockCms extends Module if ($this->_postValidation() == false) return false; + $this->_clearCache('blockcms.tpl'); + $this->_errors = array(); if (Tools::isSubmit('submitBlockCMS')) { @@ -661,42 +665,33 @@ class BlockCms extends Module public function displayBlockCMS($column) { - $cms_titles = BlockCMSModel::getCMSTitles($column); + if (!$this->isCached('blockcms.tpl', $this->getCacheId($column))) + { + $cms_titles = BlockCMSModel::getCMSTitles($column); - $this->smarty->assign(array( - 'block' => 1, - 'cms_titles' => $cms_titles, - 'contact_url' => (_PS_VERSION_ >= 1.5) ? 'contact' : 'contact-form' - )); - - return $this->display(__FILE__, 'blockcms.tpl'); + $this->smarty->assign(array( + 'block' => 1, + 'cms_titles' => $cms_titles, + 'contact_url' => (_PS_VERSION_ >= 1.5) ? 'contact' : 'contact-form' + )); + } + return $this->display(__FILE__, 'blockcms.tpl', $this->getCacheId($column)); } - - private function _prepareHook() + + protected function getCacheId($name = null) { - $block_activation = Configuration::get('FOOTER_BLOCK_ACTIVATION'); - - if (!$block_activation) - return false; - - $cms_titles = BlockCMSModel::getCMSTitlesFooter(); - $display_footer = Configuration::get('PS_STORES_DISPLAY_FOOTER'); - $display_poweredby = Configuration::get('FOOTER_POWEREDBY'); - $footer_text = Configuration::get('FOOTER_CMS_TEXT_'.(int)$this->context->language->id); - - $this->smarty->assign( - array( - 'block' => 0, - 'contact_url' => 'contact', - 'cmslinks' => $cms_titles, - 'display_stores_footer' => $display_footer, - 'display_poweredby' => ((int)$display_poweredby === 1 || $display_poweredby === false), - 'footer_text' => $footer_text - ) - ); - return true; + return parent::getCacheId('blockcms|'.$name); } + public function hookActionObjectCmsUpdateAfter() + { + $this->_clearCache('blockcms.tpl'); + } + + public function hookActionObjectCmsDeleteAfter() + { + $this->_clearCache('blockcms.tpl'); + } public function hookHeader($params) { @@ -715,9 +710,28 @@ class BlockCms extends Module public function hookFooter() { - if (!$this->_prepareHook()) - return ; - return $this->display(__FILE__, 'blockcms.tpl'); + if (!($block_activation = Configuration::get('FOOTER_BLOCK_ACTIVATION'))) + return; + + if (!$this->isCached('blockcms.tpl', $this->getCacheId(BlockCMSModel::FOOTER))) + { + $cms_titles = BlockCMSModel::getCMSTitlesFooter(); + $display_footer = Configuration::get('PS_STORES_DISPLAY_FOOTER'); + $display_poweredby = Configuration::get('FOOTER_POWEREDBY'); + $footer_text = Configuration::get('FOOTER_CMS_TEXT_'.(int)$this->context->language->id); + + $this->smarty->assign( + array( + 'block' => 0, + 'contact_url' => 'contact', + 'cmslinks' => $cms_titles, + 'display_stores_footer' => $display_footer, + 'display_poweredby' => ((int)$display_poweredby === 1 || $display_poweredby === false), + 'footer_text' => $footer_text + ) + ); + } + return $this->display(__FILE__, 'blockcms.tpl', $this->getCacheId(BlockCMSModel::FOOTER)); } protected function updatePositionsDnd() diff --git a/modules/blockcms/config.xml b/modules/blockcms/config.xml index aa10092cc..2abc36c39 100755 --- a/modules/blockcms/config.xml +++ b/modules/blockcms/config.xml @@ -2,7 +2,7 @@ blockcms - + diff --git a/modules/blockcms/upgrade/install-1.2.php b/modules/blockcms/upgrade/install-1.2.php new file mode 100644 index 000000000..7daca8af4 --- /dev/null +++ b/modules/blockcms/upgrade/install-1.2.php @@ -0,0 +1,9 @@ +registerHook('actionObjectCmsUpdateAfter') && $object->registerHook('actionObjectCmsDeleteAfter')); +} From a8d96ed0c0de54270001ac87cfb88cf562175066 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 28 Jun 2013 16:38:08 +0200 Subject: [PATCH 04/12] // Removed useless feature --- admin-dev/themes/default/template/controllers/modules/page.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin-dev/themes/default/template/controllers/modules/page.tpl b/admin-dev/themes/default/template/controllers/modules/page.tpl index ea759f137..00e197055 100644 --- a/admin-dev/themes/default/template/controllers/modules/page.tpl +++ b/admin-dev/themes/default/template/controllers/modules/page.tpl @@ -58,7 +58,7 @@ {foreach from=$list_modules_categories item=module_category key=module_category_key} {/foreach} From 583346bbb7209753faf6ae24e2dd9eaa59ef34e1 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 28 Jun 2013 17:19:06 +0200 Subject: [PATCH 05/12] [*] FO : added smarty cache on homefeatured module --- modules/homefeatured/config.xml | 6 +- modules/homefeatured/homefeatured.php | 60 +++++++++++++++----- modules/homefeatured/upgrade/install-1.0.php | 9 +++ 3 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 modules/homefeatured/upgrade/install-1.0.php diff --git a/modules/homefeatured/config.xml b/modules/homefeatured/config.xml index fa546c282..cd700c29d 100755 --- a/modules/homefeatured/config.xml +++ b/modules/homefeatured/config.xml @@ -1,9 +1,9 @@ homefeatured - - - + + + 1 diff --git a/modules/homefeatured/homefeatured.php b/modules/homefeatured/homefeatured.php index 4567adfa1..2657134d5 100644 --- a/modules/homefeatured/homefeatured.php +++ b/modules/homefeatured/homefeatured.php @@ -36,7 +36,7 @@ class HomeFeatured extends Module { $this->name = 'homefeatured'; $this->tab = 'front_office_features'; - $this->version = '0.9'; + $this->version = '1.0'; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -48,17 +48,31 @@ class HomeFeatured extends Module function install() { - if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) || !parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('header')) + $this->_clearCache('homefeatured.tpl'); + if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) + || !parent::install() + || !$this->registerHook('displayHome') + || !$this->registerHook('header') + || !$this->registerHook('addproduct') + || !$this->registerHook('updateproduct') + || !$this->registerHook('deleteproduct') + ) return false; return true; } + + public function uninstall() + { + $this->_clearCache('homefeatured.tpl'); + return parent::uninstall(); + } public function getContent() { $output = '

'.$this->displayName.'

'; if (Tools::isSubmit('submitHomeFeatured')) { - $nbr = (int)(Tools::getValue('nbr')); + $nbr = (int)Tools::getValue('nbr'); if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr)) $errors[] = $this->l('An invalid number of products has been specified.'); else @@ -101,16 +115,34 @@ class HomeFeatured extends Module public function hookDisplayHome($params) { - $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); - $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); - $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10)); + if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured'))) + { + p('no cache'); + $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); + $nb = (int)Configuration::get('HOME_FEATURED_NBR'); + $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10)); - $this->smarty->assign(array( - 'products' => $products, - 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), - 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), - )); - - return $this->display(__FILE__, 'homefeatured.tpl'); + $this->smarty->assign(array( + 'products' => $products, + 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), + 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), + )); + } + return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeatured')); } -} + + public function hookAddProduct($params) + { + $this->_clearCache('homefeatured.tpl'); + } + + public function hookUpdateProduct($params) + { + $this->_clearCache('homefeatured.tpl'); + } + + public function hookDeleteProduct($params) + { + $this->_clearCache('homefeatured.tpl'); + } +} \ No newline at end of file diff --git a/modules/homefeatured/upgrade/install-1.0.php b/modules/homefeatured/upgrade/install-1.0.php new file mode 100644 index 000000000..ed388519f --- /dev/null +++ b/modules/homefeatured/upgrade/install-1.0.php @@ -0,0 +1,9 @@ +registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct')); +} From 09bbff8737f921927f456544f0557d35f1144c02 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 28 Jun 2013 17:42:43 +0200 Subject: [PATCH 06/12] [*] FO : added smarty cache on blockbestsellers --- modules/blockbestsellers/blockbestsellers.php | 91 ++++++++++++++----- modules/blockbestsellers/config.xml | 2 +- .../blockbestsellers/upgrade/install-1.2.php | 9 ++ modules/homefeatured/homefeatured.php | 6 +- 4 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 modules/blockbestsellers/upgrade/install-1.2.php diff --git a/modules/blockbestsellers/blockbestsellers.php b/modules/blockbestsellers/blockbestsellers.php index 8f736e448..58b79ff51 100644 --- a/modules/blockbestsellers/blockbestsellers.php +++ b/modules/blockbestsellers/blockbestsellers.php @@ -36,7 +36,7 @@ class BlockBestSellers extends Module { $this->name = 'blockbestsellers'; $this->tab = 'front_office_features'; - $this->version = '1.1'; + $this->version = '1.2'; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -51,14 +51,53 @@ class BlockBestSellers extends Module */ public function install() { - if (!parent::install() || - !$this->registerHook('rightColumn') || - !$this->registerHook('header') || - !$this->registerHook('updateOrderStatus') || - !ProductSale::fillProductSales()) + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + + if (!parent::install() + || !$this->registerHook('rightColumn') + || !$this->registerHook('header') + || !$this->registerHook('actionOrderStatusPostUpdate') + || !$this->registerHook('addproduct') + || !$this->registerHook('updateproduct') + || !$this->registerHook('deleteproduct') + || !ProductSale::fillProductSales() + ) return false; return true; } + + public function uninstall() + { + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + + return parent::uninstall(); + } + + public function hookAddProduct($params) + { + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + } + + public function hookUpdateProduct($params) + { + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + } + + public function hookDeleteProduct($params) + { + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + } + + public function hookActionOrderStatusPostUpdate($params) + { + $this->_clearCache('blockbestsellers.tpl'); + $this->_clearCache('blockbestsellers-home.tpl'); + } /** * Called in administration -> module -> configure @@ -102,28 +141,34 @@ class BlockBestSellers extends Module public function hookHome($params) { - $best_sellers = $this->getBestSellers($params); - if ($best_sellers === false) - return; + if (!$this->isCached('blockbestsellers-home.tpl', $this->getCacheId('blockbestsellers-home'))) + { + $best_sellers = $this->getBestSellers($params); + if ($best_sellers === false) + return; - $this->smarty->assign(array( - 'best_sellers' => $best_sellers, - 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); - return $this->display(__FILE__, 'blockbestsellers-home.tpl'); + $this->smarty->assign(array( + 'best_sellers' => $best_sellers, + 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); + } + return $this->display(__FILE__, 'blockbestsellers-home.tpl', $this->getCacheId('blockbestsellers-home')); } public function hookRightColumn($params) { - $best_sellers = $this->getBestSellers($params); - if ($best_sellers === false) - return; + if (!$this->isCached('blockbestsellers.tpl', $this->getCacheId('blockbestsellers'))) + { + $best_sellers = $this->getBestSellers($params); + if ($best_sellers === false) + return; - $this->smarty->assign(array( - 'best_sellers' => $best_sellers, - 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), - 'smallSize' => Image::getSize(ImageType::getFormatedName('small')) - )); - return $this->display(__FILE__, 'blockbestsellers.tpl'); + $this->smarty->assign(array( + 'best_sellers' => $best_sellers, + 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), + 'smallSize' => Image::getSize(ImageType::getFormatedName('small')) + )); + } + return $this->display(__FILE__, 'blockbestsellers.tpl', $this->getCacheId('blockbestsellers')); } public function hookLeftColumn($params) @@ -136,7 +181,7 @@ class BlockBestSellers extends Module if (Configuration::get('PS_CATALOG_MODE')) return false; - if (!($result = ProductSale::getBestSalesLight((int)($params['cookie']->id_lang), 0, 5))) + if (!($result = ProductSale::getBestSalesLight((int)$params['cookie']->id_lang, 0, 5))) return (Configuration::get('PS_BLOCK_BESTSELLERS_DISPLAY') ? array() : false); $bestsellers = array(); diff --git a/modules/blockbestsellers/config.xml b/modules/blockbestsellers/config.xml index b8141299b..b8a2515a0 100755 --- a/modules/blockbestsellers/config.xml +++ b/modules/blockbestsellers/config.xml @@ -2,7 +2,7 @@ blockbestsellers - + diff --git a/modules/blockbestsellers/upgrade/install-1.2.php b/modules/blockbestsellers/upgrade/install-1.2.php new file mode 100644 index 000000000..1c636719c --- /dev/null +++ b/modules/blockbestsellers/upgrade/install-1.2.php @@ -0,0 +1,9 @@ +registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct') && $object->registerHook('actionOrderStatusPostUpdate')); +} diff --git a/modules/homefeatured/homefeatured.php b/modules/homefeatured/homefeatured.php index 2657134d5..380b407b0 100644 --- a/modules/homefeatured/homefeatured.php +++ b/modules/homefeatured/homefeatured.php @@ -49,8 +49,9 @@ class HomeFeatured extends Module function install() { $this->_clearCache('homefeatured.tpl'); - if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) - || !parent::install() + Configuration::updateValue('HOME_FEATURED_NBR', 8); + + if (!parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('header') || !$this->registerHook('addproduct') @@ -117,7 +118,6 @@ class HomeFeatured extends Module { if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured'))) { - p('no cache'); $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10)); From 349a10e2a9287d4b4e1b45cbdea9cbf8b6916b21 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Fri, 28 Jun 2013 17:58:04 +0200 Subject: [PATCH 07/12] // fix warnings --- .../themes/default/template/controllers/orders/_documents.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/orders/_documents.tpl b/admin-dev/themes/default/template/controllers/orders/_documents.tpl index 54b1e8599..45b9123bd 100644 --- a/admin-dev/themes/default/template/controllers/orders/_documents.tpl +++ b/admin-dev/themes/default/template/controllers/orders/_documents.tpl @@ -110,7 +110,7 @@ {if !isset($document->is_delivery)} -
+

@@ -130,7 +130,7 @@

{l s='No documents are available'}

{if isset($invoice_management_active) && $invoice_management_active} -

{l s='Generate invoice'}

+

{l s='Generate invoice'}

{/if} From ae2491c4029392e8736c51aab11eec0dd4c3d4a4 Mon Sep 17 00:00:00 2001 From: Fabio Chelly Date: Fri, 28 Jun 2013 18:10:13 +0200 Subject: [PATCH 08/12] Prevent email to be stored twice (1 in customer newsletter and 1 in module newsletter) by removing email in newsletter table when creating a new account #PNM-1419 --- modules/blocknewsletter/blocknewsletter.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/blocknewsletter/blocknewsletter.php b/modules/blocknewsletter/blocknewsletter.php index a0f4565e9..498fbd00d 100644 --- a/modules/blocknewsletter/blocknewsletter.php +++ b/modules/blocknewsletter/blocknewsletter.php @@ -61,7 +61,8 @@ class Blocknewsletter extends Module public function install() { - if (parent::install() == false || $this->registerHook('leftColumn') == false || $this->registerHook('header') == false) + if (parent::install() == false || $this->registerHook('leftColumn') == false || $this->registerHook('header') == false + || $this->registerHook('actionCustomerAccountAdd') == false) return false; Configuration::updateValue('NW_SALT', Tools::passwdGen(16)); @@ -521,4 +522,20 @@ class Blocknewsletter extends Module { $this->context->controller->addCSS($this->_path.'blocknewsletter.css', 'all'); } + + /** + * Deletes duplicates email in newsletter table + * @param $params + * @return bool + */ + public function hookActionCustomerAccountAdd($params) + { + //if e-mail of the created user address has already been added to the newsletter through the blocknewsletter module, + //we delete it from blocknewsletter table to prevent duplicates + $id_shop = $params['newCustomer']->id_shop; + $email = $params['newCustomer']->email; + if (Validate::isEmail($email)) + return (bool)Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'newsletter WHERE id_shop='.(int)$id_shop.' AND email=\''.pSQL($email)."'"); + return false; + } } From 668181d8ecb23d85dd22d6554c10cdfb151cc48f Mon Sep 17 00:00:00 2001 From: Fabio Chelly Date: Fri, 28 Jun 2013 18:11:44 +0200 Subject: [PATCH 09/12] Newsletter field is always shown in create account form even if blocknewsletter module is disabled --- controllers/front/AuthController.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 08c96d058..d36c746c4 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -85,11 +85,7 @@ class AuthControllerCore extends FrontController $this->assignCountries(); - $active_module_newsletter = false; - if ($module_newsletter = Module::getInstanceByName('blocknewsletter')) - $active_module_newsletter = $module_newsletter->active; - - $this->context->smarty->assign('newsletter', (int)$active_module_newsletter); + $this->context->smarty->assign('newsletter', 1); $back = Tools::getValue('back'); $key = Tools::safeOutput(Tools::getValue('key')); From d574f924118a9b71e3c0b5e203907482e02072d1 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 28 Jun 2013 18:26:42 +0200 Subject: [PATCH 10/12] [*] FO : added smarty cache to blockspecials --- modules/blockspecials/blockspecials.php | 68 +++++++++++++++---- modules/blockspecials/config.xml | 2 +- modules/blockspecials/upgrade/install-1.0.php | 10 +++ 3 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 modules/blockspecials/upgrade/install-1.0.php diff --git a/modules/blockspecials/blockspecials.php b/modules/blockspecials/blockspecials.php index 24d03fbc1..4c732c099 100644 --- a/modules/blockspecials/blockspecials.php +++ b/modules/blockspecials/blockspecials.php @@ -36,7 +36,7 @@ class BlockSpecials extends Module { $this->name = 'blockspecials'; $this->tab = 'pricing_promotion'; - $this->version = '0.8'; + $this->version = '1.0'; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -48,7 +48,23 @@ class BlockSpecials extends Module public function install() { - return (parent::install() AND $this->registerHook('rightColumn') AND $this->registerHook('header')); + if (!Configuration::get('BLOCKSPECIALS_NB_CACHES')) + Configuration::updateValue('BLOCKSPECIALS_NB_CACHES', 20); + $this->_clearCache('blockspecials.tpl'); + + return (parent::install() + && $this->registerHook('rightColumn') + && $this->registerHook('header') + && $this->registerHook('addproduct') + && $this->registerHook('updateproduct') + && $this->registerHook('deleteproduct') + ); + } + + public function uninstall() + { + $this->_clearCache('blockspecials.tpl'); + return parent::uninstall(); } public function getContent() @@ -56,7 +72,8 @@ class BlockSpecials extends Module $output = '

'.$this->displayName.'

'; if (Tools::isSubmit('submitSpecials')) { - Configuration::updateValue('PS_BLOCK_SPECIALS_DISPLAY', (int)(Tools::getValue('always_display'))); + Configuration::updateValue('PS_BLOCK_SPECIALS_DISPLAY', (int)Tools::getValue('always_display')); + Configuration::updateValue('BLOCKSPECIALS_NB_CACHES', (int)Tools::getValue('BLOCKSPECIALS_NB_CACHES')); $output .= '
'.$this->l('Settings updated').'
'; } return $output.$this->displayForm(); @@ -76,6 +93,11 @@ class BlockSpecials extends Module

'.$this->l('Show the block even if no product is available.').'

+ +
+ +

'.$this->l('Specials are displayed randomly on the front end, but since it takes a lot of ressources, it is better to cache the results. Cache is reset everyday. 0 will disable the cache.').'

+
'; @@ -84,18 +106,24 @@ class BlockSpecials extends Module public function hookRightColumn($params) { if (Configuration::get('PS_CATALOG_MODE')) - return ; - - if (!($special = Product::getRandomSpecial((int)$params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) return; + + // We need to create multiple caches because the products are sorted randomly + $random = date('Ymd').'|'.round(rand(1, max(Configuration::get('BLOCKSPECIALS_NB_CACHES'), 1))); - $this->smarty->assign(array( - 'special' => $special, - 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2), - 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), - )); + if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this->isCached('blockspecials.tpl', $this->getCacheId('blockspecials|'.$random))) + { + if (!($special = Product::getRandomSpecial((int)$params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) + return; - return $this->display(__FILE__, 'blockspecials.tpl'); + $this->smarty->assign(array( + 'special' => $special, + 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2), + 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')), + )); + } + + return $this->display(__FILE__, 'blockspecials.tpl', $this->getCacheId('blockspecials|'.$random)); } public function hookLeftColumn($params) @@ -109,5 +137,19 @@ class BlockSpecials extends Module return ; $this->context->controller->addCSS(($this->_path).'blockspecials.css', 'all'); } -} + public function hookAddProduct($params) + { + $this->_clearCache('blockspecials.tpl'); + } + + public function hookUpdateProduct($params) + { + $this->_clearCache('blockspecials.tpl'); + } + + public function hookDeleteProduct($params) + { + $this->_clearCache('blockspecials.tpl'); + } +} \ No newline at end of file diff --git a/modules/blockspecials/config.xml b/modules/blockspecials/config.xml index e903067d0..613f0cc76 100755 --- a/modules/blockspecials/config.xml +++ b/modules/blockspecials/config.xml @@ -2,7 +2,7 @@ blockspecials - + diff --git a/modules/blockspecials/upgrade/install-1.0.php b/modules/blockspecials/upgrade/install-1.0.php new file mode 100644 index 000000000..3dbc3bfe0 --- /dev/null +++ b/modules/blockspecials/upgrade/install-1.0.php @@ -0,0 +1,10 @@ +registerHook('addproduct') && $object->registerHook('updateproduct') && $object->registerHook('deleteproduct')); +} From 3d85e81c3db3503a5ba65bd1bd54454c10b2e55e Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Fri, 28 Jun 2013 18:51:49 +0200 Subject: [PATCH 11/12] // Oops, removing a block is a sure way to optimize... --- modules/blocknewproducts/blocknewproducts.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/blocknewproducts/blocknewproducts.php b/modules/blocknewproducts/blocknewproducts.php index 4fa329db7..12659bc83 100644 --- a/modules/blocknewproducts/blocknewproducts.php +++ b/modules/blocknewproducts/blocknewproducts.php @@ -109,12 +109,9 @@ class BlockNewProducts extends Module public function hookRightColumn($params) { - if (!Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY')) - return; - if (!$this->isCached('blocknewproducts.tpl', $this->getCacheId())) { - if (!($newProducts = Product::getNewProducts((int)($params['cookie']->id_lang), 0, (int)Configuration::get('NEW_PRODUCTS_NBR')))) + if (!Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY') && !($newProducts = Product::getNewProducts((int)$params['cookie']->id_lang, 0, (int)Configuration::get('NEW_PRODUCTS_NBR')))) return; $this->smarty->assign(array( From 127b046c0e0273b2ca2999540086930a7fac3244 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Sun, 30 Jun 2013 19:46:04 +0200 Subject: [PATCH 12/12] //remove warning --- classes/Tools.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/classes/Tools.php b/classes/Tools.php index 10db11557..f24746dd8 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -680,19 +680,20 @@ class ToolsCore public static function deleteDirectory($dirname, $delete_self = true) { $dirname = rtrim($dirname, '/').'/'; - if ($files = scandir($dirname)) - { - foreach ($files as $file) - if ($file != '.' && $file != '..' && $file != '.svn') + if (file_exists($dirname)) + if ($files = scandir($dirname)) { - if (is_dir($dirname.$file)) - Tools::deleteDirectory($dirname.$file, true); - elseif (file_exists($dirname.$file)) - unlink($dirname.$file); + foreach ($files as $file) + if ($file != '.' && $file != '..' && $file != '.svn') + { + if (is_dir($dirname.$file)) + Tools::deleteDirectory($dirname.$file, true); + elseif (file_exists($dirname.$file)) + unlink($dirname.$file); + } + if ($delete_self) + rmdir($dirname); } - if ($delete_self) - rmdir($dirname); - } } /**