From 772ae8bc0b1125748b4e66feb2ef4c9be57d867c Mon Sep 17 00:00:00 2001 From: Fabrice Creuzot Date: Wed, 7 Jul 2021 20:00:00 +0000 Subject: [PATCH] Version 6.7.0 --- README.md | 8 +- composer.json | 3 +- .../Apijs/Block/Adminhtml/Config/Help.php | 11 +-- .../Rewrite/{Category.php => Categoryimg.php} | 10 +-- .../Apijs/Block/Adminhtml/Rewrite/Config.php | 8 +- .../Apijs/Block/Adminhtml/Rewrite/Gallery.php | 61 ++++++++++++++- .../Block/Adminhtml/Rewrite/Productimg.php | 44 +++++++++++ .../community/Luigifab/Apijs/Helper/Data.php | 73 +++++++++++++----- .../Luigifab/Apijs/Helper/Rewrite/Image.php | 48 +++++++----- .../Luigifab/Apijs/Model/Observer.php | 75 +++++++++---------- .../community/Luigifab/Apijs/Model/Python.php | 40 +++++----- .../Apijs/Model/Rewrite/Categoryimg.php | 40 ++++++++++ .../Apijs/Model/Rewrite/Productimg.php | 40 ++++++++++ .../Apijs/Model/Rewrite/Validator.php | 6 +- .../Luigifab/Apijs/Model/Useragentparser.php | 8 +- .../controllers/Apijs/CacheController.php | 8 +- .../controllers/Apijs/MediaController.php | 34 ++++----- .../controllers/Apijs/WysiwygController.php | 23 +++--- .../community/Luigifab/Apijs/etc/config.xml | 59 ++++++++------- .../community/Luigifab/Apijs/lib/image.py | 28 ++++--- src/app/code/community/Luigifab/Apijs/readme | 19 +++-- .../{install-6.6.0.php => install-6.7.0.php} | 6 +- .../template/luigifab/apijs/demo.phtml | 3 +- .../template/luigifab/apijs/files.phtml | 4 +- .../template/luigifab/apijs/gallery.phtml | 48 +++++------- .../template/luigifab/apijs/demo.phtml | 5 +- .../css/luigifab/apijs/apijs-openmage.min.css | 2 +- .../css/luigifab/apijs/apijs-print.min.css | 2 +- .../luigifab/apijs/apijs-print.min.css.map | 2 +- .../luigifab/apijs/apijs-screen-rtl.min.css | 4 +- .../apijs/apijs-screen-rtl.min.css.map | 2 +- .../css/luigifab/apijs/apijs-screen.min.css | 4 +- .../luigifab/apijs/apijs-screen.min.css.map | 2 +- .../default/css/luigifab/apijs/styles.css | 6 +- .../css/luigifab/apijs/styles.min.css.map | 2 +- .../js/luigifab/apijs/apijs-openmage.min.js | 2 +- .../default/js/luigifab/apijs/apijs.min.js | 4 +- .../js/luigifab/apijs/apijs.min.js.map | 2 +- .../default/default/js/luigifab/apijs/app.js | 23 +++--- .../default/js/luigifab/apijs/app.min.js.map | 2 +- .../css/luigifab/apijs/apijs-print.min.css | 2 +- .../luigifab/apijs/apijs-print.min.css.map | 2 +- .../luigifab/apijs/apijs-screen-rtl.min.css | 4 +- .../apijs/apijs-screen-rtl.min.css.map | 2 +- .../css/luigifab/apijs/apijs-screen.min.css | 4 +- .../luigifab/apijs/apijs-screen.min.css.map | 2 +- .../css/luigifab/apijs/styles.min.css.map | 2 +- .../default/js/luigifab/apijs/apijs.min.js | 4 +- .../js/luigifab/apijs/apijs.min.js.map | 2 +- 49 files changed, 513 insertions(+), 282 deletions(-) rename src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/{Category.php => Categoryimg.php} (74%) create mode 100644 src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Productimg.php create mode 100644 src/app/code/community/Luigifab/Apijs/Model/Rewrite/Categoryimg.php create mode 100644 src/app/code/community/Luigifab/Apijs/Model/Rewrite/Productimg.php rename src/app/code/community/Luigifab/Apijs/sql/apijs_setup/{install-6.6.0.php => install-6.7.0.php} (96%) diff --git a/README.md b/README.md index 88d2640..6d8387b 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,12 @@ # apijs -Beautiful javascript popup and slideshow for [OpenMage](https://github.com/OpenMage/magento-lts). +JavaScript pop-ups and slideshow for [OpenMage](https://github.com/OpenMage/magento-lts). For more information, go to https://www.luigifab.fr/apijs and https://www.luigifab.fr/openmage/apijs (IPv6 is required, it's not a joke). No IPv6? It's possible to get an IPv6 thanks to *Miredo*. Run `sudo apt install miredo` and `sudo service miredo force-start`. -- for the app, go to [apijs](https://www.github.com/luigifab/apijs) -- for the plugin for Redmine, go to [redmine-apijs](https://www.github.com/luigifab/redmine-apijs) -- for the bundle for Symfony, go to [symfony-apijs](https://www.github.com/luigifab/symfony-apijs) - This repository is a releases mirror. To install the module, please use the composer key available in the documentation. -- Current version: 6.6.0 (03/03/2021) +- Current version: 6.7.0 (07/07/2021) - Compatibility: OpenMage 19.x / 20.x, PHP 7.2 / 7.3 / 7.4 / 8.0, Python 3.3 / 3.4 / 3.5 / 3.6 / 3.7 / 3.8 / 3.9 - Client compatibility: Firefox 36+, Chrome 32+, 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) diff --git a/composer.json b/composer.json index db2bafb..f05dc57 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,8 @@ { "type": "magento-module", "name": "luigifab/openmage-apijs", - "description": "Beautiful javascript popup and slideshow for OpenMage.", + "description": "JavaScript pop-ups and slideshow for OpenMage.", + "keywords": ["openmage", "openmage-module"], "homepage": "https://github.com/luigifab/openmage-apijs", "license": "GPL-2.0-or-later", "authors": [ diff --git a/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Config/Help.php b/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Config/Help.php index bcf3bf4..71adfcd 100644 --- a/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Config/Help.php +++ b/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Config/Help.php @@ -1,7 +1,7 @@ * https://www.luigifab.fr/openmage/apijs @@ -23,14 +23,12 @@ public function render(Varien_Data_Form_Element_Abstract $element) { $msg = $this->checkRewrites(); if ($msg !== true) - return sprintf('

