‪TYPO3CMS  11.5
PagePositionMap.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
26 
36 {
37  // EXTERNAL, static:
41  public ‪$moveOrCopy = 'move';
42 
47 
48  // How deep the position page tree will go.
52  public ‪$depth = 2;
53 
54  // INTERNAL, dynamic:
55  // Request uri
59  public ‪$R_URI = '';
60 
61  // tt_content element uid to move.
65  public ‪$moveUid;
66 
70  public ‪$checkNewPageCache = [];
71 
77  protected ‪$pageTreeClassName = PageTreeView::class;
78 
82  protected ‪$iconFactory;
83 
89  public function ‪__construct(?string ‪$pageTreeClassName = null)
90  {
91  if (‪$pageTreeClassName !== null) {
92  $this->pageTreeClassName = ‪$pageTreeClassName;
93  }
94  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
95  }
96 
97  /*************************************
98  *
99  * Page position map:
100  *
101  **************************************/
111  public function ‪positionTree($id, $pageinfo, $perms_clause, ‪$R_URI)
112  {
113  // Make page tree object
114  if ($this->pageTreeClassName === NewRecordPageTreeView::class) {
115  $pageTree = GeneralUtility::makeInstance($this->pageTreeClassName, (int)$id);
116  } else {
117  $pageTree = GeneralUtility::makeInstance($this->pageTreeClassName);
118  }
120  $pageTree->init(' AND ' . $perms_clause);
121  $pageTree->addField('pid');
122  // Initialize variables:
123  $this->R_URI = ‪$R_URI;
124  // Create page tree, in $this->depth levels.
125  $pageTree->getTree($pageinfo['pid'] ?? 0, $this->depth);
126  // Initialize variables:
127  $saveLatestUid = [];
128  $latestInvDepth = ‪$this->depth;
129  // Traverse the tree:
130  $lines = [];
131  foreach ($pageTree->tree as $cc => $dat) {
132  if ($latestInvDepth > $dat['invertedDepth']) {
133  $margin = 'style="margin-left: ' . ($dat['invertedDepth'] * 16 + 9) . 'px;"';
134  $lines[] = '<ul class="list-tree" ' . $margin . '>';
135  }
136  // Make link + parameters.
137  $latestInvDepth = $dat['invertedDepth'];
138  $saveLatestUid[$latestInvDepth] = $dat;
139  if (isset($pageTree->tree[$cc - 1])) {
140  $prev_dat = $pageTree->tree[$cc - 1];
141  // If current page, subpage?
142  if ($prev_dat['row']['uid'] == $id) {
143  // 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...
144  if (!$this->dontPrintPageInsertIcons && $this->‪checkNewPageInPid($id) && !($prev_dat['invertedDepth'] > $pageTree->tree[$cc]['invertedDepth'])) {
145  end($lines);
146  $margin = 'style="margin-left: ' . (($dat['invertedDepth'] - 1) * 16 + 9) . 'px;"';
147  $lines[] = '<ul class="list-tree" ' . $margin . '><li><span class="text-nowrap"><a href="' . htmlspecialchars($this->‪getActionLink($id, $id)) . '"><i class="t3-icon fa fa-long-arrow-left" title="' . $this->‪insertlabel() . '"></i></a></span></li></ul>';
148  }
149  }
150  // If going down
151  if ($prev_dat['invertedDepth'] > $pageTree->tree[$cc]['invertedDepth']) {
152  $prevPid = $pageTree->tree[$cc]['row']['pid'];
153  } elseif ($prev_dat['invertedDepth'] < $pageTree->tree[$cc]['invertedDepth']) {
154  // If going up
155  // First of all the previous level should have an icon:
156  if (!$this->dontPrintPageInsertIcons && $this->‪checkNewPageInPid($prev_dat['row']['pid'])) {
157  $prevPid = -$prev_dat['row']['uid'];
158  end($lines);
159  $lines[] = '<li><span class="text-nowrap"><a href="' . htmlspecialchars($this->‪getActionLink((int)$prevPid, $prev_dat['row']['pid'])) . '"><i class="t3-icon fa fa-long-arrow-left" title="' . $this->‪insertlabel() . '"></i></a></span></li>';
160  }
161  // Then set the current prevPid
162  $prevPid = -$prev_dat['row']['pid'];
163  if ($prevPid !== $dat['row']['pid']) {
164  $lines[] = '</ul>';
165  }
166  } else {
167  // In on the same level
168  $prevPid = -$prev_dat['row']['uid'];
169  }
170  } else {
171  // First in the tree
172  $prevPid = $dat['row']['pid'];
173  }
174  // print arrow on the same level
175  if (!$this->dontPrintPageInsertIcons && $this->‪checkNewPageInPid($dat['row']['pid'])) {
176  $lines[] = '<span class="text-nowrap"><a href="' . htmlspecialchars($this->‪getActionLink($prevPid, $dat['row']['pid'])) . '"><i class="t3-icon fa fa-long-arrow-left" title="' . $this->‪insertlabel() . '"></i></a></span>';
177  }
178  // The line with the icon and title:
179  $toolTip = BackendUtility::getRecordToolTip($dat['row'], 'pages');
180  $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord('pages', $dat['row'], ‪Icon::SIZE_SMALL)->render() . '</span>';
181 
182  $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>';
183  }
184  // If the current page was the last in the tree:
185  $prev_dat = end($pageTree->tree);
186  if ($prev_dat['row']['uid'] == $id) {
187  if (!$this->dontPrintPageInsertIcons && $this->‪checkNewPageInPid($id)) {
188  $lines[] = '<ul class="list-tree" style="margin-left: 25px"><li><span class="text-nowrap"><a href="' . htmlspecialchars($this->‪getActionLink($id, $id)) . '"><i class="t3-icon fa fa-long-arrow-left" title="' . $this->‪insertlabel() . '"></i></a></span></li></ul>';
189  }
190  }
191  for ($a = $latestInvDepth; $a <= ‪$this->depth; $a++) {
192  $dat = $saveLatestUid[$a];
193  $prevPid = -$dat['row']['uid'];
194  if (!$this->dontPrintPageInsertIcons && $this->‪checkNewPageInPid($dat['row']['pid'])) {
195  if ($latestInvDepth < $dat['invertedDepth']) {
196  $lines[] = '</ul>';
197  }
198  $lines[] = '<span class="text-nowrap"><a href="' . htmlspecialchars($this->‪getActionLink((int)$prevPid, $dat['row']['pid'])) . '"><i class="t3-icon fa fa-long-arrow-left" title="' . $this->‪insertlabel() . '"></i></a></span>';
199  }
200  }
201 
202  $code = '<ul class="list-tree">';
203 
204  foreach ($lines as $line) {
205  if ((strpos($line, '<ul') === 0) || (strpos($line, '</ul') === 0)) {
206  $code .= $line;
207  } else {
208  $code .= '<li>' . $line . '</li>';
209  }
210  }
211 
212  $code .= '</ul>';
213  return $code;
214  }
215 
224  public function ‪boldTitle($t_code, $dat, $id)
225  {
226  if ($dat['row']['uid'] == $id) {
227  $t_code = '<strong>' . $t_code . '</strong>';
228  }
229  return $t_code;
230  }
231 
242  public function ‪getActionLink($pid, $newPagePID): string
243  {
244  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
245  $TSconfig = BackendUtility::getPagesTSconfig($newPagePID)['mod.']['newPageWizard.'] ?? [];
246  if (isset($TSconfig['override']) && !empty($TSconfig['override'])) {
247  $url = $uriBuilder->buildUriFromRoute(
248  $TSconfig['override'],
249  [
250  'positionPid' => $pid,
251  'newPageId' => $newPagePID,
252  'cmd' => 'crPage',
253  'returnUrl' => $this->R_URI,
254  ]
255  );
256  return (string)$url;
257  }
258 
259  return (string)$uriBuilder->buildUriFromRoute('record_edit', [
260  'edit' => [
261  'pages' => [
262  $pid => 'new',
263  ],
264  ],
265  'returnNewPageId' => '1',
266  'returnUrl' => $this->R_URI,
267  ]);
268  }
269 
275  protected function ‪insertlabel()
276  {
277  return htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:insertNewPageHere'));
278  }
279 
287  public function ‪linkPageTitle($str, $rec)
288  {
289  return $str;
290  }
291 
299  public function ‪checkNewPageInPid($pid)
300  {
301  if (!isset($this->checkNewPageCache[$pid])) {
302  $pidInfo = BackendUtility::getRecord('pages', $pid);
303  $this->checkNewPageCache[$pid] = $this->‪getBackendUser()->‪isAdmin() || $this->‪getBackendUser()->‪doesUserHaveAccess($pidInfo, ‪Permission::PAGE_NEW);
304  }
305  return $this->checkNewPageCache[$pid];
306  }
307 
313  protected function ‪getBackendUser()
314  {
315  return ‪$GLOBALS['BE_USER'];
316  }
317 
323  protected function ‪getLanguageService()
324  {
325  return ‪$GLOBALS['LANG'];
326  }
327 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\linkPageTitle
‪string linkPageTitle($str, $rec)
Definition: PagePositionMap.php:279
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\$moveUid
‪int $moveUid
Definition: PagePositionMap.php:60
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_NEW
‪const PAGE_NEW
Definition: Permission.php:50
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\$pageTreeClassName
‪string $pageTreeClassName
Definition: PagePositionMap.php:70
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\$R_URI
‪string $R_URI
Definition: PagePositionMap.php:55
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isAdmin
‪bool isAdmin()
Definition: BackendUserAuthentication.php:245
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\$checkNewPageCache
‪array $checkNewPageCache
Definition: PagePositionMap.php:64
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\positionTree
‪string positionTree($id, $pageinfo, $perms_clause, $R_URI)
Definition: PagePositionMap.php:103
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\insertlabel
‪string insertlabel()
Definition: PagePositionMap.php:267
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\getActionLink
‪string getActionLink($pid, $newPagePID)
Definition: PagePositionMap.php:234
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: PagePositionMap.php:305
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\checkNewPageInPid
‪bool checkNewPageInPid($pid)
Definition: PagePositionMap.php:291
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\getLanguageService
‪LanguageService getLanguageService()
Definition: PagePositionMap.php:315
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap
Definition: PagePositionMap.php:36
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\doesUserHaveAccess
‪bool doesUserHaveAccess($row, $perms)
Definition: BackendUserAuthentication.php:283
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\boldTitle
‪string boldTitle($t_code, $dat, $id)
Definition: PagePositionMap.php:216
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\$iconFactory
‪IconFactory $iconFactory
Definition: PagePositionMap.php:74
‪TYPO3\CMS\Backend\Tree\View
Definition: AbstractContentPagePositionMap.php:18
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\$depth
‪int $depth
Definition: PagePositionMap.php:49
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\$dontPrintPageInsertIcons
‪int $dontPrintPageInsertIcons
Definition: PagePositionMap.php:44
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\$moveOrCopy
‪string $moveOrCopy
Definition: PagePositionMap.php:40
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Tree\View\PagePositionMap\__construct
‪__construct(?string $pageTreeClassName=null)
Definition: PagePositionMap.php:81