[TASK] Call explicit render() on icon objects
[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\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Imaging\Icon;
21 use TYPO3\CMS\Core\Imaging\IconFactory;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24 /**
25 * Script Class for rendering the move-element wizard display
26 */
27 class MoveElementController {
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 * @var IconFactory
87 */
88 protected $iconFactory;
89
90 /**
91 * Constructor
92 */
93 public function __construct() {
94 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_misc.xlf');
95 $GLOBALS['SOBE'] = $this;
96 $this->init();
97 }
98
99 /**
100 * Constructor, initializing internal variables.
101 *
102 * @return void
103 */
104 public function init() {
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(1);
115 // Starting the document template object:
116 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
117 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/move_el.html');
118 $this->doc->JScode = '';
119 // Starting document content (header):
120 $this->content = '';
121 $this->content .= $this->doc->header($this->getLanguageService()->getLL('movingElement'));
122 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
123 }
124
125 /**
126 * Injects the request object for the current request or subrequest
127 * As this controller goes only through the main() method, it is rather simple for now
128 *
129 * @param ServerRequestInterface $request the current request
130 * @param ResponseInterface $response
131 * @return ResponseInterface the response with the content
132 */
133 public function mainAction(ServerRequestInterface $request, ResponseInterface $response) {
134 $this->main();
135
136 $response->getBody()->write($this->content);
137 return $response;
138 }
139
140 /**
141 * Creating the module output.
142 *
143 * @return void
144 */
145 public function main() {
146 $lang = $this->getLanguageService();
147 if ($this->page_id) {
148 $backendUser = $this->getBackendUser();
149 // Get record for element:
150 $elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid);
151 // Headerline: Icon, record title:
152 $headerLine = '<span title="' . BackendUtility::getRecordIconAltText($elRow, $this->table) . '">' . $this->iconFactory->getIconForRecord($this->table, $elRow, Icon::SIZE_SMALL)->render() . '</span>';
153 $headerLine .= BackendUtility::getRecordTitle($this->table, $elRow, TRUE);
154 // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
155 $headerLine .= $this->doc->spacer(5);
156 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(array('makeCopy' => !$this->makeCopy))) . ';';
157 $headerLine .= $this->doc->spacer(5);
158 $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>';
159 // Add the header-content to the module content:
160 $this->content .= $this->doc->section('', $headerLine, FALSE, TRUE);
161 $this->content .= $this->doc->spacer(20);
162 // Reset variable to pick up the module content in:
163 $code = '';
164 // IF the table is "pages":
165 if ((string)$this->table == 'pages') {
166 // Get page record (if accessible):
167 $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
168 if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
169 // Initialize the position map:
170 $posMap = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap::class);
171 $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
172 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
173 if ($pageInfo['pid']) {
174 $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
175 if (is_array($pidPageInfo)) {
176 if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
177 $code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('uid' => (int)$pageInfo['pid'], 'moveUid' => $this->moveUid))) . '">' . $this->iconFactory->getIcon('actions-view-go-up', Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '</a><br />';
178 } else {
179 $code .= $this->iconFactory->getIconForRecord('pages', $pidPageInfo, Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '<br />';
180 }
181 }
182 }
183 // Create the position tree:
184 $code .= $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
185 }
186 }
187 // IF the table is "tt_content":
188 if ((string)$this->table == 'tt_content') {
189 // First, get the record:
190 $tt_content_rec = BackendUtility::getRecord('tt_content', $this->moveUid);
191 // ?
192 if (!$this->input_moveUid) {
193 $this->page_id = $tt_content_rec['pid'];
194 }
195 // Checking if the parent page is readable:
196 $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
197 if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
198 // Initialize the position map:
199 $posMap = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\ContentMovingPagePositionMap::class);
200 $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
201 $posMap->cur_sys_language = $this->sys_language;
202 // Headerline for the parent page: Icon, record title:
203 $headerLine = '<span title="' . BackendUtility::getRecordIconAltText($pageInfo, 'pages') . '">' . $this->iconFactory->getIconForRecord('pages', $pageInfo, Icon::SIZE_SMALL)->render() . '</span>';
204 $headerLine .= BackendUtility::getRecordTitle('pages', $pageInfo, TRUE);
205 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
206 // SHARED page-TSconfig settings.
207 // $modTSconfig_SHARED = BackendUtility::getModTSconfig($this->pageId, 'mod.SHARED');
208 $colPosArray = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
209 $colPosIds = array();
210 foreach ($colPosArray as $colPos) {
211 $colPosIds[] = $colPos[1];
212 }
213 // Removing duplicates, if any
214 $colPosList = implode(',', array_unique($colPosIds));
215 // Adding parent page-header and the content element columns from position-map:
216 $code = $headerLine . '<br />';
217 $code .= $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
218 // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
219 $code .= '<br /><br />';
220 if ($pageInfo['pid']) {
221 $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
222 if (is_array($pidPageInfo)) {
223 if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
224 $code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array(
225 'uid' => (int)$pageInfo['pid'],
226 'moveUid' => $this->moveUid
227 ))) . '">' . $this->iconFactory->getIcon('actions-view-go-up', Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '</a><br />';
228 } else {
229 $code .= $this->iconFactory->getIconForRecord('pages', $pidPageInfo, Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, TRUE) . '<br />';
230 }
231 }
232 }
233 // Create the position tree (for pages):
234 $code .= $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
235 }
236 }
237 // Add the $code content as a new section to the module:
238 $this->content .= $this->doc->section($lang->getLL('selectPositionOfElement'), $code, FALSE, TRUE);
239 }
240 // Setting up the buttons and markers for docheader
241 $docHeaderButtons = $this->getButtons();
242 $markers['CSH'] = $docHeaderButtons['csh'];
243 $markers['CONTENT'] = $this->content;
244 // Build the <body> for the module
245 $this->content = $this->doc->startPage($lang->getLL('movingElement'));
246 $this->content .= $this->doc->moduleBody($pageInfo, $docHeaderButtons, $markers);
247 $this->content .= $this->doc->endPage();
248 $this->content = $this->doc->insertStylesAndJS($this->content);
249 }
250
251 /**
252 * Print out the accumulated content:
253 *
254 * @return void
255 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use mainAction() instead
256 */
257 public function printContent() {
258 GeneralUtility::logDeprecatedFunction();
259 echo $this->content;
260 }
261
262 /**
263 * Create the panel of buttons for submitting the form or otherwise perform operations.
264 *
265 * @return array All available buttons as an assoc. array
266 */
267 protected function getButtons() {
268 $buttons = array(
269 'csh' => '',
270 'back' => ''
271 );
272 if ($this->page_id) {
273 if ((string)$this->table == 'pages') {
274 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'move_el_pages');
275 } elseif ((string)$this->table == 'tt_content') {
276 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'move_el_cs');
277 }
278 if ($this->R_URI) {
279 $buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $this->getLanguageService()->getLL('goBack', TRUE) . '">' . $this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL)->render() . '</a>';
280 }
281 }
282 return $buttons;
283 }
284
285 /**
286 * Returns LanguageService
287 *
288 * @return \TYPO3\CMS\Lang\LanguageService
289 */
290 protected function getLanguageService() {
291 return $GLOBALS['LANG'];
292 }
293
294 /**
295 * Returns the current BE user.
296 *
297 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
298 */
299 protected function getBackendUser() {
300 return $GLOBALS['BE_USER'];
301 }
302
303 }