Skip to content

Commit

Permalink
Version 4.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Jan 1, 2023
1 parent a1b9108 commit 1641ce9
Show file tree
Hide file tree
Showing 43 changed files with 240 additions and 220 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/openmage/minifier (IPv6 is r

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

- Current version: 4.3.2 (10/10/2022)
- Compatibility: OpenMage 19.x / 20.x / 21.x, PHP 7.2 / 7.3 / 7.4 / 8.0 / 8.1
- Current version: 4.4.0 (01/01/2023)
- Compatibility: OpenMage 19.x / 20.x / 21.x, PHP 7.2 / 7.3 / 7.4 / 8.0 / 8.1 / 8.2
- 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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* Created D/25/02/2018
* Updated J/22/07/2021
* Updated S/03/12/2022
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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,7 +20,7 @@
class Luigifab_Minifier_Block_Adminhtml_Config_Check extends Mage_Adminhtml_Block_System_Config_Form_Field {

public function render(Varien_Data_Form_Element_Abstract $element) {
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue()->unsPath();
return parent::render($element);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created S/01/02/2020
* Updated J/12/11/2020
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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 D/15/11/2020
* Updated S/21/11/2020
* Updated S/03/12/2022
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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,7 +20,7 @@
class Luigifab_Minifier_Block_Adminhtml_Config_Debug extends Mage_Adminhtml_Block_System_Config_Form_Field {

public function render(Varien_Data_Form_Element_Abstract $element) {
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue()->unsPath();
return parent::render($element);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created S/20/06/2015
* Updated V/20/05/2022
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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/03/03/2018
* Updated L/14/02/2022
* Updated S/03/12/2022
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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 @@ -21,7 +21,8 @@ class Luigifab_Minifier_Block_Adminhtml_Config_Server extends Mage_Adminhtml_Blo

public function render(Varien_Data_Form_Element_Abstract $element) {

return str_replace(['`', "\n"], [chr(194).chr(160), '<br />'], '<tr><td colspan="4"><code style="display:block; margin:1em 0; padding-left:6px; font-size:0.9em; line-height:1.4em; border-left:3px solid #AAA;"><strong>## THE REQUIRED CONFIGURATION</strong>
// getPath PR 2774
return str_replace(['`', "\n"], [chr(194).chr(160), '<br />'], '<tr><td colspan="'.(empty($element->getPath()) ? 4 : 5).'"><code style="display:block; margin:1em 0; padding-left:6px; font-size:0.9em; line-height:1.4em; border-left:3px solid #AAA;"><strong>## THE REQUIRED CONFIGURATION</strong>
## for apache (virtual host or htaccess)
RewriteRule (.*)skin/.*/favicon.ico $1favicon.ico [L]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created M/01/09/2015
* Updated D/06/10/2019
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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 S/20/06/2015
* Updated S/31/08/2019
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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/Minifier/Block/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created D/20/05/2018
* Updated D/18/07/2021
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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 M/01/09/2015
* Updated D/15/11/2020
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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 S/20/06/2015
* Updated S/31/08/2019
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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
16 changes: 9 additions & 7 deletions src/app/code/community/Luigifab/Minifier/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* Created S/20/06/2015
* Updated S/19/02/2022
* Updated V/09/12/2022
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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,6 +19,8 @@

class Luigifab_Minifier_Helper_Data extends Mage_Core_Helper_Abstract {

protected $_cpucore;

public function getVersion() {
return (string) Mage::getConfig()->getModuleConfig('Luigifab_Minifier')->version;
}
Expand Down Expand Up @@ -111,20 +113,20 @@ 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;
}


public function getNumberOfCpuCore() {

if (empty($this->cpucore)) {
if (empty($this->_cpucore)) {
exec('nproc', $data);
$this->cpucore = max(1, (int) trim(implode($data)));
$this->_cpucore = max(1, (int) trim(implode($data)));
}

return $this->cpucore;
return $this->_cpucore;
}

public function afterToHtml(string $html) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Created L/16/07/2018
* Updated V/11/02/2022
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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
24 changes: 12 additions & 12 deletions src/app/code/community/Luigifab/Minifier/Model/Files.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
/**
* Created W/13/04/2016
* Updated D/26/06/2022
* Updated D/06/11/2022
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2022 | Fabrice Creuzot <fabrice~cellublue~com>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2022-2023 | Fabrice Creuzot <fabrice~cellublue~com>
* https://github.com/luigifab/openmage-minifier
*
* 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,9 +22,7 @@ class Luigifab_Minifier_Model_Files extends Mage_Core_Model_Layout_Update {

public function getMinifiedFiles(int $storeId) {

if (($storeId == 0) && !Mage::getStoreConfigFlag('minifier/cssjs/enabled_back'))
return [];
if (($storeId != 0) && !Mage::getStoreConfigFlag('minifier/cssjs/enabled_front', $storeId))
if (!Mage::getStoreConfigFlag(($storeId == 0) ? 'minifier/cssjs/enabled_back' : 'minifier/cssjs/enabled_front', $storeId))
return [];

$dir = Mage::getBaseDir('media').'/minifier-cache/';
Expand Down Expand Up @@ -131,7 +129,8 @@ protected function minifyFiles(array $items) {
array_map('unlink', glob($outdated));

$new = true;
$cmd = sprintf('php %s %s %s %s %d >> %s 2>&1 & echo $!',
$cmd = sprintf('%s %s %s %s %s %d >> %s 2>&1 & echo $!',
'php'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION,
str_replace('Minifier/etc', 'Minifier/lib/minify.php', Mage::getModuleDir('etc', 'Luigifab_Minifier')),
(mb_stripos($source, '.css') === false) ? 'js' : 'css',
escapeshellarg($source),
Expand Down Expand Up @@ -184,7 +183,8 @@ protected function mergeFiles(string $dest, array $data) {
unset($files[$idx]);
}

$cmd = sprintf('php %s %s %s %s %d >> %s 2>&1',
$cmd = sprintf('%s %s %s %s %s %d >> %s 2>&1',
'php'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION,
str_replace('Minifier/etc', 'Minifier/lib/minify.php', Mage::getModuleDir('etc', 'Luigifab_Minifier')),
(mb_stripos($dest, '.js') === false) ? 'mergecss' : 'mergejs',
implode(',', array_map('escapeshellarg', $files)),
Expand Down Expand Up @@ -271,12 +271,12 @@ protected function searchFiles(object $design, int $storeId) {
// récupère la liste des fichiers depuis le layout
$head = Mage::app()->getLayout()->getBlock('head');
$doc = new DOMDocument();
@$doc->loadHTML($this->merge('all')->_packageLayout->asNiceXml());
@$doc->loadHTML($this->merge('all')->_packageLayout->asNiceXml(), LIBXML_NOERROR);
$xpath = new DomXPath($doc);

foreach ($xpath->query('//action[@method="removeItem"]') as $element) {

if (stripos($element->getNodePath(), 'oauth') !== false)
if (str_contains($element->getNodePath(), 'oauth'))
continue;

$config = $element->getAttribute('ifconfig');
Expand Down Expand Up @@ -304,7 +304,7 @@ protected function searchFiles(object $design, int $storeId) {

foreach ($xpath->query('//action[@method="addItem"]|//action[@method="addCss"]|//action[@method="addJs"]') as $element) {

if (stripos($element->getNodePath(), 'oauth') !== false)
if (str_contains($element->getNodePath(), 'oauth'))
continue;

$config = $element->getAttribute('ifconfig');
Expand Down
40 changes: 22 additions & 18 deletions src/app/code/community/Luigifab/Minifier/Model/Observer.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* Created S/20/06/2015
* Updated D/18/09/2022
* Updated D/11/12/2022
*
* Copyright 2011-2022 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/minifier
* Copyright 2011-2023 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://github.com/luigifab/openmage-minifier
*
* 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 @@ -30,10 +30,10 @@ public function clearMinifiedFiles(Varien_Event_Observer $observer) {
Mage::getBaseDir('media').'/js/'
];

exec('rm -rf '.implode(' ', $dirs));
exec('rm -f '.Mage::getBaseDir('media').'/minifier-cache/virtual*');
exec('rm -rf '.implode(' ', array_map('escapeshellarg', $dirs)));
exec('rm -f '.escapeshellarg(Mage::getBaseDir('media').'/minifier-cache/virtual*'));

$this->updateConfig($observer);
$this->clearCache($observer);
}

// EVENT admin_system_config_changed_section_minifier (adminhtml)
Expand All @@ -46,7 +46,7 @@ public function clearCache(Varien_Event_Observer $observer) {
}

// EVENT controller_action_predispatch_adminhtml_index_changeLocale (adminhtml)
public function updateBackgendLanguage(Varien_Event_Observer $observer) {
public function updateBackendLanguage(Varien_Event_Observer $observer) {

$locale = $observer->getData('controller_action')->getRequest()->getParam('locale');
Mage::getSingleton('core/session')->setData('locale', $locale);
Expand All @@ -70,18 +70,23 @@ public function setBackendLanguage(Varien_Event_Observer $observer) {

protected function searchCurrentLocale(array $locales, string $result = 'en_US') {

$codes = [];

// recherche des préférences dans HTTP_ACCEPT_LANGUAGE
// https://stackoverflow.com/a/33748742
$codes = array_reduce(
empty(getenv('HTTP_ACCEPT_LANGUAGE')) ? [] : explode(',', getenv('HTTP_ACCEPT_LANGUAGE')),
static function ($items, $item) {
[$code, $q] = explode(';q=', $item.';q=1');
$items[str_replace('-', '_', $code)] = (float) $q;
return $items;
}, []);

arsort($codes);
$codes = array_map('\strval', array_keys($codes));
if (!empty(getenv('HTTP_ACCEPT_LANGUAGE'))) {

$codes = array_reduce(
explode(',', getenv('HTTP_ACCEPT_LANGUAGE')),
static function ($items, $item) {
[$code, $q] = explode(';q=', $item.';q=1');
$items[str_replace('-', '_', $code)] = (float) $q;
return $items;
}, []);

arsort($codes);
$codes = array_map('\strval', array_keys($codes));
}

// ajoute la locale présente dans l'url en premier car elle est prioritaire
if (!empty($_GET['lang'])) {
Expand All @@ -92,7 +97,6 @@ static function ($items, $item) {
}

// cherche la locale à utiliser
// essaye es ou fil puis es_ES ou fil_PH
foreach ($codes as $code) {

if ((strlen($code) >= 2) && !str_contains($code, '_')) {
Expand Down
Loading

0 comments on commit 1641ce9

Please sign in to comment.