TYPO3 CMS  TYPO3_7-6
PagePositionMap.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 
31 {
32  // EXTERNAL, static:
36  public $moveOrCopy = 'move';
37 
42 
43  // How deep the position page tree will go.
47  public $depth = 2;
48 
49  // Can be set to the sys_language uid to select content elements for.
54 
55  // INTERNAL, dynamic:
56  // Request uri
60  public $R_URI = '';
61 
62  // Element id.
66  public $elUid = '';
67 
68  // tt_content element uid to move.
72  public $moveUid = '';
73 
74  // Caching arrays:
78  public $getModConfigCache = [];
79 
83  public $checkNewPageCache = [];
84 
85  // Label keys:
89  public $l_insertNewPageHere = 'insertNewPageHere';
90 
94  public $l_insertNewRecordHere = 'insertNewRecordHere';
95 
99  public $modConfigStr = 'mod.web_list.newPageWiz';
100 
106  protected $pageTreeClassName = ElementBrowserPageTreeView::class;
107 
111  protected $iconFactory;
112 
118  public function __construct($pageTreeClassName = null)
119  {
120  if ($pageTreeClassName !== null) {
121  $this->pageTreeClassName = $pageTreeClassName;
122  }
123  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
124  }
125 
126  /*************************************
127  *
128  * Page position map:
129  *
130  **************************************/
140  public function positionTree($id, $pageinfo, $perms_clause, $R_URI)
141  {
142  // Make page tree object:
144  $pageTree = GeneralUtility::makeInstance($this->pageTreeClassName);
145  $pageTree->init(' AND ' . $perms_clause);
146  $pageTree->addField('pid');
147  // Initialize variables:
148  $this->R_URI = $R_URI;
149  $this->elUid = $id;
150  // Create page tree, in $this->depth levels.
151  $pageTree->getTree($pageinfo['pid'], $this->depth);
152  // Initialize variables:
153  $saveLatestUid = [];
154  $latestInvDepth = $this->depth;
155  // Traverse the tree:
156  $lines = [];
157  foreach ($pageTree->tree as $cc => $dat) {
158  if ($latestInvDepth > $dat['invertedDepth']) {
159  $margin = 'style="margin-left: ' . ($dat['invertedDepth'] * 16 + 9) . 'px;"';
160  $lines[] = '<ul class="list-tree" ' . $margin . '>';
161  }
162  // Make link + parameters.
163  $latestInvDepth = $dat['invertedDepth'];
164  $saveLatestUid[$latestInvDepth] = $dat;
165  if (isset($pageTree->tree[$cc - 1])) {
166  $prev_dat = $pageTree->tree[$cc - 1];
167  // If current page, subpage?
168  if ($prev_dat['row']['uid'] == $id) {
169  // 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...
170  if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($id) && !($prev_dat['invertedDepth'] > $pageTree->tree[$cc]['invertedDepth'])) {
171  end($lines);
172  $margin = 'style="margin-left: ' . (($dat['invertedDepth'] - 1) * 16 + 9) . 'px;"';
173  $lines[] = '<ul class="list-tree" ' . $margin . '><li><span class="text-nowrap"><a href="#" onclick="' . htmlspecialchars($this->onClickEvent($id, $id)) . '"><i class="t3-icon fa fa-long-arrow-left" title="' . $this->insertlabel() . '"></i></a></span></li></ul>';
174  }
175  }
176  // If going down
177  if ($prev_dat['invertedDepth'] > $pageTree->tree[$cc]['invertedDepth']) {
178  $prevPid = $pageTree->tree[$cc]['row']['pid'];
179  } elseif ($prev_dat['invertedDepth'] < $pageTree->tree[$cc]['invertedDepth']) {
180  // If going up
181  // First of all the previous level should have an icon:
182  if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($prev_dat['row']['pid'])) {
183  $prevPid = -$prev_dat['row']['uid'];
184  end($lines);
185  $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>';
186  }
187  // Then set the current prevPid
188  $prevPid = -$prev_dat['row']['pid'];
189  if ($prevPid !== $dat['row']['pid']) {
190  $lines[] = '</ul>';
191  }
192  } else {
193  // In on the same level
194  $prevPid = -$prev_dat['row']['uid'];
195  }
196  } else {
197  // First in the tree
198  $prevPid = $dat['row']['pid'];
199  }
200  // print arrow on the same level
201  if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($dat['row']['pid'])) {
202  $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>';
203  }
204  // The line with the icon and title:
205  $toolTip = BackendUtility::getRecordToolTip($dat['row'], 'pages');
206  $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord('pages', $dat['row'], Icon::SIZE_SMALL)->render() . '</span>';
207 
208  $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>';
209  }
210  // If the current page was the last in the tree:
211  $prev_dat = end($pageTree->tree);
212  if ($prev_dat['row']['uid'] == $id) {
213  if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($id)) {
214  $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>';
215  }
216  }
217  for ($a = $latestInvDepth; $a <= $this->depth; $a++) {
218  $dat = $saveLatestUid[$a];
219  $prevPid = -$dat['row']['uid'];
220  if (!$this->dontPrintPageInsertIcons && $this->checkNewPageInPid($dat['row']['pid'])) {
221  if ($latestInvDepth < $dat['invertedDepth']) {
222  $lines[] = '</ul>';
223  }
224  $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>';
225  }
226  }
227 
228  $code = '<ul class="list-tree">';
229 
230  foreach ($lines as $line) {
231  if ((substr($line, 0, 3) === '<ul') || (substr($line, 0, 4) === '</ul')) {
232  $code .= $line;
233  } else {
234  $code .= '<li>' . $line . '</li>';
235  }
236  }
237 
238  $code .= '</ul>';
239  return $code;
240  }
241 
250  public function boldTitle($t_code, $dat, $id)
251  {
252  if ($dat['row']['uid'] == $id) {
253  $t_code = '<strong>' . $t_code . '</strong>';
254  }
255  return $t_code;
256  }
257 
268  public function onClickEvent($pid, $newPagePID)
269  {
270  $TSconfigProp = $this->getModConfig($newPagePID);
271  if ($TSconfigProp['overrideWithExtension']) {
272  if (ExtensionManagementUtility::isLoaded($TSconfigProp['overrideWithExtension'])) {
273  $onclick = 'window.location.href=' . GeneralUtility::quoteJSvalue(ExtensionManagementUtility::extRelPath($TSconfigProp['overrideWithExtension']) . 'mod1/index.php?cmd=crPage&positionPid=' . $pid) . ';';
274  return $onclick;
275  }
276  }
277  $params = '&edit[pages][' . $pid . ']=new&returnNewPageId=1';
278  return BackendUtility::editOnClick($params, '', $this->R_URI);
279  }
280 
286  public function insertlabel()
287  {
288  return $this->getLanguageService()->getLL($this->l_insertNewPageHere, 1);
289  }
290 
298  public function linkPageTitle($str, $rec)
299  {
300  return $str;
301  }
302 
310  public function checkNewPageInPid($pid)
311  {
312  if (!isset($this->checkNewPageCache[$pid])) {
313  $pidInfo = BackendUtility::getRecord('pages', $pid);
314  $this->checkNewPageCache[$pid] = $this->getBackendUser()->isAdmin() || $this->getBackendUser()->doesUserHaveAccess($pidInfo, 8);
315  }
316  return $this->checkNewPageCache[$pid];
317  }
318 
326  public function getModConfig($pid)
327  {
328  if (!isset($this->getModConfigCache[$pid])) {
329  // Acquiring TSconfig for this PID:
330  $this->getModConfigCache[$pid] = BackendUtility::getModTSconfig($pid, $this->modConfigStr);
331  }
332  return $this->getModConfigCache[$pid]['properties'];
333  }
334 
335  /*************************************
336  *
337  * Content element positioning:
338  *
339  **************************************/
350  public function printContentElementColumns($pid, $moveUid, $colPosList, $showHidden, $R_URI)
351  {
352  $this->R_URI = $R_URI;
353  $this->moveUid = $moveUid;
354  $colPosArray = GeneralUtility::trimExplode(',', $colPosList, true);
355  $lines = [];
356  foreach ($colPosArray as $kk => $vv) {
357  $res = $this->getDatabase()->exec_SELECTquery('*', 'tt_content', 'pid=' . (int)$pid . ($showHidden ? '' : BackendUtility::BEenableFields('tt_content')) . ' AND colPos=' . (int)$vv . ((string)$this->cur_sys_language !== '' ? ' AND sys_language_uid=' . (int)$this->cur_sys_language : '') . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'), '', 'sorting');
358  $lines[$vv] = [];
359  $lines[$vv][] = $this->insertPositionIcon('', $vv, $kk, $moveUid, $pid);
360  while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
361  BackendUtility::workspaceOL('tt_content', $row);
362  if (is_array($row)) {
363  $lines[$vv][] = $this->wrapRecordHeader($this->getRecordHeader($row), $row);
364  $lines[$vv][] = $this->insertPositionIcon($row, $vv, $kk, $moveUid, $pid);
365  }
366  }
367  $this->getDatabase()->sql_free_result($res);
368  }
369  return $this->printRecordMap($lines, $colPosArray, $pid);
370  }
371 
380  public function printRecordMap($lines, $colPosArray, $pid = 0)
381  {
382  $count = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange(count($colPosArray), 1);
383  $backendLayout = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getSelectedBackendLayout', $pid, $this);
384  if (isset($backendLayout['__config']['backend_layout.'])) {
385  $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
386  $table = '<div class="table-fit"><table class="table table-condensed table-bordered table-vertical-top">';
387  $colCount = (int)$backendLayout['__config']['backend_layout.']['colCount'];
388  $rowCount = (int)$backendLayout['__config']['backend_layout.']['rowCount'];
389  $table .= '<colgroup>';
390  for ($i = 0; $i < $colCount; $i++) {
391  $table .= '<col style="width:' . 100 / $colCount . '%"></col>';
392  }
393  $table .= '</colgroup>';
394  $table .= '<tbody>';
395  $tcaItems = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $pid, $this);
396  // Cycle through rows
397  for ($row = 1; $row <= $rowCount; $row++) {
398  $rowConfig = $backendLayout['__config']['backend_layout.']['rows.'][$row . '.'];
399  if (!isset($rowConfig)) {
400  continue;
401  }
402  $table .= '<tr>';
403  for ($col = 1; $col <= $colCount; $col++) {
404  $columnConfig = $rowConfig['columns.'][$col . '.'];
405  if (!isset($columnConfig)) {
406  continue;
407  }
408  // Which tt_content colPos should be displayed inside this cell
409  $columnKey = (int)$columnConfig['colPos'];
410  $head = '';
411  foreach ($tcaItems as $item) {
412  if ($item[1] == $columnKey) {
413  $head = $this->getLanguageService()->sL($item[0], true);
414  }
415  }
416  // Render the grid cell
417  $table .= '<td'
418  . (isset($columnConfig['colspan']) ? ' colspan="' . $columnConfig['colspan'] . '"' : '')
419  . (isset($columnConfig['rowspan']) ? ' rowspan="' . $columnConfig['rowspan'] . '"' : '')
420  . ' class="col-nowrap col-min'
421  . (!isset($columnConfig['colPos']) ? ' warning' : '')
422  . (isset($columnConfig['colPos']) && !$head ? ' danger' : '') . '">';
423  // Render header
424  $table .= '<p>';
425  if (isset($columnConfig['colPos']) && $head) {
426  $table .= '<strong>' . $this->wrapColumnHeader($head, '', '') . '</strong>';
427  } elseif ($columnConfig['colPos']) {
428  $table .= '<em>' . $this->wrapColumnHeader($this->getLanguageService()->getLL('noAccess'), '', '') . '</em>';
429  } else {
430  $table .= '<em>' . $this->wrapColumnHeader(($columnConfig['name']?: '') . ' (' . $this->getLanguageService()->getLL('notAssigned') . ')', '', '') . '</em>';
431  }
432  $table .= '</p>';
433  // Render lines
434  if (isset($columnConfig['colPos']) && $head && !empty($lines[$columnKey])) {
435  $table .= '<ul class="list-unstyled">';
436  foreach ($lines[$columnKey] as $line) {
437  $table .= '<li>' . $line . '</li>';
438  }
439  $table .= '</ul>';
440  }
441  $table .= '</td>';
442  }
443  $table .= '</tr>';
444  }
445  $table .= '</tbody>';
446  $table .= '</table></div>';
447  } else {
448  // Traverse the columns here:
449  $row = '';
450  foreach ($colPosArray as $kk => $vv) {
451  $row .= '<td class="col-nowrap col-min" width="' . round(100 / $count) . '%">';
452  $row .= '<p><strong>' . $this->wrapColumnHeader($this->getLanguageService()->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $vv), true), $vv) . '</strong></p>';
453  if (!empty($lines[$vv])) {
454  $row .= '<ul class="list-unstyled">';
455  foreach ($lines[$vv] as $line) {
456  $row .= '<li>' . $line . '</li>';
457  }
458  $row .= '</ul>';
459  }
460  $row .= '</td>';
461  }
462  $table = '
463 
464  <!--
465  Map of records in columns:
466  -->
467  <div class="table-fit">
468  <table class="table table-condensed table-bordered table-vertical-top">
469  <tr>' . $row . '</tr>
470  </table>
471  </div>
472 
473  ';
474  }
475  return $table;
476  }
477 
486  public function wrapColumnHeader($str, $vv)
487  {
488  return $str;
489  }
490 
502  public function insertPositionIcon($row, $vv, $kk, $moveUid, $pid)
503  {
504  if (is_array($row) && !empty($row['uid'])) {
505  // Use record uid for the hash when inserting after this content element
506  $uid = $row['uid'];
507  } else {
508  // No uid means insert at first position in the column
509  $uid = '';
510  }
511  $cc = hexdec(substr(md5($uid . '-' . $vv . '-' . $kk), 0, 4));
512  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="' . $this->getLanguageService()->getLL($this->l_insertNewRecordHere, 1) . '"></i></a>';
513  }
514 
526  public function onClickInsertRecord($row, $vv, $moveUid, $pid, $sys_lang = 0)
527  {
528  $table = 'tt_content';
529  if (is_array($row)) {
530  $location = BackendUtility::getModuleUrl('tce_db') . '&cmd[' . $table . '][' . $moveUid . '][' . $this->moveOrCopy . ']=-' . $row['uid'] . '&prErr=1&uPT=1&vC=' . $this->getBackendUser()->veriCode();
531  } else {
532  $location = BackendUtility::getModuleUrl('tce_db') . '&cmd[' . $table . '][' . $moveUid . '][' . $this->moveOrCopy . ']=' . $pid . '&data[' . $table . '][' . $moveUid . '][colPos]=' . $vv . '&prErr=1&vC=' . $this->getBackendUser()->veriCode();
533  }
534  $location .= '&redirect=' . rawurlencode($this->R_URI);
535  // returns to prev. page
536  return 'window.location.href=' . GeneralUtility::quoteJSvalue($location) . ';return false;';
537  }
538 
546  public function wrapRecordHeader($str, $row)
547  {
548  return $str;
549  }
550 
557  public function getRecordHeader($row)
558  {
559  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
560  $toolTip = BackendUtility::getRecordToolTip($row, 'tt_content');
561  $line = '<span ' . $toolTip . ' title="' . BackendUtility::getRecordIconAltText($row, 'tt_content') . '">' . $iconFactory->getIconForRecord('tt_content', $row, Icon::SIZE_SMALL)->render() . '</span>';
562  $line .= BackendUtility::getRecordTitle('tt_content', $row, true);
563  return $this->wrapRecordTitle($line, $row);
564  }
565 
573  public function wrapRecordTitle($str, $row)
574  {
575  return '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(['uid' => (int)$row['uid'], 'moveUid' => ''])) . '">' . $str . '</a>';
576  }
577 
583  protected function getBackendUser()
584  {
585  return $GLOBALS['BE_USER'];
586  }
587 
593  protected function getLanguageService()
594  {
595  return $GLOBALS['LANG'];
596  }
597 
601  protected function getDatabase()
602  {
603  return $GLOBALS['TYPO3_DB'];
604  }
605 }
static editOnClick($params, $_='', $requestUri='')
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
static BEenableFields($table, $inv=false)
insertPositionIcon($row, $vv, $kk, $moveUid, $pid)
static getRecordToolTip(array $row, $table='pages')
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=false)
static linkThisScript(array $getParams=[])
static callUserFunction($funcName, &$params, &$ref, $checkPrefix='', $errorMode=0)
onClickInsertRecord($row, $vv, $moveUid, $pid, $sys_lang=0)
printRecordMap($lines, $colPosArray, $pid=0)
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
printContentElementColumns($pid, $moveUid, $colPosList, $showHidden, $R_URI)
static getRecordIconAltText($row, $table='pages')
static fixed_lgd_cs($string, $chars, $appendString='...')
$uid
Definition: server.php:38
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 deleteClause($table, $tableAlias='')
static getLabelFromItemlist($table, $col, $key)