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