2022-01-03 10:11:24 -05:00
|
|
|
<?php
|
2022-01-30 18:02:52 -05:00
|
|
|
namespace App\Controllers;
|
2022-01-05 18:11:00 -05:00
|
|
|
|
2022-01-30 18:02:52 -05:00
|
|
|
use App\Helpers\Misc;
|
|
|
|
use App\Helpers\Cookies;
|
|
|
|
use App\Helpers\Following;
|
|
|
|
use App\Models\SettingsTemplate;
|
2022-01-28 09:54:09 -05:00
|
|
|
|
2022-01-30 18:02:52 -05:00
|
|
|
class SettingsController {
|
|
|
|
static public function index() {
|
2022-01-28 09:54:09 -05:00
|
|
|
$latte = Misc::latte();
|
|
|
|
$latte->render(Misc::getView('settings'), new SettingsTemplate());
|
2022-01-30 18:02:52 -05:00
|
|
|
}
|
2022-01-03 10:11:24 -05:00
|
|
|
|
2022-01-30 18:02:52 -05:00
|
|
|
static public function proxy() {
|
|
|
|
if (in_array(Cookies::PROXY, $_POST)) {
|
|
|
|
foreach (Cookies::PROXY as $proxy_element) {
|
|
|
|
Cookies::set($proxy_element, $_POST[$proxy_element]);
|
2022-01-28 09:54:09 -05:00
|
|
|
}
|
2022-01-03 10:11:24 -05:00
|
|
|
}
|
2022-02-05 18:58:30 -05:00
|
|
|
$url = Misc::url('/settings');
|
2022-01-30 18:02:52 -05:00
|
|
|
header("Location: {$url}");
|
|
|
|
}
|
2022-01-05 18:11:00 -05:00
|
|
|
|
2022-01-30 18:02:52 -05:00
|
|
|
static public function following() {
|
2022-01-28 09:54:09 -05:00
|
|
|
$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);
|
2022-01-30 18:02:52 -05:00
|
|
|
Cookies::set('following', $following_string);
|
2022-02-05 18:58:30 -05:00
|
|
|
$url = Misc::url('/settings');
|
|
|
|
header("Location: {$url}");
|
2022-01-30 18:02:52 -05:00
|
|
|
}
|
|
|
|
}
|