Skip to content

Commit

Permalink
Version 6.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Jan 1, 2023
1 parent d0d8949 commit 2cd838f
Show file tree
Hide file tree
Showing 66 changed files with 296 additions and 196 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ For more information, go to https://www.luigifab.fr/apijs and https://www.luigif

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

- Current version: 6.9.2 (10/10/2022)
- Compatibility: OpenMage 19.x / 20.x / 21.x, PHP 7.2 / 7.3 / 7.4 / 8.0 / 8.1, Python 3.3+
- Current version: 6.9.3 (01/01/2023)
- Compatibility: OpenMage 19.x / 20.x / 21.x, PHP 7.2 / 7.3 / 7.4 / 8.0 / 8.1 / 8.2, Python 3.3+
- 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) / Chinese (zh), Czech (cs), Dutch (nl), Greek (el), Hungarian (hu), Japanese (ja), Polish (pl), Romanian (ro), Russian (ru), Slovak (sk), Turkish (tr), Ukrainian (uk)
- License: GNU GPL 2+
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@
["src/skin/frontend/base/default/js/luigifab/apijs/", "skin/frontend/base/default/js/luigifab/apijs/"]
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created V/23/05/2014
* Updated V/20/05/2022
*
* Copyright 2008-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/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
Expand Down Expand Up @@ -47,6 +47,7 @@ protected function checkRewrites() {
['model' => 'catalog_resource/product_attribute_backend_media'],
['model' => 'cms/wysiwyg_images_storage'],
['model' => 'core/file_validator_image'],
['model' => 'varien/image'],
];

foreach ($rewrites as $rewrite) {
Expand Down
10 changes: 6 additions & 4 deletions src/app/code/community/Luigifab/Apijs/Block/Adminhtml/Demo.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* Created D/20/11/2011
* Updated M/28/02/2017
* Updated S/03/12/2022
*
* Copyright 2008-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/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
Expand All @@ -22,6 +22,8 @@ class Luigifab_Apijs_Block_Adminhtml_Demo extends Mage_Adminhtml_Block_Abstract
protected $_template = 'luigifab/apijs/demo.phtml';

public function render(Varien_Data_Form_Element_Abstract $element) {
return '<tr><td colspan="4">'.$this->toHtml().'</td></tr>';
// getPath PR 2774
$isDefault = !$element->getCanUseWebsiteValue() && !$element->getCanUseDefaultValue();
return '<tr><td colspan="'.(empty($element->getPath()) ? ($isDefault ? 4 : 5) : ($isDefault ? 5 : 6)).'">'.$this->toHtml().'</td></tr>';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created M/06/10/2020
* Updated M/06/10/2020
*
* Copyright 2008-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created L/30/03/2020
* Updated J/23/12/2021
*
* Copyright 2008-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created L/26/10/2015
* Updated J/23/12/2021
*
* Copyright 2008-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* Created S/04/10/2014
* Updated J/11/08/2022
* Updated D/11/12/2022
*
* Copyright 2008-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/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
Expand All @@ -23,13 +23,23 @@ protected function _construct() {
$this->setModuleName('Mage_Adminhtml');
}

public function __construct() {
public function setTemplate($template) {

parent::__construct();
$product = Mage::registry('current_product');

if (!empty($product) && !empty($product->getId()) && Mage::getStoreConfigFlag('apijs/general/backend'))
$this->setTemplate('luigifab/apijs/gallery.phtml'); // catalog/product/helper/gallery.phtml
$template = 'luigifab/apijs/gallery.phtml'; // catalog/product/helper/gallery.phtml

return parent::setTemplate($template);
}

public function getScopeLabel(object $attribute) {

if ($attribute->isScopeGlobal())
return $this->__('[GLOBAL]');
if ($attribute->isScopeWebsite())
return $this->__('[WEBSITE]');

return $this->__('[STORE VIEW]');
}

public function getImages(bool $sortByStore) {
Expand Down Expand Up @@ -93,7 +103,7 @@ public function getImages(bool $sortByStore) {
}
}

$storeValues[$code] = $product->getResource()->getAttributeRawValue($productId, $code, $storeId);
$storeValues[$code] = $product->getResource()->getAttributeRawValue($productId, $code, $storeId);
}
}

Expand All @@ -106,17 +116,13 @@ public function getImages(bool $sortByStore) {
}
}

