|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the TYPO3 CMS project. |
|
7
|
|
|
* |
|
8
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
9
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
10
|
|
|
* of the License, or any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please read the |
|
13
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
14
|
|
|
* |
|
15
|
|
|
* The TYPO3 project - inspiring people to share! |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Backend\Controller\ContentElement; |
|
19
|
|
|
|
|
20
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
21
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
22
|
|
|
use TYPO3\CMS\Backend\Template\ModuleTemplate; |
|
23
|
|
|
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; |
|
24
|
|
|
use TYPO3\CMS\Backend\Tree\View\ContentMovingPagePositionMap; |
|
25
|
|
|
use TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap; |
|
26
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
27
|
|
|
use TYPO3\CMS\Backend\View\BackendLayoutView; |
|
28
|
|
|
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; |
|
29
|
|
|
use TYPO3\CMS\Core\Http\HtmlResponse; |
|
30
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
|
31
|
|
|
use TYPO3\CMS\Core\Imaging\IconFactory; |
|
32
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
|
33
|
|
|
use TYPO3\CMS\Core\Page\PageRenderer; |
|
34
|
|
|
use TYPO3\CMS\Core\Type\Bitmask\Permission; |
|
35
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
36
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Script Class for rendering the move-element wizard display |
|
40
|
|
|
* @internal This class is a specific Backend controller implementation and is not considered part of the Public TYPO3 API. |
|
41
|
|
|
*/ |
|
42
|
|
|
class MoveElementController |
|
43
|
|
|
{ |
|
44
|
|
|
/** |
|
45
|
|
|
* @var int |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $sys_language = 0; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var int |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $page_id; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var string |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $table; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $R_URI; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var int |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $input_moveUid; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var int |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $moveUid; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var int |
|
76
|
|
|
*/ |
|
77
|
|
|
protected $makeCopy; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Pages-select clause |
|
81
|
|
|
* |
|
82
|
|
|
* @var string |
|
83
|
|
|
*/ |
|
84
|
|
|
protected $perms_clause; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Content for module accumulated here. |
|
88
|
|
|
* |
|
89
|
|
|
* @var string |
|
90
|
|
|
*/ |
|
91
|
|
|
protected $content; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* ModuleTemplate object |
|
95
|
|
|
* |
|
96
|
|
|
* @var ModuleTemplate |
|
97
|
|
|
*/ |
|
98
|
|
|
protected $moduleTemplate; |
|
99
|
|
|
|
|
100
|
|
|
protected IconFactory $iconFactory; |
|
101
|
|
|
protected PageRenderer $pageRenderer; |
|
102
|
|
|
protected ModuleTemplateFactory $moduleTemplateFactory; |
|
103
|
|
|
|
|
104
|
|
|
public function __construct( |
|
105
|
|
|
IconFactory $iconFactory, |
|
106
|
|
|
PageRenderer $pageRenderer, |
|
107
|
|
|
ModuleTemplateFactory $moduleTemplateFactory |
|
108
|
|
|
) { |
|
109
|
|
|
$this->iconFactory = $iconFactory; |
|
110
|
|
|
$this->pageRenderer = $pageRenderer; |
|
111
|
|
|
$this->moduleTemplateFactory = $moduleTemplateFactory; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Injects the request object for the current request or subrequest |
|
116
|
|
|
* As this controller goes only through the main() method, it is rather simple for now |
|
117
|
|
|
* |
|
118
|
|
|
* @param ServerRequestInterface $request the current request |
|
119
|
|
|
* @return ResponseInterface the response with the content |
|
120
|
|
|
*/ |
|
121
|
|
|
public function mainAction(ServerRequestInterface $request): ResponseInterface |
|
122
|
|
|
{ |
|
123
|
|
|
$this->moduleTemplate = $this->moduleTemplateFactory->create($request); |
|
124
|
|
|
$this->getLanguageService()->includeLLFile('EXT:core/Resources/Private/Language/locallang_misc.xlf'); |
|
125
|
|
|
$this->init($request); |
|
126
|
|
|
$this->renderContent(); |
|
127
|
|
|
return new HtmlResponse($this->content); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Constructor, initializing internal variables. |
|
132
|
|
|
* |
|
133
|
|
|
* @param ServerRequestInterface $request |
|
134
|
|
|
*/ |
|
135
|
|
|
protected function init(ServerRequestInterface $request) |
|
136
|
|
|
{ |
|
137
|
|
|
$parsedBody = $request->getParsedBody(); |
|
138
|
|
|
$queryParams = $request->getQueryParams(); |
|
139
|
|
|
|
|
140
|
|
|
// Setting internal vars: |
|
141
|
|
|
$this->sys_language = (int)($parsedBody['sys_language'] ?? $queryParams['sys_language'] ?? 0); |
|
142
|
|
|
$this->page_id = (int)($parsedBody['uid'] ?? $queryParams['uid'] ?? 0); |
|
143
|
|
|
$this->table = $parsedBody['table'] ?? $queryParams['table'] ?? null; |
|
144
|
|
|
$this->R_URI = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? ''); |
|
145
|
|
|
$this->input_moveUid = $parsedBody['moveUid'] ?? $queryParams['moveUid'] ?? null; |
|
146
|
|
|
$this->moveUid = $this->input_moveUid ?: $this->page_id; |
|
147
|
|
|
$this->makeCopy = $parsedBody['makeCopy'] ?? $queryParams['makeCopy'] ?? 0; |
|
148
|
|
|
// Select-pages where clause for read-access: |
|
149
|
|
|
$this->perms_clause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Creating the module output. |
|
154
|
|
|
*/ |
|
155
|
|
|
protected function renderContent(): void |
|
156
|
|
|
{ |
|
157
|
|
|
$lang = $this->getLanguageService(); |
|
158
|
|
|
|
|
159
|
|
|
if ($this->page_id) { |
|
160
|
|
|
$assigns = []; |
|
161
|
|
|
$backendUser = $this->getBackendUser(); |
|
162
|
|
|
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip'); |
|
163
|
|
|
// Get record for element: |
|
164
|
|
|
$elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid); |
|
165
|
|
|
// Headerline: Icon, record title: |
|
166
|
|
|
$assigns['table'] = $this->table; |
|
167
|
|
|
$assigns['elRow'] = $elRow; |
|
168
|
|
|
$assigns['recordTooltip'] = BackendUtility::getRecordToolTip($elRow, $this->table); |
|
169
|
|
|
$assigns['recordTitle'] = BackendUtility::getRecordTitle($this->table, $elRow, true); |
|
170
|
|
|
// Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently): |
|
171
|
|
|
$assigns['makeCopyChecked'] = $this->makeCopy ? ' checked="checked"' : ''; |
|
172
|
|
|
$assigns['makeCopyUrl'] = GeneralUtility::linkThisScript(['makeCopy' => !$this->makeCopy]); |
|
173
|
|
|
// IF the table is "pages": |
|
174
|
|
|
if ((string)$this->table === 'pages') { |
|
175
|
|
|
// Get page record (if accessible): |
|
176
|
|
|
$pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause); |
|
177
|
|
|
if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) { |
|
|
|
|
|
|
178
|
|
|
// Initialize the position map: |
|
179
|
|
|
$posMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class); |
|
180
|
|
|
$posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move'; |
|
181
|
|
|
$posMap->moveUid = $this->moveUid; |
|
182
|
|
|
// Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page). |
|
183
|
|
|
if ($pageInfo['pid']) { |
|
184
|
|
|
$pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause); |
|
185
|
|
|
if (is_array($pidPageInfo)) { |
|
186
|
|
|
if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) { |
|
|
|
|
|
|
187
|
|
|
$assigns['pages']['goUpUrl'] = GeneralUtility::linkThisScript([ |
|
188
|
|
|
'uid' => (int)$pageInfo['pid'], |
|
189
|
|
|
'moveUid' => $this->moveUid |
|
190
|
|
|
]); |
|
191
|
|
|
} else { |
|
192
|
|
|
$assigns['pages']['pidPageInfo'] = $pidPageInfo; |
|
193
|
|
|
} |
|
194
|
|
|
$assigns['pages']['pidRecordTitle'] = BackendUtility::getRecordTitle('pages', $pidPageInfo, true); |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
// Create the position tree: |
|
198
|
|
|
$assigns['pages']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
// IF the table is "tt_content": |
|
202
|
|
|
if ((string)$this->table === 'tt_content') { |
|
203
|
|
|
// First, get the record: |
|
204
|
|
|
$tt_content_rec = BackendUtility::getRecord('tt_content', $this->moveUid); |
|
205
|
|
|
// ? |
|
206
|
|
|
if (!$this->input_moveUid) { |
|
207
|
|
|
$this->page_id = $tt_content_rec['pid']; |
|
208
|
|
|
} |
|
209
|
|
|
// Checking if the parent page is readable: |
|
210
|
|
|
$pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause); |
|
211
|
|
|
if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) { |
|
|
|
|
|
|
212
|
|
|
// Initialize the position map: |
|
213
|
|
|
$posMap = GeneralUtility::makeInstance(ContentMovingPagePositionMap::class); |
|
214
|
|
|
$posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move'; |
|
215
|
|
|
$posMap->moveUid = $this->moveUid; |
|
216
|
|
|
$posMap->cur_sys_language = $this->sys_language; |
|
217
|
|
|
// Headerline for the parent page: Icon, record title: |
|
218
|
|
|
$assigns['ttContent']['pageInfo'] = $pageInfo; |
|
219
|
|
|
$assigns['ttContent']['recordTooltip'] = BackendUtility::getRecordToolTip($pageInfo, 'pages'); |
|
220
|
|
|
$assigns['ttContent']['recordTitle'] = BackendUtility::getRecordTitle('pages', $pageInfo, true); |
|
221
|
|
|
$colPosArray = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this); |
|
222
|
|
|
$colPosIds = []; |
|
223
|
|
|
foreach ($colPosArray as $colPos) { |
|
224
|
|
|
$colPosIds[] = $colPos[1]; |
|
225
|
|
|
} |
|
226
|
|
|
// Removing duplicates, if any |
|
227
|
|
|
$colPosList = implode(',', array_unique($colPosIds)); |
|
228
|
|
|
// Adding parent page-header and the content element columns from position-map: |
|
229
|
|
|
$assigns['ttContent']['contentElementColumns'] = $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI); |
|
230
|
|
|
// Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page). |
|
231
|
|
|
if ($pageInfo['pid']) { |
|
232
|
|
|
$pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause); |
|
233
|
|
|
if (is_array($pidPageInfo)) { |
|
234
|
|
|
if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) { |
|
|
|
|
|
|
235
|
|
|
$assigns['ttContent']['goUpUrl'] = GeneralUtility::linkThisScript([ |
|
236
|
|
|
'uid' => (int)$pageInfo['pid'], |
|
237
|
|
|
'moveUid' => $this->moveUid |
|
238
|
|
|
]); |
|
239
|
|
|
} else { |
|
240
|
|
|
$assigns['ttContent']['pidPageInfo'] = $pidPageInfo; |
|
241
|
|
|
} |
|
242
|
|
|
$assigns['ttContent']['pidRecordTitle'] = BackendUtility::getRecordTitle('pages', $pidPageInfo, true); |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
// Create the position tree (for pages): |
|
246
|
|
|
$assigns['ttContent']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI); |
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
// Rendering of the output via fluid |
|
250
|
|
|
$view = GeneralUtility::makeInstance(StandaloneView::class); |
|
251
|
|
|
$view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]); |
|
252
|
|
|
$view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]); |
|
253
|
|
|
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName( |
|
254
|
|
|
'EXT:backend/Resources/Private/Templates/ContentElement/MoveElement.html' |
|
255
|
|
|
)); |
|
256
|
|
|
$view->assignMultiple($assigns); |
|
257
|
|
|
$this->content .= $view->render(); |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
// Setting up the buttons and markers for docheader |
|
261
|
|
|
$this->getButtons(); |
|
|
|
|
|
|
262
|
|
|
// Build the <body> for the module |
|
263
|
|
|
$this->moduleTemplate->setTitle($lang->getLL('movingElement')); |
|
264
|
|
|
$this->moduleTemplate->setContent($this->content); |
|
265
|
|
|
|
|
266
|
|
|
$this->content = $this->moduleTemplate->renderContent(); |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Create the panel of buttons for submitting the form or otherwise perform operations. |
|
271
|
|
|
*/ |
|
272
|
|
|
protected function getButtons() |
|
273
|
|
|
{ |
|
274
|
|
|
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); |
|
275
|
|
|
if ($this->page_id) { |
|
276
|
|
|
if ((string)$this->table === 'pages') { |
|
277
|
|
|
$cshButton = $buttonBar->makeHelpButton() |
|
278
|
|
|
->setModuleName('xMOD_csh_corebe') |
|
279
|
|
|
->setFieldName('move_el_pages'); |
|
280
|
|
|
$buttonBar->addButton($cshButton); |
|
281
|
|
|
} elseif ((string)$this->table === 'tt_content') { |
|
282
|
|
|
$cshButton = $buttonBar->makeHelpButton() |
|
283
|
|
|
->setModuleName('xMOD_csh_corebe') |
|
284
|
|
|
->setFieldName('move_el_cs'); |
|
285
|
|
|
$buttonBar->addButton($cshButton); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
if ($this->R_URI) { |
|
289
|
|
|
$backButton = $buttonBar->makeLinkButton() |
|
290
|
|
|
->setHref($this->R_URI) |
|
291
|
|
|
->setTitle($this->getLanguageService()->getLL('goBack')) |
|
292
|
|
|
->setIcon($this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL)); |
|
293
|
|
|
$buttonBar->addButton($backButton); |
|
294
|
|
|
} |
|
295
|
|
|
} |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* @return LanguageService |
|
300
|
|
|
*/ |
|
301
|
|
|
protected function getLanguageService(): LanguageService |
|
302
|
|
|
{ |
|
303
|
|
|
return $GLOBALS['LANG']; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
/** |
|
307
|
|
|
* @return BackendUserAuthentication |
|
308
|
|
|
*/ |
|
309
|
|
|
protected function getBackendUser(): BackendUserAuthentication |
|
310
|
|
|
{ |
|
311
|
|
|
return $GLOBALS['BE_USER']; |
|
312
|
|
|
} |
|
313
|
|
|
} |
|
314
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: