TYPO3 CMS  TYPO3_8-7
MoveElementController.php
Go to the documentation of this file.
1 <?php
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 
26 
31 {
35  public $sys_language = 0;
36 
40  public $page_id;
41 
45  public $table;
46 
50  public $R_URI;
51 
56 
60  public $moveUid;
61 
65  public $makeCopy;
66 
72  public $perms_clause;
73 
79  public $content;
80 
84  public function __construct()
85  {
86  parent::__construct();
87  $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
88  $GLOBALS['SOBE'] = $this;
89  $this->init();
90  }
91 
95  public function init()
96  {
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  }
108 
117  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
118  {
119  $this->main();
120 
121  $this->moduleTemplate->setContent($this->content);
122  $response->getBody()->write($this->moduleTemplate->renderContent());
123  return $response;
124  }
125 
129  public function main()
130  {
131  $lang = $this->getLanguageService();
132  if ($this->page_id) {
133  $assigns = [];
134  $backendUser = $this->getBackendUser();
135  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
136  // Get record for element:
137  $elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid);
138  // Headerline: Icon, record title:
139  $assigns['table'] = $this->table;
140  $assigns['elRow'] = $elRow;
141  $assigns['recordTooltip'] = BackendUtility::getRecordToolTip($elRow, $this->table);
142  $assigns['recordTitle'] = BackendUtility::getRecordTitle($this->table, $elRow, true);
143  // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
144  $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(['makeCopy' => !$this->makeCopy])) . ';';
145  $assigns['makeCopyChecked'] = $this->makeCopy ? ' checked="checked"' : '';
146  $assigns['makeCopyOnClick'] = $onClick;
147  // IF the table is "pages":
148  if ((string)$this->table === 'pages') {
149  // Get page record (if accessible):
150  $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
151  if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
152  // Initialize the position map:
153  $posMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class);
154  $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
155  // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
156  if ($pageInfo['pid']) {
157  $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
158  if (is_array($pidPageInfo)) {
159  if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
160  $assigns['pages']['goUpUrl'] = GeneralUtility::linkThisScript([
161  'uid' => (int)$pageInfo['pid'],
162  'moveUid' => $this->moveUid
163  ]);
164  } else {
165  $assigns['pages']['pidPageInfo'] = $pidPageInfo;
166  }
167  $assigns['pages']['pidRecordTitle'] = BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
168  }
169  }
170  // Create the position tree:
171  $assigns['pages']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
172  }
173  }
174  // IF the table is "tt_content":
175  if ((string)$this->table === 'tt_content') {
176  // First, get the record:
177  $tt_content_rec = BackendUtility::getRecord('tt_content', $this->moveUid);
178  // ?
179  if (!$this->input_moveUid) {
180  $this->page_id = $tt_content_rec['pid'];
181  }
182  // Checking if the parent page is readable:
183  $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
184  if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
185  // Initialize the position map:
186  $posMap = GeneralUtility::makeInstance(ContentMovingPagePositionMap::class);
187  $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
188  $posMap->cur_sys_language = $this->sys_language;
189  // Headerline for the parent page: Icon, record title:
190  $assigns['ttContent']['pageInfo'] = $pageInfo;
191  $assigns['ttContent']['recordTooltip'] = BackendUtility::getRecordToolTip($pageInfo, 'pages');
192  $assigns['ttContent']['recordTitle'] = BackendUtility::getRecordTitle('pages', $pageInfo, true);
193  // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
194  // SHARED page-TSconfig settings.
195  // $modTSconfig_SHARED = BackendUtility::getModTSconfig($this->pageId, 'mod.SHARED');
196  $colPosArray = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
197  $colPosIds = [];
198  foreach ($colPosArray as $colPos) {
199  $colPosIds[] = $colPos[1];
200  }
201  // Removing duplicates, if any
202  $colPosList = implode(',', array_unique($colPosIds));
203  // Adding parent page-header and the content element columns from position-map:
204  $assigns['ttContent']['contentElementColumns'] = $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
205  // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
206  if ($pageInfo['pid']) {
207  $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
208  if (is_array($pidPageInfo)) {
209  if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
210  $assigns['ttContent']['goUpUrl'] = GeneralUtility::linkThisScript([
211  'uid' => (int)$pageInfo['pid'],
212  'moveUid' => $this->moveUid
213  ]);
214  } else {
215  $assigns['ttContent']['pidPageInfo'] = $pidPageInfo;
216  }
217  $assigns['ttContent']['pidRecordTitle'] = BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
218  }
219  }
220  // Create the position tree (for pages):
221  $assigns['ttContent']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
222  }
223  }
224  // Rendering of the output via fluid
225  $view = GeneralUtility::makeInstance(StandaloneView::class);
226  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
227  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
228  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
229  'EXT:backend/Resources/Private/Templates/ContentElement/MoveElement.html'
230  ));
231  $view->assignMultiple($assigns);
232  $this->content .= $view->render();
233  }
234  // Setting up the buttons and markers for docheader
235  $this->getButtons();
236  // Build the <body> for the module
237  $this->moduleTemplate->setTitle($lang->getLL('movingElement'));
238  }
239 
243  protected function getButtons()
244  {
245  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
246  if ($this->page_id) {
247  if ((string)$this->table === 'pages') {
248  $cshButton = $buttonBar->makeHelpButton()
249  ->setModuleName('xMOD_csh_corebe')
250  ->setFieldName('move_el_pages');
251  $buttonBar->addButton($cshButton);
252  } elseif ((string)$this->table === 'tt_content') {
253  $cshButton = $buttonBar->makeHelpButton()
254  ->setModuleName('xMOD_csh_corebe')
255  ->setFieldName('move_el_cs');
256  $buttonBar->addButton($cshButton);
257  }
258 
259  if ($this->R_URI) {
260  $backButton = $buttonBar->makeLinkButton()
261  ->setHref($this->R_URI)
262  ->setTitle($this->getLanguageService()->getLL('goBack'))
263  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
264  'actions-view-go-back',
266  ));
267  $buttonBar->addButton($backButton);
268  }
269  }
270  }
271 
277  protected function getLanguageService()
278  {
279  return $GLOBALS['LANG'];
280  }
281 
287  protected function getBackendUser()
288  {
289  return $GLOBALS['BE_USER'];
290  }
291 }
static getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static readPageAccess($id, $perms_clause)
static callUserFunction($funcName, &$params, &$ref, $_='', $errorMode=0)
static getRecordToolTip(array $row, $table='pages')
static getFileAbsFileName($filename, $_=null, $_2=null)
static linkThisScript(array $getParams=[])
static makeInstance($className,... $constructorArguments)
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']