TYPO3 CMS  TYPO3_7-6
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 
25 
30 {
34  public $sys_language = 0;
35 
39  public $page_id;
40 
44  public $table;
45 
49  public $R_URI;
50 
55 
59  public $moveUid;
60 
64  public $makeCopy;
65 
71  public $perms_clause;
72 
78  public $content;
79 
83  public function __construct()
84  {
85  parent::__construct();
86  $this->getLanguageService()->includeLLFile('EXT:lang/locallang_misc.xlf');
87  $GLOBALS['SOBE'] = $this;
88  $this->init();
89  }
90 
96  public function init()
97  {
98  // Setting internal vars:
99  $this->sys_language = (int)GeneralUtility::_GP('sys_language');
100  $this->page_id = (int)GeneralUtility::_GP('uid');
101  $this->table = GeneralUtility::_GP('table');
102  $this->R_URI = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
103  $this->input_moveUid = GeneralUtility::_GP('moveUid');
104  $this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
105  $this->makeCopy = GeneralUtility::_GP('makeCopy');
106  // Select-pages where clause for read-access:
107  $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
108  $this->content = '<h1>' . $this->getLanguageService()->getLL('movingElement') . '</h1>';
109  }
110 
119  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
120  {
121  $this->main();
122 
123  $this->moduleTemplate->setContent($this->content);
124  $response->getBody()->write($this->moduleTemplate->renderContent());
125  return $response;
126  }
127 
133  public function main()
134  {
135  $lang = $this->getLanguageService();
136  if ($this->page_id) {
137  $backendUser = $this->getBackendUser();
138  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
139  // Get record for element:
140  $elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid);
141  // Headerline: Icon, record title:
142  $headerLine = '<span ' . BackendUtility::getRecordToolTip($elRow, $this->table) . '>' . $this->moduleTemplate->getIconFactory()->getIconForRecord($this->table, $elRow, Icon::SIZE_SMALL)->render() . '</span>';
143  $headerLine .= BackendUtility::getRecordTitle($this->table, $elRow, true);
144  // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
145  $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(['makeCopy' => !$this->makeCopy])) . ';';
146  $headerLine .= '<div><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></div>';
147  // Add the header-content to the module content:
148  $this->content .= '<div>' . $headerLine . '</div>';
149  // Reset variable to pick up the module content in:
150  $code = '';
151  // IF the table is "pages":
152  if ((string)$this->table == 'pages') {
153  // Get page record (if accessible):
154  $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
155  if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
156  // Initialize the position map:
157  $posMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class);
158  $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
159  // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
160  if ($pageInfo['pid']) {
161  $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
162  if (is_array($pidPageInfo)) {
163  if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
164  $code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(['uid' => (int)$pageInfo['pid'], 'moveUid' => $this->moveUid])) . '">' . $this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-up', Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '</a><br />';
165  } else {
166  $code .= $this->moduleTemplate->getIconFactory()->getIconForRecord('pages', $pidPageInfo, Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '<br />';
167  }
168  }
169  }
170  // Create the position tree:
171  $code .= $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  $headerLine = '<span ' . BackendUtility::getRecordToolTip($pageInfo, 'pages') . '>'
191  . $this->moduleTemplate->getIconFactory()->getIconForRecord(
192  'pages',
193  $pageInfo,
195  )->render() . '</span>';
196  $headerLine .= BackendUtility::getRecordTitle('pages', $pageInfo, true);
197  // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
198  // SHARED page-TSconfig settings.
199  // $modTSconfig_SHARED = BackendUtility::getModTSconfig($this->pageId, 'mod.SHARED');
200  $colPosArray = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
201  $colPosIds = [];
202  foreach ($colPosArray as $colPos) {
203  $colPosIds[] = $colPos[1];
204  }
205  // Removing duplicates, if any
206  $colPosList = implode(',', array_unique($colPosIds));
207  // Adding parent page-header and the content element columns from position-map:
208  $code = $headerLine . '<br />';
209  $code .= $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
210  // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
211  $code .= '<br /><br />';
212  if ($pageInfo['pid']) {
213  $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
214  if (is_array($pidPageInfo)) {
215  if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
216  $code .= '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript([
217  'uid' => (int)$pageInfo['pid'],
218  'moveUid' => $this->moveUid
219  ])) . '">' . $this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-up', Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '</a><br />';
220  } else {
221  $code .= $this->moduleTemplate->getIconFactory()->getIconForRecord('pages', $pidPageInfo, Icon::SIZE_SMALL)->render() . BackendUtility::getRecordTitle('pages', $pidPageInfo, true) . '<br />';
222  }
223  }
224  }
225  // Create the position tree (for pages):
226  $code .= $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
227  }
228  }
229  // Add the $code content as a new section to the module:
230  $this->content .= '<h2>' . $lang->getLL('selectPositionOfElement') . '</h2>';
231  $this->content .= '<div>' . $code . '</div>';
232  }
233  // Setting up the buttons and markers for docheader
234  $this->getButtons();
235  // Build the <body> for the module
236  $this->moduleTemplate->setTitle($lang->getLL('movingElement'));
237  }
238 
245  public function printContent()
246  {
248  echo $this->content;
249  }
250 
254  protected function getButtons()
255  {
256  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
257  if ($this->page_id) {
258  if ((string)$this->table == 'pages') {
259  $cshButton = $buttonBar->makeHelpButton()
260  ->setModuleName('xMOD_csh_corebe')
261  ->setFieldName('move_el_pages');
262  $buttonBar->addButton($cshButton);
263  } elseif ((string)$this->table == 'tt_content') {
264  $cshButton = $buttonBar->makeHelpButton()
265  ->setModuleName('xMOD_csh_corebe')
266  ->setFieldName('move_el_cs');
267  $buttonBar->addButton($cshButton);
268  }
269 
270  if ($this->R_URI) {
271  $backButton = $buttonBar->makeLinkButton()
272  ->setHref($this->R_URI)
273  ->setTitle($this->getLanguageService()->getLL('goBack'))
274  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
275  'actions-view-go-back',
277  ));
278  $buttonBar->addButton($backButton);
279  }
280  }
281  }
282 
288  protected function getLanguageService()
289  {
290  return $GLOBALS['LANG'];
291  }
292 
298  protected function getBackendUser()
299  {
300  return $GLOBALS['BE_USER'];
301  }
302 }
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static readPageAccess($id, $perms_clause)
static getRecordToolTip(array $row, $table='pages')
static linkThisScript(array $getParams=[])
static callUserFunction($funcName, &$params, &$ref, $checkPrefix='', $errorMode=0)
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']
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)