158 lines
5.0 KiB
PHP
158 lines
5.0 KiB
PHP
<?php
|
|
/**
|
|
* 2014-2020 Presta-Mod.pl Rafał Zontek
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* Poniższy kod jest kodem płatnym, rozpowszechanie bez pisemnej zgody autora zabronione
|
|
* Moduł można zakupić na stronie Presta-Mod.pl. Modyfikacja kodu jest zabroniona,
|
|
* wszelkie modyfikacje powodują utratę gwarancji
|
|
*
|
|
* http://presta-mod.pl
|
|
*
|
|
* DISCLAIMER
|
|
*
|
|
*
|
|
* @author Presta-Mod.pl Rafał Zontek <biuro@presta-mod.pl>
|
|
* @copyright 2014-2020 Presta-Mod.pl
|
|
* @license Licecnja na jedną domenę
|
|
* Presta-Mod.pl Rafał Zontek
|
|
*/
|
|
|
|
if (!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
|
|
class regenerateimage extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->need_instance = 0;
|
|
$this->bootstrap = true;
|
|
$this->name = 'regenerateimage';
|
|
$this->tab = 'administration';
|
|
$this->version = '1.1.1';
|
|
$this->author = 'Presta-Mod.pl';
|
|
$this->module_key = '';
|
|
$this->images_types = ImageType::getImagesTypes('products');
|
|
$this->legacy_images = Configuration::get('PS_LEGACY_IMAGES');
|
|
|
|
$this->displayName = $this->l('Generowanie obrazków produktów');
|
|
$this->description = $this->l('Generowanie obrazków produktów');
|
|
$this->confirmUninstall = $this->l('Are you sure you want to uninstall my module?');
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
parent::install();
|
|
return true;
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
parent::uninstall();
|
|
return true;
|
|
}
|
|
|
|
private function getStatus()
|
|
{
|
|
$s = 0;
|
|
if (file_exists(dirname(__FILE__).'/status.txt')) {
|
|
$s = (int)file_get_contents(dirname(__FILE__).'/status.txt');
|
|
}
|
|
return $s;
|
|
}
|
|
|
|
public function getContent()
|
|
{
|
|
$status = 0;
|
|
$status = $this->getStatus();
|
|
|
|
$useSSL = Configuration::get('PS_SSL_ENABLED');
|
|
|
|
$protocol_content = ($useSSL) ? 'https://' : 'http://';
|
|
$content_dir = $protocol_content.Tools::getHttpHost().__PS_BASE_URI__;
|
|
|
|
$this->context->smarty->assign('status', $status);
|
|
$this->context->smarty->assign('all', $this->getAll());
|
|
$this->context->smarty->assign('base_dir', $content_dir);
|
|
return $this->context->smarty->fetch(dirname(__FILE__).'/templates/views/admin/config.tpl');
|
|
}
|
|
|
|
public function ajaxCall()
|
|
{
|
|
if (Tools::isSubmit('get_status')) {
|
|
echo $this->getStatus();
|
|
die();
|
|
} elseif (Tools::isSubmit('reset_status')) {
|
|
$this->resetStatus();
|
|
die();
|
|
} elseif (Tools::isSubmit('progress')) {
|
|
$this->progress();
|
|
die();
|
|
}
|
|
}
|
|
|
|
public function resetStatus()
|
|
{
|
|
if (file_exists(dirname(__FILE__).'/status.txt')) {
|
|
unlink(dirname(__FILE__).'/status.txt');
|
|
}
|
|
}
|
|
|
|
public function getAll()
|
|
{
|
|
$sql = 'SELECT count(*) AS pall FROM '._DB_PREFIX_.'image';
|
|
$images_all = Db::getInstance()->getRow($sql);
|
|
return $images_all['pall'];
|
|
}
|
|
public function progress()
|
|
{
|
|
$status = $this->getStatus();
|
|
|
|
$sql = 'SELECT * FROM '._DB_PREFIX_.'image limit '.$status.',2';
|
|
$sqlcurrent = Db::getInstance()->executeS($sql);
|
|
|
|
$sql = 'SELECT count(*) AS pall FROM '._DB_PREFIX_.'image';
|
|
$images_all = Db::getInstance()->getRow($sql);
|
|
foreach ($sqlcurrent as $current) {
|
|
$st = ++$status;
|
|
if ($status > $images_all['pall']) {
|
|
echo '-1aaaaaaaaaaaaaaaaaaaaaaaaaaaa';
|
|
file_put_contents(dirname(__FILE__).'/status.txt', 0);
|
|
return '-1';
|
|
}
|
|
file_put_contents(dirname(__FILE__).'/status.txt', $st);
|
|
$img = new Image($current['id_image']);
|
|
echo $this->l('Generowanie obrazka dla produktu o id: ');
|
|
echo $current['id_product'].'[';
|
|
echo $current['id_image'].']';
|
|
echo ''.PHP_EOL;
|
|
$file_name = ($this->legacy_images == 1 ? $product_id.'-'.$img->id.'.jpg' : ($img->createImgFolder() ? $img->getImgPath().'.jpg' : $product_id.'-'.$img->id.'.jpg'));
|
|
$file_name = _PS_PROD_IMG_DIR_.$file_name;
|
|
if ($new_path = $img->getPathForCreation()) {
|
|
foreach ($this->images_types as $image_type) {
|
|
ImageManager::resize(
|
|
$file_name,
|
|
$new_path.'-'.Tools::stripslashes($image_type['name']).'.jpg',
|
|
$image_type['width'],
|
|
$image_type['height'],
|
|
'jpg'
|
|
);
|
|
}
|
|
Hook::exec(
|
|
'actionWatermark',
|
|
array('id_image' => $current['id_image'], 'id_product' => $current['id_product'])
|
|
);
|
|
}
|
|
}
|
|
if ($status >= $images_all['pall']) {
|
|
file_put_contents(dirname(__FILE__).'/status.txt', 0);
|
|
echo PHP_EOL.'-1';
|
|
die();
|
|
}
|
|
}
|
|
}
|