Skip to content

Commit c43b08a

Browse files
authored
fix: typo on czech translation
fix: subscription progress above 100% for disabled subscriptions fix: use gd if imagick is not available fix: bug setting main currency for the first registered user fix: deprecation message fix: use first currency on the list of currencies if user has not selected a main currency
1 parent 9c13a45 commit c43b08a

File tree

6 files changed

+72
-30
lines changed

6 files changed

+72
-30
lines changed

endpoints/payments/add.php

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,31 @@ function saveLogo($imageData, $uploadFile, $name, $settings)
6060
imagepng($image, $tempFile);
6161
imagedestroy($image);
6262

63-
$imagick = new Imagick($tempFile);
64-
if ($removeBackground) {
65-
$fuzz = Imagick::getQuantum() * 0.1; // 10%
66-
$imagick->transparentPaintImage("rgb(247, 247, 247)", 0, $fuzz, false);
67-
}
68-
$imagick->setImageFormat('png');
69-
$imagick->writeImage($uploadFile);
63+
if (extension_loaded('imagick')) {
64+
$imagick = new Imagick($tempFile);
65+
if ($removeBackground) {
66+
$fuzz = Imagick::getQuantum() * 0.1; // 10%
67+
$imagick->transparentPaintImage("rgb(247, 247, 247)", 0, $fuzz, false);
68+
}
69+
$imagick->setImageFormat('png');
70+
$imagick->writeImage($uploadFile);
7071

71-
$imagick->clear();
72-
$imagick->destroy();
72+
$imagick->clear();
73+
$imagick->destroy();
74+
} else {
75+
// Alternative method if Imagick is not available
76+
$newImage = imagecreatefrompng($tempFile);
77+
if ($removeBackground) {
78+
imagealphablending($newImage, false);
79+
imagesavealpha($newImage, true);
80+
$transparent = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
81+
imagefill($newImage, 0, 0, $transparent); // Fill the entire image with transparency
82+
imagepng($newImage, $uploadFile);
83+
imagedestroy($newImage);
84+
}
85+
imagepng($newImage, $uploadFile);
86+
imagedestroy($newImage);
87+
}
7388
unlink($tempFile);
7489

7590
return true;
@@ -120,13 +135,13 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name)
120135
$newHeight = $height;
121136

122137
if ($width > $targetWidth) {
123-
$newWidth = (int)$targetWidth;
124-
$newHeight = (int)(($targetWidth / $width) * $height);
138+
$newWidth = (int) $targetWidth;
139+
$newHeight = (int) (($targetWidth / $width) * $height);
125140
}
126141

127142
if ($newHeight > $targetHeight) {
128-
$newWidth = (int)(($targetHeight / $newHeight) * $newWidth);
129-
$newHeight = (int)$targetHeight;
143+
$newWidth = (int) (($targetHeight / $newHeight) * $newWidth);
144+
$newHeight = (int) $targetHeight;
130145
}
131146

132147
$resizedImage = imagecreatetruecolor($newWidth, $newHeight);

endpoints/subscription/add.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,36 @@ function saveLogo($imageData, $uploadFile, $name, $settings)
6161
imagepng($image, $tempFile);
6262
imagedestroy($image);
6363

64-
$imagick = new Imagick($tempFile);
65-
if ($removeBackground) {
66-
$fuzz = Imagick::getQuantum() * 0.1; // 10%
67-
$imagick->transparentPaintImage("rgb(247, 247, 247)", 0, $fuzz, false);
68-
}
69-
$imagick->setImageFormat('png');
70-
$imagick->writeImage($uploadFile);
64+
if (extension_loaded('imagick')) {
65+
$imagick = new Imagick($tempFile);
66+
if ($removeBackground) {
67+
$fuzz = Imagick::getQuantum() * 0.1; // 10%
68+
$imagick->transparentPaintImage("rgb(247, 247, 247)", 0, $fuzz, false);
69+
}
70+
$imagick->setImageFormat('png');
71+
$imagick->writeImage($uploadFile);
7172

72-
$imagick->clear();
73-
$imagick->destroy();
73+
$imagick->clear();
74+
$imagick->destroy();
75+
} else {
76+
// Alternative method if Imagick is not available
77+
$newImage = imagecreatefrompng($tempFile);
78+
if ($newImage !== false) {
79+
if ($removeBackground) {
80+
imagealphablending($newImage, false);
81+
imagesavealpha($newImage, true);
82+
$transparent = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
83+
imagefill($newImage, 0, 0, $transparent); // Fill the entire image with transparency
84+
imagepng($newImage, $uploadFile);
85+
imagedestroy($newImage);
86+
}
87+
imagepng($newImage, $uploadFile);
88+
imagedestroy($newImage);
89+
} else {
90+
unlink($tempFile);
91+
return false;
92+
}
93+
}
7494
unlink($tempFile);
7595

