Skip to content

Commit

Permalink
php-cs-fixer + autoindex
Browse files Browse the repository at this point in the history
  • Loading branch information
PrestaSafe committed Aug 19, 2024
1 parent 996306a commit a649004
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 44 deletions.
37 changes: 17 additions & 20 deletions classes/HelperBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand All @@ -409,65 +411,60 @@ 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]) . ' ';
}
}

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,
];

}

}
16 changes: 6 additions & 10 deletions classes/PrettyBlocksModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 6 additions & 3 deletions classes/prettyblocks/core/FieldCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -234,11 +234,11 @@ public function formatForFront()
|
*/


/**
* formatFieldSlider
* use for display field type slider in PrettyBlocks
* @return Integer
*
* @return int
*/
public function formatFieldSlider()
{
Expand Down Expand Up @@ -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);
}

Expand All @@ -281,6 +283,7 @@ public function formatFieldDatepicker()
if (!$date) {
$date = \DateTime::createFromFormat($format, $this->new_value);
}

return $date ? $date->format($format) : date($format);
}

Expand Down
3 changes: 0 additions & 3 deletions controllers/front/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ public function displayAjaxUpdateState()
}
}


public function displayAjaxGetBlockRender()
{
$id_block = (int) Tools::getValue('id_prettyblocks');
Expand All @@ -476,10 +475,8 @@ public function displayAjaxGetBlockRender()
'html' => $html,
]
));

}


public function displayAjaxBlockRender()
{
// for drag n drop
Expand Down
14 changes: 8 additions & 6 deletions prettyblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Controller/AdminThemeManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,7 +116,6 @@ public function uploadAction(Request $request)
]);
}


private function getShops()
{
$shops = \Shop::getShops();
Expand Down

0 comments on commit a649004

Please sign in to comment.