Skip to content

Commit

Permalink
feat: cache logos for offline use
Browse files Browse the repository at this point in the history
fix: don't allow saving main and accent colors if they're the same
feat: rework styles of theme section on settings page
feat: more uniform and aligned styles on the settings page
feat: ability to add custom css styles
  • Loading branch information
ellite authored Jul 3, 2024
1 parent d721a49 commit 50bd104
Show file tree
Hide file tree
Showing 30 changed files with 744 additions and 334 deletions.
37 changes: 37 additions & 0 deletions endpoints/settings/customcss.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

require_once '../../includes/connect_endpoint.php';

if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
die(json_encode([
"success" => false,
"message" => translate('session_expired', $i18n)
]));
}

if ($_SERVER["REQUEST_METHOD"] === "POST") {
$postData = file_get_contents("php://input");
$data = json_decode($postData, true);

$customCss = $data['customCss'];

$stmt = $db->prepare('DELETE FROM custom_css_style WHERE user_id = :userId');
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
$stmt->execute();

$stmt = $db->prepare('INSERT INTO custom_css_style (css, user_id) VALUES (:customCss, :userId)');
$stmt->bindParam(':customCss', $customCss, SQLITE3_TEXT);
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);

if ($stmt->execute()) {
die(json_encode([
"success" => true,
"message" => translate("success", $i18n)
]));
} else {
die(json_encode([
"success" => false,
"message" => translate("error", $i18n)
]));
}
}
10 changes: 9 additions & 1 deletion endpoints/settings/customtheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
$accent_color = $data['accentColor'];
$hover_color = $data['hoverColor'];

$stmt = $db->prepare('DELETE FROM custom_colors');
if ($main_color == $accent_color) {
die(json_encode([
"success" => false,
"message" => translate("main_accent_color_error", $i18n)
]));
}

$stmt = $db->prepare('DELETE FROM custom_colors WHERE user_id = :userId');
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
$stmt->execute();

$stmt = $db->prepare('INSERT INTO custom_colors (main_color, accent_color, hover_color, user_id) VALUES (:main_color, :accent_color, :hover_color, :userId)');
Expand Down
9 changes: 9 additions & 0 deletions includes/getsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
$settings['customColors'] = $customColors;
}

$query = "SELECT * FROM custom_css_style WHERE user_id = :userId";
$stmt = $db->prepare($query);
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
$result = $stmt->execute();
$customCss = $result->fetchArray(SQLITE3_ASSOC);
if ($customCss) {
$settings['customCss'] = $customCss['css'];
}

$query = "SELECT * FROM admin";
$result = $db->query($query);
$adminSettings = $result->fetchArray(SQLITE3_ASSOC);
Expand Down
25 changes: 25 additions & 0 deletions includes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,27 @@
$colorTheme = $settings['color_theme'];
}

$customCss = "";
if (isset($settings['customCss'])) {
$customCss = $settings['customCss'];
}

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

function hex2rgb($hex) {
$hex = str_replace("#", "", $hex);
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
}
return "$r, $g, $b";
}

