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