90df5ff201a1242fb6e4b8fb83d0fae163f8b83a
[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->backPath = $GLOBALS['BACK_PATH'];
110 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/move_el.html');
111 $this->doc->JScode = '';
112 // Starting document content (header):
113 $this->content = '';
114 $this->content .= $this->doc->header($this->getLanguageService()->getLL('movingElement'));
115 }
116
117 /**
118 * Creating the module output.
119 *
120 * @return void
121 */
122 public function main() {
123 $lang = $this->getLanguageService();
124 if ($this->page_id) {
125 $backendUser = $this->getBackendUser();
126 // Get record for element:
127 $elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid);
128 // Headerline: Icon, record title:
129 $headerLine = IconUtility::getSpriteIconForRecord($this->table, $elRow, array('title' => htmlspecialchars(BackendUtility::getRecordIconAltText($elRow, $this->table))));
130 $headerLine .= BackendUtility::getRecordTitle($this->table, $elRow, TRUE);
131 // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
132 $headerLine .= $this->doc->spacer(5);
133 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(array('makeCopy' => !$this->makeCopy))) . ';';
134 $headerLine .= $this->doc->spacer(5);
135 $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>';
136 // Add the header-content to the module content:
137 $this->content .= $this->doc->section('', $headerLine, FALSE, TRUE);
138 $this->content .= $this->doc->spacer(20);
139 // Reset variable to pick up the module content in:
140 $code = '';
141 // IF the table is "pages":
142 if ((string)$this->table == 'pages') {
143 // Get page record (if accessible):
144 $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
145 if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
146 // Initialize the position map:
147 $posMap = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap::class);
148 $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
149 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
150 if ($pageInfo['pid']) {
151 $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
152 if (is_array($pidPageInfo)) {
153 if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
154 $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 />';
155 } else {
156 $code .= IconUtility::getSpriteIconForRecord('pages', $pidPageInfo) . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '<br />';
157 }
158 }
159 }
160 // Create the position tree:
161 $code .= $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
162 }
163 }
164 // IF the table is "tt_content":
165 if ((string)$this->table == 'tt_content') {
166 // First, get the record:
167 $tt_content_rec = BackendUtility::getRecord('tt_content', $this->moveUid);
168 // ?
169 if (!$this->input_moveUid) {
170 $this->page_id = $tt_content_rec['pid'];
171 }
172 // Checking if the parent page is readable:
173 $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
174 if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
175 // Initialize the position map:
176 $posMap = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\ContentMovingPagePositionMap::class);
177 $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
178 $posMap->cur_sys_language = $this->sys_language;
179 // Headerline for the parent page: Icon, record title:
180 $headerLine = IconUtility::getSpriteIconForRecord('pages', $pageInfo, array('title' => htmlspecialchars(BackendUtility::getRecordIconAltText($pageInfo, 'pages'))));
181 $headerLine .= BackendUtility::getRecordTitle('pages', $pageInfo, TRUE);
182 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
183 // SHARED page-TSconfig settings.
184 // $modTSconfig_SHARED = BackendUtility::getModTSconfig($this->pageId, 'mod.SHARED');
185 $colPosArray = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
186 $colPosIds = array();
187 foreach ($colPosArray as $colPos) {
188 $colPosIds[] = $colPos[1];
189 }
190 // Removing duplicates, if any
191 $colPosList = implode(',', array_unique($colPosIds));
192 // Adding parent page-header and the content element columns from position-map:
193 $code = $headerLine . '<br />';
194 $code .= $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
195 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
196 $code .= '<br /><br />';
197 if ($pageInfo['pid']) {
198 $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
199 if (is_array($pidPageInfo)) {
200 if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
201 $code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array(
202 'uid' => (int)$pageInfo['pid'],
203 'moveUid' => $this->moveUid
204 ))) . '">' . IconUtility::getSpriteIcon('actions-view-go-up') . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '</a><br />';
205 } else {
206 $code .= IconUtility::getSpriteIconForRecord('pages', $pidPageInfo) . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '<br />';
207 }
208 }
209 }
210 // Create the position tree (for pages):
211 $code .= $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
212 }
213 }
214 // Add the $code content as a new section to the module:
215 $this->content .= $this->doc->section($lang->getLL('selectPositionOfElement'), $code, FALSE, TRUE);
216 }
217 // Setting up the buttons and markers for docheader
218 $docHeaderButtons = $this->getButtons();
219 $markers['CSH'] = $docHeaderButtons['csh'];
220 $markers['CONTENT'] = $this->content;
221 // Build the <body> for the module
222 $this->content = $this->doc->startPage($lang->getLL('movingElement'));
223 $this->content .= $this->doc->moduleBody($pageInfo, $docHeaderButtons, $markers);
224 $this->content .= $this->doc->endPage();
225 $this->content = $this->doc->insertStylesAndJS($this->content);
226 }
227
228 /**
229 * Print out the accumulated content:
230 *
231 * @return void
232 */
233 public function printContent() {
234 echo $this->content;
235 }
236
237 /**
238 * Create the panel of buttons for submitting the form or otherwise perform operations.
239 *
240 * @return array All available buttons as an assoc. array
241 */
242 protected function getButtons() {
243 $buttons = array(
244 'csh' => '',
245 'back' => ''
246 );
247 if ($this->page_id) {
248 if ((string)$this->table == 'pages') {
249 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'move_el_pages');
250 } elseif ((string)$this->table == 'tt_content') {
251 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'move_el_cs');
252 }
253 if ($this->R_URI) {
254 $buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $this->getLanguageService()->getLL('goBack', TRUE) . '">' . IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
255 }
256 }
257 return $buttons;
258 }
259
260 /**
261 * Returns LanguageService
262 *
263 * @return \TYPO3\CMS\Lang\LanguageService
264 */
265 protected function getLanguageService() {
266 return $GLOBALS['LANG'];
267 }
268
269 /**
270 * Returns the current BE user.
271 *
272 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
273 */
274 protected function getBackendUser() {
275 return $GLOBALS['BE_USER'];
276 }
277
278 }