f12590c7011731ece6154ab876d7d0f0515eee0f
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / ContentObject / Menu / AbstractMenuContentObject.php
1 <?php
2 namespace TYPO3\CMS\Frontend\ContentObject\Menu;
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
17 use TYPO3\CMS\Core\Cache\CacheManager;
18 use TYPO3\CMS\Core\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Database\RelationHandler;
20 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
21 use TYPO3\CMS\Core\TypoScript\TemplateService;
22 use TYPO3\CMS\Core\Utility\ArrayUtility;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24 use TYPO3\CMS\Core\Utility\MathUtility;
25 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
26 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
27 use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
28 use TYPO3\CMS\Frontend\Page\PageRepository;
29
30 /**
31 * Generating navigation/menus from TypoScript
32 *
33 * The HMENU content object uses this (or more precisely one of the extension classes).
34 * Among others the class generates an array of menu items. Thereafter functions from the subclasses are called.
35 * The class is always used through extension classes (like GraphicalMenuContentObject or TextMenuContentObject).
36 */
37 abstract class AbstractMenuContentObject
38 {
39 /**
40 * tells you which menu number this is. This is important when getting data from the setup
41 *
42 * @var int
43 */
44 public $menuNumber = 1;
45
46 /**
47 * 0 = rootFolder
48 *
49 * @var int
50 */
51 public $entryLevel = 0;
52
53 /**
54 * The doktype-number that defines a spacer
55 *
56 * @var string
57 */
58 public $spacerIDList = '199';
59
60 /**
61 * Doktypes that define which should not be included in a menu
62 *
63 * @var string
64 */
65 public $doktypeExcludeList = '6';
66
67 /**
68 * @var int[]
69 */
70 public $alwaysActivePIDlist = [];
71
72 /**
73 * @var string
74 */
75 public $imgNamePrefix = 'img';
76
77 /**
78 * @var int
79 */
80 public $imgNameNotRandom = 0;
81
82 /**
83 * @var bool
84 */
85 public $debug = false;
86
87 /**
88 * Loaded with the parent cObj-object when a new HMENU is made
89 *
90 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
91 */
92 public $parent_cObj = null;
93
94 /**
95 * @var string
96 */
97 public $GMENU_fixKey = 'gmenu';
98
99 /**
100 * accumulation of mount point data
101 *
102 * @var string[]
103 */
104 public $MP_array = [];
105
106 /**
107 * HMENU configuration
108 *
109 * @var array
110 */
111 public $conf = [];
112
113 /**
114 * xMENU configuration (TMENU, GMENU etc)
115 *
116 * @var array
117 */
118 public $mconf = [];
119
120 /**
121 * @var \TYPO3\CMS\Core\TypoScript\TemplateService
122 */
123 public $tmpl = null;
124
125 /**
126 * @var \TYPO3\CMS\Frontend\Page\PageRepository
127 */
128 public $sys_page = null;
129
130 /**
131 * The base page-id of the menu.
132 *
133 * @var int
134 */
135 public $id;
136
137 /**
138 * Holds the page uid of the NEXT page in the root line from the page pointed to by entryLevel;
139 * Used to expand the menu automatically if in a certain root line.
140 *
141 * @var string
142 */
143 public $nextActive;
144
145 /**
146 * The array of menuItems which is built
147 *
148 * @var array[]
149 */
150 public $menuArr;
151
152 /**
153 * @var string
154 */
155 public $hash;
156
157 /**
158 * @var array
159 */
160 public $result = [];
161
162 /**
163 * Is filled with an array of page uid numbers + RL parameters which are in the current
164 * root line (used to evaluate whether a menu item is in active state)
165 *
166 * @var array
167 */
168 public $rL_uidRegister;
169
170 /**
171 * @var string
172 */
173 public $INPfixMD5;
174
175 /**
176 * @var mixed[]
177 */
178 public $I;
179
180 /**
181 * @var string
182 */
183 public $WMresult;
184
185 /**
186 * @var string
187 */
188 public $WMfreezePrefix;
189
190 /**
191 * @var int
192 */
193 public $WMmenuItems;
194
195 /**
196 * @var array[]
197 */
198 public $WMsubmenuObjSuffixes;
199
200 /**
201 * @var string
202 */
203 public $WMextraScript;
204
205 /**
206 * @var ContentObjectRenderer
207 */
208 public $WMcObj = null;
209
210 /**
211 * Can be set to contain menu item arrays for sub-levels.
212 *
213 * @var string
214 */
215 public $alternativeMenuTempArray = '';
216
217 /**
218 * Will be 'id' in XHTML-mode
219 *
220 * @var string
221 */
222 public $nameAttribute = 'name';
223
224 /**
225 * TRUE to use cHash in generated link (normally only for the language
226 * selector and if parameters exist in the URL).
227 *
228 * @var bool
229 */
230 protected $useCacheHash = false;
231
232 /**
233 * Holds the menuArr of the parent menu, if this menu is a subMenu.
234 *
235 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, please use getter and setter methods.
236 *
237 * @var array
238 */
239 public $parentMenuArr = [];
240
241 /**
242 * Array key of the parentMenuItem in the parentMenuArr, if this menu is a subMenu.
243 *
244 * @var null|int
245 */
246 protected $parentMenuArrItemKey;
247
248 /**
249 * The initialization of the object. This just sets some internal variables.
250 *
251 * @param TemplateService $tmpl The $this->getTypoScriptFrontendController()->tmpl object
252 * @param PageRepository $sys_page The $this->getTypoScriptFrontendController()->sys_page object
253 * @param int|string $id A starting point page id. This should probably be blank since the 'entryLevel' value will be used then.
254 * @param array $conf The TypoScript configuration for the HMENU cObject
255 * @param int $menuNumber Menu number; 1,2,3. Should probably be 1
256 * @param string $objSuffix Submenu Object suffix. This offers submenus a way to use alternative configuration for specific positions in the menu; By default "1 = TMENU" would use "1." for the TMENU configuration, but if this string is set to eg. "a" then "1a." would be used for configuration instead (while "1 = " is still used for the overall object definition of "TMENU")
257 * @return bool Returns TRUE on success
258 * @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::HMENU()
259 */
260 public function start($tmpl, $sys_page, $id, $conf, $menuNumber, $objSuffix = '')
261 {
262 $tsfe = $this->getTypoScriptFrontendController();
263 // Init:
264 $this->conf = $conf;
265 $this->menuNumber = $menuNumber;
266 $this->mconf = $conf[$this->menuNumber . $objSuffix . '.'];
267 $this->debug = $tsfe->debug;
268 $this->WMcObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
269 // In XHTML and HTML5 there is no "name" attribute anymore
270 switch ($tsfe->xhtmlDoctype) {
271 case 'xhtml_strict':
272 // intended fall-through
273 case 'xhtml_11':
274 // intended fall-through
275 case 'html5':
276 // intended fall-through
277 case '':
278 // empty means that it's HTML5 by default
279 $this->nameAttribute = 'id';
280 break;
281 default:
282 $this->nameAttribute = 'name';
283 }
284 // Sets the internal vars. $tmpl MUST be the template-object. $sys_page MUST be the sys_page object
285 if ($this->conf[$this->menuNumber . $objSuffix] && is_object($tmpl) && is_object($sys_page)) {
286 $this->tmpl = $tmpl;
287 $this->sys_page = $sys_page;
288 // alwaysActivePIDlist initialized:
289 if (trim($this->conf['alwaysActivePIDlist']) || isset($this->conf['alwaysActivePIDlist.'])) {
290 if (isset($this->conf['alwaysActivePIDlist.'])) {
291 $this->conf['alwaysActivePIDlist'] = $this->parent_cObj->stdWrap(
292 $this->conf['alwaysActivePIDlist'],
293 $this->conf['alwaysActivePIDlist.']
294 );
295 }
296 $this->alwaysActivePIDlist = GeneralUtility::intExplode(',', $this->conf['alwaysActivePIDlist']);
297 }
298 // 'not in menu' doktypes
299 if ($this->conf['excludeDoktypes']) {
300 $this->doktypeExcludeList = implode(',', GeneralUtility::intExplode(',', $this->conf['excludeDoktypes']));
301 }
302 // EntryLevel
303 $this->entryLevel = $this->parent_cObj->getKey(
304 isset($conf['entryLevel.']) ? $this->parent_cObj->stdWrap(
305 $conf['entryLevel'],
306 $conf['entryLevel.']
307 ) : $conf['entryLevel'],
308 $this->tmpl->rootLine
309 );
310 // Set parent page: If $id not stated with start() then the base-id will be found from rootLine[$this->entryLevel]
311 // Called as the next level in a menu. It is assumed that $this->MP_array is set from parent menu.
312 if ($id) {
313 $this->id = (int)$id;
314 } else {
315 // This is a BRAND NEW menu, first level. So we take ID from rootline and also find MP_array (mount points)
316 $this->id = (int)$this->tmpl->rootLine[$this->entryLevel]['uid'];
317 // Traverse rootline to build MP_array of pages BEFORE the entryLevel
318 // (MP var for ->id is picked up in the next part of the code...)
319 foreach ($this->tmpl->rootLine as $entryLevel => $levelRec) {
320 // For overlaid mount points, set the variable right now:
321 if ($levelRec['_MP_PARAM'] && $levelRec['_MOUNT_OL']) {
322 $this->MP_array[] = $levelRec['_MP_PARAM'];
323 }
324 // Break when entry level is reached:
325 if ($entryLevel >= $this->entryLevel) {
326 break;
327 }
328 // For normal mount points, set the variable for next level.
329 if ($levelRec['_MP_PARAM'] && !$levelRec['_MOUNT_OL']) {
330 $this->MP_array[] = $levelRec['_MP_PARAM'];
331 }
332 }
333 }
334 // Return FALSE if no page ID was set (thus no menu of subpages can be made).
335 if ($this->id <= 0) {
336 return false;
337 }
338 // Check if page is a mount point, and if so set id and MP_array
339 // (basically this is ONLY for non-overlay mode, but in overlay mode an ID with a mount point should never reach this point anyways, so no harm done...)
340 $mount_info = $this->sys_page->getMountPointInfo($this->id);
341 if (is_array($mount_info)) {
342 $this->MP_array[] = $mount_info['MPvar'];
343 $this->id = $mount_info['mount_pid'];
344 }
345 // Gather list of page uids in root line (for "isActive" evaluation). Also adds the MP params in the path so Mount Points are respected.
346 // (List is specific for this rootline, so it may be supplied from parent menus for speed...)
347 if ($this->rL_uidRegister === null) {
348 $this->rL_uidRegister = [];
349 $rl_MParray = [];
350 foreach ($this->tmpl->rootLine as $v_rl) {
351 // For overlaid mount points, set the variable right now:
352 if ($v_rl['_MP_PARAM'] && $v_rl['_MOUNT_OL']) {
353 $rl_MParray[] = $v_rl['_MP_PARAM'];
354 }
355 // Add to register:
356 $this->rL_uidRegister[] = 'ITEM:' . $v_rl['uid'] .
357 (!empty($rl_MParray)
358 ? ':' . implode(',', $rl_MParray)
359 : ''
360 );
361 // For normal mount points, set the variable for next level.
362 if ($v_rl['_MP_PARAM'] && !$v_rl['_MOUNT_OL']) {
363 $rl_MParray[] = $v_rl['_MP_PARAM'];
364 }
365 }
366 }
367 // Set $directoryLevel so the following evalution of the nextActive will not return
368 // an invalid value if .special=directory was set
369 $directoryLevel = 0;
370 if ($this->conf['special'] === 'directory') {
371 $value = isset($this->conf['special.']['value.']) ? $this->parent_cObj->stdWrap(
372 $this->conf['special.']['value'],
373 $this->conf['special.']['value.']
374 ) : $this->conf['special.']['value'];
375 if ($value === '') {
376 $value = $tsfe->page['uid'];
377 }
378 $directoryLevel = (int)$tsfe->tmpl->getRootlineLevel($value);
379 }
380 // Setting "nextActive": This is the page uid + MPvar of the NEXT page in rootline. Used to expand the menu if we are in the right branch of the tree
381 // Notice: The automatic expansion of a menu is designed to work only when no "special" modes (except "directory") are used.
382 $startLevel = $directoryLevel ?: $this->entryLevel;
383 $currentLevel = $startLevel + $this->menuNumber;
384 if (is_array($this->tmpl->rootLine[$currentLevel])) {
385 $nextMParray = $this->MP_array;
386 if (empty($nextMParray) && !$this->tmpl->rootLine[$currentLevel]['_MOUNT_OL'] && $currentLevel > 0) {
387 // Make sure to slide-down any mount point information (_MP_PARAM) to children records in the rootline
388 // otherwise automatic expansion will not work
389 $parentRecord = $this->tmpl->rootLine[$currentLevel - 1];
390 if (isset($parentRecord['_MP_PARAM'])) {
391 $nextMParray[] = $parentRecord['_MP_PARAM'];
392 }
393 }
394 // In overlay mode, add next level MPvars as well:
395 if ($this->tmpl->rootLine[$currentLevel]['_MOUNT_OL']) {
396 $nextMParray[] = $this->tmpl->rootLine[$currentLevel]['_MP_PARAM'];
397 }
398 $this->nextActive = $this->tmpl->rootLine[$currentLevel]['uid'] .
399 (!empty($nextMParray)
400 ? ':' . implode(',', $nextMParray)
401 : ''
402 );
403 } else {
404 $this->nextActive = '';
405 }
406 // imgNamePrefix
407 if ($this->mconf['imgNamePrefix']) {
408 $this->imgNamePrefix = $this->mconf['imgNamePrefix'];
409 }
410 $this->imgNameNotRandom = $this->mconf['imgNameNotRandom'];
411 $retVal = true;
412 } else {
413 $this->getTimeTracker()->setTSlogMessage('ERROR in menu', 3);
414 $retVal = false;
415 }
416 return $retVal;
417 }
418
419 /**
420 * Creates the menu in the internal variables, ready for output.
421 * Basically this will read the page records needed and fill in the internal $this->menuArr
422 * Based on a hash of this array and some other variables the $this->result variable will be
423 * loaded either from cache OR by calling the generate() method of the class to create the menu for real.
424 *
425 * @return void
426 */
427 public function makeMenu()
428 {
429 if (!$this->id) {
430 return;
431 }
432
433 $this->useCacheHash = false;
434
435 // Initializing showAccessRestrictedPages
436 $SAVED_where_groupAccess = '';
437 if ($this->mconf['showAccessRestrictedPages']) {
438 // SAVING where_groupAccess
439 $SAVED_where_groupAccess = $this->sys_page->where_groupAccess;
440 // Temporarily removing fe_group checking!
441 $this->sys_page->where_groupAccess = '';
442 }
443
444 $menuItems = $this->prepareMenuItems();
445
446 $c = 0;
447 $c_b = 0;
448 $minItems = (int)($this->mconf['minItems'] ?: $this->conf['minItems']);
449 $maxItems = (int)($this->mconf['maxItems'] ?: $this->conf['maxItems']);
450 $begin = $this->parent_cObj->calc($this->mconf['begin'] ? $this->mconf['begin'] : $this->conf['begin']);
451 $minItemsConf = isset($this->mconf['minItems.']) ? $this->mconf['minItems.'] : (isset($this->conf['minItems.']) ? $this->conf['minItems.'] : null);
452 $minItems = is_array($minItemsConf) ? $this->parent_cObj->stdWrap($minItems, $minItemsConf) : $minItems;
453 $maxItemsConf = isset($this->mconf['maxItems.']) ? $this->mconf['maxItems.'] : (isset($this->conf['maxItems.']) ? $this->conf['maxItems.'] : null);
454 $maxItems = is_array($maxItemsConf) ? $this->parent_cObj->stdWrap($maxItems, $maxItemsConf) : $maxItems;
455 $beginConf = isset($this->mconf['begin.']) ? $this->mconf['begin.'] : (isset($this->conf['begin.']) ? $this->conf['begin.'] : null);
456 $begin = is_array($beginConf) ? $this->parent_cObj->stdWrap($begin, $beginConf) : $begin;
457 $banUidArray = $this->getBannedUids();
458 // Fill in the menuArr with elements that should go into the menu:
459 $this->menuArr = [];
460 foreach ($menuItems as $data) {
461 $spacer = GeneralUtility::inList($this->spacerIDList, $data['doktype']) || $data['ITEM_STATE'] === 'SPC';
462 // if item is a spacer, $spacer is set
463 if ($this->filterMenuPages($data, $banUidArray, $spacer)) {
464 $c_b++;
465 // If the beginning item has been reached.
466 if ($begin <= $c_b) {
467 $this->menuArr[$c] = $data;
468 $this->menuArr[$c]['isSpacer'] = $spacer;
469 $c++;
470 if ($maxItems && $c >= $maxItems) {
471 break;
472 }
473 }
474 }
475 }
476 // Fill in fake items, if min-items is set.
477 if ($minItems) {
478 while ($c < $minItems) {
479 $this->menuArr[$c] = [
480 'title' => '...',
481 'uid' => $this->getTypoScriptFrontendController()->id
482 ];
483 $c++;
484 }
485 }
486 // Passing the menuArr through a user defined function:
487 if ($this->mconf['itemArrayProcFunc']) {
488 $this->menuArr = $this->userProcess('itemArrayProcFunc', $this->menuArr);
489 }
490 // Setting number of menu items
491 $this->getTypoScriptFrontendController()->register['count_menuItems'] = count($this->menuArr);
492 $this->hash = md5(
493 serialize($this->menuArr) .
494 serialize($this->mconf) .
495 serialize($this->tmpl->rootLine) .
496 serialize($this->MP_array)
497 );
498 // Get the cache timeout:
499 if ($this->conf['cache_period']) {
500 $cacheTimeout = $this->conf['cache_period'];
501 } else {
502 $cacheTimeout = $this->getTypoScriptFrontendController()->get_cache_timeout();
503 }
504 $cache = $this->getCache();
505 $cachedData = $cache->get($this->hash);
506 if (!is_array($cachedData)) {
507 $this->generate();
508 $cache->set($this->hash, $this->result, ['ident_MENUDATA'], (int)$cacheTimeout);
509 } else {
510 $this->result = $cachedData;
511 }
512 // End showAccessRestrictedPages
513 if ($this->mconf['showAccessRestrictedPages']) {
514 // RESTORING where_groupAccess
515 $this->sys_page->where_groupAccess = $SAVED_where_groupAccess;
516 }
517 }
518
519 /**
520 * Generates the the menu data.
521 *
522 * Subclasses should overwrite this method.
523 *
524 * @return void
525 */
526 public function generate()
527 {
528 }
529
530 /**
531 * @return string The HTML for the menu
532 */
533 public function writeMenu()
534 {
535 return '';
536 }
537
538 /**
539 * Gets an array of page rows and removes all, which are not accessible
540 *
541 * @param array $pages
542 * @return array
543 */
544 protected function removeInaccessiblePages(array $pages)
545 {
546 $banned = $this->getBannedUids();
547 $filteredPages = [];
548 foreach ($pages as $aPage) {
549 if ($this->filterMenuPages($aPage, $banned, $aPage['doktype'] === PageRepository::DOKTYPE_SPACER)) {
550 $filteredPages[$aPage['uid']] = $aPage;
551 }
552 }
553 return $filteredPages;
554 }
555
556 /**
557 * Main function for retrieving menu items based on the menu type (special or sectionIndex or "normal")
558 *
559 * @return array
560 */
561 protected function prepareMenuItems()
562 {
563 $menuItems = [];
564 $alternativeSortingField = trim($this->mconf['alternativeSortingField']) ?: 'sorting';
565
566 // Additional where clause, usually starts with AND (as usual with all additionalWhere functionality in TS)
567 $additionalWhere = isset($this->mconf['additionalWhere']) ? $this->mconf['additionalWhere'] : '';
568 if (isset($this->mconf['additionalWhere.'])) {
569 $additionalWhere = $this->parent_cObj->stdWrap($additionalWhere, $this->mconf['additionalWhere.']);
570 }
571
572 // ... only for the FIRST level of a HMENU
573 if ($this->menuNumber == 1 && $this->conf['special']) {
574 $value = isset($this->conf['special.']['value.'])
575 ? $this->parent_cObj->stdWrap($this->conf['special.']['value'], $this->conf['special.']['value.'])
576 : $this->conf['special.']['value'];
577 switch ($this->conf['special']) {
578 case 'userfunction':
579 $menuItems = $this->prepareMenuItemsForUserSpecificMenu($value, $alternativeSortingField);
580 break;
581 case 'language':
582 $menuItems = $this->prepareMenuItemsForLanguageMenu($value);
583 break;
584 case 'directory':
585 $menuItems = $this->prepareMenuItemsForDirectoryMenu($value, $alternativeSortingField);
586 break;
587 case 'list':
588 $menuItems = $this->prepareMenuItemsForListMenu($value);
589 break;
590 case 'updated':
591 $menuItems = $this->prepareMenuItemsForUpdatedMenu(
592 $value,
593 $this->mconf['alternativeSortingField'] ?: false
594 );
595 break;
596 case 'keywords':
597 $menuItems = $this->prepareMenuItemsForKeywordsMenu(
598 $value,
599 $this->mconf['alternativeSortingField'] ?: false
600 );
601 break;
602 case 'categories':
603 /** @var CategoryMenuUtility $categoryMenuUtility */
604 $categoryMenuUtility = GeneralUtility::makeInstance(CategoryMenuUtility::class);
605 $menuItems = $categoryMenuUtility->collectPages($value, $this->conf['special.'], $this);
606 break;
607 case 'rootline':
608 $menuItems = $this->prepareMenuItemsForRootlineMenu();
609 break;
610 case 'browse':
611 $menuItems = $this->prepareMenuItemsForBrowseMenu($value, $alternativeSortingField, $additionalWhere);
612 break;
613 }
614 if ($this->mconf['sectionIndex']) {
615 $sectionIndexes = [];
616 foreach ($menuItems as $page) {
617 $sectionIndexes = $sectionIndexes + $this->sectionIndex($alternativeSortingField, $page['uid']);
618 }
619 $menuItems = $sectionIndexes;
620 }
621 } elseif (is_array($this->alternativeMenuTempArray)) {
622 // Setting $menuItems array if not level 1.
623 $menuItems = $this->alternativeMenuTempArray;
624 } elseif ($this->mconf['sectionIndex']) {
625 $menuItems = $this->sectionIndex($alternativeSortingField);
626 } else {
627 // Default: Gets a hierarchical menu based on subpages of $this->id
628 $menuItems = $this->sys_page->getMenu($this->id, '*', $alternativeSortingField, $additionalWhere);
629 }
630 return $menuItems;
631 }
632
633 /**
634 * Fetches all menuitems if special = userfunction is set
635 *
636 * @param string $specialValue The value from special.value
637 * @param string $sortingField The sorting field
638 * @return array
639 */
640 protected function prepareMenuItemsForUserSpecificMenu($specialValue, $sortingField)
641 {
642 $menuItems = $this->parent_cObj->callUserFunction(
643 $this->conf['special.']['userFunc'],
644 array_merge($this->conf['special.'], ['value' => $specialValue, '_altSortField' => $sortingField]),
645 ''
646 );
647 if (!is_array($menuItems)) {
648 $menuItems = [];
649 }
650 return $menuItems;
651 }
652
653 /**
654 * Fetches all menuitems if special = language is set
655 *
656 * @param string $specialValue The value from special.value
657 * @return array
658 */
659 protected function prepareMenuItemsForLanguageMenu($specialValue)
660 {
661 $menuItems = [];
662 // Getting current page record NOT overlaid by any translation:
663 $tsfe = $this->getTypoScriptFrontendController();
664 $currentPageWithNoOverlay = $this->sys_page->getRawRecord('pages', $tsfe->page['uid']);
665 // Traverse languages set up:
666 $languageItems = GeneralUtility::intExplode(',', $specialValue);
667 foreach ($languageItems as $sUid) {
668 // Find overlay record:
669 if ($sUid) {
670 $lRecs = $this->sys_page->getPageOverlay($tsfe->page['uid'], $sUid);
671 } else {
672 $lRecs = [];
673 }
674 // Checking if the "disabled" state should be set.
675 if (GeneralUtility::hideIfNotTranslated($tsfe->page['l18n_cfg']) && $sUid &&
676 empty($lRecs) || GeneralUtility::hideIfDefaultLanguage($tsfe->page['l18n_cfg']) &&
677 (!$sUid || empty($lRecs)) ||
678 !$this->conf['special.']['normalWhenNoLanguage'] && $sUid && empty($lRecs)
679 ) {
680 $iState = $tsfe->sys_language_uid == $sUid ? 'USERDEF2' : 'USERDEF1';
681 } else {
682 $iState = $tsfe->sys_language_uid == $sUid ? 'ACT' : 'NO';
683 }
684 if ($this->conf['addQueryString']) {
685 $getVars = $this->parent_cObj->getQueryArguments(
686 $this->conf['addQueryString.'],
687 ['L' => $sUid],
688 true
689 );
690 $this->analyzeCacheHashRequirements($getVars);
691 } else {
692 $getVars = '&L=' . $sUid;
693 }
694 // Adding menu item:
695 $menuItems[] = array_merge(
696 array_merge($currentPageWithNoOverlay, $lRecs),
697 [
698 'ITEM_STATE' => $iState,
699 '_ADD_GETVARS' => $getVars,
700 '_SAFE' => true
701 ]
702 );
703 }
704 return $menuItems;
705 }
706
707 /**
708 * Fetches all menuitems if special = directory is set
709 *
710 * @param string $specialValue The value from special.value
711 * @param string $sortingField The sorting field
712 * @return array
713 */
714 protected function prepareMenuItemsForDirectoryMenu($specialValue, $sortingField)
715 {
716 $tsfe = $this->getTypoScriptFrontendController();
717 $menuItems = [];
718 if ($specialValue == '') {
719 $specialValue = $tsfe->page['uid'];
720 }
721 $items = GeneralUtility::intExplode(',', $specialValue);
722 foreach ($items as $id) {
723 $MP = $this->tmpl->getFromMPmap($id);
724 // Checking if a page is a mount page and if so, change the ID and set the MP var properly.
725 $mount_info = $this->sys_page->getMountPointInfo($id);
726 if (is_array($mount_info)) {
727 if ($mount_info['overlay']) {
728 // Overlays should already have their full MPvars calculated:
729 $MP = $this->tmpl->getFromMPmap($mount_info['mount_pid']);
730 $MP = $MP ? $MP : $mount_info['MPvar'];
731 } else {
732 $MP = ($MP ? $MP . ',' : '') . $mount_info['MPvar'];
733 }
734 $id = $mount_info['mount_pid'];
735 }
736 // Get sub-pages:
737 $statement = $this->parent_cObj->exec_getQuery('pages', ['pidInList' => $id, 'orderBy' => $sortingField]);
738 while ($row = $statement->fetch()) {
739 $tsfe->sys_page->versionOL('pages', $row, true);
740 if (!empty($row)) {
741 // Keep mount point?
742 $mount_info = $this->sys_page->getMountPointInfo($row['uid'], $row);
743 // There is a valid mount point.
744 if (is_array($mount_info) && $mount_info['overlay']) {
745 // Using "getPage" is OK since we need the check for enableFields
746 // AND for type 2 of mount pids we DO require a doktype < 200!
747 $mp_row = $this->sys_page->getPage($mount_info['mount_pid']);
748 if (!empty($mp_row)) {
749 $row = $mp_row;
750 $row['_MP_PARAM'] = $mount_info['MPvar'];
751 } else {
752 // If the mount point could not be fetched with respect
753 // to enableFields, unset the row so it does not become a part of the menu!
754 unset($row);
755 }
756 }
757 // Add external MP params, then the row:
758 if (!empty($row)) {
759 if ($MP) {
760 $row['_MP_PARAM'] = $MP . ($row['_MP_PARAM'] ? ',' . $row['_MP_PARAM'] : '');
761 }
762 $menuItems[$row['uid']] = $this->sys_page->getPageOverlay($row);
763 }
764 }
765 }
766 }
767
768 return $menuItems;
769 }
770
771 /**
772 * Fetches all menuitems if special = list is set
773 *
774 * @param string $specialValue The value from special.value
775 * @return array
776 */
777 protected function prepareMenuItemsForListMenu($specialValue)
778 {
779 $menuItems = [];
780 if ($specialValue == '') {
781 $specialValue = $this->id;
782 }
783 $skippedEnableFields = [];
784 if (!empty($this->mconf['showAccessRestrictedPages'])) {
785 $skippedEnableFields = ['fe_group' => 1];
786 }
787 /** @var RelationHandler $loadDB*/
788 $loadDB = GeneralUtility::makeInstance(RelationHandler::class);
789 $loadDB->setFetchAllFields(true);
790 $loadDB->start($specialValue, 'pages');
791 $loadDB->additionalWhere['pages'] = $this->parent_cObj->enableFields('pages', false, $skippedEnableFields);
792 $loadDB->getFromDB();
793 foreach ($loadDB->itemArray as $val) {
794 $MP = $this->tmpl->getFromMPmap($val['id']);
795 // Keep mount point?
796 $mount_info = $this->sys_page->getMountPointInfo($val['id']);
797 // There is a valid mount point.
798 if (is_array($mount_info) && $mount_info['overlay']) {
799 // Using "getPage" is OK since we need the check for enableFields
800 // AND for type 2 of mount pids we DO require a doktype < 200!
801 $mp_row = $this->sys_page->getPage($mount_info['mount_pid']);
802 if (!empty($mp_row)) {
803 $row = $mp_row;
804 $row['_MP_PARAM'] = $mount_info['MPvar'];
805 // Overlays should already have their full MPvars calculated
806 if ($mount_info['overlay']) {
807 $MP = $this->tmpl->getFromMPmap($mount_info['mount_pid']);
808 if ($MP) {
809 unset($row['_MP_PARAM']);
810 }
811 }
812 } else {
813 // If the mount point could not be fetched with respect to
814 // enableFields, unset the row so it does not become a part of the menu!
815 unset($row);
816 }
817 } else {
818 $row = $loadDB->results['pages'][$val['id']];
819 }
820 // Add versioning overlay for current page (to respect workspaces)
821 if (isset($row) && is_array($row)) {
822 $this->sys_page->versionOL('pages', $row, true);
823 }
824 // Add external MP params, then the row:
825 if (isset($row) && is_array($row)) {
826 if ($MP) {
827 $row['_MP_PARAM'] = $MP . ($row['_MP_PARAM'] ? ',' . $row['_MP_PARAM'] : '');
828 }
829 $menuItems[] = $this->sys_page->getPageOverlay($row);
830 }
831 }
832 return $menuItems;
833 }
834
835 /**
836 * Fetches all menuitems if special = updated is set
837 *
838 * @param string $specialValue The value from special.value
839 * @param string $sortingField The sorting field
840 * @return array
841 */
842 protected function prepareMenuItemsForUpdatedMenu($specialValue, $sortingField)
843 {
844 $tsfe = $this->getTypoScriptFrontendController();
845 $menuItems = [];
846 if ($specialValue == '') {
847 $specialValue = $tsfe->page['uid'];
848 }
849 $items = GeneralUtility::intExplode(',', $specialValue);
850 if (MathUtility::canBeInterpretedAsInteger($this->conf['special.']['depth'])) {
851 $depth = MathUtility::forceIntegerInRange($this->conf['special.']['depth'], 1, 20);
852 } else {
853 $depth = 20;
854 }
855 // Max number of items
856 $limit = MathUtility::forceIntegerInRange($this->conf['special.']['limit'], 0, 100);
857 $maxAge = (int)$this->parent_cObj->calc($this->conf['special.']['maxAge']);
858 if (!$limit) {
859 $limit = 10;
860 }
861 // *'auto', 'manual', 'tstamp'
862 $mode = $this->conf['special.']['mode'];
863 // Get id's
864 $id_list_arr = [];
865 foreach ($items as $id) {
866 $bA = MathUtility::forceIntegerInRange($this->conf['special.']['beginAtLevel'], 0, 100);
867 $id_list_arr[] = $this->parent_cObj->getTreeList(-1 * $id, $depth - 1 + $bA, $bA - 1);
868 }
869 $id_list = implode(',', $id_list_arr);
870 // Get sortField (mode)
871 switch ($mode) {
872 case 'starttime':
873 $sortField = 'starttime';
874 break;
875 case 'lastUpdated':
876 case 'manual':
877 $sortField = 'lastUpdated';
878 break;
879 case 'tstamp':
880 $sortField = 'tstamp';
881 break;
882 case 'crdate':
883 $sortField = 'crdate';
884 break;
885 default:
886 $sortField = 'SYS_LASTCHANGED';
887 }
888 $extraWhere = ($this->conf['includeNotInMenu'] ? '' : ' AND pages.nav_hide=0') . $this->getDoktypeExcludeWhere();
889 if ($this->conf['special.']['excludeNoSearchPages']) {
890 $extraWhere .= ' AND pages.no_search=0';
891 }
892 if ($maxAge > 0) {
893 $extraWhere .= ' AND ' . $sortField . '>' . ($GLOBALS['SIM_ACCESS_TIME'] - $maxAge);
894 }
895 $statement = $this->parent_cObj->exec_getQuery('pages', [
896 'pidInList' => '0',
897 'uidInList' => $id_list,
898 'where' => $sortField . '>=0' . $extraWhere,
899 'orderBy' => $sortingField ?: $sortField . ' DESC',
900 'max' => $limit
901 ]);
902 while ($row = $statement->fetch()) {
903 $tsfe->sys_page->versionOL('pages', $row, true);
904 if (is_array($row)) {
905 $menuItems[$row['uid']] = $this->sys_page->getPageOverlay($row);
906 }
907 }
908
909 return $menuItems;
910 }
911
912 /**
913 * Fetches all menuitems if special = keywords is set
914 *
915 * @param string $specialValue The value from special.value
916 * @param string $sortingField The sorting field
917 * @return array
918 */
919 protected function prepareMenuItemsForKeywordsMenu($specialValue, $sortingField)
920 {
921 $tsfe = $this->getTypoScriptFrontendController();
922 $menuItems = [];
923 list($specialValue) = GeneralUtility::intExplode(',', $specialValue);
924 if (!$specialValue) {
925 $specialValue = $tsfe->page['uid'];
926 }
927 if ($this->conf['special.']['setKeywords'] || $this->conf['special.']['setKeywords.']) {
928 $kw = isset($this->conf['special.']['setKeywords.']) ? $this->parent_cObj->stdWrap($this->conf['special.']['setKeywords'], $this->conf['special.']['setKeywords.']) : $this->conf['special.']['setKeywords'];
929 } else {
930 // The page record of the 'value'.
931 $value_rec = $this->sys_page->getPage($specialValue);
932 $kfieldSrc = $this->conf['special.']['keywordsField.']['sourceField'] ? $this->conf['special.']['keywordsField.']['sourceField'] : 'keywords';
933 // keywords.
934 $kw = trim($this->parent_cObj->keywords($value_rec[$kfieldSrc]));
935 }
936 // *'auto', 'manual', 'tstamp'
937 $mode = $this->conf['special.']['mode'];
938 switch ($mode) {
939 case 'starttime':
940 $sortField = 'starttime';
941 break;
942 case 'lastUpdated':
943 case 'manual':
944 $sortField = 'lastUpdated';
945 break;
946 case 'tstamp':
947 $sortField = 'tstamp';
948 break;
949 case 'crdate':
950 $sortField = 'crdate';
951 break;
952 default:
953 $sortField = 'SYS_LASTCHANGED';
954 }
955 // Depth, limit, extra where
956 if (MathUtility::canBeInterpretedAsInteger($this->conf['special.']['depth'])) {
957 $depth = MathUtility::forceIntegerInRange($this->conf['special.']['depth'], 0, 20);
958 } else {
959 $depth = 20;
960 }
961 // Max number of items
962 $limit = MathUtility::forceIntegerInRange($this->conf['special.']['limit'], 0, 100);
963 $extraWhere = ' AND pages.uid<>' . $specialValue . ($this->conf['includeNotInMenu'] ? '' : ' AND pages.nav_hide=0') . $this->getDoktypeExcludeWhere();
964 if ($this->conf['special.']['excludeNoSearchPages']) {
965 $extraWhere .= ' AND pages.no_search=0';
966 }
967 // Start point
968 $eLevel = $this->parent_cObj->getKey(isset($this->conf['special.']['entryLevel.'])
969 ? $this->parent_cObj->stdWrap($this->conf['special.']['entryLevel'], $this->conf['special.']['entryLevel.'])
970 : $this->conf['special.']['entryLevel'], $this->tmpl->rootLine
971 );
972 $startUid = (int)$this->tmpl->rootLine[$eLevel]['uid'];
973 // Which field is for keywords
974 $kfield = 'keywords';
975 if ($this->conf['special.']['keywordsField']) {
976 list($kfield) = explode(' ', trim($this->conf['special.']['keywordsField']));
977 }
978 // If there are keywords and the startuid is present
979 if ($kw && $startUid) {
980 $bA = MathUtility::forceIntegerInRange($this->conf['special.']['beginAtLevel'], 0, 100);
981 $id_list = $this->parent_cObj->getTreeList(-1 * $startUid, $depth - 1 + $bA, $bA - 1);
982 $kwArr = GeneralUtility::trimExplode(',', $kw, true);
983 $keyWordsWhereArr = [];
984 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
985 foreach ($kwArr as $word) {
986 $keyWordsWhereArr[] = $queryBuilder->expr()->like(
987 $kfield,
988 $queryBuilder->createNamedParameter(
989 '%' . $queryBuilder->escapeLikeWildcards($word) . '%',
990 \PDO::PARAM_STR
991 )
992 );
993 }
994 $where = empty($keyWordsWhereArr) ? '' : '(' . implode(' OR ', $keyWordsWhereArr) . ')';
995 $statement = $this->parent_cObj->exec_getQuery('pages', [
996 'pidInList' => '0',
997 'uidInList' => $id_list,
998 'where' => $where . $extraWhere,
999 'orderBy' => $sortingField ?: $sortField . ' desc',
1000 'max' => $limit
1001 ]);
1002 while ($row = $statement->fetch()) {
1003 $tsfe->sys_page->versionOL('pages', $row, true);
1004 if (is_array($row)) {
1005 $menuItems[$row['uid']] = $this->sys_page->getPageOverlay($row);
1006 }
1007 }
1008 }
1009
1010 return $menuItems;
1011 }
1012
1013 /**
1014 * Fetches all menuitems if special = rootline is set
1015 *
1016 * @return array
1017 */
1018 protected function prepareMenuItemsForRootlineMenu()
1019 {
1020 $menuItems = [];
1021 $range = isset($this->conf['special.']['range.'])
1022 ? $this->parent_cObj->stdWrap($this->conf['special.']['range'], $this->conf['special.']['range.'])
1023 : $this->conf['special.']['range'];
1024 $begin_end = explode('|', $range);
1025 $begin_end[0] = (int)$begin_end[0];
1026 if (!MathUtility::canBeInterpretedAsInteger($begin_end[1])) {
1027 $begin_end[1] = -1;
1028 }
1029 $beginKey = $this->parent_cObj->getKey($begin_end[0], $this->tmpl->rootLine);
1030 $endKey = $this->parent_cObj->getKey($begin_end[1], $this->tmpl->rootLine);
1031 if ($endKey < $beginKey) {
1032 $endKey = $beginKey;
1033 }
1034 $rl_MParray = [];
1035 foreach ($this->tmpl->rootLine as $k_rl => $v_rl) {
1036 // For overlaid mount points, set the variable right now:
1037 if ($v_rl['_MP_PARAM'] && $v_rl['_MOUNT_OL']) {
1038 $rl_MParray[] = $v_rl['_MP_PARAM'];
1039 }
1040 // Traverse rootline:
1041 if ($k_rl >= $beginKey && $k_rl <= $endKey) {
1042 $temp_key = $k_rl;
1043 $menuItems[$temp_key] = $this->sys_page->getPage($v_rl['uid']);
1044 if (!empty($menuItems[$temp_key])) {
1045 // If there are no specific target for the page, put the level specific target on.
1046 if (!$menuItems[$temp_key]['target']) {
1047 $menuItems[$temp_key]['target'] = $this->conf['special.']['targets.'][$k_rl];
1048 $menuItems[$temp_key]['_MP_PARAM'] = implode(',', $rl_MParray);
1049 }
1050 } else {
1051 unset($menuItems[$temp_key]);
1052 }
1053 }
1054 // For normal mount points, set the variable for next level.
1055 if ($v_rl['_MP_PARAM'] && !$v_rl['_MOUNT_OL']) {
1056 $rl_MParray[] = $v_rl['_MP_PARAM'];
1057 }
1058 }
1059 // Reverse order of elements (e.g. "1,2,3,4" gets "4,3,2,1"):
1060 if (isset($this->conf['special.']['reverseOrder']) && $this->conf['special.']['reverseOrder']) {
1061 $menuItems = array_reverse($menuItems);
1062 }
1063 return $menuItems;
1064 }
1065
1066 /**
1067 * Fetches all menuitems if special = browse is set
1068 *
1069 * @param string $specialValue The value from special.value
1070 * @param string $sortingField The sorting field
1071 * @param string $additionalWhere Additional WHERE clause
1072 * @return array
1073 */
1074 protected function prepareMenuItemsForBrowseMenu($specialValue, $sortingField, $additionalWhere)
1075 {
1076 $menuItems = [];
1077 list($specialValue) = GeneralUtility::intExplode(',', $specialValue);
1078 if (!$specialValue) {
1079 $specialValue = $this->getTypoScriptFrontendController()->page['uid'];
1080 }
1081 // Will not work out of rootline
1082 if ($specialValue != $this->tmpl->rootLine[0]['uid']) {
1083 $recArr = [];
1084 // The page record of the 'value'.
1085 $value_rec = $this->sys_page->getPage($specialValue);
1086 // 'up' page cannot be outside rootline
1087 if ($value_rec['pid']) {
1088 // The page record of 'up'.
1089 $recArr['up'] = $this->sys_page->getPage($value_rec['pid']);
1090 }
1091 // If the 'up' item was NOT level 0 in rootline...
1092 if ($recArr['up']['pid'] && $value_rec['pid'] != $this->tmpl->rootLine[0]['uid']) {
1093 // The page record of "index".
1094 $recArr['index'] = $this->sys_page->getPage($recArr['up']['pid']);
1095 }
1096 // check if certain pages should be excluded
1097 $additionalWhere .= ($this->conf['includeNotInMenu'] ? '' : ' AND pages.nav_hide=0') . $this->getDoktypeExcludeWhere();
1098 if ($this->conf['special.']['excludeNoSearchPages']) {
1099 $additionalWhere .= ' AND pages.no_search=0';
1100 }
1101 // prev / next is found
1102 $prevnext_menu = $this->removeInaccessiblePages($this->sys_page->getMenu($value_rec['pid'], '*', $sortingField, $additionalWhere));
1103 $lastKey = 0;
1104 $nextActive = 0;
1105 foreach ($prevnext_menu as $k_b => $v_b) {
1106 if ($nextActive) {
1107 $recArr['next'] = $v_b;
1108 $nextActive = 0;
1109 }
1110 if ($v_b['uid'] == $specialValue) {
1111 if ($lastKey) {
1112 $recArr['prev'] = $prevnext_menu[$lastKey];
1113 }
1114 $nextActive = 1;
1115 }
1116 $lastKey = $k_b;
1117 }
1118
1119 $recArr['first'] = reset($prevnext_menu);
1120 $recArr['last'] = end($prevnext_menu);
1121 // prevsection / nextsection is found
1122 // You can only do this, if there is a valid page two levels up!
1123 if (!empty($recArr['index']['uid'])) {
1124 $prevnextsection_menu = $this->removeInaccessiblePages($this->sys_page->getMenu($recArr['index']['uid'], '*', $sortingField, $additionalWhere));
1125 $lastKey = 0;
1126 $nextActive = 0;
1127 foreach ($prevnextsection_menu as $k_b => $v_b) {
1128 if ($nextActive) {
1129 $sectionRec_temp = $this->removeInaccessiblePages($this->sys_page->getMenu($v_b['uid'], '*', $sortingField, $additionalWhere));
1130 if (!empty($sectionRec_temp)) {
1131 $recArr['nextsection'] = reset($sectionRec_temp);
1132 $recArr['nextsection_last'] = end($sectionRec_temp);
1133 $nextActive = 0;
1134 }
1135 }
1136 if ($v_b['uid'] == $value_rec['pid']) {
1137 if ($lastKey) {
1138 $sectionRec_temp = $this->removeInaccessiblePages($this->sys_page->getMenu($prevnextsection_menu[$lastKey]['uid'], '*', $sortingField, $additionalWhere));
1139 if (!empty($sectionRec_temp)) {
1140 $recArr['prevsection'] = reset($sectionRec_temp);
1141 $recArr['prevsection_last'] = end($sectionRec_temp);
1142 }
1143 }
1144 $nextActive = 1;
1145 }
1146 $lastKey = $k_b;
1147 }
1148 }
1149 if ($this->conf['special.']['items.']['prevnextToSection']) {
1150 if (!is_array($recArr['prev']) && is_array($recArr['prevsection_last'])) {
1151 $recArr['prev'] = $recArr['prevsection_last'];
1152 }
1153 if (!is_array($recArr['next']) && is_array($recArr['nextsection'])) {
1154 $recArr['next'] = $recArr['nextsection'];
1155 }
1156 }
1157 $items = explode('|', $this->conf['special.']['items']);
1158 $c = 0;
1159 foreach ($items as $k_b => $v_b) {
1160 $v_b = strtolower(trim($v_b));
1161 if ((int)$this->conf['special.'][$v_b . '.']['uid']) {
1162 $recArr[$v_b] = $this->sys_page->getPage((int)$this->conf['special.'][$v_b . '.']['uid']);
1163 }
1164 if (is_array($recArr[$v_b])) {
1165 $menuItems[$c] = $recArr[$v_b];
1166 if ($this->conf['special.'][$v_b . '.']['target']) {
1167 $menuItems[$c]['target'] = $this->conf['special.'][$v_b . '.']['target'];
1168 }
1169 $tmpSpecialFields = $this->conf['special.'][$v_b . '.']['fields.'];
1170 if (is_array($tmpSpecialFields)) {
1171 foreach ($tmpSpecialFields as $fk => $val) {
1172 $menuItems[$c][$fk] = $val;
1173 }
1174 }
1175 $c++;
1176 }
1177 }
1178 }
1179 return $menuItems;
1180 }
1181
1182 /**
1183 * Analyzes the parameters to find if the link needs a cHash parameter.
1184 *
1185 * @param string $queryString
1186 * @return void
1187 */
1188 protected function analyzeCacheHashRequirements($queryString)
1189 {
1190 $parameters = GeneralUtility::explodeUrl2Array($queryString);
1191 if (!empty($parameters)) {
1192 if (!isset($parameters['id'])) {
1193 $queryString .= '&id=' . $this->getTypoScriptFrontendController()->id;
1194 }
1195 /** @var CacheHashCalculator $cacheHashCalculator */
1196 $cacheHashCalculator = GeneralUtility::makeInstance(CacheHashCalculator::class);
1197 $cHashParameters = $cacheHashCalculator->getRelevantParameters($queryString);
1198 if (count($cHashParameters) > 1) {
1199 $this->useCacheHash = (
1200 $GLOBALS['TYPO3_CONF_VARS']['FE']['disableNoCacheParameter'] ||
1201 !isset($parameters['no_cache']) ||
1202 !$parameters['no_cache']
1203 );
1204 }
1205 }
1206 }
1207
1208 /**
1209 * Checks if a page is OK to include in the final menu item array. Pages can be excluded if the doktype is wrong,
1210 * if they are hidden in navigation, have a uid in the list of banned uids etc.
1211 *
1212 * @param array $data Array of menu items
1213 * @param array $banUidArray Array of page uids which are to be excluded
1214 * @param bool $spacer If set, then the page is a spacer.
1215 * @return bool Returns TRUE if the page can be safely included.
1216 *
1217 * @throws \UnexpectedValueException
1218 */
1219 public function filterMenuPages(&$data, $banUidArray, $spacer)
1220 {
1221 $includePage = true;
1222 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/tslib/class.tslib_menu.php']['filterMenuPages'])) {
1223 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/tslib/class.tslib_menu.php']['filterMenuPages'] as $classRef) {
1224 $hookObject = GeneralUtility::getUserObj($classRef);
1225 if (!$hookObject instanceof AbstractMenuFilterPagesHookInterface) {
1226 throw new \UnexpectedValueException($classRef . ' must implement interface ' . AbstractMenuFilterPagesHookInterface::class, 1269877402);
1227 }
1228 $includePage = $includePage && $hookObject->processFilter($data, $banUidArray, $spacer, $this);
1229 }
1230 }
1231 if (!$includePage) {
1232 return false;
1233 }
1234 if ($data['_SAFE']) {
1235 return true;
1236 }
1237
1238 if (
1239 ($this->mconf['SPC'] || !$spacer) // If the spacer-function is not enabled, spacers will not enter the $menuArr
1240 && (!$data['nav_hide'] || $this->conf['includeNotInMenu']) // Not hidden in navigation
1241 && !GeneralUtility::inList($this->doktypeExcludeList, $data['doktype']) // Page may not be 'not_in_menu' or 'Backend User Section'
1242 && !ArrayUtility::inArray($banUidArray, $data['uid']) // not in banned uid's
1243 ) {
1244 // Checks if the default language version can be shown:
1245 // Block page is set, if l18n_cfg allows plus: 1) Either default language or 2) another language but NO overlay record set for page!
1246 $tsfe = $this->getTypoScriptFrontendController();
1247 $blockPage = GeneralUtility::hideIfDefaultLanguage($data['l18n_cfg']) && (!$tsfe->sys_language_uid || $tsfe->sys_language_uid && !$data['_PAGES_OVERLAY']);
1248 if (!$blockPage) {
1249 // Checking if a page should be shown in the menu depending on whether a translation exists:
1250 $tok = true;
1251 // There is an alternative language active AND the current page requires a translation:
1252 if ($tsfe->sys_language_uid && GeneralUtility::hideIfNotTranslated($data['l18n_cfg'])) {
1253 if (!$data['_PAGES_OVERLAY']) {
1254 $tok = false;
1255 }
1256 }
1257 // Continue if token is TRUE:
1258 if ($tok) {
1259 // Checking if "&L" should be modified so links to non-accessible pages will not happen.
1260 if ($this->conf['protectLvar']) {
1261 $languageUid = (int)$tsfe->config['config']['sys_language_uid'];
1262 if ($languageUid && ($this->conf['protectLvar'] == 'all' || GeneralUtility::hideIfNotTranslated($data['l18n_cfg']))) {
1263 $olRec = $tsfe->sys_page->getPageOverlay($data['uid'], $languageUid);
1264 if (empty($olRec)) {
1265 // If no pages_language_overlay record then page can NOT be accessed in
1266 // the language pointed to by "&L" and therefore we protect the link by setting "&L=0"
1267 $data['_ADD_GETVARS'] .= '&L=0';
1268 }
1269 }
1270 }
1271 return true;
1272 }
1273 }
1274 }
1275 return false;
1276 }
1277
1278 /**
1279 * Generating the per-menu-item configuration arrays based on the settings for item states (NO, RO, ACT, CUR etc)
1280 * set in ->mconf (config for the current menu object)
1281 * Basically it will produce an individual array for each menu item based on the item states.
1282 * BUT in addition the "optionSplit" syntax for the values is ALSO evaluated here so that all property-values
1283 * are "option-splitted" and the output will thus be resolved.
1284 * Is called from the "generate" functions in the extension classes. The function is processor intensive due to
1285 * the option split feature in particular. But since the generate function is not always called
1286 * (since the ->result array may be cached, see makeMenu) it doesn't hurt so badly.
1287 *
1288 * @param int $splitCount Number of menu items in the menu
1289 * @return array An array with two keys: array($NOconf,$ROconf) - where $NOconf contains the resolved configuration for each item when NOT rolled-over and $ROconf contains the ditto for the mouseover state (if any)
1290 *
1291 * @internal
1292 */
1293 public function procesItemStates($splitCount)
1294 {
1295 // Prepare normal settings
1296 if (!is_array($this->mconf['NO.']) && $this->mconf['NO']) {
1297 // Setting a blank array if NO=1 and there are no properties.
1298 $this->mconf['NO.'] = [];
1299 }
1300 $NOconf = $this->tmpl->splitConfArray($this->mconf['NO.'], $splitCount);
1301 // Prepare rollOver settings, overriding normal settings
1302 $ROconf = [];
1303 if ($this->mconf['RO']) {
1304 $ROconf = $this->tmpl->splitConfArray($this->mconf['RO.'], $splitCount);
1305 }
1306 // Prepare IFSUB settings, overriding normal settings
1307 // IFSUB is TRUE if there exist submenu items to the current item
1308 if (!empty($this->mconf['IFSUB'])) {
1309 $IFSUBconf = null;
1310 $IFSUBROconf = null;
1311 foreach ($NOconf as $key => $val) {
1312 if ($this->isItemState('IFSUB', $key)) {
1313 // if this is the first IFSUB element, we must generate IFSUB.
1314 if ($IFSUBconf === null) {
1315 $IFSUBconf = $this->tmpl->splitConfArray($this->mconf['IFSUB.'], $splitCount);
1316 if (!empty($this->mconf['IFSUBRO'])) {
1317 $IFSUBROconf = $this->tmpl->splitConfArray($this->mconf['IFSUBRO.'], $splitCount);
1318 }
1319 }
1320 // Substitute normal with ifsub
1321 if (isset($IFSUBconf[$key])) {
1322 $NOconf[$key] = $IFSUBconf[$key];
1323 }
1324 // If rollOver on normal, we must apply a state for rollOver on the active
1325 if ($ROconf) {
1326 // If RollOver on active then apply this
1327 $ROconf[$key] = !empty($IFSUBROconf[$key]) ? $IFSUBROconf[$key] : $IFSUBconf[$key];
1328 }
1329 }
1330 }
1331 }
1332 // Prepare active settings, overriding normal settings
1333 if (!empty($this->mconf['ACT'])) {
1334 $ACTconf = null;
1335 $ACTROconf = null;
1336 // Find active
1337 foreach ($NOconf as $key => $val) {
1338 if ($this->isItemState('ACT', $key)) {
1339 // If this is the first 'active', we must generate ACT.
1340 if ($ACTconf === null) {
1341 $ACTconf = $this->tmpl->splitConfArray($this->mconf['ACT.'], $splitCount);
1342 // Prepare active rollOver settings, overriding normal active settings
1343 if (!empty($this->mconf['ACTRO'])) {
1344 $ACTROconf = $this->tmpl->splitConfArray($this->mconf['ACTRO.'], $splitCount);
1345 }
1346 }
1347 // Substitute normal with active
1348 if (isset($ACTconf[$key])) {
1349 $NOconf[$key] = $ACTconf[$key];
1350 }
1351 // If rollOver on normal, we must apply a state for rollOver on the active
1352 if ($ROconf) {
1353 // If RollOver on active then apply this
1354 $ROconf[$key] = !empty($ACTROconf[$key]) ? $ACTROconf[$key] : $ACTconf[$key];
1355 }
1356 }
1357 }
1358 }
1359 // Prepare ACT (active)/IFSUB settings, overriding normal settings
1360 // ACTIFSUB is TRUE if there exist submenu items to the current item and the current item is active
1361 if (!empty($this->mconf['ACTIFSUB'])) {
1362 $ACTIFSUBconf = null;
1363 $ACTIFSUBROconf = null;
1364 // Find active
1365 foreach ($NOconf as $key => $val) {
1366 if ($this->isItemState('ACTIFSUB', $key)) {
1367 // If this is the first 'active', we must generate ACTIFSUB.
1368 if ($ACTIFSUBconf === null) {
1369 $ACTIFSUBconf = $this->tmpl->splitConfArray($this->mconf['ACTIFSUB.'], $splitCount);
1370 // Prepare active rollOver settings, overriding normal active settings
1371 if (!empty($this->mconf['ACTIFSUBRO'])) {
1372 $ACTIFSUBROconf = $this->tmpl->splitConfArray($this->mconf['ACTIFSUBRO.'], $splitCount);
1373 }
1374 }
1375 // Substitute normal with active
1376 if (isset($ACTIFSUBconf[$key])) {
1377 $NOconf[$key] = $ACTIFSUBconf[$key];
1378 }
1379 // If rollOver on normal, we must apply a state for rollOver on the active
1380 if ($ROconf) {
1381 // If RollOver on active then apply this
1382 $ROconf[$key] = !empty($ACTIFSUBROconf[$key]) ? $ACTIFSUBROconf[$key] : $ACTIFSUBconf[$key];
1383 }
1384 }
1385 }
1386 }
1387 // Prepare CUR (current) settings, overriding normal settings
1388 // CUR is TRUE if the current page equals the item here!
1389 if (!empty($this->mconf['CUR'])) {
1390 $CURconf = null;
1391 $CURROconf = null;
1392 foreach ($NOconf as $key => $val) {
1393 if ($this->isItemState('CUR', $key)) {
1394 // if this is the first 'current', we must generate CUR. Basically this control is just inherited
1395 // from the other implementations as current would only exist one time and that's it
1396 // (unless you use special-features of HMENU)
1397 if ($CURconf === null) {
1398 $CURconf = $this->tmpl->splitConfArray($this->mconf['CUR.'], $splitCount);
1399 if (!empty($this->mconf['CURRO'])) {
1400 $CURROconf = $this->tmpl->splitConfArray($this->mconf['CURRO.'], $splitCount);
1401 }
1402 }
1403 // Substitute normal with current
1404 if (isset($CURconf[$key])) {
1405 $NOconf[$key] = $CURconf[$key];
1406 }
1407 // If rollOver on normal, we must apply a state for rollOver on the active
1408 if ($ROconf) {
1409 // If RollOver on active then apply this
1410 $ROconf[$key] = !empty($CURROconf[$key]) ? $CURROconf[$key] : $CURconf[$key];
1411 }
1412 }
1413 }
1414 }
1415 // Prepare CUR (current)/IFSUB settings, overriding normal settings
1416 // CURIFSUB is TRUE if there exist submenu items to the current item and the current page equals the item here!
1417 if (!empty($this->mconf['CURIFSUB'])) {
1418 $CURIFSUBconf = null;
1419 $CURIFSUBROconf = null;
1420 foreach ($NOconf as $key => $val) {
1421 if ($this->isItemState('CURIFSUB', $key)) {
1422 // If this is the first 'current', we must generate CURIFSUB.
1423 if ($CURIFSUBconf === null) {
1424 $CURIFSUBconf = $this->tmpl->splitConfArray($this->mconf['CURIFSUB.'], $splitCount);
1425 // Prepare current rollOver settings, overriding normal current settings
1426 if (!empty($this->mconf['CURIFSUBRO'])) {
1427 $CURIFSUBROconf = $this->tmpl->splitConfArray($this->mconf['CURIFSUBRO.'], $splitCount);
1428 }
1429 }
1430 // Substitute normal with active
1431 if ($CURIFSUBconf[$key]) {
1432 $NOconf[$key] = $CURIFSUBconf[$key];
1433 }
1434 // If rollOver on normal, we must apply a state for rollOver on the current
1435 if ($ROconf) {
1436 // If RollOver on current then apply this
1437 $ROconf[$key] = !empty($CURIFSUBROconf[$key]) ? $CURIFSUBROconf[$key] : $CURIFSUBconf[$key];
1438 }
1439 }
1440 }
1441 }
1442 // Prepare active settings, overriding normal settings
1443 if (!empty($this->mconf['USR'])) {
1444 $USRconf = null;
1445 $USRROconf = null;
1446 // Find active
1447 foreach ($NOconf as $key => $val) {
1448 if ($this->isItemState('USR', $key)) {
1449 // if this is the first active, we must generate USR.
1450 if ($USRconf === null) {
1451 $USRconf = $this->tmpl->splitConfArray($this->mconf['USR.'], $splitCount);
1452 // Prepare active rollOver settings, overriding normal active settings
1453 if (!empty($this->mconf['USRRO'])) {
1454 $USRROconf = $this->tmpl->splitConfArray($this->mconf['USRRO.'], $splitCount);
1455 }
1456 }
1457 // Substitute normal with active
1458 if ($USRconf[$key]) {
1459 $NOconf[$key] = $USRconf[$key];
1460 }
1461 // If rollOver on normal, we must apply a state for rollOver on the active
1462 if ($ROconf) {
1463 // If RollOver on active then apply this
1464 $ROconf[$key] = !empty($USRROconf[$key]) ? $USRROconf[$key] : $USRconf[$key];
1465 }
1466 }
1467 }
1468 }
1469 // Prepare spacer settings, overriding normal settings
1470 if (!empty($this->mconf['SPC'])) {
1471 $SPCconf = null;
1472 // Find spacers
1473 foreach ($NOconf as $key => $val) {
1474 if ($this->isItemState('SPC', $key)) {
1475 // If this is the first spacer, we must generate SPC.
1476 if ($SPCconf === null) {
1477 $SPCconf = $this->tmpl->splitConfArray($this->mconf['SPC.'], $splitCount);
1478 }
1479 // Substitute normal with spacer
1480 if (isset($SPCconf[$key])) {
1481 $NOconf[$key] = $SPCconf[$key];
1482 }
1483 }
1484 }
1485 }
1486 // Prepare Userdefined settings
1487 if (!empty($this->mconf['USERDEF1'])) {
1488 $USERDEF1conf = null;
1489 $USERDEF1ROconf = null;
1490 // Find active
1491 foreach ($NOconf as $key => $val) {
1492 if ($this->isItemState('USERDEF1', $key)) {
1493 // If this is the first active, we must generate USERDEF1.
1494 if ($USERDEF1conf === null) {
1495 $USERDEF1conf = $this->tmpl->splitConfArray($this->mconf['USERDEF1.'], $splitCount);
1496 // Prepare active rollOver settings, overriding normal active settings
1497 if (!empty($this->mconf['USERDEF1RO'])) {
1498 $USERDEF1ROconf = $this->tmpl->splitConfArray($this->mconf['USERDEF1RO.'], $splitCount);
1499 }
1500 }
1501 // Substitute normal with active
1502 if (isset($USERDEF1conf[$key])) {
1503 $NOconf[$key] = $USERDEF1conf[$key];
1504 }
1505 // If rollOver on normal, we must apply a state for rollOver on the active
1506 if ($ROconf) {
1507 // If RollOver on active then apply this
1508 $ROconf[$key] = !empty($USERDEF1ROconf[$key]) ? $USERDEF1ROconf[$key] : $USERDEF1conf[$key];
1509 }
1510 }
1511 }
1512 }
1513 // Prepare Userdefined settings
1514 if (!empty($this->mconf['USERDEF2'])) {
1515 $USERDEF2conf = null;
1516 $USERDEF2ROconf = null;
1517 // Find active
1518 foreach ($NOconf as $key => $val) {
1519 if ($this->isItemState('USERDEF2', $key)) {
1520 // If this is the first active, we must generate USERDEF2.
1521 if ($USERDEF2conf === null) {
1522 $USERDEF2conf = $this->tmpl->splitConfArray($this->mconf['USERDEF2.'], $splitCount);
1523 // Prepare active rollOver settings, overriding normal active settings
1524 if (!empty($this->mconf['USERDEF2RO'])) {
1525 $USERDEF2ROconf = $this->tmpl->splitConfArray($this->mconf['USERDEF2RO.'], $splitCount);
1526 }
1527 }
1528 // Substitute normal with active
1529 if (isset($USERDEF2conf[$key])) {
1530 $NOconf[$key] = $USERDEF2conf[$key];
1531 }
1532 // If rollOver on normal, we must apply a state for rollOver on the active
1533 if ($ROconf) {
1534 // If RollOver on active then apply this
1535 $ROconf[$key] = !empty($USERDEF2ROconf[$key]) ? $USERDEF2ROconf[$key] : $USERDEF2conf[$key];
1536 }
1537 }
1538 }
1539 }
1540 return [$NOconf, $ROconf];
1541 }
1542
1543 /**
1544 * Creates the URL, target and onclick values for the menu item link. Returns them in an array as key/value pairs for <A>-tag attributes
1545 * This function doesn't care about the url, because if we let the url be redirected, it will be logged in the stat!!!
1546 *
1547 * @param int $key Pointer to a key in the $this->menuArr array where the value for that key represents the menu item we are linking to (page record)
1548 * @param string $altTarget Alternative target
1549 * @param string $typeOverride Alternative type
1550 * @return array Returns an array with A-tag attributes as key/value pairs (HREF, TARGET and onClick)
1551 * @internal
1552 */
1553 public function link($key, $altTarget = '', $typeOverride = '')
1554 {
1555 // Mount points:
1556 $MP_var = $this->getMPvar($key);
1557 $MP_params = $MP_var ? '&MP=' . rawurlencode($MP_var) : '';
1558 // Setting override ID
1559 if ($this->mconf['overrideId'] || $this->menuArr[$key]['overrideId']) {
1560 $overrideArray = [];
1561 // If a user script returned the value overrideId in the menu array we use that as page id
1562 $overrideArray['uid'] = $this->mconf['overrideId'] ?: $this->menuArr[$key]['overrideId'];
1563 $overrideArray['alias'] = '';
1564 // Clear MP parameters since ID was changed.
1565 $MP_params = '';
1566 } else {
1567 $overrideArray = '';
1568 }
1569 // Setting main target:
1570 if ($altTarget) {
1571 $mainTarget = $altTarget;
1572 } elseif ($this->mconf['target.']) {
1573 $mainTarget = $this->parent_cObj->stdWrap($this->mconf['target'], $this->mconf['target.']);
1574 } else {
1575 $mainTarget = $this->mconf['target'];
1576 }
1577 // Creating link:
1578 $addParams = $this->mconf['addParams'] . $MP_params;
1579 if ($this->mconf['collapse'] && $this->isActive($this->menuArr[$key]['uid'], $this->getMPvar($key))) {
1580 $thePage = $this->sys_page->getPage($this->menuArr[$key]['pid']);
1581 $addParams .= $this->menuArr[$key]['_ADD_GETVARS'];
1582 $LD = $this->menuTypoLink($thePage, $mainTarget, '', '', $overrideArray, $addParams, $typeOverride);
1583 } else {
1584 $addParams .= $this->I['val']['additionalParams'] . $this->menuArr[$key]['_ADD_GETVARS'];
1585 $LD = $this->menuTypoLink($this->menuArr[$key], $mainTarget, '', '', $overrideArray, $addParams, $typeOverride);
1586 }
1587 // Override URL if using "External URL"
1588 if ($this->menuArr[$key]['doktype'] == PageRepository::DOKTYPE_LINK) {
1589 if ($this->menuArr[$key]['urltype'] == 3 && GeneralUtility::validEmail($this->menuArr[$key]['url'])) {
1590 // Create mailto-link using \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::typolink (concerning spamProtectEmailAddresses):
1591 $LD['totalURL'] = $this->parent_cObj->typoLink_URL(['parameter' => $this->menuArr[$key]['url']]);
1592 $LD['target'] = '';
1593 } else {
1594 $LD['totalURL'] = $this->parent_cObj->typoLink_URL(['parameter' => $this->getSysPage()->getExtURL($this->menuArr[$key])]);
1595 }
1596 }
1597
1598 $tsfe = $this->getTypoScriptFrontendController();
1599
1600 // Override url if current page is a shortcut
1601 $shortcut = null;
1602 if ($this->menuArr[$key]['doktype'] == PageRepository::DOKTYPE_SHORTCUT && $this->menuArr[$key]['shortcut_mode'] != PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
1603 $menuItem = $this->determineOriginalShortcutPage($this->menuArr[$key]);
1604 try {
1605 $shortcut = $tsfe->getPageShortcut(
1606 $menuItem['shortcut'],
1607 $menuItem['shortcut_mode'],
1608 $menuItem['uid'],
1609 20,
1610 [],
1611 true
1612 );
1613 } catch (\Exception $ex) {
1614 }
1615 if (!is_array($shortcut)) {
1616 return [];
1617 }
1618 // Only setting url, not target
1619 $LD['totalURL'] = $this->parent_cObj->typoLink_URL([
1620 'parameter' => $shortcut['uid'],
1621 'additionalParams' => $addParams . $this->I['val']['additionalParams'] . $menuItem['_ADD_GETVARS'],
1622 'linkAccessRestrictedPages' => $this->mconf['showAccessRestrictedPages'] && $this->mconf['showAccessRestrictedPages'] !== 'NONE'
1623 ]);
1624 }
1625 if ($shortcut) {
1626 $pageData = $shortcut;
1627 $pageData['_SHORTCUT_PAGE_UID'] = $this->menuArr[$key]['uid'];
1628 } else {
1629 $pageData = $this->menuArr[$key];
1630 }
1631 // Manipulation in case of access restricted pages:
1632 $this->changeLinksForAccessRestrictedPages($LD, $pageData, $mainTarget, $typeOverride);
1633 // Overriding URL / Target if set to do so:
1634 if ($this->menuArr[$key]['_OVERRIDE_HREF']) {
1635 $LD['totalURL'] = $this->menuArr[$key]['_OVERRIDE_HREF'];
1636 if ($this->menuArr[$key]['_OVERRIDE_TARGET']) {
1637 $LD['target'] = $this->menuArr[$key]['_OVERRIDE_TARGET'];
1638 }
1639 }
1640 // OnClick open in windows.
1641 $onClick = '';
1642 if ($this->mconf['JSWindow']) {
1643 $conf = $this->mconf['JSWindow.'];
1644 $url = $LD['totalURL'];
1645 $LD['totalURL'] = '#';
1646 $onClick = 'openPic('
1647 . GeneralUtility::quoteJSvalue($tsfe->baseUrlWrap($url)) . ','
1648 . '\'' . ($conf['newWindow'] ? md5($url) : 'theNewPage') . '\','
1649 . GeneralUtility::quoteJSvalue($conf['params']) . '); return false;';
1650 $tsfe->setJS('openPic');
1651 }
1652 // look for type and popup
1653 // following settings are valid in field target:
1654 // 230 will add type=230 to the link
1655 // 230 500x600 will add type=230 to the link and open in popup window with 500x600 pixels
1656 // 230 _blank will add type=230 to the link and open with target "_blank"
1657 // 230x450:resizable=0,location=1 will open in popup window with 500x600 pixels with settings "resizable=0,location=1"
1658 $matches = [];
1659 $targetIsType = $LD['target'] && MathUtility::canBeInterpretedAsInteger($LD['target']) ? (int)$LD['target'] : false;
1660 if (preg_match('/([0-9]+[\\s])?(([0-9]+)x([0-9]+))?(:.+)?/s', $LD['target'], $matches) || $targetIsType) {
1661 // has type?
1662 if ((int)$matches[1] || $targetIsType) {
1663 $LD['totalURL'] = $this->parent_cObj->URLqMark($LD['totalURL'], '&type=' . ($targetIsType ?: (int)$matches[1]));
1664 $LD['target'] = $targetIsType ? '' : trim(substr($LD['target'], strlen($matches[1]) + 1));
1665 }
1666 // Open in popup window?
1667 if ($matches[3] && $matches[4]) {
1668 $JSparamWH = 'width=' . $matches[3] . ',height=' . $matches[4] . ($matches[5] ? ',' . substr($matches[5], 1) : '');
1669 $onClick = 'vHWin=window.open('
1670 . GeneralUtility::quoteJSvalue($tsfe->baseUrlWrap($LD['totalURL']))
1671 . ',\'FEopenLink\',' . GeneralUtility::quoteJSvalue($JSparamWH) . ');vHWin.focus();return false;';
1672 $LD['target'] = '';
1673 }
1674 }
1675 // out:
1676 $list = [];
1677 // Added this check: What it does is to enter the baseUrl (if set, which it should for "realurl" based sites)
1678 // as URL if the calculated value is empty. The problem is that no link is generated with a blank URL
1679 // and blank URLs might appear when the realurl encoding is used and a link to the frontpage is generated.
1680 $list['HREF'] = (string)$LD['totalURL'] !== '' ? $LD['totalURL'] : $tsfe->baseUrl;
1681 $list['TARGET'] = $LD['target'];
1682 $list['onClick'] = $onClick;
1683 return $list;
1684 }
1685
1686 /**
1687 * Determines original shortcut destination in page overlays.
1688 *
1689 * Since the pages records used for menu rendering are overlaid by default,
1690 * the original 'shortcut' value is lost, if a translation did not define one.
1691 * The behaviour in TSFE can be compared to the 'mergeIfNotBlank' feature, but
1692 * it's hardcoded there and not related to the mentioned setting at all.
1693 *
1694 * @param array $page
1695 * @return array
1696 */
1697 protected function determineOriginalShortcutPage(array $page)
1698 {
1699 // Check if modification is required
1700 if (
1701 $this->getTypoScriptFrontendController()->sys_language_uid > 0
1702 && empty($page['shortcut'])
1703 && !empty($page['uid'])
1704 && !empty($page['_PAGES_OVERLAY'])
1705 && !empty($page['_PAGES_OVERLAY_UID'])
1706 ) {
1707 // Using raw record since the record was overlaid and is correct already:
1708 $originalPage = $this->sys_page->getRawRecord('pages', $page['uid']);
1709
1710 if ($originalPage['shortcut_mode'] === $page['shortcut_mode'] && !empty($originalPage['shortcut'])) {
1711 $page['shortcut'] = $originalPage['shortcut'];
1712 }
1713 }
1714
1715 return $page;
1716 }
1717
1718 /**
1719 * Will change $LD (passed by reference) if the page is access restricted
1720 *
1721 * @param array $LD The array from the linkData() function
1722 * @param array $page Page array
1723 * @param string $mainTarget Main target value
1724 * @param string $typeOverride Type number override if any
1725 * @return void ($LD passed by reference might be changed.)
1726 */
1727 public function changeLinksForAccessRestrictedPages(&$LD, $page, $mainTarget, $typeOverride)
1728 {
1729 // If access restricted pages should be shown in menus, change the link of such pages to link to a redirection page:
1730 if ($this->mconf['showAccessRestrictedPages'] && $this->mconf['showAccessRestrictedPages'] !== 'NONE' && !$this->getTypoScriptFrontendController()->checkPageGroupAccess($page)) {
1731 $thePage = $this->sys_page->getPage($this->mconf['showAccessRestrictedPages']);
1732 $addParams = str_replace(
1733 [
1734 '###RETURN_URL###',
1735 '###PAGE_ID###'
1736 ],
1737 [
1738 rawurlencode($LD['totalURL']),
1739 isset($page['_SHORTCUT_PAGE_UID']) ? $page['_SHORTCUT_PAGE_UID'] : $page['uid']
1740 ],
1741 $this->mconf['showAccessRestrictedPages.']['addParams']
1742 );
1743 $LD = $this->menuTypoLink($thePage, $mainTarget, '', '', '', $addParams, $typeOverride);
1744 }
1745 }
1746
1747 /**
1748 * Creates a submenu level to the current level - if configured for.
1749 *
1750 * @param int $uid Page id of the current page for which a submenu MAY be produced (if conditions are met)
1751 * @param string $objSuffix Object prefix, see ->start()
1752 * @return string HTML content of the submenu
1753 * @internal
1754 */
1755 public function subMenu($uid, $objSuffix = '')
1756 {
1757 // Setting alternative menu item array if _SUB_MENU has been defined in the current ->menuArr
1758 $altArray = '';
1759 if (is_array($this->menuArr[$this->I['key']]['_SUB_MENU']) && !empty($this->menuArr[$this->I['key']]['_SUB_MENU'])) {
1760 $altArray = $this->menuArr[$this->I['key']]['_SUB_MENU'];
1761 }
1762 // Make submenu if the page is the next active
1763 $menuType = $this->conf[($this->menuNumber + 1) . $objSuffix];
1764 // stdWrap for expAll
1765 if (isset($this->mconf['expAll.'])) {
1766 $this->mconf['expAll'] = $this->parent_cObj->stdWrap($this->mconf['expAll'], $this->mconf['expAll.']);
1767 }
1768 if (($this->mconf['expAll'] || $this->isNext($uid, $this->getMPvar($this->I['key'])) || is_array($altArray)) && !$this->mconf['sectionIndex']) {
1769 try {
1770 $menuObjectFactory = GeneralUtility::makeInstance(MenuContentObjectFactory::class);
1771 /** @var $submenu AbstractMenuContentObject */
1772 $submenu = $menuObjectFactory->getMenuObjectByType($menuType);
1773 $submenu->entryLevel = $this->entryLevel + 1;
1774 $submenu->rL_uidRegister = $this->rL_uidRegister;
1775 $submenu->MP_array = $this->MP_array;
1776 if ($this->menuArr[$this->I['key']]['_MP_PARAM']) {
1777 $submenu->MP_array[] = $this->menuArr[$this->I['key']]['_MP_PARAM'];
1778 }
1779 // Especially scripts that build the submenu needs the parent data
1780 $submenu->parent_cObj = $this->parent_cObj;
1781 $submenu->setParentMenu($this->menuArr, $this->I['key']);
1782 // Setting alternativeMenuTempArray (will be effective only if an array)
1783 if (is_array($altArray)) {
1784 $submenu->alternativeMenuTempArray = $altArray;
1785 }
1786 if ($submenu->start($this->tmpl, $this->sys_page, $uid, $this->conf, $this->menuNumber + 1, $objSuffix)) {
1787 $submenu->makeMenu();
1788 // Memorize the current menu item count
1789 $tsfe = $this->getTypoScriptFrontendController();
1790 $tempCountMenuObj = $tsfe->register['count_MENUOBJ'];
1791 // Reset the menu item count for the submenu
1792 $tsfe->register['count_MENUOBJ'] = 0;
1793 $content = $submenu->writeMenu();
1794 // Restore the item count now that the submenu has been handled
1795 $tsfe->register['count_MENUOBJ'] = $tempCountMenuObj;
1796 $tsfe->register['count_menuItems'] = count($this->menuArr);
1797 return $content;
1798 }
1799 } catch (Exception\NoSuchMenuTypeException $e) {
1800 }
1801 }
1802 return '';
1803 }
1804
1805 /**
1806 * Returns TRUE if the page with UID $uid is the NEXT page in root line (which means a submenu should be drawn)
1807 *
1808 * @param int $uid Page uid to evaluate.
1809 * @param string $MPvar MPvar for the current position of item.
1810 * @return bool TRUE if page with $uid is active
1811 * @internal
1812 * @see subMenu()
1813 */
1814 public function isNext($uid, $MPvar = '')
1815 {
1816 // Check for always active PIDs:
1817 if (!empty($this->alwaysActivePIDlist) && in_array((int)$uid, $this->alwaysActivePIDlist, true)) {
1818 return true;
1819 }
1820 $testUid = $uid . ($MPvar ? ':' . $MPvar : '');
1821 if ($uid && $testUid == $this->nextActive) {
1822 return true;
1823 }
1824 return false;
1825 }
1826
1827 /**
1828 * Returns TRUE if the page with UID $uid is active (in the current rootline)
1829 *
1830 * @param int $uid Page uid to evaluate.
1831 * @param string $MPvar MPvar for the current position of item.
1832 * @return bool TRUE if page with $uid is active
1833 * @internal
1834 */
1835 public function isActive($uid, $MPvar = '')
1836 {
1837 // Check for always active PIDs:
1838 if (!empty($this->alwaysActivePIDlist) && in_array((int)$uid, $this->alwaysActivePIDlist, true)) {
1839 return true;
1840 }
1841 $testUid = $uid . ($MPvar ? ':' . $MPvar : '');
1842 if ($uid && in_array('ITEM:' . $testUid, $this->rL_uidRegister, true)) {
1843 return true;
1844 }
1845 return false;
1846 }
1847
1848 /**
1849 * Returns TRUE if the page with UID $uid is the CURRENT page (equals $this->getTypoScriptFrontendController()->id)
1850 *
1851 * @param int $uid Page uid to evaluate.
1852 * @param string $MPvar MPvar for the current position of item.
1853 * @return bool TRUE if page $uid = $this->getTypoScriptFrontendController()->id
1854 * @internal
1855 */
1856 public function isCurrent($uid, $MPvar = '')
1857 {
1858 $testUid = $uid . ($MPvar ? ':' . $MPvar : '');
1859 return $uid && end($this->rL_uidRegister) === 'ITEM:' . $testUid;
1860 }
1861
1862 /**
1863 * Returns TRUE if there is a submenu with items for the page id, $uid
1864 * Used by the item states "IFSUB", "ACTIFSUB" and "CURIFSUB" to check if there is a submenu
1865 *
1866 * @param int $uid Page uid for which to search for a submenu
1867 * @return bool Returns TRUE if there was a submenu with items found
1868 * @internal
1869 */
1870 public function isSubMenu($uid)
1871 {
1872 // Looking for a mount-pid for this UID since if that
1873 // exists we should look for a subpages THERE and not in the input $uid;
1874 $mount_info = $this->sys_page->getMountPointInfo($uid);
1875 if (is_array($mount_info)) {
1876 $uid = $mount_info['mount_pid'];
1877 }
1878 $recs = $this->sys_page->getMenu($uid, 'uid,pid,doktype,mount_pid,mount_pid_ol,nav_hide,shortcut,shortcut_mode,l18n_cfg');
1879 $hasSubPages = false;
1880 $bannedUids = $this->getBannedUids();
1881 foreach ($recs as $theRec) {
1882 // no valid subpage if the document type is excluded from the menu
1883 if (GeneralUtility::inList($this->doktypeExcludeList, $theRec['doktype'])) {
1884 continue;
1885 }
1886 // No valid subpage if the page is hidden inside menus and
1887 // it wasn't forced to show such entries
1888 if ($theRec['nav_hide'] && !$this->conf['includeNotInMenu']) {
1889 continue;
1890 }
1891 // No valid subpage if the default language should be shown and the page settings
1892 // are excluding the visibility of the default language
1893 if (!$this->getTypoScriptFrontendController()->sys_language_uid && GeneralUtility::hideIfDefaultLanguage($theRec['l18n_cfg'])) {
1894 continue;
1895 }
1896 // No valid subpage if the alternative language should be shown and the page settings
1897 // are requiring a valid overlay but it doesn't exists
1898 $hideIfNotTranslated = GeneralUtility::hideIfNotTranslated($theRec['l18n_cfg']);
1899 if ($this->getTypoScriptFrontendController()->sys_language_uid && $hideIfNotTranslated && !$theRec['_PAGES_OVERLAY']) {
1900 continue;
1901 }
1902 // No valid subpage if the subpage is banned by excludeUidList
1903 if (in_array($theRec['uid'], $bannedUids)) {
1904 continue;
1905 }
1906 $hasSubPages = true;
1907 break;
1908 }
1909 return $hasSubPages;
1910 }
1911
1912 /**
1913 * Used by procesItemStates() to evaluate if a menu item (identified by $key) is in a certain state.
1914 *
1915 * @param string $kind The item state to evaluate (SPC, IFSUB, ACT etc... but no xxxRO states of course)
1916 * @param int $key Key pointing to menu item from ->menuArr
1917 * @return bool Returns TRUE if state matches
1918 * @internal
1919 * @see procesItemStates()
1920 */
1921 public function isItemState($kind, $key)
1922 {
1923 $natVal = false;
1924 // If any value is set for ITEM_STATE the normal evaluation is discarded
1925 if ($this->menuArr[$key]['ITEM_STATE']) {
1926 if ((string)$this->menuArr[$key]['ITEM_STATE'] === (string)$kind) {
1927 $natVal = true;
1928 }
1929 } else {
1930 switch ($kind) {
1931 case 'SPC':
1932 $natVal = (bool)$this->menuArr[$key]['isSpacer'];
1933 break;
1934 case 'IFSUB':
1935 $natVal = $this->isSubMenu($this->menuArr[$key]['uid']);
1936 break;
1937 case 'ACT':
1938 $natVal = $this->isActive($this->menuArr[$key]['uid'], $this->getMPvar($key));
1939 break;
1940 case 'ACTIFSUB':
1941 $natVal = $this->isActive($this->menuArr[$key]['uid'], $this->getMPvar($key)) && $this->isSubMenu($this->menuArr[$key]['uid']);
1942 break;
1943 case 'CUR':
1944 $natVal = $this->isCurrent($this->menuArr[$key]['uid'], $this->getMPvar($key));
1945 break;
1946 case 'CURIFSUB':
1947 $natVal = $this->isCurrent($this->menuArr[$key]['uid'], $this->getMPvar($key)) && $this->isSubMenu($this->menuArr[$key]['uid']);
1948 break;
1949 case 'USR':
1950 $natVal = (bool)$this->menuArr[$key]['fe_group'];
1951 break;
1952 }
1953 }
1954 return $natVal;
1955 }
1956
1957 /**
1958 * Creates an access-key for a TMENU/GMENU menu item based on the menu item titles first letter
1959 *
1960 * @param string $title Menu item title.
1961 * @return array Returns an array with keys "code" ("accesskey" attribute for the img-tag) and "alt" (text-addition to the "alt" attribute) if an access key was defined. Otherwise array was empty
1962 * @internal
1963 */
1964 public function accessKey($title)
1965 {
1966 $tsfe = $this->getTypoScriptFrontendController();
1967 // The global array ACCESSKEY is used to globally control if letters are already used!!
1968 $result = [];
1969 $title = trim(strip_tags($title));
1970 $titleLen = strlen($title);
1971 for ($a = 0; $a < $titleLen; $a++) {
1972 $key = strtoupper(substr($title, $a, 1));
1973 if (preg_match('/[A-Z]/', $key) && !isset($tsfe->accessKey[$key])) {
1974 $tsfe->accessKey[$key] = 1;
1975 $result['code'] = ' accesskey="' . $key . '"';
1976 $result['alt'] = ' (ALT+' . $key . ')';
1977 $result['key'] = $key;
1978 break;
1979 }
1980 }
1981 return $result;
1982 }
1983
1984 /**
1985 * Calls a user function for processing of internal data.
1986 * Used for the properties "IProcFunc" and "itemArrayProcFunc"
1987 *
1988 * @param string $mConfKey Key pointing for the property in the current ->mconf array holding possibly parameters to pass along to the function/method. Currently the keys used are "IProcFunc" and "itemArrayProcFunc".
1989 * @param mixed $passVar A variable to pass to the user function and which should be returned again from the user function. The idea is that the user function modifies this variable according to what you want to achieve and then returns it. For "itemArrayProcFunc" this variable is $this->menuArr, for "IProcFunc" it is $this->I
1990 * @return mixed The processed $passVar
1991 * @internal
1992 */
1993 public function userProcess($mConfKey, $passVar)
1994 {
1995 if ($this->mconf[$mConfKey]) {
1996 $funcConf = $this->mconf[$mConfKey . '.'];
1997 $funcConf['parentObj'] = $this;
1998 $passVar = $this->parent_cObj->callUserFunction($this->mconf[$mConfKey], $funcConf, $passVar);
1999 }
2000 return $passVar;
2001 }
2002
2003 /**
2004 * Creates the <A> tag parts for the current item (in $this->I, [A1] and [A2]) based on other information in this array (like $this->I['linkHREF'])
2005 *
2006 * @return void
2007 * @internal
2008 */
2009 public function setATagParts()
2010 {
2011 $params = trim($this->I['val']['ATagParams']) . $this->I['accessKey']['code'];
2012 $params = $params !== '' ? ' ' . $params : '';
2013 $this->I['A1'] = '<a ' . GeneralUtility::implodeAttributes($this->I['linkHREF'], 1) . $params . '>';
2014 $this->I['A2'] = '</a>';
2015 }
2016
2017 /**
2018 * Returns the title for the navigation
2019 *
2020 * @param string $title The current page title
2021 * @param string $nav_title The current value of the navigation title
2022 * @return string Returns the navigation title if it is NOT blank, otherwise the page title.
2023 * @internal
2024 */
2025 public function getPageTitle($title, $nav_title)
2026 {
2027 return trim($nav_title) !== '' ? $nav_title : $title;
2028 }
2029
2030 /**
2031 * Return MPvar string for entry $key in ->menuArr
2032 *
2033 * @param int $key Pointer to element in ->menuArr
2034 * @return string MP vars for element.
2035 * @see link()
2036 */
2037 public function getMPvar($key)
2038 {
2039 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids']) {
2040 $localMP_array = $this->MP_array;
2041 // NOTICE: "_MP_PARAM" is allowed to be a commalist of PID pairs!
2042 if ($this->menuArr[$key]['_MP_PARAM']) {
2043 $localMP_array[] = $this->menuArr[$key]['_MP_PARAM'];
2044 }
2045 return !empty($localMP_array) ? implode(',', $localMP_array) : '';
2046 }
2047 return '';
2048 }
2049
2050 /**
2051 * Returns where clause part to exclude 'not in menu' pages
2052 *
2053 * @return string where clause part.
2054 * @internal
2055 */
2056 public function getDoktypeExcludeWhere()
2057 {
2058 return $this->doktypeExcludeList ? ' AND pages.doktype NOT IN (' . $this->doktypeExcludeList . ')' : '';
2059 }
2060
2061 /**
2062 * Returns an array of banned UIDs (from excludeUidList)
2063 *
2064 * @return array Array of banned UIDs
2065 * @internal
2066 */
2067 public function getBannedUids()
2068 {
2069 $excludeUidList = isset($this->conf['excludeUidList.'])
2070 ? $this->parent_cObj->stdWrap($this->conf['excludeUidList'], $this->conf['excludeUidList.'])
2071 : $this->conf['excludeUidList'];
2072
2073 if (!trim($excludeUidList)) {
2074 return [];
2075 }
2076
2077 $banUidList = str_replace('current', $this->getTypoScriptFrontendController()->page['uid'], $excludeUidList);
2078 return GeneralUtility::intExplode(',', $banUidList);
2079 }
2080
2081 /**
2082 * Calls typolink to create menu item links.
2083 *
2084 * @param array $page Page record (uid points where to link to)
2085 * @param string $oTarget Target frame/window
2086 * @param bool $no_cache TRUE if caching should be disabled
2087 * @param string $script Alternative script name (unused)
2088 * @param array|string $overrideArray Array to override values in $page, empty string to skip override
2089 * @param string $addParams Parameters to add to URL
2090 * @param int|string $typeOverride "type" value, empty string means "not set"
2091 * @return array See linkData
2092 */
2093 public function menuTypoLink($page, $oTarget, $no_cache, $script, $overrideArray = '', $addParams = '', $typeOverride = '')
2094 {
2095 $conf = [
2096 'parameter' => is_array($overrideArray) && $overrideArray['uid'] ? $overrideArray['uid'] : $page['uid']
2097 ];
2098 if (MathUtility::canBeInterpretedAsInteger($typeOverride)) {
2099 $conf['parameter'] .= ',' . (int)$typeOverride;
2100 }
2101 if ($addParams) {
2102 $conf['additionalParams'] = $addParams;
2103 }
2104 if ($no_cache) {
2105 $conf['no_cache'] = true;
2106 } elseif ($this->useCacheHash) {
2107 $conf['useCacheHash'] = true;
2108 }
2109 if ($oTarget) {
2110 $conf['target'] = $oTarget;
2111 }
2112 if ($page['sectionIndex_uid']) {
2113 $conf['section'] = $page['sectionIndex_uid'];
2114 }
2115 $conf['linkAccessRestrictedPages'] = $this->mconf['showAccessRestrictedPages'] && $this->mconf['showAccessRestrictedPages'] !== 'NONE';
2116 $this->parent_cObj->typoLink('|', $conf);
2117 $LD = $this->parent_cObj->lastTypoLinkLD;
2118 $LD['totalURL'] = $this->parent_cObj->lastTypoLinkUrl;
2119 return $LD;
2120 }
2121
2122 /**
2123 * Generates a list of content objects with sectionIndex enabled
2124 * available on a specific page
2125 *
2126 * Used for menus with sectionIndex enabled
2127 *
2128 * @param string $altSortField Alternative sorting field
2129 * @param int $pid The page id to search for sections
2130 * @throws \UnexpectedValueException if the query to fetch the content elements unexpectedly fails
2131 * @return array
2132 */
2133 protected function sectionIndex($altSortField, $pid = null)
2134 {
2135 $pid = (int)($pid ?: $this->id);
2136 $basePageRow = $this->sys_page->getPage($pid);
2137 if (!is_array($basePageRow)) {
2138 return [];
2139 }
2140 $tsfe = $this->getTypoScriptFrontendController();
2141 $configuration = $this->mconf['sectionIndex.'];
2142 $useColPos = 0;
2143 if (trim($configuration['useColPos']) !== '' || is_array($configuration['useColPos.'])) {
2144 $useColPos = $tsfe->cObj->stdWrap($configuration['useColPos'], $configuration['useColPos.']);
2145 $useColPos = (int)$useColPos;
2146 }
2147 $selectSetup = [
2148 'pidInList' => $pid,
2149 'orderBy' => $altSortField,
2150 'languageField' => 'sys_language_uid',
2151 'where' => $useColPos >= 0 ? 'colPos=' . $useColPos : ''
2152 ];
2153 if ($basePageRow['content_from_pid']) {
2154 // If the page is configured to show content from a referenced page the sectionIndex contains only contents of
2155 // the referenced page
2156 $selectSetup['pidInList'] = $basePageRow['content_from_pid'];
2157 }
2158 $statement = $this->parent_cObj->exec_getQuery('tt_content', $selectSetup);
2159 if (!$statement) {
2160 $message = 'SectionIndex: Query to fetch the content elements failed!';
2161 throw new \UnexpectedValueException($message, 1337334849);
2162 }
2163 $result = [];
2164 while ($row = $statement->fetch()) {
2165 $this->sys_page->versionOL('tt_content', $row);
2166 if ($tsfe->sys_language_contentOL && $basePageRow['_PAGES_OVERLAY_LANGUAGE']) {
2167 $row = $this->sys_page->getRecordOverlay('tt_content', $row, $basePageRow['_PAGES_OVERLAY_LANGUAGE'], $tsfe->sys_language_contentOL);
2168 }
2169 if ($this->mconf['sectionIndex.']['type'] !== 'all') {
2170 $doIncludeInSectionIndex = $row['sectionIndex'] >= 1;
2171 $doHeaderCheck = $this->mconf['sectionIndex.']['type'] === 'header';
2172 $isValidHeader = ((int)$row['header_layout'] !== 100 || !empty($this->mconf['sectionIndex.']['includeHiddenHeaders'])) && trim($row['header']) !== '';
2173 if (!$doIncludeInSectionIndex || $doHeaderCheck && !$isValidHeader) {
2174 continue;
2175 }
2176 }
2177 if (is_array($row)) {
2178 $uid = $row['uid'];
2179 $result[$uid] = $basePageRow;
2180 $result[$uid]['title'] = $row['header'];
2181 $result[$uid]['nav_title'] = $row['header'];
2182 // Prevent false exclusion in filterMenuPages, thus: Always show tt_content records
2183 $result[$uid]['nav_hide'] = 0;
2184 $result[$uid]['subtitle'] = $row['subheader'];
2185 $result[$uid]['starttime'] = $row['starttime'];
2186 $result[$uid]['endtime'] = $row['endtime'];
2187 $result[$uid]['fe_group'] = $row['fe_group'];
2188 $result[$uid]['media'] = $row['media'];
2189 $result[$uid]['header_layout'] = $row['header_layout'];
2190 $result[$uid]['bodytext'] = $row['bodytext'];
2191 $result[$uid]['image'] = $row['image'];
2192 $result[$uid]['sectionIndex_uid'] = $uid;
2193 }
2194 }
2195
2196 return $result;
2197 }
2198
2199 /**
2200 * Returns the sys_page object
2201 *
2202 * @return \TYPO3\CMS\Frontend\Page\PageRepository
2203 */
2204 public function getSysPage()
2205 {
2206 return $this->sys_page;
2207 }
2208
2209 /**
2210 * Returns the parent content object
2211 *
2212 * @return \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
2213 */
2214 public function getParentContentObject()
2215 {
2216 return $this->parent_cObj;
2217 }
2218
2219 /**
2220 * @return TypoScriptFrontendController
2221 */
2222 protected function getTypoScriptFrontendController()
2223 {
2224 return $GLOBALS['TSFE'];
2225 }
2226
2227 /**
2228 * @return TimeTracker
2229 */
2230 protected function getTimeTracker()
2231 {
2232 return GeneralUtility::makeInstance(TimeTracker::class);
2233 }
2234
2235 /**
2236 * @return \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
2237 */
2238 protected function getCache()
2239 {
2240 return GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_hash');
2241 }
2242
2243 /**
2244 * Set the parentMenuArr and key to provide the parentMenu informations to the
2245 * subMenu, special fur IProcFunc and itemArrayProcFunc user functions.
2246 *
2247 * @internal
2248 *
2249 * @param array $menuArr
2250 * @param int $menuItemKey
2251 */
2252 public function setParentMenu(array $menuArr = [], $menuItemKey)
2253 {
2254 // check if menuArr is a valid array and that menuItemKey matches an existing menuItem in menuArr
2255 if (is_array($menuArr)
2256 && (is_int($menuItemKey) && $menuItemKey >= 0 && isset($menuArr[$menuItemKey]))
2257 ) {
2258 $this->parentMenuArr = $menuArr;
2259 $this->parentMenuArrItemKey = $menuItemKey;
2260 }
2261 }
2262
2263 /**
2264 * Check if there is an valid parentMenuArr.
2265 *
2266 * @return bool
2267 */
2268 protected function hasParentMenuArr()
2269 {
2270 return
2271 $this->menuNumber > 1
2272 && is_array($this->parentMenuArr)
2273 && !empty($this->parentMenuArr)
2274 ;
2275 }
2276
2277 /**
2278 * Check if we have an parentMenutArrItemKey
2279 */
2280 protected function hasParentMenuItemKey()
2281 {
2282 return null !== $this->parentMenuArrItemKey;
2283 }
2284
2285 /**
2286 * Check if the the parentMenuItem exists
2287 */
2288 protected function hasParentMenuItem()
2289 {
2290 return
2291 $this->hasParentMenuArr()
2292 && $this->hasParentMenuItemKey()
2293 && isset($this->getParentMenuArr()[$this->parentMenuArrItemKey])
2294 ;
2295 }
2296
2297 /**
2298 * Get the parentMenuArr, if this is subMenu.
2299 *
2300 * @return array
2301 */
2302 public function getParentMenuArr()
2303 {
2304 return $this->hasParentMenuArr() ? $this->parentMenuArr : [];
2305 }
2306
2307 /**
2308 * Get the parentMenuItem from the parentMenuArr, if this is a subMenu
2309 *
2310 * @return null|array
2311 */
2312 public function getParentMenuItem()
2313 {
2314 // check if we have an parentMenuItem and if it is an array
2315 if ($this->hasParentMenuItem()
2316 && is_array($this->getParentMenuArr()[$this->parentMenuArrItemKey])
2317 ) {
2318 return $this->getParentMenuArr()[$this->parentMenuArrItemKey];
2319 }
2320
2321 return null;
2322 }
2323 }