%s %s %3$s | ⚠ IPv6

'. - '

%s
%s

', + return sprintf('

%s %s %3$s | ⚠ IPv6

%s
%s

', 'Luigifab/Apijs', $this->helper('apijs')->getVersion(), 'luigifab.fr/openmage/apijs', $this->__('INCOMPLETE MODULE INSTALLATION'), $this->__('There is conflict (%s).', $msg)); - return sprintf('

%s %s '. - '%3$s | %4$s | ⚠ IPv6

', + return sprintf('

%s %s %3$s | %4$s | ⚠ IPv6

', 'Luigifab/Apijs', $this->helper('apijs')->getVersion(), 'luigifab.fr/openmage/apijs', 'luigifab.fr/apijs'); } @@ -40,10 +38,13 @@ private function checkRewrites() { ['block' => 'adminhtml/cache_additional'], ['block' => 'adminhtml/catalog_category_helper_image'], ['block' => 'adminhtml/catalog_product_helper_form_gallery_content'], + ['block' => 'adminhtml/catalog_product_helper_form_image'], ['block' => 'adminhtml/cms_wysiwyg_images_tree'], ['block' => 'adminhtml/system_config_form_field_image'], ['helper' => 'catalog/image'], + ['model' => 'catalog/category_attribute_backend_image'], ['model' => 'catalog/product_attribute_backend_media'], + ['model' => 'catalog_resource/product_attribute_backend_image'], ['model' => 'catalog_resource/product_attribute_backend_media'], ['model' => 'core/file_validator_image'] ]; diff --git a/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Category.php b/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Categoryimg.php similarity index 74% rename from src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Category.php rename to src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Categoryimg.php index bd9733b..8beaa06 100644 --- a/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Category.php +++ b/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Categoryimg.php @@ -1,7 +1,7 @@ * https://www.luigifab.fr/openmage/apijs @@ -17,7 +17,7 @@ * GNU General Public License (GPL) for more details. */ -class Luigifab_Apijs_Block_Adminhtml_Rewrite_Category extends Mage_Adminhtml_Block_Catalog_Category_Helper_Image { +class Luigifab_Apijs_Block_Adminhtml_Rewrite_Categoryimg extends Mage_Adminhtml_Block_Catalog_Category_Helper_Image { protected function _construct() { $this->setModuleName('Mage_Adminhtml'); @@ -31,9 +31,9 @@ public function getElementHtml() { $html = '
'.Varien_Data_Form_Element_Abstract::getElementHtml(); if ($this->getValue()) { - $url = $this->_getUrl(); - $url = (mb_stripos($url, 'http') === 0) ? $url : Mage::getBaseUrl('media').$url; - $html .= sprintf(' %s (%s) ', $url, addslashes($this->getValue()), $this->getHtmlId(), Mage::helper('apijs')->__('Preview'), $this->getValue()); // pas de this->helper ici + $link = $this->_getUrl(); + $link = (mb_stripos($link, 'http') === 0) ? $link : Mage::getBaseUrl('media').$link; + $html .= sprintf(' %s (%s) ', $link, addslashes($this->getValue()), $this->getHtmlId(), Mage::helper('apijs')->__('Preview'), $this->getValue()); // pas de this->helper ici } return $html.$this->_getDeleteCheckbox().'
'; diff --git a/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Config.php b/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Config.php index 1067381..00ab74c 100644 --- a/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Config.php +++ b/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Config.php @@ -1,7 +1,7 @@ * https://www.luigifab.fr/openmage/apijs @@ -31,9 +31,9 @@ public function getElementHtml() { $html = '
'.Varien_Data_Form_Element_Abstract::getElementHtml(); if ($this->getValue()) { - $url = $this->_getUrl(); - $url = (mb_stripos($url, 'http') === 0) ? $url : Mage::getBaseUrl('media').$url; - $html .= sprintf(' %s (%s) ', $url, addslashes($this->getValue()), $this->getHtmlId(), Mage::helper('apijs')->__('Preview'), $this->getValue()); // pas de $this->helper + $link = $this->_getUrl(); + $link = (mb_stripos($link, 'http') === 0) ? $link : Mage::getBaseUrl('media').$link; + $html .= sprintf(' %s (%s) ', $link, addslashes($this->getValue()), $this->getHtmlId(), Mage::helper('apijs')->__('Preview'), $this->getValue()); // pas de this->helper ici } return $html.$this->_getDeleteCheckbox().'
'; diff --git a/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Gallery.php b/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Gallery.php index 8f39398..1f4b7e8 100644 --- a/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Gallery.php +++ b/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Gallery.php @@ -1,7 +1,7 @@ * https://www.luigifab.fr/openmage/apijs @@ -32,7 +32,62 @@ public function __construct() { $this->setTemplate('luigifab/apijs/gallery.phtml'); // catalog/product/helper/gallery.phtml } - public function getScopeLabel($attribute) { + public function getImages(bool $sortByStore) { + + $product = Mage::registry('current_product'); + $storeId = $product->getStoreId(); + $attributes = $product->getMediaAttributes(); + + $values = $product->getMediaGallery('images'); + $values = empty($values) ? [] : $values; + + $images = []; + $counts = []; + foreach ($values as $image) { + + $image = is_object($image) ? $image : new Varien_Object($image); + $images[$image->getData('file')] = $image; + + if (empty($storeId)) + $image->setData('position', (int) $image->getData('position')); + else if ($image->getData('position') != $image->getData('position_default')) + $image->setData('position', (int) $image->getData('position')); + else + $image->setData('position', (int) $image->getData('position_default')); + + $image->setData('apijs_group', $sortByStore ? (int) ($image->getData('position') / 100) * 100 : 0); + + if (array_key_exists($image->getData('apijs_group'), $counts)) + $counts[$image->getData('apijs_group')]++; + else + $counts[$image->getData('apijs_group')] = 1; + } + + $ids = []; + foreach ($attributes as $attribute) { + if (($attribute->getIsText() !== true) && ($attribute->getIsCheckbox() !== true)) + $ids[] = $attribute->getId(); + } + + $database = Mage::getSingleton('core/resource'); + $read = $database->getConnection('core_read'); + $table = $database->getTableName('catalog_product_entity_varchar'); + $values = $read->fetchAll('SELECT store_id, attribute_id, value FROM '.$table.' WHERE entity_id = '.$product->getId().' AND attribute_id IN ('.implode(',', $ids).')'); + + $defaults = []; + foreach ($values as $value) { + + if (!empty($images[$value['value']])) { + $image = $images[$value['value']]; + if (floor($image->getData('position') / 100) == $value['store_id']) + $defaults[$value['attribute_id']][$value['store_id']] = $value['value']; + } + } + + return [$images, $counts, $defaults]; + } + + public function getScopeLabel(object $attribute) { if ($attribute->isScopeGlobal()) return $this->__('[GLOBAL]'); @@ -42,7 +97,7 @@ public function getScopeLabel($attribute) { return $this->__('[STORE VIEW]'); } - public function isUseGlobal($image, $field, $value) { + public function isUseGlobal(object $image, string $field, string $value) { return empty($image->getData($field.'_global')) ? '' : $value.'="'.$value.'"'; } diff --git a/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Productimg.php b/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Productimg.php new file mode 100644 index 0000000..4612e81 --- /dev/null +++ b/src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Rewrite/Productimg.php @@ -0,0 +1,44 @@ + + * 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_Productimg extends Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Image { + + protected function _construct() { + $this->setModuleName('Mage_Adminhtml'); + } + + public function getElementHtml() { + + if (Mage::getStoreConfigFlag('apijs/general/backend')) { + + $this->setData('class', 'input-file'); + $html = '
'.Varien_Data_Form_Element_Abstract::getElementHtml(); + + if ($this->getValue()) { + $link = $this->_getUrl(); + $link = (mb_stripos($link, 'http') === 0) ? $link : Mage::getBaseUrl('media').$link; + $html .= sprintf(' %s (%s) ', $link, addslashes($this->getValue()), $this->getHtmlId(), Mage::helper('apijs')->__('Preview'), $this->getValue()); // pas de this->helper ici + } + + return $html.$this->_getDeleteCheckbox().'
'; + } + + return parent::getElementHtml(); + } +} \ No newline at end of file diff --git a/src/app/code/community/Luigifab/Apijs/Helper/Data.php b/src/app/code/community/Luigifab/Apijs/Helper/Data.php index 583f429..cac37a3 100644 --- a/src/app/code/community/Luigifab/Apijs/Helper/Data.php +++ b/src/app/code/community/Luigifab/Apijs/Helper/Data.php @@ -1,7 +1,7 @@ * https://www.luigifab.fr/openmage/apijs @@ -58,7 +58,11 @@ public function getNumberToHumanSize(int $number) { public function getCatalogProductImageDir(bool $cache = false) { - return rtrim(Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(), '/').($cache ? '/cache/' : '/'); + + if (empty($this->_baseMediaPath)) + $this->_baseMediaPath = rtrim(Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(), '/'); + + return $this->_baseMediaPath.($cache ? '/cache/' : '/'); } public function getCatalogCategoryImageDir(bool $cache = false) { @@ -66,8 +70,11 @@ public function getCatalogCategoryImageDir(bool $cache = false) { } public function getWysiwygImageDir(bool $cache = false, bool $old = false) { - $dir = $old ? Mage_Cms_Model_Wysiwyg_Images_Storage::THUMBS_DIRECTORY_NAME : 'cache'; - return rtrim(Mage::helper('cms/wysiwyg_images')->getStorageRoot(), '/').($cache ? '/'.$dir.'/' : '/'); + + if (empty($this->_baseWysiwygPath)) + $this->_baseWysiwygPath = rtrim(Mage::helper('cms/wysiwyg_images')->getStorageRoot(), '/'); + + return $this->_baseWysiwygPath.($cache ? '/'.($old ? Mage_Cms_Model_Wysiwyg_Images_Storage::THUMBS_DIRECTORY_NAME : 'cache').'/' : '/'); } @@ -184,21 +191,6 @@ public function getThumbnail($product, $default, object $image, int $id) { } - 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+$#', $file) === 1)) { - - Mage::log(sprintf('Remove all %s images with exec(find) in %s', $file, $dir), Zend_Log::INFO, 'apijs.log'); - - if (mb_stripos($file, '/') === false) - exec('find '.escapeshellarg($dir).' -name '.escapeshellarg($file).' | xargs rm'); - else - exec('find '.escapeshellarg($dir).' -wholename '.escapeshellarg('*/'.$file).' | xargs rm'); - } - } - public function getMaxSizes(bool $dump = false) { // config admise en Mo, "one file, all files" @@ -231,7 +223,7 @@ public function getTabName($product = null) { foreach ($egroups as $group) { $attributes = $product->getAttributes($group->getId(), true); - foreach ($attributes as $key => $attribute) { + foreach ($attributes as $attribute) { if (in_array($attribute->getData('attribute_code'), ['media_gallery', 'gallery'])) return 'group_'.$group->getId(); } @@ -249,4 +241,45 @@ public function renderGalleryBlock(object $product) { return $block->toHtml(); } + + + private function searchAndRemoveFiles(string $dir, string $file) { + + if (mb_stripos($file, '/') === false) + $cmd = 'find '.escapeshellarg($dir).' -name '.escapeshellarg($file).' | xargs rm'; + else + $cmd = 'find '.escapeshellarg($dir).' -wholename '.escapeshellarg('*/'.trim($file, '/')).' | xargs rm'; + + Mage::log($cmd, Zend_Log::DEBUG, 'apijs.log'); + exec($cmd); + } + + public function removeFiles(string $dir, string $file, bool $now = false) { + + // recherche et supprime 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+$#', $file) === 1)) { + + if (empty($this->_filesToRemove)) + $this->_filesToRemove = []; + + if (is_dir($dir)) { + if ($now) + $this->searchAndRemoveFiles($dir, $file); + else + $this->_filesToRemove[] = [$dir => $file]; + } + } + } + + public function __destruct() { + + if (!empty($this->_filesToRemove)) { + foreach ($this->_filesToRemove as $data) { + foreach ($data as $dir => $file) { + $this->searchAndRemoveFiles($dir, $file); + } + } + } + } } \ No newline at end of file diff --git a/src/app/code/community/Luigifab/Apijs/Helper/Rewrite/Image.php b/src/app/code/community/Luigifab/Apijs/Helper/Rewrite/Image.php index 45d810d..1e9202c 100644 --- a/src/app/code/community/Luigifab/Apijs/Helper/Rewrite/Image.php +++ b/src/app/code/community/Luigifab/Apijs/Helper/Rewrite/Image.php @@ -1,7 +1,7 @@ * Copyright 2019-2021 | Fabrice Creuzot @@ -33,8 +33,14 @@ public function init($product, $attribute, $path = null, $fixed = true) { //$this->_debugStart = microtime(true); //Mage::log('Open file '.$path.'...'); + if (empty($this->_helper)) { + $this->_helper = Mage::helper('apijs'); + $this->_modelImg = Mage::getModel('catalog/product_image'); + $this->_cleanUrl = mb_strpos(Mage::getBaseUrl('media'), Mage::getBaseUrl('web')) === 0; + } + // sans le dossier, cela ne génère pas les miniatures wysiwyg ou category - $dir = Mage::helper('apijs')->getCatalogProductImageDir(true); + $dir = $this->_helper->getCatalogProductImageDir(true); if (!is_dir($dir)) @mkdir($dir, 0755, true); @@ -51,7 +57,7 @@ public function init($product, $attribute, $path = null, $fixed = true) { $path = '../category/'.$path; } - $model = Mage::getModel('catalog/product_image'); + $model = clone $this->_modelImg; $model->setDestinationSubdir($attribute); $attribute = $model->getDestinationSubdir(); $this->_setModel($model); @@ -59,6 +65,8 @@ public function init($product, $attribute, $path = null, $fixed = true) { // cache de la config et des urls générées if (empty($this->_cacheConfig) || empty($this->_cacheUrls)) { + $this->_processor = Mage::getSingleton('apijs/python'); + $this->_cacheConfig = Mage::app()->useCache('config') ? @json_decode(Mage::app()->loadCache('apijs_config'), true) : null; if (empty($this->_cacheConfig) || !is_array($this->_cacheConfig)) { $this->_cacheConfig = [ @@ -68,7 +76,7 @@ public function init($product, $attribute, $path = null, $fixed = true) { ]; } - $this->_cacheUrls = Mage::app()->useCache('config') ? @json_decode(Mage::app()->loadCache('apijs_urls'), true) : null; + $this->_cacheUrls = Mage::app()->useCache('block_html') ? @json_decode(Mage::app()->loadCache('apijs_urls'), true) : null; if (empty($this->_cacheUrls) || !is_array($this->_cacheUrls)) { $this->_cacheUrls = [ 'date' => date('Y-m-d H:i:s \U\T\C') @@ -138,11 +146,11 @@ public function setBaseFile() { //$go = microtime(true); $model = $this->_getModel(); - $file = Mage::helper('apijs')->getCatalogProductImageDir().trim($this->_imageFile, '/'); + $file = $this->_helper->getCatalogProductImageDir().trim($this->_imageFile, '/'); if ($this->_cacheConfig['apijs/general/python']) { - $processor = Mage::getSingleton('apijs/python')->setFilename($file)->setFixed($this->_fixed); - $model->setImageProcessor($processor); + $this->_processor->setFilename($file)->setFixed($this->_fixed); + $model->setImageProcessor($this->_processor); } try { @@ -158,11 +166,11 @@ public function setBaseFile() { else { $model->setBaseFile('/no_selection'); $this->_imageFile = $model->getBaseFile(); - if (is_object($processor)) - $processor->setFilename($this->_imageFile); + if (is_object($this->_processor)) + $this->_processor->setFilename($this->_imageFile); } } - catch (Throwable $e) { + catch (Throwable $t) { $area = Mage::getDesign()->getArea(); if ($area == 'adminhtml') Mage::getDesign()->setArea('frontend'); @@ -171,8 +179,8 @@ public function setBaseFile() { $model->setDestinationSubdir('image'); $model->setBaseFile('/no_selection'); $this->_imageFile = $model->getBaseFile(); - if (is_object($processor)) - $processor->setFilename($this->_imageFile); + if (is_object($this->_processor)) + $this->_processor->setFilename($this->_imageFile); // si ça crash encore // c'est éventuellement la faute à un lien symbolique, quelque part dans media, au lieu d'être complètement sur media if ($area == 'adminhtml') @@ -183,6 +191,10 @@ public function setBaseFile() { return $this; } + public function cleanUrl($url) { + return $this->_cleanUrl ? mb_substr($url, strpos($url, '/', 9)) : $url; + } + public function __toString() { $model = $this->_getModel(); @@ -210,7 +222,7 @@ public function __toString() { // .../media/wysiwyg/cache/1200x/040ec09b1e35df139433887a97daa66f/wysiwyg/abc/xyz.jpg $dir = Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY; $filename = $model->getNewFile(); - $filename = str_replace(['../', '//'], ['', '/'], Mage::helper('apijs')->getWysiwygImageDir(true). + $filename = str_replace(['../', '//'], ['', '/'], $this->_helper->getWysiwygImageDir(true). mb_substr($filename, mb_stripos($filename, '/'.$dir.'/') + mb_strlen('/'.$dir.'/'))); if (array_key_exists($filename, $this->_cacheUrls)) { @@ -236,8 +248,8 @@ public function __toString() { // 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)); + $url = $this->cleanUrl($model->getUrl()); + $url = str_replace('../', '', preg_replace('#catalog/product/cache/(?:\d+/)?'.$dir.'/#', $dir.'/cache/', $url)); // cache $this->_cacheUrls[$filename] = $url; @@ -275,7 +287,7 @@ public function __toString() { // 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 = $this->cleanUrl($model->getUrl()); $url = str_replace(['../', '/category/', '/catalog/product/'], ['', '/', '/catalog/category/'], $url); // cache @@ -312,7 +324,7 @@ public function __toString() { // return $model->getUrl(); // .../media/catalog/product/cache/[0/]category/1200x/040ec09b1e35df139433887a97daa66f/x/y/xyz.jpg - $url = $model->getUrl(); + $url = $this->cleanUrl($model->getUrl()); if ($this->_cacheConfig['apijs/general/remove_store_id']) $url = preg_replace('#/cache/\d+/#', '/cache/', $url); @@ -321,7 +333,7 @@ public function __toString() { } } } - catch (Throwable $e) { + catch (Throwable $t) { $url = Mage::getDesign()->getSkinUrl($this->getPlaceholder()); } diff --git a/src/app/code/community/Luigifab/Apijs/Model/Observer.php b/src/app/code/community/Luigifab/Apijs/Model/Observer.php index c71b178..8d07cef 100644 --- a/src/app/code/community/Luigifab/Apijs/Model/Observer.php +++ b/src/app/code/community/Luigifab/Apijs/Model/Observer.php @@ -1,7 +1,7 @@ * https://www.luigifab.fr/openmage/apijs @@ -19,17 +19,48 @@ class Luigifab_Apijs_Model_Observer extends Luigifab_Apijs_Helper_Data { - // EVENT catalog_product_delete_commit_after (adminhtml) + // EVENT catalog_category_delete_commit_after (global) + public function removeCategoryImages(Varien_Event_Observer $observer) { + + $category = $observer->getData('category'); + if (is_object($category) && !empty($category->getId())) { + + $entityType = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Category::ENTITY)->getId(); + $attributes = Mage::getResourceModel('eav/entity_attribute_collection') + ->addFieldToFilter('frontend_input', 'image') + ->addFieldToFilter('entity_type_id', $entityType) + ->getItems(); + + foreach ($attributes as $attribute) { + $file = $category->getData($attribute->getData('attribute_code')); + if (!empty($file)) + $this->removeFiles($this->getCatalogCategoryImageDir(), $file); // pas uniquement dans le cache + } + } + } + + // EVENT catalog_product_delete_commit_after (global) public function removeProductImages(Varien_Event_Observer $observer) { $product = $observer->getData('product'); if (is_object($product) && !empty($product->getId())) { + $entityType = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY)->getId(); + $attributes = Mage::getResourceModel('eav/entity_attribute_collection') + ->addFieldToFilter('frontend_input', 'image') + ->addFieldToFilter('entity_type_id', $entityType) + ->getItems(); + + foreach ($attributes as $attribute) { + $file = basename($product->getData($attribute->getData('attribute_code'))); + if (!empty($file)) + $this->removeFiles($this->getCatalogProductImageDir(), $file); // pas uniquement dans le cache + } + foreach ($product->getMediaGallery('images') as $image) { $file = basename($image['file']); - // pas uniquement dans le cache if (!empty($file)) - $this->removeFiles(Mage::helper('apijs')->getCatalogProductImageDir(), $file); + $this->removeFiles($this->getCatalogProductImageDir(), $file); // pas uniquement dans le cache } } } @@ -120,40 +151,4 @@ public function updatePostForGallery(Varien_Event_Observer $observer) { } } } - - // EVENT catalog_category_delete_commit_after (adminhtml) - // EVENT controller_action_predispatch_adminhtml_catalog_category_save (adminhtml) - public function removeCategoryImages(Varien_Event_Observer $observer) { - - $category = $observer->getData('category'); - if (is_object($category) && !empty($category->getId())) { - - $entityType = Mage::getSingleton('eav/config')->getEntityType(Mage_Catalog_Model_Category::ENTITY)->getId(); - $attributes = Mage::getResourceModel('eav/entity_attribute_collection') - ->addFieldToFilter('frontend_input', 'image') - ->addFieldToFilter('entity_type_id', $entityType) - ->getItems(); - - foreach ($attributes as $attribute) { - $file = $category->getData($attribute->getData('attribute_code')); - // pas uniquement dans le cache - if (!empty($file)) - $this->removeFiles(Mage::helper('apijs')->getCatalogCategoryImageDir(), $file); - } - } - - $post = is_object($observer->getData('controller_action')) ? $observer->getData('controller_action')->getRequest()->getPost() : null; - if (!empty($post) && is_array($post)) { - - foreach ($post as $key => $value) { - if (is_array($value)) { - foreach ($value as $subkey => $subvalue) { - // pas uniquement dans le cache - if (is_array($subvalue) && !empty($subvalue['delete']) && !empty($subvalue['value'])) - $this->removeFiles(Mage::helper('apijs')->getCatalogCategoryImageDir(), $subvalue['value']); - } - } - } - } - } } \ No newline at end of file diff --git a/src/app/code/community/Luigifab/Apijs/Model/Python.php b/src/app/code/community/Luigifab/Apijs/Model/Python.php index c3fe610..0c039e0 100644 --- a/src/app/code/community/Luigifab/Apijs/Model/Python.php +++ b/src/app/code/community/Luigifab/Apijs/Model/Python.php @@ -1,7 +1,7 @@ * https://www.luigifab.fr/openmage/apijs @@ -37,16 +37,7 @@ public function __construct($file = null, $adapter = null) { } public function __destruct() { - - while (!empty($this->_pids)) { - foreach ($this->_pids as $key => $pid) { - if (!file_exists('/proc/'.$pid)) - unset($this->_pids[$key]); - else - clearstatcache('/proc/'.$pid); - } - sleep(0.1); - } + $this->waitThreads(); } public function getProgramVersions($helpPil, $helpSco) { @@ -129,26 +120,39 @@ public function save($destination = null, $newFilename = null) { // ne génère pas deux fois la même image if (!in_array($destination, $this->_files)) { + Mage::log($cmd, Zend_Log::DEBUG, 'apijs.log'); $this->_files[] = $destination; $this->_pids[] = exec($cmd); - Mage::log($cmd, Zend_Log::INFO, 'apijs.log'); } $this->reset(); } - catch (Throwable $e) { - Mage::logException($e); - throw $e; + catch (Throwable $t) { + Mage::logException($t); + throw $t; } return $this; } + public function waitThreads() { + + while (!empty($this->_pids)) { + foreach ($this->_pids as $key => $pid) { + if (!file_exists('/proc/'.$pid)) + unset($this->_pids[$key]); + else + clearstatcache('/proc/'.$pid); + } + sleep(0.1); + } + } + public function display() { } - // simple getter + // getter public function getOriginalWidth() { @@ -199,7 +203,7 @@ public function isSvg() { return $this->_svg; } - // simple setter + // setter public function rotate($angle) { $this->_rotateAngle = $angle; @@ -310,7 +314,7 @@ public function reset() { $this->_watermarkPositionY = null; $this->_watermarkOpacity = null; $this->_watermarkRepeat = null; - $this->_quality = null; + $this->_quality = 100; $this->_keepAspectRatio = null; $this->_keepFrame = null; $this->_keepTransparency = null; diff --git a/src/app/code/community/Luigifab/Apijs/Model/Rewrite/Categoryimg.php b/src/app/code/community/Luigifab/Apijs/Model/Rewrite/Categoryimg.php new file mode 100644 index 0000000..7417890 --- /dev/null +++ b/src/app/code/community/Luigifab/Apijs/Model/Rewrite/Categoryimg.php @@ -0,0 +1,40 @@ + + * Copyright 2019-2021 | Fabrice Creuzot + * 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_Model_Rewrite_Categoryimg extends Mage_Catalog_Model_Category_Attribute_Backend_Image { + + public function beforeSave($object) { + + $name = $this->getAttribute()->getName(); + $value = $object->getData($name); + + if (is_array($value)) { + + $help = Mage::helper('apijs'); + + if (!empty($value['delete'])) + $help->removeFiles($help->getCatalogCategoryImageDir(), $value['value']); // pas uniquement dans le cache + else if (!empty($value['value']) && !empty($_FILES[$name]['size'])) + $help->removeFiles($help->getCatalogCategoryImageDir(), $value['value'], true); // pas uniquement dans le cache + } + + return parent::beforeSave($object); + } +} \ No newline at end of file diff --git a/src/app/code/community/Luigifab/Apijs/Model/Rewrite/Productimg.php b/src/app/code/community/Luigifab/Apijs/Model/Rewrite/Productimg.php new file mode 100644 index 0000000..caf13eb --- /dev/null +++ b/src/app/code/community/Luigifab/Apijs/Model/Rewrite/Productimg.php @@ -0,0 +1,40 @@ + + * Copyright 2019-2021 | Fabrice Creuzot + * 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_Model_Rewrite_Productimg extends Mage_Catalog_Model_Resource_Product_Attribute_Backend_Image { + + public function beforeSave($object) { + + $name = $this->getAttribute()->getName(); + $value = $object->getData($name); + + if (is_array($value)) { + + $help = Mage::helper('apijs'); + + if (!empty($value['delete'])) + $help->removeFiles($help->getCatalogProductImageDir(), basename($value['value'])); // pas uniquement dans le cache + else if (!empty($value['value']) && !empty($_FILES[$name]['size'])) + $help->removeFiles($help->getCatalogProductImageDir(), basename($value['value']), true); // pas uniquement dans le cache + } + + return parent::beforeSave($object); + } +} \ No newline at end of file diff --git a/src/app/code/community/Luigifab/Apijs/Model/Rewrite/Validator.php b/src/app/code/community/Luigifab/Apijs/Model/Rewrite/Validator.php index c882c40..63b4769 100644 --- a/src/app/code/community/Luigifab/Apijs/Model/Rewrite/Validator.php +++ b/src/app/code/community/Luigifab/Apijs/Model/Rewrite/Validator.php @@ -1,7 +1,7 @@ * https://www.luigifab.fr/openmage/apijs @@ -32,8 +32,8 @@ public function validate($path) { $processor = Mage::getSingleton('apijs/python'); $processor->setFilename($path)->resize($processor->getOriginalWidth(), $processor->getOriginalHeight())->save($path); } - catch (Throwable $e) { - Mage::throwException('Invalid image: '.$e->getMessage()); + catch (Throwable $t) { + Mage::throwException('Invalid image: '.$t->getMessage()); } return true; diff --git a/src/app/code/community/Luigifab/Apijs/Model/Useragentparser.php b/src/app/code/community/Luigifab/Apijs/Model/Useragentparser.php index 6070d2d..d5749a0 100644 --- a/src/app/code/community/Luigifab/Apijs/Model/Useragentparser.php +++ b/src/app/code/community/Luigifab/Apijs/Model/Useragentparser.php @@ -4,7 +4,7 @@ * https://github.com/donatj/PhpUserAgent * * Copyright 2019-2021 | Fabrice Creuzot (luigifab) - * https://gist.github.com/luigifab/4cb373e75f3cd2f342ca6bc25504b149 (1.3.0-fork1) + * https://gist.github.com/luigifab/4cb373e75f3cd2f342ca6bc25504b149 (1.4.0-fork1) * * Parses a user agent string into its important parts * Licensed under the MIT License @@ -49,7 +49,7 @@ public function parse($userAgent = null) { preg_match_all( // ["browser" => ["Firefox"...], "version" => ["45.0"...]] - '/(?PCamino|Kindle(\ Fire)?|Firefox|Iceweasel|IceCat|Safari|MSIE|Trident|AppleWebKit|TizenBrowser|(?:Headless)?Chrome|YaBrowser|Vivaldi|IEMobile|Opera|OPR|Silk|Midori|Edge|Edg|CriOS|UCBrowser|Puffin|OculusBrowser|SamsungBrowser|SailfishBrowser|XiaoMi\/MiuiBrowser|Baiduspider|Applebot|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl|Valve\ Steam\ Tenfoot|NintendoBrowser|PLAYSTATION\ (\d|Vita)+) (?:\)?;?) (?:(?:[:\/ ])(?P[0-9A-Z.]+)|\/(?:[A-Z]*))/ix', + '/(?PCamino|Kindle(\ Fire)?|Firefox|Iceweasel|IceCat|Safari|MSIE|Trident|AppleWebKit|TizenBrowser|(?:Headless)?Chrome|YaBrowser|Vivaldi|IEMobile|Opera|OPR|Silk|Midori|Edge|Edg|CriOS|UCBrowser|Puffin|OculusBrowser|SamsungBrowser|SailfishBrowser|XiaoMi\/MiuiBrowser|Baiduspider|Applebot|Facebot|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl|Valve\ Steam\ Tenfoot|NintendoBrowser|PLAYSTATION\ (\d|Vita)+) (?:\)?;?) (?:(?:[:\/ ])(?P[0-9A-Z.]+)|\/(?:[A-Z]*))/ix', $userAgent, $result); @@ -79,8 +79,8 @@ public function parse($userAgent = null) { $key = 0; $val = ''; - if ($this->findT($lowerBrowser, ['OPR' => 'Opera', 'UCBrowser' => 'UC Browser', 'YaBrowser' => 'Yandex', 'Iceweasel' => 'Firefox', 'Icecat' => 'Firefox', 'CriOS' => 'Chrome', 'Edg' => 'Edge', 'XiaoMi/MiuiBrowser' => 'MiuiBrowser'], $key, $browser)) { - $version = $result['version'][$key]; + if ($this->findT($lowerBrowser, ['OPR' => 'Opera', 'Facebot' => 'iMessageBot', 'UCBrowser' => 'UC Browser', 'YaBrowser' => 'Yandex', 'Iceweasel' => 'Firefox', 'Icecat' => 'Firefox', 'CriOS' => 'Chrome', 'Edg' => 'Edge', 'XiaoMi/MiuiBrowser' => 'MiuiBrowser'], $key, $browser)) { + $version = is_numeric(substr($result['version'][$key], 0, 1)) ? $result['version'][$key] : null; } else if ($this->find($lowerBrowser, 'Playstation Vita', $key, $platform)) { $platform = 'PlayStation Vita'; diff --git a/src/app/code/community/Luigifab/Apijs/controllers/Apijs/CacheController.php b/src/app/code/community/Luigifab/Apijs/controllers/Apijs/CacheController.php index b75b54a..242547e 100644 --- a/src/app/code/community/Luigifab/Apijs/controllers/Apijs/CacheController.php +++ b/src/app/code/community/Luigifab/Apijs/controllers/Apijs/CacheController.php @@ -1,7 +1,7 @@ * Copyright 2019-2021 | Fabrice Creuzot @@ -72,11 +72,11 @@ public function clearCacheAction() { $this->_getSession()->addSuccess($this->__('The image cache was cleaned.')); } } - catch (Throwable $e) { - $this->_getSession()->addError($e->getMessage()); + catch (Throwable $t) { + $this->_getSession()->addError($t->getMessage()); } - // très important car les chemins et les urls sont aussi mis en cache + // très important car les chemins et les URLs sont aussi mis en cache Mage::app()->getCacheInstance()->cleanType('block_html'); $this->_redirect('*/system_config/edit', ['section' => 'apijs']); diff --git a/src/app/code/community/Luigifab/Apijs/controllers/Apijs/MediaController.php b/src/app/code/community/Luigifab/Apijs/controllers/Apijs/MediaController.php index a514c3e..d8c96a8 100644 --- a/src/app/code/community/Luigifab/Apijs/controllers/Apijs/MediaController.php +++ b/src/app/code/community/Luigifab/Apijs/controllers/Apijs/MediaController.php @@ -1,7 +1,7 @@ * Copyright 2019-2021 | Fabrice Creuzot @@ -38,7 +38,7 @@ private function disableAllBuffer() { for ($i = 0; $i < ob_get_level(); $i++) ob_end_clean(); } - catch (Throwable $e) { } + catch (Throwable $t) { } echo ' '; } @@ -99,16 +99,16 @@ public function uploadWidgetAction() { $success[] = $filepath; } - catch (Throwable $e) { - $errors[] = $e->getMessage(); + catch (Throwable $t) { + $errors[] = $t->getMessage(); } } // retour $result = $this->formatResult($success, $errors, 'ok'); } - catch (Throwable $e) { - $result = $e->getMessage(); + catch (Throwable $t) { + $result = $t->getMessage(); } sleep(1); @@ -203,8 +203,8 @@ public function uploadProductAction() { $success[] = $filepath; } - catch (Throwable $e) { - $errors[] = $e->getMessage(); + catch (Throwable $t) { + $errors[] = $t->getMessage(); } } @@ -228,13 +228,13 @@ public function uploadProductAction() { // reload $product->setStoreId($storeId)->load($product->getId()); - // très important car les chemins et les urls sont aussi mis en cache + // très important car les chemins et les URLs sont aussi mis en cache Mage::app()->getCacheInstance()->cleanType('block_html'); // html $result = $this->formatResult($success, $errors, $help->renderGalleryBlock($product)); } - catch (Throwable $e) { - $result = $e->getMessage(); + catch (Throwable $t) { + $result = $t->getMessage(); } sleep(1); @@ -270,13 +270,13 @@ public function saveAction() { // reload $product->setStoreId($storeId)->load($product->getId()); - // très important car les chemins et les urls sont aussi mis en cache + // très important car les chemins et les URLs sont aussi mis en cache Mage::app()->getCacheInstance()->cleanType('block_html'); // html $result = $this->formatResult(null, null, Mage::helper('apijs')->renderGalleryBlock($product)); } - catch (Throwable $e) { - $result = $e->getMessage(); + catch (Throwable $t) { + $result = $t->getMessage(); } $this->getResponse()->setBody($result); @@ -358,13 +358,13 @@ public function removeAction() { // reload $product->setStoreId($storeId)->load($product->getId()); - // très important car les chemins et les urls sont aussi mis en cache + // très important car les chemins et les URLs sont aussi mis en cache Mage::app()->getCacheInstance()->cleanType('block_html'); // html $result = $this->formatResult(null, null, $help->renderGalleryBlock($product)); } - catch (Throwable $e) { - $result = $e->getMessage(); + catch (Throwable $t) { + $result = $t->getMessage(); } $this->getResponse()->setBody($result); diff --git a/src/app/code/community/Luigifab/Apijs/controllers/Apijs/WysiwygController.php b/src/app/code/community/Luigifab/Apijs/controllers/Apijs/WysiwygController.php index 7b29e63..2da7aed 100644 --- a/src/app/code/community/Luigifab/Apijs/controllers/Apijs/WysiwygController.php +++ b/src/app/code/community/Luigifab/Apijs/controllers/Apijs/WysiwygController.php @@ -1,7 +1,7 @@ * Copyright 2019-2021 | Fabrice Creuzot @@ -50,11 +50,12 @@ public function indexAction() { public function deleteFolderAction() { $files = $this->getStorage()->getFilesCollection($dir = $this->getStorage()->getSession()->getCurrentPath()); - $path = 'wysiwyg/'.str_replace([Mage::helper('apijs')->getWysiwygImageDir(), Mage::getBaseDir('media').'/', '//'], ['', '', '/'], $dir); + $help = Mage::helper('apijs'); + $path = 'wysiwyg/'.str_replace([$help->getWysiwygImageDir(), Mage::getBaseDir('media').'/', '//'], ['', '', '/'], $dir); foreach ($files as $file) { $oldfile = trim($path, '/').'/'.$file->getName(); - Mage::helper('apijs')->removeFiles(Mage::helper('apijs')->getWysiwygImageDir(true), $oldfile); + $help->removeFiles($help->getWysiwygImageDir(true), $oldfile); } parent::deleteFolderAction(); @@ -62,7 +63,7 @@ public function deleteFolderAction() { if (is_dir($dir)) unlink($dir); - // très important car les chemins et les urls sont aussi mis en cache + // très important car les chemins et les URLs sont aussi mis en cache Mage::app()->getCacheInstance()->cleanType('block_html'); } @@ -73,15 +74,16 @@ public function deleteFilesAction() { if (!empty($files = $this->getRequest()->getParam('files'))) { $files = Mage::helper('core')->jsonDecode($files); - $path = 'wysiwyg/'.str_replace([Mage::helper('apijs')->getWysiwygImageDir(), Mage::getBaseDir('media').'/', '//'], ['', '', '/'], $this->getStorage()->getSession()->getCurrentPath()); + $help = Mage::helper('apijs'); + $path = 'wysiwyg/'.str_replace([$help->getWysiwygImageDir(), Mage::getBaseDir('media').'/', '//'], ['', '', '/'], $this->getStorage()->getSession()->getCurrentPath()); foreach ($files as $file) { $oldfile = trim($path, '/').'/'.Mage::helper('cms/wysiwyg_images')->idDecode($file); - Mage::helper('apijs')->removeFiles(Mage::helper('apijs')->getWysiwygImageDir(true), $oldfile); + $help->removeFiles($help->getWysiwygImageDir(true), $oldfile); } } - // très important car les chemins et les urls sont aussi mis en cache + // très important car les chemins et les URLs sont aussi mis en cache Mage::app()->getCacheInstance()->cleanType('block_html'); } @@ -142,15 +144,16 @@ public function renameFileAction() { // images en cache $path = 'wysiwyg/'.str_replace([$help->getWysiwygImageDir(), Mage::getBaseDir('media').'/', '//'], ['', '', '/'], $this->getStorage()->getSession()->getCurrentPath()); + $oldfile = trim($path, '/').'/'.Mage::helper('cms/wysiwyg_images')->idDecode($file); $help->removeFiles($help->getWysiwygImageDir(true), $oldfile); - // très important car les chemins et les urls sont aussi mis en cache + // très important car les chemins et les URLs sont aussi mis en cache Mage::app()->getCacheInstance()->cleanType('block_html'); } } - catch (Throwable $e) { - $result = ['error' => true, 'message' => $e->getMessage()]; + catch (Throwable $t) { + $result = ['error' => true, 'message' => $t->getMessage()]; $this->getResponse()->setBody(json_encode($result)); } } diff --git a/src/app/code/community/Luigifab/Apijs/etc/config.xml b/src/app/code/community/Luigifab/Apijs/etc/config.xml index c3fefd6..06af5bb 100644 --- a/src/app/code/community/Luigifab/Apijs/etc/config.xml +++ b/src/app/code/community/Luigifab/Apijs/etc/config.xml @@ -1,7 +1,7 @@