Skip to content

Wallos: Open-source, self-hostable personal subscription tracker. Visualize your recurring expenses, manage your budget, and save money.

feat: better navigation inside logo search

Miguel Ribeiro921fcfd1598d
diff --git a/api/subscriptions/set_subscriptions.php b/api/subscriptions/set_subscriptions.php
index b8cc34e..b5263f1 100644
--- a/api/subscriptions/set_subscriptions.php
+++ b/api/subscriptions/set_subscriptions.php
@@ -47,6 +47,7 @@ error_reporting(E_ERROR | E_PARSE);
require_once '../../includes/connect_endpoint.php';
require_once '../../includes/inputvalidation.php';
require_once '../../includes/ssrf_helper.php';
+require_once '../../includes/logo_theme_variant.php';
header('Content-Type: application/json; charset=UTF-8');
@@ -101,6 +102,8 @@ if (!$action || !in_array($action, ['add', 'edit', 'delete'], true)) {
// Load user settings now that user is authenticated
require_once '../../includes/getsettings.php';
+$removeBackgroundEnabled = isset($settings['removeBackground']) && $settings['removeBackground'] === 'true';
+
if (!file_exists('../../images/uploads/logos')) {
mkdir('../../images/uploads/logos', 0777, true);
mkdir('../../images/uploads/logos/avatars', 0777, true);
@@ -307,6 +310,42 @@ function validateDate($date, $format = 'Y-m-d') {
return $d && $d->format($format) === $date;
}
+// Themed variant generation piggybacks on the same "remove background"
+// setting: both only make sense for logos we're already reprocessing, and
+// this avoids running pixel classification on every single upload.
+function generateLogoThemeVariant($logo, $removeBackgroundEnabled)
+{
+ $logoTextColor = null;
+ $logoVariant = null;
+
+ if ($logo !== "" && $removeBackgroundEnabled) {
+ $logoExtension = strtolower(pathinfo($logo, PATHINFO_EXTENSION));
+ $logoPath = '../../images/uploads/logos/' . $logo;
+
+ if ($logoExtension === 'png' || $logoExtension === 'webp') {
+ $sourceImage = $logoExtension === 'png' ? imagecreatefrompng($logoPath) : imagecreatefromwebp($logoPath);
+
+ if ($sourceImage !== false) {
+ imagealphablending($sourceImage, false);
+ imagesavealpha($sourceImage, true);
+
+ $logoTextColor = classifyLogoTextColor($sourceImage);
+
+ if ($logoTextColor !== null) {
+ $variantImage = generateThemedLogoVariant($sourceImage);
+ $logoVariant = pathinfo($logo, PATHINFO_FILENAME) . '-variant.png';
+ imagepng($variantImage, '../../images/uploads/logos/' . $logoVariant);
+ imagedestroy($variantImage);
+ }
+
+ imagedestroy($sourceImage);
+ }
+ }
+ }
+
+ return [$logoTextColor, $logoVariant];
+}
+
switch ($action) {
case 'add':
$name = $_POST['name'] ?? null;
@@ -488,21 +527,25 @@ switch ($action) {
}
}
+ [$logoTextColor, $logoVariant] = generateLogoThemeVariant($logo, $removeBackgroundEnabled);
+
// Insert
$sqlInsert = "INSERT INTO subscriptions (
- name, logo, price, currency_id, next_payment, cycle, frequency, notes,
- payment_method_id, payer_user_id, category_id, notify, inactive, url,
+ name, logo, price, currency_id, next_payment, cycle, frequency, notes,
+ payment_method_id, payer_user_id, category_id, notify, inactive, url,
notify_days_before, user_id, cancellation_date, replacement_subscription_id,
- auto_renew, start_date
+ auto_renew, start_date, logo_text_color, logo_variant
) VALUES (
- :name, :logo, :price, :currencyId, :nextPayment, :cycle, :frequency, :notes,
- :paymentMethodId, :payerUserId, :categoryId, :notify, :inactive, :url,
+ :name, :logo, :price, :currencyId, :nextPayment, :cycle, :frequency, :notes,
+ :paymentMethodId, :payerUserId, :categoryId, :notify, :inactive, :url,
:notifyDaysBefore, :userId, :cancellationDate, :replacement_subscription_id,
- :autoRenew, :startDate
+ :autoRenew, :startDate, :logoTextColor, :logoVariant
)";
$stmtInsert = $db->prepare($sqlInsert);
$stmtInsert->bindParam(':name', $name, SQLITE3_TEXT);
$stmtInsert->bindParam(':logo', $logo, SQLITE3_TEXT);
+ $stmtInsert->bindParam(':logoTextColor', $logoTextColor, SQLITE3_TEXT);
+ $stmtInsert->bindParam(':logoVariant', $logoVariant, SQLITE3_TEXT);
$stmtInsert->bindParam(':price', $price, SQLITE3_FLOAT);
$stmtInsert->bindParam(':currencyId', $currencyId, SQLITE3_INTEGER);
$stmtInsert->bindParam(':nextPayment', $nextPayment, SQLITE3_TEXT);
@@ -759,45 +802,58 @@ switch ($action) {
// Process Logo
$logo = $subscription['logo'];
+ $logoTextColor = $subscription['logo_text_color'];
+ $logoVariant = $subscription['logo_variant'];
+ $logoChanged = false;
$logoUrl = $_POST['logo_url'] ?? $_POST['logo-url'] ?? '';
if ($logoUrl !== "") {
$resLogo = getLogoFromUrl($logoUrl, '../../images/uploads/logos/', $name, $settings);
if ($resLogo['success']) {
$logo = $resLogo['filename'];
+ $logoChanged = true;
}
} elseif (!empty($_FILES['logo']['name'])) {
$fileType = mime_content_type($_FILES['logo']['tmp_name']);
if (strpos($fileType, 'image') !== false) {
$logo = resizeAndUploadLogo($_FILES['logo'], '../../images/uploads/logos/', $name, $settings);
+ $logoChanged = true;
}
}
+ if ($logoChanged) {
+ [$logoTextColor, $logoVariant] = generateLogoThemeVariant($logo, $removeBackgroundEnabled);
+ }
+
// Update
- $sqlUpdate = "UPDATE subscriptions SET
- name = :name,
+ $sqlUpdate = "UPDATE subscriptions SET
+ name = :name,
logo = :logo,
- price = :price,
+ logo_text_color = :logoTextColor,
+ logo_variant = :logoVariant,
+ price = :price,
currency_id = :currencyId,
- next_payment = :nextPayment,
+ next_payment = :nextPayment,
auto_renew = :autoRenew,
start_date = :startDate,
- cycle = :cycle,
- frequency = :frequency,
- notes = :notes,
+ cycle = :cycle,
+ frequency = :frequency,
+ notes = :notes,
payment_method_id = :paymentMethodId,
- payer_user_id = :payerUserId,
- category_id = :categoryId,
- notify = :notify,
- inactive = :inactive,
- url = :url,
- notify_days_before = :notifyDaysBefore,
- cancellation_date = :cancellationDate,
+ payer_user_id = :payerUserId,
+ category_id = :categoryId,
+ notify = :notify,
+ inactive = :inactive,
+ url = :url,
+ notify_days_before = :notifyDaysBefore,
+ cancellation_date = :cancellationDate,
replacement_subscription_id = :replacement_subscription_id
WHERE id = :id AND user_id = :userId";
-
+
$stmtUpdate = $db->prepare($sqlUpdate);
$stmtUpdate->bindParam(':name', $name, SQLITE3_TEXT);
$stmtUpdate->bindParam(':logo', $logo, SQLITE3_TEXT);
+ $stmtUpdate->bindParam(':logoTextColor', $logoTextColor, SQLITE3_TEXT);
+ $stmtUpdate->bindParam(':logoVariant', $logoVariant, SQLITE3_TEXT);
$stmtUpdate->bindParam(':price', $price, SQLITE3_FLOAT);
$stmtUpdate->bindParam(':currencyId', $currencyId, SQLITE3_INTEGER);
$stmtUpdate->bindParam(':nextPayment', $nextPayment, SQLITE3_TEXT);
diff --git a/includes/version.php b/includes/version.php
index 1364c2e..0834a3b 100644
--- a/includes/version.php
+++ b/includes/version.php
@@ -1,3 +1,3 @@
<?php
-$version = "v5.1.1";
+$version = "v5.2.0";
?>
diff --git a/scripts/i18n/nl.js b/scripts/i18n/nl.js
index 3a47e1e..6c89279 100644
--- a/scripts/i18n/nl.js
+++ b/scripts/i18n/nl.js
@@ -45,6 +45,6 @@ let i18n = {
paid_by: "Betaald door",
payment_method: "Betaalmethode",
notes: "Notities",
- export: "Exporteren"
+ export: "Exporteren",
no_results_found: "Geen resultaten gevonden",
}
diff --git a/scripts/subscriptions.js b/scripts/subscriptions.js
index 4890bec..93157de 100644
--- a/scripts/subscriptions.js
+++ b/scripts/subscriptions.js
@@ -319,11 +319,16 @@ function searchLogo() {
const logoSearchPopup = document.querySelector("#logo-search-results");
const logoResults = document.querySelector("#logo-search-images");
+ const logoNav = document.querySelector("#logo-search-nav");
const logoSearchBackdrop = document.querySelector("#logo-search-backdrop");
logoSearchPopup.classList.add("is-open");
if (logoSearchBackdrop) {
logoSearchBackdrop.classList.add("is-open");
}
+ const subscriptionForm = document.querySelector("#subscription-form");
+ if (subscriptionForm) {
+ subscriptionForm.classList.add("scroll-locked");
+ }
const logoSearchTitle = document.querySelector("#logo-search-title");
if (logoSearchTitle) {
const baseTitle = logoSearchTitle.dataset.title;
@@ -344,6 +349,9 @@ function searchLogo() {
}
logoResults.innerHTML = "";
+ if (logoNav) {
+ logoNav.innerHTML = "";
+ }
sources.forEach(source => {
const section = document.createElement("div");
@@ -360,6 +368,18 @@ function searchLogo() {
logoResults.appendChild(section);
showSearchState(resultsContainer, 'loading');
+ if (logoNav) {
+ const navItem = document.createElement("button");
+ navItem.type = "button";
+ navItem.className = "logo-search-nav-item";
+ navItem.textContent = source.label;
+ navItem.onclick = function () {
+ const targetTop = section.getBoundingClientRect().top - logoResults.getBoundingClientRect().top + logoResults.scrollTop;
+ logoResults.scrollTo({ top: targetTop, behavior: 'smooth' });
+ };
+ logoNav.appendChild(navItem);
+ }
+
fetch(source.url)
.then(response => response.json())
.then(data => {
@@ -411,6 +431,10 @@ function closeLogoSearch() {
if (logoSearchBackdrop) {
logoSearchBackdrop.classList.remove("is-open");
}
+ const subscriptionForm = document.querySelector("#subscription-form");
+ if (subscriptionForm) {
+ subscriptionForm.classList.remove("scroll-locked");
+ }
const logoSearchTitle = document.querySelector("#logo-search-title");
if (logoSearchTitle) {
logoSearchTitle.textContent = logoSearchTitle.dataset.title;
diff --git a/styles/styles.css b/styles/styles.css
index 4b4ec85..f28153b 100644
--- a/styles/styles.css
+++ b/styles/styles.css
@@ -1650,7 +1650,7 @@ textarea.thin {
.logo-search-backdrop,
.icon-search-backdrop {
- display: none;
+ display: block;
position: fixed;
left: 0;
top: 0;
@@ -1659,11 +1659,16 @@ textarea.thin {
background-color: rgba(0, 0, 0, 0.4);
backdrop-filter: blur(3px);
z-index: 21;
+ opacity: 0;
+ visibility: hidden;
+ transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}
.logo-search-backdrop.is-open,
.icon-search-backdrop.is-open {
- display: block;
+ opacity: 1;
+ visibility: visible;
+ transition: opacity 0.25s ease;
}
.logo-search,
@@ -1764,13 +1769,38 @@ textarea.thin {
display: none;
}
+.logo-search-nav {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px;
+ margin: 0 0 12px;
+ flex-shrink: 0;
+}
+
+.logo-search-nav-item {
+ border: 1px solid var(--input-border-color);
+ background-color: var(--input-background-color);
+ color: var(--text-muted);
+ font-size: 12px;
+ font-weight: 600;
+ padding: 5px 10px;
+ border-radius: 999px;
+ cursor: pointer;
+ transition: color 0.15s, border-color 0.15s;
+}
+
+.logo-search-nav-item:hover {
+ color: var(--text-color);
+ border-color: var(--main-color);
+}
+
.logo-search-section>h4 {
margin: 0px 0px 6px;
- font-size: 11px;
- font-weight: 600;
- letter-spacing: 0.06em;
+ font-size: 13px;
+ font-weight: 700;
+ letter-spacing: 0.04em;
text-transform: uppercase;
- color: var(--text-muted);
+ color: var(--text-color);
}
.logo-search-section-results {
@@ -1896,6 +1926,13 @@ button.dark-theme-button i {
overflow-y: auto;
width: 90%;
display: none;
+ scrollbar-width: none;
+ -ms-overflow-style: none;
+}
+
+.subscription-form::-webkit-scrollbar,
+.subscription-modal::-webkit-scrollbar {
+ display: none;
}
.subscription-form.is-open,
@@ -1903,6 +1940,10 @@ button.dark-theme-button i {
display: block;
}
+.subscription-form.scroll-locked {
+ overflow: hidden;
+}
+
.subscription-form h3,
.subscription-modal h3 {
padding-bottom: 15px;
@@ -3689,17 +3730,22 @@ body.details-open {
}
.details-backdrop {
- display: none;
+ display: block;
position: fixed;
inset: 0;
background-color: rgba(10, 14, 22, 0.45);
-webkit-backdrop-filter: blur(3px);
backdrop-filter: blur(3px);
z-index: 19;
+ opacity: 0;
+ visibility: hidden;
+ transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}
.details-backdrop.is-open {
- display: block;
+ opacity: 1;
+ visibility: visible;
+ transition: opacity 0.25s ease;
}
.subscription-details {
@@ -3961,17 +4007,34 @@ body.details-open {
.subscription-details,
.logo-search,
.icon-search {
+ display: block;
left: 0px;
right: 0px;
top: auto;
bottom: 0px;
- transform: none;
+ transform: translateY(100%);
+ visibility: hidden;
width: 100%;
max-width: none;
max-height: 70dvh;
border-radius: 20px 20px 0px 0px;
border-bottom: none;
padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
+ transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0.32s;
+ }
+
+ .logo-search,
+ .icon-search {
+ display: flex;
+ flex-direction: column;
+ }
+
+ .subscription-details.is-open,
+ .logo-search.is-open,
+ .icon-search.is-open {
+ transform: translateY(0);
+ visibility: visible;
+ transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}
.mobile-navigation .subscription-details {
@@ -4019,7 +4082,7 @@ body.details-open {
display: flex;
flex-direction: column;
justify-content: center;
- gap: 2px;
+ gap: 6px;
position: absolute;
inset: 0;
transform: rotateY(180deg);
@@ -4027,7 +4090,7 @@ body.details-open {
backface-visibility: hidden;
background-color: var(--box-background-color);
border-radius: inherit;
- padding: 14px 12px;
+ padding: 12px 10px;
box-sizing: border-box;
overflow-y: auto;
}
@@ -4046,14 +4109,14 @@ body.details-open {
align-items: center;
gap: 10px;
width: 100%;
- border: none;
- background-color: transparent;
+ border: 1px solid var(--input-border-color);
+ background-color: var(--input-background-color);
color: var(--text-color);
font-family: Barlow, 'Helvetica Neue', Helvetica, sans-serif;
- font-size: 14px;
- font-weight: 500;
+ font-size: 15px;
+ font-weight: 600;
text-align: start;
- padding: 10px 12px;
+ padding: 8px 12px;
border-radius: 8px;
cursor: pointer;
box-sizing: border-box;
@@ -4061,17 +4124,19 @@ body.details-open {
.subscription-back .back-action:hover {
background-color: var(--surface-hover);
+ border-color: var(--main-color);
}
.subscription-back .back-action>i {
color: var(--main-color);
- font-size: 14px;
+ font-size: 15px;
width: 18px;
text-align: center;
}
.subscription-back .back-action.delete:hover {
background-color: rgba(var(--error-color-rgb), 0.1);
+ border-color: var(--error-color);
}
.subscription-back .back-action.delete:hover>i {
@@ -4109,14 +4174,19 @@ body.details-open {
@media (max-width: 768px) {
.subscriptions.grid-view .subscription-back {
- padding: 10px 8px;
+ padding: 8px;
+ gap: 4px;
}
.subscription-back .back-action {
- font-size: 13px;
- padding: 7px 10px;
+ font-size: 14px;
+ padding: 6px 10px;
gap: 8px;
}
+
+ .subscription-back .back-action>i {
+ font-size: 14px;
+ }
}
.stats-section {
diff --git a/subscriptions.php b/subscriptions.php
index 18982db..2afb1fb 100644
--- a/subscriptions.php
+++ b/subscriptions.php
@@ -338,6 +338,7 @@ $subscriptionsView = (isset($_COOKIE['subscriptionsView']) && $_COOKIE['subscrip
<?= translate('web_search', $i18n) ?>
</h3>
</header>
+ <div id="logo-search-nav" class="logo-search-nav"></div>
<div id="logo-search-images"></div>
</div>
</div>