-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: persist display and experimental settings on the db
feat: small styles changed
- Loading branch information
Showing
15 changed files
with
242 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
require_once '../../includes/connect_endpoint.php'; | ||
session_start(); | ||
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); | ||
|
||
$convert_currency = $data['value']; | ||
|
||
$stmt = $db->prepare('UPDATE settings SET convert_currency = :convert_currency'); | ||
$stmt->bindParam(':convert_currency', $convert_currency, SQLITE3_INTEGER); | ||
|
||
if ($stmt->execute()) { | ||
die(json_encode([ | ||
"success" => true, | ||
"message" => translate("success", $i18n) | ||
])); | ||
} else { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => translate("error", $i18n) | ||
])); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
require_once '../../includes/connect_endpoint.php'; | ||
session_start(); | ||
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); | ||
|
||
$monthly_price = $data['value']; | ||
|
||
$stmt = $db->prepare('UPDATE settings SET monthly_price = :monthly_price'); | ||
$stmt->bindParam(':monthly_price', $monthly_price, SQLITE3_INTEGER); | ||
|
||
if ($stmt->execute()) { | ||
die(json_encode([ | ||
"success" => true, | ||
"message" => translate("success", $i18n) | ||
])); | ||
} else { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => translate("error", $i18n) | ||
])); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
require_once '../../includes/connect_endpoint.php'; | ||
session_start(); | ||
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); | ||
|
||
$remove_background = $data['value']; | ||
|
||
$stmt = $db->prepare('UPDATE settings SET remove_background = :remove_background'); | ||
$stmt->bindParam(':remove_background', $remove_background, SQLITE3_INTEGER); | ||
|
||
if ($stmt->execute()) { | ||
die(json_encode([ | ||
"success" => true, | ||
"message" => translate("success", $i18n) | ||
])); | ||
} else { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => translate("error", $i18n) | ||
])); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
require_once '../../includes/connect_endpoint.php'; | ||
session_start(); | ||
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); | ||
|
||
$theme = $data['theme']; | ||
|
||
$stmt = $db->prepare('UPDATE settings SET dark_theme = :theme'); | ||
$stmt->bindParam(':theme', $theme, SQLITE3_INTEGER); | ||
|
||
if ($stmt->execute()) { | ||
die(json_encode([ | ||
"success" => true, | ||
"message" => translate("success", $i18n) | ||
])); | ||
} else { | ||
die(json_encode([ | ||
"success" => false, | ||
"message" => translate("error", $i18n) | ||
])); | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
$query = "SELECT * FROM settings"; | ||
$result = $db->query($query); | ||
$settings = $result->fetchArray(SQLITE3_ASSOC); | ||
if ($settings) { | ||
$cookieExpire = time() + (30 * 24 * 60 * 60); | ||
setcookie('theme', $settings['dark_theme'] ? 'dark': 'light', $cookieExpire); | ||
$settings['theme'] = $settings['dark_theme'] ? 'dark': 'light'; | ||
$settings['showMonthlyPrice'] = $settings['monthly_price'] ? 'true': 'false'; | ||
$settings['convertCurrency'] = $settings['convert_currency'] ? 'true': 'false'; | ||
$settings['removeBackground'] = $settings['remove_background'] ? 'true': 'false'; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<?php | ||
$version = "v1.3.0"; | ||
$version = "v1.4.0"; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
// This migration adds a new table to store the display and experimental settings | ||
// This settings will now be persisted across sessions and devices | ||
|
||
/** @noinspection PhpUndefinedVariableInspection */ | ||
$db->exec('CREATE TABLE IF NOT EXISTS settings ( | ||
dark_theme BOOLEAN DEFAULT 0, | ||
monthly_price BOOLEAN DEFAULT 0, | ||
convert_currency BOOLEAN DEFAULT 0, | ||
remove_background BOOLEAN DEFAULT 0 | ||
)'); | ||
|
||
|
||
$db->exec('INSERT INTO settings (dark_theme, monthly_price, convert_currency, remove_background) VALUES (0, 0, 0, 0)'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.