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