|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Zikula package. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright Zikula - https://ziku.la/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Zikula\DefaultTheme\Controller; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
19
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
20
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
21
|
|
|
use Zikula\Bundle\CoreBundle\Controller\AbstractController; |
|
22
|
|
|
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @Route("/ajax") |
|
26
|
|
|
*/ |
|
27
|
|
|
class AjaxController extends AbstractController |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @Route("/changeUserStyle", methods = {"POST"}, options={"expose"=true}) |
|
31
|
|
|
*/ |
|
32
|
|
|
public function changeUserStyleAction( |
|
33
|
|
|
Request $request, |
|
34
|
|
|
ZikulaHttpKernelInterface $kernel |
|
35
|
|
|
): JsonResponse { |
|
36
|
|
|
if (!$request->isXmlHttpRequest()) { |
|
37
|
|
|
return $this->json($this->trans('Only ajax access is allowed!'), Response::HTTP_BAD_REQUEST); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$themeBundle = $kernel->getBundle('ZikulaDefaultTheme'); |
|
41
|
|
|
$themeVarsPath = $themeBundle->getConfigPath() . '/variables.yaml'; |
|
|
|
|
|
|
42
|
|
|
$variableDefinitions = Yaml::parse(file_get_contents($themeVarsPath)); |
|
43
|
|
|
$availableStyles = $variableDefinitions['theme_style']['options']['choices']; |
|
44
|
|
|
|
|
45
|
|
|
$style = $request->request->get('style', ''); |
|
46
|
|
|
if (!$style || !in_array($style, array_values($availableStyles), true)) { |
|
47
|
|
|
return $this->json(['result' => false]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if ($request->hasSession() && ($session = $request->getSession())) { |
|
51
|
|
|
$session->set('currentBootstrapStyle', $style); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
return $this->json(['result' => true]); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|