2022-01-03 10:11:24 -05:00
|
|
|
<?php
|
2022-01-05 18:11:00 -05:00
|
|
|
|
2022-01-28 09:54:09 -05:00
|
|
|
/**@var Bramus\Router\Router $router */
|
|
|
|
|
2022-01-05 18:11:00 -05:00
|
|
|
use Helpers\Following;
|
|
|
|
use Helpers\Settings;
|
|
|
|
use Helpers\Misc;
|
2022-01-25 11:20:11 -05:00
|
|
|
use Views\Models\SettingsTemplate;
|
2022-01-03 10:11:24 -05:00
|
|
|
|
2022-01-28 09:54:09 -05:00
|
|
|
$router->mount('/settings', function () use ($router) {
|
|
|
|
$router->get('/', function () {
|
|
|
|
$latte = Misc::latte();
|
|
|
|
$latte->render(Misc::getView('settings'), new SettingsTemplate());
|
|
|
|
});
|
2022-01-03 10:11:24 -05:00
|
|
|
|
2022-01-28 09:54:09 -05:00
|
|
|
$router->post('/proxy', function () {
|
|
|
|
if (in_array(Settings::PROXY, $_POST)) {
|
|
|
|
foreach (Settings::PROXY as $proxy_element) {
|
|
|
|
Settings::set($proxy_element, $_POST[$proxy_element]);
|
|
|
|
}
|
2022-01-03 10:11:24 -05:00
|
|
|
}
|
2022-01-28 09:54:09 -05:00
|
|
|
http_response_code(302);
|
|
|
|
header('Location: ./home');
|
|
|
|
});
|
2022-01-05 18:11:00 -05:00
|
|
|
|
2022-01-28 09:54:09 -05:00
|
|
|
$router->post('/following', function () {
|
|
|
|
$following = Following::getUsers();
|
|
|
|
if (!isset($_POST['mode']) || empty($_POST['mode'])) {
|
|
|
|
die('You need to send a mode');
|
|
|
|
}
|
2022-01-05 18:11:00 -05:00
|
|
|
|
2022-01-28 09:54:09 -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');
|
|
|
|
}
|
2022-01-05 18:11:00 -05:00
|
|
|
|
2022-01-28 09:54:09 -05:00
|
|
|
// Build string
|
|
|
|
$following_string = implode(',', $following);
|
|
|
|
Settings::set('following', $following_string);
|
|
|
|
header('Location: ../settings');
|
|
|
|
});
|
|
|
|
});
|