From a649004971c4435107fce20c30a5dcbbb7444762 Mon Sep 17 00:00:00 2001 From: Prestasafe Date: Mon, 19 Aug 2024 09:53:19 +0200 Subject: [PATCH] php-cs-fixer + autoindex --- classes/HelperBuilder.php | 37 +++++++++---------- classes/PrettyBlocksModel.php | 16 +++----- classes/prettyblocks/core/FieldCore.php | 9 +++-- controllers/front/ajax.php | 3 -- prettyblocks.php | 14 ++++--- .../AdminThemeManagerController.php | 2 - 6 files changed, 37 insertions(+), 44 deletions(-) diff --git a/classes/HelperBuilder.php b/classes/HelperBuilder.php index 553e466a..922faa59 100644 --- a/classes/HelperBuilder.php +++ b/classes/HelperBuilder.php @@ -313,8 +313,8 @@ public static function zoneHasBlock($zone_name) $query->select('COUNT(*)'); $query->from('prettyblocks'); $query->where('zone_name = "' . pSQL($zone_name) . '"'); - $query->where('id_lang = '.(int)$contextPS->language->id); - $query->where('id_shop = '.(int)$contextPS->shop->id); + $query->where('id_lang = ' . (int) $contextPS->language->id); + $query->where('id_shop = ' . (int) $contextPS->shop->id); $count = Db::getInstance()->getValue($query); // Fin de la sélection @@ -395,7 +395,9 @@ public static function getProductsCategory($id_category, $nProducts = 8) * Generate css classes for blocks spacings * classes are imported from tailwindcss with tw_ prefix by default * ex: tw_xs_p-10 tw_md_p-20 tw_lg_p-30 + * * @see tailwindimport.tpl + * * @param array $values * @param string $type * @@ -409,42 +411,40 @@ public static function generateBlocksSpacings($values, $type = 'paddings') $devices = [ 'mobile' => '', 'tablet' => 'lg:', - 'desktop' => 'xl:' + 'desktop' => 'xl:', ]; $sides = ['top', 'right', 'bottom', 'left']; $alias = [ 'paddings' => 'padding', - 'margins' => 'margin' + 'margins' => 'margin', ]; $classesPrefix = []; $stylesArray = []; - foreach($devices as $device => $prefix) { - if(isset($values[$device]["use_custom_data"]) && $values[$device]['use_custom_data'] == true) { + foreach ($devices as $device => $prefix) { + if (isset($values[$device]['use_custom_data']) && $values[$device]['use_custom_data'] == true) { // generate styles - foreach($sides as $side) { + foreach ($sides as $side) { $value = $values[$device][$side]; - if($value !== '') { + if ($value !== '') { if (!preg_match('/(px|rem|em|%|vh|vw|vmin|vmax)$/', $value)) { $value .= 'px'; } - $stylesArray[$device][$side] = $alias[$type] . '-' . $side . ':'. $value; + $stylesArray[$device][$side] = $alias[$type] . '-' . $side . ':' . $value; } } - } else { // generate classes - foreach($sides as $side) { + foreach ($sides as $side) { $value = $values[$device][$side]; // return a format for tailwindcss prefixed with tw_ ex: _xs_t-10 - if($value !== '' && $value !== null) { - $classesPrefix[$device][$side] = $prefix . 'tw_' . substr($type, 0, 1) . substr($side, 0, 1).'-'. $value ; + if ($value !== '' && $value !== null) { + $classesPrefix[$device][$side] = $prefix . 'tw_' . substr($type, 0, 1) . substr($side, 0, 1) . '-' . $value; } } } } - foreach ($devices as $breakpoint => $prefix) { if (!empty($classesPrefix[$breakpoint])) { $cssClasses .= implode(' ', $classesPrefix[$breakpoint]) . ' '; @@ -452,22 +452,19 @@ public static function generateBlocksSpacings($values, $type = 'paddings') } foreach ($devices as $breakpoint => $prefix) { - if (!empty($stylesArray[$breakpoint])) { $pfx = rtrim($prefix, ':'); - if($pfx == '') { + if ($pfx == '') { $pfx = 'sm'; } $style = 'style-' . $pfx; - $stylesCss .= $style. '=' . implode(';', $stylesArray[$breakpoint]).' ' ; + $stylesCss .= $style . '=' . implode(';', $stylesArray[$breakpoint]) . ' '; } } return [ 'classes' => rtrim($cssClasses), - 'styles' => $stylesCss + 'styles' => $stylesCss, ]; - } - } diff --git a/classes/PrettyBlocksModel.php b/classes/PrettyBlocksModel.php index 0aa19794..9e610d83 100644 --- a/classes/PrettyBlocksModel.php +++ b/classes/PrettyBlocksModel.php @@ -248,25 +248,22 @@ public function mergeStateWithFields() // die(); // } - $block['classes'] = ''; - if($paddings !== '') { + if ($paddings !== '') { $block['classes'] .= $paddings; } - if($margins !== '') { - $block['classes'] .= ' '.$margins; + if ($margins !== '') { + $block['classes'] .= ' ' . $margins; } $block['styles'] = ''; - if($paddingStyles !== '') { + if ($paddingStyles !== '') { $block['styles'] .= $paddingStyles; } - if($marginStyles !== '') { - $block['styles'] .= ' '.$marginStyles; + if ($marginStyles !== '') { + $block['styles'] .= ' ' . $marginStyles; } - - $block['settings_formatted'] = $this->_formatConfig($block, 'back'); $block['repeater_db'] = $this->_formatRepeaterDb($states, $repeaterDefault); @@ -1021,7 +1018,6 @@ public static function getThemeSettings($with_tabs = true, $context = 'front', $ $no_tabs = []; foreach ($theme_settings as $key => $settings) { - if (isset($settings['private']) && $settings['private'] === true && $context == 'front') { continue; } diff --git a/classes/prettyblocks/core/FieldCore.php b/classes/prettyblocks/core/FieldCore.php index 49d48799..9dba1f2d 100644 --- a/classes/prettyblocks/core/FieldCore.php +++ b/classes/prettyblocks/core/FieldCore.php @@ -149,7 +149,7 @@ public function compile() if ($this->force_default_value) { $data['force_default_value'] = $this->force_default_value; } - if($this->options) { + if ($this->options) { $data['options'] = $this->options; } @@ -234,11 +234,11 @@ public function formatForFront() | */ - /** * formatFieldSlider * use for display field type slider in PrettyBlocks - * @return Integer + * + * @return int */ public function formatFieldSlider() { @@ -268,11 +268,13 @@ public function formatFieldDatepicker() // if value exists in DB and new_value is empty if (!is_null($this->value) && is_null($this->new_value)) { $date = \DateTime::createFromFormat($format, $this->value); + return $date ? $date->format($format) : date($format); } // if value doesn't exists in DB and new value is set if ($this->force_default_value && is_null($this->new_value)) { $date = \DateTime::createFromFormat($format, $this->default); + return $date ? $date->format($format) : date($format); } @@ -281,6 +283,7 @@ public function formatFieldDatepicker() if (!$date) { $date = \DateTime::createFromFormat($format, $this->new_value); } + return $date ? $date->format($format) : date($format); } diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 27377224..6651324b 100644 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -459,7 +459,6 @@ public function displayAjaxUpdateState() } } - public function displayAjaxGetBlockRender() { $id_block = (int) Tools::getValue('id_prettyblocks'); @@ -476,10 +475,8 @@ public function displayAjaxGetBlockRender() 'html' => $html, ] )); - } - public function displayAjaxBlockRender() { // for drag n drop diff --git a/prettyblocks.php b/prettyblocks.php index 32da7b0e..8fff9a94 100755 --- a/prettyblocks.php +++ b/prettyblocks.php @@ -22,6 +22,7 @@ use PrestaSafe\PrettyBlocks\Core\Components\Title; use PrestaShop\PrestaShop\Core\Module\WidgetInterface; use Symfony\Component\Dotenv\Dotenv; + if (!defined('_PS_VERSION_')) { exit; } @@ -163,17 +164,18 @@ public function isUsingNewTranslationSystem() /** * get .env parameters + * * @return void */ public function loadDotEnv() { - // register .env - $env_file = _PS_MODULE_DIR_ . '/prettyblocks/.env'; + // register .env + $env_file = _PS_MODULE_DIR_ . '/prettyblocks/.env'; - if (file_exists($env_file)) { - $dotenv = new Dotenv(); - $dotenv->load($env_file); - } + if (file_exists($env_file)) { + $dotenv = new Dotenv(); + $dotenv->load($env_file); + } } /** diff --git a/src/Controller/AdminThemeManagerController.php b/src/Controller/AdminThemeManagerController.php index 90f8683d..d52257ea 100644 --- a/src/Controller/AdminThemeManagerController.php +++ b/src/Controller/AdminThemeManagerController.php @@ -22,7 +22,6 @@ // use Doctrine\Common\Cache\CacheProvider; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; - use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; @@ -117,7 +116,6 @@ public function uploadAction(Request $request) ]); } - private function getShops() { $shops = \Shop::getShops();