From 6482fbe2ba947c54d8e91b6b40ad4c58bc8a7ac9 Mon Sep 17 00:00:00 2001 From: Qetesh <4559341+Qetesh@users.noreply.github.com> Date: Mon, 18 Nov 2024 15:39:18 +0800 Subject: [PATCH 1/3] feat: add iCalendar Subscription --- api/subscriptions/get_subscriptions.php | 57 +++++++++++++++++++++++++ calendar.php | 37 ++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/api/subscriptions/get_subscriptions.php b/api/subscriptions/get_subscriptions.php index fc118669a..d960f628f 100644 --- a/api/subscriptions/get_subscriptions.php +++ b/api/subscriptions/get_subscriptions.php @@ -306,6 +306,63 @@ function getPriceConverted($price, $currency, $database) $subscriptionsToReturn[] = $subscriptionToReturn; } + if (isset($_REQUEST['type'])) { + $type = $_REQUEST['type']; + $stmt->bindValue(':inactive', false, SQLITE3_INTEGER); + $result = $stmt->execute(); + + if ($type == "iCalendar") { + header('Content-Type: text/calendar; charset=utf-8'); + header('Content-Disposition: attachment; filename="subscriptions.ics"'); + + if ($result === false) { + die("BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:NAME:\nEND:VCALENDAR"); + } + + $icsContent = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Wallos//$type//EN\nNAME:Wallos\nX-WR-CALNAME:Wallos\n"; + + while ($subscription = $result->fetchArray(SQLITE3_ASSOC)) { + $subscription['payer_user'] = $members[$subscription['payer_user_id']]; + $subscription['category'] = $categories[$subscription['category_id']]; + $subscription['payment_method'] = $paymentMethods[$subscription['payment_method_id']]; + $subscription['currency'] = $currencies[$subscription['currency_id']]['symbol']; + $subscription['trigger'] = $subscription['notify_days_before'] ? $subscription['notify_days_before'] : 1; + $subscription['price'] = number_format($subscription['price'], 2); + + $uid = uniqid(); + $summary = "Wallos: " . $subscription['name']; + $description = "Price: {$subscription['currency']}{$subscription['price']}\\nCategory: {$subscription['category']}\\nPayment Method: {$subscription['payment_method']}\\nPayer: {$subscription['payer_user']}\\nNotes: {$subscription['notes']}"; + $dtstart = (new DateTime($subscription['next_payment']))->format('Ymd\THis\Z'); + $dtend = (new DateTime($subscription['next_payment']))->modify('+1 hour')->format('Ymd\THis\Z'); + $location = isset($subscription['url']) ? $subscription['url'] : ''; + $alarm_trigger = '-' . $subscription['trigger'] . 'D'; + + $icsContent .= <<close(); + exit; + } + } $response = [ "success" => true, diff --git a/calendar.php b/calendar.php index 66ec25975..19213238a 100644 --- a/calendar.php +++ b/calendar.php @@ -105,6 +105,43 @@ function getPriceConverted($price, $currency, $database, $userId) ?>

Calendar

+ +
+ +
+ + +
+
+ + +
Date: Mon, 18 Nov 2024 19:33:38 +0800 Subject: [PATCH 2/3] fix: copyToClipboard & invalid_api_key --- calendar.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/calendar.php b/calendar.php index 19213238a..4ebea2c21 100644 --- a/calendar.php +++ b/calendar.php @@ -126,6 +126,10 @@ function getPriceConverted($price, $currency, $database, $userId) document.getElementById('iCalendarUrl').value = fullUrl; function showExportPopup() { + if (apiKey === "") { + showErrorMessage( "" ); + return; + } document.getElementById('subscriptions_calendar').classList.add('is-open'); } function closePopup() { @@ -133,12 +137,16 @@ function closePopup() { } function copyToClipboard() { - const urlField = document.getElementById('calendarUrl'); + const urlField = document.getElementById('iCalendarUrl'); urlField.select(); urlField.setSelectionRange(0, 99999); // For mobile devices navigator.clipboard.writeText(urlField.value) - .then(() => {showSuccessMessage(translate('copied_to_clipboard'));}) - .catch(() => {showErrorMessage(translate('unknown_error'))}); + .then(() => { + showSuccessMessage(translate('copied_to_clipboard')); + }) + .catch(() => { + showErrorMessage(translate('unknown_error')); + }); } From c5a64d768a3108adbd309b25779f12aa3d93978f Mon Sep 17 00:00:00 2001 From: Qetesh <4559341+Qetesh@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:38:33 +0800 Subject: [PATCH 3/3] Move const into function --- calendar.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/calendar.php b/calendar.php index 4ebea2c21..8d0ce802b 100644 --- a/calendar.php +++ b/calendar.php @@ -118,14 +118,14 @@ function getPriceConverted($price, $currency, $database, $userId)