?>
<!DOCTYPE html>
<html dir="<?= $languages[$lang]['dir'] ?>">
Expand Down Expand Up @@ -64,19 +83,25 @@
window.lang = "<?=$lang ?>";
window.colorTheme = "<?= $colorTheme ?>";
</script>
<style>
<?= htmlspecialchars($customCss, ENT_QUOTES, 'UTF-8') ?>
</style>
<?php
if (isset($settings['customColors'])) {
?>
<style id="custom_theme_colors">
:root {
<?php if (isset($settings['customColors']['main_color']) && !empty($settings['customColors']['main_color'])): ?>
--main-color: <?= $settings['customColors']['main_color'] ?>;
--main-color-rgb: <?= hex2rgb($settings['customColors']['main_color']) ?>;
<?php endif; ?>
<?php if (isset($settings['customColors']['accent_color']) && !empty($settings['customColors']['accent_color'])): ?>
--accent-color: <?= $settings['customColors']['accent_color'] ?>;
--accent-color-rgb: <?= hex2rgb($settings['customColors']['accent_color']) ?>;
<?php endif; ?>
<?php if (isset($settings['customColors']['hover_color']) && !empty($settings['customColors']['hover_color'])): ?>
--hover-color: <?= $settings['customColors']['hover_color'] ?>;
--hover-color-rgb: <?= hex2rgb($settings['customColors']['hover_color']) ?>;
<?php endif; ?>
}
</style>
Expand Down
11 changes: 11 additions & 0 deletions includes/i18n/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,19 @@
"get_key_alternative" => "Alternativ können Sie einen kostenlosen Fixer-Api-Schlüssel erhalten von",
"display_settings" => "Display-Einstellungen",
"theme_settings" => "Themen-Einstellungen",
"colors" => "Farben",
"custom_colors" => "Benutzerdefinierte Farben",
"theme" => "Thema",
"dark_theme" => "Dark Theme",
"light_theme" => "Light Theme",
"automatic"=> "Automatisch",
"main_color" => "Hauptfarbe",
"accent_color" => "Akzentfarbe",
"hover_color" => "Hover Farbe",
"custom_css" => "Benutzerdefiniertes CSS",
"save_custom_css" => "Benutzerdefiniertes CSS speichern",
"save_custom_colors" => "Benutzerdefinierte Farben speichern",
"reset_custom_colors" => "Benutzerdefinierte Farben zurücksetzen",
"calculate_monthly_price" => "Berechne und zeige monatlichen Preis für alle Abonnements an",
"convert_prices" => "Preise immer in meine Hauptwährung umrechnen und darin anzeigen (langsamer)",
"hide_disabled_subscriptions" => "Deaktivierte Abonnements verstecken",
Expand All @@ -202,6 +212,7 @@
"add" => "Hinzufügen",
"save" => "Speichern",
"reset" => "Zurücksetzen",
"main_accent_color_error" => "Haupt- und Akzentfarbe dürfen nicht identisch sein",
"backup_and_restore" => "Backup und Wiederherstellung",
"backup" => "Backup",
"restore" => "Wiederherstellen",
Expand Down
11 changes: 11 additions & 0 deletions includes/i18n/el.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,19 @@
"get_key_alternative" => "Εναλλακτικά, μπορείτε να λάβετε ένα δωρεάν κλειδί api fixer από το",
"display_settings" => "Ρυθμίσεις εμφάνισης",
"theme_settings" => "Ρυθμίσεις θέματος",
"colors" => "Χρώματα",
"custom_colors" => "Προσαρμοσμένα χρώματα",
"theme" => "Θέμα",
"dark_theme" => "Dark Theme",
"light_theme" => "Light Theme",
"automatic"=> "Αυτόματο",
"main_color" => "Κύριο χρώμα",
"accent_color" => "Χρώμα επισήμανσης",
"hover_color" => "Χρώμα πάνω από",
"save_custom_colors" => "Αποθήκευση προσαρμοσμένων χρωμάτων",
"reset_custom_colors" => "Επαναφορά προεπιλεγμένων χρωμάτων",
"custom_css" => "Προσαρμοσμένο CSS",
"save_custom_css" => "Αποθήκευση προσαρμοσμένου CSS",
"calculate_monthly_price" => "Υπολογισμός και εμφάνιση της μηνιαίας τιμής για όλες τις συνδρομές",
"convert_prices" => "Πάντα να μετατρέπει και να εμφανίζει τις τιμές στο κύριο νόμισμά μου (πιο αργό)",
"hide_disabled_subscriptions" => "Απόκρυψη απενεργοποιημένων συνδρομών",
Expand All @@ -202,6 +212,7 @@
"add" => "Προσθήκη",
"save" => "Αποθήκευση",
"reset" => "Επαναφορά",
"main_accent_color_error" => "Το κύριο χρώμα δεν μπορεί να είναι το ίδιο με το χρώμα επισήμανσης",
"backup_and_restore" => "Αντίγραφο ασφαλείας και επαναφορά",
"backup" => "Αντίγραφο ασφαλείας",
"restore" => "Επαναφορά",
Expand Down
11 changes: 11 additions & 0 deletions includes/i18n/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,19 @@
"get_key_alternative" => "Alternatively, you can get a free fixer api key from",
"display_settings" => "Display Settings",
"theme_settings" => "Theme Settings",
"colors" => "Colors",
"custom_colors" => "Custom Colors",
"theme" => "Theme",
"dark_theme" => "Dark Theme",
"light_theme" => "Light Theme",
"automatic"=> "Automatic",
"main_color" => "Main Color",
"accent_color" => "Accent Color",
"hover_color" => "Hover Color",
"save_custom_colors" => "Save Custom Colors",
"reset_custom_colors" => "Reset Custom Colors",
"custom_css" => "Custom CSS",
"save_custom_css" => "Save Custom CSS",
"calculate_monthly_price" => "Calculate and show monthly price for all subscriptions",
"convert_prices" => "Always convert and show prices on my main currency (slower)",
"hide_disabled_subscriptions" => "Hide disabled subscriptions",
Expand All @@ -202,6 +212,7 @@
"add" => "Add",
"save" => "Save",
"reset" => "Reset",
"main_accent_color_error" => "Main and accent color can't be the same",
"backup_and_restore" => "Backup and Restore",
"backup" => "Backup",
"restore" => "Restore",
Expand Down
11 changes: 11 additions & 0 deletions includes/i18n/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,19 @@
"get_key_alternative" => "También puede obtener una clave api gratuita de Fixer en",
"display_settings" => "Configuración de Pantalla",
"theme_settings" => "Configuración de Tema",
"colors" => "Colores",
"custom_collors" => "Colores Personalizados",
"theme" => "Tema",
"dark_theme" => "Tema Oscuro",
"light_theme" => "Tema Claro",
"automatic"=> "Automático",
"main_color" => "Color Principal",
"accent_color" => "Color de Acento",
"hover_color" => "Color de Hover",
"save_custom_colors" => "Guardar Colores Personalizados",
"reset_custom_colors" => "Restablecer Colores Personalizados",
"custom_css" => "CSS Personalizado",
"save_custom_css" => "Guardar CSS Personalizado",
"calculate_monthly_price" => "Calcular y mostrar el precio mensual de todas las suscripciones",
"convert_prices" => "Convertir y mostrar siempre los precios en mi moneda principal (más lento)",
"hide_disabled_subscriptions" => "Ocultar suscripciones desactivadas",
Expand All @@ -202,6 +212,7 @@
"add" => "Agregar",
"save" => "Guardar",
"reset" => "Restablecer",
"main_accent_color_error" => "El color principal y el color de acento no pueden ser iguales",
"backup_and_restore" => "Copia de Seguridad y Restauración",
"backup" => "Copia de Seguridad",
"restore" => "Restaurar",
Expand Down
11 changes: 11 additions & 0 deletions includes/i18n/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,19 @@
"get_key_alternative" => "Vous pouvez également obtenir une clé api de fixation gratuite auprès de",
"display_settings" => "Paramètres d'affichage",
"theme_settings" => "Paramètres de thème",
"colors" => "Couleurs",
"custom_colors" => "Couleurs personnalisées",
"theme" => "Thème",
"dark_theme" => "Thème sombre",
"light_theme" => "Thème clair",
"automatic"=> "Automatique",
"main_color" => "Couleur principale",
"accent_color" => "Couleur d'accent",
"hover_color" => "Couleur de survol",
"save_custom_colors" => "Enregistrer les couleurs personnalisées",
"reset_custom_colors" => "Réinitialiser les couleurs personnalisées",
"custom_css" => "CSS personnalisé",
"save_custom_css" => "Enregistrer le CSS personnalisé",
"calculate_monthly_price" => "Calculer et afficher le prix mensuel pour tous les abonnements",
"convert_prices" => "Convertir toujours et afficher les prix dans ma devise principale (plus lent)",
"hide_disabled_subscriptions" => "Masquer les abonnements désactivés",
Expand All @@ -202,6 +212,7 @@
"add" => "Ajouter",
"save" => "Enregistrer",
"reset" => "Réinitialiser",
"main_accent_color_error" => "La couleur principale et la couleur d'accent ne peuvent pas être identiques",
"backup_and_restore" => "Sauvegarde et restauration",
"backup" => "Sauvegarde",
"restore" => "Restauration",
Expand Down
11 changes: 11 additions & 0 deletions includes/i18n/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,19 @@
'get_key_alternative' => 'In alternativa, puoi ottenere gratuitamente una chiave API di Fixer da',
'display_settings' => 'Impostazioni di visualizzazione',
"theme_settings" => 'Impostazioni del tema',
"colors" => 'Colori',
"custom_colors" => 'Colori personalizzati',
"theme" => 'Tema',
"dark_theme" => 'Tema scuro',
"light_theme" => 'Tema chiaro',
"automatic" => "Automatico",
"main_color" => "Colore principale",
"accent_color" => "Colore di accento",
"hover_color" => "Colore al passaggio del mouse",
"save_custom_colors" => "Salva colori personalizzati",
"reset_custom_colors" => "Ripristina colori personalizzati",
"custom_css" => "CSS personalizzato",
"save_custom_css" => "Salva CSS personalizzato",
'calculate_monthly_price' => 'Calcola e mostra il prezzo mensile per tutti gli abbonamenti',
'convert_prices' => 'Converti sempre e mostra i prezzi nella mia valuta principale (più lento)',
"hide_disabled_subscriptions" => 'Nascondi gli abbonamenti disattivati',
Expand All @@ -210,6 +220,7 @@
'add' => 'Aggiungi',
'save' => 'Salva',
"reset" => 'Ripristina',
"main_accent_color_error" => 'Il colore principale e il colore di accento non possono essere uguali',
"backup_and_restore" => 'Backup e ripristino',
"backup" => 'Backup',
"restore" => 'Ripristina',
Expand Down
11 changes: 11 additions & 0 deletions includes/i18n/jp.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,19 @@
"get_key_alternative" => "または、以下のサイトから無料のフィクサーapiキーを入手することもできます。",
"display_settings" => "表示設定",
"theme_settings" => "テーマ設定",
"colors" => "",
"custom_colors" => "カスタムカラー",
"theme" => "テーマ",
"dark_theme" => "ダークテーマ",
"light_theme" => "ライトテーマ",
"automatic"=> "自動",
"main_color" => "メインカラー",
"accent_color" => "アクセントカラー",
"hover_color" => "ホバーカラー",
"save_custom_colors" => "カスタムカラーを保存",
"reset_custom_colors" => "カスタムカラーをリセット",
"custom_css" => "カスタムCSS",
"save_custom_css" => "カスタムCSSを保存",
"calculate_monthly_price" => "すべての定期購入の月額料金を計算して表示する",
"convert_prices" => "常にメイン通貨で価格を換算して表示する (遅い)",
"hide_disabled_subscriptions" => "無効な定期購入を非表示にする",
Expand All @@ -202,6 +212,7 @@
"add" => "追加",
"save" => "保存",
"reset" => "リセット",
"main_accent_color_error" => "メインカラーとアクセントカラーは同じにすることはできません",
"backup_and_restore" => "バックアップとリストア",
"backup" => "バックアップ",
"restore" => "リストア",
Expand Down
11 changes: 11 additions & 0 deletions includes/i18n/ko.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,19 @@
"get_key_alternative" => "또는 다음 사이트에서 무료 Fixer api 키를 얻을 수 있습니다.",
"display_settings" => "디스플레이 설정",
"theme_settings" => "테마 설정",
"colors" => "색상",
"custom_colors" => "커스텀 색상",
"theme" => "테마",
"dark_theme" => "다크 테마",
"light_theme" => "라이트 테마",
"automatic"=> "자동",
"main_color" => "메인 색상",
"accent_color" => "강조 색상",
"hover_color" => "마우스 호버 색상",
"save_custom_colors" => "커스텀 색상 저장",
"reset_custom_colors" => "커스텀 색상 리셋",
"custom_css" => "커스텀 CSS",
"save_custom_css" => "커스텀 CSS 저장",
"calculate_monthly_price" => "모든 구독에 대한 월별 요금을 계산하고 표시",
"convert_prices" => "항상 기본 통화로 가격을 환산하고 표시 (느림)",
"hide_disabled_subscriptions" => "비활성화된 구독 숨기기",
Expand All @@ -203,6 +213,7 @@
"add" => "추가",
"save" => "저장",
"reset" => "리셋",
"main_accent_color_error" => "메인 색상과 강조 색상은 같을 수 없습니다.",
"backup_and_restore" => "백업 및 복구",
"backup" => "백업",
"restore" => "복구",
Expand Down
11 changes: 11 additions & 0 deletions includes/i18n/pl.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,19 @@
"get_key_alternative" => "Alternatywnie, możesz uzyskać darmowy klucz api fixer'a od",
"display_settings" => "Ustawienia wyświetlania",
"theme_settings" => "Ustawienia motywu",
"colors" => "Kolory",
"custom_colors" => "Kolory niestandardowe",
"theme" => "Motyw",
"dark_theme" => "Przełącz na jasny/ciemny motyw",
"light_theme" => "Przełącz na ciemny/jasny motyw",
"automatic"=> "Automatycznie",
"main_color" => "Główny kolor",
"accent_color" => "Kolor akcentowy",
"hover_color" => "Kolor najechania",
"save_custom_colors" => "Zapisz niestandardowe kolory",
"reset_custom_colors" => "Resetuj niestandardowe kolory",
"custom_css" => "Niestandardowy CSS",
"save_custom_css" => "Zapisz niestandardowy CSS",
"calculate_monthly_price" => "Oblicz i pokaż miesięczną cenę wszystkich subskrypcji",
"convert_prices" => "Zawsze przeliczaj i pokazuj ceny w mojej głównej walucie (wolniej)",
"hide_disabled_subscriptions" => "Ukryj wyłączone subskrypcje",
Expand All @@ -202,6 +212,7 @@
"add" => "Dodaj",
"save" => "Zapisz",
"reset" => "Resetuj",
"main_accent_color_error" => "Kolor główny i akcentowy nie mogą być takie same",
"backup_and_restore" => "Kopia zapasowa i przywracanie",
"backup" => "Kopia zapasowa",
"restore" => "Przywróć",
Expand Down
Loading

0 comments on commit 50bd104

Please sign in to comment.