diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 4911c85..766fbeb 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -58,7 +58,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - presta-versions: ['1.7.4.4', '1.7.5.1', '1.7.6', '1.7.7', '1.7.8', 'latest'] + presta-versions: ['1.7.5.1', '1.7.6', '1.7.7', '1.7.8', 'latest'] steps: - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/README.md b/README.md index c70719a..b6d1c4f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Add sliding images to your homepage to welcome your visitors in a visual and fri ## Compatibility -PrestaShop: `1.7.4.0` or later +PrestaShop: `1.7.5.0` or later ## Multistore compatibility diff --git a/ajax_ps_imageslider.php b/ajax_ps_imageslider.php deleted file mode 100644 index deb8871..0000000 --- a/ajax_ps_imageslider.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 - */ -include_once '../../config/config.inc.php'; -include_once '../../init.php'; -include_once 'ps_imageslider.php'; - -$home_slider = new Ps_ImageSlider(); -$slides = []; - -if (!Tools::isSubmit('secure_key') || Tools::getValue('secure_key') != $home_slider->secure_key || !Tools::getValue('action')) { - exit(1); -} - -if (Tools::getValue('action') == 'updateSlidesPosition' && Tools::getValue('slides')) { - $slides = Tools::getValue('slides'); - - foreach ($slides as $position => $id_slide) { - $res = Db::getInstance()->execute(' - UPDATE `' . _DB_PREFIX_ . 'homeslider_slides` SET `position` = ' . (int) $position . ' - WHERE `id_homeslider_slides` = ' . (int) $id_slide - ); - } - - $home_slider->clearCache(); -} 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 new file mode 100644 index 0000000..5abef0f --- /dev/null +++ b/controllers/admin/AdminConfigureSlidesController.php @@ -0,0 +1,48 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ +class AdminConfigureSlidesController extends ModuleAdminController +{ + public function ajaxProcessUpdateSlidesPosition() + { + 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; + } + + // 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(); + + ob_end_clean(); + header('Content-Type: application/json'); + $this->ajaxRender(json_encode(['success' => true])); + exit; + } +} diff --git a/ps_imageslider.php b/ps_imageslider.php index 3dbbf28..e79f9a9 100644 --- a/ps_imageslider.php +++ b/ps_imageslider.php @@ -52,7 +52,7 @@ 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); @@ -62,7 +62,7 @@ public function __construct() $this->displayName = $this->trans('Image slider', [], 'Modules.Imageslider.Admin'); $this->description = $this->trans('Add sliding images to your homepage to welcome your visitors in a visual and friendly way.', [], 'Modules.Imageslider.Admin'); - $this->ps_versions_compliancy = ['min' => '1.7.4.0', 'max' => _PS_VERSION_]; + $this->ps_versions_compliancy = ['min' => '1.7.5.0', 'max' => _PS_VERSION_]; $this->templateFile = 'module:ps_imageslider/views/templates/hook/slider.tpl'; } @@ -75,6 +75,7 @@ public function install() /* Adds Module */ if ( parent::install() && + $this->installTab() && $this->registerHook('displayHeader') && $this->registerHook('displayHome') && $this->registerHook('actionShopDataDuplication') @@ -125,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 */ @@ -158,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'); @@ -169,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 */ @@ -215,7 +246,7 @@ protected function createTables() */ protected function deleteTables() { - $slides = $this->getSlides(); + $slides = $this->getSlides(null, true); foreach ($slides as $slide) { $to_del = new Ps_HomeSlide($slide['id_slide']); $to_del->delete(); @@ -613,30 +644,52 @@ public function hookActionShopDataDuplication($params) public function headerHTML() { - if ('AdminModules' !== Tools::getValue('controller') || - Tools::getValue('configure') !== $this->name || - Tools::getIsset('id_slide')) { + // Run only on module configuration page + if (Tools::getValue('controller') != 'AdminModules' || Tools::getValue('configure') !== $this->name) { return; } - $this->context->controller->addJS($this->_path . 'js/Sortable.min.js'); - /* Style & js for fieldset 'slides configuration' */ - $html = ''; @@ -654,7 +707,15 @@ public function getNextPosition() return ++$row['next_position']; } - public function getSlides($active = null) + /** + * Get slides + * + * @param bool $active + * @param bool $forceShowAll Include all slides, even those without image for a given language + * + * @return array + */ + public function getSlides($active = null, $forceShowAll = false) { $this->context = Context::getContext(); $id_shop = $this->context->shop->id; @@ -667,8 +728,8 @@ public function getSlides($active = null) LEFT JOIN ' . _DB_PREFIX_ . 'homeslider_slides hss ON (hs.id_homeslider_slides = hss.id_homeslider_slides) LEFT JOIN ' . _DB_PREFIX_ . 'homeslider_slides_lang hssl ON (hss.id_homeslider_slides = hssl.id_homeslider_slides) WHERE id_shop = ' . (int) $id_shop . ' - AND hssl.id_lang = ' . (int) $id_lang . ' - AND hssl.`image` <> ""' . + AND hssl.id_lang = ' . (int) $id_lang . + ($forceShowAll ? '' : ' AND hssl.`image` <> ""') . ($active ? ' AND hss.`active` = 1' : ' ') . ' ORDER BY hss.position' ); @@ -731,7 +792,7 @@ public function slideExists($id_slide) public function renderList() { - $slides = $this->getSlides(); + $slides = $this->getSlides(null, true); foreach ($slides as $key => $slide) { $slides[$key]['status'] = $this->displayStatus($slide['id_slide'], $slide['active']); $associated_shop_ids = Ps_HomeSlide::getAssociatedIdsShop((int) $slide['id_slide']); diff --git a/upgrade/upgrade-3.2.0.php b/upgrade/upgrade-3.2.0.php new file mode 100644 index 0000000..6e54416 --- /dev/null +++ b/upgrade/upgrade-3.2.0.php @@ -0,0 +1,27 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + * International Registered Trademark & Property of PrestaShop SA + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +function upgrade_module_3_2_0($object) +{ + return $object->installTab(); +}