Skip to content

Commit 5430927

Browse files
committed
upd to 0.11.1
1 parent 9c148e1 commit 5430927

File tree

4 files changed

+68
-28
lines changed

4 files changed

+68
-28
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22
$arModuleVersion = [
3-
'VERSION' => '0.11.0',
4-
'VERSION_DATE' => '2025-02-18 23:30:00',
3+
'VERSION' => '0.11.1',
4+
'VERSION_DATE' => '2025-02-19 02:30:00',
55
];

utf8/dev2fun.imagecompress/lib/Convert.php

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* @author darkfriend <hi@darkfriend.ru>
44
* @copyright dev2fun
5-
* @version 0.11.0
5+
* @version 0.11.1
66
*/
77

88
namespace Dev2fun\ImageCompress;
@@ -725,7 +725,8 @@ public static function PostConverterEvent(string &$content)
725725
return $content;
726726
}
727727

728-
$curUri = $APPLICATION->GetCurUri();
728+
// $curUri = $APPLICATION->GetCurUri();
729+
$curUri = $APPLICATION->GetCurPage();
729730
$userGroups = 'guest';
730731
$includeUserGroups = self::getInstance()->cacheIncludeUserGroups;
731732
if ($includeUserGroups && $USER->IsAuthorized()) {
@@ -830,6 +831,9 @@ function () use ($arFiles) {
830831
ImageCompressImagesTable::getTableName(),
831832
$rows
832833
);
834+
835+
// var_dump($sql);
836+
// die();
833837
// $connection->getSqlHelper()->prepareMerge(
834838
// ImageCompressImagesTable::getTableName(),
835839
// [],
@@ -866,35 +870,42 @@ function () use ($arFiles) {
866870
'IMAGE_IGNORE' => 'N',
867871
];
868872
$imagesHash = [];
873+
$arFilesHash = [];
869874
foreach ($arFiles as $file) {
870-
$file = str_replace('\/', '/', $file);
871-
$isUrl = !empty(parse_url($file, PHP_URL_HOST));
875+
$fileNormalize = str_replace('\/', '/', $file);
876+
$isUrl = !empty(parse_url($fileNormalize, PHP_URL_HOST));
872877
$hash = null;
873878
if ($isUrl) {
874-
$hash = md5_file($file);
879+
$hash = md5_file($fileNormalize);
875880
} else {
876-
$absFile = $_SERVER['DOCUMENT_ROOT'] . '/' . ltrim($file, '/');
881+
$absFile = $_SERVER['DOCUMENT_ROOT'] . '/' . ltrim($fileNormalize, '/');
877882
if (is_file($absFile)) {
878-
$hash = md5_file($_SERVER['DOCUMENT_ROOT'].$file);
883+
$hash = md5_file($_SERVER['DOCUMENT_ROOT'].$fileNormalize);
879884
}
880885
}
886+
881887
if ($hash) {
882888
$imagesHash[] = $hash;
889+
$arFilesHash[$hash][] = $file;
883890
}
891+
892+
893+
894+
// var_dump(empty($currentFiles[$md5]));
895+
884896
// $imagesHash[] = md5_file($_SERVER['DOCUMENT_ROOT'].$file);
885897
// $rows[] = [
886898
// 'SITE_ID' => Dev2funImageCompress::getSiteId(),
887899
// 'IMAGE_PATH' => $file,
888900
// 'IMAGE_HASH' => md5_file($_SERVER['DOCUMENT_ROOT'].$file),
889901
// ];
890902
}
903+
891904
if (!$imagesHash) {
892905
return [];
893906
}
894907
$filter[] = [
895908
'IMAGE_HASH', 'in', array_unique($imagesHash),
896-
// 'logic' => Filter::LOGIC_OR,
897-
// ['IMAGE_HASH', 'in', ''],
898909
];
899910
$images = ImageCompressImagesTable::getList([
900911
'select' => [
@@ -911,19 +922,28 @@ function () use ($arFiles) {
911922
])
912923
->fetchAll();
913924

925+
914926
$result = [];
915927
foreach ($images as $image) {
916-
if (self::isExcludeFile($image['IMAGE_PATH'])) {
928+
if (
929+
empty($arFilesHash[$image['IMAGE_HASH']])
930+
|| (!empty($arFilesHash[$image['IMAGE_HASH']]) && !in_array($image['IMAGE_PATH'], $arFilesHash[$image['IMAGE_HASH']]))
931+
) {
917932
continue;
918933
}
919-
$result[$image['IMAGE_PATH']] = $image['CONVERTED_IMAGE_PATH'];
934+
foreach ($arFilesHash[$image['IMAGE_HASH']] as $filePath) {
935+
if (self::isExcludeFile($filePath)) {
936+
continue;
937+
}
938+
$result[$filePath] = $image['CONVERTED_IMAGE_PATH'];
939+
}
920940
}
921941

922942
return $result;
923943
}
924944
);
925945

926-
if($arFileReplace) {
946+
if ($arFileReplace) {
927947
$content = \strtr($content, $arFileReplace);
928948
}
929949

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22
$arModuleVersion = [
3-
'VERSION' => '0.11.0',
4-
'VERSION_DATE' => '2025-02-18 23:30:00',
3+
'VERSION' => '0.11.1',
4+
'VERSION_DATE' => '2025-02-19 02:30:00',
55
];

win1251/dev2fun.imagecompress/lib/Convert.php

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* @author darkfriend <hi@darkfriend.ru>
44
* @copyright dev2fun
5-
* @version 0.11.0
5+
* @version 0.11.1
66
*/
77

88
namespace Dev2fun\ImageCompress;
@@ -725,7 +725,8 @@ public static function PostConverterEvent(string &$content)
725725
return $content;
726726
}
727727

728-
$curUri = $APPLICATION->GetCurUri();
728+
// $curUri = $APPLICATION->GetCurUri();
729+
$curUri = $APPLICATION->GetCurPage();
729730
$userGroups = 'guest';
730731
$includeUserGroups = self::getInstance()->cacheIncludeUserGroups;
731732
if ($includeUserGroups && $USER->IsAuthorized()) {
@@ -830,6 +831,9 @@ function () use ($arFiles) {
830831
ImageCompressImagesTable::getTableName(),
831832
$rows
832833
);
834+
835+
// var_dump($sql);
836+
// die();
833837
// $connection->getSqlHelper()->prepareMerge(
834838
// ImageCompressImagesTable::getTableName(),
835839
// [],
@@ -866,35 +870,42 @@ function () use ($arFiles) {
866870
'IMAGE_IGNORE' => 'N',
867871
];
868872
$imagesHash = [];
873+
$arFilesHash = [];
869874
foreach ($arFiles as $file) {
870-
$file = str_replace('\/', '/', $file);
871-
$isUrl = !empty(parse_url($file, PHP_URL_HOST));
875+
$fileNormalize = str_replace('\/', '/', $file);
876+
$isUrl = !empty(parse_url($fileNormalize, PHP_URL_HOST));
872877
$hash = null;
873878
if ($isUrl) {
874-
$hash = md5_file($file);
879+
$hash = md5_file($fileNormalize);
875880
} else {
876-
$absFile = $_SERVER['DOCUMENT_ROOT'] . '/' . ltrim($file, '/');
881+
$absFile = $_SERVER['DOCUMENT_ROOT'] . '/' . ltrim($fileNormalize, '/');
877882
if (is_file($absFile)) {
878-
$hash = md5_file($_SERVER['DOCUMENT_ROOT'].$file);
883+
$hash = md5_file($_SERVER['DOCUMENT_ROOT'].$fileNormalize);
879884
}
880885
}
886+
881887
if ($hash) {
882888
$imagesHash[] = $hash;
889+
$arFilesHash[$hash][] = $file;
883890
}
891+
892+
893+
894+
// var_dump(empty($currentFiles[$md5]));
895+
884896
// $imagesHash[] = md5_file($_SERVER['DOCUMENT_ROOT'].$file);
885897
// $rows[] = [
886898
// 'SITE_ID' => Dev2funImageCompress::getSiteId(),
887899
// 'IMAGE_PATH' => $file,
888900
// 'IMAGE_HASH' => md5_file($_SERVER['DOCUMENT_ROOT'].$file),
889901
// ];
890902
}
903+
891904
if (!$imagesHash) {
892905
return [];
893906
}
894907
$filter[] = [
895908
'IMAGE_HASH', 'in', array_unique($imagesHash),
896-
// 'logic' => Filter::LOGIC_OR,
897-
// ['IMAGE_HASH', 'in', ''],
898909
];
899910
$images = ImageCompressImagesTable::getList([
900911
'select' => [
@@ -911,19 +922,28 @@ function () use ($arFiles) {
911922
])
912923
->fetchAll();
913924

925+
914926
$result = [];
915927
foreach ($images as $image) {
916-
if (self::isExcludeFile($image['IMAGE_PATH'])) {
928+
if (
929+
empty($arFilesHash[$image['IMAGE_HASH']])
930+
|| (!empty($arFilesHash[$image['IMAGE_HASH']]) && !in_array($image['IMAGE_PATH'], $arFilesHash[$image['IMAGE_HASH']]))
931+
) {
917932
continue;
918933
}
919-
$result[$image['IMAGE_PATH']] = $image['CONVERTED_IMAGE_PATH'];
934+
foreach ($arFilesHash[$image['IMAGE_HASH']] as $filePath) {
935+
if (self::isExcludeFile($filePath)) {
936+
continue;
937+
}
938+
$result[$filePath] = $image['CONVERTED_IMAGE_PATH'];
939+
}
920940
}
921941

922942
return $result;
923943
}
924944
);
925945

926-
if($arFileReplace) {
946+
if ($arFileReplace) {
927947
$content = \strtr($content, $arFileReplace);
928948
}
929949

0 commit comments

Comments
 (0)