TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
PagePositionMap.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\View;
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 
28 
34 {
35  // EXTERNAL, static:
39  public $moveOrCopy = 'move';
40 
45 
46  // How deep the position page tree will go.
50  public $depth = 2;
51 
52  // Can be set to the sys_language uid to select content elements for.
57 
58  // INTERNAL, dynamic:
59  // Request uri
63  public $R_URI = '';
64 
65  // Element id.
69  public $elUid = '';
70 
71  // tt_content element uid to move.
75  public $moveUid = '';
76 
77  // Caching arrays:
81  public $getModConfigCache = [];
82 
86  public $checkNewPageCache = [];
87 
88  // Label keys:
92  public $l_insertNewPageHere = 'insertNewPageHere';
93 
97  public $l_insertNewRecordHere = 'insertNewRecordHere';
98 
102  public $modConfigStr = 'mod.web_list.newPageWiz';
103 
109  protected $pageTreeClassName = ElementBrowserPageTreeView::class;
110 
114  protected $iconFactory;
115 
121  public function __construct($pageTreeClassName = null)
122  {
123  if ($pageTreeClassName !== null) {
124  $this->pageTreeClassName = $pageTreeClassName;
125  }
126  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
127  }
128 
129  /*************************************
130  *
131  * Page position map:
132  *
133  **************************************/
143  public function positionTree($id, $pageinfo, $perms_clause, $R_URI)
144  {
145  // Make page tree object:
147  $pageTree = GeneralUtility::makeInstance($this->pageTreeClassName);
148  $pageTree->init(' AND ' . $perms_clause);
149  $pageTree->addField('pid');
150  // Initialize variables:
151  $this->R_URI = $R_URI;
152  $this->elUid = $id;
153  // Create page tree, in $this->depth levels.
154  $pageTree->getTree($pageinfo['pid'], $this->depth);
155  // Initialize variables:
156  $saveLatestUid = [];
157  $latestInvDepth = $this->depth;
158  // Traverse the tree:
159  $lines = [];
160  foreach ($pageTree->tree as $cc => $dat) {
161  if ($latestInvDepth > $dat['invertedDepth']) {
162  $margin = 'style="margin-left: ' . ($dat['invertedDepth'] * 16 + 9) . 'px;"';
163  $lines[] = '<ul class="list-tree" ' . $margin . '>';
164  }
165  // Make link + parameters.
166  $latestInvDepth = $dat['invertedDepth'];
167  $saveLatestUid[$latestInvDepth] = $dat;
168  if (isset($pageTree->tree[$cc - 1])) {
169  $prev_dat = $pageTree->tree[$cc - 1];
170  // If current page, subpage?
171  if ($prev_dat['row']['uid'] == $id) {
172  // 1) It must be allowed to create a new page and 2) If there are subpages there is no need to render a subpage icon here - it'll be done over the subpages...
173  if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($id) && !($prev_dat['invertedDepth'] > $pageTree->tree[$cc]['invertedDepth'])) {
174  end($lines);
175  $lines[] = '<li><span class="text-nowrap"><a href="#" onclick="' . htmlspecialchars($this->onClickEvent($id, $id, 1)) . '"><i class="t3-icon fa fa-long-arrow-left" title="' . $this->insertlabel() . '"></i></a></span></li>';
176  }
177  }
178  // If going down
179  if ($prev_dat['invertedDepth'] > $pageTree->tree[$cc]['invertedDepth']) {
180  $prevPid = $pageTree->tree[$cc]['row']['pid'];
181  } elseif ($prev_dat['invertedDepth'] < $pageTree->tree[$cc]['invertedDepth']) {
182  // If going up
183  // First of all the previous level should have an icon:
184  if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($prev_dat['row']['pid'])) {
185  $prevPid = -$prev_dat['row']['uid'];
186  end($lines);
187  $lines[] = '<li><span class="text-nowrap"><a href="#" onclick="' . htmlspecialchars($this->onClickEvent($prevPid, $prev_dat['row']['pid'], 2)) . '"><i class="t3-icon fa fa-long-arrow-left" title="' . $this->insertlabel() . '"></i></a></span></li>';
188  }
189  // Then set the current prevPid
190  $prevPid = -$prev_dat['row']['pid'];
191  if ($prevPid !== $dat['row']['pid']) {
192  $lines[] = '</ul>';
193  }
194  } else {
195  // In on the same level
196  $prevPid = -$prev_dat['row']['uid'];
197  }
198  } else {
199  // First in the tree
200  $prevPid = $dat['row']['pid'];
201  }
202  // print arrow on the same level
203  if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($dat['row']['pid'])) {
204  $lines[] = '<span class="text-nowrap"><a href="#" onclick="' . htmlspecialchars($this->onClickEvent($prevPid, $dat['row']['pid'], 3)) . '"><i class="t3-icon fa fa-long-arrow-left" title="' . $this->insertlabel() . '"></i></a></span>';
205  }
206  // The line with the icon and title:
207  $toolTip = BackendUtility::getRecordToolTip($dat['row'], 'pages');
208  $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord('pages', $dat['row'], Icon::SIZE_SMALL)->render() . '</span>';
209 
210  $lines[] = '<span class="text-nowrap">' . $icon . $this->linkPageTitle($this->boldTitle(htmlspecialchars(GeneralUtility::fixed_lgd_cs($dat['row']['title'], $this->getBackendUser()->uc['titleLen'])), $dat, $id), $dat['row']) . '</span>';
211  }
212  // If the current page was the last in the tree:
213  $prev_dat = end($pageTree->tree);
214  if ($prev_dat['row']['uid'] == $id) {
215  if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($id)) {
216  $lines[] = '<ul class="list-tree" style="margin-left: 25px"><li><span class="text-nowrap"><a href="#" onclick="' . htmlspecialchars($this->onClickEvent($id, $id, 4)) . '"><i class="t3-icon fa fa-long-arrow-left" title="' . $this->insertlabel() . '"></i></a></span></li></ul>';
217  }
218  }
219  for ($a = $latestInvDepth; $a <= $this->depth; $a++) {
220  $dat = $saveLatestUid[$a];
221  $prevPid = -$dat['row']['uid'];
222  if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($dat['row']['pid'])) {
223  if ($latestInvDepth < $dat['invertedDepth']) {
224  $lines[] = '</ul>';
225  }
226  $lines[] = '<span class="text-nowrap"><a href="#" onclick="' . htmlspecialchars($this->onClickEvent($prevPid, $dat['row']['pid'], 5)) . '"><i class="t3-icon fa fa-long-arrow-left" title="' . $this->insertlabel() . '"></i></a></span>';
227  }
228  }
229 
230  $code = '<ul class="list-tree">';
231 
232  foreach ($lines as $line) {
233  if ((substr($line, 0, 3) === '<ul') || (substr($line, 0, 4) === '</ul')) {
234  $code .= $line;
235  } else {
236  $code .= '<li>' . $line . '</li>';
237  }
238  }
239 
240  $code .= '</ul>';
241  return $code;
242  }
243 
252  public function boldTitle($t_code, $dat, $id)
253  {
254  if ($dat['row']['uid'] == $id) {
255  $t_code = '<strong>' . $t_code . '</strong>';
256  }
257  return $t_code;
258  }
259 
270  public function onClickEvent($pid, $newPagePID)
271  {
272  $TSconfig = BackendUtility::getModTSconfig($newPagePID, 'mod.newPageWizard');
273  $TSconfig = $TSconfig['properties'];
274  if (isset($TSconfig['override']) && !empty($TSconfig['override'])) {
275  $url = BackendUtility::getModuleUrl($TSconfig['override'], [
276  'positionPid' => $pid,
277  'newPageId' => $newPagePID,
278  'cmd' => 'crPage',
279  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')]
280  );
281  return 'window.location.href=' . GeneralUtility::quoteJSvalue($url) . ';';
282  }
283  $params = '&edit[pages][' . $pid . ']=new&returnNewPageId=1';
284  return BackendUtility::editOnClick($params, '', $this->R_URI);
285  }
286 
292  public function insertlabel()
293  {
294  return htmlspecialchars($this->getLanguageService()->getLL($this->l_insertNewPageHere));
295  }
296 
304  public function linkPageTitle($str, $rec)
305  {
306  return $str;
307  }
308 
316  public function checkNewPageInPid($pid)
317  {
318  if (!isset($this->checkNewPageCache[$pid])) {
319  $pidInfo = BackendUtility::getRecord('pages', $pid);
320  $this->checkNewPageCache[$pid] = $this->getBackendUser()->isAdmin() || $this->getBackendUser()->doesUserHaveAccess($pidInfo, 8);
321  }
322  return $this->checkNewPageCache[$pid];
323  }
324 
332  public function getModConfig($pid)
333  {
334  if (!isset($this->getModConfigCache[$pid])) {
335  // Acquiring TSconfig for this PID:
336  $this->getModConfigCache[$pid] = BackendUtility::getModTSconfig($pid, $this->modConfigStr);
337  }
338  return $this->getModConfigCache[$pid]['properties'];
339  }
340 
341  /*************************************
342  *
343  * Content element positioning:
344  *
345  **************************************/
356  public function printContentElementColumns($pid, $moveUid, $colPosList, $showHidden, $R_URI)
357  {
358  $this->R_URI = $R_URI;
359  $this->moveUid = $moveUid;
360  $colPosArray = GeneralUtility::trimExplode(',', $colPosList, true);
361  $lines = [];
362  foreach ($colPosArray as $kk => $vv) {
363  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
364  $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
365  if ($showHidden) {
366  $queryBuilder->getRestrictions()
367  ->removeByType(HiddenRestriction::class)
368  ->removeByType(StartTimeRestriction::class)
369  ->removeByType(EndTimeRestriction::class);
370  }
371  $queryBuilder
372  ->select('*')
373  ->from('tt_content')
374  ->where(
375  $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)),
376  $queryBuilder->expr()->eq('colPos', $queryBuilder->createNamedParameter($vv, \PDO::PARAM_INT))
377  )
378  ->orderBy('sorting');
379 
380  if ((string)$this->cur_sys_language !== '') {
381  $queryBuilder->andWhere(
382  $queryBuilder->expr()->eq(
383  'sys_language_uid',
384  $queryBuilder->createNamedParameter($this->cur_sys_language, \PDO::PARAM_INT)
385  )
386  );
387  }
388 
389  $res = $queryBuilder->execute();
390  $lines[$vv] = [];
391  $lines[$vv][] = $this->insertPositionIcon('', $vv, $kk, $moveUid, $pid);
392 
393  while ($row = $res->fetch()) {
394  BackendUtility::workspaceOL('tt_content', $row);
395  if (is_array($row)) {
396  $lines[$vv][] = $this->wrapRecordHeader($this->getRecordHeader($row), $row);
397  $lines[$vv][] = $this->insertPositionIcon($row, $vv, $kk, $moveUid, $pid);
398  }
399  }
400  }
401  return $this->printRecordMap($lines, $colPosArray, $pid);
402  }
403 
412  public function printRecordMap($lines, $colPosArray, $pid = 0)
413  {
414  $count = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(count($colPosArray), 1);
415  $backendLayout = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getSelectedBackendLayout', $pid, $this);
416  if (isset($backendLayout['__config']['backend_layout.'])) {
417  $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
418  $table = '<div class="table-fit"><table class="table table-condensed table-bordered table-vertical-top">';
419  $colCount = (int)$backendLayout['__config']['backend_layout.']['colCount'];
420  $rowCount = (int)$backendLayout['__config']['backend_layout.']['rowCount'];
421  $table .= '<colgroup>';
422  for ($i = 0; $i < $colCount; $i++) {
423  $table .= '<col style="width:' . 100 / $colCount . '%"></col>';
424  }
425  $table .= '</colgroup>';
426  $table .= '<tbody>';
427  $tcaItems = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $pid, $this);
428  // Cycle through rows
429  for ($row = 1; $row <= $rowCount; $row++) {
430  $rowConfig = $backendLayout['__config']['backend_layout.']['rows.'][$row . '.'];
431  if (!isset($rowConfig)) {
432  continue;
433  }
434  $table .= '<tr>';
435  for ($col = 1; $col <= $colCount; $col++) {
436  $columnConfig = $rowConfig['columns.'][$col . '.'];
437  if (!isset($columnConfig)) {
438  continue;
439  }
440  // Which tt_content colPos should be displayed inside this cell
441  $columnKey = (int)$columnConfig['colPos'];
442  $head = '';
443  foreach ($tcaItems as $item) {
444  if ($item[1] == $columnKey) {
445  $head = htmlspecialchars($this->getLanguageService()->sL($item[0]));
446  }
447  }
448  // Render the grid cell
449  $table .= '<td'
450  . (isset($columnConfig['colspan']) ? ' colspan="' . $columnConfig['colspan'] . '"' : '')
451  . (isset($columnConfig['rowspan']) ? ' rowspan="' . $columnConfig['rowspan'] . '"' : '')
452  . ' class="col-nowrap col-min'
453  . (!isset($columnConfig['colPos']) ? ' warning' : '')
454  . (isset($columnConfig['colPos']) && !$head ? ' danger' : '') . '">';
455  // Render header
456  $table .= '<p>';
457  if (isset($columnConfig['colPos']) && $head) {
458  $table .= '<strong>' . $this->wrapColumnHeader($head, '', '') . '</strong>';
459  } elseif ($columnConfig['colPos']) {
460  $table .= '<em>' . $this->wrapColumnHeader($this->getLanguageService()->getLL('noAccess'), '', '') . '</em>';
461  } else {
462  $table .= '<em>' . $this->wrapColumnHeader(($columnConfig['name']?: '') . ' (' . $this->getLanguageService()->getLL('notAssigned') . ')', '', '') . '</em>';
463  }
464  $table .= '</p>';
465  // Render lines
466  if (isset($columnConfig['colPos']) && $head && !empty($lines[$columnKey])) {
467  $table .= '<ul class="list-unstyled">';
468  foreach ($lines[$columnKey] as $line) {
469  $table .= '<li>' . $line . '</li>';
470  }
471  $table .= '</ul>';
472  }
473  $table .= '</td>';
474  }
475  $table .= '</tr>';
476  }
477  $table .= '</tbody>';
478  $table .= '</table></div>';
479  } else {
480  // Traverse the columns here:
481  $row = '';
482  foreach ($colPosArray as $kk => $vv) {
483  $row .= '<td class="col-nowrap col-min" width="' . round(100 / $count) . '%">';
484  $row .= '<p><strong>' . $this->wrapColumnHeader(htmlspecialchars($this->getLanguageService()->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $vv))), $vv) . '</strong></p>';
485  if (!empty($lines[$vv])) {
486  $row .= '<ul class="list-unstyled">';
487  foreach ($lines[$vv] as $line) {
488  $row .= '<li>' . $line . '</li>';
489  }
490  $row .= '</ul>';
491  }
492  $row .= '</td>';
493  }
494  $table = '
495 
496  <!--
497  Map of records in columns:
498  -->
499  <div class="table-fit">
500  <table class="table table-condensed table-bordered table-vertical-top">
501  <tr>' . $row . '</tr>
502  </table>
503  </div>
504 
505  ';
506  }
507  return $table;
508  }
509 
518  public function wrapColumnHeader($str, $vv)
519  {
520  return $str;
521  }
522 
534  public function insertPositionIcon($row, $vv, $kk, $moveUid, $pid)
535  {
536  if (is_array($row) && !empty($row['uid'])) {
537  // Use record uid for the hash when inserting after this content element
538  $uid = $row['uid'];
539  } else {
540  // No uid means insert at first position in the column
541  $uid = '';
542  }
543  $cc = hexdec(substr(md5($uid . '-' . $vv . '-' . $kk), 0, 4));
544  return '<a href="#" onclick="' . htmlspecialchars($this->onClickInsertRecord($row, $vv, $moveUid, $pid, $this->cur_sys_language)) . '">' . '<i class="t3-icon fa fa-long-arrow-left" name="mImgEnd' . $cc . '" title="' . htmlspecialchars($this->getLanguageService()->getLL($this->l_insertNewRecordHere)) . '"></i></a>';
545  }
546 
558  public function onClickInsertRecord($row, $vv, $moveUid, $pid, $sys_lang = 0)
559  {
560  $table = 'tt_content';
561  if (is_array($row)) {
562  $location = BackendUtility::getModuleUrl('tce_db') . '&cmd[' . $table . '][' . $moveUid . '][' . $this->moveOrCopy . ']=-' . $row['uid'] . '&prErr=1&uPT=1&vC=' . $this->getBackendUser()->veriCode();
563  } else {
564  $location = BackendUtility::getModuleUrl('tce_db') . '&cmd[' . $table . '][' . $moveUid . '][' . $this->moveOrCopy . ']=' . $pid . '&data[' . $table . '][' . $moveUid . '][colPos]=' . $vv . '&prErr=1&vC=' . $this->getBackendUser()->veriCode();
565  }
566  $location .= '&redirect=' . rawurlencode($this->R_URI);
567  // returns to prev. page
568  return 'window.location.href=' . GeneralUtility::quoteJSvalue($location) . ';return false;';
569  }
570 
578  public function wrapRecordHeader($str, $row)
579  {
580  return $str;
581  }
582 
589  public function getRecordHeader($row)
590  {
591  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
592  $toolTip = BackendUtility::getRecordToolTip($row, 'tt_content');
593  $line = '<span ' . $toolTip . ' title="' . BackendUtility::getRecordIconAltText($row, 'tt_content') . '">' . $iconFactory->getIconForRecord('tt_content', $row, Icon::SIZE_SMALL)->render() . '</span>';
594  $line .= BackendUtility::getRecordTitle('tt_content', $row, true);
595  return $this->wrapRecordTitle($line, $row);
596  }
597 
605  public function wrapRecordTitle($str, $row)
606  {
607  return '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(['uid' => (int)$row['uid'], 'moveUid' => ''])) . '">' . $str . '</a>';
608  }
609 
615  protected function getBackendUser()
616  {
617  return $GLOBALS['BE_USER'];
618  }
619 
625  protected function getLanguageService()
626  {
627  return $GLOBALS['LANG'];
628  }
629 }
printRecordMap($lines, $colPosArray, $pid=0)
insertPositionIcon($row, $vv, $kk, $moveUid, $pid)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=false)
static getRecord($table, $uid, $fields= '*', $where= '', $useDeleteClause=true)
static linkThisScript(array $getParams=[])
onClickInsertRecord($row, $vv, $moveUid, $pid, $sys_lang=0)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
static callUserFunction($funcName, &$params, &$ref, $_= '', $errorMode=0)
printContentElementColumns($pid, $moveUid, $colPosList, $showHidden, $R_URI)