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,79 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\ConfigurationInterface;
abstract class AbstractAssetManagerCore
{
protected $directories;
protected $configuration;
protected $list = array();
const DEFAULT_MEDIA = 'all';
const DEFAULT_PRIORITY = 50;
const DEFAULT_JS_POSITION = 'bottom';
use PrestaShop\PrestaShop\Adapter\Assets\AssetUrlGeneratorTrait;
public function __construct(array $directories, ConfigurationInterface $configuration)
{
$this->directories = $directories;
$this->configuration = $configuration;
$this->list = $this->getDefaultList();
}
abstract protected function getDefaultList();
abstract protected function getList();
protected function getFullPath($relativePath)
{
foreach ($this->getDirectories() as $baseDir) {
$fullPath = $baseDir . ltrim($relativePath, '/'); // not DIRECTORY_SEPARATOR because, it's path included manualy
if (file_exists($this->getPathFromUri($fullPath))) {
return $fullPath;
}
}
return false;
}
private function getDirectories()
{
static $directories;
if (null === $directories) {
foreach ($this->directories as $baseDir) {
if (!empty($baseDir)) {
$directories[] = $baseDir;
}
}
}
return $directories;
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\ConfigurationInterface;
use Symfony\Component\Filesystem\Filesystem;
class CccReducerCore
{
private $cacheDir;
protected $filesystem;
use PrestaShop\PrestaShop\Adapter\Assets\AssetUrlGeneratorTrait;
public function __construct($cacheDir, ConfigurationInterface $configuration, Filesystem $filesystem)
{
$this->cacheDir = $cacheDir;
$this->configuration = $configuration;
$this->filesystem = $filesystem;
if (!is_dir($this->cacheDir)) {
$this->filesystem->mkdir($this->cacheDir);
}
}
public function reduceCss($cssFileList)
{
$files = array();
foreach ($cssFileList['external'] as $key => &$css) {
if ('all' === $css['media'] && 'local' === $css['server']) {
$files[] = $this->getPathFromUri($css['path']);
unset($cssFileList['external'][$key]);
}
}
$version = Configuration::get('PS_CCCCSS_VERSION');
$cccFilename = 'theme-' . $this->getFileNameIdentifierFromList($files) . $version . '.css';
$destinationPath = $this->cacheDir . $cccFilename;
if (!$this->filesystem->exists($destinationPath)) {
CssMinifier::minify($files, $destinationPath);
}
$cssFileList['external']['theme-ccc'] = [
'id' => 'theme-ccc',
'type' => 'external',
'path' => $destinationPath,
'uri' => $this->getFQDN() . $this->getUriFromPath($destinationPath),
'media' => 'all',
'priority' => StylesheetManager::DEFAULT_PRIORITY,
];
return $cssFileList;
}
public function reduceJs($jsFileList)
{
foreach ($jsFileList as $position => &$list) {
$files = array();
foreach ($list['external'] as $key => $js) {
// We only CCC the file without 'refer' or 'async'
if ('' === $js['attribute'] && 'local' === $js['server']) {
$files[] = $this->getPathFromUri($js['path']);
unset($list['external'][$key]);
}
}
if (empty($files)) {
// No file to CCC
continue;
}
$version = Configuration::get('PS_CCCJS_VERSION');
$cccFilename = $position . '-' . $this->getFileNameIdentifierFromList($files) . $version . '.js';
$destinationPath = $this->cacheDir . $cccFilename;
if (!$this->filesystem->exists($destinationPath)) {
JsMinifier::minify($files, $destinationPath);
}
$cccItem = [];
$cccItem[$position . '-js-ccc'] = [
'id' => $position . '-js-ccc',
'type' => 'external',
'path' => $destinationPath,
'uri' => $this->getFQDN() . $this->getUriFromPath($destinationPath),
'priority' => JavascriptManager::DEFAULT_PRIORITY,
'attribute' => '',
];
$list['external'] = array_merge($cccItem, $list['external']);
}
return $jsFileList;
}
private function getFileNameIdentifierFromList(array $files)
{
return substr(sha1(implode('|', $files)), 0, 6);
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use MatthiasMullie\Minify\CSS;
class CssMinifierCore
{
public static function minify(array $files, $destination)
{
$minifier = new CSS();
foreach ($files as $file) {
$minifier->add($file);
}
return $minifier->minify($destination);
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class JavascriptManagerCore extends AbstractAssetManager
{
protected $list;
protected $valid_position = ['head', 'bottom'];
protected $valid_attribute = ['async', 'defer'];
protected function getDefaultList()
{
$default = [];
foreach ($this->valid_position as $position) {
$default[$position] = [
'external' => array(),
'inline' => array(),
];
}
return $default;
}
public function register(
$id,
$relativePath,
$position = self::DEFAULT_JS_POSITION,
$priority = self::DEFAULT_PRIORITY,
$inline = false,
$attribute = null,
$server = 'local'
) {
if ('remote' === $server) {
$this->add($id, $relativePath, $position, $priority, $inline, $attribute, $server);
} elseif ($fullPath = $this->getFullPath($relativePath)) {
$this->add($id, $fullPath, $position, $priority, $inline, $attribute, $server);
}
}
public function unregisterById($idToRemove)
{
foreach ($this->valid_position as $position) {
foreach ($this->list[$position] as $type => $null) {
foreach ($this->list[$position][$type] as $id => $item) {
if ($idToRemove === $id) {
unset($this->list[$position][$type][$id]);
}
}
}
}
}
protected function add($id, $fullPath, $position, $priority, $inline, $attribute, $server)
{
$priority = is_int($priority) ? $priority : self::DEFAULT_PRIORITY;
$position = $this->getSanitizedPosition($position);
$attribute = $this->getSanitizedAttribute($attribute);
if ('remote' === $server) {
$uri = $fullPath;
$type = 'external';
} else {
$uri = $this->getFQDN() . $this->getUriFromPath($fullPath);
$type = ($inline) ? 'inline' : 'external';
}
$this->list[$position][$type][$id] = array(
'id' => $id,
'type' => $type,
'path' => $fullPath,
'uri' => $uri,
'priority' => $priority,
'attribute' => $attribute,
'server' => $server,
);
}
public function getList()
{
$this->sortList();
$this->addInlinedJavascriptContent();
return $this->list;
}
private function addInlinedJavascriptContent()
{
foreach ($this->valid_position as $position) {
foreach ($this->list[$position]['inline'] as &$item) {
$item['content'] =
'/* ---- ' . $item['id'] . ' @ ' . $item['path'] . ' ---- */' . "\r\n" .
file_get_contents($item['path']);
}
}
}
private function getSanitizedPosition($position)
{
return in_array($position, $this->valid_position, true) ? $position : self::DEFAULT_JS_POSITION;
}
private function getSanitizedAttribute($attribute)
{
return in_array($attribute, $this->valid_attribute, true) ? $attribute : '';
}
private function sortList()
{
foreach ($this->valid_position as $position) {
foreach ($this->list[$position] as $type => $items) {
Tools::uasort($items, function ($a, $b) {
if ($a['priority'] === $b['priority']) {
return 0;
}
return ($a['priority'] < $b['priority']) ? -1 : 1;
});
$this->list[$position][$type] = $items;
}
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use MatthiasMullie\Minify\JS;
class JsMinifierCore
{
public static function minify(array $files, $destination)
{
$minifier = new JS();
foreach ($files as $file) {
$minifier->add($file);
}
return $minifier->minify($destination);
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class PrestashopAssetsLibraries
{
const css = 'registerStylesheet';
const js = 'registerJavascript';
/**
* List of libraries available.
*
* @var array
*/
private static $assetsLibraries = array(
'font-awesome' => array(
// array of array because a library can have js & css
array(
'id' => 'font-awesome-css',
'type' => self::css,
'path' => '/themes/_libraries/font-awesome/css/font-awesome.min.css',
'params' => array('media' => 'all', 'priority' => 10),
),
),
// can imagine others libraries
);
/**
* Get Library files from name.
*
* @param $name
*
* @return bool|mixed
*/
public static function getAssetsLibraries($name)
{
return array_key_exists($name, self::$assetsLibraries) ? self::$assetsLibraries[$name] : false;
}
}

View File

@@ -0,0 +1,143 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* 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.txt.
* 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://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class StylesheetManagerCore extends AbstractAssetManager
{
private $valid_media = array(
'all',
'braille',
'embossed',
'handheld',
'print',
'projection',
'screen',
'speech',
'tty',
'tv',
);
protected function getDefaultList()
{
return [
'external' => array(),
'inline' => array(),
];
}
public function register(
$id,
$relativePath,
$media = self::DEFAULT_MEDIA,
$priority = self::DEFAULT_PRIORITY,
$inline = false,
$server = 'local',
$needRtl = true
) {
$fullPath = $this->getFullPath($relativePath);
$rtlFullPath = $this->getFullPath(str_replace('.css', '_rtl.css', $relativePath));
$context = Context::getContext();
$isRTL = is_object($context->language) && $context->language->is_rtl;
if ('remote' === $server) {
$this->add($id, $relativePath, $media, $priority, $inline, $server);
} elseif ($needRtl && $isRTL && $rtlFullPath) {
$this->add($id, $rtlFullPath, $media, $priority, $inline, $server);
} elseif ($fullPath) {
$this->add($id, $fullPath, $media, $priority, $inline, $server);
}
}
public function unregisterById($idToRemove)
{
foreach ($this->list as $type => $null) {
foreach ($this->list[$type] as $id => $item) {
if ($idToRemove === $id) {
unset($this->list[$type][$id]);
}
}
}
}
public function getList()
{
$this->sortList();
$this->addInlinedStyleContent();
return $this->list;
}
protected function add($id, $fullPath, $media, $priority, $inline, $server)
{
$priority = is_int($priority) ? $priority : self::DEFAULT_PRIORITY;
$media = $this->getSanitizedMedia($media);
if ('remote' === $server) {
$uri = $fullPath;
$type = 'external';
} else {
$uri = $this->getFQDN() . $this->getUriFromPath($fullPath);
$type = ($inline) ? 'inline' : 'external';
}
$this->list[$type][$id] = array(
'id' => $id,
'type' => $type,
'path' => $fullPath,
'uri' => $uri,
'media' => $media,
'priority' => $priority,
'server' => $server,
);
}
private function getSanitizedMedia($media)
{
return in_array($media, $this->valid_media, true) ? $media : self::DEFAULT_MEDIA;
}
private function sortList()
{
foreach ($this->list as &$items) {
Tools::uasort(
$items,
function ($a, $b) {
if ($a['priority'] === $b['priority']) {
return 0;
}
return ($a['priority'] < $b['priority']) ? -1 : 1;
}
);
}
}
private function addInlinedStyleContent()
{
foreach ($this->list['inline'] as &$item) {
$item['content'] =
'/* ---- ' . $item['id'] . ' @ ' . $item['path'] . ' ---- */' . "\r\n" .
file_get_contents($item['path']);
}
}
}