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