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