first commit
This commit is contained in:
@@ -0,0 +1,646 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2018 PrestaShop
|
||||
*
|
||||
* 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:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* 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 http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2018 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
**/
|
||||
use PrestaShop\PrestaShop\Core\Addon\Theme\ThemeManager;
|
||||
use PrestaShop\PrestaShop\Core\Addon\Theme\ThemeManagerBuilder;
|
||||
use PrestaShop\PrestaShop\Core\Addon\Theme\ThemeRepository;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class AdminPsThemeCustoAdvancedController extends ModuleAdminController
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $skeleton_name;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $childtheme_skeleton;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $sandbox_path;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $controller_quick_name;
|
||||
/**
|
||||
* @var ThemeManager
|
||||
*/
|
||||
public $theme_manager;
|
||||
/**
|
||||
* @var ThemeRepository
|
||||
*/
|
||||
public $theme_repository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->skeleton_name = 'childtheme_skeleton';
|
||||
$this->childtheme_skeleton = $this->getModule()->module_path . '/src/' . $this->skeleton_name . '.zip';
|
||||
$this->sandbox_path = _PS_CACHE_DIR_ . 'sandbox/';
|
||||
$this->controller_quick_name = 'advanced';
|
||||
$this->theme_manager = (new ThemeManagerBuilder($this->context, Db::getInstance()))->build();
|
||||
$this->theme_repository = (new ThemeManagerBuilder($this->context, Db::getInstance()))->buildRepository();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the content by adding Boostrap and loading the TPL
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'enable' => $this->getModule()->active,
|
||||
'moduleName' => $this->getModule()->displayName,
|
||||
'bootstrap' => 1,
|
||||
'configure_type' => $this->controller_quick_name,
|
||||
'images' => $this->getModule()->img_path . '/controllers/advanced/',
|
||||
'isPsReady' => $this->getModule()->ready,
|
||||
]);
|
||||
$aJsDef = [
|
||||
'admin_module_controller_psthemecusto' => $this->getModule()->controller_name[0],
|
||||
'admin_module_ajax_url_psthemecusto' => $this->getModule()->front_controller[0],
|
||||
'default_error_upload' => $this->l('An error occured, please check your zip file'),
|
||||
'file_not_valid' => $this->l('The file is not valid.'),
|
||||
];
|
||||
$aJs = [
|
||||
$this->getModule()->js_path . '/controllers/' . $this->controller_quick_name . '/dropzone.js',
|
||||
$this->getModule()->js_path . '/controllers/' . $this->controller_quick_name . '/back.js',
|
||||
];
|
||||
$aCss = [$this->getModule()->css_path . '/controllers/' . $this->controller_quick_name . '/back.css'];
|
||||
$this->getModule()->setMedia($aJsDef, $aJs, $aCss);
|
||||
|
||||
$this->setTemplate($this->getModule()->template_dir . 'page.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone a theme and modify the config to set the parent theme
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function ajaxProcessDownloadChildTheme()
|
||||
{
|
||||
$bPrepareChildtheme = self::prepareChildTheme(_THEME_NAME_, _PS_THEME_DIR_);
|
||||
|
||||
if (!$bPrepareChildtheme) {
|
||||
exit(false);
|
||||
}
|
||||
|
||||
$bCreateChildTheme = self::createChildTheme(_THEME_NAME_);
|
||||
|
||||
if (!$bCreateChildTheme) {
|
||||
exit(false);
|
||||
}
|
||||
|
||||
exit(self::getChildTheme(_THEME_NAME_, _PS_ROOT_DIR_));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the child theme
|
||||
*
|
||||
* @param string $sParentThemeName
|
||||
* @param string $sParentThemeDir
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function prepareChildTheme($sParentThemeName, $sParentThemeDir)
|
||||
{
|
||||
Tools::ZipExtract($this->childtheme_skeleton, $this->sandbox_path);
|
||||
|
||||
$aStringToReplace = [
|
||||
'{childtheme_parent}' => $sParentThemeName,
|
||||
'{childtheme_name}' => 'child_' . $sParentThemeName,
|
||||
'{childtheme_description}' => 'Child theme of ' . $sParentThemeName . '\'s theme',
|
||||
];
|
||||
|
||||
$sChildThemeConfigPath = $this->sandbox_path . '/' . $this->skeleton_name . '/config/theme.yml';
|
||||
|
||||
$sConfigFile = @file_get_contents($sChildThemeConfigPath);
|
||||
|
||||
foreach ($aStringToReplace as $sSearchElement => $sReplace) {
|
||||
$sConfigFile = str_replace($sSearchElement, $sReplace, $sConfigFile);
|
||||
}
|
||||
|
||||
$bPutContents = @file_put_contents($sChildThemeConfigPath, $sConfigFile);
|
||||
|
||||
if (!$bPutContents) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return @copy($sParentThemeDir . '/preview.png', $this->sandbox_path . '/' . $this->skeleton_name . '/preview.png');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the child theme
|
||||
*
|
||||
* @param string $sParentThemeName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function createChildTheme($sParentThemeName)
|
||||
{
|
||||
$sChildThemeFolderName = 'child_' . $sParentThemeName;
|
||||
|
||||
$oZip = new ZipArchive();
|
||||
$oZip->open($this->sandbox_path . '/' . $sChildThemeFolderName . '.zip', ZipArchive::CREATE);
|
||||
$fileList = Finder::create()
|
||||
->files()
|
||||
->in($this->sandbox_path . '/' . $this->skeleton_name . '/');
|
||||
|
||||
foreach ($fileList as $file) {
|
||||
$oZip->addFile($file->getRealpath(), $sChildThemeFolderName . '/' . $file->getRelativePathName());
|
||||
}
|
||||
|
||||
return $oZip->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the ZIP archive into Theme's folder and unlink all the files in sandbox
|
||||
*
|
||||
* @param string $sParentThemeName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getChildTheme($sParentThemeName, $sPrestashopRootDir)
|
||||
{
|
||||
$sChildThemeZipName = 'child_' . $sParentThemeName . '.zip';
|
||||
|
||||
@rename($this->sandbox_path . '/' . $sChildThemeZipName, $sPrestashopRootDir . '/themes/' . $sChildThemeZipName);
|
||||
|
||||
self::recursiveDelete($this->sandbox_path . $this->skeleton_name);
|
||||
|
||||
return $this->getModule()->ps_uri . '/themes/' . $sChildThemeZipName;
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX getting a file attachment and will upload the file, install it, check if there's modules in it ...
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ajaxProcessUploadChildTheme()
|
||||
{
|
||||
$aChildThemeReturned = Tools::fileAttachment('file');
|
||||
$sZipPath = self::processUploadFileChild($aChildThemeReturned, $this->sandbox_path . $aChildThemeReturned['rename']);
|
||||
$bZipFormat = self::processCheckZipFormat($sZipPath);
|
||||
if (!$bZipFormat) {
|
||||
exit(json_encode([
|
||||
'state' => 0,
|
||||
'message' => $this->l('Make sure you zip your edited theme files directly to the root of your child theme\'s folder before uploading it.'),
|
||||
]));
|
||||
}
|
||||
|
||||
$bUploadIsClean = self::processCheckFiles($sZipPath, $this->sandbox_path . rand());
|
||||
|
||||
if (!$bUploadIsClean) {
|
||||
if ($this->getModule()->ready) {
|
||||
$sMessageUploadNotClean = $this->l('Only CSS, YML and PNG files are accepted in the ZIP');
|
||||
} else {
|
||||
$sMessageUploadNotClean = $this->l('There is some PHP files in your ZIP');
|
||||
}
|
||||
|
||||
exit(json_encode([
|
||||
'state' => 0,
|
||||
'message' => $sMessageUploadNotClean,
|
||||
]));
|
||||
}
|
||||
|
||||
/** @var bool|string $sFolderPath */
|
||||
$sFolderPath = self::postProcessInstall($sZipPath);
|
||||
|
||||
if ($sFolderPath === false) {
|
||||
@unlink($sZipPath);
|
||||
exit(json_encode([
|
||||
'state' => 0,
|
||||
'message' => $this->l('The theme already exists or the parent name in the config file is wrong'),
|
||||
]));
|
||||
}
|
||||
|
||||
if (!self::checkIfIsChildTheme($sFolderPath)) {
|
||||
self::recursiveDelete($sFolderPath);
|
||||
exit(json_encode([
|
||||
'state' => 0,
|
||||
'message' => $this->l('You must enter the parent theme name in the theme.yml file. Furthermore, the parent name must be the current parent theme.'),
|
||||
]));
|
||||
}
|
||||
|
||||
exit(json_encode([
|
||||
'state' => 1,
|
||||
'message' => $this->l('The child theme has been added successfully.'),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check upload file on upload
|
||||
*
|
||||
* @param array $aChildThemeReturned
|
||||
* @param string $dest
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function processUploadFileChild($aChildThemeReturned, $dest)
|
||||
{
|
||||
if (!$this->getModule()->hasEditRight()) {
|
||||
return $this->l('You do not have permission to edit this.');
|
||||
}
|
||||
|
||||
switch ($aChildThemeReturned['error']) {
|
||||
case UPLOAD_ERR_OK:
|
||||
break;
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
$this->errors[] = $this->trans('The uploaded file is too large.', [], 'Admin.Design.Notification');
|
||||
|
||||
return false;
|
||||
default:
|
||||
$this->errors[] = $this->trans('Unknown error.', [], 'Admin.Notifications.Error');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$tmp_name = $aChildThemeReturned['tmp_name'];
|
||||
$goodMimeType = false;
|
||||
|
||||
$mimeType = self::processCheckMimeType($tmp_name);
|
||||
|
||||
if (!empty($mimeType)) {
|
||||
preg_match('#application/zip#', $mimeType, $matches);
|
||||
if (!empty($matches)) {
|
||||
$goodMimeType = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (false === $goodMimeType) {
|
||||
$this->errors[] = $this->trans('Invalid file format.', [], 'Admin.Design.Notification');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$name = $aChildThemeReturned['name'];
|
||||
if (!Validate::isFileName($name)) {
|
||||
$dest = _PS_ALL_THEMES_DIR_ . sha1_file($tmp_name) . '.zip';
|
||||
}
|
||||
|
||||
if (!move_uploaded_file(
|
||||
$aChildThemeReturned['tmp_name'],
|
||||
$dest
|
||||
)) {
|
||||
$this->errors[] = $this->trans('Failed to move uploaded file.', [], 'Admin.Design.Notification');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$bZipeFileIsValid = self::checkZipFile($aChildThemeReturned, $dest);
|
||||
|
||||
if (!$bZipeFileIsValid) {
|
||||
$this->errors[] = $this->trans('Unknown error.', [], 'Admin.Notifications.Error');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check zip file and modify it if necessary
|
||||
*
|
||||
* @param array $aChildThemeReturned
|
||||
* @param string $sZipPath
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkZipFile($aChildThemeReturned, $sZipPath)
|
||||
{
|
||||
$oZip = new ZipArchive();
|
||||
$oZip->open($sZipPath);
|
||||
$aHaveRootFolder = [];
|
||||
|
||||
for ($i = 0; $i < $oZip->numFiles; ++$i) {
|
||||
$aZipElement = explode('/', $oZip->getNameIndex($i));
|
||||
$aHaveRootFolder[$i] = count($aZipElement);
|
||||
/* If we get 1 we can stop it because the zip architecture is valid */
|
||||
if ($aHaveRootFolder[$i] == 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if 1 : There is no root foler
|
||||
if no 1 : There is root folder
|
||||
The zip file has a root folder ? We must remove it
|
||||
*/
|
||||
if (!in_array(1, $aHaveRootFolder)) {
|
||||
$oZip->extractTo($this->sandbox_path);
|
||||
$oZip->close();
|
||||
@unlink($sZipPath);
|
||||
$aFolderName = explode('.zip', $aChildThemeReturned['name']);
|
||||
$sFolderName = $aFolderName[0];
|
||||
$oZipCreate = new ZipArchive();
|
||||
$oZipCreate->open($this->sandbox_path . '/' . $aChildThemeReturned['rename'], ZipArchive::CREATE);
|
||||
$fileList = Finder::create()->in($this->sandbox_path . '/' . $sFolderName . '/');
|
||||
|
||||
foreach ($fileList as $file) {
|
||||
if ($file->isDir()) {
|
||||
$oZipCreate->addEmptyDir($file->getRelativePathName());
|
||||
} else {
|
||||
$oZipCreate->addFile($file->getRealpath(), '' . $file->getRelativePathName());
|
||||
}
|
||||
}
|
||||
|
||||
$bZipCreateClose = (bool) $oZipCreate->close();
|
||||
$bRecursiveDelete = (bool) self::recursiveDelete($this->sandbox_path . '/' . $sFolderName . '/');
|
||||
|
||||
return $bZipCreateClose && $bRecursiveDelete;
|
||||
} else {
|
||||
return $oZip->close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mime type of the file
|
||||
*
|
||||
* @param string $tmp_name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function processCheckMimeType($tmp_name)
|
||||
{
|
||||
$mimeType = '';
|
||||
|
||||
if (function_exists('finfo_open')) {
|
||||
$finfo = @finfo_open(FILEINFO_MIME);
|
||||
$mimeType = @finfo_file($finfo, $tmp_name);
|
||||
@finfo_close($finfo);
|
||||
} elseif (function_exists('mime_content_type')) {
|
||||
$mimeType = @mime_content_type($tmp_name);
|
||||
} elseif (function_exists('exec')) {
|
||||
$mimeType = trim(@exec('file -b --mime-type ' . escapeshellarg($tmp_name)));
|
||||
if (!$mimeType) {
|
||||
$mimeType = trim(@exec('file --mime ' . escapeshellarg($tmp_name)));
|
||||
}
|
||||
if (!$mimeType) {
|
||||
$mimeType = trim(@exec('file -bi ' . escapeshellarg($tmp_name)));
|
||||
}
|
||||
}
|
||||
|
||||
return $mimeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* We check if the Zip is valid. The root folder must have all the theme element, we check it with the folder Config.
|
||||
*
|
||||
* @param string $sZipPath
|
||||
*
|
||||
* @return bool $bZipIsValid
|
||||
*/
|
||||
public function processCheckZipFormat($sZipPath)
|
||||
{
|
||||
$oZip = new ZipArchive();
|
||||
$oZip->open($sZipPath);
|
||||
$aRootFilesAndFolders = [];
|
||||
|
||||
for ($i = 0; $i < $oZip->numFiles; ++$i) {
|
||||
$aZipElement = array_filter(explode('/', $oZip->getNameIndex($i)));
|
||||
if (count($aZipElement) == 1) {
|
||||
$aRootFilesAndFolders[] = $aZipElement[0];
|
||||
}
|
||||
}
|
||||
|
||||
$oZip->close();
|
||||
|
||||
if (in_array('config', $aRootFilesAndFolders)) {
|
||||
$bZipIsValid = true;
|
||||
} else {
|
||||
$bZipIsValid = false;
|
||||
@unlink($sZipPath);
|
||||
}
|
||||
|
||||
return $bZipIsValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* We unzip the child theme zip in a sandbox to check it
|
||||
*
|
||||
* @param string $sZipSource
|
||||
* @param string $sSandboxPath
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function processCheckFiles($sZipSource, $sSandboxPath)
|
||||
{
|
||||
if (!$this->getModule()->hasEditRight()) {
|
||||
return $this->l('You do not have permission to edit this.');
|
||||
}
|
||||
|
||||
Tools::ZipExtract($sZipSource, $sSandboxPath);
|
||||
|
||||
if ($this->getModule()->ready) {
|
||||
$bCleanFiles = self::checkContentsForReady($sZipSource, $sSandboxPath);
|
||||
} else {
|
||||
$bCleanFiles = self::getDirPhpContents($sZipSource, $sSandboxPath);
|
||||
}
|
||||
|
||||
self::recursiveDelete($sSandboxPath);
|
||||
|
||||
return $bCleanFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* We check if there is unvalid files
|
||||
*
|
||||
* @param string $sZipSource
|
||||
* @param string $sSandboxPath
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function checkContentsForReady($sZipSource, $sSandboxPath)
|
||||
{
|
||||
$sPatternGeneral = '#[.\-\/](css|yml|png)#';
|
||||
$sPatternPHP = '#[.\-\/](php)#';
|
||||
$sIndexPhpFile = Tools::getDefaultIndexContent();
|
||||
|
||||
$zip = new ZipArchive();
|
||||
$it = new RecursiveDirectoryIterator($sSandboxPath, RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
|
||||
$zip->open($sZipSource);
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (!$file->isDir()) {
|
||||
$sSubject = $file->getFilename() . self::processCheckMimeType($file->getRealPath());
|
||||
$bFileIsValid = (bool) preg_match($sPatternGeneral, $sSubject);
|
||||
if (!$bFileIsValid) {
|
||||
$bIsPHPfile = (bool) preg_match($sPatternPHP, $sSubject);
|
||||
if ($bIsPHPfile && $file->getFilename() === 'index.php') {
|
||||
$sRealPathFile = str_replace($sSandboxPath . '/', '', $file->getRealPath());
|
||||
$zip->deleteName($sRealPathFile);
|
||||
$zip->addFromString($sRealPathFile, $sIndexPhpFile);
|
||||
} else {
|
||||
$zip->close();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* We check if there is some PHP files
|
||||
*
|
||||
* @param string $sZipSource
|
||||
* @param string $sSandboxPath
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function getDirPhpContents($sZipSource, $sSandboxPath)
|
||||
{
|
||||
$sPattern = '#[.\-\/](php)#';
|
||||
$sIndexPhpFile = Tools::getDefaultIndexContent();
|
||||
|
||||
$zip = new ZipArchive();
|
||||
$it = new RecursiveDirectoryIterator($sSandboxPath, RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
|
||||
$zip->open($sZipSource);
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (!$file->isDir()) {
|
||||
$sSubject = $file->getFilename() . self::processCheckMimeType($file->getRealPath());
|
||||
if ($file->getFilename() === 'index.php') {
|
||||
$sRealPathFile = str_replace($sSandboxPath . '/', '', $file->getRealPath());
|
||||
$zip->deleteName($sRealPathFile);
|
||||
$zip->addFromString($sRealPathFile, $sIndexPhpFile);
|
||||
} elseif (preg_match($sPattern, $sSubject)) {
|
||||
$zip->close();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* We install the child theme and we return the folder child theme's name
|
||||
*
|
||||
* @param string $dest
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function postProcessInstall($dest)
|
||||
{
|
||||
if (!$this->getModule()->hasEditRight()) {
|
||||
return $this->l('You do not have permission to edit this.');
|
||||
}
|
||||
$aFolder = [];
|
||||
|
||||
try {
|
||||
$this->theme_manager->install($dest);
|
||||
@unlink($dest);
|
||||
$aFolderScan = @scandir(_PS_ALL_THEMES_DIR_);
|
||||
|
||||
foreach ($aFolderScan as $key => $sObject) {
|
||||
$sDirThemeFolder = _PS_ALL_THEMES_DIR_ . $sObject;
|
||||
if (is_dir($sDirThemeFolder) && !in_array($sObject, ['.', '..'])) {
|
||||
$aFolder[filemtime($sDirThemeFolder)] = $sDirThemeFolder;
|
||||
}
|
||||
}
|
||||
|
||||
krsort($aFolder);
|
||||
$aChildthemeFolder = array_values($aFolder);
|
||||
|
||||
return $aChildthemeFolder[0];
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We check in theme.yml if this theme is a child theme of the current main theme.
|
||||
*
|
||||
* @param string $sFolderPath
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkIfIsChildTheme($sFolderPath)
|
||||
{
|
||||
$sFile = 'theme.yml';
|
||||
$aLines = file($sFolderPath . '/config/' . $sFile);
|
||||
$sSearchString = 'parent:';
|
||||
$bIsChildTheme = false;
|
||||
|
||||
foreach ($aLines as $line) {
|
||||
if (strpos($line, $sSearchString) !== false) {
|
||||
$aParentThemeName = explode(':', $line);
|
||||
$sParentThemeName = trim($aParentThemeName[1]);
|
||||
if ($sParentThemeName == _THEME_NAME_) {
|
||||
$bIsChildTheme = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $bIsChildTheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* the child theme has modules. We can't keep it.
|
||||
*
|
||||
* @param string $sFolderPath
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function recursiveDelete($sFolderPath)
|
||||
{
|
||||
$it = new RecursiveDirectoryIterator($sFolderPath, RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
@rmdir($file->getRealPath());
|
||||
} else {
|
||||
@unlink($file->getRealPath());
|
||||
}
|
||||
}
|
||||
|
||||
return @rmdir($sFolderPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ps_themecusto
|
||||
*/
|
||||
private function getModule()
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
return $this->module;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,620 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2018 PrestaShop
|
||||
*
|
||||
* 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:
|
||||
* http://opensource.org/licenses/osl-3.0.php
|
||||
* 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 http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2018 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
**/
|
||||
if (file_exists(_PS_MODULE_DIR_ . 'ps_themecusto/vendor/autoload.php')) {
|
||||
require_once _PS_MODULE_DIR_ . 'ps_themecusto/vendor/autoload.php';
|
||||
}
|
||||
|
||||
class AdminPsThemeCustoConfigurationController extends ModuleAdminController
|
||||
{
|
||||
public $isPsVersion174Plus;
|
||||
public $controller_quick_name;
|
||||
public $aModuleActions;
|
||||
public $moduleActionsNames;
|
||||
public $categoryList;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->isPsVersion174Plus = (bool) version_compare(_PS_VERSION_, '1.7.4', '>=');
|
||||
$this->controller_quick_name = 'configuration';
|
||||
$this->aModuleActions = ['uninstall', 'install', 'configure', 'enable', 'disable', 'disable_mobile', 'enable_mobile', 'reset'];
|
||||
$this->moduleActionsNames = [
|
||||
$this->l('Uninstall'),
|
||||
$this->l('Install'),
|
||||
$this->l('Configure'),
|
||||
$this->l('Enable'),
|
||||
$this->l('Disable'),
|
||||
$this->l('Disable Mobile'),
|
||||
$this->l('Enable Mobile'),
|
||||
$this->l('Reset'),
|
||||
];
|
||||
|
||||
$this->categoryList = [
|
||||
'menu' => $this->l('Menu'),
|
||||
'slider' => $this->l('Slider'),
|
||||
'home_products' => $this->l('Home Products'),
|
||||
'block_text' => $this->l('Text block'),
|
||||
'banner' => $this->l('Banner'),
|
||||
'social_newsletter' => $this->l('Social & Newsletter'),
|
||||
'footer' => $this->l('Footer'),
|
||||
'content' => $this->l('content'),
|
||||
'categories' => $this->l('Categories'),
|
||||
'navigation_column' => $this->l('Navigation column'),
|
||||
'product_management' => $this->l('Product management'),
|
||||
'product_detail' => $this->l('Product detail'),
|
||||
'product_block' => $this->l('Product block'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get homepage list of modules to show
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHomepageListConfiguration()
|
||||
{
|
||||
if ($this->isPsVersion174Plus) {
|
||||
$footerModules = [
|
||||
'blockreassurance' => 22312,
|
||||
'ps_linklist' => 24360,
|
||||
];
|
||||
} else {
|
||||
$footerModules = [
|
||||
'ps_linklist' => 24360,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'menu' => [
|
||||
'pages' => [
|
||||
'AdminCategories' => [
|
||||
$this->l('Categories'),
|
||||
$this->l('Create here a full range of categories and subcategories to classify your products and manage your catalog easily.'),
|
||||
],
|
||||
'AdminCmsContent' => [
|
||||
$this->l('Content pages'),
|
||||
$this->l('Add and manage your content pages to make your store interesting and trustworthy.'),
|
||||
],
|
||||
'AdminManufacturers' => [
|
||||
$this->l('Brands and Suppliers'),
|
||||
$this->l('Manage both your brands and suppliers at the same place !'),
|
||||
],
|
||||
],
|
||||
'modules' => [
|
||||
'ps_mainmenu' => 22321,
|
||||
],
|
||||
],
|
||||
'slider' => [
|
||||
'modules' => [
|
||||
$this->getModule()->ready ? 'pshomeslider' : 'ps_imageslider' => $this->getModule()->ready ? 27562 : 22320,
|
||||
],
|
||||
],
|
||||
'home_products' => [
|
||||
'modules' => [
|
||||
'ps_featuredproducts' => 22319,
|
||||
'ps_bestsellers' => 24566,
|
||||
'ps_newproducts' => 24671,
|
||||
'ps_specials' => 24672,
|
||||
],
|
||||
],
|
||||
'block_text' => [
|
||||
'modules' => [
|
||||
'ps_customtext' => 22317,
|
||||
],
|
||||
],
|
||||
'banner' => [
|
||||
'modules' => [
|
||||
'ps_banner' => 22313,
|
||||
],
|
||||
],
|
||||
'social_newsletter' => [
|
||||
'modules' => [
|
||||
'ps_emailsubscription' => 22318,
|
||||
'ps_socialfollow' => 22323,
|
||||
],
|
||||
],
|
||||
'footer' => [
|
||||
'modules' => $footerModules,
|
||||
'pages' => [
|
||||
'AdminStores' => [
|
||||
$this->l('Shop details'),
|
||||
$this->l('Display additional information about your store or how to contact you to make it easy for your customers to reach you.'),
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get category list of modules to show
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategoryListConfiguration()
|
||||
{
|
||||
if ($this->isPsVersion174Plus) {
|
||||
$category = [
|
||||
'sfRoutePages' => [
|
||||
'admin_product_preferences' => [
|
||||
$this->l('Pagination'),
|
||||
$this->l('Set the numbers of products you want to display per page and how.'),
|
||||
],
|
||||
],
|
||||
];
|
||||
$footerModules = [
|
||||
'blockreassurance' => 22312,
|
||||
'ps_linklist' => 24360,
|
||||
];
|
||||
|
||||
$menu = [
|
||||
'pages' => [
|
||||
'AdminCmsContent' => [
|
||||
$this->l('Content pages'),
|
||||
$this->l('Add and manage your content pages to make your store interesting and trustworthy.'),
|
||||
],
|
||||
'AdminManufacturers' => [
|
||||
$this->l('Brands and Suppliers'),
|
||||
$this->l('Manage both your brands and suppliers at the same place !'),
|
||||
],
|
||||
],
|
||||
'modules' => [
|
||||
'ps_mainmenu' => 22321,
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$category = [
|
||||
'pages' => [
|
||||
'AdminPPreferences' => [
|
||||
$this->l('Pagination'),
|
||||
$this->l('Set the numbers of products you want to display per page and how.'),
|
||||
],
|
||||
],
|
||||
];
|
||||
$footerModules = [
|
||||
'ps_linklist' => 24360,
|
||||
];
|
||||
|
||||
$menu = [
|
||||
'pages' => [
|
||||
'AdminCmsContent' => [
|
||||
$this->l('Content pages'),
|
||||
$this->l('Add and manage your content pages to make your store interesting and trustworthy.'),
|
||||
],
|
||||
'AdminManufacturers' => [
|
||||
$this->l('Brands and Suppliers'),
|
||||
$this->l('Manage both your brands and suppliers at the same place !'),
|
||||
],
|
||||
],
|
||||
'modules' => [
|
||||
'ps_mainmenu' => 22321,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'menu' => $menu,
|
||||
'categories' => [
|
||||
'pages' => [
|
||||
'AdminCategories' => [
|
||||
$this->l('Categories'),
|
||||
$this->l('Create a full range of Categories and Subcategories to classify your products, add categoryies desciptions and manage your catalog easily.'),
|
||||
],
|
||||
],
|
||||
],
|
||||
'navigation_column' => [
|
||||
'modules' => [
|
||||
'ps_categorytree' => 22314,
|
||||
'ps_facetedsearch' => 23867,
|
||||
],
|
||||
],
|
||||
'content' => $category,
|
||||
'social_newsletter' => [
|
||||
'modules' => [
|
||||
'ps_emailsubscription' => 22318,
|
||||
'ps_socialfollow' => 22323,
|
||||
],
|
||||
],
|
||||
'footer' => [
|
||||
'modules' => $footerModules,
|
||||
'pages' => [
|
||||
'AdminStores' => [
|
||||
$this->l('Shop details'),
|
||||
$this->l('Display additional information about your store or how to contact you to make it easy for your customers to reach you.'),
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product list of modules to show
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProductListConfiguration()
|
||||
{
|
||||
if ($this->isPsVersion174Plus) {
|
||||
$productManagement = [
|
||||
'sfRoutePages' => [
|
||||
'admin_product_catalog' => [
|
||||
$this->l('Catalog'),
|
||||
$this->l('Access your list of products to manage your catalog efficiently.'),
|
||||
],
|
||||
'admin_stock_overview' => [
|
||||
$this->l('Stock'),
|
||||
$this->l('Manage your stock and edit product quantities right here.'),
|
||||
],
|
||||
],
|
||||
'pages' => [
|
||||
'AdminAttributesGroups' => [
|
||||
$this->l('Product attributes'),
|
||||
$this->l('Create or manage your attributes : colors, sizes, materials, ...'),
|
||||
],
|
||||
],
|
||||
];
|
||||
$productDetailsModules = [
|
||||
'blockreassurance' => 22312,
|
||||
'ps_sharebuttons' => 22322,
|
||||
];
|
||||
if (version_compare(_PS_VERSION_, '1.7.6', '>=')) {
|
||||
$productDetailsModules['productcomments'] = 9144;
|
||||
}
|
||||
} else {
|
||||
$productManagement = [
|
||||
'sfRoutePages' => [
|
||||
'admin_product_catalog' => [
|
||||
$this->l('Catalog'),
|
||||
$this->l('Access your list of products to manage your catalog efficiently.'),
|
||||
],
|
||||
],
|
||||
'pages' => [
|
||||
'AdminAttributesGroups' => [
|
||||
$this->l('Product attributes'),
|
||||
$this->l('Create or manage your attributes : colors, sizes, materials, ...'),
|
||||
],
|
||||
'AdminPPreferences' => [
|
||||
$this->l('Quantities and stock availability'),
|
||||
$this->l('Choose the way you display quantities and stock availability on your product page.'),
|
||||
],
|
||||
'AdminStockManagement' => [
|
||||
$this->l('Stock'),
|
||||
$this->l('Manage your stock and edit product quantities right here.'),
|
||||
],
|
||||
],
|
||||
];
|
||||
$productDetailsModules = [
|
||||
'ps_sharebuttons' => 22322,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'menu' => [
|
||||
'pages' => [
|
||||
'AdminCategories' => [
|
||||
$this->l('Categories'),
|
||||
$this->l('Create here a full range of categories and subcategories to classify your products and manage your catalog easily.'),
|
||||
],
|
||||
'AdminCmsContent' => [
|
||||
$this->l('Content pages'),
|
||||
$this->l('Add and manage your content pages to make your store interesting and trustworthy.'),
|
||||
],
|
||||
'AdminManufacturers' => [
|
||||
$this->l('Brands and Suppliers'),
|
||||
$this->l('Manage both your brands and suppliers at the same place !'),
|
||||
],
|
||||
],
|
||||
'modules' => [
|
||||
'ps_mainmenu' => 22321,
|
||||
],
|
||||
],
|
||||
'product_management' => $productManagement,
|
||||
'product_detail' => [
|
||||
'modules' => $productDetailsModules,
|
||||
],
|
||||
'product_block' => [
|
||||
'modules' => [
|
||||
'ps_categoryproducts' => 24588,
|
||||
'ps_viewedproduct' => 24674,
|
||||
'ps_crossselling' => 24696,
|
||||
],
|
||||
],
|
||||
'social_newsletter' => [
|
||||
'modules' => [
|
||||
'ps_emailsubscription' => 22318,
|
||||
'ps_socialfollow' => 22323,
|
||||
],
|
||||
],
|
||||
'footer' => [
|
||||
'pages' => [
|
||||
'AdminStores' => [
|
||||
$this->l('Shop details'),
|
||||
$this->l('Display additional information about your store or how to contact you to make it easy for your customers to reach you.'),
|
||||
],
|
||||
],
|
||||
'modules' => [
|
||||
'ps_linklist' => 24360,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the content by adding Boostrap and loading the TPL
|
||||
*/
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
if (Module::isInstalled('ps_mbo')) {
|
||||
$selectionModulePage = $this->context->link->getAdminLink('AdminPsMboModule');
|
||||
} else {
|
||||
$selectionModulePage = $this->context->link->getAdminLink('AdminModulesCatalog');
|
||||
}
|
||||
$installedModulePage = $this->context->link->getAdminLink('AdminModulesManage');
|
||||
|
||||
$homepageListToConfigure = $this->getHomepageListConfiguration();
|
||||
$categoryListToConfigure = $this->getCategoryListConfiguration();
|
||||
$productListToConfigure = $this->getProductListConfiguration();
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'enable' => $this->getModule()->active,
|
||||
'moduleName' => $this->getModule()->displayName,
|
||||
'bootstrap' => 1,
|
||||
'configure_type' => $this->controller_quick_name,
|
||||
'iconConfiguration' => $this->getModule()->img_path . '/controllers/configuration/icon_configurator.png',
|
||||
'listCategories' => $this->categoryList,
|
||||
'homePageList' => $this->setFinalList($homepageListToConfigure),
|
||||
'categoryPageList' => $this->setFinalList($categoryListToConfigure),
|
||||
'productPageList' => $this->setFinalList($productListToConfigure),
|
||||
'selectionModulePage' => $selectionModulePage,
|
||||
'installedModulePage' => $installedModulePage,
|
||||
'moduleImgUri' => $this->getModule()->img_path . '/controllers/configuration/',
|
||||
'moduleActions' => $this->aModuleActions,
|
||||
'moduleActionsNames' => $this->moduleActionsNames,
|
||||
'themeConfiguratorUrl' => $this->context->link->getAdminLink(
|
||||
'AdminModules',
|
||||
true,
|
||||
false,
|
||||
['configure' => 'ps_themeconfigurator']
|
||||
),
|
||||
'isPsReady' => $this->getModule()->ready,
|
||||
'ps_uri' => $this->getModule()->ps_uri,
|
||||
]);
|
||||
|
||||
$aJsDef = [
|
||||
'admin_module_controller_psthemecusto' => $this->getModule()->controller_name[1],
|
||||
'admin_module_ajax_url_psthemecusto' => $this->getModule()->front_controller[1],
|
||||
'module_action_sucess' => $this->l('Action on the module successfully completed'),
|
||||
'module_action_failed' => $this->l('Action on module failed'),
|
||||
];
|
||||
$jsPath = [$this->getModule()->js_path . '/controllers/' . $this->controller_quick_name . '/back.js'];
|
||||
$cssPath = [$this->getModule()->css_path . '/controllers/' . $this->controller_quick_name . '/back.css'];
|
||||
|
||||
$this->getModule()->setMedia($aJsDef, $jsPath, $cssPath);
|
||||
$this->setTemplate($this->getModule()->template_dir . 'page.tpl');
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX : Do a module action like Install, disable, enable ...
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function ajaxProcessUpdateModule()
|
||||
{
|
||||
if (!$this->getModule()->hasEditRight()) {
|
||||
exit($this->l('You do not have permission to edit this.'));
|
||||
}
|
||||
|
||||
$sModuleName = pSQL(Tools::getValue('module_name'));
|
||||
$sModuleAction = pSQL(Tools::getValue('action_module'));
|
||||
$oModule = Module::getInstanceByName($sModuleName);
|
||||
$sUrlActive = $oModule->isEnabled($oModule->name) ? 'configure' : 'enable';
|
||||
|
||||
switch ($sModuleAction) {
|
||||
case 'uninstall':
|
||||
if ($this->getModule()->ready === true) {
|
||||
break;
|
||||
}
|
||||
$oModule->uninstall();
|
||||
$sUrlActive = 'install';
|
||||
break;
|
||||
case 'install':
|
||||
if ($this->getModule()->ready === true) {
|
||||
break;
|
||||
}
|
||||
$oModule->install();
|
||||
$sUrlActive = method_exists($oModule, 'getContent') ? 'configure' : 'disable';
|
||||
break;
|
||||
case 'enable':
|
||||
$oModule->enable();
|
||||
$sUrlActive = method_exists($oModule, 'getContent') ? 'configure' : 'disable';
|
||||
break;
|
||||
case 'disable':
|
||||
$oModule->disable();
|
||||
$sUrlActive = 'enable';
|
||||
break;
|
||||
case 'disable_mobile':
|
||||
$oModule->disableDevice(Context::DEVICE_MOBILE);
|
||||
$sUrlActive = method_exists($oModule, 'getContent') ? 'configure' : 'disable';
|
||||
break;
|
||||
case 'enable_mobile':
|
||||
$oModule->enableDevice(Context::DEVICE_MOBILE);
|
||||
$sUrlActive = method_exists($oModule, 'getContent') ? 'configure' : 'disable';
|
||||
break;
|
||||
case 'reset':
|
||||
$oModule->uninstall();
|
||||
$oModule->install();
|
||||
$sUrlActive = method_exists($oModule, 'getContent') ? 'configure' : 'disable';
|
||||
break;
|
||||
default:
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$aModule['id_module'] = $oModule->id;
|
||||
$aModule['name'] = $oModule->name;
|
||||
$aModule['displayName'] = $oModule->displayName;
|
||||
$aModule['url_active'] = $sUrlActive;
|
||||
$aModule['active'] = ThemeCustoRequests::getModuleDeviceStatus($oModule->id);
|
||||
$aModule['actions_url']['configure'] = $this->context->link->getAdminLink('AdminModules', true, false, ['configure' => $oModule->name]);
|
||||
$aModule['can_configure'] = method_exists($oModule, 'getContent') ? true : false;
|
||||
$aModule['enable_mobile'] = (int) Db::getInstance()->getValue('SELECT enable_device FROM ' . _DB_PREFIX_ . 'module_shop WHERE id_module = ' . (int) $oModule->id);
|
||||
|
||||
$this->context->smarty->assign([
|
||||
'module' => $aModule,
|
||||
'moduleActions' => $this->aModuleActions,
|
||||
'moduleActionsNames' => $this->moduleActionsNames,
|
||||
'isPsReady' => $this->getModule()->ready,
|
||||
]);
|
||||
|
||||
$this->ajaxDie($this->context->smarty->fetch(__DIR__ . '/../../views/templates/admin/controllers/' . $this->controller_quick_name . '/elem/module_actions.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* get list to show
|
||||
*
|
||||
* @param array $aList
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setFinalList($aList)
|
||||
{
|
||||
$modulesOnDisk = Module::getModulesDirOnDisk();
|
||||
$aModuleFinalList = [];
|
||||
|
||||
foreach ($aList as $sSegmentName => $aElementListByType) {
|
||||
foreach ($aElementListByType as $sType => $aElementsList) {
|
||||
if ($sType == 'pages') {
|
||||
foreach ($aElementsList as $sController => $aPage) {
|
||||
$aModuleFinalList[$sSegmentName][$sType][$sController]['name'] = $sController;
|
||||
$aModuleFinalList[$sSegmentName][$sType][$sController]['displayName'] = $this->l($aPage[0]);
|
||||
$aModuleFinalList[$sSegmentName][$sType][$sController]['url'] = $this->context->link->getAdminLink($sController);
|
||||
$aModuleFinalList[$sSegmentName][$sType][$sController]['description'] = $this->l($aPage[1]);
|
||||
$aModuleFinalList[$sSegmentName][$sType][$sController]['action'] = $this->l('Configure');
|
||||
}
|
||||
} elseif ($sType == 'sfRoutePages') {
|
||||
$container = PrestaShop\PrestaShop\Adapter\SymfonyContainer::getInstance();
|
||||
foreach ($aElementsList as $sController => $aPage) {
|
||||
$aModuleFinalList[$sSegmentName][$sType][$sController]['name'] = $sController;
|
||||
$aModuleFinalList[$sSegmentName][$sType][$sController]['displayName'] = $this->l($aPage[0]);
|
||||
$aModuleFinalList[$sSegmentName][$sType][$sController]['url'] = $container->get('router')->generate($sController);
|
||||
$aModuleFinalList[$sSegmentName][$sType][$sController]['description'] = $this->l($aPage[1]);
|
||||
$aModuleFinalList[$sSegmentName][$sType][$sController]['action'] = $this->l('Configure');
|
||||
}
|
||||
} else {
|
||||
foreach ($aElementsList as $sModuleName => $iModuleId) {
|
||||
if (!in_array($sModuleName, $modulesOnDisk)) {
|
||||
if ($this->getModule()->ready !== false) {
|
||||
continue;
|
||||
}
|
||||
/* For a module coming from outside. It will be downloaded and installed */
|
||||
$length = file_put_contents(_PS_MODULE_DIR_ . basename($sModuleName) . '.zip', Tools::addonsRequest('module', ['id_module' => $iModuleId]));
|
||||
if (!empty($length) && Tools::ZipExtract(_PS_MODULE_DIR_ . basename($sModuleName) . '.zip', _PS_MODULE_DIR_)) {
|
||||
unlink(_PS_MODULE_DIR_ . basename($sModuleName) . '.zip');
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$aModuleFinalList[$sSegmentName][$sType][$sModuleName] = $this->setModuleFinalList(Module::getInstanceByName($sModuleName), Module::isInstalled($sModuleName));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isset($aModuleFinalList[$sSegmentName])) {
|
||||
$aModuleFinalList[$sSegmentName] = null;
|
||||
}
|
||||
if (isset($aModuleFinalList[$sSegmentName]['modules'])
|
||||
&& is_array($aModuleFinalList[$sSegmentName]['modules'])
|
||||
&& is_callable([$this, 'sortArrayInstalledModulesFirst'])) {
|
||||
uasort($aModuleFinalList[$sSegmentName]['modules'], [$this, 'sortArrayInstalledModulesFirst']);
|
||||
}
|
||||
}
|
||||
|
||||
return $aModuleFinalList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render final list of modules
|
||||
*
|
||||
* @param Module $oModuleInstance
|
||||
* @param bool $bIsInstalled
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setModuleFinalList($oModuleInstance, $bIsInstalled)
|
||||
{
|
||||
$aModule = [];
|
||||
|
||||
$aModule['id_module'] = $oModuleInstance->id;
|
||||
$aModule['active'] = $oModuleInstance->active;
|
||||
|
||||
if ($bIsInstalled === true) {
|
||||
$aModule['can_configure'] = (method_exists($oModuleInstance, 'getContent')) ? true : false;
|
||||
if (method_exists($oModuleInstance, 'getContent')) {
|
||||
$aModule['url_active'] = $this->l(($oModuleInstance->active ? 'configure' : 'enable'));
|
||||
} else {
|
||||
$aModule['url_active'] = $this->l(($oModuleInstance->active ? 'disable' : 'enable'));
|
||||
}
|
||||
$aModule['installed'] = 1;
|
||||
} else {
|
||||
$aModule['can_configure'] = false;
|
||||
$aModule['url_active'] = 'install';
|
||||
$aModule['installed'] = 0;
|
||||
}
|
||||
|
||||
$aModule['enable_mobile'] = (int) Db::getInstance()->getValue('SELECT enable_device FROM ' . _DB_PREFIX_ . 'module_shop WHERE id_module = ' . (int) $oModuleInstance->id);
|
||||
$aModule['name'] = $oModuleInstance->name;
|
||||
$aModule['displayName'] = $oModuleInstance->displayName;
|
||||
$aModule['description'] = $oModuleInstance->description;
|
||||
$aModule['controller_name'] = (isset($oModuleInstance->controller_name) ? $oModuleInstance->controller_name : '');
|
||||
$aModule['logo'] = '/modules/' . $oModuleInstance->name . '/logo.png';
|
||||
$aModule['actions_url']['configure'] = $this->context->link->getAdminLink('AdminModules', true, false, ['configure' => $oModuleInstance->name]);
|
||||
|
||||
return $aModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Order Final array for having installed module first
|
||||
*
|
||||
* @param array $a
|
||||
* @param array $b
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function sortArrayInstalledModulesFirst($a, $b)
|
||||
{
|
||||
return strcmp($b['installed'], $a['installed']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ps_themecusto
|
||||
*/
|
||||
private function getModule()
|
||||
{
|
||||
/* @phpstan-ignore-next-line */
|
||||
return $this->module;
|
||||
}
|
||||
}
|
||||
24
modules/ps_themecusto/controllers/admin/index.php
Normal file
24
modules/ps_themecusto/controllers/admin/index.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* 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 http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @license http://addons.prestashop.com/en/content/12-terms-and-conditions-of-use
|
||||
* 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;
|
||||
24
modules/ps_themecusto/controllers/index.php
Normal file
24
modules/ps_themecusto/controllers/index.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2014 PrestaShop
|
||||
*
|
||||
* 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 http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2014 PrestaShop SA
|
||||
* @license http://addons.prestashop.com/en/content/12-terms-and-conditions-of-use
|
||||
* 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;
|
||||
Reference in New Issue
Block a user