-
Notifications
You must be signed in to change notification settings - Fork 639
/
AbstractMenuContentObject.php
2383 lines (2272 loc) · 101 KB
/
AbstractMenuContentObject.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
namespace TYPO3\CMS\Frontend\ContentObject\Menu;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\RelationHandler;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
use TYPO3\CMS\Frontend\Page\PageRepository;
use TYPO3\CMS\Frontend\Typolink\PageLinkBuilder;
/**
* Generating navigation/menus from TypoScript
*
* The HMENU content object uses this (or more precisely one of the extension classes).
* Among others the class generates an array of menu items. Thereafter functions from the subclasses are called.
* The class is always used through extension classes (like GraphicalMenuContentObject or TextMenuContentObject).
*/
abstract class AbstractMenuContentObject
{
/**
* tells you which menu number this is. This is important when getting data from the setup
*
* @var int
*/
public $menuNumber = 1;
/**
* 0 = rootFolder
*
* @var int
*/
public $entryLevel = 0;
/**
* The doktype-number that defines a spacer
*
* @var string
*/
public $spacerIDList = '199';
/**
* Doktypes that define which should not be included in a menu
*
* @var string
*/
public $doktypeExcludeList = '6';
/**
* @var int[]
*/
public $alwaysActivePIDlist = [];
/**
* @var string
*/
public $imgNamePrefix = 'img';
/**
* @var int
*/
public $imgNameNotRandom = 0;
/**
* @var bool
*/
public $debug = false;
/**
* Loaded with the parent cObj-object when a new HMENU is made
*
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
*/
public $parent_cObj = null;
/**
* @var string
*/
public $GMENU_fixKey = 'gmenu';
/**
* accumulation of mount point data
*
* @var string[]
*/
public $MP_array = [];
/**
* HMENU configuration
*
* @var array
*/
public $conf = [];
/**
* xMENU configuration (TMENU, GMENU etc)
*
* @var array
*/
public $mconf = [];
/**
* @var \TYPO3\CMS\Core\TypoScript\TemplateService
*/
public $tmpl = null;
/**
* @var \TYPO3\CMS\Frontend\Page\PageRepository
*/
public $sys_page = null;
/**
* The base page-id of the menu.
*
* @var int
*/
public $id;
/**
* Holds the page uid of the NEXT page in the root line from the page pointed to by entryLevel;
* Used to expand the menu automatically if in a certain root line.
*
* @var string
*/
public $nextActive;
/**
* The array of menuItems which is built
*
* @var array[]
*/
public $menuArr;
/**
* @var string
*/
public $hash;
/**
* @var array
*/
public $result = [];
/**
* Is filled with an array of page uid numbers + RL parameters which are in the current
* root line (used to evaluate whether a menu item is in active state)
*
* @var array
*/
public $rL_uidRegister;
/**
* @var string
*/
public $INPfixMD5;
/**
* @var mixed[]
*/
public $I;
/**
* @var string
*/
public $WMresult;
/**
* @var string
*/
public $WMfreezePrefix;
/**
* @var int
*/
public $WMmenuItems;
/**
* @var array[]
*/
public $WMsubmenuObjSuffixes;
/**
* @var string
*/
public $WMextraScript;
/**
* @var ContentObjectRenderer
*/
public $WMcObj = null;
/**
* Can be set to contain menu item arrays for sub-levels.
*
* @var string
*/
public $alternativeMenuTempArray = '';
/**
* Will be 'id' in XHTML-mode
*
* @var string
*/
public $nameAttribute = 'name';
/**
* TRUE to use cHash in generated link (normally only for the language
* selector and if parameters exist in the URL).
*
* @var bool
*/
protected $useCacheHash = false;
/**
* Array key of the parentMenuItem in the parentMenuArr, if this menu is a subMenu.
*
* @var int|null
*/
protected $parentMenuArrItemKey;
/**
* The initialization of the object. This just sets some internal variables.
*
* @param TemplateService $tmpl The $this->getTypoScriptFrontendController()->tmpl object
* @param PageRepository $sys_page The $this->getTypoScriptFrontendController()->sys_page object
* @param int|string $id A starting point page id. This should probably be blank since the 'entryLevel' value will be used then.
* @param array $conf The TypoScript configuration for the HMENU cObject
* @param int $menuNumber Menu number; 1,2,3. Should probably be 1
* @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")
* @return bool Returns TRUE on success
* @see \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::HMENU()
*/
public function start($tmpl, $sys_page, $id, $conf, $menuNumber, $objSuffix = '')
{
$tsfe = $this->getTypoScriptFrontendController();
// Init:
$this->conf = $conf;
$this->menuNumber = $menuNumber;
$this->mconf = $conf[$this->menuNumber . $objSuffix . '.'];
$this->debug = $tsfe->debug;
$this->WMcObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
// In XHTML and HTML5 there is no "name" attribute anymore
switch ($tsfe->xhtmlDoctype) {
case 'xhtml_strict':
// intended fall-through
case 'xhtml_11':
// intended fall-through
case 'html5':
// intended fall-through
case '':
// empty means that it's HTML5 by default
$this->nameAttribute = 'id';
break;
default:
$this->nameAttribute = 'name';
}
// Sets the internal vars. $tmpl MUST be the template-object. $sys_page MUST be the sys_page object
if ($this->conf[$this->menuNumber . $objSuffix] && is_object($tmpl) && is_object($sys_page)) {
$this->tmpl = $tmpl;
$this->sys_page = $sys_page;
// alwaysActivePIDlist initialized:
if (trim($this->conf['alwaysActivePIDlist']) || isset($this->conf['alwaysActivePIDlist.'])) {
if (isset($this->conf['alwaysActivePIDlist.'])) {
$this->conf['alwaysActivePIDlist'] = $this->parent_cObj->stdWrap(
$this->conf['alwaysActivePIDlist'],
$this->conf['alwaysActivePIDlist.']
);
}
$this->alwaysActivePIDlist = GeneralUtility::intExplode(',', $this->conf['alwaysActivePIDlist']);
}
// 'not in menu' doktypes
if ($this->conf['excludeDoktypes']) {
$this->doktypeExcludeList = implode(',', GeneralUtility::intExplode(',', $this->conf['excludeDoktypes']));
}
// EntryLevel
$this->entryLevel = $this->parent_cObj->getKey(
isset($conf['entryLevel.']) ? $this->parent_cObj->stdWrap(
$conf['entryLevel'],
$conf['entryLevel.']
) : $conf['entryLevel'],
$this->tmpl->rootLine
);
// Set parent page: If $id not stated with start() then the base-id will be found from rootLine[$this->entryLevel]
// Called as the next level in a menu. It is assumed that $this->MP_array is set from parent menu.
if ($id) {
$this->id = (int)$id;
} else {
// This is a BRAND NEW menu, first level. So we take ID from rootline and also find MP_array (mount points)
$this->id = (int)$this->tmpl->rootLine[$this->entryLevel]['uid'];
// Traverse rootline to build MP_array of pages BEFORE the entryLevel
// (MP var for ->id is picked up in the next part of the code...)
foreach ($this->tmpl->rootLine as $entryLevel => $levelRec) {
// For overlaid mount points, set the variable right now:
if ($levelRec['_MP_PARAM'] && $levelRec['_MOUNT_OL']) {
$this->MP_array[] = $levelRec['_MP_PARAM'];
}
// Break when entry level is reached:
if ($entryLevel >= $this->entryLevel) {
break;
}
// For normal mount points, set the variable for next level.
if ($levelRec['_MP_PARAM'] && !$levelRec['_MOUNT_OL']) {
$this->MP_array[] = $levelRec['_MP_PARAM'];
}
}
}
// Return FALSE if no page ID was set (thus no menu of subpages can be made).
if ($this->id <= 0) {
return false;
}
// Check if page is a mount point, and if so set id and MP_array
// (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...)
$mount_info = $this->sys_page->getMountPointInfo($this->id);
if (is_array($mount_info)) {
$this->MP_array[] = $mount_info['MPvar'];
$this->id = $mount_info['mount_pid'];
}
// Gather list of page uids in root line (for "isActive" evaluation). Also adds the MP params in the path so Mount Points are respected.
// (List is specific for this rootline, so it may be supplied from parent menus for speed...)
if ($this->rL_uidRegister === null) {
$this->rL_uidRegister = [];
$rl_MParray = [];
foreach ($this->tmpl->rootLine as $v_rl) {
// For overlaid mount points, set the variable right now:
if ($v_rl['_MP_PARAM'] && $v_rl['_MOUNT_OL']) {
$rl_MParray[] = $v_rl['_MP_PARAM'];
}
// Add to register:
$this->rL_uidRegister[] = 'ITEM:' . $v_rl['uid'] .
(
!empty($rl_MParray)
? ':' . implode(',', $rl_MParray)
: ''
);
// For normal mount points, set the variable for next level.
if ($v_rl['_MP_PARAM'] && !$v_rl['_MOUNT_OL']) {
$rl_MParray[] = $v_rl['_MP_PARAM'];
}
}
}
// Set $directoryLevel so the following evalution of the nextActive will not return
// an invalid value if .special=directory was set
$directoryLevel = 0;
if ($this->conf['special'] === 'directory') {
$value = isset($this->conf['special.']['value.']) ? $this->parent_cObj->stdWrap(
$this->conf['special.']['value'],
$this->conf['special.']['value.']
) : $this->conf['special.']['value'];
if ($value === '') {
$value = $tsfe->page['uid'];
}
$directoryLevel = (int)$tsfe->tmpl->getRootlineLevel($value);
}
// 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
// Notice: The automatic expansion of a menu is designed to work only when no "special" modes (except "directory") are used.
$startLevel = $directoryLevel ?: $this->entryLevel;
$currentLevel = $startLevel + $this->menuNumber;
if (is_array($this->tmpl->rootLine[$currentLevel])) {
$nextMParray = $this->MP_array;
if (empty($nextMParray) && !$this->tmpl->rootLine[$currentLevel]['_MOUNT_OL'] && $currentLevel > 0) {
// Make sure to slide-down any mount point information (_MP_PARAM) to children records in the rootline
// otherwise automatic expansion will not work
$parentRecord = $this->tmpl->rootLine[$currentLevel - 1];
if (isset($parentRecord['_MP_PARAM'])) {
$nextMParray[] = $parentRecord['_MP_PARAM'];
}
}
// In overlay mode, add next level MPvars as well:
if ($this->tmpl->rootLine[$currentLevel]['_MOUNT_OL']) {
$nextMParray[] = $this->tmpl->rootLine[$currentLevel]['_MP_PARAM'];
}
$this->nextActive = $this->tmpl->rootLine[$currentLevel]['uid'] .
(
!empty($nextMParray)
? ':' . implode(',', $nextMParray)
: ''
);
} else {
$this->nextActive = '';
}
// imgNamePrefix
if ($this->mconf['imgNamePrefix']) {
$this->imgNamePrefix = $this->mconf['imgNamePrefix'];
}
$this->imgNameNotRandom = $this->mconf['imgNameNotRandom'];
$retVal = true;
} else {
$this->getTimeTracker()->setTSlogMessage('ERROR in menu', 3);
$retVal = false;
}
return $retVal;
}
/**
* Creates the menu in the internal variables, ready for output.
* Basically this will read the page records needed and fill in the internal $this->menuArr
* 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.
*/
public function makeMenu()
{
if (!$this->id) {
return;
}
$this->useCacheHash = false;
// Initializing showAccessRestrictedPages
$SAVED_where_groupAccess = '';
if ($this->mconf['showAccessRestrictedPages']) {
// SAVING where_groupAccess
$SAVED_where_groupAccess = $this->sys_page->where_groupAccess;
// Temporarily removing fe_group checking!
$this->sys_page->where_groupAccess = '';
}
$menuItems = $this->prepareMenuItems();
$c = 0;
$c_b = 0;
$minItems = (int)($this->mconf['minItems'] ?: $this->conf['minItems']);
$maxItems = (int)($this->mconf['maxItems'] ?: $this->conf['maxItems']);
$begin = $this->parent_cObj->calc($this->mconf['begin'] ? $this->mconf['begin'] : $this->conf['begin']);
$minItemsConf = $this->mconf['minItems.'] ?? $this->conf['minItems.'] ?? null;
$minItems = is_array($minItemsConf) ? $this->parent_cObj->stdWrap($minItems, $minItemsConf) : $minItems;
$maxItemsConf = $this->mconf['maxItems.'] ?? $this->conf['maxItems.'] ?? null;
$maxItems = is_array($maxItemsConf) ? $this->parent_cObj->stdWrap($maxItems, $maxItemsConf) : $maxItems;
$beginConf = $this->mconf['begin.'] ?? $this->conf['begin.'] ?? null;
$begin = is_array($beginConf) ? $this->parent_cObj->stdWrap($begin, $beginConf) : $begin;
$banUidArray = $this->getBannedUids();
// Fill in the menuArr with elements that should go into the menu:
$this->menuArr = [];
foreach ($menuItems as $data) {
$spacer = GeneralUtility::inList($this->spacerIDList, $data['doktype']) || $data['ITEM_STATE'] === 'SPC';
// if item is a spacer, $spacer is set
if ($this->filterMenuPages($data, $banUidArray, $spacer)) {
$c_b++;
// If the beginning item has been reached.
if ($begin <= $c_b) {
$this->menuArr[$c] = $data;
$this->menuArr[$c]['isSpacer'] = $spacer;
$c++;
if ($maxItems && $c >= $maxItems) {
break;
}
}
}
}
// Fill in fake items, if min-items is set.
if ($minItems) {
while ($c < $minItems) {
$this->menuArr[$c] = [
'title' => '...',
'uid' => $this->getTypoScriptFrontendController()->id
];
$c++;
}
}
// Passing the menuArr through a user defined function:
if ($this->mconf['itemArrayProcFunc']) {
$this->menuArr = $this->userProcess('itemArrayProcFunc', $this->menuArr);
}
// Setting number of menu items
$this->getTypoScriptFrontendController()->register['count_menuItems'] = count($this->menuArr);
$this->hash = md5(
serialize($this->menuArr) .
serialize($this->mconf) .
serialize($this->tmpl->rootLine) .
serialize($this->MP_array)
);
// Get the cache timeout:
if ($this->conf['cache_period']) {
$cacheTimeout = $this->conf['cache_period'];
} else {
$cacheTimeout = $this->getTypoScriptFrontendController()->get_cache_timeout();
}
$cache = $this->getCache();
$cachedData = $cache->get($this->hash);
if (!is_array($cachedData)) {
$this->generate();
$cache->set($this->hash, $this->result, ['ident_MENUDATA'], (int)$cacheTimeout);
} else {
$this->result = $cachedData;
}
// End showAccessRestrictedPages
if ($this->mconf['showAccessRestrictedPages']) {
// RESTORING where_groupAccess
$this->sys_page->where_groupAccess = $SAVED_where_groupAccess;
}
}
/**
* Generates the the menu data.
*
* Subclasses should overwrite this method.
*/
public function generate()
{
}
/**
* @return string The HTML for the menu
*/
public function writeMenu()
{
return '';
}
/**
* Gets an array of page rows and removes all, which are not accessible
*
* @param array $pages
* @return array
*/
protected function removeInaccessiblePages(array $pages)
{
$banned = $this->getBannedUids();
$filteredPages = [];
foreach ($pages as $aPage) {
if ($this->filterMenuPages($aPage, $banned, $aPage['doktype'] === PageRepository::DOKTYPE_SPACER)) {
$filteredPages[$aPage['uid']] = $aPage;
}
}
return $filteredPages;
}
/**
* Main function for retrieving menu items based on the menu type (special or sectionIndex or "normal")
*
* @return array
*/
protected function prepareMenuItems()
{
$menuItems = [];
$alternativeSortingField = trim($this->mconf['alternativeSortingField']) ?: 'sorting';
// Additional where clause, usually starts with AND (as usual with all additionalWhere functionality in TS)
$additionalWhere = $this->mconf['additionalWhere'] ?? '';
if (isset($this->mconf['additionalWhere.'])) {
$additionalWhere = $this->parent_cObj->stdWrap($additionalWhere, $this->mconf['additionalWhere.']);
}
// ... only for the FIRST level of a HMENU
if ($this->menuNumber == 1 && $this->conf['special']) {
$value = isset($this->conf['special.']['value.'])
? $this->parent_cObj->stdWrap($this->conf['special.']['value'], $this->conf['special.']['value.'])
: $this->conf['special.']['value'];
switch ($this->conf['special']) {
case 'userfunction':
$menuItems = $this->prepareMenuItemsForUserSpecificMenu($value, $alternativeSortingField);
break;
case 'language':
$menuItems = $this->prepareMenuItemsForLanguageMenu($value);
break;
case 'directory':
$menuItems = $this->prepareMenuItemsForDirectoryMenu($value, $alternativeSortingField);
break;
case 'list':
$menuItems = $this->prepareMenuItemsForListMenu($value);
break;
case 'updated':
$menuItems = $this->prepareMenuItemsForUpdatedMenu(
$value,
$this->mconf['alternativeSortingField'] ?: false
);
break;
case 'keywords':
$menuItems = $this->prepareMenuItemsForKeywordsMenu(
$value,
$this->mconf['alternativeSortingField'] ?: false
);
break;
case 'categories':
/** @var CategoryMenuUtility $categoryMenuUtility */
$categoryMenuUtility = GeneralUtility::makeInstance(CategoryMenuUtility::class);
$menuItems = $categoryMenuUtility->collectPages($value, $this->conf['special.'], $this);
break;
case 'rootline':
$menuItems = $this->prepareMenuItemsForRootlineMenu();
break;
case 'browse':
$menuItems = $this->prepareMenuItemsForBrowseMenu($value, $alternativeSortingField, $additionalWhere);
break;
}
if ($this->mconf['sectionIndex']) {
$sectionIndexes = [];
foreach ($menuItems as $page) {
$sectionIndexes = $sectionIndexes + $this->sectionIndex($alternativeSortingField, $page['uid']);
}
$menuItems = $sectionIndexes;
}
} elseif (is_array($this->alternativeMenuTempArray)) {
// Setting $menuItems array if not level 1.
$menuItems = $this->alternativeMenuTempArray;
} elseif ($this->mconf['sectionIndex']) {
$menuItems = $this->sectionIndex($alternativeSortingField);
} else {
// Default: Gets a hierarchical menu based on subpages of $this->id
$menuItems = $this->sys_page->getMenu($this->id, '*', $alternativeSortingField, $additionalWhere);
}
return $menuItems;
}
/**
* Fetches all menuitems if special = userfunction is set
*
* @param string $specialValue The value from special.value
* @param string $sortingField The sorting field
* @return array
*/
protected function prepareMenuItemsForUserSpecificMenu($specialValue, $sortingField)
{
$menuItems = $this->parent_cObj->callUserFunction(
$this->conf['special.']['userFunc'],
array_merge($this->conf['special.'], ['value' => $specialValue, '_altSortField' => $sortingField]),
''
);
if (!is_array($menuItems)) {
$menuItems = [];
}
return $menuItems;
}
/**
* Fetches all menuitems if special = language is set
*
* @param string $specialValue The value from special.value
* @return array
*/
protected function prepareMenuItemsForLanguageMenu($specialValue)
{
$menuItems = [];
// Getting current page record NOT overlaid by any translation:
$tsfe = $this->getTypoScriptFrontendController();
$currentPageWithNoOverlay = $this->sys_page->getRawRecord('pages', $tsfe->page['uid']);
// Traverse languages set up:
$languageItems = GeneralUtility::intExplode(',', $specialValue);
foreach ($languageItems as $sUid) {
// Find overlay record:
if ($sUid) {
$lRecs = $this->sys_page->getPageOverlay($tsfe->page['uid'], $sUid);
} else {
$lRecs = [];
}
// Checking if the "disabled" state should be set.
if (GeneralUtility::hideIfNotTranslated($tsfe->page['l18n_cfg']) && $sUid &&
empty($lRecs) || GeneralUtility::hideIfDefaultLanguage($tsfe->page['l18n_cfg']) &&
(!$sUid || empty($lRecs)) ||
!$this->conf['special.']['normalWhenNoLanguage'] && $sUid && empty($lRecs)
) {
$iState = $tsfe->sys_language_uid == $sUid ? 'USERDEF2' : 'USERDEF1';
} else {
$iState = $tsfe->sys_language_uid == $sUid ? 'ACT' : 'NO';
}
if ($this->conf['addQueryString']) {
$getVars = $this->parent_cObj->getQueryArguments(
$this->conf['addQueryString.'],
['L' => $sUid],
true
);
$this->analyzeCacheHashRequirements($getVars);
} else {
$getVars = '&L=' . $sUid;
}
// Adding menu item:
$menuItems[] = array_merge(
array_merge($currentPageWithNoOverlay, $lRecs),
[
'ITEM_STATE' => $iState,
'_ADD_GETVARS' => $getVars,
'_SAFE' => true
]
);
}
return $menuItems;
}
/**
* Fetches all menuitems if special = directory is set
*
* @param string $specialValue The value from special.value
* @param string $sortingField The sorting field
* @return array
*/
protected function prepareMenuItemsForDirectoryMenu($specialValue, $sortingField)
{
$tsfe = $this->getTypoScriptFrontendController();
$menuItems = [];
if ($specialValue == '') {
$specialValue = $tsfe->page['uid'];
}
$items = GeneralUtility::intExplode(',', $specialValue);
$pageLinkBuilder = GeneralUtility::makeInstance(PageLinkBuilder::class, $this->parent_cObj);
foreach ($items as $id) {
$MP = $pageLinkBuilder->getMountPointParameterFromRootPointMaps($id);
// Checking if a page is a mount page and if so, change the ID and set the MP var properly.
$mount_info = $this->sys_page->getMountPointInfo($id);
if (is_array($mount_info)) {
if ($mount_info['overlay']) {
// Overlays should already have their full MPvars calculated:
$MP = $pageLinkBuilder->getMountPointParameterFromRootPointMaps((int)$mount_info['mount_pid']);
$MP = $MP ? $MP : $mount_info['MPvar'];
} else {
$MP = ($MP ? $MP . ',' : '') . $mount_info['MPvar'];
}
$id = $mount_info['mount_pid'];
}
// Get sub-pages:
$statement = $this->parent_cObj->exec_getQuery('pages', ['pidInList' => $id, 'orderBy' => $sortingField]);
while ($row = $statement->fetch()) {
$tsfe->sys_page->versionOL('pages', $row, true);
if (!empty($row)) {
// Keep mount point?
$mount_info = $this->sys_page->getMountPointInfo($row['uid'], $row);
// There is a valid mount point.
if (is_array($mount_info) && $mount_info['overlay']) {
// Using "getPage" is OK since we need the check for enableFields
// AND for type 2 of mount pids we DO require a doktype < 200!
$mp_row = $this->sys_page->getPage($mount_info['mount_pid']);
if (!empty($mp_row)) {
$row = $mp_row;
$row['_MP_PARAM'] = $mount_info['MPvar'];
} else {
// If the mount point could not be fetched with respect
// to enableFields, unset the row so it does not become a part of the menu!
unset($row);
}
}
// Add external MP params, then the row:
if (!empty($row)) {
if ($MP) {
$row['_MP_PARAM'] = $MP . ($row['_MP_PARAM'] ? ',' . $row['_MP_PARAM'] : '');
}
$menuItems[$row['uid']] = $this->sys_page->getPageOverlay($row);
}
}
}
}
return $menuItems;
}
/**
* Fetches all menuitems if special = list is set
*
* @param string $specialValue The value from special.value
* @return array
*/
protected function prepareMenuItemsForListMenu($specialValue)
{
$menuItems = [];
if ($specialValue == '') {
$specialValue = $this->id;
}
$skippedEnableFields = [];
if (!empty($this->mconf['showAccessRestrictedPages'])) {
$skippedEnableFields = ['fe_group' => 1];
}
/** @var RelationHandler $loadDB*/
$loadDB = GeneralUtility::makeInstance(RelationHandler::class);
$loadDB->setFetchAllFields(true);
$loadDB->start($specialValue, 'pages');
$loadDB->additionalWhere['pages'] = $this->parent_cObj->enableFields('pages', false, $skippedEnableFields);
$loadDB->getFromDB();
$pageLinkBuilder = GeneralUtility::makeInstance(PageLinkBuilder::class, $this->parent_cObj);
foreach ($loadDB->itemArray as $val) {
$MP = $pageLinkBuilder->getMountPointParameterFromRootPointMaps((int)$val['id']);
// Keep mount point?
$mount_info = $this->sys_page->getMountPointInfo($val['id']);
// There is a valid mount point.
if (is_array($mount_info) && $mount_info['overlay']) {
// Using "getPage" is OK since we need the check for enableFields
// AND for type 2 of mount pids we DO require a doktype < 200!
$mp_row = $this->sys_page->getPage($mount_info['mount_pid']);
if (!empty($mp_row)) {
$row = $mp_row;
$row['_MP_PARAM'] = $mount_info['MPvar'];
// Overlays should already have their full MPvars calculated
if ($mount_info['overlay']) {
$MP = $pageLinkBuilder->getMountPointParameterFromRootPointMaps((int)$mount_info['mount_pid']);
if ($MP) {
unset($row['_MP_PARAM']);
}
}
} else {
// If the mount point could not be fetched with respect to
// enableFields, unset the row so it does not become a part of the menu!
unset($row);
}
} else {
$row = $loadDB->results['pages'][$val['id']];
}
// Add versioning overlay for current page (to respect workspaces)
if (isset($row) && is_array($row)) {
$this->sys_page->versionOL('pages', $row, true);
}
// Add external MP params, then the row:
if (isset($row) && is_array($row)) {
if ($MP) {
$row['_MP_PARAM'] = $MP . ($row['_MP_PARAM'] ? ',' . $row['_MP_PARAM'] : '');
}
$menuItems[] = $this->sys_page->getPageOverlay($row);
}
}
return $menuItems;
}
/**
* Fetches all menuitems if special = updated is set
*
* @param string $specialValue The value from special.value
* @param string $sortingField The sorting field
* @return array
*/
protected function prepareMenuItemsForUpdatedMenu($specialValue, $sortingField)
{
$tsfe = $this->getTypoScriptFrontendController();
$menuItems = [];
if ($specialValue == '') {
$specialValue = $tsfe->page['uid'];
}
$items = GeneralUtility::intExplode(',', $specialValue);
if (MathUtility::canBeInterpretedAsInteger($this->conf['special.']['depth'])) {
$depth = MathUtility::forceIntegerInRange($this->conf['special.']['depth'], 1, 20);
} else {
$depth = 20;
}
// Max number of items
$limit = MathUtility::forceIntegerInRange($this->conf['special.']['limit'], 0, 100);
$maxAge = (int)$this->parent_cObj->calc($this->conf['special.']['maxAge']);
if (!$limit) {
$limit = 10;
}
// *'auto', 'manual', 'tstamp'
$mode = $this->conf['special.']['mode'];
// Get id's
$id_list_arr = [];
foreach ($items as $id) {
$bA = MathUtility::forceIntegerInRange($this->conf['special.']['beginAtLevel'], 0, 100);
$id_list_arr[] = $this->parent_cObj->getTreeList(-1 * $id, $depth - 1 + $bA, $bA - 1);
}
$id_list = implode(',', $id_list_arr);
// Get sortField (mode)
switch ($mode) {
case 'starttime':
$sortField = 'starttime';
break;
case 'lastUpdated':
case 'manual':
$sortField = 'lastUpdated';
break;
case 'tstamp':
$sortField = 'tstamp';
break;
case 'crdate':
$sortField = 'crdate';
break;
default:
$sortField = 'SYS_LASTCHANGED';
}
$extraWhere = ($this->conf['includeNotInMenu'] ? '' : ' AND pages.nav_hide=0') . $this->getDoktypeExcludeWhere();
if ($this->conf['special.']['excludeNoSearchPages']) {
$extraWhere .= ' AND pages.no_search=0';
}
if ($maxAge > 0) {
$extraWhere .= ' AND ' . $sortField . '>' . ($GLOBALS['SIM_ACCESS_TIME'] - $maxAge);
}
$statement = $this->parent_cObj->exec_getQuery('pages', [
'pidInList' => '0',
'uidInList' => $id_list,
'where' => $sortField . '>=0' . $extraWhere,
'orderBy' => $sortingField ?: $sortField . ' DESC',
'max' => $limit
]);
while ($row = $statement->fetch()) {
$tsfe->sys_page->versionOL('pages', $row, true);
if (is_array($row)) {
$menuItems[$row['uid']] = $this->sys_page->getPageOverlay($row);
}
}
return $menuItems;
}
/**
* Fetches all menuitems if special = keywords is set
*
* @param string $specialValue The value from special.value
* @param string $sortingField The sorting field
* @return array
*/
protected function prepareMenuItemsForKeywordsMenu($specialValue, $sortingField)
{
$tsfe = $this->getTypoScriptFrontendController();
$menuItems = [];
list($specialValue) = GeneralUtility::intExplode(',', $specialValue);
if (!$specialValue) {
$specialValue = $tsfe->page['uid'];
}
if ($this->conf['special.']['setKeywords'] || $this->conf['special.']['setKeywords.']) {
$kw = isset($this->conf['special.']['setKeywords.']) ? $this->parent_cObj->stdWrap($this->conf['special.']['setKeywords'], $this->conf['special.']['setKeywords.']) : $this->conf['special.']['setKeywords'];
} else {
// The page record of the 'value'.
$value_rec = $this->sys_page->getPage($specialValue);
$kfieldSrc = $this->conf['special.']['keywordsField.']['sourceField'] ? $this->conf['special.']['keywordsField.']['sourceField'] : 'keywords';
// keywords.
$kw = trim($this->parent_cObj->keywords($value_rec[$kfieldSrc]));
}
// *'auto', 'manual', 'tstamp'
$mode = $this->conf['special.']['mode'];
switch ($mode) {
case 'starttime':
$sortField = 'starttime';
break;
case 'lastUpdated':
case 'manual':
$sortField = 'lastUpdated';
break;
case 'tstamp':
$sortField = 'tstamp';
break;
case 'crdate':
$sortField = 'crdate';
break;
default:
$sortField = 'SYS_LASTCHANGED';
}
// Depth, limit, extra where
if (MathUtility::canBeInterpretedAsInteger($this->conf['special.']['depth'])) {
$depth = MathUtility::forceIntegerInRange($this->conf['special.']['depth'], 0, 20);
} else {
$depth = 20;
}
// Max number of items
$limit = MathUtility::forceIntegerInRange($this->conf['special.']['limit'], 0, 100);
// Start point
$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
);
$startUid = (int)$this->tmpl->rootLine[$eLevel]['uid'];
// Which field is for keywords
$kfield = 'keywords';
if ($this->conf['special.']['keywordsField']) {
list($kfield) = explode(' ', trim($this->conf['special.']['keywordsField']));
}
// If there are keywords and the startuid is present
if ($kw && $startUid) {
$bA = MathUtility::forceIntegerInRange($this->conf['special.']['beginAtLevel'], 0, 100);
$id_list = $this->parent_cObj->getTreeList(-1 * $startUid, $depth - 1 + $bA, $bA - 1);
$kwArr = GeneralUtility::trimExplode(',', $kw, true);
$keyWordsWhereArr = [];
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
foreach ($kwArr as $word) {
$keyWordsWhereArr[] = $queryBuilder->expr()->like(
$kfield,
$queryBuilder->createNamedParameter(
'%' . $queryBuilder->escapeLikeWildcards($word) . '%',
\PDO::PARAM_STR
)
);
}
$queryBuilder
->select('*')
->from('pages')
->where(
$queryBuilder->expr()->in(
'uid',
GeneralUtility::intExplode(',', $id_list, true)
),
$queryBuilder->expr()->neq(
'uid',
$queryBuilder->createNamedParameter($specialValue, \PDO::PARAM_INT)
)
);
if (count($keyWordsWhereArr) !== 0) {
$queryBuilder->andWhere($queryBuilder->expr()->orX(...$keyWordsWhereArr));
}