Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

View File

@@ -0,0 +1,158 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* 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 <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Mbo\Tab;
use PrestaShop\Module\Mbo\RecommendedModule\RecommendedModuleCollection;
use PrestaShop\Module\Mbo\RecommendedModule\RecommendedModuleCollectionInterface;
class Tab implements TabInterface
{
/**
* @var string class name of the tab
*/
private $legacyClassName;
/**
* @var string class name of the tab
*/
private $displayMode;
/**
* @var RecommendedModuleCollectionInterface recommended modules of the tab
*/
private $recommendedModules;
/**
* Tab constructor.
*/
public function __construct()
{
$this->recommendedModules = new RecommendedModuleCollection();
}
/**
* {@inheritdoc}
*/
public function getLegacyClassName()
{
return $this->legacyClassName;
}
/**
* {@inheritdoc}
*/
public function setLegacyClassName($legacyClassName)
{
$this->legacyClassName = $legacyClassName;
return $this;
}
/**
* {@inheritdoc}
*/
public function getDisplayMode()
{
return $this->displayMode;
}
/**
* {@inheritdoc}
*/
public function setDisplayMode($displayMode)
{
$this->displayMode = $displayMode;
return $this;
}
/**
* {@inheritdoc}
*/
public function getRecommendedModules()
{
return $this->recommendedModules;
}
/**
* {@inheritdoc}
*/
public function setRecommendedModules(RecommendedModuleCollectionInterface $recommendedModules)
{
$this->recommendedModules = $recommendedModules;
return $this;
}
/**
* {@inheritdoc}
*/
public function hasRecommendedModules()
{
return !$this->recommendedModules->isEmpty();
}
/**
* {@inheritdoc}
*/
public function getRecommendedModulesInstalled()
{
$recommendedModulesInstalled = $this->getRecommendedModules();
if ($this->hasRecommendedModules()) {
return $recommendedModulesInstalled->getInstalled();
}
return $recommendedModulesInstalled;
}
/**
* {@inheritdoc}
*/
public function getRecommendedModulesNotInstalled()
{
$recommendedModulesNotInstalled = $this->getRecommendedModules();
if ($this->hasRecommendedModules()) {
return $recommendedModulesNotInstalled->getNotInstalled();
}
return $recommendedModulesNotInstalled;
}
/**
* {@inheritdoc}
*/
public function shouldDisplayButton()
{
return $this->hasRecommendedModules()
&& TabInterface::DISPLAY_MODE_MODAL === $this->getDisplayMode();
}
/**
* {@inheritdoc}
*/
public function shouldDisplayAfterContent()
{
return $this->hasRecommendedModules()
&& TabInterface::DISPLAY_MODE_AFTER_CONTENT === $this->getDisplayMode();
}
}

View File