7696
return true;

includes/getsettings.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
$result = $stmt->execute();
77

88
$settings = $result->fetchArray(SQLITE3_ASSOC);
9-
if ($settings) {
9+
if ($settings !== false) {
1010
$themeMapping = array(0 => 'light', 1 => 'dark', 2 => 'automatic');
1111
$themeKey = isset($settings['dark_theme']) ? $settings['dark_theme'] : 2;
1212
$themeValue = $themeMapping[$themeKey];
@@ -37,7 +37,7 @@
3737
$result = $stmt->execute();
3838
$customColors = $result->fetchArray(SQLITE3_ASSOC);
3939

40-
if ($customColors) {
40+
if ($customColors !== false) {
4141
$settings['customColors'] = $customColors;
4242
}
4343

@@ -46,15 +46,15 @@
4646
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
4747
$result = $stmt->execute();
4848
$customCss = $result->fetchArray(SQLITE3_ASSOC);
49-
if ($customCss) {
49+
if ($customCss !== false) {
5050
$settings['customCss'] = $customCss['css'];
5151
}
5252

5353
$query = "SELECT * FROM admin";
5454
$result = $db->query($query);
5555
$adminSettings = $result->fetchArray(SQLITE3_ASSOC);
5656

57-
if ($adminSettings) {
57+
if ($adminSettings !== false) {
5858
$settings['disableLogin'] = $adminSettings['login_disabled'];
5959
$settings['update_notification'] = $adminSettings['update_notification'];
6060
$settings['latest_version'] = $adminSettings['latest_version'];

includes/list_subscriptions.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,10 @@ class="name"><?php include $imagePath . "images/siteicons/svg/subscription.php";
289289
</div>
290290
<?php
291291
if ($showSubscriptionProgress === 'true') {
292+
$progress = $subscription['progress'] > 100 ? 100 : $subscription['progress'];
292293
?>
293294
<div class="subscription-progress-container">
294-
<span class="subscription-progress" style="width: <?= $subscription['progress'] ?>%;"></span>
295+
<span class="subscription-progress" style="width: <?= $progress ?>%;"></span>
295296
</div>
296297
<?php
297298
}
@@ -306,6 +307,10 @@ class="name"><?php include $imagePath . "images/siteicons/svg/subscription.php";
306307
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
307308
$result = $stmt->execute();
308309
$row = $result->fetchArray(SQLITE3_ASSOC);
309-
$mainCurrencyId = $row['main_currency'];
310+
if ($row !== false) {
311+
$mainCurrencyId = $row['main_currency'];
312+
} else {
313+
$mainCurrencyId = $currencies[1]['id'];
314+
}
310315

311316
?>

includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
2-
$version = "v2.45.1";
2+
$version = "v2.45.2";
33
?>

registration.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ function validate($value)
162162
$password = $_POST['password'];
163163
$confirm_password = $_POST['confirm_password'];
164164
$main_currency = $_POST['main_currency'];
165+
$main_currency_index = array_search($main_currency, array_column($currencies, 'code'));
166+
$main_currency_id = $currencies[$main_currency_index]['id'];
165167
$language = $_POST['language'];
166168
$avatar = "images/avatars/0.svg";
167169

@@ -199,7 +201,7 @@ function validate($value)
199201
$stmt->bindValue(':username', $username, SQLITE3_TEXT);
200202
$stmt->bindValue(':email', $email, SQLITE3_TEXT);
201203
$stmt->bindValue(':password', $hashedPassword, SQLITE3_TEXT);
202-
$stmt->bindValue(':main_currency', 1, SQLITE3_TEXT);
204+
$stmt->bindValue(':main_currency', $main_currency_id, SQLITE3_TEXT);
203205
$stmt->bindValue(':avatar', $avatar, SQLITE3_TEXT);
204206
$stmt->bindValue(':language', $language, SQLITE3_TEXT);
205207
$stmt->bindValue(':budget', 0, SQLITE3_INTEGER);

0 commit comments

Comments
 (0)