|
1
|
|
|
<?php |
|
2
|
|
|
namespace EWW\Dpf\Controller; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the TYPO3 CMS project. |
|
6
|
|
|
* |
|
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
9
|
|
|
* of the License, or any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please read the |
|
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
13
|
|
|
* |
|
14
|
|
|
* The TYPO3 project - inspiring people to share! |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
18
|
|
|
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; |
|
19
|
|
|
use TYPO3\CMS\Core\Log\LogManager; |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
abstract class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* authorizationChecker |
|
26
|
|
|
* |
|
27
|
|
|
* @var \EWW\Dpf\Security\AuthorizationChecker |
|
28
|
|
|
* @TYPO3\CMS\Extbase\Annotation\Inject |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $authorizationChecker = null; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* security |
|
34
|
|
|
* |
|
35
|
|
|
* @var \EWW\Dpf\Security\Security |
|
36
|
|
|
* @TYPO3\CMS\Extbase\Annotation\Inject |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $security = null; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* clientRepository |
|
42
|
|
|
* |
|
43
|
|
|
* @var \EWW\Dpf\Domain\Repository\ClientRepository |
|
44
|
|
|
* @TYPO3\CMS\Extbase\Annotation\Inject |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $clientRepository = null; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* signalSlotDispatcher |
|
50
|
|
|
* |
|
51
|
|
|
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher |
|
52
|
|
|
* @TYPO3\CMS\Extbase\Annotation\Inject |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $signalSlotDispatcher = null; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* session |
|
58
|
|
|
* |
|
59
|
|
|
* @var \EWW\Dpf\Session\Session |
|
60
|
|
|
* @TYPO3\CMS\Extbase\Annotation\Inject |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $session = null; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* logger |
|
66
|
|
|
* |
|
67
|
|
|
* @var \TYPO3\CMS\Core\Log\Logger |
|
68
|
|
|
*/ |
|
69
|
|
|
protected $logger = null; |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
public function __construct() |
|
73
|
|
|
{ |
|
74
|
|
|
/** @var $logger \TYPO3\CMS\Core\Log\Logger */ |
|
75
|
|
|
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) |
|
79
|
|
|
{ |
|
80
|
|
|
parent::initializeView($view); |
|
81
|
|
|
|
|
82
|
|
|
$client = $this->clientRepository->findAll()->current(); |
|
83
|
|
|
|
|
84
|
|
|
$key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:manager.chooseClientMessage'; |
|
85
|
|
|
$message = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, 'dpf'); |
|
86
|
|
|
|
|
87
|
|
|
if (!$client) { |
|
88
|
|
|
$this->addFlashMessage( |
|
89
|
|
|
$message, |
|
90
|
|
|
$messageTitle = '', |
|
91
|
|
|
$severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::WARNING, |
|
92
|
|
|
$storeInSession = true |
|
93
|
|
|
); |
|
94
|
|
|
} else { |
|
95
|
|
|
$view->assign('client', $client); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Set session data |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $key |
|
103
|
|
|
* @param string $data |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setSessionData($key, $data) |
|
106
|
|
|
{ |
|
107
|
|
|
if (!empty($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) { |
|
108
|
|
|
|
|
109
|
|
|
$userGlobals = $GLOBALS['TSFE']->fe_user; |
|
110
|
|
|
|
|
111
|
|
|
} else if (!empty($GLOBALS['BE_USER']) && is_object($GLOBALS['BE_USER'])) { |
|
112
|
|
|
|
|
113
|
|
|
$userGlobals = $GLOBALS['BE_USER']; |
|
114
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$userGlobals->setAndSaveSessionData($key, $data); |
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
return; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Get session data |
|
124
|
|
|
* |
|
125
|
|
|
* @param string $key |
|
126
|
|
|
* |
|
127
|
|
|
* @return |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getSessionData($key) |
|
130
|
|
|
{ |
|
131
|
|
|
if (!empty($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) { |
|
132
|
|
|
|
|
133
|
|
|
$userGlobals = $GLOBALS['TSFE']->fe_user; |
|
134
|
|
|
|
|
135
|
|
|
} else if (!empty($GLOBALS['BE_USER']) && is_object($GLOBALS['BE_USER'])) { |
|
136
|
|
|
|
|
137
|
|
|
$userGlobals = $GLOBALS['BE_USER']; |
|
138
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
return $userGlobals->getSessionData($key); |
|
|
|
|
|
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Safely gets Parameters from request |
|
145
|
|
|
* if they exist |
|
146
|
|
|
* |
|
147
|
|
|
* @param string $parameterName |
|
148
|
|
|
* |
|
149
|
|
|
* @return null|string |
|
150
|
|
|
*/ |
|
151
|
|
|
protected function getParametersSafely($parameterName) |
|
152
|
|
|
{ |
|
153
|
|
|
if ($this->request->hasArgument($parameterName)) { |
|
154
|
|
|
return $this->filterSafelyParameters($this->request->getArgument($parameterName)); |
|
155
|
|
|
} |
|
156
|
|
|
return null; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* remove XSS stuff recursively |
|
161
|
|
|
* |
|
162
|
|
|
* @param mixed $param |
|
163
|
|
|
* |
|
164
|
|
|
* @return string |
|
165
|
|
|
*/ |
|
166
|
|
|
protected function filterSafelyParameters($param) |
|
167
|
|
|
{ |
|
168
|
|
|
if (is_array($param)) { |
|
169
|
|
|
foreach ($param as $key => $item) { |
|
170
|
|
|
$param[$key] = $this->filterSafelyParameters($item); |
|
171
|
|
|
} |
|
172
|
|
|
return $param; |
|
|
|
|
|
|
173
|
|
|
} else { |
|
174
|
|
|
// FIXME: removeXSS is deprecated; |
|
175
|
|
|
//return GeneralUtility::removeXSS($param) |
|
176
|
|
|
return $param; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
public function initializeAction() |
|
181
|
|
|
{ |
|
182
|
|
|
parent::initializeAction(); |
|
183
|
|
|
|
|
184
|
|
|
$signalSlotDispatcher = GeneralUtility::makeInstance(Dispatcher::class); |
|
185
|
|
|
$signalSlotDispatcher->dispatch(get_class($this), 'actionChange', [$this->actionMethodName, get_class($this)]); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
public function getCurrentAction() |
|
190
|
|
|
{ |
|
191
|
|
|
return str_replace('Action', '', $this->actionMethodName); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
public function getCurrentController() |
|
195
|
|
|
{ |
|
196
|
|
|
$controllerName = end(explode('\\', get_Class($this))); |
|
197
|
|
|
return str_replace('Controller', '', $controllerName); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
|
|
201
|
|
|
} |
|
202
|
|
|
|