return ['images' => $images, 'counts' => $counts, 'defaultValues' => $defaultValues, 'storeValues' => $storeValues, 'globalValues' => $globalValues];
}

public function getScopeLabel(object $attribute) {

if ($attribute->isScopeGlobal())
return $this->__('[GLOBAL]');
if ($attribute->isScopeWebsite())
return $this->__('[WEBSITE]');

return $this->__('[STORE VIEW]');
return [
'images' => $images,
'counts' => $counts,
'defaultValues' => $defaultValues,
'storeValues' => $storeValues,
'globalValues' => $globalValues,
];
}

public function isUseGlobal(object $image, string $field, string $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created J/27/05/2021
* Updated J/23/12/2021
*
* Copyright 2008-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/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
Expand Down
4 changes: 2 additions & 2 deletions src/app/code/community/Luigifab/Apijs/Block/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created V/11/10/2019
* Updated V/11/10/2019
*
* Copyright 2008-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/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
Expand Down
12 changes: 8 additions & 4 deletions src/app/code/community/Luigifab/Apijs/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* Created D/20/11/2011
* Updated L/03/10/2022
* Updated V/09/12/2022
*
* Copyright 2008-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/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
Expand All @@ -19,7 +19,11 @@

class Luigifab_Apijs_Helper_Data extends Mage_Core_Helper_Abstract {

// singleton
protected $_usePython;
protected $_baseMediaPath;
protected $_baseWysiwygPath;
protected $_filesToRemove;


public function getVersion() {
Expand Down Expand Up @@ -114,7 +118,7 @@ public function getUsername() {
$user = $action->getFullActionName();
// frontend
else
$user = sprintf('frontend %d', Mage::app()->getStore()->getData('code'));
$user = sprintf('frontend %s', Mage::app()->getStore()->getData('code'));

return $user;
}
Expand Down
55 changes: 36 additions & 19 deletions src/app/code/community/Luigifab/Apijs/Helper/Rewrite/Image.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
/**
* Created J/12/09/2019
* Updated L/03/10/2022
* Updated V/23/12/2022
*
* Copyright 2008-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2019-2022 | Fabrice Creuzot <fabrice~cellublue~com>
* https://www.luigifab.fr/openmage/apijs
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2019-2023 | Fabrice Creuzot <fabrice~cellublue~com>
* https://github.com/luigifab/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
Expand All @@ -20,15 +20,26 @@

class Luigifab_Apijs_Helper_Rewrite_Image extends Mage_Catalog_Helper_Image {

// singleton
protected $_usePython;
protected $_cacheConfig;
protected $_cacheUrls;
protected $_webp;
protected $_processor;
protected $_helper;
protected $_modelImg;
protected $_cleanUrl;
protected $_storeId;
protected $_svg;
protected $_fixed;
protected $_imageFile;


public function __construct() {
$this->_usePython = Mage::getStoreConfigFlag('apijs/general/python');
}

public function init($product, $attribute, $path = null, $fixed = true, $webp = false) {
public function init($object, $attribute, $path = null, $fixed = true, $webp = false) {

$this->_reset();
$this->_webp = $webp;
Expand Down Expand Up @@ -63,9 +74,16 @@ public function init($product, $attribute, $path = null, $fixed = true, $webp =
$path = '../../'.$dir.'/'.mb_substr($path, mb_stripos($path, '/'.$dir.'/') + mb_strlen('/'.$dir.'/'));
}
else if ($attribute == 'category') {
if (empty($path) && !empty($object->getId()))
$path = $object->getResource()->getAttributeRawValue($object->getId(), $attribute, $object->getStoreId());
// xyz.jpg => ../category/xyz.jpg
$path = '../category/'.$path;
}
else if (empty($path)) {
$path = $object->getData($attribute);
if (empty($path) && !empty($object->getId()))
$path = $object->getResource()->getAttributeRawValue($object->getId(), $attribute, $object->getStoreId());
}

$model = clone $this->_modelImg;
$model->setDestinationSubdir($attribute);
Expand All @@ -81,7 +99,7 @@ public function init($product, $attribute, $path = null, $fixed = true, $webp =
if (empty($this->_cacheConfig) || !is_array($this->_cacheConfig)) {

$this->_cacheConfig = [
'date' => date('Y-m-d H:i:s \U\T\C'),
'date' => date('c'),
'apijs/general/python' => $this->_usePython,
'apijs/general/remove_store_id' => Mage::getStoreConfigFlag('apijs/general/remove_store_id'),
'list_search' => [],
Expand All @@ -91,23 +109,23 @@ public function init($product, $attribute, $path = null, $fixed = true, $webp =
if (Mage::getStoreConfigFlag('apijs/general/use_link')) {

$dir = Mage::getBaseDir('media');
$all = ['wysiwyg/cache', 'catalog/category/cache'];
$tmp = ['wysiwyg/cache', 'catalog/category/cache'];

$attrs = Mage::getModel('catalog/product')->getMediaAttributes();
if ($this->_cacheConfig['apijs/general/remove_store_id']) {
foreach ($attrs as $attrCode => $attr)
$all[] = 'catalog/product/cache/'.$attrCode;
$tmp[] = 'catalog/product/cache/'.$attrCode;
}
else {
$storeIds = Mage::getResourceModel('core/store_collection')->getAllIds();
foreach ($attrs as $attrCode => $attr) {
$all[] = 'catalog/product/cache/'.$attrCode;
$tmp[] = 'catalog/product/cache/'.$attrCode;
foreach ($storeIds as $storeId)
$all[] = 'catalog/product/cache/'.$storeId.'/'.$attrCode;
$tmp[] = 'catalog/product/cache/'.$storeId.'/'.$attrCode;
}
}

foreach ($all as $full) {
foreach ($tmp as $full) {

$short = '';
$key = crc32($full);
Expand All @@ -119,7 +137,9 @@ public function init($product, $attribute, $path = null, $fixed = true, $webp =
while (in_array('/media/'.$short.'/', $this->_cacheConfig['list_replace']))
$short .= substr($word.$key, ++$idx, 1);

if (!file_exists($dir.'/'.$short))
// $dir $short => /var/www/xyz/web/media wc
// $dir $full => /var/www/xyz/web/media wysiwyg/cache
if (!file_exists($dir.'/'.$full))
@mkdir($dir.'/'.$full, 0755, true);
if (!file_exists($dir.'/'.$short))
@symlink($full, $dir.'/'.$short);
Expand All @@ -133,7 +153,7 @@ public function init($product, $attribute, $path = null, $fixed = true, $webp =
$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'),
'date' => date('c'),
];
}
}
Expand All @@ -152,9 +172,6 @@ public function init($product, $attribute, $path = null, $fixed = true, $webp =
$this->setWatermarkSize($this->_cacheConfig['design/watermark/'.$attribute.'_size']);
}

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

$this->_svg = !empty($path) && (mb_substr($path, -4) == '.svg');
$this->_fixed = $fixed;
$this->_imageFile = $path;
Expand Down Expand Up @@ -208,7 +225,7 @@ public function setBaseFile() {

//$go = microtime(true);
$model = $this->_getModel();
$file = $this->_helper->getCatalogProductImageDir().trim($this->_imageFile, '/');
$file = $this->_imageFile ? $this->_helper->getCatalogProductImageDir().trim($this->_imageFile, '/') : false;

if ($this->_cacheConfig['apijs/general/python']) {
$this->_processor->setFilename($file)->setFixed($this->_fixed);
Expand All @@ -219,7 +236,7 @@ public function setBaseFile() {
// essaye le fichier source ou le placeholder
// setWatermarkFile pour avoir une url unique
// par exemple, en cas de suppression de l'image a.jpg, puis de l'ajout de l'image a.jpg, même nom mais contenu différent
if (is_file($file)) {
if (!empty($file) && is_file($file)) {
$old = $model->getWatermarkFile();
$model->setWatermarkFile($old.filemtime($file));
$model->setBaseFile($this->_imageFile);
Expand Down Expand Up @@ -255,7 +272,7 @@ public function setBaseFile() {

public function cleanUrl(string $url) {

$url = $this->_cleanUrl ? mb_substr($url, strpos($url, '/', 9)) : $url;
$url = $this->_cleanUrl ? mb_substr($url, mb_strpos($url, '/', 9)) : $url;

if ($this->_cacheConfig['apijs/general/remove_store_id'])
$url = str_replace('/cache/'.$this->_storeId.'/', '/cache/', $url);
Expand Down
4 changes: 2 additions & 2 deletions src/app/code/community/Luigifab/Apijs/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created S/13/06/2015
* Updated D/18/09/2022
*
* Copyright 2008-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/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
Expand Down
Loading

0 comments on commit 2cd838f

Please sign in to comment.