@@ -0,0 +1,111 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* 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 <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Mbo\Tab;
use ArrayIterator;
class TabCollection implements TabCollectionInterface
{
/**
* @var TabInterface[]
*/
private $tabs = [];
/**
* {@inheritdoc}
*/
public function addTab(TabInterface $tab)
{
$this->tabs[] = $tab;
return $this;
}
/**
* {@inheritdoc}
*/
public function getTab($tabClassName)
{
foreach ($this->tabs as $tab) {
if ($tabClassName === $tab->getLegacyClassName()) {
return $tab;
}
}
return new Tab();
}
/**
* {@inheritdoc}
*/
public function offsetExists($offset)
{
return array_key_exists($offset, $this->tabs);
}
/**
* {@inheritdoc}
*/
public function offsetSet($offset, $value)
{
$this->tabs[$offset] = $value;
}
/**
* {@inheritdoc}
*/
public function offsetGet($offset)
{
return $this->tabs[$offset];
}
/**
* {@inheritdoc}
*/
public function offsetUnset($offset)
{
unset($this->tabs[$offset]);
}
/**
* {@inheritdoc}
*/
public function getIterator()
{
return new ArrayIterator($this->tabs);
}
/**
* {@inheritdoc}
*/
public function count()
{
return count($this->tabs);
}
/**
* {@inheritdoc}
*/
public function isEmpty()
{
return empty($this->tabs);
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* 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 <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Mbo\Tab;
class TabCollectionDecoderXml
{
private $content;
/**
* Constructor.
*
* @param string $content
*/
public function __construct($content)
{
$this->content = $content;
}
/**
* @return array
*/
public function toArray()
{
$data = [];
if (empty($this->content)) {
return $data;
}
$simpleXMLElement = @simplexml_load_string($this->content);
if (false === $simpleXMLElement
|| !isset($simpleXMLElement->tab)
) {
return $data;
}
foreach ($simpleXMLElement->tab as $tab) {
$tabClassName = null;
$tabDisplayMode = 'slider_list';
$tabRecommendedModules = [];
foreach ($tab->attributes() as $key => $value) {
if ('class_name' === $key) {
$tabClassName = (string) $value;
}
if ('display_type' === $key) {
$tabDisplayMode = (string) $value;
}
}
foreach ($tab->children() as $module) {
if (isset($module['position'], $module['name'])) {
$tabRecommendedModules[(int) $module['position']] = (string) $module['name'];
}
}
if (!empty($tabClassName)) {
$data[$tabClassName] = [
'displayMode' => $tabDisplayMode,
'recommendedModules' => $tabRecommendedModules,
];
}
}
return $data;
}
}

View File

@@ -0,0 +1,104 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* 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 <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Mbo\Tab;
use PrestaShop\Module\Mbo\ModuleCollectionDataProvider;
use PrestaShop\Module\Mbo\RecommendedModule\RecommendedModule;
use PrestaShop\Module\Mbo\RecommendedModule\RecommendedModuleCollection;
class TabCollectionFactory implements TabCollectionFactoryInterface
{
private $moduleCollectionDataProvider;
/**
* Constructor.
*
* @param ModuleCollectionDataProvider $moduleCollectionDataProvider
*/
public function __construct(ModuleCollectionDataProvider $moduleCollectionDataProvider)
{
$this->moduleCollectionDataProvider = $moduleCollectionDataProvider;
}
/**
* {@inheritdoc}
*/
public function buildFromArray(array $data)
{
$tabCollection = new TabCollection();
if (empty($data)) {
return $tabCollection;
}
$modulesData = $this->moduleCollectionDataProvider->getData($this->getModuleNames($data));
if (empty($modulesData)) {
return $tabCollection;
}
foreach ($data as $tabClassName => $tabData) {
$recommendedModuleCollection = new RecommendedModuleCollection();
foreach ($tabData['recommendedModules'] as $position => $moduleName) {
if (isset($modulesData[$moduleName])) {
$recommendedModule = new RecommendedModule();
$recommendedModule->setModuleName($moduleName);
$recommendedModule->setPosition((int) $position);
$recommendedModule->setInstalled((bool) $modulesData[$moduleName]['database']['installed']);
$recommendedModule->setModuleData($modulesData[$moduleName]);
$recommendedModuleCollection->addRecommendedModule($recommendedModule);
}
}
if (!$recommendedModuleCollection->isEmpty()) {
$recommendedModuleCollection->sortByPosition();
$tab = new Tab();
$tab->setLegacyClassName($tabClassName);
$tab->setDisplayMode($tabData['displayMode']);
$tab->setRecommendedModules($recommendedModuleCollection);
$tabCollection->addTab($tab);
}
}
return $tabCollection;
}
/**
* @param array $data
*
* @return string[]
*/
private function getModuleNames(array $data)
{
$moduleNames = [];
foreach ($data as $tabData) {
foreach ($tabData['recommendedModules'] as $moduleName) {
$moduleNames[] = $moduleName;
}
}
return array_unique($moduleNames);
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* 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 <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Mbo\Tab;
interface TabCollectionFactoryInterface
{
/**
* Builds a tabs recommended modules collection from an array.
*
* @param array $data
*
* @return TabCollectionInterface
*/
public function buildFromArray(array $data);
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* 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 <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Mbo\Tab;
use ArrayAccess;
use Countable;
use IteratorAggregate;
interface TabCollectionInterface extends ArrayAccess, IteratorAggregate, Countable
{
/**
* Add a tab to this collection.
*
* @param TabInterface $tab
*
* @return self
*/
public function addTab(TabInterface $tab);
/**
* @param string $tabClassName
*
* @return TabInterface
*/
public function getTab($tabClassName);
/**
* @param mixed $offset
*
* @return TabInterface
*/
public function offsetGet($offset);
/**
* @return bool
*/
public function isEmpty();
}

View File

@@ -0,0 +1,128 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* 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 <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Mbo\Tab;
use Doctrine\Common\Cache\CacheProvider;
use PrestaShop\Module\Mbo\ExternalContentProvider\ExternalContentProviderInterface;
use PrestaShop\PrestaShop\Adapter\LegacyContext;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
class TabCollectionProvider implements TabCollectionProviderInterface
{
const CACHE_KEY = 'recommendedModules';
const CACHE_LIFETIME_SECONDS = 604800;
const API_URL = 'https://api.prestashop.com/xml/tab_modules_list_17.xml';
/**
* @var LegacyContext
*/
private $context;
/**
* @var ExternalContentProviderInterface
*/
private $externalContentProvider;
/**
* @var TabCollectionFactoryInterface
*/
private $tabCollectionFactory;
/**
* @var CacheProvider|null
*/
private $cacheProvider;
/**
* @param LegacyContext $context
* @param ExternalContentProviderInterface $externalContentProvider
* @param TabCollectionFactoryInterface $tabCollectionFactory
* @param CacheProvider|null $cacheProvider
*/
public function __construct(
LegacyContext $context,
ExternalContentProviderInterface $externalContentProvider,
TabCollectionFactoryInterface $tabCollectionFactory,
CacheProvider $cacheProvider = null
) {
$this->context = $context;
$this->externalContentProvider = $externalContentProvider;
$this->tabCollectionFactory = $tabCollectionFactory;
$this->cacheProvider = $cacheProvider;
}
/**
* {@inheritdoc}
*/
public function getTabCollection()
{
if ($this->isTabCollectionCached()) {
return $this->cacheProvider->fetch($this->getCacheKey());
}
$tabCollection = $this->getTabCollectionFromApi();
if ($this->cacheProvider
&& false === $tabCollection->isEmpty()
) {
$this->cacheProvider->save(
$this->getCacheKey(),
$tabCollection,
static::CACHE_LIFETIME_SECONDS
);
}
return $tabCollection;
}
private function getCacheKey()
{
return static::CACHE_KEY . '-' . $this->context->getEmployeeLanguageIso();
}
/**
* Check if recommended modules cache is set
*
* @return bool
*/
public function isTabCollectionCached()
{
return $this->cacheProvider
&& $this->cacheProvider->contains($this->getCacheKey());
}
/**
* Retrieve tabs with recommended modules from PrestaShop
*
* @return TabCollectionInterface
*
* @throws ServiceUnavailableHttpException
*/
private function getTabCollectionFromApi()
{
$apiResponse = $this->externalContentProvider->getContent(self::API_URL);
$tabCollectionDecoderXml = new TabCollectionDecoderXml($apiResponse);
return $this->tabCollectionFactory->buildFromArray($tabCollectionDecoderXml->toArray());
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* 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 <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Mbo\Tab;
interface TabCollectionProviderInterface
{
/**
* @return TabCollectionInterface
*/
public function getTabCollection();
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* 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 <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Mbo\Tab;
use PrestaShop\Module\Mbo\RecommendedModule\RecommendedModuleCollectionInterface;
interface TabInterface
{
const DISPLAY_MODE_MODAL = 'slider_list';
const DISPLAY_MODE_AFTER_CONTENT = 'default_list';
/**
* Get the class name of the tab.
*
* @return string
*/
public function getLegacyClassName();
/**
* @param string $legacyClassName
*
* @return TabInterface
*/
public function setLegacyClassName($legacyClassName);
/**
* Get the display mode of the tab.
*
* @return string
*/
public function getDisplayMode();
/**
* @param string $displayMode
*
* @return TabInterface
*/
public function setDisplayMode($displayMode);
/**
* Get the recommended modules of the tab.
*
* @return RecommendedModuleCollectionInterface
*/
public function getRecommendedModules();
/**
* @param RecommendedModuleCollectionInterface $recommendedModules
*
* @return TabInterface
*/
public function setRecommendedModules(RecommendedModuleCollectionInterface $recommendedModules);
/**
* Check if the tab has recommended modules.
*
* @return bool
*/
public function hasRecommendedModules();
/**
* Get the installed recommended modules of the tab.
*
* @return RecommendedModuleCollectionInterface
*/
public function getRecommendedModulesInstalled();
/**
* Get the not installed recommended modules of the tab.
*
* @return RecommendedModuleCollectionInterface
*/
public function getRecommendedModulesNotInstalled();
/**
* @return bool
*/
public function shouldDisplayButton();
/**
* @return bool
*/
public function shouldDisplayAfterContent();
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* 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 <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;