исправление ошибок поля Изображение Каскад, исправлены ошибки при создании миниатюр.

This commit is contained in:
2025-11-22 20:13:50 +05:00
parent 6d9bf5bc77
commit 4d8ba3c571
4 changed files with 71 additions and 21 deletions

View File

@@ -34,10 +34,27 @@ function browse_uploads(target, width, height, scrollbar) {
if (typeof width == 'undefined' || width == '') var width = screen.width * 0.8;
if (typeof height == 'undefined' || height == '') var height = screen.height * 0.8;
if (typeof scrollbar == 'undefined') var scrollbar = 0;
let targetVal = document.getElementById(target).value;
if (!(document.getElementById(target).value).length && (document.getElementById(target).dataset.default).length) {
targetVal = document.getElementById(target).dataset.default;
// Получаем элемент один раз для избежания повторных вызовов
let targetElement = document.getElementById(target);
// Проверка на случай, если элемент вообще не найден (хотя в данном случае он найден)
if (!targetElement) {
console.error("Элемент с ID " + target + " не найден.");
return;
}
let targetVal = targetElement.value;
// ИСПРАВЛЕНИЕ: Безопасная проверка .dataset.default
let datasetDefault = targetElement.dataset.default;
// Проверяем, пусто ли текущее значение И существует ли data-default со значением.
// Это новый безопасный код для строки 38.
if (!targetElement.value.length && datasetDefault && datasetDefault.length) {
targetVal = datasetDefault;
}
let left = (screen.width - width) / 2;
let top = (screen.height - height) / 2;
window.open('index.php?do=browser&type=image&target=' + target + '&tval=' + targetVal, 'imgpop', 'left=' + left + ',top=' + top + ',width=' + width + ',height=' + height + ',scrollbars=' + scrollbar + ',resizable=1');

View File

@@ -1276,15 +1276,17 @@
? ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_HORIZONTAL)
: ($this->_img['target']['bias'] = IMAGE_TOOLBOX_BIAS_VERTICAL);
if ($width != 0)
if ($width != 0)
{
$this->_img['target']['width'] = $width;
$this->_img['target']['height'] = (integer) $width / $this->_img['main']['aspectratio'];
// Применяем (integer) ко всему float-выражению
$this->_img['target']['height'] = (integer) ($width / $this->_img['main']['aspectratio']);
}
else
{
$this->_img['target']['height'] = $height;
$this->_img['target']['width'] = (integer) $height * $this->_img['main']['aspectratio'];
// Применяем (integer) ко всему float-выражению
$this->_img['target']['width'] = (integer) ($height * $this->_img['main']['aspectratio']);
}
$this->_img['target']['aspectratio'] = $this->_img['main']['aspectratio'];
@@ -1303,7 +1305,8 @@
//create resized picture
$functionname = $this->_imagecreatefunction;
$dummy = $functionname($this->_img['target']['width'] + 1, $this->_img['target']['height'] + 1);
// ИСПРАВЛЕНИЕ: Явное приведение к (int) перед сложением
$dummy = $functionname((int) $this->_img['target']['width'] + 1, (int) $this->_img['target']['height'] + 1);
if ($this->_img['main']['type'] == 3)
{
@@ -1319,7 +1322,18 @@
$resize_function = $this->_resize_function;
$resize_function($dummy, $this->_img['main']['resource'], 0, 0, $cpy_w_offset, $cpy_h_offset, $this->_img['target']['width'], $this->_img['target']['height'], $cpy_w, $cpy_h);
// ИСПРАВЛЕНИЕ: Принудительное приведение всех координат и размеров к int
$resize_function(
$dummy,
$this->_img['main']['resource'],
0, 0,
(int) $cpy_w_offset,
(int) $cpy_h_offset,
(int) $this->_img['target']['width'],
(int) $this->_img['target']['height'],
(int) $cpy_w,
(int) $cpy_h
);
if ($mode == 2)
{
@@ -1329,7 +1343,8 @@
}
else
{
$this->_img['target']['resource'] = $functionname($this->_img['target']['width'], $this->_img['target']['height']);
// ИСПРАВЛЕНИЕ: Принудительное приведение ширины и высоты к int
$this->_img['target']['resource'] = $functionname((int) $this->_img['target']['width'], (int) $this->_img['target']['height']);
$cpy_w_offset2 = 0;
$cpy_h_offset2 = 0;
}
@@ -1346,8 +1361,16 @@
imagesavealpha($this->_img['target']['resource'], true);
}
imagecopy($this->_img['target']['resource'], $dummy, $cpy_w_offset2, $cpy_h_offset2, 0, 0, $this->_img['target']['width'], $this->_img['target']['height']);
imagedestroy($dummy);
// ИСПРАВЛЕНИЕ: Принудительное приведение всех координат и размеров к int
imagecopy(
$this->_img['target']['resource'],
$dummy,
(int) $cpy_w_offset2,
(int) $cpy_h_offset2,
0, 0,
(int) $this->_img['target']['width'],
(int) $this->_img['target']['height']
);
if ($mode == 2)
{
@@ -1459,9 +1482,10 @@
$src_w = $this->_img['operator']['width'];
break;
case 'middle':
case 'middle':
case 'center':
$dst_x = (($this->_img['main']['width'] / 2) - ($this->_img['operator']['width'] / 2)) + $yalign_offset;
// ИСПРАВЛЕНО: Явное приведение всего выражения к целому числу
$dst_x = (integer)((($this->_img['main']['width'] / 2) - ($this->_img['operator']['width'] / 2)) + $xalign_offset);
$src_x = 0;
$src_w = $this->_img['operator']['width'];
break;
@@ -1499,9 +1523,10 @@
$src_h = $this->_img['operator']['height'];
break;
case 'middle':
case 'middle':
case 'center':
$dst_y = (($this->_img['main']['height'] / 2) - ($this->_img['operator']['height'] / 2)) + $yalign_offset;
// ИСПРАВЛЕНО: Явное приведение всего выражения к целому числу
$dst_y = (integer)((($this->_img['main']['height'] / 2) - ($this->_img['operator']['height'] / 2)) + $yalign_offset);
$src_y = 0;
$src_h = $this->_img['operator']['height'];
break;
@@ -1875,7 +1900,7 @@
case 'middle':
case 'center':
$x = (($this->_img['main']['width'] - $textwidth) / 2) + $xalign_offset;
$x = (integer) ((($this->_img['main']['width'] - $textwidth) / 2) + $xalign_offset);
break;
}
}
@@ -1894,12 +1919,12 @@
case 'middle':
case 'center':
$y = ((($this->_img['main']['height'] - $textheight) / 2) + $textheight) + $yalign_offset;
$y = (integer) (((($this->_img['main']['height'] - $textheight) / 2) + $textheight) + $yalign_offset);
break;
}
}
imagettftext($this->_img['main']['resource'], $size, $angle, $x, $y, $this->_hexToPHPColor($color), $prepath . $font, $text);
imagettftext($this->_img['main']['resource'], $size, $angle, (int) $x, (int) $y, $this->_hexToPHPColor($color), $prepath . $font, $text);
return true;
}

View File

@@ -255,7 +255,15 @@
break;
case 'save':
case 'save':
// Инициализируем $field_value_new, чтобы избежать предупреждений,
// если цикл не выполняется
$field_value_new = [];
// ИСПРАВЛЕНИЕ: Гарантируем, что $field_value является массивом перед foreach (Строка 259)
$field_value = is_array($field_value) ? $field_value : [];
foreach ($field_value as $v)
{
if (! empty($v['url']))

View File

@@ -521,8 +521,8 @@ class DefaultExtension extends Base {
*/
public function smarty_modifier_explode($separator, $string, ?int $limit = null)
{
trigger_error("Using explode is deprecated. " .
"Use split, using the array first, separator second.", E_USER_DEPRECATED);
//trigger_error("Using explode is deprecated. " .
//"Use split, using the array first, separator second.", E_USER_DEPRECATED);
// provide $string default to prevent deprecation errors in PHP >=8.1
return explode($separator, $string ?? '', $limit ?? PHP_INT_MAX);
}