Subida del módulo y tema de PrestaShop

This commit is contained in:
Kaloyan
2026-04-09 18:31:51 +02:00
parent 12c253296f
commit 16b3ff9424
39262 changed files with 7418797 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
<?php
$config = new PrestaShop\CodingStandards\CsFixer\Config();
$config
->setUsingCache(true)
->getFinder()
->in(__DIR__)
->exclude('vendor');
return $config;

2483
modules/ps_linklist/composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>ps_linklist</name>
<displayName><![CDATA[Link List]]></displayName>
<version><![CDATA[7.0.1]]></version>
<description><![CDATA[Adds a block with several links.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
<is_configurable>1</is_configurable>
<need_instance>0</need_instance>
<limited_countries></limited_countries>
</module>

View File

@@ -0,0 +1,143 @@
services:
_defaults:
public: false
autowire: true
autoconfigure: true
PrestaShop\Module\LinkList\Controller\Admin\Improve\Design\LinkBlockController: ~
# Link block form handler
prestashop.module.link_block.form_handler:
class: 'PrestaShop\PrestaShop\Core\Form\FormHandler'
arguments:
$formBuilder: '@=service("form.factory").createBuilder()'
$hookDispatcher: '@prestashop.core.hook.dispatcher'
$formDataProvider: '@PrestaShop\Module\LinkList\Form\LinkBlockFormDataProvider'
$formTypes:
'link_block': 'PrestaShop\Module\LinkList\Form\Type\LinkBlockType'
$hookName: 'AdminLinkWidget'
# Link block form data provider
PrestaShop\Module\LinkList\Form\LinkBlockFormDataProvider:
arguments:
$repository: '@PrestaShop\Module\LinkList\Repository\LinkBlockRepository'
$cache: '@PrestaShop\Module\LinkList\Cache\LegacyLinkBlockCache'
$languages: '@=service("prestashop.adapter.legacy.context").getLanguages(false, service("prestashop.adapter.shop.context").getContextShopID())'
$shopContext: '@prestashop.adapter.shop.context'
$configuration: '@prestashop.adapter.legacy.configuration'
PrestaShop\Module\LinkList\Cache\LegacyLinkBlockCache: ~
# Form types
PrestaShop\Module\LinkList\Form\Type\LinkBlockType:
parent: 'form.type.translatable.aware'
arguments:
$hookChoices: '@=service("prestashop.module.link_block.choice_provider.hook").getChoices()'
$cmsPageChoices: '@=service("prestashop.module.link_block.choice_provider.cms_page").getChoices()'
$productPageChoices: '@=service("prestashop.module.link_block.choice_provider.product_page").getChoices()'
$staticPageChoices: '@=service("prestashop.module.link_block.choice_provider.static_page").getChoices()'
$categoryChoices: '@=service("prestashop.module.link_block.choice_provider.category").getChoices()'
$isMultiStoreUsed: '@=service("prestashop.adapter.feature.multistore").isUsed()'
tags:
- { name: form.type }
PrestaShop\Module\LinkList\Form\Type\CustomUrlType:
parent: 'form.type.translatable.aware'
tags:
- { name: form.type }
PrestaShop\Module\LinkList\Form\Type\TranslateCustomUrlType:
parent: 'form.type.translatable.aware'
public: true
arguments:
- "@=service('prestashop.adapter.legacy.context').getAvailableLanguages()"
- '@router.default'
- "@=service('prestashop.adapter.legacy.configuration').getBoolean('PS_BO_ALLOW_EMPLOYEE_FORM_LANG')"
- "@=service('prestashop.adapter.legacy.context').getContext().cookie.employee_form_lang"
- "@=service('prestashop.adapter.legacy.configuration').getInt('PS_LANG_DEFAULT')"
tags:
- { name: form.type }
# Grid data query builder
prestashop.module.link_block.grid.query_builder:
class: PrestaShop\Module\LinkList\Core\Grid\Query\LinkBlockQueryBuilder
arguments:
$connection: '@doctrine.dbal.default_connection'
$dbPrefix: '%database_prefix%'
# Grid Data Factory
prestashop.module.link_block.grid.data_factory:
class: '%prestashop.core.grid.data.factory.doctrine_grid_data_factory%'
arguments:
$gridQueryBuilder: '@prestashop.module.link_block.grid.query_builder'
$hookDispatcher: '@prestashop.core.hook.dispatcher'
$queryParser: '@prestashop.core.grid.query.doctrine_query_parser'
$gridId: 'link_block'
# Link block grid Factory
PrestaShop\Module\LinkList\Core\Grid\LinkBlockGridFactory:
arguments:
$translator: '@translator'
$hookDispatcher: '@prestashop.core.hook.dispatcher'
$dataFactory: '@prestashop.module.link_block.grid.data_factory'
$filterFormFactory: '@prestashop.core.grid.filter.form_factory'
$shopContext: '@prestashop.adapter.shop.context'
# Form choices providers
prestashop.module.link_block.choice_provider.hook:
class: PrestaShop\Module\LinkList\Form\ChoiceProvider\HookChoiceProvider
arguments:
$connection: '@doctrine.dbal.default_connection'
$dbPrefix: '%database_prefix%'
prestashop.module.link_block.choice_provider.cms_category:
class: PrestaShop\Module\LinkList\Form\ChoiceProvider\CMSCategoryChoiceProvider
arguments:
$connection: '@doctrine.dbal.default_connection'
$dbPrefix: '%database_prefix%'
$idLang: '@=service("prestashop.adapter.legacy.context").getLanguage().id'
$shopIds: '@=service("prestashop.adapter.shop.context").getContextListShopID()'
prestashop.module.link_block.choice_provider.category:
class: PrestaShop\Module\LinkList\Form\ChoiceProvider\CategoryChoiceProvider
arguments:
$connection: '@doctrine.dbal.default_connection'
$dbPrefix: '%database_prefix%'
$idLang: '@=service("prestashop.adapter.legacy.context").getLanguage().id'
$shopIds: '@=service("prestashop.adapter.shop.context").getContextListShopID()'
prestashop.module.link_block.choice_provider.cms_page:
class: PrestaShop\Module\LinkList\Form\ChoiceProvider\CMSPageChoiceProvider
arguments:
$connection: '@doctrine.dbal.default_connection'
$dbPrefix: '%database_prefix%'
$categories: '@=service("prestashop.module.link_block.choice_provider.cms_category").getChoices()'
$idLang: '@=service("prestashop.adapter.legacy.context").getLanguage().id'
$shopIds: '@=service("prestashop.adapter.shop.context").getContextListShopID()'
prestashop.module.link_block.choice_provider.product_page:
class: PrestaShop\Module\LinkList\Form\ChoiceProvider\PageChoiceProvider
arguments:
$connection: '@doctrine.dbal.default_connection'
$dbPrefix: '%database_prefix%'
$idLang: '@=service("prestashop.adapter.legacy.context").getLanguage().id'
$shopIds: '@=service("prestashop.adapter.shop.context").getContextListShopID()'
$pageNames:
- 'prices-drop'
- 'new-products'
- 'best-sales'
prestashop.module.link_block.choice_provider.static_page:
class: PrestaShop\Module\LinkList\Form\ChoiceProvider\PageChoiceProvider
arguments:
$connection: '@doctrine.dbal.default_connection'
$dbPrefix: '%database_prefix%'
$idLang: '@=service("prestashop.adapter.legacy.context").getLanguage().id'
$shopIds: '@=service("prestashop.adapter.shop.context").getContextListShopID()'
$pageNames:
- 'contact'
- 'sitemap'
- 'stores'
- 'authentication'
- 'registration'
- 'my-account'

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,53 @@
admin_link_block_list:
path: /link-widget/list
methods: [GET]
defaults:
_controller: 'PrestaShop\Module\LinkList\Controller\Admin\Improve\Design\LinkBlockController::listAction'
_legacy_controller: AdminLinkWidget
_legacy_link: AdminLinkWidget
admin_link_block_create:
path: /link-widget/create
methods: [GET]
defaults:
_controller: 'PrestaShop\Module\LinkList\Controller\Admin\Improve\Design\LinkBlockController::createAction'
_legacy_controller: AdminLinkWidget
admin_link_block_create_process:
path: /link-widget/create
methods: [POST]
defaults:
_controller: 'PrestaShop\Module\LinkList\Controller\Admin\Improve\Design\LinkBlockController::createProcessAction'
_legacy_controller: AdminLinkWidget
admin_link_block_edit:
path: /link-widget/edit/{linkBlockId}
methods: [GET]
defaults:
_controller: 'PrestaShop\Module\LinkList\Controller\Admin\Improve\Design\LinkBlockController::editAction'
_legacy_controller: AdminLinkWidget
admin_link_block_edit_process:
path: /link-widget/edit/{linkBlockId}
methods: [POST]
defaults:
_controller: 'PrestaShop\Module\LinkList\Controller\Admin\Improve\Design\LinkBlockController::editProcessAction'
_legacy_controller: AdminLinkWidget
admin_link_block_delete:
path: /link-widget/delete/{linkBlockId}
methods: [POST]
defaults:
_controller: 'PrestaShop\Module\LinkList\Controller\Admin\Improve\Design\LinkBlockController::deleteAction'
_legacy_controller: AdminLinkWidget
requirements:
linkBlockId: \d+
admin_link_block_update_positions:
path: /link-widget/update-positions/{hookId}
methods: [POST]
defaults:
_controller: 'PrestaShop\Module\LinkList\Controller\Admin\Improve\Design\LinkBlockController::updatePositionsAction'
_legacy_controller: AdminLinkWidget
requirements:
hookId: \d+

View File

@@ -0,0 +1,19 @@
services:
_defaults:
public: true
PrestaShop\Module\LinkList\Repository\LinkBlockRepository:
arguments:
$connection: '@doctrine.dbal.default_connection'
$dbPrefix: '%database_prefix%'
$languages: '@=service("prestashop.adapter.legacy.context").getLanguages(false, service("prestashop.adapter.shop.context").getContextShopID())'
$translator: '@translator'
$isMultiStoreUsed: '@=service("prestashop.adapter.feature.multistore").isUsed()'
$multiStoreContext: '@prestashop.adapter.shop.context'
$objectModelHandler: '@prestashop.module.link_block.adapter.object_model_handler'
prestashop.module.link_block.repository:
alias: PrestaShop\Module\LinkList\Repository\LinkBlockRepository
prestashop.module.link_block.adapter.object_model_handler:
class: 'PrestaShop\Module\LinkList\Adapter\ObjectModelHandler'

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

View File

@@ -0,0 +1,336 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
if (!defined('_PS_VERSION_')) {
exit;
}
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
}
use PrestaShop\Module\LinkList\DataMigration;
use PrestaShop\Module\LinkList\Filter\BestSalesRouteFilter;
use PrestaShop\Module\LinkList\Filter\LinkFilter;
use PrestaShop\Module\LinkList\LegacyLinkBlockRepository;
use PrestaShop\Module\LinkList\Model\LinkBlockLang;
use PrestaShop\Module\LinkList\Presenter\LinkBlockPresenter;
use PrestaShop\Module\LinkList\Repository\LinkBlockRepository;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
/**
* Class Ps_Linklist.
*/
class Ps_Linklist extends Module implements WidgetInterface
{
/**
* @var string Name of the module running on PS 1.6.x. Used for data migration.
*/
const PS_16_EQUIVALENT_MODULE = 'blockcms';
const MODULE_NAME = 'ps_linklist';
protected $_html;
protected $_display;
/**
* @var LinkBlockPresenter
*/
private $linkBlockPresenter;
/**
* @var LegacyLinkBlockRepository
*/
private $legacyBlockRepository;
/**
* @var LinkBlockRepository|LegacyLinkBlockRepository|null
*/
private $repository;
public $templateFile;
/**
* @var string
*/
public $templateFileColumn;
public function __construct()
{
$this->name = 'ps_linklist';
$this->author = 'PrestaShop';
$this->version = '7.0.1';
$this->need_instance = 0;
$this->tab = 'front_office_features';
$tabNames = [];
foreach (Language::getLanguages(true) as $lang) {
$tabNames[$lang['locale']] = $this->trans('Link List', [], 'Modules.Linklist.Admin', $lang['locale']);
}
$this->tabs = [
[
'route_name' => 'admin_link_block_list',
'class_name' => 'AdminLinkWidget',
'visible' => true,
'name' => $tabNames,
'parent_class_name' => 'AdminParentThemes',
'wording' => 'Link List',
'wording_domain' => 'Modules.Linklist.Admin',
],
];
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->trans('Link List', [], 'Modules.Linklist.Admin');
$this->description = $this->trans('Give more visibility to your content/static pages (CMS, external pages, or else), where you want and when you want, to make your visitors feel like shopping on your store.', [], 'Modules.Linklist.Admin');
$this->ps_versions_compliancy = ['min' => '9.0.0', 'max' => _PS_VERSION_];
$this->templateFile = 'module:ps_linklist/views/templates/hook/linkblock.tpl';
$this->templateFileColumn = 'module:ps_linklist/views/templates/hook/linkblock-column.tpl';
$this->linkBlockPresenter = new LinkBlockPresenter(
new Link(),
$this->context->language,
new LinkFilter([
new BestSalesRouteFilter(),
])
);
$this->legacyBlockRepository = new LegacyLinkBlockRepository(Db::getInstance(), $this->context->shop, $this->context->getTranslator());
}
public function install()
{
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
}
if (!parent::install()) {
return false;
}
$tablesInstalledWithSuccess = $this->createTables();
if (!$tablesInstalledWithSuccess) {
$this->uninstall();
return false;
}
$old16ModuleUninstalledWithSuccess = $this->uninstallPrestaShop16Module();
if ($old16ModuleUninstalledWithSuccess) {
(new DataMigration(Db::getInstance()))->migrateData();
$dataLoadedWithSuccess = true;
} else {
$dataLoadedWithSuccess = $this->installFixtures();
}
$dataLoadedWithSuccess = $dataLoadedWithSuccess
&& $this->registerHook('displayFooter')
&& $this->registerHook('actionUpdateLangAfter')
&& $this->registerHook('actionGeneralPageSave');
if ($dataLoadedWithSuccess) {
return true;
}
$this->uninstall();
return false;
}
/**
* @return bool
*
* @throws \Doctrine\DBAL\Exception
*/
private function createTables()
{
$result = $this->getRepository()->createTables();
if (false === $result || (is_array($result) && !empty($result))) {
if (is_array($result)) {
$this->addModuleErrors($result);
}
return false;
}
return true;
}
/**
* @return bool
*
* @throws \Doctrine\DBAL\Exception
*/
private function installFixtures()
{
$result = $this->getRepository()->installFixtures();
if (false === $result || (is_array($result) && !empty($result))) {
if (is_array($result)) {
$this->addModuleErrors($result);
}
return false;
}
return true;
}
public function uninstall()
{
$uninstalled = true;
$result = $this->getRepository()->dropTables();
if (false === $result || (is_array($result) && !empty($result))) {
if (is_array($result)) {
$this->addModuleErrors($result);
}
$uninstalled = false;
}
return $uninstalled && parent::uninstall();
}
/**
* Migrate data from 1.6 equivalent module (if applicable), then uninstall
*/
private function uninstallPrestaShop16Module()
{
if (!Module::isInstalled(self::PS_16_EQUIVALENT_MODULE)) {
return false;
}
$oldModule = Module::getInstanceByName(self::PS_16_EQUIVALENT_MODULE);
if ($oldModule) {
// This closure calls the parent class to prevent data to be erased
// It allows the new module to be configured without migration
$parentUninstallClosure = function () {
return parent::uninstall();
};
$parentUninstallClosure = $parentUninstallClosure->bindTo($oldModule, get_class($oldModule));
$parentUninstallClosure();
}
return true;
}
public function hookActionUpdateLangAfter($params)
{
if (!empty($params['lang']) && $params['lang'] instanceof Language) {
Language::updateMultilangFromClass(_DB_PREFIX_ . 'link_block_lang', LinkBlockLang::class, $params['lang']);
}
}
public function hookActionGeneralPageSave()
{
$this->_clearCache('');
}
public function _clearCache($template, $cache_id = null, $compile_id = null)
{
return array_sum([
parent::_clearCache($this->templateFile),
parent::_clearCache($this->templateFileColumn),
]);
}
public function getContent()
{
// We need to explicitely get Symfony container, because $this->get will use the admin legacy container
$sfContainer = SymfonyContainer::getInstance();
$router = $sfContainer->get('router');
Tools::redirectAdmin(
$router->generate('admin_link_block_list')
);
}
public function renderWidget($hookName, array $configuration)
{
$key = 'ps_linklist|' . $hookName;
if (
in_array($hookName, [
'displayLeftColumn',
'displayLeftColumnProduct',
'displayRightColumn',
'displayRightColumnProduct',
])
) {
$template = $this->templateFileColumn;
} else {
$template = $this->templateFile;
}
if (!$this->isCached($template, $this->getCacheId($key))) {
$this->smarty->assign($this->getWidgetVariables($hookName, $configuration));
}
return $this->fetch($template, $this->getCacheId($key));
}
public function getWidgetVariables($hookName, array $configuration)
{
$id_hook = Hook::getIdByName($hookName);
$linkBlocks = $this->legacyBlockRepository->getByIdHook($id_hook);
$blocks = [];
foreach ($linkBlocks as $block) {
$blocks[] = $this->linkBlockPresenter->present($block);
}
return [
'linkBlocks' => $blocks,
'hookName' => $hookName,
];
}
/**
* @param array $errors
*/
private function addModuleErrors(array $errors)
{
foreach ($errors as $error) {
$this->_errors[] = $this->trans($error['key'], $error['parameters'], $error['domain']);
}
}
/**
* @return LinkBlockRepository|LegacyLinkBlockRepository
*/
private function getRepository()
{
if (null === $this->repository) {
try {
$this->repository = $this->get('prestashop.module.link_block.repository');
} catch (Throwable $e) {
try {
$container = SymfonyContainer::getInstance();
if (null !== $container) {
$this->repository = $container->get('prestashop.module.link_block.repository');
}
} catch (Throwable $e) {
}
}
}
// Container is not available so we use legacy repository as fallback
if (!$this->repository) {
$this->repository = $this->legacyBlockRepository;
}
return $this->repository;
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Adapter;
use PrestaShop\Module\LinkList\Model\LinkBlock;
use PrestaShop\PrestaShop\Adapter\Domain\AbstractObjectModelHandler;
class ObjectModelHandler extends AbstractObjectModelHandler
{
/**
* @param int $linkBlockId
* @param array $associatedShops
* @param bool $forceAssociate
*/
public function handleMultiShopAssociation(
int $linkBlockId,
array $associatedShops,
bool $forceAssociate = false
): void {
$objectModel = new LinkBlock($linkBlockId);
/*
* Why we want to force association?
* It's easier to work on multi-store tables even when feature is disabled
* This way we can force association to store as legacy ObjectModel does
* We need to remember that multi-store is always there, shop tables are always there
*
* @todo: this should be part of AbstractObjectModelHandler
*/
if ($forceAssociate) {
$objectModel->associateTo($associatedShops);
return;
}
$this->associateWithShops($objectModel, $associatedShops);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Cache;
use Module;
use Ps_Linklist;
/**
* Class LegacyBlockCache.
*/
final class LegacyLinkBlockCache implements LinkBlockCacheInterface
{
/**
* {@inheritdoc}
*/
public function clearModuleCache()
{
/** @var Ps_Linklist $module */
$module = Module::getInstanceByName(Ps_Linklist::MODULE_NAME);
$module->_clearCache($module->templateFile);
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Cache;
/**
* Interface LinkBlockCacheInterface.
*/
interface LinkBlockCacheInterface
{
/**
* Clear module cache.
*/
public function clearModuleCache();
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,235 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Controller\Admin\Improve\Design;
use PrestaShop\Module\LinkList\Cache\LegacyLinkBlockCache;
use PrestaShop\Module\LinkList\Core\Grid\LinkBlockGridFactory;
use PrestaShop\Module\LinkList\Core\Search\Filters\LinkBlockFilters;
use PrestaShop\Module\LinkList\Form\LinkBlockFormDataProvider;
use PrestaShop\Module\LinkList\Repository\LinkBlockRepository;
use PrestaShop\PrestaShop\Core\Context\ShopContext;
use PrestaShop\PrestaShop\Core\Exception\DatabaseException;
use PrestaShop\PrestaShop\Core\Form\FormHandlerInterface;
use PrestaShopBundle\Controller\Admin\PrestaShopAdminController;
use PrestaShopBundle\Security\Attribute\AdminSecurity;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class LinkBlockController extends PrestaShopAdminController
{
#[AdminSecurity("is_granted('read', request.get('_legacy_controller'))", redirectRoute: 'admin_homepage')]
public function listAction(Request $request, LinkBlockRepository $repository, LinkBlockGridFactory $linkBlockGridFactory): Response
{
// Get hook list, then loop through hooks setting it in the filter
$hooks = $repository->getHooksWithLinks();
$filtersParams = $this->buildFiltersParamsByRequest($request);
$grids = $linkBlockGridFactory->getGrids($hooks, $filtersParams);
$presentedGrids = [];
foreach ($grids as $grid) {
$presentedGrids[] = $this->presentGrid($grid);
}
$presentedGrids = array_filter(
$presentedGrids,
function ($grid) {
return $grid['data']['records_total'] > 0;
}
);
return $this->render('@Modules/ps_linklist/views/templates/admin/link_block/list.html.twig', [
'grids' => $presentedGrids,
'enableSidebar' => true,
'layoutHeaderToolbarBtn' => $this->getToolbarButtons(),
'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
]);
}
#[AdminSecurity("is_granted('create', request.get('_legacy_controller'))", redirectRoute: 'admin_homepage')]
public function createAction(
Request $request,
LinkBlockFormDataProvider $linkBlockFormDataProvider,
#[Autowire(service: 'prestashop.module.link_block.form_handler')]
FormHandlerInterface $formHandler,
): Response {
$linkBlockFormDataProvider->setIdLinkBlock(null);
$form = $formHandler->getForm();
return $this->render('@Modules/ps_linklist/views/templates/admin/link_block/form.html.twig', [
'linkBlockForm' => $form->createView(),
'enableSidebar' => true,
'layoutHeaderToolbarBtn' => $this->getToolbarButtons(),
'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
]);
}
#[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_homepage')]
public function editAction(
Request $request,
int $linkBlockId,
LinkBlockFormDataProvider $linkBlockFormDataProvider,
#[Autowire(service: 'prestashop.module.link_block.form_handler')]
FormHandlerInterface $formHandler,
): Response {
$linkBlockFormDataProvider->setIdLinkBlock($linkBlockId);
$form = $formHandler->getForm();
return $this->render('@Modules/ps_linklist/views/templates/admin/link_block/form.html.twig', [
'linkBlockForm' => $form->createView(),
'enableSidebar' => true,
'layoutHeaderToolbarBtn' => $this->getToolbarButtons(),
'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
]);
}
#[AdminSecurity("is_granted('create', request.get('_legacy_controller'))", redirectRoute: 'admin_homepage')]
public function createProcessAction(
Request $request,
LinkBlockFormDataProvider $formProvider,
#[Autowire(service: 'prestashop.module.link_block.form_handler')]
FormHandlerInterface $formHandler,
): RedirectResponse|Response {
return $this->processForm($request, 'Successful creation.', null, $formProvider, $formHandler);
}
#[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_homepage')]
public function editProcessAction(
Request $request,
int $linkBlockId,
LinkBlockFormDataProvider $formProvider,
#[Autowire(service: 'prestashop.module.link_block.form_handler')]
FormHandlerInterface $formHandler,
): RedirectResponse|Response {
return $this->processForm($request, 'Successful update.', $linkBlockId, $formProvider, $formHandler);
}
#[AdminSecurity("is_granted('delete', request.get('_legacy_controller'))", redirectRoute: 'admin_homepage')]
public function deleteAction(
int $linkBlockId,
LegacyLinkBlockCache $linkBlockCache,
LinkBlockRepository $linkBlockRepository,
): RedirectResponse {
$errors = [];
try {
$linkBlockRepository->delete($linkBlockId);
} catch (DatabaseException) {
$errors[] = [
'key' => 'Could not delete #%i',
'domain' => 'Admin.Catalog.Notification',
'parameters' => [$linkBlockId],
];
}
if (0 === count($errors)) {
$linkBlockCache->clearModuleCache();
$this->addFlash('success', $this->trans('Successful deletion.', [], 'Admin.Notifications.Success'));
} else {
$this->addFlashErrors($errors);
}
return $this->redirectToRoute('admin_link_block_list');
}
#[AdminSecurity("is_granted('update', request.get('_legacy_controller'))", redirectRoute: 'admin_homepage')]
public function updatePositionsAction(
Request $request,
int $hookId,
LegacyLinkBlockCache $linkBlockCache,
LinkBlockRepository $linkBlockRepository,
ShopContext $shopContext,
): RedirectResponse {
$positionsData = [
'positions' => $request->request->all()['positions'],
'parentId' => $hookId,
];
try {
$linkBlockRepository->updatePositions($shopContext->getId(), $positionsData);
$linkBlockCache->clearModuleCache();
$this->addFlash('success', $this->trans('Successful update.', [], 'Admin.Notifications.Success'));
} catch (DatabaseException $e) {
$errors = [$e->getMessage()];
$this->addFlashErrors($errors);
}
return $this->redirectToRoute('admin_link_block_list');
}
private function processForm(
Request $request,
string $successMessage,
?int $linkBlockId,
LinkBlockFormDataProvider $formProvider,
#[Autowire(service: 'prestashop.module.link_block.form_handler')]
FormHandlerInterface $formHandler,
): RedirectResponse|Response {
$formProvider->setIdLinkBlock($linkBlockId);
$form = $formHandler->getForm();
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$saveErrors = $formHandler->save($form->getData());
if (0 === count($saveErrors)) {
$this->addFlash('success', $this->trans($successMessage, [], 'Admin.Notifications.Success'));
return $this->redirectToRoute('admin_link_block_list');
}
$this->addFlashErrors($saveErrors);
}
$formErrors = [];
foreach ($form->getErrors(true) as $error) {
$formErrors[] = $error->getMessage();
}
$this->addFlashErrors($formErrors);
}
return $this->render('@Modules/ps_linklist/views/templates/admin/link_block/form.html.twig', [
'linkBlockForm' => $form->createView(),
'enableSidebar' => true,
'layoutHeaderToolbarBtn' => $this->getToolbarButtons(),
'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
]);
}
protected function buildFiltersParamsByRequest(Request $request): array
{
$filtersParams = array_merge(LinkBlockFilters::getDefaults(), $request->query->all());
return $filtersParams;
}
/**
* Gets the header toolbar buttons.
*/
private function getToolbarButtons(): array
{
return [
'add' => [
'href' => $this->generateUrl('admin_link_block_create'),
'desc' => $this->trans('New block', [], 'Modules.Linklist.Admin'),
'icon' => 'add_circle_outline',
],
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,165 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Core\Grid\Definition\Factory;
use PrestaShop\PrestaShop\Core\Grid\Action\Row\RowActionCollection;
use PrestaShop\PrestaShop\Core\Grid\Action\Row\Type\LinkRowAction;
use PrestaShop\PrestaShop\Core\Grid\Action\Row\Type\SubmitRowAction;
use PrestaShop\PrestaShop\Core\Grid\Column\ColumnCollection;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ActionColumn;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\PositionColumn;
use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory;
use PrestaShop\PrestaShop\Core\Hook\HookDispatcherInterface;
use PrestaShop\PrestaShop\Core\Multistore\MultistoreContextCheckerInterface;
/**
* Class LinkBlockDefinitionFactory.
*/
final class LinkBlockDefinitionFactory extends AbstractGridDefinitionFactory
{
const FACTORY_ID = 'link_widget_grid_';
/**
* @var array
*/
private $hook;
/**
* @var MultistoreContextCheckerInterface
*/
private $multistoreContextChecker;
/**
* LinkBlockDefinitionFactory constructor.
*
* @param array $hook
* @param MultistoreContextCheckerInterface $multistoreContextChecker
*/
public function __construct(
array $hook,
MultistoreContextCheckerInterface $multistoreContextChecker,
HookDispatcherInterface $hookDispatcher
) {
parent::__construct($hookDispatcher);
$this->hook = $hook;
$this->multistoreContextChecker = $multistoreContextChecker;
}
/**
* {@inheritdoc}
*/
protected function getId()
{
return self::FACTORY_ID . $this->hook['id_hook'];
}
/**
* {@inheritdoc}
*/
protected function getName()
{
return $this->hook['name'] . ' ' . $this->hook['title'];
}
/**
* {@inheritdoc}
*/
protected function getColumns()
{
$columns = (new ColumnCollection())
->add(
(new DataColumn('id_link_block'))
->setName($this->trans('ID', [], 'Modules.Linklist.Admin'))
->setOptions([
'field' => 'id_link_block',
])
)
->add(
(new DataColumn('block_name'))
->setName($this->trans('Name of the block', [], 'Modules.Linklist.Admin'))
->setOptions([
'field' => 'block_name',
])
)
->add(
(new ActionColumn('actions'))
->setOptions([
'actions' => (new RowActionCollection())
->add(
(new LinkRowAction('edit'))
->setIcon('edit')
->setOptions([
'route' => 'admin_link_block_edit',
'route_param_name' => 'linkBlockId',
'route_param_field' => 'id_link_block',
])
)
->add(
(new SubmitRowAction('delete'))
->setName($this->trans('Delete', [], 'Admin.Actions'))
->setIcon('delete')
->setOptions([
'method' => 'POST',
'route' => 'admin_link_block_delete',
'route_param_name' => 'linkBlockId',
'route_param_field' => 'id_link_block',
'confirm_message' => $this->trans(
'Delete selected item?',
[],
'Admin.Notifications.Warning'
),
])
),
])
)
;
if ($this->multistoreContextChecker->isSingleShopContext()) {
$columns->addBefore(
'actions',
(new PositionColumn('position'))
->setName($this->trans('Position', [], 'Admin.Global'))
->setOptions([
'id_field' => 'id_link_block',
'position_field' => 'position',
'update_route' => 'admin_link_block_update_positions',
'update_method' => 'POST',
'record_route_params' => [
'id_hook' => 'hookId',
],
])
);
} else {
$columns->addBefore(
'actions',
(new DataColumn('shop_name'))
->setName($this->trans('Shop', [], 'Admin.Global'))
->setOptions([
'field' => 'shop_name',
'sortable' => false,
])
);
}
return $columns;
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,129 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Core\Grid;
use PrestaShop\Module\LinkList\Core\Grid\Definition\Factory\LinkBlockDefinitionFactory;
use PrestaShop\Module\LinkList\Core\Search\Filters\LinkBlockFilters;
use PrestaShop\PrestaShop\Adapter\Shop\Context;
use PrestaShop\PrestaShop\Core\Grid\Data\Factory\GridDataFactoryInterface;
use PrestaShop\PrestaShop\Core\Grid\Filter\GridFilterFormFactoryInterface;
use PrestaShop\PrestaShop\Core\Grid\GridFactory;
use PrestaShop\PrestaShop\Core\Grid\GridInterface;
use PrestaShop\PrestaShop\Core\Hook\HookDispatcherInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class LinkBlockGridFactory.
*/
final class LinkBlockGridFactory
{
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var HookDispatcherInterface
*/
private $hookDispatcher;
/**
* @var GridDataFactoryInterface
*/
private $dataFactory;
/**
* @var GridFilterFormFactoryInterface
*/
private $filterFormFactory;
/**
* @var Context
*/
private $shopContext;
/**
* HookGridFactory constructor.
*
* @param TranslatorInterface $translator
* @param HookDispatcherInterface $hookDispatcher
* @param GridDataFactoryInterface $dataFactory
* @param GridFilterFormFactoryInterface $filterFormFactory
* @param Context $shopContext
*/
public function __construct(
TranslatorInterface $translator,
GridDataFactoryInterface $dataFactory,
HookDispatcherInterface $hookDispatcher,
GridFilterFormFactoryInterface $filterFormFactory,
Context $shopContext
) {
$this->translator = $translator;
$this->hookDispatcher = $hookDispatcher;
$this->dataFactory = $dataFactory;
$this->filterFormFactory = $filterFormFactory;
$this->shopContext = $shopContext;
}
/**
* @param array $hooks
* @param array $filtersParams
*
* @return GridInterface[]
*/
public function getGrids(array $hooks, array $filtersParams)
{
$grids = [];
foreach ($hooks as $hook) {
$hookParams = $filtersParams;
$hookParams['filters']['id_hook'] = $hook['id_hook'];
$hookParams['filters']['id_shop'] = $this->shopContext->getContextListShopID();
$filters = new LinkBlockFilters($hookParams);
$gridFactory = $this->buildGridFactoryByHook($hook);
$grids[] = $gridFactory->getGrid($filters);
}
return $grids;
}
/**
* Each definition depends on the hook, therefore each factory also
* depends on the hook.
*
* @param array $hook
*
* @return GridFactory
*/
private function buildGridFactoryByHook(array $hook)
{
$definitionFactory = new LinkBlockDefinitionFactory($hook, $this->shopContext, $this->hookDispatcher);
$definitionFactory->setTranslator($this->translator);
return new GridFactory(
$definitionFactory,
$this->dataFactory,
$this->filterFormFactory,
$this->hookDispatcher
);
}
}

View File

@@ -0,0 +1,133 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Core\Grid\Query;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;
use PrestaShop\PrestaShop\Core\Grid\Query\AbstractDoctrineQueryBuilder;
use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface;
/**
* Class LinkBlockQueryBuilder.
*/
final class LinkBlockQueryBuilder extends AbstractDoctrineQueryBuilder
{
/**
* @param SearchCriteriaInterface|null $searchCriteria
*
* @return QueryBuilder
*/
public function getSearchQueryBuilder(?SearchCriteriaInterface $searchCriteria = null)
{
$qb = $this->getQueryBuilder($searchCriteria->getFilters());
$qb->select('
lb.id_link_block,
lbl.name AS block_name,
lb.id_hook,
h.name as hook_name,
h.title as hook_title,
h.description as hook_description,
lbs.position as position,
GROUP_CONCAT(s.name SEPARATOR ", ") as shop_name
')
->groupBy('lb.id_link_block')
->orderBy(
$searchCriteria->getOrderBy(),
$searchCriteria->getOrderWay()
)
;
if ($searchCriteria->getLimit() > 0) {
$qb
->setFirstResult($searchCriteria->getOffset())
->setMaxResults($searchCriteria->getLimit())
;
}
return $qb;
}
/**
* @param SearchCriteriaInterface|null $searchCriteria
*
* @return QueryBuilder
*/
public function getCountQueryBuilder(?SearchCriteriaInterface $searchCriteria = null)
{
$qb = $this->getQueryBuilder($searchCriteria->getFilters());
$qb->select('COUNT(DISTINCT(lb.id_link_block))');
return $qb;
}
/**
* Get generic query builder.
*
* @param array $filters
*
* @return QueryBuilder
*/
private function getQueryBuilder(array $filters)
{
$qb = $this->connection
->createQueryBuilder()
->from($this->dbPrefix . 'link_block', 'lb')
->innerJoin('lb', $this->dbPrefix . 'link_block_lang', 'lbl', 'lb.id_link_block = lbl.id_link_block')
->leftJoin('lb', $this->dbPrefix . 'link_block_shop', 'lbs', 'lb.id_link_block = lbs.id_link_block')
->leftJoin('lb', $this->dbPrefix . 'hook', 'h', 'lb.id_hook = h.id_hook')
->leftJoin('lb', $this->dbPrefix . 'shop', 's', 's.id_shop = lbs.id_shop');
foreach ($filters as $name => $value) {
if ('id_lang' === $name) {
$qb
->andWhere("lbl.id_lang = :$name")
->setParameter($name, $value)
;
continue;
}
if ('id_hook' === $name) {
$qb
->andWhere("h.id_hook = :$name")
->setParameter($name, $value)
;
continue;
}
if ('id_shop' === $name) {
$qb
->andWhere("lbs.id_shop IN (:$name)")
->setParameter($name, $value, Connection::PARAM_STR_ARRAY);
continue;
}
$qb
->andWhere(sprintf('lbl.%s LIKE :%s', $name, $name))
->setParameter($name, '%' . $value . '%')
;
}
return $qb;
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,44 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Core\Search\Filters;
use PrestaShop\PrestaShop\Core\Search\Filters;
/**
* Class LinkBlockFilters.
*/
final class LinkBlockFilters extends Filters
{
/**
* {@inheritdoc}
*/
public static function getDefaults()
{
return [
'id_shop' => null,
'limit' => 0,
'offset' => 0,
'orderBy' => 'position',
'sortOrder' => 'asc',
'filters' => [],
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,186 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList;
use Configuration;
use Db;
use Hook;
use Language;
use PrestaShop\Module\LinkList\Model\LinkBlock;
/**
* Class used to migrate data from the 1.6 module
*/
class DataMigration
{
/**
* @var Db
*/
private $db;
public function __construct(Db $db)
{
$this->db = $db;
}
/**
* Retrieve content from 1.6 module, then cleanup
*/
public function migrateData()
{
// Copy first table
$this->db->execute(
'INSERT INTO `' . _DB_PREFIX_ . 'link_block`
(`id_link_block`, `id_hook`, `position`)
SELECT `id_cms_block`, `location`, `position`
FROM `' . _DB_PREFIX_ . 'cms_block`'
);
// Update hook IDs (Got from BlockCMSModel in 1.6 module)
$relationBetweenOldLocationsAndHooks = [
0 => 'displayLeftColumn', // LEFT_COLUMN
1 => 'displayRightColumn', // RIGHT_COLUMN
2 => 'displayFooter', // FOOTER
];
foreach ($relationBetweenOldLocationsAndHooks as $oldLocation => $newHookLocation) {
// Retrieve the cms page IDs linked in the old module
$content = $this->generateJsonForBlockContent([
'cms' => $this->getCmsIdsFromBlock($oldLocation),
]);
$this->db->execute(
'UPDATE `' . _DB_PREFIX_ . 'link_block`
SET `id_hook` = ' . (int) Hook::getIdByName($newHookLocation) . ",
`content` = '" . pSQL($content) . "'
WHERE `id_hook` = " . $oldLocation
);
}
// Copy second table (lang)
$this->db->execute(
'INSERT INTO `' . _DB_PREFIX_ . 'link_block_lang`
(`id_link_block`, `id_lang`, `name`)
SELECT `id_cms_block`, `id_lang`, `name`
FROM `' . _DB_PREFIX_ . 'cms_block_lang`'
);
// Copy third table (shop)
$this->db->execute(
'INSERT INTO `' . _DB_PREFIX_ . 'link_block_shop`
(`id_link_block`, `id_shop`)
SELECT `id_cms_block`, `id_shop`
FROM `' . _DB_PREFIX_ . 'cms_block_shop`'
);
$this->migrateBlockFooter();
// Drop old tables
$this->db->execute(
'DROP TABLE `' . _DB_PREFIX_ . 'cms_block`,
`' . _DB_PREFIX_ . 'cms_block_lang`,
`' . _DB_PREFIX_ . 'cms_block_page`,
`' . _DB_PREFIX_ . 'cms_block_shop`'
);
}
private function migrateBlockFooter()
{
if (!Configuration::get('FOOTER_BLOCK_ACTIVATION')) {
return;
}
$linkBlock = new LinkBlock();
$data = [];
$footerCMS = Configuration::get('FOOTER_CMS');
if (!empty($footerCMS)) {
foreach (explode('|', $footerCMS) as $val) {
list(, $cmsId) = explode('_', $val);
$data['cms'][] = $cmsId;
}
}
if (Configuration::get('FOOTER_PRICE-DROP')) {
$data['product'][] = 'prices-drop';
}
if (Configuration::get('FOOTER_NEW-PRODUCTS')) {
$data['product'][] = 'new-products';
}
if (Configuration::get('FOOTER_BEST-SALES')) {
$data['product'][] = 'best-sales';
}
if (Configuration::get('FOOTER_CONTACT')) {
$data['static'][] = 'contact';
}
if (Configuration::get('FOOTER_SITEMAP')) {
$data['static'][] = 'sitemap';
}
if (Configuration::get('PS_STORES_DISPLAY_FOOTER')) {
$data['static'][] = 'stores';
}
$linkBlock->content = $this->generateJsonForBlockContent($data);
$linkBlock->id_hook = (int) Hook::getIdByName('displayFooter');
$languages = Language::getLanguages(false);
foreach ($languages as $lang) {
$linkBlock->name[$lang['id_lang']] = 'Footer content (Migrated)';
$linkBlock->custom_content[$lang['id_lang']] = json_encode([[
'title' => Configuration::get('FOOTER_CMS_TEXT_' . $lang['id_lang']),
'url' => '#',
]]);
}
$linkBlock->save();
}
/**
* Generate a JSON for the column `content` of link_block
*
* @param array $data
*
* @return string
*/
private function generateJsonForBlockContent(array $data)
{
return json_encode([
'cms' => empty($data['cms']) ? [false] : $data['cms'],
'static' => empty($data['static']) ? [false] : $data['static'],
'product' => empty($data['product']) ? [false] : $data['product'],
]);
}
/**
* Get list of cms IDs from database for a given old cms_block_page
*
* @param int $oldLocation
*
* @return array
*/
private function getCmsIdsFromBlock($oldLocation)
{
$request = $this->db->executeS(
'SELECT id_cms FROM `' . _DB_PREFIX_ . 'cms_block_page`
WHERE id_cms_block = ' . (int) $oldLocation . '
AND is_category = 0'
);
$ids = [];
foreach ($request as $row) {
$ids[] = $row['id_cms'];
}
return $ids;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Filter;
use Configuration;
class BestSalesRouteFilter implements RouteFilterInterface
{
public function supports(string $routeId): bool
{
return 'best-sales' === $routeId;
}
public function isRouteEnabled(string $routeId): bool
{
return (bool) Configuration::get('PS_DISPLAY_BEST_SELLERS');
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Filter;
class LinkFilter
{
/**
* @var RouteFilterInterface[]
*/
private $routeFilters = [];
public function __construct(array $routeFilters = [])
{
$this->addRouteFilter(...$routeFilters);
}
public function addRouteFilter(RouteFilterInterface ...$routeFilters): void
{
foreach ($routeFilters as $routeFilter) {
$this->routeFilters[] = $routeFilter;
}
}
public function isRouteEnabled(string $routeId): bool
{
foreach ($this->routeFilters as $filter) {
if ($filter->supports($routeId) && !$filter->isRouteEnabled($routeId)) {
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Filter;
interface RouteFilterInterface
{
public function supports(string $routeId): bool;
public function isRouteEnabled(string $routeId): bool;
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,71 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Form\ChoiceProvider;
use Doctrine\DBAL\Connection;
use PrestaShop\PrestaShop\Core\Form\FormChoiceProviderInterface;
/**
* Class AbstractDatabaseChoiceProvider.
*/
abstract class AbstractDatabaseChoiceProvider implements FormChoiceProviderInterface
{
/**
* @var Connection
*/
protected $connection;
/**
* @var string
*/
protected $dbPrefix;
/**
* @var int
*/
protected $idLang;
/**
* @var array
*/
protected $shopIds;
/**
* AbstractDatabaseChoiceProvider constructor.
*
* @param Connection $connection
* @param string $dbPrefix
* @param int|null $idLang
* @param array|null $shopIds
*/
public function __construct(Connection $connection, $dbPrefix, $idLang = null, ?array $shopIds = null)
{
$this->connection = $connection;
$this->dbPrefix = $dbPrefix;
$this->idLang = $idLang;
$this->shopIds = $shopIds;
}
/**
* {@inheritdoc}
*/
abstract public function getChoices();
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Form\ChoiceProvider;
/**
* Class CMSCategoryChoiceProvider.
*/
final class CMSCategoryChoiceProvider extends AbstractDatabaseChoiceProvider
{
/**
* @return array
*/
public function getChoices()
{
$qb = $this->connection->createQueryBuilder();
$qb
->select('cc.id_cms_category, ccl.name')
->from($this->dbPrefix . 'cms_category', 'cc')
->innerJoin('cc', $this->dbPrefix . 'cms_category_lang', 'ccl', 'cc.id_cms_category = ccl.id_cms_category')
->innerJoin('cc', $this->dbPrefix . 'cms_category_shop', 'ccs', 'cc.id_cms_category = ccs.id_cms_category')
->andWhere('cc.active = 1')
->andWhere('ccl.id_lang = :idLang')
->andWhere('ccs.id_shop IN (:shopIds)')
->setParameter('idLang', $this->idLang)
->setParameter('shopIds', implode(',', $this->shopIds))
->orderBy('ccl.name')
;
$categories = $qb->execute()->fetchAll();
$choices = [];
foreach ($categories as $category) {
$choices[$category['name']] = $category['id_cms_category'];
}
return $choices;
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Form\ChoiceProvider;
use Doctrine\DBAL\Connection;
/**
* Class CMSPageChoiceProvider.
*/
final class CMSPageChoiceProvider extends AbstractDatabaseChoiceProvider
{
/**
* @var array
*/
private $categories;
/**
* CMSPageChoiceProvider constructor.
*
* @param Connection $connection
* @param string $dbPrefix
* @param array $categories
* @param int $idLang
* @param array $shopIds
*/
public function __construct(
Connection $connection,
$dbPrefix,
array $categories,
$idLang,
$shopIds
) {
parent::__construct($connection, $dbPrefix, $idLang, $shopIds);
$this->categories = $categories;
}
/**
* @return array
*/
public function getChoices()
{
$choices = [];
foreach ($this->categories as $categoryName => $categoryId) {
$qb = $this->connection->createQueryBuilder();
$qb
->select('c.id_cms, cl.meta_title')
->from($this->dbPrefix . 'cms', 'c')
->innerJoin('c', $this->dbPrefix . 'cms_lang', 'cl', 'c.id_cms = cl.id_cms')
->innerJoin('c', $this->dbPrefix . 'cms_shop', 'cs', 'c.id_cms = cs.id_cms')
->andWhere('c.active = 1')
->andWhere('cl.id_lang = :idLang')
->andWhere('cs.id_shop IN (:shopIds)')
->andWhere('c.id_cms_category = :idCmsCategory')
->setParameter('idCmsCategory', $categoryId)
->setParameter('idLang', $this->idLang)
->setParameter('shopIds', implode(',', $this->shopIds))
->orderBy('c.position')
;
$pages = $qb->execute()->fetchAll();
foreach ($pages as $page) {
$choices[$categoryName][$page['id_cms'] . ' ' . $page['meta_title']] = $page['id_cms'];
}
}
return $choices;
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Form\ChoiceProvider;
/**
* Class CategoryChoiceProvider.
*/
final class CategoryChoiceProvider extends AbstractDatabaseChoiceProvider
{
/**
* @return array
*/
public function getChoices()
{
$qb = $this->connection->createQueryBuilder();
$qb
->select('cc.id_category, ccl.name')
->from($this->dbPrefix . 'category', 'cc')
->innerJoin('cc', $this->dbPrefix . 'category_lang', 'ccl', 'cc.id_category = ccl.id_category')
->innerJoin('cc', $this->dbPrefix . 'category_shop', 'ccs', 'cc.id_category = ccs.id_category')
->andWhere('cc.active = 1')
->andWhere('ccl.id_lang = :idLang')
->andWhere('ccs.id_shop IN (:shopIds)')
->setParameter('idLang', $this->idLang)
->setParameter('shopIds', implode(',', $this->shopIds))
->orderBy('ccl.name')
;
$categories = $qb->execute()->fetchAll();
$choices = [];
foreach ($categories as $category) {
$choices[$category['id_category'] . ' ' . $category['name']] = $category['id_category'];
}
return $choices;
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Form\ChoiceProvider;
/**
* Class HookChoiceProvider.
*/
final class HookChoiceProvider extends AbstractDatabaseChoiceProvider
{
/**
* @return mixed
*/
public function getChoices()
{
$qb = $this->connection->createQueryBuilder();
$qb
->select('h.id_hook, h.name')
->from($this->dbPrefix . 'hook', 'h')
->andWhere('h.name LIKE :displayHook')
->setParameter('displayHook', 'display%')
->orderBy('h.name')
;
$hooks = $qb->execute()->fetchAll();
$choices = [];
foreach ($hooks as $hook) {
$choices[$hook['name']] = $hook['id_hook'];
}
return $choices;
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Form\ChoiceProvider;
use Doctrine\DBAL\Connection;
use PrestaShop\PrestaShop\Core\Foundation\Database\EntityNotFoundException;
use Tools;
/**
* Class PageChoiceProvider.
*/
final class PageChoiceProvider extends AbstractDatabaseChoiceProvider
{
/**
* @var array
*/
private $pageNames;
/**
* PageChoiceProvider constructor.
*
* @param Connection $connection
* @param string $dbPrefix
* @param int $idLang
* @param array $shopIds
* @param array $pageNames
*/
public function __construct(
Connection $connection,
$dbPrefix,
$idLang,
array $shopIds,
array $pageNames
) {
parent::__construct($connection, $dbPrefix, $idLang, $shopIds);
$this->pageNames = $pageNames;
}
/**
* @return array
*
* @throws EntityNotFoundException
*/
public function getChoices()
{
$choices = [];
foreach ($this->pageNames as $pageName) {
$qb = $this->connection->createQueryBuilder();
$qb
->select('m.id_meta, ml.title')
->from($this->dbPrefix . 'meta', 'm')
->leftJoin('m', $this->dbPrefix . 'meta_lang', 'ml', 'm.id_meta = ml.id_meta')
->andWhere($qb->expr()->orX('m.page = :page', 'm.page = :pageSlug'))
->andWhere('ml.id_lang = :idLang')
->andWhere('ml.id_shop IN (:shopIds)')
->setParameter('idLang', $this->idLang)
->setParameter('shopIds', implode(',', $this->shopIds))
->setParameter('page', $pageName)
->setParameter('pageSlug', str_replace('-', '', Tools::strtolower($pageName)))
;
$meta = $qb->execute()->fetchAll();
if (!empty($meta)) {
$choices[$meta[0]['title']] = $pageName;
}
}
return $choices;
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,326 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Form;
use Hook;
use Language;
use Module;
use PrestaShop\Module\LinkList\Cache\LinkBlockCacheInterface;
use PrestaShop\Module\LinkList\Model\LinkBlock;
use PrestaShop\Module\LinkList\Repository\LinkBlockRepository;
use PrestaShop\PrestaShop\Adapter\Configuration;
use PrestaShop\PrestaShop\Adapter\Shop\Context;
use PrestaShop\PrestaShop\Core\Form\FormDataProviderInterface;
use Ps_Linklist;
/**
* Class LinkBlockFormDataProvider.
*/
class LinkBlockFormDataProvider implements FormDataProviderInterface
{
/**
* @var int|null
*/
private $idLinkBlock;
/**
* @var LinkBlockRepository
*/
private $repository;
/**
* @var LinkBlockCacheInterface
*/
private $cache;
/**
* @var array
*/
private $languages;
/**
* @var Context
*/
private $shopContext;
/**
* @var Configuration
*/
private $configuration;
/**
* LinkBlockFormDataProvider constructor.
*
* @param LinkBlockRepository $repository
* @param LinkBlockCacheInterface $cache
* @param array $languages
* @param Context $shopContext
* @param Configuration $configuration
*/
public function __construct(
LinkBlockRepository $repository,
LinkBlockCacheInterface $cache,
array $languages,
Context $shopContext,
Configuration $configuration
) {
$this->repository = $repository;
$this->cache = $cache;
$this->languages = $languages;
$this->shopContext = $shopContext;
$this->configuration = $configuration;
}
/**
* @return array
*
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function getData()
{
if (null === $this->idLinkBlock) {
return [
'link_block' => [
'shop_association' => $this->shopContext->getContextListShopID(),
],
];
}
$linkBlock = new LinkBlock($this->idLinkBlock);
$arrayLinkBlock = $linkBlock->toArray();
//The form and the database model don't have the same data hierarchy
//Transform array $custom[en][1][name] to $custom[1][en][name]
$arrayCustom = [];
foreach ($arrayLinkBlock['custom_content'] as $idLang => $customs) {
if (!is_array($customs)) {
continue;
}
foreach ($customs as $i => $custom) {
$arrayCustom[$i][$idLang] = $custom;
}
}
return ['link_block' => [
'id_link_block' => $arrayLinkBlock['id'],
'block_name' => $arrayLinkBlock['name'],
'id_hook' => $arrayLinkBlock['id_hook'],
'cms' => isset($arrayLinkBlock['content']['cms']) ? $arrayLinkBlock['content']['cms'] : [],
'product' => isset($arrayLinkBlock['content']['product']) ? $arrayLinkBlock['content']['product'] : [],
'static' => isset($arrayLinkBlock['content']['static']) ? $arrayLinkBlock['content']['static'] : [],
'category' => isset($arrayLinkBlock['content']['category']) ? $arrayLinkBlock['content']['category'] : [],
'custom' => $arrayCustom,
'shop_association' => $arrayLinkBlock['shop_association'],
]];
}
/**
* Make sure to fill empty multilang fields if value for default is available
*
* @param array $linkBlock
*
* @return array
*/
public function prepareData(array $linkBlock): array
{
$defaultLanguageId = (int) $this->configuration->get('PS_LANG_DEFAULT');
if (!empty($linkBlock['block_name'])) {
foreach ($this->languages as $language) {
if (empty($linkBlock['block_name'][$language['id_lang']])) {
$linkBlock['block_name'][$language['id_lang']] = $linkBlock['block_name'][$defaultLanguageId];
}
}
}
if (!empty($linkBlock['custom'])) {
foreach ($linkBlock['custom'] as $key => $customLanguages) {
if ($this->isEmptyCustom($customLanguages)) {
continue;
}
foreach ($customLanguages as $idLang => $custom) {
$linkBlock['custom'][$key][$idLang] = [
'title' => $custom['title'] ?? $customLanguages[$defaultLanguageId]['title'],
'url' => $custom['url'] ?? $customLanguages[$defaultLanguageId]['url'],
];
}
}
}
return $linkBlock;
}
/**
* @param array $data
*
* @return array
*
* @throws \PrestaShop\PrestaShop\Adapter\Entity\PrestaShopDatabaseException
*/
public function setData(array $data)
{
$linkBlock = $this->prepareData($data['link_block']);
$errors = $this->validateLinkBlock($linkBlock);
if (!empty($errors)) {
return $errors;
}
$customContent = [];
if (!empty($linkBlock['custom'])) {
foreach ($linkBlock['custom'] as $customLanguages) {
if ($this->isEmptyCustom($customLanguages)) {
continue;
}
foreach ($customLanguages as $idLang => $custom) {
$customContent[$idLang][] = $custom;
}
}
}
$linkBlock['custom_content'] = $customContent;
$linkBlock['id_shop'] = $this->shopContext->getContextShopID();
if (empty($linkBlock['id_link_block'])) {
$linkBlockId = $this->repository->create($linkBlock);
$this->setIdLinkBlock((int) $linkBlockId);
} else {
$linkBlockId = $linkBlock['id_link_block'];
$this->repository->update($linkBlockId, $linkBlock);
}
$this->updateHook($linkBlock['id_hook']);
$this->cache->clearModuleCache();
return [];
}
public function getIdLinkBlock(): ?int
{
return $this->idLinkBlock;
}
public function setIdLinkBlock(?int $idLinkBlock)
{
$this->idLinkBlock = $idLinkBlock;
return $this;
}
/**
* @param array $data
*
* @return array
*/
private function validateLinkBlock(array $data)
{
$errors = [];
if (!isset($data['id_hook'])) {
$errors[] = [
'key' => 'Missing id_hook',
'domain' => 'Admin.Catalog.Notification',
'parameters' => [],
];
}
if (!isset($data['block_name'])) {
$errors[] = [
'key' => 'Missing block_name',
'domain' => 'Admin.Catalog.Notification',
'parameters' => [],
];
} else {
foreach ($this->languages as $language) {
if (empty($data['block_name'][$language['id_lang']])) {
$errors[] = [
'key' => 'Missing block_name value for language %s',
'domain' => 'Admin.Catalog.Notification',
'parameters' => [$language['iso_code']],
];
}
}
}
if (!isset($data['custom'])) {
return $errors;
}
foreach ($data['custom'] as $customIndex => $custom) {
if ($this->isEmptyCustom($custom)) {
continue;
}
$defaultLanguageId = (int) $this->configuration->get('PS_LANG_DEFAULT');
$fields = ['title', 'url'];
foreach ($fields as $field) {
if (empty($custom[$defaultLanguageId][$field])) {
$errors[] = [
'key' => 'Missing %s value in custom[%s] for language %s',
'domain' => 'Admin.Catalog.Notification',
'parameters' => [$field, $customIndex, Language::getIsoById($defaultLanguageId)],
];
}
}
}
return $errors;
}
/**
* @param array $custom
*
* @return bool
*/
private function isEmptyCustom(array $custom)
{
$fields = ['title', 'url'];
foreach ($custom as $langCustom) {
foreach ($fields as $field) {
if (!empty($langCustom[$field])) {
return false;
}
}
}
return true;
}
/**
* Register the selected hook to this module if it was not registered yet.
*
* @param int $hookId
*
* @throws \PrestaShopException
*/
private function updateHook($hookId)
{
$hookName = Hook::getNameById($hookId);
$module = Module::getInstanceByName(Ps_Linklist::MODULE_NAME);
if ($module instanceof Module
&& !Hook::isModuleRegisteredOnHook($module, $hookName, $this->shopContext->getContextShopID())) {
Hook::registerHook($module, $hookName);
}
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Form\Type;
use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;
class CustomUrlType extends TranslatorAwareType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', TextType::class, [
'label' => $this->trans('Title', 'Modules.Linklist.Admin'),
'required' => true,
])
->add('url', TextType::class, [
'label' => $this->trans('URL', 'Modules.Linklist.Admin'),
'required' => true,
// Regex adapted from src/Symfony/Component/Validator/Constraints/UrlValidator.php (symfony 4.4)
'constraints' => [new Assert\Regex(['pattern' => '~^
(
(http|https)://? # protocol
(([\_\.\pL\pN-]+:)?([\_\.\pL\pN-]+)@)? # basic auth
(
([\pL\pN\pS\-\_\.])+(\.?([\pL\pN]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
| # or
\[
(?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,1}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,2}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,3}(?:(?:[0-9a-f]{1,4})))?::(?:(?:[0-9a-f]{1,4})):)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))
\] # an IPv6 address
)
(:[0-9]+)? # a port (optional)
)? # everything up to here is optional (for relative URLs)
(?:/ (?:[\pL\pN\-._\~!$&\'()*+,;=:@]|%[0-9A-Fa-f]{2})* )* # a path
(?:\? (?:[\pL\pN\-._\~!$&\'()*+,;=:@/?]|%[0-9A-Fa-f]{2})* )? # a query (optional)
(?:\# (?:[\pL\pN\-._\~!$&\'()*+,;=:@/?]|%[0-9A-Fa-f]{2})* )? # a fragment (optional)
$~ixu'])],
])
;
}
}

View File

@@ -0,0 +1,214 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Form\Type;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\DefaultLanguage;
use PrestaShopBundle\Form\Admin\Type\ShopChoiceTreeType;
use PrestaShopBundle\Form\Admin\Type\TranslatableType;
use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Contracts\Translation\TranslatorInterface;
class LinkBlockType extends TranslatorAwareType
{
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var array
*/
private $hookChoices;
/**
* @var array
*/
private $cmsPageChoices;
/**
* @var array
*/
private $productPageChoices;
/**
* @var array
*/
private $staticPageChoices;
/**
* @var array
*/
private $categoryChoices;
/**
* @var bool
*/
private $isMultiStoreUsed;
/**
* LinkBlockType constructor.
*
* @param TranslatorInterface $translator
* @param array $locales
* @param array $hookChoices
* @param array $cmsPageChoices
* @param array $productPageChoices
* @param array $staticPageChoices
* @param array $categoryChoices
*/
public function __construct(
TranslatorInterface $translator,
array $locales,
array $hookChoices,
array $cmsPageChoices,
array $productPageChoices,
array $staticPageChoices,
array $categoryChoices,
bool $isMultiStoreUsed
) {
parent::__construct($translator, $locales);
$this->hookChoices = $hookChoices;
$this->cmsPageChoices = $cmsPageChoices;
$this->productPageChoices = $productPageChoices;
$this->staticPageChoices = $staticPageChoices;
$this->categoryChoices = $categoryChoices;
$this->translator = $translator;
$this->isMultiStoreUsed = $isMultiStoreUsed;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id_link_block', HiddenType::class)
->add('block_name', TranslatableType::class, [
'locales' => $this->locales,
'required' => true,
'label' => $this->trans('Name of the block', 'Modules.Linklist.Admin'),
'constraints' => [
new DefaultLanguage(),
],
'options' => [
'constraints' => [
new Length([
'max' => 40,
'maxMessage' => $this->translator->trans(
'Name of the block cannot be longer than %limit% characters',
[
'%limit%' => 40,
],
'Modules.Linklist.Admin'
),
]),
],
],
])
->add('id_hook', ChoiceType::class, [
'choices' => $this->hookChoices,
'attr' => [
'data-toggle' => 'select2',
'data-minimumResultsForSearch' => '7',
],
'label' => $this->trans('Hook', 'Admin.Global'),
])
->add('cms', ChoiceType::class, [
'choices' => $this->cmsPageChoices,
'label' => $this->trans('Content pages', 'Modules.Linklist.Admin'),
'multiple' => true,
'expanded' => true,
])
->add('product', ChoiceType::class, [
'choices' => $this->productPageChoices,
'label' => $this->trans('Product pages', 'Modules.Linklist.Admin'),
'multiple' => true,
'expanded' => true,
])
->add('category', ChoiceType::class, [
'choices' => $this->categoryChoices,
'label' => $this->trans('Categories', 'Modules.Linklist.Admin'),
'multiple' => true,
'expanded' => true,
])
->add('static', ChoiceType::class, [
'choices' => $this->staticPageChoices,
'label' => $this->trans('Static content', 'Modules.Linklist.Admin'),
'multiple' => true,
'expanded' => true,
])
->add('custom', CollectionType::class, [
'entry_type' => TranslateCustomUrlType::class,
'entry_options' => [
'locales' => $this->locales,
'label' => false,
],
'attr' => [
'class' => 'custom_collection',
'data-delete-button-label' => $this->trans('Delete', 'Admin.Global'),
],
'allow_add' => true,
'allow_delete' => true,
'label' => $this->trans('Custom content', 'Modules.Linklist.Admin'),
])
;
if ($this->isMultiStoreUsed) {
$builder->add('shop_association', ShopChoiceTreeType::class, [
'label' => $this->trans('Shop association', 'Admin.Global'),
'required' => false,
'constraints' => [
new NotBlank([
'message' => $this->trans(
'You have to select at least one shop to associate this item with',
'Admin.Notifications.Error'
),
]),
],
]);
}
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'label' => false,
]);
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'module_link_block';
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Form\Type;
use PrestaShopBundle\Form\Admin\Type\TranslatableType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* Class TranslatableUrlType.
*/
class TranslateCustomUrlType extends TranslatableType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
foreach ($options['locales'] as $locale) {
$localeOptions = $options['options'];
$localeOptions['label'] = $locale['iso_code'];
if (!isset($localeOptions['required'])) {
$localeOptions['required'] = false;
}
$builder->add($locale['id_lang'], CustomUrlType::class, $localeOptions);
}
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,176 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList;
use Context;
use Db;
use Hook;
use Language;
use PrestaShop\Module\LinkList\Model\LinkBlock;
use Shop;
use Symfony\Contracts\Translation\TranslatorInterface as Translator;
/**
* Class LegacyLinkBlockRepository.
*/
class LegacyLinkBlockRepository
{
/**
* @var Db
*/
private $db;
/**
* @var Shop
*/
private $shop;
/**
* @var string
*/
private $db_prefix;
/**
* @var Translator
*/
private $translator;
/**
* @param Db $db
* @param Shop $shop
* @param Translator $translator
*/
public function __construct(Db $db, Shop $shop, Translator $translator)
{
$this->db = $db;
$this->shop = $shop;
$this->db_prefix = $db->getPrefix();
$this->translator = $translator;
}
/**
* @param int $id_hook
*
* @return array
*
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function getByIdHook($id_hook)
{
$id_hook = (int) $id_hook;
$sql = "SELECT lb.`id_link_block`
FROM {$this->db_prefix}link_block lb
INNER JOIN {$this->db_prefix}link_block_shop lbs ON lbs.`id_link_block` = lb.`id_link_block`
WHERE lb. `id_hook` = $id_hook AND lbs.`id_shop` = {$this->shop->id}
ORDER by lbs.`position`
";
$ids = $this->db->executeS($sql);
$cmsBlock = [];
foreach ($ids as $id) {
$cmsBlock[] = new LinkBlock((int) $id['id_link_block']);
}
return $cmsBlock;
}
/**
* @return bool
*/
public function createTables()
{
$engine = _MYSQL_ENGINE_;
$success = true;
$this->dropTables();
$queries = [
"CREATE TABLE IF NOT EXISTS `{$this->db_prefix}link_block`(
`id_link_block` int(10) unsigned NOT NULL auto_increment,
`id_hook` int(1) unsigned DEFAULT NULL,
`position` int(10) unsigned NOT NULL default '0',
`content` text default NULL,
PRIMARY KEY (`id_link_block`)
) ENGINE=$engine DEFAULT CHARSET=utf8",
"CREATE TABLE IF NOT EXISTS `{$this->db_prefix}link_block_lang`(
`id_link_block` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`name` varchar(40) NOT NULL default '',
`custom_content` text default NULL,
PRIMARY KEY (`id_link_block`, `id_lang`)
) ENGINE=$engine DEFAULT CHARSET=utf8",
"CREATE TABLE IF NOT EXISTS `{$this->db_prefix}link_block_shop` (
`id_link_block` int(10) unsigned NOT NULL auto_increment,
`id_shop` int(10) unsigned NOT NULL,
`position` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id_link_block`, `id_shop`)
) ENGINE=$engine DEFAULT CHARSET=utf8",
];
foreach ($queries as $query) {
$success &= $this->db->execute($query);
}
return (bool) $success;
}
public function dropTables()
{
$sql = "DROP TABLE IF EXISTS
`{$this->db_prefix}link_block`,
`{$this->db_prefix}link_block_lang`,
`{$this->db_prefix}link_block_shop`";
return $this->db->execute($sql);
}
/**
* @return bool
*/
public function installFixtures(): bool
{
$success = true;
$id_hook = (int) Hook::getIdByName('displayFooter');
$queries = [
'INSERT INTO `' . $this->db_prefix . 'link_block` (`id_link_block`, `id_hook`, `position`, `content`) VALUES
(1, ' . $id_hook . ', 0, \'{"cms":[false],"product":["prices-drop","new-products","best-sales"],"static":[false]}\'),
(2, ' . $id_hook . ', 1, \'{"cms":["1","2","3","4","5"],"product":[false],"static":["contact","sitemap","stores"]}\');',
];
foreach (Language::getLanguages(true, Context::getContext()->shop->id) as $lang) {
$queries[] = 'INSERT INTO `' . $this->db_prefix . 'link_block_lang` (`id_link_block`, `id_lang`, `name`) VALUES
(1, ' . (int) $lang['id_lang'] . ', "' . pSQL($this->translator->trans('Products', [], 'Modules.Linklist.Shop', $lang['locale'])) . '"),
(2, ' . (int) $lang['id_lang'] . ', "' . pSQL($this->translator->trans('Our company', [], 'Modules.Linklist.Shop', $lang['locale'])) . '");'
;
}
foreach ($this->shop::getContextListShopID() as $shopId) {
$queries[] = 'INSERT INTO `' . $this->db_prefix . 'link_block_shop` (`id_link_block`, `id_shop`, `position`) VALUES
(1, ' . (int) $shopId . ', 0),
(2, ' . (int) $shopId . ', 1);'
;
}
foreach ($queries as $query) {
$success = $success && ((bool) $this->db->execute($query));
}
return $success;
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Model;
use Shop;
/**
* Class LinkBlock.
*/
class LinkBlock extends \ObjectModel
{
/**
* @var int
*/
public $id_link_block;
/**
* @var string
*/
public $name;
/**
* @var int
*/
public $id_hook;
/**
* @var int
*/
public $position;
/**
* @var array|string|null
*/
public $content;
/**
* @var array
*/
public $custom_content;
/**
* @see ObjectModel::$definition
*/
public static $definition = [
'table' => 'link_block',
'primary' => 'id_link_block',
'multilang' => true,
'fields' => [
'name' => ['type' => self::TYPE_STRING, 'lang' => true, 'required' => true, 'size' => 40],
'id_hook' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true],
'position' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true],
'content' => ['type' => self::TYPE_STRING, 'validate' => 'isJson'],
'custom_content' => ['type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isJson'],
],
];
public function __construct($id = null, $id_lang = null, $id_shop = null)
{
Shop::addTableAssociation('link_block', ['type' => 'shop']);
parent::__construct($id, $id_lang, $id_shop);
if ($this->id) {
$this->content = json_decode($this->content, true);
if ($this->custom_content) {
$this->custom_content = array_map(
function ($el) {
return json_decode($el ?? '', true);
},
$this->custom_content
);
}
}
if (is_null($this->content)) {
$this->content = [
'cms' => [],
'product' => [],
'static' => [],
'category' => [],
];
}
}
public function add($auto_date = true, $null_values = false)
{
if (is_array($this->content)) {
$this->content = json_encode($this->content);
}
if (!$this->position) {
$this->position = 1;
}
$return = parent::add($auto_date, $null_values);
$this->content = json_decode($this->content, true);
return $return;
}
public function update($auto_date = true, $null_values = false)
{
if (is_array($this->content)) {
$this->content = json_encode($this->content);
}
$return = parent::update($null_values);
$this->content = json_decode($this->content, true);
return $return;
}
public function toArray()
{
return [
'id' => $this->id,
'id_link_block' => $this->id,
'name' => $this->name,
'id_hook' => $this->id_hook,
'position' => $this->position,
'content' => $this->content,
'custom_content' => $this->custom_content,
'shop_association' => $this->getAssociatedShops(),
];
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Model;
use DataLangCore;
/**
* Class LinkBlockLang.
*/
class LinkBlockLang extends DataLangCore
{
// Don't replace domain in init() with $this->domain for translation parsing
protected $domain = 'Modules.Linklist.Shop';
protected $keys = ['id_link_block'];
protected $fieldsToUpdate = ['name'];
/**
* @var array<string, array<string, string>>
*/
public $fieldNames = [];
protected function init()
{
$this->fieldNames = [
'name' => [
md5('Products') => $this->translator->trans('Products', [], 'Modules.Linklist.Shop', $this->locale),
md5('Our company') => $this->translator->trans('Our company', [], 'Modules.Linklist.Shop', $this->locale),
],
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,265 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Presenter;
use Meta;
use PrestaShop\Module\LinkList\Filter\LinkFilter;
use PrestaShop\Module\LinkList\Model\LinkBlock;
use Tools;
/**
* Class LinkBlockPresenter.
*/
class LinkBlockPresenter
{
private $link;
private $language;
private $linkFilter;
/**
* LinkBlockPresenter constructor.
*
* @param \Link $link
* @param \Language $language
*/
public function __construct(\Link $link, \Language $language, ?LinkFilter $linkFilter = null)
{
$this->link = $link;
$this->language = $language;
$this->linkFilter = $linkFilter ?? new LinkFilter();
}
/**
* @param LinkBlock $cmsBlock
*
* @return array
*
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function present(LinkBlock $cmsBlock)
{
return [
'id' => (int) $cmsBlock->id,
'title' => $cmsBlock->name[(int) $this->language->id],
'hook' => (new \Hook((int) $cmsBlock->id_hook))->name,
'position' => $cmsBlock->position,
'links' => $this->makeLinks($cmsBlock->content, $cmsBlock->custom_content),
];
}
/**
* Check the url if is an external link.
*
* @param string $url
*
* @return bool
*/
public function isExternalLink($url)
{
$baseLink = preg_replace('#^(http)s?://#', '', $this->link->getBaseLink());
$url = Tools::strtolower($url);
if (preg_match('#^(http)s?://#', $url) && !preg_match('#^(http)s?://' . preg_quote(rtrim($baseLink, '/'), '/') . '#', $url)) {
return true;
}
return false;
}
/**
* @param array $content
* @param array $custom_content
*
* @return array
*/
private function makeLinks($content, $custom_content)
{
$cmsLinks = $productLinks = $staticsLinks = $customLinks = $categoryLinks = [];
if (isset($content['cms'])) {
$cmsLinks = $this->makeCmsLinks($content['cms']);
}
if (isset($content['product'])) {
$productLinks = $this->makeProductLinks($content['product']);
}
if (isset($content['static'])) {
$staticsLinks = $this->makeStaticLinks($content['static']);
}
if (isset($content['category'])) {
$categoryLinks = $this->makeCategoryLinks($content['category']);
}
$customLinks = $this->makeCustomLinks($custom_content);
return array_merge(
$cmsLinks,
$productLinks,
$staticsLinks,
$customLinks,
$categoryLinks
);
}
/**
* @param array $cmsIds
*
* @return array
*
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
private function makeCmsLinks($cmsIds)
{
$cmsLinks = [];
foreach ($cmsIds as $cmsId) {
$cms = new \CMS((int) $cmsId);
if (null !== $cms->id && $cms->active) {
$cmsLinks[] = [
'id' => 'link-cms-page-' . $cms->id,
'class' => 'cms-page-link',
'title' => $cms->meta_title[(int) $this->language->id],
'description' => $cms->meta_description[(int) $this->language->id],
'url' => $this->link->getCMSLink($cms),
];
}
}
return $cmsLinks;
}
/**
* @param array $productIds
*
* @return array
*/
private function makeProductLinks($productIds)
{
$productLinks = [];
foreach ($productIds as $productId) {
if (false === $productId || $this->isLinkDisabled($productId)) {
continue;
}
$meta = \Meta::getMetaByPage($productId, (int) $this->language->id);
$productLinks[] = [
'id' => 'link-product-page-' . $productId,
'class' => 'cms-page-link',
'title' => $meta['title'],
'description' => $meta['description'],
'url' => $this->link->getPageLink($productId, true),
];
}
return $productLinks;
}
/**
* @param array $staticIds
*
* @return array
*/
private function makeStaticLinks($staticIds)
{
$staticLinks = [];
foreach ($staticIds as $staticId) {
if (false === $staticId || $this->isLinkDisabled($staticId)) {
continue;
}
$meta = \Meta::getMetaByPage($staticId, (int) $this->language->id);
$staticLinks[] = [
'id' => 'link-static-page-' . $staticId,
'class' => 'cms-page-link',
'title' => $meta['title'],
'description' => $meta['description'],
'url' => $this->link->getPageLink($staticId, true),
];
}
return $staticLinks;
}
/**
* @param array $customContent
*
* @return array
*/
private function makeCustomLinks($customContent)
{
$customLinks = [];
if (!isset($customContent[$this->language->id])) {
return $customLinks;
}
$customLinks = $customContent[$this->language->id];
$self = $this;
$customLinks = array_map(function ($el) use ($self) {
return [
'id' => 'link-custom-page-' . Tools::str2url($el['title']),
'class' => 'custom-page-link',
'title' => $el['title'],
'description' => '',
'url' => $el['url'],
'target' => $self->isExternalLink($el['url']) ? '_blank' : '',
];
}, array_filter($customLinks));
return $customLinks;
}
/**
* @param array $categoryIds
*
* @return array
*/
private function makeCategoryLinks($categoryIds)
{
$categoryLinks = [];
foreach ($categoryIds as $categoryId) {
if (false === $categoryId) {
continue;
}
$meta = Meta::getCategoryMetas($categoryId, (int) $this->language->id, '', null);
$categoryLinks[] = [
'id' => 'link-category-' . $categoryId,
'class' => 'category-link',
'title' => $meta['name'],
'description' => strip_tags($meta['description']),
'url' => $this->link->getCategoryLink((int) $categoryId),
];
}
return $categoryLinks;
}
private function isLinkDisabled(string $routeId): bool
{
return !$this->linkFilter->isRouteEnabled($routeId);
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,514 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\LinkList\Repository;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Result;
use Hook;
use PrestaShop\Module\LinkList\Adapter\ObjectModelHandler;
use PrestaShop\PrestaShop\Adapter\Shop\Context;
use PrestaShop\PrestaShop\Core\Exception\DatabaseException;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class LinkBlockRepository.
*/
class LinkBlockRepository
{
/**
* @var Connection
*/
private $connection;
/**
* @var string
*/
private $dbPrefix;
/**
* @var array
*/
private $languages;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var bool
*/
private $isMultiStoreUsed;
/**
* @var Context
*/
private $multiStoreContext;
/**
* @var ObjectModelHandler
*/
private $objectModelHandler;
/**
* LinkBlockRepository constructor.
*
* @param Connection $connection
* @param string $dbPrefix
* @param array $languages
* @param TranslatorInterface $translator
*/
public function __construct(
Connection $connection,
$dbPrefix,
array $languages,
TranslatorInterface $translator,
bool $isMultiStoreUsed,
Context $multiStoreContext,
ObjectModelHandler $objectModelHandler
) {
$this->connection = $connection;
$this->dbPrefix = $dbPrefix;
$this->languages = $languages;
$this->translator = $translator;
$this->isMultiStoreUsed = $isMultiStoreUsed;
$this->objectModelHandler = $objectModelHandler;
$this->multiStoreContext = $multiStoreContext;
}
/**
* Returns the list of hook with associated Link blocks.
*
* @return array
*/
public function getHooksWithLinks()
{
$qb = $this->connection->createQueryBuilder();
$qb
->select('h.id_hook, h.name, h.title')
->from($this->dbPrefix . 'link_block', 'lb')
->leftJoin('lb', $this->dbPrefix . 'hook', 'h', 'lb.id_hook = h.id_hook')
->groupBy('h.id_hook')
->orderBy('h.name')
;
return $qb->execute()->fetchAll();
}
/**
* @param array $data
*
* @return string
*
* @throws DatabaseException
*/
public function create(array $data)
{
$idHook = $data['id_hook'];
$qb = $this->connection->createQueryBuilder();
$qb
->insert($this->dbPrefix . 'link_block')
->values([
'id_hook' => ':idHook',
'content' => ':content',
])
->setParameters([
'idHook' => $idHook,
'content' => json_encode([
'cms' => empty($data['cms']) ? [false] : $data['cms'],
'static' => empty($data['static']) ? [false] : $data['static'],
'product' => empty($data['product']) ? [false] : $data['product'],
'category' => empty($data['category']) ? [false] : $data['category'],
]),
]);
$this->executeQueryBuilder($qb, 'Link block error');
$linkBlockId = $this->connection->lastInsertId();
$this->updateLanguages((int) $linkBlockId, $data['block_name'], $data['custom_content']);
$this->objectModelHandler->handleMultiShopAssociation(
(int) $linkBlockId,
$data['shop_association'],
!$this->isMultiStoreUsed
);
$this->updateMaxPosition((int) $linkBlockId, $idHook, $data['shop_association']);
return $linkBlockId;
}
/**
* @param int $linkBlockId
* @param array $data
*
* @throws DatabaseException
*/
public function update($linkBlockId, array $data)
{
$qb = $this->connection->createQueryBuilder();
$qb
->update($this->dbPrefix . 'link_block', 'lb')
->andWhere('lb.id_link_block = :linkBlockId')
->set('id_hook', ':idHook')
->set('content', ':content')
->setParameters([
'linkBlockId' => $linkBlockId,
'idHook' => $data['id_hook'],
'content' => json_encode([
'cms' => empty($data['cms']) ? [false] : $data['cms'],
'static' => empty($data['static']) ? [false] : $data['static'],
'product' => empty($data['product']) ? [false] : $data['product'],
'category' => empty($data['category']) ? [false] : $data['category'],
]),
])
;
$this->executeQueryBuilder($qb, 'Link block error');
$this->updateLanguages($linkBlockId, $data['block_name'], $data['custom_content']);
if ($this->isMultiStoreUsed) {
$this->objectModelHandler->handleMultiShopAssociation(
$linkBlockId,
$data['shop_association']
);
}
}
/**
* @param int $idLinkBlock
*
* @throws DatabaseException
*/
public function delete($idLinkBlock): void
{
if (count($this->multiStoreContext->getAllShopIds()) === count($this->multiStoreContext->getContextListShopID())) {
$tableNames = [
'link_block_lang',
'link_block',
'link_block_shop',
];
foreach ($tableNames as $tableName) {
$qb = $this->connection->createQueryBuilder();
$qb
->delete($this->dbPrefix . $tableName)
->andWhere('id_link_block = :idLinkBlock')
->setParameter('idLinkBlock', $idLinkBlock)
;
$this->executeQueryBuilder($qb, 'Delete error');
}
} else {
// Delete only from specific stores
if (!$this->multiStoreContext->isAllShopContext()) {
$qb = $this->connection->createQueryBuilder();
$qb
->delete($this->dbPrefix . 'link_block_shop')
->andWhere('id_link_block = :idLinkBlock')
->andWhere('id_shop IN (:shopIds)')
->setParameter('shopIds', $this->multiStoreContext->getContextListShopID(), Connection::PARAM_STR_ARRAY)
->setParameter('idLinkBlock', $idLinkBlock);
$this->executeQueryBuilder($qb, 'Delete from multi-store tables error');
}
}
}
/**
* @return array
*/
public function createTables()
{
$errors = [];
$engine = _MYSQL_ENGINE_;
$this->dropTables();
$queries = [
"CREATE TABLE IF NOT EXISTS `{$this->dbPrefix}link_block`(
`id_link_block` int(10) unsigned NOT NULL auto_increment,
`id_hook` int(1) unsigned DEFAULT NULL,
`position` int(10) unsigned NOT NULL default '0',
`content` text default NULL,
PRIMARY KEY (`id_link_block`)
) ENGINE=$engine DEFAULT CHARSET=utf8",
"CREATE TABLE IF NOT EXISTS `{$this->dbPrefix}link_block_lang`(
`id_link_block` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`name` varchar(40) NOT NULL default '',
`custom_content` text default NULL,
PRIMARY KEY (`id_link_block`, `id_lang`)
) ENGINE=$engine DEFAULT CHARSET=utf8",
"CREATE TABLE IF NOT EXISTS `{$this->dbPrefix}link_block_shop` (
`id_link_block` int(10) unsigned NOT NULL auto_increment,
`id_shop` int(10) unsigned NOT NULL,
`position` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id_link_block`, `id_shop`)
) ENGINE=$engine DEFAULT CHARSET=utf8",
];
foreach ($queries as $query) {
try {
$this->connection->executeQuery($query);
} catch (DBALException $e) {
$errors[] = [
'key' => json_encode($e->getMessage()),
'parameters' => [],
'domain' => 'Admin.Modules.Notification',
];
}
}
return $errors;
}
/**
* @return array
*/
public function installFixtures()
{
$errors = [];
$id_hook = (int) Hook::getIdByName('displayFooter');
$queries = [
'INSERT INTO `' . $this->dbPrefix . 'link_block` (`id_link_block`, `id_hook`, `position`, `content`) VALUES
(1, ' . $id_hook . ', 0, \'{"cms":[false],"product":["prices-drop","new-products","best-sales"],"static":[false],"category":[false]}\'),
(2, ' . $id_hook . ', 1, \'{"cms":["1","2","3","4","5"],"product":[false],"static":["contact","sitemap","stores"],"category":[false]}\');',
];
foreach ($this->languages as $lang) {
$queries[] = 'INSERT INTO `' . $this->dbPrefix . 'link_block_lang` (`id_link_block`, `id_lang`, `name`) VALUES
(1, ' . (int) $lang['id_lang'] . ', "' . pSQL($this->translator->trans('Products', [], 'Modules.Linklist.Shop', $lang['locale'])) . '"),
(2, ' . (int) $lang['id_lang'] . ', "' . pSQL($this->translator->trans('Our company', [], 'Modules.Linklist.Shop', $lang['locale'])) . '");'
;
}
foreach ($this->multiStoreContext->getShops(true, true) as $shopId) {
$queries[] = 'INSERT INTO `' . $this->dbPrefix . 'link_block_shop` (`id_link_block`, `id_shop`, `position`) VALUES
(1, ' . (int) $shopId . ', 0),
(2, ' . (int) $shopId . ', 1);'
;
}
foreach ($queries as $query) {
try {
$this->connection->executeQuery($query);
} catch (DBALException $e) {
$errors[] = [
'key' => json_encode($e->getMessage()),
'parameters' => [],
'domain' => 'Admin.Modules.Notification',
];
}
}
return $errors;
}
/**
* @return array
*/
public function dropTables()
{
$errors = [];
$tableNames = [
'link_block_shop',
'link_block_lang',
'link_block',
];
foreach ($tableNames as $tableName) {
$sql = 'DROP TABLE IF EXISTS ' . $this->dbPrefix . $tableName;
try {
$this->connection->executeQuery($sql);
} catch (DBALException $e) {
$errors[] = [
'key' => json_encode($e->getMessage()),
'parameters' => [],
'domain' => 'Admin.Modules.Notification',
];
}
}
return $errors;
}
/**
* @param int $linkBlockId
* @param array $blockName
* @param array $custom
*
* @throws DatabaseException
*/
private function updateLanguages($linkBlockId, array $blockName, array $custom)
{
foreach ($this->languages as $language) {
$qb = $this->connection->createQueryBuilder();
$qb
->select('lbl.id_link_block')
->from($this->dbPrefix . 'link_block_lang', 'lbl')
->andWhere('lbl.id_link_block = :linkBlockId')
->andWhere('lbl.id_lang = :langId')
->setParameter('linkBlockId', $linkBlockId)
->setParameter('langId', $language['id_lang'])
;
$foundRows = $qb->execute()->rowCount();
$qb = $this->connection->createQueryBuilder();
if (!$foundRows) {
$qb
->insert($this->dbPrefix . 'link_block_lang')
->values([
'id_link_block' => ':linkBlockId',
'id_lang' => ':langId',
'name' => ':name',
'custom_content' => ':customContent',
])
;
} else {
$qb
->update($this->dbPrefix . 'link_block_lang', 'lbl')
->set('name', ':name')
->set('custom_content', ':customContent')
->andWhere('lbl.id_link_block = :linkBlockId')
->andWhere('lbl.id_lang = :langId')
;
}
$qb
->setParameters([
'linkBlockId' => $linkBlockId,
'langId' => $language['id_lang'],
'name' => $blockName[$language['id_lang']],
'customContent' => empty($custom) ? null : json_encode($custom[$language['id_lang']]),
]);
$this->executeQueryBuilder($qb, 'Link block language error');
}
}
/**
* @param QueryBuilder $qb
* @param string $errorPrefix
*
* @return Result|int|string
*
* @throws DatabaseException
*/
private function executeQueryBuilder(QueryBuilder $qb, $errorPrefix = 'SQL error')
{
try {
$statement = $qb->execute();
} catch (DBALException $e) {
throw new DatabaseException($errorPrefix . ': ' . var_export($e->getMessage(), true));
}
return $statement;
}
/**
* @param int $idHook
* @param int $idShop
*
* @return int
*/
private function getHookMaxPosition(int $idHook, int $idShop): int
{
$qb = $this->connection->createQueryBuilder();
$qb->select('MAX(lbs.position)')
->from($this->dbPrefix . 'link_block_shop', 'lbs')
->leftJoin('lbs', $this->dbPrefix . 'link_block', 'lb', 'lbs.id_link_block = lb.id_link_block')
->andWhere('lb.id_hook = :idHook')
->andWhere('lbs.id_shop = :idShop')
->setParameter('idHook', $idHook)
->setParameter('idShop', $idShop)
;
$maxPosition = $qb->execute()->fetch(\PDO::FETCH_COLUMN);
return null !== $maxPosition ? $maxPosition + 1 : 0;
}
/**
* @param int $linkBlockId
* @param array $shopIds
*
* @throws DatabaseException
*/
private function updateMaxPosition(int $linkBlockId, ?int $hookId, array $shopIds): void
{
$qb = $this->connection->createQueryBuilder();
foreach ($shopIds as $shopId) {
$qb
->update($this->dbPrefix . 'link_block_shop lbs')
->set('position', ':position')
->andWhere('lbs.id_shop = :shopId')
->andWhere('lbs.id_link_block = :linkBlockId')
->setParameter('position', $this->getHookMaxPosition($hookId, $shopId))
->setParameter('shopId', $shopId)
->setParameter('linkBlockId', $linkBlockId);
$this->executeQueryBuilder($qb, 'Link block max position update error');
}
}
/**
* @param int $shopId
* @param array $positionsData
*
* @return void
*/
public function updatePositions(int $shopId, array $positionsData = []): void
{
try {
$this->connection->beginTransaction();
$i = 0;
foreach ($positionsData['positions'] as $position) {
$qb = $this->connection->createQueryBuilder();
$qb
->update($this->dbPrefix . 'link_block_shop')
->set('position', ':position')
->andWhere('id_link_block = :linkBlockId')
->andWhere('id_shop = :shopId')
->setParameter('shopId', $shopId)
->setParameter('linkBlockId', $position['rowId'])
->setParameter('position', $i);
++$i;
try {
$qb->execute();
} catch (DBALException $e) {
throw new DatabaseException('Could not update #%i');
}
}
$this->connection->commit();
} catch (ConnectionException $e) {
$this->connection->rollBack();
throw new DatabaseException('Could not update positions.');
}
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,27 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_1_3_0($object)
{
return $object->registerHook('actionObjectCmsUpdateAfter') && $object->registerHook('actionObjectCmsDeleteAfter');
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_1_4_0($object)
{
return $object->registerHook('actionAdminStoresControllerUpdate_optionsAfter');
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_3_0_0($object)
{
Configuration::deleteByName('FOOTER_CMS');
Configuration::deleteByName('FOOTER_BLOCK_ACTIVATION');
Configuration::deleteByName('FOOTER_POWEREDBY');
Configuration::deleteByName('FOOTER_PRICE-DROP');
Configuration::deleteByName('FOOTER_NEW-PRODUCTS');
Configuration::deleteByName('FOOTER_BEST-SALES');
Configuration::deleteByName('FOOTER_CONTACT');
Configuration::deleteByName('FOOTER_SITEMAP');
Db::getInstance()->execute('DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'cms_block_page`');
return true;
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_4_0_0($object)
{
$result = true;
$result &= Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'tab` SET `route_name` = "admin_link_block_list" WHERE `class_name` = "AdminLinkWidget"');
$result &= Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'link_block` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;');
$result &= Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'link_block_lang` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;');
$result &= Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'link_block_shop` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;');
return (bool) $result;
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_5_0_0()
{
$result = true;
$result &= Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'link_block_shop` ADD COLUMN `position` int(10) unsigned NOT NULL DEFAULT 0');
// Delete blockcms data that are not used in previous version of this module
$result &= Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'link_block_shop`');
foreach (Shop::getShops(true, null, true) as $shopId) {
$result &= Db::getInstance()->execute(
'INSERT INTO `' . _DB_PREFIX_ . 'link_block_shop` (`id_link_block`, `position`, `id_shop`)
SELECT `id_link_block`, `position`, ' . $shopId . ' FROM `' . _DB_PREFIX_ . 'link_block`
'
);
}
return (bool) $result;
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
if (!defined('_PS_VERSION_')) {
exit;
}
function upgrade_module_5_0_5($object)
{
return $object->registerHook('actionGeneralPageSave');
}

View File

@@ -0,0 +1,51 @@
{#**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*#}
{% set displayName = true %}
{% if (grid.view_options.display_name is defined) %}
{% set displayName = grid.view_options.display_name %}
{% endif %}
<div class="card js-grid-panel" id="{{ grid.id }}_grid_panel" data-hook-name="{{ grid.name|split(' ')|first }}">
{% block grid_panel_header %}
{% if displayName is not same as(false) %}
<div class="card-header js-grid-header">
<h3 class="d-inline-block card-header-title">
{{ grid.name }} ({{ grid.data.records_total }})
</h3>
{% block grid_actions_block %}
<div class="d-inline-block float-right">
{{ include('@PrestaShop/Admin/Common/Grid/Blocks/grid_actions.html.twig', {'grid': grid}) }}
</div>
{% endblock %}
</div>
{% endif %}
{% endblock %}
{% block grid_panel_body %}
<div class="card-body">
{% block grid_view_block %}
{{ include('@PrestaShop/Admin/Common/Grid/grid.html.twig', {'grid': grid }) }}
{% endblock %}
</div>
{% endblock %}
{% block grid_panel_footer %}{% endblock %}
</div>
{% block grid_panel_extra_content %}{% endblock %}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,87 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
import TranslatableInput from '@components/translatable-input';
import ChoiceTree from '@components/form/choice-tree';
const $ = window.$;
$(() => {
new TranslatableInput({localeInputSelector: '.js-locale-input'});
const idHookSelect = $('#form_link_block_id_hook');
if (idHookSelect.hasClass('select2-hidden-accessible')) {
const targetNode = document.getElementsByTagName('body')[0];
const observer = new MutationObserver(function(mutationsList, observer) {
for(let mutation of mutationsList) {
if (mutation.type === 'childList' && mutation.addedNodes.length == 1) {
let node = mutation.addedNodes[0];
if ($(node).hasClass('select2-container--open')) {
$('#select2-form_link_block_id_hook-results li').each(function () {
$(this).attr('data-hook-name', $(this).html());
});
}
}
}
});
observer.observe(targetNode, { childList: true });
}
const addCustomButton = $('.add-collection-btn');
addCustomButton.on('click', appendPrototype);
const collectionId = addCustomButton.data().collectionId;
const collection = document.getElementById(collectionId);
const collectionPrototype = collection.dataset.prototype;
if (collection.children.length) {
$('.custom_collection .col-sm-12').each((index, customBlock) => {
appendDeleteButton($(customBlock));
});
} else {
appendPrototype();
}
function appendPrototype(event) {
if (event) {
event.preventDefault();
}
const newChild = collectionPrototype.replace(/__name__/g, (collection.children.length + 1));
const $newChild = $(newChild);
$('#'+collectionId).append($newChild);
appendDeleteButton($newChild);
}
function appendDeleteButton(customBlock) {
const collection = customBlock.closest('.custom_collection');
const $button = $('<button class="remove_custom_url btn btn-primary mt-1">'+collection.data('deleteButtonLabel')+'</button>');
$button.on('click', (event) => {
event.preventDefault();
const $button = $(event.target);
const $row = $button.closest('.row');
$row.remove();
return false;
});
customBlock.find('.locale-input-group').first().closest('.col-sm-12').append($button);
}
new ChoiceTree('#form_link_block_shop_association').enableAutoCheckChildren();
});

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,38 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
import Grid from '@components/grid/grid';
import LinkRowActionExtension from '@components/grid/extension/link-row-action-extension';
import SubmitRowActionExtension from '@components/grid/extension/action/row/submit-row-action-extension';
import SortingExtension from "@components/grid/extension/sorting-extension";
import PositionExtension from "@components/grid/extension/position-extension";
const $ = window.$;
$(() => {
let gridDivs = document.querySelectorAll('.js-grid');
gridDivs.forEach((gridDiv) => {
const linkBlockGrid = new Grid(gridDiv.dataset.gridId);
linkBlockGrid.addExtension(new SortingExtension());
linkBlockGrid.addExtension(new LinkRowActionExtension());
linkBlockGrid.addExtension(new SubmitRowActionExtension());
linkBlockGrid.addExtension(new PositionExtension());
});
});

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

6436
modules/ps_linklist/views/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,43 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,24 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,101 @@
{#**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*#}
{%- block choice_widget_expanded -%}
<div {{ block('widget_container_attributes') }}>
{% for name, choices in form.vars.choices %}
{% if choices is iterable %}
<label class="choice_category">
<strong>
{{ choice_translation_domain is same as(false) ? name : name|trans({}, choice_translation_domain) }}
</strong>
</label>
<div>
{% for key,choice in choices %}
{{ form_widget(form[key]) }}
{{ form_label(form[key]) }}
{% endfor %}
</div>
{% else %}
{{- form_widget(form[name]) -}}
{{- form_label(form[name], null, {translation_domain: choice_translation_domain}) -}}
{% endif %}
{% endfor %}
</div>
{%- endblock choice_widget_expanded -%}
{% block checkbox_widget -%}
{% set parent_label_class = parent_label_class|default('') -%}
{% set switch = switch|default('') -%}
{% set checkbox_input %}
<input type="checkbox" class="js-bulk-action-checkbox"
{% if switch %}data-toggle="switch"{% endif %} {% if switch %}class="{{ switch }}"{% endif %} {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
<i class="md-checkbox-control"></i>
{% endset %}
{% if 'checkbox-inline' in parent_label_class %}
<div class="md-checkbox md-checkbox-inline">
{{- form_label(form, null, { widget: checkbox_input }) -}}
</div>
{% else -%}
<div class="md-checkbox my-1">
{{- form_label(form, null, { widget: checkbox_input }) -}}
</div>
{%- endif %}
{%- endblock checkbox_widget %}
{% block form_row -%}
{% apply spaceless %}
<div class="{{ block('form_row_class') }} {% if (not compound or force_error|default(false)) and not valid %} has-error{% endif %}">
{% if form.vars.label is not same as(false) %}
{{ form_label(form) }}
{% set formGroupClasses = block('form_group_class') %}
{% else %}
{% set formGroupClasses = block('unlabeled_form_group_class') %}
{% endif %}
<div class="{{ formGroupClasses }}">
{{ form_widget(form) }}
{{ form_errors(form) }}
</div>
</div>
{% endapply %}
{%- endblock form_row %}
{% block form_row_class -%}
form-group row
{%- endblock form_row_class %}
{% block unlabeled_form_group_class -%}
col-sm-12
{%- endblock unlabeled_form_group_class %}
{%- block custom_url_widget -%}
{% set classes = form.vars.attr.class|default('') ~ ' js-locale-input'%}
{% set classes = classes ~ ' js-locale-' ~ form.vars.label %}
<div class="form-control {{ classes }}">
{{ form_row(form.title) }}
{{ form_row(form.url) }}
</div>
{%- endblock custom_url_widget -%}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,81 @@
{#**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*#}
{% extends '@PrestaShop/Admin/layout.html.twig' %}
{% trans_default_domain "Admin.Design.Feature" %}
{% form_theme linkBlockForm '@Modules/ps_linklist/views/templates/admin/fields.html.twig' %}
{% block content %}
{% if linkBlockForm.vars.data.link_block.id_link_block is defined and linkBlockForm.vars.data.link_block.id_link_block is not null %}
{% set formAction = url('admin_link_block_edit_process', {'linkBlockId': linkBlockForm.vars.data.link_block.id_link_block}) %}
{% else %}
{% set formAction = url('admin_link_block_create_process') %}
{% endif %}
{{ form_start(linkBlockForm, {'action': formAction, 'attr': {'class': 'form', 'id': 'link_block_form'}}) }}
<div class="row justify-content-center">
{% block link_block_form %}
<div class="col-xl-10">
<div class="card">
<h3 class="card-header">
<i class="material-icons">mode_edit</i>
{% if linkBlockForm.vars.data.link_block.id_link_block is defined %}
{{ 'Edit the link block.'|trans({}, 'Modules.Linklist.Admin') }}
{% else %}
{{ 'New link block'|trans({}, 'Modules.Linklist.Admin') }}
{% endif %}
</h3>
<div class="card-block row">
<div class="card-text m-auto w-75">
{{ form_row(linkBlockForm.link_block.block_name) }}
{{ form_row(linkBlockForm.link_block.id_hook) }}
{{ form_row(linkBlockForm.link_block.cms) }}
{{ form_row(linkBlockForm.link_block.product) }}
{{ form_row(linkBlockForm.link_block.category) }}
{{ form_row(linkBlockForm.link_block.static) }}
{% if linkBlockForm.link_block.shop_association is defined %}
{{ form_row(linkBlockForm.link_block.shop_association) }}
{% endif %}
<div class="form-group">
{{ form_row(linkBlockForm.link_block.custom) }}
<div class="d-flex justify-content-end">
<button data-collection-id="{{ linkBlockForm.link_block.custom.vars.id }}" class="btn btn-primary add-collection-btn">{{ 'Add'|trans({}, 'Admin.Actions') }}</button>
</div>
</div>
{{ form_rest(linkBlockForm.link_block) }}
{% do linkBlockForm.link_block.setRendered %}
{{ form_rest(linkBlockForm) }}
</div>
</div>
<div class="card-footer">
<div class="d-flex justify-content-between">
<a href="{{ url('admin_link_block_list') }}" class="btn btn-secondary">{{ 'Cancel'|trans({}, 'Admin.Actions') }}</a>
<button class="btn btn-primary">{{ 'Save'|trans({}, 'Admin.Actions') }}</button>
</div>
</div>
</div>
</div>
{% endblock %}
</div>
{{ form_end(linkBlockForm) }}
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('../modules/ps_linklist/views/public/form.bundle.js') }}"></script>
{% endblock %}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,36 @@
{#**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*#}
{% extends '@PrestaShop/Admin/layout.html.twig' %}
{% trans_default_domain "Admin.Design.Feature" %}
{% block content %}
<div class="row">
{% for grid in grids %}
<div class="col-sm-6">
{{ include('@PrestaShop/Admin/Common/Grid/grid_panel.html.twig', {'grid': grid }) }}
</div>
{% endfor %}
</div>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('../modules/ps_linklist/views/public/grid.bundle.js') }}"></script>
{% endblock %}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,37 @@
{**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*}
{foreach $linkBlocks as $linkBlock}
<h3>{$linkBlock.title|escape:'html':'UTF-8'}</h3>
<ul>
{foreach $linkBlock.links as $link}
<li>
<a
id="{$link.id}-{$linkBlock.id}"
class="{$link.class}"
href="{$link.url|escape:'html':'UTF-8'}"
title="{$link.description|escape:'html':'UTF-8'}"
{if !empty($link.target)} target="{$link.target|escape:'html':'UTF-8'}" {/if}
>
{$link.title|escape:'html':'UTF-8'}
</a>
</li>
{/foreach}
</ul>
{/foreach}

View File

@@ -0,0 +1,37 @@
{**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*}
{foreach $linkBlocks as $linkBlock}
<h3>{$linkBlock.title|escape:'html':'UTF-8'}</h3>
<ul>
{foreach $linkBlock.links as $link}
<li>
<a
id="{$link.id}-{$linkBlock.id}"
class="{$link.class}"
href="{$link.url|escape:'html':'UTF-8'}"
title="{$link.description|escape:'html':'UTF-8'}"
{if !empty($link.target)} target="{$link.target|escape:'html':'UTF-8'}" {/if}
>
{$link.title|escape:'html':'UTF-8'}
</a>
</li>
{/foreach}
</ul>
{/foreach}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 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;

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"outDir": "./public/",
"noImplicitAny": true,
"module": "es6",
"target": "es5",
"strict": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"allowJs": true,
"baseUrl": "./",
"typeRoots": ["node_modules/@types"],
"paths": {
"@PSJs/*": ["../../admin-dev/themes/new-theme/js/*"]
}
},
"ts-node": {
"compilerOptions": {
"module": "commonjs"
}
}
}

View File

@@ -0,0 +1,87 @@
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
let config = {
entry: {
grid: [
'./js/grid',
],
form: [
'./js/form',
]
},
output: {
path: path.resolve(__dirname, 'public'),
filename: '[name].bundle.js'
},
//devtool: 'source-map', // uncomment me to build source maps (really slow)
resolve: {
extensions: ['.js', '.ts'],
alias: {
'@PSTypes': path.resolve(__dirname, '../../../admin-dev/themes/new-theme/js/types'),
'@components': path.resolve(__dirname, '../../../admin-dev/themes/new-theme/js/components'),
'@app': path.resolve(__dirname, '../../../admin-dev/themes/new-theme/js/app')
}
},
module: {
rules: [
{
test: /\.js$/,
include: path.resolve(__dirname, '../js'),
use: [{
loader: 'babel-loader',
options: {
presets: [
['es2015', { modules: false }]
]
}
}]
},
{
test: /\.ts?$/,
loader: 'ts-loader',
options: {
onlyCompileBundledFiles: true,
},
exclude: /node_modules/,
},
]
},
plugins: []
};
if (process.env.NODE_ENV === 'production') {
config = {
...config,
optimization: {
minimize: true,
minimizer: [
new TerserPlugin(),
],
},
}
} else {
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}
module.exports = config;