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