Skip to content

Commit

Permalink
Version 6.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Oct 10, 2020
1 parent 20b16c5 commit b8f6784
Show file tree
Hide file tree
Showing 58 changed files with 463 additions and 176 deletions.
2 changes: 1 addition & 1 deletion FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
custom: ["https://www.paypal.me/luigifab", "https://gandi.link/f/4b904048"]
custom: ["https://www.paypal.me/luigifab", "https://gandi.link/f/4b904048", "https://ekwateur.fr/?parrain=EKW001147103"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ For more information, go to https://www.luigifab.fr/apijs or https://www.luigifa

This repository is a mirror. To install the module, please use the extension key or the composer key available in the documentation.

- Current version: 6.3.0 (08/08/2020)
- Compatibility: OpenMage 19+, Magento Community 1.9+, PHP 7.2 / 7.3 / 7.4
- Current version: 6.4.0 (10/10/2020)
- Compatibility: OpenMage 19+, Magento Community 1.9+, PHP 7.2 / 7.3 / 7.4 / 8.0
- Client compatibility: Firefox 36+, Chrome 31+, Opera 19+, Edge 16+, Safari 9+
- Translations: English (en), French (fr-FR/fr-CA), German (de), Italian (it), Portuguese (pt-PT/pt-BR), Spanish (es)
- Other translations: Czech (cs), Dutch (nl), Japanese (ja), Polish (pl), Slovak (sk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function render(Varien_Data_Form_Element_Abstract $element) {
private function checkRewrites() {

$rewrites = [
['block' => 'adminhtml/cache_additional'],
['block' => 'adminhtml/catalog_category_helper_image'],
['block' => 'adminhtml/catalog_product_helper_form_gallery_content'],
['block' => 'adminhtml/cms_wysiwyg_images_tree'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Created M/06/10/2020
* Updated M/06/10/2020
*
* Copyright 2008-2020 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
*
* This program is free software, you can redistribute it or modify
* it under the terms of the GNU General Public License (GPL) as published
* by the free software foundation, either version 2 of the license, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but without any warranty, without even the implied warranty of
* merchantability or fitness for a particular purpose. See the
* GNU General Public License (GPL) for more details.
*/

class Luigifab_Apijs_Block_Adminhtml_Rewrite_Additional extends Mage_Adminhtml_Block_Cache_Additional {

protected function _construct() {
$this->setModuleName('Mage_Adminhtml');
}

public function getCleanImagesUrl() {
return $this->getUrl('*/system_config/edit', ['section' => 'apijs']);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created S/04/01/2020
* Updated M/21/01/2020
* Updated M/29/09/2020
*
* Copyright 2008-2020 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
Expand All @@ -19,6 +19,10 @@

class Luigifab_Apijs_Block_Adminhtml_Rewrite_Tree extends Mage_Adminhtml_Block_Cms_Wysiwyg_Images_Tree {

protected function _construct() {
$this->setModuleName('Mage_Adminhtml');
}

public function getTreeJson() {

$helper = $this->helper('cms/wysiwyg_images');
Expand Down
14 changes: 7 additions & 7 deletions src/app/code/community/Luigifab/Apijs/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created D/20/11/2011
* Updated J/16/07/2020
* Updated D/20/09/2020
*
* Copyright 2008-2020 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
Expand Down Expand Up @@ -180,18 +180,18 @@ public function getThumbnail($product, $default, $image, $id) {
return $data;
}

public function removeFiles(string $dir, string $filename) {
public function removeFiles(string $dir, string $file) {

// recherche tous les fichiers avec la commande find
// si le nom du fichier contient des caractères simples
if (Mage::getStoreConfigFlag('apijs/general/remove_cache') && (preg_match('#[\w\-]+\.\w+$#', $filename) === 1)) {
if (Mage::getStoreConfigFlag('apijs/general/remove_cache') && (preg_match('#[\w\-]+\.\w+$#', $file) === 1)) {

Mage::log(sprintf('Remove all %s images with exec(find) in %s', $filename, $dir), Zend_Log::INFO, 'apijs.log');
Mage::log(sprintf('Remove all %s images with exec(find) in %s', $file, $dir), Zend_Log::INFO, 'apijs.log');

if (mb_stripos($filename, '/') === false)
exec('find '.escapeshellarg($dir).' -name '.escapeshellarg($filename).' | xargs rm');
if (mb_stripos($file, '/') === false)
exec('find '.escapeshellarg($dir).' -name '.escapeshellarg($file).' | xargs rm');
else
exec('find '.escapeshellarg($dir).' -wholename '.escapeshellarg('*/'.$filename).' | xargs rm');
exec('find '.escapeshellarg($dir).' -wholename '.escapeshellarg('*/'.$file).' | xargs rm');
}
}

Expand Down
193 changes: 128 additions & 65 deletions src/app/code/community/Luigifab/Apijs/Helper/Rewrite/Image.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php
/**
* Created J/12/09/2019
* Updated D/26/07/2020
* Updated M/06/10/2020
*
* Copyright 2008-2020 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2019-2020 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2020 | Jérôme Siau <jerome~cellublue~com>
* https://www.luigifab.fr/openmage/apijs
*
* This program is free software, you can redistribute it or modify
Expand All @@ -30,7 +32,7 @@ public function init($product, $attribute, $path = null, $fixed = true) {
// sans le dossier, cela ne génère pas les miniatures wysiwyg ou category
$dir = Mage::helper('apijs')->getCatalogProductImageDir(true);
if (!is_dir($dir))
mkdir($dir, 0755, true);
@mkdir($dir, 0755, true);

//if (!isset($this->_begin)) $this->_begin = microtime(true);
//if (!isset($this->_count)) $this->_count = 0;
Expand All @@ -54,22 +56,50 @@ public function init($product, $attribute, $path = null, $fixed = true) {
$model = Mage::getModel('catalog/product_image');
$model->setDestinationSubdir($attribute);
$attribute = $model->getDestinationSubdir();

$this->_setModel($model);
$this->setWatermark(Mage::getStoreConfig('design/watermark/'.$attribute.'_image'));
$this->setWatermarkImageOpacity(Mage::getStoreConfig('design/watermark/'.$attribute.'_imageOpacity'));
$this->setWatermarkPosition(Mage::getStoreConfig('design/watermark/'.$attribute.'_position'));
$this->setWatermarkSize(Mage::getStoreConfig('design/watermark/'.$attribute.'_size'));

// cache de la config et des urls générées
if (empty($this->_config) || empty($this->_urls)) {

$this->_config = @json_decode(Mage::app()->loadCache('apijs_config'), true);
if (empty($this->_config) || !is_array($this->_config)) {
$this->_config = [
'date' => date('Y-m-d H:i:s \U\T\C'),
'apijs/general/python' => Mage::getStoreConfigFlag('apijs/general/python'),
'apijs/general/remove_store_id' => Mage::getStoreConfigFlag('apijs/general/remove_store_id')
];
}

$this->_urls = @json_decode(Mage::app()->loadCache('apijs_urls'), true);
if (empty($this->_urls) || !is_array($this->_urls)) {
$this->_urls = [
'date' => date('Y-m-d H:i:s \U\T\C')
];
}
}

// watermark
if (!array_key_exists('design/watermark/'.$attribute.'_image', $this->_config)) {
$this->_config['design/watermark/'.$attribute.'_image'] = Mage::getStoreConfig('design/watermark/'.$attribute.'_image');
$this->_config['design/watermark/'.$attribute.'_imageOpacity'] = Mage::getStoreConfig('design/watermark/'.$attribute.'_imageOpacity');
$this->_config['design/watermark/'.$attribute.'_position'] = Mage::getStoreConfig('design/watermark/'.$attribute.'_position');
$this->_config['design/watermark/'.$attribute.'_size'] = Mage::getStoreConfig('design/watermark/'.$attribute.'_size');
}
if (!empty($this->_config['design/watermark/'.$attribute.'_image'])) {
$this->setWatermark($this->_config['design/watermark/'.$attribute.'_image']);
$this->setWatermarkImageOpacity($this->_config['design/watermark/'.$attribute.'_imageOpacity']);
$this->setWatermarkPosition($this->_config['design/watermark/'.$attribute.'_position']);
$this->setWatermarkSize($this->_config['design/watermark/'.$attribute.'_size']);
}

if (empty($path))
$path = $product->getData($attribute);


$this->_svg = (!empty($path) && (mb_substr($path, -4) == '.svg'));
$this->setImageFile($path);
$this->setBaseFile($model, $path);

if (Mage::getStoreConfigFlag('apijs/general/python')) {
if ($this->_config['apijs/general/python']) {
$processor = Mage::getSingleton('apijs/python')->setFilename($model->getBaseFile())->setFixed($fixed);
$model->setImageProcessor($processor);
}
Expand Down Expand Up @@ -126,7 +156,7 @@ public function __toString() {
$model = $this->_getModel();
if (!empty($this->_svg)) {
$this->resize(0, 0);
if (!Mage::getStoreConfigFlag('apijs/general/python')) {
if (!$this->_config['apijs/general/python']) {
if ($model->getDestinationSubdir() == 'wysiwyg')
return Mage::getBaseUrl('media').str_replace('../', '', $this->getImageFile());
if ($model->getDestinationSubdir() == 'category')
Expand All @@ -149,25 +179,33 @@ public function __toString() {
$filename = str_replace(['../', '//'], ['', '/'], Mage::helper('apijs')->getWysiwygImageDir(true).
mb_substr($filename, mb_stripos($filename, '/'.$dir.'/') + mb_strlen('/'.$dir.'/')));

if (!is_file($filename)) {

if (!empty($this->_scheduleRotate))
$model->rotate($this->getAngle());
if (!empty($this->_scheduleResize))
$model->resize();
if (!empty($this->getWatermark()))
$model->setWatermark($this->getWatermark());

// $url = $model->saveFile()->getUrl();
// oui mais non car il faut supprimer les ../ des chemins et des urls
$model->getImageProcessor()->save($filename);
if (array_key_exists($filename, $this->_urls)) {
$url = $this->_urls[$filename];
}
else {
if (!is_file($filename)) {

if (!empty($this->_scheduleRotate))
$model->rotate($this->getAngle());
if (!empty($this->_scheduleResize))
$model->resize();
if (!empty($this->getWatermark()))
$model->setWatermark($this->getWatermark());

// $url = $model->saveFile()->getUrl();
// oui mais non car il faut supprimer les ../ des chemins et des urls
$model->getImageProcessor()->save($filename);
}

// return $model->getUrl();
// .../media/catalog/product/cache/[0/]wysiwyg/1200x/040ec09b1e35df139433887a97daa66f/../../wysiwyg/abc/xyz.jpg
// .../media/wysiwyg/cache/1200x/040ec09b1e35df139433887a97daa66f/wysiwyg/abc/xyz.jpg
$url = $model->getUrl();
$url = str_replace('../', '', preg_replace('#catalog/product/cache/(?:[0-9]+/)?'.$dir.'/#', $dir.'/cache/', $url));

// cache
$this->_urls[$filename] = $url;
}

// return $model->getUrl();
// .../media/catalog/product/cache/[0/]wysiwyg/1200x/040ec09b1e35df139433887a97daa66f/../../wysiwyg/abc/xyz.jpg
// .../media/wysiwyg/cache/1200x/040ec09b1e35df139433887a97daa66f/wysiwyg/abc/xyz.jpg
$url = $model->getUrl();
$url = str_replace('../', '', preg_replace('#catalog/product/cache/(?:[0-9]+/)?'.$dir.'/#', $dir.'/cache/', $url));
}
else if ($model->getDestinationSubdir() == 'category') {
// if ($model->isCached())
Expand All @@ -178,53 +216,69 @@ public function __toString() {
$filename = $model->getNewFile();
$filename = str_replace(['../', '//', '/category/', '/catalog/product/'], ['', '/', '/', '/catalog/category/'], $filename);

if (!is_file($filename)) {

if (!empty($this->_scheduleRotate))
$model->rotate($this->getAngle());
if (!empty($this->_scheduleResize))
$model->resize();
if (!empty($this->getWatermark()))
$model->setWatermark($this->getWatermark());

// $url = $model->saveFile()->getUrl();
// oui mais non car il faut supprimer les ../ des chemins et des urls
$model->getImageProcessor()->save($filename);
if (array_key_exists($filename, $this->_urls)) {
$url = $this->_urls[$filename];
}
else {
if (!is_file($filename)) {

if (!empty($this->_scheduleRotate))
$model->rotate($this->getAngle());
if (!empty($this->_scheduleResize))
$model->resize();
if (!empty($this->getWatermark()))
$model->setWatermark($this->getWatermark());

// $url = $model->saveFile()->getUrl();
// oui mais non car il faut supprimer les ../ des chemins et des urls
$model->getImageProcessor()->save($filename);
}

// return $model->getUrl();
// .../media/catalog/product/cache/[0/]category/1200x/040ec09b1e35df139433887a97daa66f/../category/xyz.jpg
// .../media/catalog/category/cache/[0/]1200x/040ec09b1e35df139433887a97daa66f/xyz.jpg
$url = $model->getUrl();
$url = str_replace(['../', '/category/', '/catalog/product/'], ['', '/', '/catalog/category/'], $url);

// cache
$this->_urls[$filename] = $url;
}

// return $model->getUrl();
// .../media/catalog/product/cache/[0/]category/1200x/040ec09b1e35df139433887a97daa66f/../category/xyz.jpg
// .../media/catalog/category/cache/[0/]1200x/040ec09b1e35df139433887a97daa66f/xyz.jpg
$url = $model->getUrl();
$url = str_replace(['../', '/category/', '/catalog/product/'], ['', '/', '/catalog/category/'], $url);
}
else {
// if ($model->isCached())
// /x/y/xyz.jpg
// .../media/catalog/product/cache/[0/]category/1200x/040ec09b1e35df139433887a97daa66f/x/y/xyz.jpg
$filename = $model->getNewFile();
if (Mage::getStoreConfigFlag('apijs/general/remove_store_id'))
if ($this->_config['apijs/general/remove_store_id'])
$filename = preg_replace('#/cache/\d+/#', '/cache/', $filename);

if (!is_file($filename)) {

if (!empty($this->_scheduleRotate))
$model->rotate($this->getAngle());
if (!empty($this->_scheduleResize))
$model->resize();
if (!empty($this->getWatermark()))
$model->setWatermark($this->getWatermark());

// $url = $model->saveFile()->getUrl();
// oui mais non car il faut supprimer les ../ des chemins et des urls
$model->getImageProcessor()->save($filename);
if (array_key_exists($filename, $this->_urls)) {
$url = $this->_urls[$filename];
}
else {
if (!is_file($filename)) {

if (!empty($this->_scheduleRotate))
$model->rotate($this->getAngle());
if (!empty($this->_scheduleResize))
$model->resize();
if (!empty($this->getWatermark()))
$model->setWatermark($this->getWatermark());

// $url = $model->saveFile()->getUrl();
// oui mais non car il faut supprimer les ../ des chemins et des urls
$model->getImageProcessor()->save($filename);
}

// return $model->getUrl();
// .../media/catalog/product/cache/[0/]category/1200x/040ec09b1e35df139433887a97daa66f/x/y/xyz.jpg
$url = $model->getUrl();
if ($this->_config['apijs/general/remove_store_id'])
$url = preg_replace('#/cache/\d+/#', '/cache/', $url);

// cache
$this->_urls[$filename] = $url;
}

// return $model->getUrl();
// .../media/catalog/product/cache/[0/]category/1200x/040ec09b1e35df139433887a97daa66f/x/y/xyz.jpg
$url = $model->getUrl();
if (Mage::getStoreConfigFlag('apijs/general/remove_store_id'))
$url = preg_replace('#/cache/\d+/#', '/cache/', $url);
}
}
catch (Exception $e) {
Expand All @@ -235,4 +289,13 @@ public function __toString() {

return $url;
}

public function __destruct() {

if (!empty($this->_config) && Mage::app()->useCache('config')) // ici la balise XML du cache, ci-dessous une clef et le tag du cache
Mage::app()->saveCache(json_encode($this->_config), 'apijs_config', ['CONFIG']);

if (!empty($this->_urls) && Mage::app()->useCache('block_html')) // ici la balise XML du cache, ci-dessous une clef et le tag du cache
Mage::app()->saveCache(json_encode($this->_urls), 'apijs_urls', ['CONFIG', 'BLOCK_HTML']);
}
}
Loading

0 comments on commit b8f6784

Please sign in to comment.