proxitok/routes/settings.php

56 lines
1.4 KiB
PHP
Raw Normal View History

<?php
use Helpers\Following;
use Helpers\Settings;
use Helpers\Misc;
use Steampixel\Route;
Route::add("/settings", function () {
$latte = Misc::latte();
2022-01-25 08:08:31 -05:00
$latte->render(Misc::getView('settings'), [
"proxy_elements" => Settings::PROXY,
"following" => Following::get(),
"title" => "Settings"
]);
});
Route::add("/settings/proxy", function () {
2022-01-06 18:13:51 -05:00
if (in_array(Settings::PROXY, $_POST)) {
foreach (Settings::PROXY as $proxy_element) {
Settings::set($proxy_element, $_POST[$proxy_element]);
}
}
http_response_code(302);
header('Location: ./home');
}, 'POST');
Route::add("/settings/following", function () {
$following = Following::get();
2022-01-06 18:13:51 -05:00
if (!isset($_POST['mode']) || empty($_POST['mode'])) {
die('You need to send a mode');
}
2022-01-06 18:13:51 -05:00
switch ($_POST['mode']) {
case 'add':
// Add following
array_push($following, $_POST['account']);
break;
case 'remove':
// Remove following
$index = array_search($_POST['account'], $following);
if ($index !== false) {
unset($following[$index]);
}
break;
default:
// Invalid
die('Invalid mode');
}
// Build string
$following_string = implode(',', $following);
Settings::set('following', $following_string);
header('Location: ../settings');
}, 'POST');