[TASK] Move record-related entrypoints to backend routing
[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\ServerRequestInterface;
18 use Psr\Http\Message\ResponseInterface;
19 use TYPO3\CMS\Core\Http\Response;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Backend\Utility\IconUtility;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24 /**
25 * Script Class for rendering the move-element wizard display
26 */
27 class MoveElementController implements \TYPO3\CMS\Core\Http\ControllerInterface {
28
29 /**
30 * @var int
31 */
32 public $sys_language = 0;
33
34 /**
35 * @var int
36 */
37 public $page_id;
38
39 /**
40 * @var string
41 */
42 public $table;
43
44 /**
45 * @var string
46 */
47 public $R_URI;
48
49 /**
50 * @var int
51 */
52 public $input_moveUid;
53
54 /**
55 * @var int
56 */
57 public $moveUid;
58
59 /**
60 * @var int
61 */
62 public $makeCopy;
63
64 /**
65 * Document template object
66 *
67 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
68 */
69 public $doc;
70
71 /**
72 * Pages-select clause
73 *
74 * @var string
75 */
76 public $perms_clause;
77
78 /**
79 * Content for module accumulated here.
80 *
81 * @var string
82 */
83 public $content;
84
85 /**
86 * Constructor
87 */
88 public function __construct() {
89 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_misc.xlf');
90 $GLOBALS['SOBE'] = $this;
91 $this->init();
92 }
93
94 /**
95 * Constructor, initializing internal variables.
96 *
97 * @return void
98 */
99 public function init() {
100 // Setting internal vars:
101 $this->sys_language = (int)GeneralUtility::_GP('sys_language');
102 $this->page_id = (int)GeneralUtility::_GP('uid');
103 $this->table = GeneralUtility::_GP('table');
104 $this->R_URI = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
105 $this->input_moveUid = GeneralUtility::_GP('moveUid');
106 $this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
107 $this->makeCopy = GeneralUtility::_GP('makeCopy');
108 // Select-pages where clause for read-access:
109 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
110 // Starting the document template object:
111 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
112 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/move_el.html');
113 $this->doc->JScode = '';
114 // Starting document content (header):
115 $this->content = '';
116 $this->content .= $this->doc->header($this->getLanguageService()->getLL('movingElement'));
117 }
118
119 /**
120 * Injects the request object for the current request or subrequest
121 * As this controller goes only through the main() method, it is rather simple for now
122 *
123 * @param ServerRequestInterface $request
124 * @return ResponseInterface $response
125 */
126 public function processRequest(ServerRequestInterface $request) {
127 $this->main();
128
129 /** @var Response $response */
130 $response = GeneralUtility::makeInstance(Response::class);
131 $response->getBody()->write($this->content);
132 return $response;
133 }
134
135 /**
136 * Creating the module output.
137 *
138 * @return void
139 */
140 public function main() {
141 $lang = $this->getLanguageService();
142 if ($this->page_id) {
143 $backendUser = $this->getBackendUser();
144 // Get record for element:
145 $elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid);
146 // Headerline: Icon, record title:
147 $headerLine = IconUtility::getSpriteIconForRecord($this->table, $elRow, array('title' => htmlspecialchars(BackendUtility::getRecordIconAltText($elRow, $this->table))));
148 $headerLine .= BackendUtility::getRecordTitle($this->table, $elRow, TRUE);
149 // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
150 $headerLine .= $this->doc->spacer(5);
151 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(array('makeCopy' => !$this->makeCopy))) . ';';
152 $headerLine .= $this->doc->spacer(5);
153 $headerLine .= '<input type="hidden" name="makeCopy" value="0" />' . '<input type="checkbox" name="makeCopy" id="makeCopy" value="1"' . ($this->makeCopy ? ' checked="checked"' : '') . ' onclick="' . htmlspecialchars($onClick) . '" /> <label for="makeCopy" class="t3-label-valign-top">' . $lang->getLL('makeCopy', 1) . '</label>';
154 // Add the header-content to the module content:
155 $this->content .= $this->doc->section('', $headerLine, FALSE, TRUE);
156 $this->content .= $this->doc->spacer(20);
157 // Reset variable to pick up the module content in:
158 $code = '';
159 // IF the table is "pages":
160 if ((string)$this->table == 'pages') {
161 // Get page record (if accessible):
162 $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
163 if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
164 // Initialize the position map:
165 $posMap = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap::class);
166 $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
167 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
168 if ($pageInfo['pid']) {
169 $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
170 if (is_array($pidPageInfo)) {
171 if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
172 $code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('uid' => (int)$pageInfo['pid'], 'moveUid' => $this->moveUid))) . '">' . IconUtility::getSpriteIcon('actions-view-go-up') . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '</a><br />';
173 } else {
174 $code .= IconUtility::getSpriteIconForRecord('pages', $pidPageInfo) . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '<br />';
175 }
176 }
177 }
178 // Create the position tree:
179 $code .= $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(\TYPO3\CMS\Backend\Tree\View\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 $headerLine = IconUtility::getSpriteIconForRecord('pages', $pageInfo, array('title' => htmlspecialchars(BackendUtility::getRecordIconAltText($pageInfo, 'pages'))));
199 $headerLine .= BackendUtility::getRecordTitle('pages', $pageInfo, TRUE);
200 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
201 // SHARED page-TSconfig settings.
202 // $modTSconfig_SHARED = BackendUtility::getModTSconfig($this->pageId, 'mod.SHARED');
203 $colPosArray = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
204 $colPosIds = array();
205 foreach ($colPosArray as $colPos) {
206 $colPosIds[] = $colPos[1];
207 }
208 // Removing duplicates, if any
209 $colPosList = implode(',', array_unique($colPosIds));
210 // Adding parent page-header and the content element columns from position-map:
211 $code = $headerLine . '<br />';
212 $code .= $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 $code .= '<br /><br />';
215 if ($pageInfo['pid']) {
216 $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
217 if (is_array($pidPageInfo)) {
218 if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
219 $code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array(
220 'uid' => (int)$pageInfo['pid'],
221 'moveUid' => $this->moveUid
222 ))) . '">' . IconUtility::getSpriteIcon('actions-view-go-up') . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '</a><br />';
223 } else {
224 $code .= IconUtility::getSpriteIconForRecord('pages', $pidPageInfo) . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '<br />';
225 }
226 }
227 }
228 // Create the position tree (for pages):
229 $code .= $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
230 }
231 }
232 // Add the $code content as a new section to the module:
233 $this->content .= $this->doc->section($lang->getLL('selectPositionOfElement'), $code, FALSE, TRUE);
234 }
235 // Setting up the buttons and markers for docheader
236 $docHeaderButtons = $this->getButtons();
237 $markers['CSH'] = $docHeaderButtons['csh'];
238 $markers['CONTENT'] = $this->content;
239 // Build the <body> for the module
240 $this->content = $this->doc->startPage($lang->getLL('movingElement'));
241 $this->content .= $this->doc->moduleBody($pageInfo, $docHeaderButtons, $markers);
242 $this->content .= $this->doc->endPage();
243 $this->content = $this->doc->insertStylesAndJS($this->content);
244 }
245
246 /**
247 * Print out the accumulated content:
248 *
249 * @return void
250 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use processRequest() instead
251 */
252 public function printContent() {
253 GeneralUtility::logDeprecatedFunction();
254 echo $this->content;
255 }
256
257 /**
258 * Create the panel of buttons for submitting the form or otherwise perform operations.
259 *
260 * @return array All available buttons as an assoc. array
261 */
262 protected function getButtons() {
263 $buttons = array(
264 'csh' => '',
265 'back' => ''
266 );
267 if ($this->page_id) {
268 if ((string)$this->table == 'pages') {
269 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'move_el_pages');
270 } elseif ((string)$this->table == 'tt_content') {
271 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'move_el_cs');
272 }
273 if ($this->R_URI) {
274 $buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $this->getLanguageService()->getLL('goBack', TRUE) . '">' . IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
275 }
276 }
277 return $buttons;
278 }
279
280 /**
281 * Returns LanguageService
282 *
283 * @return \TYPO3\CMS\Lang\LanguageService
284 */
285 protected function getLanguageService() {
286 return $GLOBALS['LANG'];
287 }
288
289 /**
290 * Returns the current BE user.
291 *
292 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
293 */
294 protected function getBackendUser() {
295 return $GLOBALS['BE_USER'];
296 }
297
298 }