e186d60af84c1b4b5c570a477f129d1be4541b85
[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 // Start point
964 $eLevel = $this->parent_cObj->getKey(isset($this->conf['special.']['entryLevel.'])
965 ? $this->parent_cObj->stdWrap($this->conf['special.']['entryLevel'], $this->conf['special.']['entryLevel.'])
966 : $this->conf['special.']['entryLevel'], $this->tmpl->rootLine
967 );
968 $startUid = (int)$this->tmpl->rootLine[$eLevel]['uid'];
969 // Which field is for keywords
970 $kfield = 'keywords';
971 if ($this->conf['special.']['keywordsField']) {
972 list($kfield) = explode(' ', trim($this->conf['special.']['keywordsField']));
973 }
974 // If there are keywords and the startuid is present
975 if ($kw && $startUid) {
976 $bA = MathUtility::forceIntegerInRange($this->conf['special.']['beginAtLevel'], 0, 100);
977 $id_list = $this->parent_cObj->getTreeList(-1 * $startUid, $depth - 1 + $bA, $bA - 1);
978 $kwArr = GeneralUtility::trimExplode(',', $kw, true);
979 $keyWordsWhereArr = [];
980 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
981 foreach ($kwArr as $word) {
982 $keyWordsWhereArr[] = $queryBuilder->expr()->like(
983 $kfield,
984 $queryBuilder->createNamedParameter(
985 '%' . $queryBuilder->escapeLikeWildcards($word) . '%',
986 \PDO::PARAM_STR
987 )
988 );
989 }
990 $queryBuilder
991 ->select('*')
992 ->from('pages')
993 ->where(
994 $queryBuilder->expr()->in(
995 'uid',
996 GeneralUtility::intExplode(',', $id_list, true)
997 ),
998 $queryBuilder->expr()->neq(
999 'uid',
1000 $queryBuilder->createNamedParameter($specialValue, \PDO::PARAM_INT)
1001 )
1002 );
1003
1004 if (count($keyWordsWhereArr) !== 0) {
1005 $queryBuilder->andWhere($queryBuilder->expr()->orX(...$keyWordsWhereArr));
1006 }
1007
1008 if ($this->doktypeExcludeList) {
1009 $queryBuilder->andWhere(
1010 $queryBuilder->expr()->notIn(
1011 'pages.doktype',
1012 GeneralUtility::intExplode(',', $this->doktypeExcludeList, true)
1013 )
1014 );
1015 }
1016
1017 if (!$this->conf['includeNotInMenu']) {
1018 $queryBuilder->andWhere($queryBuilder->expr()->eq('pages.nav_hide', 0));
1019 }
1020
1021 if ($this->conf['special.']['excludeNoSearchPages']) {
1022 $queryBuilder->andWhere($queryBuilder->expr()->eq('pages.no_search', 0));
1023 }
1024
1025 if ($limit > 0) {
1026 $queryBuilder->setMaxResults($limit);
1027 }
1028
1029 if ($sortingField) {
1030 $queryBuilder->orderBy($sortingField);
1031 } else {
1032 $queryBuilder->orderBy($sortField, 'desc');
1033 }
1034
1035 $result = $queryBuilder->execute();
1036 while ($row = $result->fetch()) {
1037 $tsfe->sys_page->versionOL('pages', $row, true);
1038 if (is_array($row)) {
1039 $menuItems[$row['uid']] = $this->sys_page->getPageOverlay($row);
1040 }
1041 }
1042 }
1043
1044 return $menuItems;
1045 }
1046
1047 /**
1048 * Fetches all menuitems if special = rootline is set
1049 *
1050 * @return array
1051 */
1052 protected function prepareMenuItemsForRootlineMenu()
1053 {
1054 $menuItems = [];
1055 $range = isset($this->conf['special.']['range.'])
1056 ? $this->parent_cObj->stdWrap($this->conf['special.']['range'], $this->conf['special.']['range.'])
1057 : $this->conf['special.']['range'];
1058 $begin_end = explode('|', $range);
1059 $begin_end[0] = (int)$begin_end[0];
1060 if (!MathUtility::canBeInterpretedAsInteger($begin_end[1])) {
1061 $begin_end[1] = -1;
1062 }
1063 $beginKey = $this->parent_cObj->getKey($begin_end[0], $this->tmpl->rootLine);
1064 $endKey = $this->parent_cObj->getKey($begin_end[1], $this->tmpl->rootLine);
1065 if ($endKey < $beginKey) {
1066 $endKey = $beginKey;
1067 }
1068 $rl_MParray = [];
1069 foreach ($this->tmpl->rootLine as $k_rl => $v_rl) {
1070 // For overlaid mount points, set the variable right now:
1071 if ($v_rl['_MP_PARAM'] && $v_rl['_MOUNT_OL']) {
1072 $rl_MParray[] = $v_rl['_MP_PARAM'];
1073 }
1074 // Traverse rootline:
1075 if ($k_rl >= $beginKey && $k_rl <= $endKey) {
1076 $temp_key = $k_rl;
1077 $menuItems[$temp_key] = $this->sys_page->getPage($v_rl['uid']);
1078 if (!empty($menuItems[$temp_key])) {
1079 // If there are no specific target for the page, put the level specific target on.
1080 if (!$menuItems[$temp_key]['target']) {
1081 $menuItems[$temp_key]['target'] = $this->conf['special.']['targets.'][$k_rl];
1082 $menuItems[$temp_key]['_MP_PARAM'] = implode(',', $rl_MParray);
1083 }
1084 } else {
1085 unset($menuItems[$temp_key]);
1086 }
1087 }
1088 // For normal mount points, set the variable for next level.
1089 if ($v_rl['_MP_PARAM'] && !$v_rl['_MOUNT_OL']) {
1090 $rl_MParray[] = $v_rl['_MP_PARAM'];
1091 }
1092 }
1093 // Reverse order of elements (e.g. "1,2,3,4" gets "4,3,2,1"):
1094 if (isset($this->conf['special.']['reverseOrder']) && $this->conf['special.']['reverseOrder']) {
1095 $menuItems = array_reverse($menuItems);
1096 }
1097 return $menuItems;
1098 }
1099
1100 /**
1101 * Fetches all menuitems if special = browse is set
1102 *
1103 * @param string $specialValue The value from special.value
1104 * @param string $sortingField The sorting field
1105 * @param string $additionalWhere Additional WHERE clause
1106 * @return array
1107 */
1108 protected function prepareMenuItemsForBrowseMenu($specialValue, $sortingField, $additionalWhere)
1109 {
1110 $menuItems = [];
1111 list($specialValue) = GeneralUtility::intExplode(',', $specialValue);
1112 if (!$specialValue) {
1113 $specialValue = $this->getTypoScriptFrontendController()->page['uid'];
1114 }
1115 // Will not work out of rootline
1116 if ($specialValue != $this->tmpl->rootLine[0]['uid']) {
1117 $recArr = [];
1118 // The page record of the 'value'.
1119 $value_rec = $this->sys_page->getPage($specialValue);
1120 // 'up' page cannot be outside rootline
1121 if ($value_rec['pid']) {
1122 // The page record of 'up'.
1123 $recArr['up'] = $this->sys_page->getPage($value_rec['pid']);
1124 }
1125 // If the 'up' item was NOT level 0 in rootline...
1126 if ($recArr['up']['pid'] && $value_rec['pid'] != $this->tmpl->rootLine[0]['uid']) {
1127 // The page record of "index".
1128 $recArr['index'] = $this->sys_page->getPage($recArr['up']['pid']);
1129 }
1130 // check if certain pages should be excluded
1131 $additionalWhere .= ($this->conf['includeNotInMenu'] ? '' : ' AND pages.nav_hide=0') . $this->getDoktypeExcludeWhere();
1132 if ($this->conf['special.']['excludeNoSearchPages']) {
1133 $additionalWhere .= ' AND pages.no_search=0';
1134 }
1135 // prev / next is found
1136 $prevnext_menu = $this->removeInaccessiblePages($this->sys_page->getMenu($value_rec['pid'], '*', $sortingField, $additionalWhere));
1137 $lastKey = 0;
1138 $nextActive = 0;
1139 foreach ($prevnext_menu as $k_b => $v_b) {
1140 if ($nextActive) {
1141 $recArr['next'] = $v_b;
1142 $nextActive = 0;
1143 }
1144 if ($v_b['uid'] == $specialValue) {
1145 if ($lastKey) {
1146 $recArr['prev'] = $prevnext_menu[$lastKey];
1147 }
1148 $nextActive = 1;
1149 }
1150 $lastKey = $k_b;
1151 }
1152
1153 $recArr['first'] = reset($prevnext_menu);
1154 $recArr['last'] = end($prevnext_menu);
1155 // prevsection / nextsection is found
1156 // You can only do this, if there is a valid page two levels up!
1157 if (!empty($recArr['index']['uid'])) {
1158 $prevnextsection_menu = $this->removeInaccessiblePages($this->sys_page->getMenu($recArr['index']['uid'], '*', $sortingField, $additionalWhere));
1159 $lastKey = 0;
1160 $nextActive = 0;
1161 foreach ($prevnextsection_menu as $k_b => $v_b) {
1162 if ($nextActive) {
1163 $sectionRec_temp = $this->removeInaccessiblePages($this->sys_page->getMenu($v_b['uid'], '*', $sortingField, $additionalWhere));
1164 if (!empty($sectionRec_temp)) {
1165 $recArr['nextsection'] = reset($sectionRec_temp);
1166 $recArr['nextsection_last'] = end($sectionRec_temp);
1167 $nextActive = 0;
1168 }
1169 }
1170 if ($v_b['uid'] == $value_rec['pid']) {
1171 if ($lastKey) {
1172 $sectionRec_temp = $this->removeInaccessiblePages($this->sys_page->getMenu($prevnextsection_menu[$lastKey]['uid'], '*', $sortingField, $additionalWhere));
1173 if (!empty($sectionRec_temp)) {
1174 $recArr['prevsection'] = reset($sectionRec_temp);
1175 $recArr['prevsection_last'] = end($sectionRec_temp);
1176 }
1177 }
1178 $nextActive = 1;
1179 }
1180 $lastKey = $k_b;
1181 }
1182 }
1183 if ($this->conf['special.']['items.']['prevnextToSection']) {
1184 if (!is_array($recArr['prev']) && is_array($recArr['prevsection_last'])) {
1185 $recArr['prev'] = $recArr['prevsection_last'];
1186 }
1187 if (!is_array($recArr['next']) && is_array($recArr['nextsection'])) {
1188 $recArr['next'] = $recArr['nextsection'];
1189 }
1190 }
1191 $items = explode('|', $this->conf['special.']['items']);
1192 $c = 0;
1193 foreach ($items as $k_b => $v_b) {
1194 $v_b = strtolower(trim($v_b));
1195 if ((int)$this->conf['special.'][$v_b . '.']['uid']) {
1196 $recArr[$v_b] = $this->sys_page->getPage((int)$this->conf['special.'][$v_b . '.']['uid']);
1197 }
1198 if (is_array($recArr[$v_b])) {
1199 $menuItems[$c] = $recArr[$v_b];
1200 if ($this->conf['special.'][$v_b . '.']['target']) {
1201 $menuItems[$c]['target'] = $this->conf['special.'][$v_b . '.']['target'];
1202 }
1203 $tmpSpecialFields = $this->conf['special.'][$v_b . '.']['fields.'];
1204 if (is_array($tmpSpecialFields)) {
1205 foreach ($tmpSpecialFields as $fk => $val) {
1206 $menuItems[$c][$fk] = $val;
1207 }
1208 }
1209 $c++;
1210 }
1211 }
1212 }
1213 return $menuItems;
1214 }
1215
1216 /**
1217 * Analyzes the parameters to find if the link needs a cHash parameter.
1218 *
1219 * @param string $queryString
1220 * @return void
1221 */
1222 protected function analyzeCacheHashRequirements($queryString)
1223 {
1224 $parameters = GeneralUtility::explodeUrl2Array($queryString);
1225 if (!empty($parameters)) {
1226 if (!isset($parameters['id'])) {
1227 $queryString .= '&id=' . $this->getTypoScriptFrontendController()->id;
1228 }
1229 /** @var CacheHashCalculator $cacheHashCalculator */
1230 $cacheHashCalculator = GeneralUtility::makeInstance(CacheHashCalculator::class);
1231 $cHashParameters = $cacheHashCalculator->getRelevantParameters($queryString);
1232 if (count($cHashParameters) > 1) {
1233 $this->useCacheHash = (
1234 $GLOBALS['TYPO3_CONF_VARS']['FE']['disableNoCacheParameter'] ||
1235 !isset($parameters['no_cache']) ||
1236 !$parameters['no_cache']
1237 );
1238 }
1239 }
1240 }
1241
1242 /**
1243 * Checks if a page is OK to include in the final menu item array. Pages can be excluded if the doktype is wrong,
1244 * if they are hidden in navigation, have a uid in the list of banned uids etc.
1245 *
1246 * @param array $data Array of menu items
1247 * @param array $banUidArray Array of page uids which are to be excluded
1248 * @param bool $spacer If set, then the page is a spacer.
1249 * @return bool Returns TRUE if the page can be safely included.
1250 *
1251 * @throws \UnexpectedValueException
1252 */
1253 public function filterMenuPages(&$data, $banUidArray, $spacer)
1254 {
1255 $includePage = true;
1256 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/tslib/class.tslib_menu.php']['filterMenuPages'])) {
1257 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/tslib/class.tslib_menu.php']['filterMenuPages'] as $classRef) {
1258 $hookObject = GeneralUtility::getUserObj($classRef);
1259 if (!$hookObject instanceof AbstractMenuFilterPagesHookInterface) {
1260 throw new \UnexpectedValueException($classRef . ' must implement interface ' . AbstractMenuFilterPagesHookInterface::class, 1269877402);
1261 }
1262 $includePage = $includePage && $hookObject->processFilter($data, $banUidArray, $spacer, $this);
1263 }
1264 }
1265 if (!$includePage) {
1266 return false;
1267 }
1268 if ($data['_SAFE']) {
1269 return true;
1270 }
1271
1272 if (
1273 ($this->mconf['SPC'] || !$spacer) // If the spacer-function is not enabled, spacers will not enter the $menuArr
1274 && (!$data['nav_hide'] || $this->conf['includeNotInMenu']) // Not hidden in navigation
1275 && !GeneralUtility::inList($this->doktypeExcludeList, $data['doktype']) // Page may not be 'not_in_menu' or 'Backend User Section'
1276 && !ArrayUtility::inArray($banUidArray, $data['uid']) // not in banned uid's
1277 ) {
1278 // Checks if the default language version can be shown:
1279 // Block page is set, if l18n_cfg allows plus: 1) Either default language or 2) another language but NO overlay record set for page!
1280 $tsfe = $this->getTypoScriptFrontendController();
1281 $blockPage = GeneralUtility::hideIfDefaultLanguage($data['l18n_cfg']) && (!$tsfe->sys_language_uid || $tsfe->sys_language_uid && !$data['_PAGES_OVERLAY']);
1282 if (!$blockPage) {
1283 // Checking if a page should be shown in the menu depending on whether a translation exists:
1284 $tok = true;
1285 // There is an alternative language active AND the current page requires a translation:
1286 if ($tsfe->sys_language_uid && GeneralUtility::hideIfNotTranslated($data['l18n_cfg'])) {
1287 if (!$data['_PAGES_OVERLAY']) {
1288 $tok = false;
1289 }
1290 }
1291 // Continue if token is TRUE:
1292 if ($tok) {
1293 // Checking if "&L" should be modified so links to non-accessible pages will not happen.
1294 if ($this->conf['protectLvar']) {
1295 $languageUid = (int)$tsfe->config['config']['sys_language_uid'];
1296 if ($languageUid && ($this->conf['protectLvar'] == 'all' || GeneralUtility::hideIfNotTranslated($data['l18n_cfg']))) {
1297 $olRec = $tsfe->sys_page->getPageOverlay($data['uid'], $languageUid);
1298 if (empty($olRec)) {
1299 // If no pages_language_overlay record then page can NOT be accessed in
1300 // the language pointed to by "&L" and therefore we protect the link by setting "&L=0"
1301 $data['_ADD_GETVARS'] .= '&L=0';
1302 }
1303 }
1304 }
1305 return true;
1306 }
1307 }
1308 }
1309 return false;
1310 }
1311
1312 /**
1313 * Generating the per-menu-item configuration arrays based on the settings for item states (NO, RO, ACT, CUR etc)
1314 * set in ->mconf (config for the current menu object)
1315 * Basically it will produce an individual array for each menu item based on the item states.
1316 * BUT in addition the "optionSplit" syntax for the values is ALSO evaluated here so that all property-values
1317 * are "option-splitted" and the output will thus be resolved.
1318 * Is called from the "generate" functions in the extension classes. The function is processor intensive due to
1319 * the option split feature in particular. But since the generate function is not always called
1320 * (since the ->result array may be cached, see makeMenu) it doesn't hurt so badly.
1321 *
1322 * @param int $splitCount Number of menu items in the menu
1323 * @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)
1324 *
1325 * @internal
1326 */
1327 public function procesItemStates($splitCount)
1328 {
1329 // Prepare normal settings
1330 if (!is_array($this->mconf['NO.']) && $this->mconf['NO']) {
1331 // Setting a blank array if NO=1 and there are no properties.
1332 $this->mconf['NO.'] = [];
1333 }
1334 $NOconf = $this->tmpl->splitConfArray($this->mconf['NO.'], $splitCount);
1335 // Prepare rollOver settings, overriding normal settings
1336 $ROconf = [];
1337 if ($this->mconf['RO']) {
1338 $ROconf = $this->tmpl->splitConfArray($this->mconf['RO.'], $splitCount);
1339 }
1340 // Prepare IFSUB settings, overriding normal settings
1341 // IFSUB is TRUE if there exist submenu items to the current item
1342 if (!empty($this->mconf['IFSUB'])) {
1343 $IFSUBconf = null;
1344 $IFSUBROconf = null;
1345 foreach ($NOconf as $key => $val) {
1346 if ($this->isItemState('IFSUB', $key)) {
1347 // if this is the first IFSUB element, we must generate IFSUB.
1348 if ($IFSUBconf === null) {
1349 $IFSUBconf = $this->tmpl->splitConfArray($this->mconf['IFSUB.'], $splitCount);
1350 if (!empty($this->mconf['IFSUBRO'])) {
1351 $IFSUBROconf = $this->tmpl->splitConfArray($this->mconf['IFSUBRO.'], $splitCount);
1352 }
1353 }
1354 // Substitute normal with ifsub
1355 if (isset($IFSUBconf[$key])) {
1356 $NOconf[$key] = $IFSUBconf[$key];
1357 }
1358 // If rollOver on normal, we must apply a state for rollOver on the active
1359 if ($ROconf) {
1360 // If RollOver on active then apply this
1361 $ROconf[$key] = !empty($IFSUBROconf[$key]) ? $IFSUBROconf[$key] : $IFSUBconf[$key];
1362 }
1363 }
1364 }
1365 }
1366 // Prepare active settings, overriding normal settings
1367 if (!empty($this->mconf['ACT'])) {
1368 $ACTconf = null;
1369 $ACTROconf = null;
1370 // Find active
1371 foreach ($NOconf as $key => $val) {
1372 if ($this->isItemState('ACT', $key)) {
1373 // If this is the first 'active', we must generate ACT.
1374 if ($ACTconf === null) {
1375 $ACTconf = $this->tmpl->splitConfArray($this->mconf['ACT.'], $splitCount);
1376 // Prepare active rollOver settings, overriding normal active settings
1377 if (!empty($this->mconf['ACTRO'])) {
1378 $ACTROconf = $this->tmpl->splitConfArray($this->mconf['ACTRO.'], $splitCount);
1379 }
1380 }
1381 // Substitute normal with active
1382 if (isset($ACTconf[$key])) {
1383 $NOconf[$key] = $ACTconf[$key];
1384 }
1385 // If rollOver on normal, we must apply a state for rollOver on the active
1386 if ($ROconf) {
1387 // If RollOver on active then apply this
1388 $ROconf[$key] = !empty($ACTROconf[$key]) ? $ACTROconf[$key] : $ACTconf[$key];
1389 }
1390 }
1391 }
1392 }
1393 // Prepare ACT (active)/IFSUB settings, overriding normal settings
1394 // ACTIFSUB is TRUE if there exist submenu items to the current item and the current item is active
1395 if (!empty($this->mconf['ACTIFSUB'])) {
1396 $ACTIFSUBconf = null;
1397 $ACTIFSUBROconf = null;
1398 // Find active
1399 foreach ($NOconf as $key => $val) {
1400 if ($this->isItemState('ACTIFSUB', $key)) {
1401 // If this is the first 'active', we must generate ACTIFSUB.
1402 if ($ACTIFSUBconf === null) {
1403 $ACTIFSUBconf = $this->tmpl->splitConfArray($this->mconf['ACTIFSUB.'], $splitCount);
1404 // Prepare active rollOver settings, overriding normal active settings
1405 if (!empty($this->mconf['ACTIFSUBRO'])) {
1406 $ACTIFSUBROconf = $this->tmpl->splitConfArray($this->mconf['ACTIFSUBRO.'], $splitCount);
1407 }
1408 }
1409 // Substitute normal with active
1410 if (isset($ACTIFSUBconf[$key])) {
1411 $NOconf[$key] = $ACTIFSUBconf[$key];
1412 }
1413 // If rollOver on normal, we must apply a state for rollOver on the active
1414 if ($ROconf) {
1415 // If RollOver on active then apply this
1416 $ROconf[$key] = !empty($ACTIFSUBROconf[$key]) ? $ACTIFSUBROconf[$key] : $ACTIFSUBconf[$key];
1417 }
1418 }
1419 }
1420 }
1421 // Prepare CUR (current) settings, overriding normal settings
1422 // CUR is TRUE if the current page equals the item here!
1423 if (!empty($this->mconf['CUR'])) {
1424 $CURconf = null;
1425 $CURROconf = null;
1426 foreach ($NOconf as $key => $val) {
1427 if ($this->isItemState('CUR', $key)) {
1428 // if this is the first 'current', we must generate CUR. Basically this control is just inherited
1429 // from the other implementations as current would only exist one time and that's it
1430 // (unless you use special-features of HMENU)
1431 if ($CURconf === null) {
1432 $CURconf = $this->tmpl->splitConfArray($this->mconf['CUR.'], $splitCount);
1433 if (!empty($this->mconf['CURRO'])) {
1434 $CURROconf = $this->tmpl->splitConfArray($this->mconf['CURRO.'], $splitCount);
1435 }
1436 }
1437 // Substitute normal with current
1438 if (isset($CURconf[$key])) {
1439 $NOconf[$key] = $CURconf[$key];
1440 }
1441 // If rollOver on normal, we must apply a state for rollOver on the active
1442 if ($ROconf) {
1443 // If RollOver on active then apply this
1444 $ROconf[$key] = !empty($CURROconf[$key]) ? $CURROconf[$key] : $CURconf[$key];
1445 }
1446 }
1447 }
1448 }
1449 // Prepare CUR (current)/IFSUB settings, overriding normal settings
1450 // CURIFSUB is TRUE if there exist submenu items to the current item and the current page equals the item here!
1451 if (!empty($this->mconf['CURIFSUB'])) {
1452 $CURIFSUBconf = null;
1453 $CURIFSUBROconf = null;
1454 foreach ($NOconf as $key => $val) {
1455 if ($this->isItemState('CURIFSUB', $key)) {
1456 // If this is the first 'current', we must generate CURIFSUB.
1457 if ($CURIFSUBconf === null) {
1458 $CURIFSUBconf = $this->tmpl->splitConfArray($this->mconf['CURIFSUB.'], $splitCount);
1459 // Prepare current rollOver settings, overriding normal current settings
1460 if (!empty($this->mconf['CURIFSUBRO'])) {
1461 $CURIFSUBROconf = $this->tmpl->splitConfArray($this->mconf['CURIFSUBRO.'], $splitCount);
1462 }
1463 }
1464 // Substitute normal with active
1465 if ($CURIFSUBconf[$key]) {
1466 $NOconf[$key] = $CURIFSUBconf[$key];
1467 }
1468 // If rollOver on normal, we must apply a state for rollOver on the current
1469 if ($ROconf) {
1470 // If RollOver on current then apply this
1471 $ROconf[$key] = !empty($CURIFSUBROconf[$key]) ? $CURIFSUBROconf[$key] : $CURIFSUBconf[$key];
1472 }
1473 }
1474 }
1475 }
1476 // Prepare active settings, overriding normal settings
1477 if (!empty($this->mconf['USR'])) {
1478 $USRconf = null;
1479 $USRROconf = null;
1480 // Find active
1481 foreach ($NOconf as $key => $val) {
1482 if ($this->isItemState('USR', $key)) {
1483 // if this is the first active, we must generate USR.
1484 if ($USRconf === null) {
1485 $USRconf = $this->tmpl->splitConfArray($this->mconf['USR.'], $splitCount);
1486 // Prepare active rollOver settings, overriding normal active settings
1487 if (!empty($this->mconf['USRRO'])) {
1488 $USRROconf = $this->tmpl->splitConfArray($this->mconf['USRRO.'], $splitCount);
1489 }
1490 }
1491 // Substitute normal with active
1492 if ($USRconf[$key]) {
1493 $NOconf[$key] = $USRconf[$key];
1494 }
1495 // If rollOver on normal, we must apply a state for rollOver on the active
1496 if ($ROconf) {
1497 // If RollOver on active then apply this
1498 $ROconf[$key] = !empty($USRROconf[$key]) ? $USRROconf[$key] : $USRconf[$key];
1499 }
1500 }
1501 }
1502 }
1503 // Prepare spacer settings, overriding normal settings
1504 if (!empty($this->mconf['SPC'])) {
1505 $SPCconf = null;
1506 // Find spacers
1507 foreach ($NOconf as $key => $val) {
1508 if ($this->isItemState('SPC', $key)) {
1509 // If this is the first spacer, we must generate SPC.
1510 if ($SPCconf === null) {
1511 $SPCconf = $this->tmpl->splitConfArray($this->mconf['SPC.'], $splitCount);
1512 }
1513 // Substitute normal with spacer
1514 if (isset($SPCconf[$key])) {
1515 $NOconf[$key] = $SPCconf[$key];
1516 }
1517 }
1518 }
1519 }
1520 // Prepare Userdefined settings
1521 if (!empty($this->mconf['USERDEF1'])) {
1522 $USERDEF1conf = null;
1523 $USERDEF1ROconf = null;
1524 // Find active
1525 foreach ($NOconf as $key => $val) {
1526 if ($this->isItemState('USERDEF1', $key)) {
1527 // If this is the first active, we must generate USERDEF1.
1528 if ($USERDEF1conf === null) {
1529 $USERDEF1conf = $this->tmpl->splitConfArray($this->mconf['USERDEF1.'], $splitCount);
1530 // Prepare active rollOver settings, overriding normal active settings
1531 if (!empty($this->mconf['USERDEF1RO'])) {
1532 $USERDEF1ROconf = $this->tmpl->splitConfArray($this->mconf['USERDEF1RO.'], $splitCount);
1533 }
1534 }
1535 // Substitute normal with active
1536 if (isset($USERDEF1conf[$key])) {
1537 $NOconf[$key] = $USERDEF1conf[$key];
1538 }
1539 // If rollOver on normal, we must apply a state for rollOver on the active
1540 if ($ROconf) {
1541 // If RollOver on active then apply this
1542 $ROconf[$key] = !empty($USERDEF1ROconf[$key]) ? $USERDEF1ROconf[$key] : $USERDEF1conf[$key];
1543 }
1544 }
1545 }
1546 }
1547 // Prepare Userdefined settings
1548 if (!empty($this->mconf['USERDEF2'])) {
1549 $USERDEF2conf = null;
1550 $USERDEF2ROconf = null;
1551 // Find active
1552 foreach ($NOconf as $key => $val) {
1553 if ($this->isItemState('USERDEF2', $key)) {
1554 // If this is the first active, we must generate USERDEF2.
1555 if ($USERDEF2conf === null) {
1556 $USERDEF2conf = $this->tmpl->splitConfArray($this->mconf['USERDEF2.'], $splitCount);
1557 // Prepare active rollOver settings, overriding normal active settings
1558 if (!empty($this->mconf['USERDEF2RO'])) {
1559 $USERDEF2ROconf = $this->tmpl->splitConfArray($this->mconf['USERDEF2RO.'], $splitCount);
1560 }
1561 }
1562 // Substitute normal with active
1563 if (isset($USERDEF2conf[$key])) {
1564 $NOconf[$key] = $USERDEF2conf[$key];
1565 }
1566 // If rollOver on normal, we must apply a state for rollOver on the active
1567 if ($ROconf) {
1568 // If RollOver on active then apply this
1569 $ROconf[$key] = !empty($USERDEF2ROconf[$key]) ? $USERDEF2ROconf[$key] : $USERDEF2conf[$key];
1570 }
1571 }
1572 }
1573 }
1574 return [$NOconf, $ROconf];
1575 }
1576
1577 /**
1578 * 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
1579 * This function doesn't care about the url, because if we let the url be redirected, it will be logged in the stat!!!
1580 *
1581 * @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)
1582 * @param string $altTarget Alternative target
1583 * @param string $typeOverride Alternative type
1584 * @return array Returns an array with A-tag attributes as key/value pairs (HREF, TARGET and onClick)
1585 * @internal
1586 */
1587 public function link($key, $altTarget = '', $typeOverride = '')
1588 {
1589 $runtimeCache = $this->getRuntimeCache();
1590 $cacheId = 'menu-generated-links-' . md5($key . $altTarget . $typeOverride . serialize($this->menuArr[$key]));
1591 $runtimeCachedLink = $runtimeCache->get($cacheId);
1592 if ($runtimeCachedLink !== false) {
1593 return $runtimeCachedLink;
1594 }
1595
1596 // Mount points:
1597 $MP_var = $this->getMPvar($key);
1598 $MP_params = $MP_var ? '&MP=' . rawurlencode($MP_var) : '';
1599 // Setting override ID
1600 if ($this->mconf['overrideId'] || $this->menuArr[$key]['overrideId']) {
1601 $overrideArray = [];
1602 // If a user script returned the value overrideId in the menu array we use that as page id
1603 $overrideArray['uid'] = $this->mconf['overrideId'] ?: $this->menuArr[$key]['overrideId'];
1604 $overrideArray['alias'] = '';
1605 // Clear MP parameters since ID was changed.
1606 $MP_params = '';
1607 } else {
1608 $overrideArray = '';
1609 }
1610 // Setting main target:
1611 if ($altTarget) {
1612 $mainTarget = $altTarget;
1613 } elseif ($this->mconf['target.']) {
1614 $mainTarget = $this->parent_cObj->stdWrap($this->mconf['target'], $this->mconf['target.']);
1615 } else {
1616 $mainTarget = $this->mconf['target'];
1617 }
1618 // Creating link:
1619 $addParams = $this->mconf['addParams'] . $MP_params;
1620 if ($this->mconf['collapse'] && $this->isActive($this->menuArr[$key]['uid'], $this->getMPvar($key))) {
1621 $thePage = $this->sys_page->getPage($this->menuArr[$key]['pid']);
1622 $addParams .= $this->menuArr[$key]['_ADD_GETVARS'];
1623 $LD = $this->menuTypoLink($thePage, $mainTarget, '', '', $overrideArray, $addParams, $typeOverride);
1624 } else {
1625 $addParams .= $this->I['val']['additionalParams'] . $this->menuArr[$key]['_ADD_GETVARS'];
1626 $LD = $this->menuTypoLink($this->menuArr[$key], $mainTarget, '', '', $overrideArray, $addParams, $typeOverride);
1627 }
1628 // Override URL if using "External URL"
1629 if ($this->menuArr[$key]['doktype'] == PageRepository::DOKTYPE_LINK) {
1630 if ($this->menuArr[$key]['urltype'] == 3 && GeneralUtility::validEmail($this->menuArr[$key]['url'])) {
1631 // Create mailto-link using \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::typolink (concerning spamProtectEmailAddresses):
1632 $LD['totalURL'] = $this->parent_cObj->typoLink_URL(['parameter' => $this->menuArr[$key]['url']]);
1633 $LD['target'] = '';
1634 } else {
1635 $LD['totalURL'] = $this->parent_cObj->typoLink_URL(['parameter' => $this->getSysPage()->getExtURL($this->menuArr[$key])]);
1636 }
1637 }
1638
1639 $tsfe = $this->getTypoScriptFrontendController();
1640
1641 // Override url if current page is a shortcut
1642 $shortcut = null;
1643 if ($this->menuArr[$key]['doktype'] == PageRepository::DOKTYPE_SHORTCUT && $this->menuArr[$key]['shortcut_mode'] != PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
1644 $menuItem = $this->determineOriginalShortcutPage($this->menuArr[$key]);
1645 try {
1646 $shortcut = $tsfe->getPageShortcut(
1647 $menuItem['shortcut'],
1648 $menuItem['shortcut_mode'],
1649 $menuItem['uid'],
1650 20,
1651 [],
1652 true
1653 );
1654 } catch (\Exception $ex) {
1655 }
1656 if (!is_array($shortcut)) {
1657 $runtimeCache->set($cacheId, []);
1658 return [];
1659 }
1660 // Only setting url, not target
1661 $LD['totalURL'] = $this->parent_cObj->typoLink_URL([
1662 'parameter' => $shortcut['uid'],
1663 'additionalParams' => $addParams . $this->I['val']['additionalParams'] . $menuItem['_ADD_GETVARS'],
1664 'linkAccessRestrictedPages' => !empty($this->mconf['showAccessRestrictedPages'])
1665 ]);
1666 }
1667 if ($shortcut) {
1668 $pageData = $shortcut;
1669 $pageData['_SHORTCUT_PAGE_UID'] = $this->menuArr[$key]['uid'];
1670 } else {
1671 $pageData = $this->menuArr[$key];
1672 }
1673 // Manipulation in case of access restricted pages:
1674 $this->changeLinksForAccessRestrictedPages($LD, $pageData, $mainTarget, $typeOverride);
1675 // Overriding URL / Target if set to do so:
1676 if ($this->menuArr[$key]['_OVERRIDE_HREF']) {
1677 $LD['totalURL'] = $this->menuArr[$key]['_OVERRIDE_HREF'];
1678 if ($this->menuArr[$key]['_OVERRIDE_TARGET']) {
1679 $LD['target'] = $this->menuArr[$key]['_OVERRIDE_TARGET'];
1680 }
1681 }
1682 // OnClick open in windows.
1683 $onClick = '';
1684 if ($this->mconf['JSWindow']) {
1685 $conf = $this->mconf['JSWindow.'];
1686 $url = $LD['totalURL'];
1687 $LD['totalURL'] = '#';
1688 $onClick = 'openPic('
1689 . GeneralUtility::quoteJSvalue($tsfe->baseUrlWrap($url)) . ','
1690 . '\'' . ($conf['newWindow'] ? md5($url) : 'theNewPage') . '\','
1691 . GeneralUtility::quoteJSvalue($conf['params']) . '); return false;';
1692 $tsfe->setJS('openPic');
1693 }
1694 // look for type and popup
1695 // following settings are valid in field target:
1696 // 230 will add type=230 to the link
1697 // 230 500x600 will add type=230 to the link and open in popup window with 500x600 pixels
1698 // 230 _blank will add type=230 to the link and open with target "_blank"
1699 // 230x450:resizable=0,location=1 will open in popup window with 500x600 pixels with settings "resizable=0,location=1"
1700 $matches = [];
1701 $targetIsType = $LD['target'] && MathUtility::canBeInterpretedAsInteger($LD['target']) ? (int)$LD['target'] : false;
1702 if (preg_match('/([0-9]+[\\s])?(([0-9]+)x([0-9]+))?(:.+)?/s', $LD['target'], $matches) || $targetIsType) {
1703 // has type?
1704 if ((int)$matches[1] || $targetIsType) {
1705 $LD['totalURL'] = $this->parent_cObj->URLqMark($LD['totalURL'], '&type=' . ($targetIsType ?: (int)$matches[1]));
1706 $LD['target'] = $targetIsType ? '' : trim(substr($LD['target'], strlen($matches[1]) + 1));
1707 }
1708 // Open in popup window?
1709 if ($matches[3] && $matches[4]) {
1710 $JSparamWH = 'width=' . $matches[3] . ',height=' . $matches[4] . ($matches[5] ? ',' . substr($matches[5], 1) : '');
1711 $onClick = 'vHWin=window.open('
1712 . GeneralUtility::quoteJSvalue($tsfe->baseUrlWrap($LD['totalURL']))
1713 . ',\'FEopenLink\',' . GeneralUtility::quoteJSvalue($JSparamWH) . ');vHWin.focus();return false;';
1714 $LD['target'] = '';
1715 }
1716 }
1717 // out:
1718 $list = [];
1719 // Added this check: What it does is to enter the baseUrl (if set, which it should for "realurl" based sites)
1720 // as URL if the calculated value is empty. The problem is that no link is generated with a blank URL
1721 // and blank URLs might appear when the realurl encoding is used and a link to the frontpage is generated.
1722 $list['HREF'] = (string)$LD['totalURL'] !== '' ? $LD['totalURL'] : $tsfe->baseUrl;
1723 $list['TARGET'] = $LD['target'];
1724 $list['onClick'] = $onClick;
1725 $runtimeCache->set($cacheId, $list);
1726 return $list;
1727 }
1728
1729 /**
1730 * Determines original shortcut destination in page overlays.
1731 *
1732 * Since the pages records used for menu rendering are overlaid by default,
1733 * the original 'shortcut' value is lost, if a translation did not define one.
1734 *
1735 * @param array $page
1736 * @return array
1737 */
1738 protected function determineOriginalShortcutPage(array $page)
1739 {
1740 // Check if modification is required
1741 if (
1742 $this->getTypoScriptFrontendController()->sys_language_uid > 0
1743 && empty($page['shortcut'])
1744 && !empty($page['uid'])
1745 && !empty($page['_PAGES_OVERLAY'])
1746 && !empty($page['_PAGES_OVERLAY_UID'])
1747 ) {
1748 // Using raw record since the record was overlaid and is correct already:
1749 $originalPage = $this->sys_page->getRawRecord('pages', $page['uid']);
1750
1751 if ($originalPage['shortcut_mode'] === $page['shortcut_mode'] && !empty($originalPage['shortcut'])) {
1752 $page['shortcut'] = $originalPage['shortcut'];
1753 }
1754 }
1755
1756 return $page;
1757 }
1758
1759 /**
1760 * Will change $LD (passed by reference) if the page is access restricted
1761 *
1762 * @param array $LD The array from the linkData() function
1763 * @param array $page Page array
1764 * @param string $mainTarget Main target value
1765 * @param string $typeOverride Type number override if any
1766 * @return void ($LD passed by reference might be changed.)
1767 */
1768 public function changeLinksForAccessRestrictedPages(&$LD, $page, $mainTarget, $typeOverride)
1769 {
1770 // If access restricted pages should be shown in menus, change the link of such pages to link to a redirection page:
1771 if ($this->mconf['showAccessRestrictedPages'] && $this->mconf['showAccessRestrictedPages'] !== 'NONE' && !$this->getTypoScriptFrontendController()->checkPageGroupAccess($page)) {
1772 $thePage = $this->sys_page->getPage($this->mconf['showAccessRestrictedPages']);
1773 $addParams = str_replace(
1774 [
1775 '###RETURN_URL###',
1776 '###PAGE_ID###'
1777 ],
1778 [
1779 rawurlencode($LD['totalURL']),
1780 isset($page['_SHORTCUT_PAGE_UID']) ? $page['_SHORTCUT_PAGE_UID'] : $page['uid']
1781 ],
1782 $this->mconf['showAccessRestrictedPages.']['addParams']
1783 );
1784 $LD = $this->menuTypoLink($thePage, $mainTarget, '', '', '', $addParams, $typeOverride);
1785 }
1786 }
1787
1788 /**
1789 * Creates a submenu level to the current level - if configured for.
1790 *
1791 * @param int $uid Page id of the current page for which a submenu MAY be produced (if conditions are met)
1792 * @param string $objSuffix Object prefix, see ->start()
1793 * @return string HTML content of the submenu
1794 * @internal
1795 */
1796 public function subMenu($uid, $objSuffix = '')
1797 {
1798 // Setting alternative menu item array if _SUB_MENU has been defined in the current ->menuArr
1799 $altArray = '';
1800 if (is_array($this->menuArr[$this->I['key']]['_SUB_MENU']) && !empty($this->menuArr[$this->I['key']]['_SUB_MENU'])) {
1801 $altArray = $this->menuArr[$this->I['key']]['_SUB_MENU'];
1802 }
1803 // Make submenu if the page is the next active
1804 $menuType = $this->conf[($this->menuNumber + 1) . $objSuffix];
1805 // stdWrap for expAll
1806 if (isset($this->mconf['expAll.'])) {
1807 $this->mconf['expAll'] = $this->parent_cObj->stdWrap($this->mconf['expAll'], $this->mconf['expAll.']);
1808 }
1809 if (($this->mconf['expAll'] || $this->isNext($uid, $this->getMPvar($this->I['key'])) || is_array($altArray)) && !$this->mconf['sectionIndex']) {
1810 try {
1811 $menuObjectFactory = GeneralUtility::makeInstance(MenuContentObjectFactory::class);
1812 /** @var $submenu AbstractMenuContentObject */
1813 $submenu = $menuObjectFactory->getMenuObjectByType($menuType);
1814 $submenu->entryLevel = $this->entryLevel + 1;
1815 $submenu->rL_uidRegister = $this->rL_uidRegister;
1816 $submenu->MP_array = $this->MP_array;
1817 if ($this->menuArr[$this->I['key']]['_MP_PARAM']) {
1818 $submenu->MP_array[] = $this->menuArr[$this->I['key']]['_MP_PARAM'];
1819 }
1820 // Especially scripts that build the submenu needs the parent data
1821 $submenu->parent_cObj = $this->parent_cObj;
1822 $submenu->setParentMenu($this->menuArr, $this->I['key']);
1823 // Setting alternativeMenuTempArray (will be effective only if an array)
1824 if (is_array($altArray)) {
1825 $submenu->alternativeMenuTempArray = $altArray;
1826 }
1827 if ($submenu->start($this->tmpl, $this->sys_page, $uid, $this->conf, $this->menuNumber + 1, $objSuffix)) {
1828 $submenu->makeMenu();
1829 // Memorize the current menu item count
1830 $tsfe = $this->getTypoScriptFrontendController();
1831 $tempCountMenuObj = $tsfe->register['count_MENUOBJ'];
1832 // Reset the menu item count for the submenu
1833 $tsfe->register['count_MENUOBJ'] = 0;
1834 $content = $submenu->writeMenu();
1835 // Restore the item count now that the submenu has been handled
1836 $tsfe->register['count_MENUOBJ'] = $tempCountMenuObj;
1837 $tsfe->register['count_menuItems'] = count($this->menuArr);
1838 return $content;
1839 }
1840 } catch (Exception\NoSuchMenuTypeException $e) {
1841 }
1842 }
1843 return '';
1844 }
1845
1846 /**
1847 * Returns TRUE if the page with UID $uid is the NEXT page in root line (which means a submenu should be drawn)
1848 *
1849 * @param int $uid Page uid to evaluate.
1850 * @param string $MPvar MPvar for the current position of item.
1851 * @return bool TRUE if page with $uid is active
1852 * @internal
1853 * @see subMenu()
1854 */
1855 public function isNext($uid, $MPvar = '')
1856 {
1857 // Check for always active PIDs:
1858 if (!empty($this->alwaysActivePIDlist) && in_array((int)$uid, $this->alwaysActivePIDlist, true)) {
1859 return true;
1860 }
1861 $testUid = $uid . ($MPvar ? ':' . $MPvar : '');
1862 if ($uid && $testUid == $this->nextActive) {
1863 return true;
1864 }
1865 return false;
1866 }
1867
1868 /**
1869 * Returns TRUE if the page with UID $uid is active (in the current rootline)
1870 *
1871 * @param int $uid Page uid to evaluate.
1872 * @param string $MPvar MPvar for the current position of item.
1873 * @return bool TRUE if page with $uid is active
1874 * @internal
1875 */
1876 public function isActive($uid, $MPvar = '')
1877 {
1878 // Check for always active PIDs:
1879 if (!empty($this->alwaysActivePIDlist) && in_array((int)$uid, $this->alwaysActivePIDlist, true)) {
1880 return true;
1881 }
1882 $testUid = $uid . ($MPvar ? ':' . $MPvar : '');
1883 if ($uid && in_array('ITEM:' . $testUid, $this->rL_uidRegister, true)) {
1884 return true;
1885 }
1886 return false;
1887 }
1888
1889 /**
1890 * Returns TRUE if the page with UID $uid is the CURRENT page (equals $this->getTypoScriptFrontendController()->id)
1891 *
1892 * @param int $uid Page uid to evaluate.
1893 * @param string $MPvar MPvar for the current position of item.
1894 * @return bool TRUE if page $uid = $this->getTypoScriptFrontendController()->id
1895 * @internal
1896 */
1897 public function isCurrent($uid, $MPvar = '')
1898 {
1899 $testUid = $uid . ($MPvar ? ':' . $MPvar : '');
1900 return $uid && end($this->rL_uidRegister) === 'ITEM:' . $testUid;
1901 }
1902
1903 /**
1904 * Returns TRUE if there is a submenu with items for the page id, $uid
1905 * Used by the item states "IFSUB", "ACTIFSUB" and "CURIFSUB" to check if there is a submenu
1906 *
1907 * @param int $uid Page uid for which to search for a submenu
1908 * @return bool Returns TRUE if there was a submenu with items found
1909 * @internal
1910 */
1911 public function isSubMenu($uid)
1912 {
1913 $cacheId = 'menucontentobject-is-submenu-decision-' . $uid;
1914 $runtimeCache = $this->getRuntimeCache();
1915 $cachedDecision = $runtimeCache->get($cacheId);
1916 if (isset($cachedDecision['result'])) {
1917 return $cachedDecision['result'];
1918 }
1919 // Looking for a mount-pid for this UID since if that
1920 // exists we should look for a subpages THERE and not in the input $uid;
1921 $mount_info = $this->sys_page->getMountPointInfo($uid);
1922 if (is_array($mount_info)) {
1923 $uid = $mount_info['mount_pid'];
1924 }
1925 $recs = $this->sys_page->getMenu($uid, 'uid,pid,doktype,mount_pid,mount_pid_ol,nav_hide,shortcut,shortcut_mode,l18n_cfg');
1926 $hasSubPages = false;
1927 $bannedUids = $this->getBannedUids();
1928 foreach ($recs as $theRec) {
1929 // no valid subpage if the document type is excluded from the menu
1930 if (GeneralUtility::inList($this->doktypeExcludeList, $theRec['doktype'])) {
1931 continue;
1932 }
1933 // No valid subpage if the page is hidden inside menus and
1934 // it wasn't forced to show such entries
1935 if ($theRec['nav_hide'] && !$this->conf['includeNotInMenu']) {
1936 continue;
1937 }
1938 // No valid subpage if the default language should be shown and the page settings
1939 // are excluding the visibility of the default language
1940 if (!$this->getTypoScriptFrontendController()->sys_language_uid && GeneralUtility::hideIfDefaultLanguage($theRec['l18n_cfg'])) {
1941 continue;
1942 }
1943 // No valid subpage if the alternative language should be shown and the page settings
1944 // are requiring a valid overlay but it doesn't exists
1945 $hideIfNotTranslated = GeneralUtility::hideIfNotTranslated($theRec['l18n_cfg']);
1946 if ($this->getTypoScriptFrontendController()->sys_language_uid && $hideIfNotTranslated && !$theRec['_PAGES_OVERLAY']) {
1947 continue;
1948 }
1949 // No valid subpage if the subpage is banned by excludeUidList
1950 if (in_array($theRec['uid'], $bannedUids)) {
1951 continue;
1952 }
1953 $hasSubPages = true;
1954 break;
1955 }
1956 $runtimeCache->set($cacheId, ['result' => $hasSubPages]);
1957 return $hasSubPages;
1958 }
1959
1960 /**
1961 * Used by procesItemStates() to evaluate if a menu item (identified by $key) is in a certain state.
1962 *
1963 * @param string $kind The item state to evaluate (SPC, IFSUB, ACT etc... but no xxxRO states of course)
1964 * @param int $key Key pointing to menu item from ->menuArr
1965 * @return bool Returns TRUE if state matches
1966 * @internal
1967 * @see procesItemStates()
1968 */
1969 public function isItemState($kind, $key)
1970 {
1971 $natVal = false;
1972 // If any value is set for ITEM_STATE the normal evaluation is discarded
1973 if ($this->menuArr[$key]['ITEM_STATE']) {
1974 if ((string)$this->menuArr[$key]['ITEM_STATE'] === (string)$kind) {
1975 $natVal = true;
1976 }
1977 } else {
1978 switch ($kind) {
1979 case 'SPC':
1980 $natVal = (bool)$this->menuArr[$key]['isSpacer'];
1981 break;
1982 case 'IFSUB':
1983 $natVal = $this->isSubMenu($this->menuArr[$key]['uid']);
1984 break;
1985 case 'ACT':
1986 $natVal = $this->isActive($this->menuArr[$key]['uid'], $this->getMPvar($key));
1987 break;
1988 case 'ACTIFSUB':
1989 $natVal = $this->isActive($this->menuArr[$key]['uid'], $this->getMPvar($key)) && $this->isSubMenu($this->menuArr[$key]['uid']);
1990 break;
1991 case 'CUR':
1992 $natVal = $this->isCurrent($this->menuArr[$key]['uid'], $this->getMPvar($key));
1993 break;
1994 case 'CURIFSUB':
1995 $natVal = $this->isCurrent($this->menuArr[$key]['uid'], $this->getMPvar($key)) && $this->isSubMenu($this->menuArr[$key]['uid']);
1996 break;
1997 case 'USR':
1998 $natVal = (bool)$this->menuArr[$key]['fe_group'];
1999 break;
2000 }
2001 }
2002 return $natVal;
2003 }
2004
2005 /**
2006 * Creates an access-key for a TMENU/GMENU menu item based on the menu item titles first letter
2007 *
2008 * @param string $title Menu item title.
2009 * @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
2010 * @internal
2011 */
2012 public function accessKey($title)
2013 {
2014 $tsfe = $this->getTypoScriptFrontendController();
2015 // The global array ACCESSKEY is used to globally control if letters are already used!!
2016 $result = [];
2017 $title = trim(strip_tags($title));
2018 $titleLen = strlen($title);
2019 for ($a = 0; $a < $titleLen; $a++) {
2020 $key = strtoupper(substr($title, $a, 1));
2021 if (preg_match('/[A-Z]/', $key) && !isset($tsfe->accessKey[$key])) {
2022 $tsfe->accessKey[$key] = 1;
2023 $result['code'] = ' accesskey="' . $key . '"';
2024 $result['alt'] = ' (ALT+' . $key . ')';
2025 $result['key'] = $key;
2026 break;
2027 }
2028 }
2029 return $result;
2030 }
2031
2032 /**
2033 * Calls a user function for processing of internal data.
2034 * Used for the properties "IProcFunc" and "itemArrayProcFunc"
2035 *
2036 * @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".
2037 * @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
2038 * @return mixed The processed $passVar
2039 * @internal
2040 */
2041 public function userProcess($mConfKey, $passVar)
2042 {
2043 if ($this->mconf[$mConfKey]) {
2044 $funcConf = $this->mconf[$mConfKey . '.'];
2045 $funcConf['parentObj'] = $this;
2046 $passVar = $this->parent_cObj->callUserFunction($this->mconf[$mConfKey], $funcConf, $passVar);
2047 }
2048 return $passVar;
2049 }
2050
2051 /**
2052 * 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'])
2053 *
2054 * @return void
2055 * @internal
2056 */
2057 public function setATagParts()
2058 {
2059 $params = trim($this->I['val']['ATagParams']) . $this->I['accessKey']['code'];
2060 $params = $params !== '' ? ' ' . $params : '';
2061 $this->I['A1'] = '<a ' . GeneralUtility::implodeAttributes($this->I['linkHREF'], 1) . $params . '>';
2062 $this->I['A2'] = '</a>';
2063 }
2064
2065 /**
2066 * Returns the title for the navigation
2067 *
2068 * @param string $title The current page title
2069 * @param string $nav_title The current value of the navigation title
2070 * @return string Returns the navigation title if it is NOT blank, otherwise the page title.
2071 * @internal
2072 */
2073 public function getPageTitle($title, $nav_title)
2074 {
2075 return trim($nav_title) !== '' ? $nav_title : $title;
2076 }
2077
2078 /**
2079 * Return MPvar string for entry $key in ->menuArr
2080 *
2081 * @param int $key Pointer to element in ->menuArr
2082 * @return string MP vars for element.
2083 * @see link()
2084 */
2085 public function getMPvar($key)
2086 {
2087 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids']) {
2088 $localMP_array = $this->MP_array;
2089 // NOTICE: "_MP_PARAM" is allowed to be a commalist of PID pairs!
2090 if ($this->menuArr[$key]['_MP_PARAM']) {
2091 $localMP_array[] = $this->menuArr[$key]['_MP_PARAM'];
2092 }
2093 return !empty($localMP_array) ? implode(',', $localMP_array) : '';
2094 }
2095 return '';
2096 }
2097
2098 /**
2099 * Returns where clause part to exclude 'not in menu' pages
2100 *
2101 * @return string where clause part.
2102 * @internal
2103 */
2104 public function getDoktypeExcludeWhere()
2105 {
2106 return $this->doktypeExcludeList ? ' AND pages.doktype NOT IN (' . $this->doktypeExcludeList . ')' : '';
2107 }
2108
2109 /**
2110 * Returns an array of banned UIDs (from excludeUidList)
2111 *
2112 * @return array Array of banned UIDs
2113 * @internal
2114 */
2115 public function getBannedUids()
2116 {
2117 $excludeUidList = isset($this->conf['excludeUidList.'])
2118 ? $this->parent_cObj->stdWrap($this->conf['excludeUidList'], $this->conf['excludeUidList.'])
2119 : $this->conf['excludeUidList'];
2120
2121 if (!trim($excludeUidList)) {
2122 return [];
2123 }
2124
2125 $banUidList = str_replace('current', $this->getTypoScriptFrontendController()->page['uid'], $excludeUidList);
2126 return GeneralUtility::intExplode(',', $banUidList);
2127 }
2128
2129 /**
2130 * Calls typolink to create menu item links.
2131 *
2132 * @param array $page Page record (uid points where to link to)
2133 * @param string $oTarget Target frame/window
2134 * @param bool $no_cache TRUE if caching should be disabled
2135 * @param string $script Alternative script name (unused)
2136 * @param array|string $overrideArray Array to override values in $page, empty string to skip override
2137 * @param string $addParams Parameters to add to URL
2138 * @param int|string $typeOverride "type" value, empty string means "not set"
2139 * @return array See linkData
2140 */
2141 public function menuTypoLink($page, $oTarget, $no_cache, $script, $overrideArray = '', $addParams = '', $typeOverride = '')
2142 {
2143 $conf = [
2144 'parameter' => is_array($overrideArray) && $overrideArray['uid'] ? $overrideArray['uid'] : $page['uid']
2145 ];
2146 if (MathUtility::canBeInterpretedAsInteger($typeOverride)) {
2147 $conf['parameter'] .= ',' . (int)$typeOverride;
2148 }
2149 if ($addParams) {
2150 $conf['additionalParams'] = $addParams;
2151 }
2152 if ($no_cache) {
2153 $conf['no_cache'] = true;
2154 } elseif ($this->useCacheHash) {
2155 $conf['useCacheHash'] = true;
2156 }
2157 if ($oTarget) {
2158 $conf['target'] = $oTarget;
2159 }
2160 if ($page['sectionIndex_uid']) {
2161 $conf['section'] = $page['sectionIndex_uid'];
2162 }
2163 $conf['linkAccessRestrictedPages'] = !empty($this->mconf['showAccessRestrictedPages']);
2164 $this->parent_cObj->typoLink('|', $conf);
2165 $LD = $this->parent_cObj->lastTypoLinkLD;
2166 $LD['totalURL'] = $this->parent_cObj->lastTypoLinkUrl;
2167 return $LD;
2168 }
2169
2170 /**
2171 * Generates a list of content objects with sectionIndex enabled
2172 * available on a specific page
2173 *
2174 * Used for menus with sectionIndex enabled
2175 *
2176 * @param string $altSortField Alternative sorting field
2177 * @param int $pid The page id to search for sections
2178 * @throws \UnexpectedValueException if the query to fetch the content elements unexpectedly fails
2179 * @return array
2180 */
2181 protected function sectionIndex($altSortField, $pid = null)
2182 {
2183 $pid = (int)($pid ?: $this->id);
2184 $basePageRow = $this->sys_page->getPage($pid);
2185 if (!is_array($basePageRow)) {
2186 return [];
2187 }
2188 $tsfe = $this->getTypoScriptFrontendController();
2189 $configuration = $this->mconf['sectionIndex.'];
2190 $useColPos = 0;
2191 if (trim($configuration['useColPos']) !== '' || is_array($configuration['useColPos.'])) {
2192 $useColPos = $tsfe->cObj->stdWrap($configuration['useColPos'], $configuration['useColPos.']);
2193 $useColPos = (int)$useColPos;
2194 }
2195 $selectSetup = [
2196 'pidInList' => $pid,
2197 'orderBy' => $altSortField,
2198 'languageField' => 'sys_language_uid',
2199 'where' => $useColPos >= 0 ? 'colPos=' . $useColPos : ''
2200 ];
2201 if ($basePageRow['content_from_pid']) {
2202 // If the page is configured to show content from a referenced page the sectionIndex contains only contents of
2203 // the referenced page
2204 $selectSetup['pidInList'] = $basePageRow['content_from_pid'];
2205 }
2206 $statement = $this->parent_cObj->exec_getQuery('tt_content', $selectSetup);
2207 if (!$statement) {
2208 $message = 'SectionIndex: Query to fetch the content elements failed!';
2209 throw new \UnexpectedValueException($message, 1337334849);
2210 }
2211 $result = [];
2212 while ($row = $statement->fetch()) {
2213 $this->sys_page->versionOL('tt_content', $row);
2214 if ($tsfe->sys_language_contentOL && $basePageRow['_PAGES_OVERLAY_LANGUAGE']) {
2215 $row = $this->sys_page->getRecordOverlay('tt_content', $row, $basePageRow['_PAGES_OVERLAY_LANGUAGE'], $tsfe->sys_language_contentOL);
2216 }
2217 if ($this->mconf['sectionIndex.']['type'] !== 'all') {
2218 $doIncludeInSectionIndex = $row['sectionIndex'] >= 1;
2219 $doHeaderCheck = $this->mconf['sectionIndex.']['type'] === 'header';
2220 $isValidHeader = ((int)$row['header_layout'] !== 100 || !empty($this->mconf['sectionIndex.']['includeHiddenHeaders'])) && trim($row['header']) !== '';
2221 if (!$doIncludeInSectionIndex || $doHeaderCheck && !$isValidHeader) {
2222 continue;
2223 }
2224 }
2225 if (is_array($row)) {
2226 $uid = $row['uid'];
2227 $result[$uid] = $basePageRow;
2228 $result[$uid]['title'] = $row['header'];
2229 $result[$uid]['nav_title'] = $row['header'];
2230 // Prevent false exclusion in filterMenuPages, thus: Always show tt_content records
2231 $result[$uid]['nav_hide'] = 0;
2232 $result[$uid]['subtitle'] = $row['subheader'];
2233 $result[$uid]['starttime'] = $row['starttime'];
2234 $result[$uid]['endtime'] = $row['endtime'];
2235 $result[$uid]['fe_group'] = $row['fe_group'];
2236 $result[$uid]['media'] = $row['media'];
2237 $result[$uid]['header_layout'] = $row['header_layout'];
2238 $result[$uid]['bodytext'] = $row['bodytext'];
2239 $result[$uid]['image'] = $row['image'];
2240 $result[$uid]['sectionIndex_uid'] = $uid;
2241 }
2242 }
2243
2244 return $result;
2245 }
2246
2247 /**
2248 * Returns the sys_page object
2249 *
2250 * @return \TYPO3\CMS\Frontend\Page\PageRepository
2251 */
2252 public function getSysPage()
2253 {
2254 return $this->sys_page;
2255 }
2256
2257 /**
2258 * Returns the parent content object
2259 *
2260 * @return \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
2261 */
2262 public function getParentContentObject()
2263 {
2264 return $this->parent_cObj;
2265 }
2266
2267 /**
2268 * @return TypoScriptFrontendController
2269 */
2270 protected function getTypoScriptFrontendController()
2271 {
2272 return $GLOBALS['TSFE'];
2273 }
2274
2275 /**
2276 * @return TimeTracker
2277 */
2278 protected function getTimeTracker()
2279 {
2280 return GeneralUtility::makeInstance(TimeTracker::class);
2281 }
2282
2283 /**
2284 * @return \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
2285 */
2286 protected function getCache()
2287 {
2288 return GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_hash');
2289 }
2290
2291 /**
2292 * @return \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
2293 */
2294 protected function getRuntimeCache()
2295 {
2296 return GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
2297 }
2298
2299 /**
2300 * Set the parentMenuArr and key to provide the parentMenu informations to the
2301 * subMenu, special fur IProcFunc and itemArrayProcFunc user functions.
2302 *
2303 * @internal
2304 *
2305 * @param array $menuArr
2306 * @param int $menuItemKey
2307 */
2308 public function setParentMenu(array $menuArr = [], $menuItemKey)
2309 {
2310 // check if menuArr is a valid array and that menuItemKey matches an existing menuItem in menuArr
2311 if (is_array($menuArr)
2312 && (is_int($menuItemKey) && $menuItemKey >= 0 && isset($menuArr[$menuItemKey]))
2313 ) {
2314 $this->parentMenuArr = $menuArr;
2315 $this->parentMenuArrItemKey = $menuItemKey;
2316 }
2317 }
2318
2319 /**
2320 * Check if there is an valid parentMenuArr.
2321 *
2322 * @return bool
2323 */
2324 protected function hasParentMenuArr()
2325 {
2326 return
2327 $this->menuNumber > 1
2328 && is_array($this->parentMenuArr)
2329 && !empty($this->parentMenuArr)
2330 ;
2331 }
2332
2333 /**
2334 * Check if we have an parentMenutArrItemKey
2335 */
2336 protected function hasParentMenuItemKey()
2337 {
2338 return null !== $this->parentMenuArrItemKey;
2339 }
2340
2341 /**
2342 * Check if the the parentMenuItem exists
2343 */
2344 protected function hasParentMenuItem()
2345 {
2346 return
2347 $this->hasParentMenuArr()
2348 && $this->hasParentMenuItemKey()
2349 && isset($this->getParentMenuArr()[$this->parentMenuArrItemKey])
2350 ;
2351 }
2352
2353 /**
2354 * Get the parentMenuArr, if this is subMenu.
2355 *
2356 * @return array
2357 */
2358 public function getParentMenuArr()
2359 {
2360 return $this->hasParentMenuArr() ? $this->parentMenuArr : [];
2361 }
2362
2363 /**
2364 * Get the parentMenuItem from the parentMenuArr, if this is a subMenu
2365 *
2366 * @return null|array
2367 */
2368 public function getParentMenuItem()
2369 {
2370 // check if we have an parentMenuItem and if it is an array
2371 if ($this->hasParentMenuItem()
2372 && is_array($this->getParentMenuArr()[$this->parentMenuArrItemKey])
2373 ) {
2374 return $this->getParentMenuArr()[$this->parentMenuArrItemKey];
2375 }
2376
2377 return null;
2378 }
2379 }