-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathThemeSetController.php
More file actions
65 lines (49 loc) · 1.95 KB
/
ThemeSetController.php
File metadata and controls
65 lines (49 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\UserPreferences;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\Theme\ThemeManager;
use PhpMyAdmin\Url;
#[Route('/themes/set', ['POST'])]
final readonly class ThemeSetController implements InvocableController
{
public function __construct(
private ResponseRenderer $response,
private ThemeManager $themeManager,
private UserPreferences $userPreferences,
private Config $config,
) {
}
public function __invoke(ServerRequest $request): Response
{
$theme = $request->getParsedBodyParamAsString('set_theme');
if (! $this->config->settings['ThemeManager'] || $theme === '') {
if ($request->isAjax()) {
$this->response->addJSON('themeColorMode', '');
return $this->response->response();
}
$this->response->redirect('index.php?route=/' . Url::getCommonRaw([], '&'));
return $this->response->response();
}
$this->themeManager->setActiveTheme($theme);
$themeColorMode = $request->getParsedBodyParamAsString('themeColorMode', '');
if ($themeColorMode !== '') {
$this->themeManager->theme->setColorMode($themeColorMode);
}
$this->themeManager->setThemeCookie();
$preferences = $this->userPreferences->load();
$preferences['config_data']['ThemeDefault'] = $theme;
$this->userPreferences->save($preferences['config_data']);
if ($request->isAjax()) {
$this->response->addJSON('themeColorMode', $this->themeManager->theme->getColorMode());
return $this->response->response();
}
$this->response->redirect('index.php?route=/' . Url::getCommonRaw([], '&'));
return $this->response->response();
}
}