Skip to content

Commit

Permalink
Version 6.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Oct 10, 2023
1 parent d214b7f commit 1929941
Show file tree
Hide file tree
Showing 31 changed files with 101 additions and 89 deletions.
1 change: 0 additions & 1 deletion FUNDING.yml

This file was deleted.

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.4 (06/06/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+
- Current version: 6.9.5 (10/10/2023)
- Compatibility: OpenMage 19.x / 20.x / 21.x, PHP 7.2 / 7.3 / 7.4 / 8.0 / 8.1 / 8.2 / 8.3, 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
14 changes: 0 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,6 @@
"issues": "https://github.com/luigifab/openmage-apijs/issues",
"docs": "https://www.luigifab.fr/openmage/apijs"
},
"funding": [
{
"type": "other",
"url": "https://gandi.link/f/4b904048"
},
{
"type": "other",
"url": "https://fr.tipeee.com/luigifab"
},
{
"type": "other",
"url": "https://ekwateur.fr/?parrain=EKW001147103"
}
],
"require": {
"php": ">=7.2.0",
"openmage/magento-lts": ">=19.4.0 || main-dev || next-dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/12/09/2019
* Updated V/14/04/2023
* Updated J/21/09/2023
*
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2019-2023 | Fabrice Creuzot <fabrice~cellublue~com>
Expand Down Expand Up @@ -133,9 +133,9 @@ public function init($object, $attribute, $path = null, $fixed = true, $webp = f

// ajoute l'id pour éviter une boucle infini
foreach (explode('/', $full) as $word)
$short .= substr($word, 0, $idx);
$short .= substr($word, 0, $idx); // not mb_substr
while (in_array('/media/'.$short.'/', $this->_cacheConfig['list_replace']))
$short .= substr($word.$key, ++$idx, 1);
$short .= substr($word.$key, ++$idx, 1); // not mb_substr

// $dir $short => /var/www/xyz/web/media wc
// $dir $full => /var/www/xyz/web/media wysiwyg/cache
Expand Down
14 changes: 9 additions & 5 deletions src/app/code/community/Luigifab/Apijs/Model/Observer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created S/13/06/2015
* Updated V/19/05/2023
* Updated S/07/10/2023
*
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-apijs
Expand Down Expand Up @@ -86,9 +86,10 @@ public function removeProductImages(Varien_Event_Observer $observer) {
// EVENT controller_action_predispatch_adminhtml_catalog_product_save (adminhtml)
public function updatePostForGallery(Varien_Event_Observer $observer) {

$post = $observer->getData('controller_action')->getRequest()->getPost();
$productId = $observer->getData('controller_action')->getRequest()->getParam('id', 0);
$storeId = $observer->getData('controller_action')->getRequest()->getParam('store', 0);
$request = $observer->getData('controller_action')->getRequest();
$post = $request->getPost();
$productId = $request->getParam('id', 0);
$storeId = $request->getParam('store', 0);

if (!empty($post['apijs'])) {

Expand All @@ -97,7 +98,7 @@ public function updatePostForGallery(Varien_Event_Observer $observer) {
$fields = $product->getResource()->getAttribute('media_gallery')->getBackend()->getAllColumns();
$gallery = [];

// simule ce que fait le js du core, quel bordel
// fait ce que fait le js du core, quel bordel
foreach ($post['apijs'] as $imageId => $image) {

if (!is_array($image) || !array_key_exists('file', $image)) {
Expand Down Expand Up @@ -136,10 +137,13 @@ public function updatePostForGallery(Varien_Event_Observer $observer) {
if (!empty($value) && ($field['Field'] == 'label')) {
$values[$field['Field']] = stripslashes($value);
$values[$field['Field'].'_default'] = stripslashes($value);
$values[$field['Field'].'_use_default'] = ($value == null); // PR 2481 // null when $$ when checked
}
else {
$values[$field['Field']] = $value;
$values[$field['Field'].'_default'] = $value;
if ($field['Field'] == 'position')
$values[$field['Field'].'_use_default'] = ($value == null); // null when $$ when checked
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/app/code/community/Luigifab/Apijs/Model/Python.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created S/09/05/2020
* Updated J/09/03/2023
* Updated J/05/10/2023
*
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-apijs
Expand Down Expand Up @@ -128,8 +128,14 @@ public function save($destination = null, $newFilename = null, $immediate = fals

try {
$this->initCommands();
$core = max(1, $this->_core - 2);
while (count($this->_pids) >= $core) {

// leaves 2 cores free, but because $runs include grep check, we add 2 for $maxc
// [] => 18:14 0:00 /usr/bin/python3 ...
// [] => 18:14 0:00 sh -c ps aux | grep Apijs/lib/image.py
// [] => 18:14 0:00 grep Apijs/lib/image.py
$maxc = 2 + max(1, $this->_core - 2);

while (count($this->_pids) >= $maxc) {
foreach ($this->_pids as $key => $pid) {
if (file_exists('/proc/'.$pid))
clearstatcache('/proc/'.$pid);
Expand All @@ -140,8 +146,7 @@ public function save($destination = null, $newFilename = null, $immediate = fals
}

exec('ps aux | grep Apijs/lib/image.py', $runs);
$core = ceil($core * 1.5);
while (count($runs) >= $core) {
while (count($runs) >= $maxc) {
usleep(90000); // 0.09 s
$runs = [];
exec('ps aux | grep Apijs/lib/image.py', $runs);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/27/05/2021
* Updated V/19/05/2023
* Updated J/21/09/2023
*
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2019-2023 | Fabrice Creuzot <fabrice~cellublue~com>
Expand All @@ -20,7 +20,7 @@

class Luigifab_Apijs_Model_Rewrite_Categoryimg extends Mage_Catalog_Model_Category_Attribute_Backend_Image {

public function getAllowedExtensions() {
public function getAllowedExtensions():array {
// PR 3301
return Mage::getSingleton('cms/wysiwyg_images_storage')->getAllowedExtensions('image');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/27/05/2021
* Updated V/19/05/2023
* Updated J/21/09/2023
*
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2019-2023 | Fabrice Creuzot <fabrice~cellublue~com>
Expand All @@ -20,7 +20,7 @@

class Luigifab_Apijs_Model_Rewrite_Productimg extends Mage_Catalog_Model_Resource_Product_Attribute_Backend_Image {

public function getAllowedExtensions() {
public function getAllowedExtensions():array {
// PR 3301
return Mage::getSingleton('cms/wysiwyg_images_storage')->getAllowedExtensions('image');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created M/10/09/2019
* Updated V/19/05/2023
* Updated J/21/09/2023
*
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2019-2023 | Fabrice Creuzot <fabrice~cellublue~com>
Expand Down Expand Up @@ -59,7 +59,7 @@ public function deleteFolderAction() {
$cache = trim('wysiwyg/'.str_replace([$base, Mage::getBaseDir('media').'/', '//'], ['', '', '/'], $path), '/');

// s'assure que le dossier à supprimer est bien dans le dossier media/wysiwyg
if (!empty($path) && (stripos($path, $base) === 0) && (trim($path, '/') != trim($base, '/'))) {
if (!empty($path) && (mb_stripos($path, $base) === 0) && (trim($path, '/') != trim($base, '/'))) {

// supprime les images en cache
foreach ($files as $file) {
Expand Down Expand Up @@ -94,7 +94,7 @@ public function deleteFilesAction() {
$cache = trim('wysiwyg/'.str_replace([$base, Mage::getBaseDir('media').'/', '//'], ['', '', '/'], $path), '/');

// s'assure que les fichiers à supprimer sont bien dans le dossier media/wysiwyg
if (!empty($path) && (stripos($path, $base) === 0)) {
if (!empty($path) && (mb_stripos($path, $base) === 0)) {

foreach ($files as $file) {

Expand Down
4 changes: 2 additions & 2 deletions src/app/code/community/Luigifab/Apijs/etc/config.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
* Created S/19/11/2011
* Updated L/24/04/2023
* Updated J/21/09/2023
*
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-apijs
Expand All @@ -20,7 +20,7 @@
<config>
<modules>
<Luigifab_Apijs>
<version>6.9.4</version>
<version>6.9.5</version>
</Luigifab_Apijs>
</modules>
<global>
Expand Down
42 changes: 25 additions & 17 deletions src/app/code/community/Luigifab/Apijs/lib/image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python3
# -*- coding: utf8 -*-
# Created J/26/12/2013
# Updated M/23/05/2023
# Updated J/05/10/2023
#
# Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
# Copyright 2020-2023 | Fabrice Creuzot <fabrice~cellublue~com>
Expand All @@ -26,11 +26,11 @@
quality = int(sys.argv[5]) if len(sys.argv) >= 6 else 0
fixed = len(sys.argv) >= 7 and sys.argv[6] == 'fixed'
except:
print("Usage: image.py source_file destination_file width_px height_px [quality=0:auto..100 or 0:auto..9 for png] [fixed]")
print("source: all supported format by python-pil (including animated gif/png/webp),")
print(" or all supported format by ffmpegthumbnailer,")
print(" or svg")
print("destination: jpg,gif,png,webp or svg")
print('Usage: image.py source_file destination_file width_px height_px [quality=0:auto..100 or 0:auto..9 for png] [fixed]')
print('source: all supported format by python-pil (including animated gif/png/webp),')
print(' or all supported format by ffmpegthumbnailer,')
print(' or svg')
print('destination: jpg,gif,png,webp or svg')
exit(-1)

# https://stackoverflow.com/a/273227/2980105
Expand Down Expand Up @@ -254,14 +254,14 @@ def saveJpg(dest, fileout, quality):
#try:
# import pyguetzli
# filefinal = pyguetzli.process_pil_image(dest.convert('RGB'), quality)
# output = open(fileout, "wb")
# output = open(fileout, 'wb')
# output.write(filefinal)
#except ImportError:
dest.convert('RGB').save(fileout, 'JPEG', optimize=True, subsampling=0, quality=quality)


# python-scour
if ".svg" in fileout:
if '.svg' in fileout:
from scour.scour import sanitizeOptions, start
options = sanitizeOptions()
options.strip_xml_prolog = True # --strip-xml-prolog
Expand All @@ -274,7 +274,7 @@ def saveJpg(dest, fileout, quality):
else:
from PIL import Image, ImageSequence

if ".ogv" in filein or ".webm" in filein or ".mp4" in filein:
if '.ogv' in filein or '.webm' in filein or '.mp4' in filein:
# from video
source = videoToImage(filein, fileout, size)
imgext = 'VIDEO'
Expand All @@ -285,19 +285,27 @@ def saveJpg(dest, fileout, quality):
size = calcSize(source, size)

# filein = fileout = /tmp/phpA5kbkc when replace tmp image with re-sampled copy to exclude images with malicious data
if imgext == 'GIF' and (same or ".gif" in fileout):
# @todo for animated GIF to animated GIF (or PNG), sadly, result file is not optimized, the idea is to reprocess the file to not replace each frames by another one
# for my test image, https://github.com/kohler/gifsicle, don't do it, but https://kraken.io/web-interface do it
if imgext == 'GIF' and (same or '.gif' in fileout):
dest = resizeAnimatedGif(source, size, fixed)
saveGif(dest, fileout, quality)
elif imgext == 'GIF' and (same or ".webp" in fileout):
elif imgext == 'GIF' and ( '.png' in fileout): # @todo
dest = resizeAnimatedGif(source, size, fixed)
savePng(dest, fileout, quality)
elif imgext == 'GIF' and ( '.webp' in fileout):
dest = resizeAnimatedGif(source, size, fixed)
saveWebp(dest, fileout, quality)
elif imgext == 'PNG' and (same or ".png" in fileout):
elif imgext == 'PNG' and (same or '.png' in fileout):
dest = resizeAnimatedPng(source, size, fixed)
savePng(dest, fileout, quality)
elif imgext == 'PNG' and (same or ".webp" in fileout):
elif imgext == 'PNG' and ( '.gif' in fileout):
dest = resizeAnimatedPng(source, size, fixed)
saveGif(dest, fileout, quality)
elif imgext == 'PNG' and ( '.webp' in fileout):
dest = resizeAnimatedPng(source, size, fixed)
saveWebp(dest, fileout, quality)
elif imgext == 'WEBP' and (same or ".webp" in fileout):
elif imgext == 'WEBP' and (same or '.webp' in fileout):
dest = resizeAnimatedWebp(source, size, fixed)
saveWebp(dest, fileout, quality)
else:
Expand Down Expand Up @@ -340,11 +348,11 @@ def saveJpg(dest, fileout, quality):
if hasTransparency(source) is False:
dest = dest.convert('RGB')

if ".gif" in fileout or (same and imgext == 'GIF'):
if '.gif' in fileout or (same and imgext == 'GIF'):
saveGif(dest, fileout, quality)
elif ".png" in fileout or (same and imgext == 'PNG'):
elif '.png' in fileout or (same and imgext == 'PNG'):
savePng(dest, fileout, quality)
elif ".webp" in fileout or (same and imgext == 'WEBP'):
elif '.webp' in fileout or (same and imgext == 'WEBP'):
saveWebp(dest, fileout, quality)
else:
saveJpg(dest, fileout, quality)
Expand Down
20 changes: 15 additions & 5 deletions src/shell/apijs-clean-images.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Forked from https://gist.github.com/peterjaap/5547654
* Updated J/25/05/2023
* Updated J/21/09/2023
*
* fdupes is required
*
Expand Down Expand Up @@ -81,10 +81,15 @@
echo '=== clean up duplicates images ===',"\n";

$output = exec('find '.$directory.' -type d -exec fdupes -n {} \;');
$before = substr(exec('find '.$directory.' -type f | wc -l'), 0, -1);
$before = substr(exec('find '.$directory.' -type f | wc -l'), 0, -1); // not mb_substr

// count files for difference calculation
$total = exec('du -h '.$directory); $total = explode("\n",$total); array_pop($total); $total = array_pop($total); $total = explode("\t",$total); $total = (int) array_shift($total);
$total = exec('du -h '.$directory);
$total = explode("\n",$total);
array_pop($total);
$total = array_pop($total);
$total = explode("\t",$total);
$total = (int) array_shift($total);
$totalBefore = $total;
$chunks = explode("\n\n", $output);

Expand Down Expand Up @@ -121,8 +126,13 @@
}

// calculate difference
$after = substr(exec('find '.$directory.' -type f | wc -l'), 0, -1);
$total = exec('du -h '.$directory); $total = explode("\n",$total); array_pop($total); $total = array_pop($total); $total = explode("\t",$total); $total = (int) array_shift($total);
$after = substr(exec('find '.$directory.' -type f | wc -l'), 0, -1); // not mb_substr
$total = exec('du -h '.$directory);
$total = explode("\n",$total);
array_pop($total);
$total = array_pop($total);
$total = explode("\t",$total);
$total = (int) array_shift($total);
$totalAfter = $total;

echo ' in directory ',$directory,' the script has deleted ',($before - $after),' files, files before: ',$totalBefore,' files after:',$totalAfter,"\n";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Created D/15/12/2013
* Updated V/28/10/2022
* Updated L/02/10/2023
*
* Copyright 2008-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-apijs
Expand Down Expand Up @@ -95,7 +95,7 @@ body.fabload #apijsGallery { pointer-events:none; opacity:0.5; }

#apijsGallery table.gallery tbody td { vertical-align:middle; }
#apijsGallery table.gallery tbody td.img { padding:3px; width:200px; }
#apijsGallery table.gallery tbody td.hgt { line-height:150px; color:gray; }
#apijsGallery table.gallery tbody td.hgt { line-height:150px; color:#808080; }
#apijsGallery table.gallery tbody td.last { white-space:inherit; }
#apijsGallery table.gallery tbody td:not(.last) * { display:block; }

Expand Down
Loading

0 comments on commit 1929941

Please sign in to comment.