[TASK] Use strict comparison for strings
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / ContentElement / MoveElementController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\ContentElement;
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 Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Module\AbstractModule;
20 use TYPO3\CMS\Backend\Tree\View\ContentMovingPagePositionMap;
21 use TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Imaging\Icon;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Fluid\View\StandaloneView;
26
27 /**
28 * Script Class for rendering the move-element wizard display
29 */
30 class MoveElementController extends AbstractModule
31 {
32 /**
33 * @var int
34 */
35 public $sys_language = 0;
36
37 /**
38 * @var int
39 */
40 public $page_id;
41
42 /**
43 * @var string
44 */
45 public $table;
46
47 /**
48 * @var string
49 */
50 public $R_URI;
51
52 /**
53 * @var int
54 */
55 public $input_moveUid;
56
57 /**
58 * @var int
59 */
60 public $moveUid;
61
62 /**
63 * @var int
64 */
65 public $makeCopy;
66
67 /**
68 * Pages-select clause
69 *
70 * @var string
71 */
72 public $perms_clause;
73
74 /**
75 * Content for module accumulated here.
76 *
77 * @var string
78 */
79 public $content;
80
81 /**
82 * Constructor
83 */
84 public function __construct()
85 {
86 parent::__construct();
87 $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
88 $GLOBALS['SOBE'] = $this;
89 $this->init();
90 }
91
92 /**
93 * Constructor, initializing internal variables.
94 *
95 * @return void
96 */
97 public function init()
98 {
99 // Setting internal vars:
100 $this->sys_language = (int)GeneralUtility::_GP('sys_language');
101 $this->page_id = (int)GeneralUtility::_GP('uid');
102 $this->table = GeneralUtility::_GP('table');
103 $this->R_URI = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
104 $this->input_moveUid = GeneralUtility::_GP('moveUid');
105 $this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
106 $this->makeCopy = GeneralUtility::_GP('makeCopy');
107 // Select-pages where clause for read-access:
108 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
109 }
110
111 /**
112 * Injects the request object for the current request or subrequest
113 * As this controller goes only through the main() method, it is rather simple for now
114 *
115 * @param ServerRequestInterface $request the current request
116 * @param ResponseInterface $response
117 * @return ResponseInterface the response with the content
118 */
119 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
120 {
121 $this->main();
122
123 $this->moduleTemplate->setContent($this->content);
124 $response->getBody()->write($this->moduleTemplate->renderContent());
125 return $response;
126 }
127
128 /**
129 * Creating the module output.
130 *
131 * @return void
132 */
133 public function main()
134 {
135 $lang = $this->getLanguageService();
136 if ($this->page_id) {
137 $assigns = [];
138 $backendUser = $this->getBackendUser();
139 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
140 // Get record for element:
141 $elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid);
142 // Headerline: Icon, record title:
143 $assigns['table'] = $this->table;
144 $assigns['elRow'] = $elRow;
145 $assigns['recordTooltip'] = BackendUtility::getRecordToolTip($elRow, $this->table);
146 $assigns['recordTitle'] = BackendUtility::getRecordTitle($this->table, $elRow, true);
147 // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
148 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(['makeCopy' => !$this->makeCopy])) . ';';
149 $assigns['makeCopyChecked'] = $this->makeCopy ? ' checked="checked"' : '';
150 $assigns['makeCopyOnClick'] = $onClick;
151 // IF the table is "pages":
152 if ((string)$this->table === 'pages') {
153 // Get page record (if accessible):
154 $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
155 if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
156 // Initialize the position map:
157 $posMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class);
158 $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
159 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
160 if ($pageInfo['pid']) {
161 $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
162 if (is_array($pidPageInfo)) {
163 if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
164 $assigns['pages']['goUpUrl'] = GeneralUtility::linkThisScript([
165 'uid' => (int)$pageInfo['pid'],
166 'moveUid' => $this->moveUid
167 ]);
168 } else {
169 $assigns['pages']['pidPageInfo'] = $pidPageInfo;
170 }
171 $assigns['pages']['pidRecordTitle'] = BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
172 }
173 }
174 // Create the position tree:
175 $assigns['pages']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
176 }
177 }
178 // IF the table is "tt_content":
179 if ((string)$this->table === 'tt_content') {
180 // First, get the record:
181 $tt_content_rec = BackendUtility::getRecord('tt_content', $this->moveUid);
182 // ?
183 if (!$this->input_moveUid) {
184 $this->page_id = $tt_content_rec['pid'];
185 }
186 // Checking if the parent page is readable:
187 $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
188 if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
189 // Initialize the position map:
190 $posMap = GeneralUtility::makeInstance(ContentMovingPagePositionMap::class);
191 $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
192 $posMap->cur_sys_language = $this->sys_language;
193 // Headerline for the parent page: Icon, record title:
194 $assigns['ttContent']['pageInfo'] = $pageInfo;
195 $assigns['ttContent']['recordTooltip'] = BackendUtility::getRecordToolTip($pageInfo, 'pages');
196 $assigns['ttContent']['recordTitle'] = BackendUtility::getRecordTitle('pages', $pageInfo, true);
197 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
198 // SHARED page-TSconfig settings.
199 // $modTSconfig_SHARED = BackendUtility::getModTSconfig($this->pageId, 'mod.SHARED');
200 $colPosArray = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
201 $colPosIds = [];
202 foreach ($colPosArray as $colPos) {
203 $colPosIds[] = $colPos[1];
204 }
205 // Removing duplicates, if any
206 $colPosList = implode(',', array_unique($colPosIds));
207 // Adding parent page-header and the content element columns from position-map:
208 $assigns['ttContent']['contentElementColumns'] = $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
209 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
210 if ($pageInfo['pid']) {
211 $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
212 if (is_array($pidPageInfo)) {
213 if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
214 $assigns['ttContent']['goUpUrl'] = GeneralUtility::linkThisScript([
215 'uid' => (int)$pageInfo['pid'],
216 'moveUid' => $this->moveUid
217 ]);
218 } else {
219 $assigns['ttContent']['pidPageInfo'] = $pidPageInfo;
220 }
221 $assigns['ttContent']['pidRecordTitle'] = BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
222 }
223 }
224 // Create the position tree (for pages):
225 $assigns['ttContent']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
226 }
227 }
228 // Rendering of the output via fluid
229 $view = GeneralUtility::makeInstance(StandaloneView::class);
230 $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
231 $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
232 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
233 'EXT:backend/Resources/Private/Templates/ContentElement/MoveElement.html'
234 ));
235 $view->assignMultiple($assigns);
236 $this->content .= $view->render();
237 }
238 // Setting up the buttons and markers for docheader
239 $this->getButtons();
240 // Build the <body> for the module
241 $this->moduleTemplate->setTitle($lang->getLL('movingElement'));
242 }
243
244 /**
245 * Create the panel of buttons for submitting the form or otherwise perform operations.
246 */
247 protected function getButtons()
248 {
249 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
250 if ($this->page_id) {
251 if ((string)$this->table === 'pages') {
252 $cshButton = $buttonBar->makeHelpButton()
253 ->setModuleName('xMOD_csh_corebe')
254 ->setFieldName('move_el_pages');
255 $buttonBar->addButton($cshButton);
256 } elseif ((string)$this->table === 'tt_content') {
257 $cshButton = $buttonBar->makeHelpButton()
258 ->setModuleName('xMOD_csh_corebe')
259 ->setFieldName('move_el_cs');
260 $buttonBar->addButton($cshButton);
261 }
262
263 if ($this->R_URI) {
264 $backButton = $buttonBar->makeLinkButton()
265 ->setHref($this->R_URI)
266 ->setTitle($this->getLanguageService()->getLL('goBack'))
267 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
268 'actions-view-go-back',
269 Icon::SIZE_SMALL
270 ));
271 $buttonBar->addButton($backButton);
272 }
273 }
274 }
275
276 /**
277 * Returns LanguageService
278 *
279 * @return \TYPO3\CMS\Lang\LanguageService
280 */
281 protected function getLanguageService()
282 {
283 return $GLOBALS['LANG'];
284 }
285
286 /**
287 * Returns the current BE user.
288 *
289 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
290 */
291 protected function getBackendUser()
292 {
293 return $GLOBALS['BE_USER'];
294 }
295 }