diff --git a/config.xml b/config.xml index 49fe122..cf023f0 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_imageslider - + diff --git a/controllers/admin/AdminConfigureSlidesController.php b/controllers/admin/AdminConfigureSlidesController.php index 13a9954..5abef0f 100644 --- a/controllers/admin/AdminConfigureSlidesController.php +++ b/controllers/admin/AdminConfigureSlidesController.php @@ -19,32 +19,30 @@ */ class AdminConfigureSlidesController extends ModuleAdminController { - public $module; - - /** - * This function allow to delete users - */ public function ajaxProcessUpdateSlidesPosition() { - $home_slider = $this->module; - $slides = []; - - if (!Tools::isSubmit('secure_key') || Tools::getValue('secure_key') != $home_slider->secure_key || !Tools::getValue('action')) { - $this->ajaxDie(json_encode(['error' => true])); - } + if (empty(Tools::getValue('action')) || Tools::getValue('action') != 'updateSlidesPosition' || empty(Tools::getValue('slides'))) { + ob_end_clean(); + header('Content-Type: application/json'); + $this->ajaxRender(json_encode(['error' => true])); + exit; + } - if (Tools::getValue('action') == 'updateSlidesPosition' && Tools::getValue('slides')) { - $slides = Tools::getValue('slides'); - - foreach ($slides as $position => $id_slide) { - $res = Db::getInstance()->execute(' + // Get slides and update their position + $slides = Tools::getValue('slides'); + foreach ($slides as $position => $id_slide) { + Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'homeslider_slides` SET `position` = ' . (int) $position . ' WHERE `id_homeslider_slides` = ' . (int) $id_slide - ); - } + ); + } + + // Wipe module cache + $this->module->clearCache(); - $home_slider->clearCache(); - } - $this->ajaxDie(json_encode(['success' => true])); + ob_end_clean(); + header('Content-Type: application/json'); + $this->ajaxRender(json_encode(['success' => true])); + exit; } } diff --git a/controllers/index.php b/controllers/index.php deleted file mode 100644 index 36c7d1f..0000000 --- a/controllers/index.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) - */ -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; diff --git a/ps_imageslider.php b/ps_imageslider.php index 27cf27c..5d4e5e7 100644 --- a/ps_imageslider.php +++ b/ps_imageslider.php @@ -48,15 +48,11 @@ class Ps_ImageSlider extends Module implements WidgetInterface */ public $secure_key; - public $adminControllers = [ - 'adminConfigureSlides' => 'AdminConfigureSlides', - ]; - public function __construct() { $this->name = 'ps_imageslider'; $this->tab = 'front_office_features'; - $this->version = '3.1.4'; + $this->version = '3.2.0'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->secure_key = Tools::hash($this->name); @@ -79,6 +75,7 @@ public function install() /* Adds Module */ if ( parent::install() && + $this->installTab() && $this->registerHook('displayHeader') && $this->registerHook('displayHome') && $this->registerHook('actionShopDataDuplication') @@ -129,6 +126,21 @@ public function install() return false; } + public function installTab() + { + $tab = new Tab(); + $tab->class_name = 'AdminConfigureSlides'; + $tab->module = $this->name; + $tab->active = true; + $tab->id_parent = -1; + $tab->name = array_fill_keys( + Language::getIDs(false), + $this->displayName + ); + + return $tab->add(); + } + /** * Adds samples */ @@ -162,6 +174,9 @@ public function uninstall() /* Deletes tables */ $res = $this->deleteTables(); + /* Delete hidden tab */ + $res &= $this->uninstallTab(); + /* Unsets configuration */ $res &= Configuration::deleteByName('HOMESLIDER_SPEED'); $res &= Configuration::deleteByName('HOMESLIDER_PAUSE_ON_HOVER'); @@ -173,6 +188,18 @@ public function uninstall() return false; } + public function uninstallTab() + { + $result = true; + $id_tab = (int) Tab::getIdFromClassName('AdminConfigureSlides'); + $tab = new Tab($id_tab); + if (Validate::isLoadedObject($tab)) { + $result = $tab->delete(); + } + + return $result; + } + /** * Creates tables */ @@ -617,6 +644,7 @@ public function hookActionShopDataDuplication($params) public function headerHTML() { + // Run only on module configuration page if ('AdminModules' !== Tools::getValue('controller') || Tools::getValue('configure') !== $this->name || Tools::getIsset('id_slide') || @@ -625,6 +653,7 @@ public function headerHTML() } $this->context->controller->addJS($this->_path . 'js/Sortable.min.js'); + /* Style & js for fieldset 'slides configuration' */ $html = '