Skip to content

Commit

Permalink
use users browser locale to set the dates on the dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Ribeiro committed Sep 29, 2024
1 parent 8715b90 commit 6ae7d63
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
11 changes: 10 additions & 1 deletion endpoints/subscriptions/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
$colorTheme = $settings['color_theme'];
}

$locale = isset($_COOKIE['user_locale']) ? $_COOKIE['user_locale'] : 'en_US';
$formatter = new IntlDateFormatter(
$locale,
IntlDateFormatter::MEDIUM,
IntlDateFormatter::NONE
);

if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {


Expand Down Expand Up @@ -146,7 +153,9 @@
$paymentMethodId = $subscription['payment_method_id'];
$print[$id]['currency_code'] = $currencies[$subscription['currency_id']]['code'];
$currencyId = $subscription['currency_id'];
$print[$id]['next_payment'] = date('M d, Y', strtotime($subscription['next_payment']));
$next_payment_timestamp = strtotime($subscription['next_payment']);
$formatted_date = $formatter->format($next_payment_timestamp);
$print[$id]['next_payment'] = $formatted_date;
$paymentIconFolder = (strpos($payment_methods[$paymentMethodId]['icon'], 'images/uploads/icons/') !== false) ? "" : "images/uploads/logos/";
$print[$id]['payment_method_icon'] = $paymentIconFolder . $payment_methods[$paymentMethodId]['icon'];
$print[$id]['payment_method_name'] = $payment_methods[$paymentMethodId]['name'];
Expand Down
7 changes: 7 additions & 0 deletions includes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@

$isAdmin = $_SESSION['userId'] == 1;

$locale = isset($_COOKIE['user_locale']) ? $_COOKIE['user_locale'] : 'en_US';
$formatter = new IntlDateFormatter(
$locale,
IntlDateFormatter::MEDIUM,
IntlDateFormatter::NONE
);

function hex2rgb($hex)
{
$hex = str_replace("#", "", $hex);
Expand Down
2 changes: 1 addition & 1 deletion includes/version.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php
$version = "v2.25.0";
$version = "v2.26.0";
?>
4 changes: 3 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@
$paymentMethodId = $subscription['payment_method_id'];
$print[$id]['currency_code'] = $currencies[$subscription['currency_id']]['code'];
$currencyId = $subscription['currency_id'];
$print[$id]['next_payment'] = date('M d, Y', strtotime($subscription['next_payment']));
$next_payment_timestamp = strtotime($subscription['next_payment']);
$formatted_date = $formatter->format($next_payment_timestamp);
$print[$id]['next_payment'] = $formatted_date;
$paymentIconFolder = (strpos($payment_methods[$paymentMethodId]['icon'], 'images/uploads/icons/') !== false) ? "" : "images/uploads/logos/";
$print[$id]['payment_method_icon'] = $paymentIconFolder . $payment_methods[$paymentMethodId]['icon'];
$print[$id]['payment_method_name'] = $payment_methods[$paymentMethodId]['name'];
Expand Down
3 changes: 3 additions & 0 deletions scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ function showSuccessMessage(message) {

document.addEventListener('DOMContentLoaded', function () {

const userLocale = navigator.language || navigator.languages[0];
document.cookie = `user_locale=${userLocale}; expires=Fri, 31 Dec 9999 23:59:59 GMT; SameSite=Strict`;

if (window.update_theme_settings) {
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
const themePreference = prefersDarkMode ? 'dark' : 'light';
Expand Down
21 changes: 12 additions & 9 deletions scripts/login.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
document.addEventListener('DOMContentLoaded', function () {

if (window.update_theme_settings) {
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
const themePreference = prefersDarkMode ? 'dark' : 'light';
const darkThemeCss = document.querySelector("#dark-theme");
darkThemeCss.disabled = themePreference === 'light';
document.body.className = themePreference;
const themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
themeColorMetaTag.setAttribute('content', themePreference === 'dark' ? '#222222' : '#FFFFFF');
}
const userLocale = navigator.language || navigator.languages[0];
document.cookie = `user_locale=${userLocale}; expires=Fri, 31 Dec 9999 23:59:59 GMT; SameSite=Strict`;

if (window.update_theme_settings) {
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
const themePreference = prefersDarkMode ? 'dark' : 'light';
const darkThemeCss = document.querySelector("#dark-theme");
darkThemeCss.disabled = themePreference === 'light';
document.body.className = themePreference;
const themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
themeColorMetaTag.setAttribute('content', themePreference === 'dark' ? '#222222' : '#FFFFFF');
}

});

0 comments on commit 6ae7d63

Please sign in to comment.