Skip to content

Commit

Permalink
php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
PrestaSafe committed Jan 26, 2024
1 parent 7b6a624 commit 4674339
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 67 deletions.
6 changes: 3 additions & 3 deletions classes/PrettyBlockCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ protected function filterVars()
* Filter file and replace vars
*
* @param $files
* $files = [
* '$/modules/your_module/views/css/vars.scss'
* ];
* $files = [
* '$/modules/your_module/views/css/vars.scss'
* ];
*
* @return string
*/
Expand Down
46 changes: 23 additions & 23 deletions classes/PrettyBlocksMigrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function addTemplateField()
$sql[] = 'ALTER TABLE `' . _DB_PREFIX_ . 'prettyblocks` ADD `template` longtext DEFAULT NULL AFTER `config`;';
$sql[] = 'ALTER TABLE `' . _DB_PREFIX_ . 'prettyblocks` ADD `default_params` longtext DEFAULT NULL AFTER `config`;';
foreach ($sql as $query) {
$res &= \Db::getInstance()->execute($query);
$res &= Db::getInstance()->execute($query);
}

return $res;
Expand All @@ -29,12 +29,12 @@ public static function migrateConfig()
&& !self::columnExists('prettyblocks', 'default_params')) {
self::addTemplateField();
}
$langs = \Language::getLanguages();
$langs = Language::getLanguages();
$res = true;
$fields = [];
foreach ($langs as $lang) {
$lang_id = $lang['id_lang'];
$blocks = (new \PrestaShopCollection('PrettyBlocksModel', $lang_id))->getAll();
$blocks = (new PrestaShopCollection('PrettyBlocksModel', $lang_id))->getAll();
// get old config
foreach ($blocks as $model) {
$block = $model->mergeStateWithFields();
Expand Down Expand Up @@ -108,10 +108,10 @@ public static function migrateLangTable()
ADD COLUMN id_lang int(11) DEFAULT NULL,
ADD COLUMN state longtext DEFAULT NULL;
';
\Db::getInstance()->execute($sql);
Db::getInstance()->execute($sql);
}

$blocks_lang = \Db::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'prettyblocks_lang');
$blocks_lang = Db::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'prettyblocks_lang');
foreach ($blocks_lang as $block) {
$existingBlock = new PrettyBlocksModel($block['id_prettyblocks']);
$newBlocks = new PrettyBlocksModel();
Expand All @@ -133,7 +133,7 @@ public static function migrateLangTable()
}

$sql = 'DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'prettyblocks_lang';
\Db::getInstance()->execute($sql);
Db::getInstance()->execute($sql);

return true;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ public static function migrateSettings()

// get settings fields:

$settings_on_hooks = \HelperBuilder::hookToArray('ActionRegisterThemeSettings');
$settings_on_hooks = HelperBuilder::hookToArray('ActionRegisterThemeSettings');
$res = [];

