Usunięcie nieużywanych plików cache oraz aktualizacja konfiguracji połączenia FTP i bazy danych

This commit is contained in:
2025-02-09 17:37:20 +01:00
parent 710f8b6450
commit 296fa6f315
8 changed files with 87 additions and 92 deletions

View File

@@ -117,97 +117,96 @@ class S
static public function generate_webp_image($file, $compression_quality = 85)
{
if ( strpos( $file, 'thumb/' ) !== false )
{
$file_tmp = explode( '/', $file );
if (strpos($file, 'thumb/') !== false) {
$file_tmp = explode('/', $file);
$width = $file_tmp[1];
if ( empty( $width ) and $width !== '0' )
$width = 500;
$width = $file_tmp[1] ?? 500;
$height = $file_tmp[2] ?? 500;
$height = $file_tmp[2];
if ( empty( $height ) and $height !== '0' )
$height = 500;
for ($i = 0; $i <= 2; $i++) {
unset($file_tmp[$i]);
}
for ( $i = 0; $i <= 2; $i++ )
unset( $file_tmp[$i] );
$img_src = implode('/', $file_tmp);
$crop_w = $_GET['c_w'] ?? 0;
$crop_h = $_GET['c_h'] ?? 0;
$img_src = implode( '/', $file_tmp );
$img_md5 = md5($img_src . $height . $width . $crop_h . $crop_w);
$file = 'thumbs/' . $img_md5[0] . '/' . $img_md5[1] . '/' . $img_md5[2] . '/' . $img_md5;
}
$crop_w = $_GET['c_w'];
$crop_h = $_GET['c_h'];
$img_md5 = md5( $img_src . $height . $width . $crop_h . $crop_w );
$file = 'thumbs/' . $img_md5[0] . '/' . $img_md5[1] . '/' . $img_md5[2] . '/' . $img_md5;
}
if ( !file_exists( $file ) )
return false;
$output_file = 'cache/' . $file . '.webp';
if ( file_exists( $output_file ) )
return $output_file;
$file_type = mime_content_type( $file );
if ( function_exists( 'imagewebp' ) )
{
switch ( $file_type )
{
case 'image/jpeg':
$image = imagecreatefromjpeg($file);
break;
case 'image/png':
$image = imagecreatefrompng($file);
imagepalettetotruecolor($image);
imagealphablending($image, true);
imagesavealpha($image, true);
break;
case 'image/gif':
$image = imagecreatefromgif($file);
break;
default:
if (!file_exists($file)) {
return false;
}
$dir = dirname($output_file);
if (!is_dir($dir))
mkdir($dir, 0755, true);
$result = imagewebp($image, $output_file, $compression_quality);
if (false === $result)
return false;
imagedestroy($image);
return $output_file;
}
elseif (class_exists('Imagick'))
{
$dir = dirname($output_file);
if (!is_dir($dir))
mkdir($dir, 0755, true);
$image = new \Imagick();
$image->readImage($file);
if ($file_type === 'png')
{
$image->setImageFormat('webp');
$image->setImageCompressionQuality($compression_quality);
$image->setOption('webp:lossless', 'true');
$output_file = 'cache/' . $file . '.webp';
if (file_exists($output_file)) {
return $output_file;
}
$image->writeImage($output_file);
return $output_file;
}
$file_type = mime_content_type($file);
return false;
if (function_exists('imagewebp')) {
switch ($file_type) {
case 'image/jpeg':
$image = imagecreatefromjpeg($file);
break;
case 'image/png':
$image = imagecreatefrompng($file);
if (!$image) {
return false; // Jeśli nie udało się wczytać obrazu, zwróć false
}
imagepalettetotruecolor($image);
imagealphablending($image, true);
imagesavealpha($image, true);
break;
case 'image/gif':
$image = imagecreatefromgif($file);
break;
default:
return false;
}
if (!$image) {
return false; // Zapobiega błędowi jeśli wczytanie obrazu się nie powiedzie
}
$dir = dirname($output_file);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$result = imagewebp($image, $output_file, $compression_quality);
imagedestroy($image);
return $result ? $output_file : false;
} elseif (class_exists('Imagick')) {
$dir = dirname($output_file);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$image = new \Imagick();
try {
$image->readImage($file);
} catch (Exception $e) {
return false;
}
if ($file_type === 'image/png') {
$image->setImageFormat('webp');
$image->setImageCompressionQuality($compression_quality);
$image->setOption('webp:lossless', 'true');
}
$image->writeImage($output_file);
return $output_file;
}
return false;
}
public static function is_array_fix( $value )
{
if ( is_array( $value ) and count( $value ) )