foreach ($settings_on_hooks as $key => $field) {
Expand Down Expand Up @@ -320,14 +320,14 @@ private static function _formatSettingsField($name, $type, $params, $context, $b
private static function _getDefaultParams($block)
{
$id_prettyblocks = (int) $block['id_prettyblocks'];
$key = \Tools::strtoupper($id_prettyblocks . '_default_params');
$key = Tools::strtoupper($id_prettyblocks . '_default_params');
// welcome = prettyblocks:views/templates/blocks/welcome.tpl
$options = [
'container' => true,
'load_ajax' => false,
'bg_color' => '',
];
$defaultParams = \Configuration::get($key);
$defaultParams = Configuration::get($key);
if (!$defaultParams) {
return $options;
}
Expand All @@ -345,10 +345,10 @@ private static function _getDefaultParams($block)
private static function _getTemplateSelected($block)
{
$id_prettyblocks = (int) $block['id_prettyblocks'];
$key = \Tools::strtoupper($id_prettyblocks . '_template');
$key = Tools::strtoupper($id_prettyblocks . '_template');
// welcome = prettyblocks:views/templates/blocks/welcome.tpl
$default_tpl = (isset($block['templates']['default'])) ? 'default' : 'welcome';
$currentTemplate = \Configuration::get($key, null, null, (int) $block['id_shop']);
$currentTemplate = Configuration::get($key, null, null, (int) $block['id_shop']);
if ($currentTemplate !== false && isset($block['templates'][$currentTemplate])) {
return $currentTemplate;
}
Expand All @@ -358,41 +358,41 @@ private static function _getTemplateSelected($block)

private static function _formatFieldConfigFront($field, $value, $block, $context = 'front')
{
\FieldFormatter::setSuffix('_config');
FieldFormatter::setSuffix('_config');

switch ($value['type']) {
case 'editor':
return \FieldFormatter::formatFieldText($field, $value, $block, $context);
return FieldFormatter::formatFieldText($field, $value, $block, $context);
break;
case 'text':
return \FieldFormatter::formatFieldText($field, $value, $block, $context);
return FieldFormatter::formatFieldText($field, $value, $block, $context);
break;
case 'textarea':
return \FieldFormatter::formatFieldText($field, $value, $block, $context);
return FieldFormatter::formatFieldText($field, $value, $block, $context);
break;
case 'color':
return \FieldFormatter::formatFieldText($field, $value, $block, $context);
return FieldFormatter::formatFieldText($field, $value, $block, $context);
break;
case 'radio':
return \FieldFormatter::formatFieldBoxes($field, $value, $block, $context);
return FieldFormatter::formatFieldBoxes($field, $value, $block, $context);
break;
case 'checkbox':
return \FieldFormatter::formatFieldBoxes($field, $value, $block, $context);
return FieldFormatter::formatFieldBoxes($field, $value, $block, $context);
break;
case 'fileupload':
return \FieldFormatter::formatFieldUpload($field, $value, $block, $context);
return FieldFormatter::formatFieldUpload($field, $value, $block, $context);
break;
case 'upload':
return \FieldFormatter::formatFieldUpload($field, $value, $block, $context);
return FieldFormatter::formatFieldUpload($field, $value, $block, $context);
break;
case 'selector':
return \FieldFormatter::formatFieldSelector($field, $value, $block, $context);
return FieldFormatter::formatFieldSelector($field, $value, $block, $context);
break;
case 'select':
return \FieldFormatter::formatFieldSelect($field, $value, $block, $context);
return FieldFormatter::formatFieldSelect($field, $value, $block, $context);
break;
case 'radio_group':
return \FieldFormatter::formatFieldRadioGroup($field, $value, $block, $context);
return FieldFormatter::formatFieldRadioGroup($field, $value, $block, $context);
break;
default:
return '';
Expand Down
12 changes: 6 additions & 6 deletions classes/PrettyBlocksModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function setDefaultParams($params)
public function getDefaultParams()
{
$data = json_encode([], true);
if (\Validate::isJson($this->default_params)) {
if (Validate::isJson($this->default_params)) {
$data = $this->default_params;
}

Expand Down Expand Up @@ -508,13 +508,13 @@ public static function getShopById($id)
*/
public static function updateThemeSettings($stateRequest)
{
$context = \Context::getContext();
$context = Context::getContext();

$id_shop = (isset($stateRequest['context']['id_shop'])) ? (int) $stateRequest['context']['id_shop'] : $context->shop->id;
$id_lang = (isset($stateRequest['context']['id_lang'])) ? (int) $stateRequest['context']['id_shop'] : $context->language->id;
$shop = self::getShopById($id_shop);

$profile = \PrettyBlocksSettingsModel::getProfileByTheme($shop['theme_name'], $id_shop);
$profile = PrettyBlocksSettingsModel::getProfileByTheme($shop['theme_name'], $id_shop);

$res = [];
foreach ($stateRequest as $tabs) {
Expand Down Expand Up @@ -921,10 +921,10 @@ public function add($auto_date = true, $null_values = false)
*/
public static function getThemeSettings($with_tabs = true, $context = 'front', $id_shop = null)
{
$context = \Context::getContext();
$context = Context::getContext();
$id_shop = ($id_shop !== null) ? (int) $id_shop : $context->shop->id;
$theme_settings = \HelperBuilder::hookToArray('ActionRegisterThemeSettings');
$settingsDB = \PrettyBlocksSettingsModel::getSettings($context->shop->theme_name, $id_shop);
$theme_settings = HelperBuilder::hookToArray('ActionRegisterThemeSettings');
$settingsDB = PrettyBlocksSettingsModel::getSettings($context->shop->theme_name, $id_shop);
$res = [];
$no_tabs = [];
foreach ($theme_settings as $key => $settings) {
Expand Down
8 changes: 4 additions & 4 deletions controllers/front/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function displayAjaxDeleteAllBlocks()
$zone_name = pSQL(Tools::getValue('zone'));
$id_lang = (int) Tools::getValue('ctx_id_lang');
$id_shop = (int) Tools::getValue('ctx_id_shop');
$success = \PrettyBlocksModel::deleteBlocksFromZone($zone_name, $id_lang, $id_shop);
$success = PrettyBlocksModel::deleteBlocksFromZone($zone_name, $id_lang, $id_shop);
$message = $this->translator->trans('An error has occured during this process', [], 'Modules.Prettyblocks.Admin');
if ($success) {
$message = $this->translator->trans('Blocks deleted with success', [], 'Modules.Prettyblocks.Admin');
Expand All @@ -138,7 +138,7 @@ public function displayAjaxCopyZone()
$id_shop = (int) Tools::getValue('ctx_id_shop');
$zone_name = pSQL(Tools::getValue('zone'));
$zone_name_to_paste = pSQL(Tools::getValue('zone_name_to_paste'));
$success = \PrettyBlocksModel::copyZone($zone_name, $zone_name_to_paste, $id_lang, $id_shop);
$success = PrettyBlocksModel::copyZone($zone_name, $zone_name_to_paste, $id_lang, $id_shop);
$message = $this->translator->trans('An error has occured during this process', [], 'Modules.Prettyblocks.Admin');
if ($success) {
$message = $this->translator->trans('Zone dupplicated with success', [], 'Modules.Prettyblocks.Admin');
Expand All @@ -160,7 +160,7 @@ public function displayAjaxinsertBlock()
$zone_name = pSQL(Tools::getValue('zone_name'));
$id_lang = (int) Tools::getValue('ctx_id_lang');
$id_shop = (int) Tools::getValue('ctx_id_shop');
$state = \PrettyBlocksModel::registerBlockToZone($zone_name, $code, $id_lang, $id_shop);
$state = PrettyBlocksModel::registerBlockToZone($zone_name, $code, $id_lang, $id_shop);

exit(json_encode([
'state' => $state,
Expand Down Expand Up @@ -487,7 +487,7 @@ public function displayAjaxupdateTitleComponent()
$id_prettyblocks = (int) Tools::getValue('id_prettyblocks');
$element = Tools::getValue('element');

$model = new \PrettyBlocksModel($id_prettyblocks, $id_lang, $id_shop);
$model = new PrettyBlocksModel($id_prettyblocks, $id_lang, $id_shop);
$model->mergeStateWithFields();
if (Tools::getIsset('index')) {
// save state
Expand Down
16 changes: 5 additions & 11 deletions prettyblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
use PrestaSafe\PrettyBlocks\Core\Components\Title;
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -159,14 +157,11 @@ public function getContent()
private function getPrettyBlocksUrl()
{
$domain = Tools::getShopDomainSsl(true);

return $domain . Link::getUrlSmarty([
'entity' => 'sf',
'route' => 'admin_prettyblocks',

]);


}

private function loadDefault()
Expand All @@ -176,15 +171,14 @@ private function loadDefault()

public function hookdisplayBackOfficeHeader($params)
{
$route = (new \Link())->getAdminLink('AdminThemeManagerControllerRouteGenerator');
$route = (new Link())->getAdminLink('AdminThemeManagerControllerRouteGenerator');
Media::addJsDef([
'prettyblocks_route_generator' => $route,
'prettyblocks_logo' => HelperBuilder::pathFormattedToUrl('$/modules/prettyblocks/logo.png'),
]);

$this->context->controller->addJS($this->_path.'views/js/back.js');
}

$this->context->controller->addJS($this->_path . 'views/js/back.js');
}

public function install()
{
Expand Down Expand Up @@ -229,7 +223,7 @@ public function getWidgetVariables($hookName = null, array $configuration = [])

public function hookdisplayHeader($params)
{
if ((isset($_SERVER['HTTP_SEC_FETCH_DEST']) && $_SERVER['HTTP_SEC_FETCH_DEST'] == 'iframe') || \Tools::getValue('prettyblocks') === '1') {
if ((isset($_SERVER['HTTP_SEC_FETCH_DEST']) && $_SERVER['HTTP_SEC_FETCH_DEST'] == 'iframe') || Tools::getValue('prettyblocks') === '1') {
$this->context->controller->registerJavascript(
'prettyblocks',
'modules/' . $this->name . '/views/js/build.js',
Expand Down
24 changes: 10 additions & 14 deletions src/Controller/AdminThemeManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,17 @@ public function indexAction()
// url to load at startup : provided url or shop home page
$startup_url = \Tools::getValue('startup_url', $shop_url);

if(\Tools::getValue('endpoint')){
switch(\Tools::getValue('endpoint'))
{
if (\Tools::getValue('endpoint')) {
switch (\Tools::getValue('endpoint')) {
case 'product':
$startup_url = $link->getProductLink((int)\Tools::getValue('id'));
break;
$startup_url = $link->getProductLink((int) \Tools::getValue('id'));
break;
case 'category':
$startup_url = $link->getCategoryLink((int)\Tools::getValue('id'));
break;
$startup_url = $link->getCategoryLink((int) \Tools::getValue('id'));
break;
case 'cms':
$startup_url = $link->getCMSLink((int)\Tools::getValue('id'));
break;
$startup_url = $link->getCMSLink((int) \Tools::getValue('id'));
break;
}
}

Expand Down Expand Up @@ -630,23 +629,20 @@ protected function getLangLink($idLang = null, \Context $context = null, $idShop
return \Language::getIsoById($idLang) . '/';
}


public function routeGeneratorAction(Request $request)
{
$posts = json_decode($request->getContent(), true);
$endpoint = $posts['endpoint'];
$id = (int)$posts['id'];
$id = (int) $posts['id'];

$router = $this->get('router');
$url = $router->generate('admin_prettyblocks', [
'endpoint' => $endpoint,
'id' => $id,
]);

return (new JsonResponse())->setData([
'url' => $url,
]);


}

}
2 changes: 1 addition & 1 deletion upgrade/upgrade-2.0.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
*/
function upgrade_module_2_0_0($module)
{
return \PrettyBlocksMigrate::migrateConfig();
return PrettyBlocksMigrate::migrateConfig();
}
6 changes: 3 additions & 3 deletions upgrade/upgrade-3.0.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
*/
function upgrade_module_3_0_0($module)
{
if (!\PrettyBlocksMigrate::tableExists('prettyblocks_settings')) {
if (!PrettyBlocksMigrate::tableExists('prettyblocks_settings')) {
$module->makeSettingsTable();
}
\PrettyBlocksMigrate::migrateLangTable();
\PrettyBlocksMigrate::migrateSettings();
PrettyBlocksMigrate::migrateLangTable();
PrettyBlocksMigrate::migrateSettings();
$module->registerHook('displayHeader');

return true;
Expand Down
4 changes: 2 additions & 2 deletions upgrade/upgrade-3.0.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
*/
function upgrade_module_3_0_2($module)
{
\Configuration::deleteByName('_PRETTYBLOCKS_TOKEN_');
\Configuration::updateGlobalValue('_PRETTYBLOCKS_TOKEN_', \Tools::passwdGen(25));
Configuration::deleteByName('_PRETTYBLOCKS_TOKEN_');
Configuration::updateGlobalValue('_PRETTYBLOCKS_TOKEN_', Tools::passwdGen(25));

return true;
}

0 comments on commit 4674339

Please sign in to comment.