-
-
Notifications
You must be signed in to change notification settings - Fork 160
/
PageModel.php
1403 lines (1223 loc) · 53.6 KB
/
PageModel.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
/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/
namespace Contao;
use Contao\CoreBundle\Exception\NoRootPageFoundException;
use Contao\CoreBundle\Routing\ResponseContext\HtmlHeadBag\HtmlHeadBag;
use Contao\CoreBundle\Routing\ResponseContext\JsonLd\ContaoPageSchema;
use Contao\CoreBundle\Routing\ResponseContext\JsonLd\JsonLdManager;
use Contao\CoreBundle\Routing\ResponseContext\ResponseContext;
use Contao\CoreBundle\Routing\ResponseContext\ResponseContextAccessor;
use Contao\CoreBundle\String\HtmlDecoder;
use Contao\CoreBundle\Util\LocaleUtil;
use Contao\Model\Collection;
use Contao\Model\Registry;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* Reads and writes pages
*
* @property string|integer $id
* @property string|integer $pid
* @property string|integer $sorting
* @property string|integer $tstamp
* @property string $title
* @property string $alias
* @property string $type
* @property string $pageTitle
* @property string $language
* @property string $robots
* @property string|null $description
* @property string $redirect
* @property string|integer $jumpTo
* @property string|boolean $redirectBack
* @property string $url
* @property string|boolean $target
* @property string $dns
* @property string $staticFiles
* @property string $staticPlugins
* @property string|boolean $fallback
* @property string|boolean $disableLanguageRedirect
* @property string|null $favicon
* @property string|null $robotsTxt
* @property string $mailerTransport
* @property string|integer $enableCanonical
* @property string $canonicalLink
* @property string $canonicalKeepParams
* @property string $adminEmail
* @property string $dateFormat
* @property string $timeFormat
* @property string $datimFormat
* @property string $validAliasCharacters
* @property string|boolean $useFolderUrl
* @property string $urlPrefix
* @property string $urlSuffix
* @property string|boolean $useSSL
* @property string|boolean $autoforward
* @property string|boolean $protected
* @property string|array|null $groups
* @property string|boolean $includeLayout
* @property string|integer $layout
* @property string|boolean $includeCache
* @property string|integer|boolean $cache
* @property string|boolean $alwaysLoadFromCache
* @property string|integer|boolean $clientCache
* @property string|boolean $includeChmod
* @property string|integer $cuser
* @property string|integer $cgroup
* @property string $chmod
* @property string|boolean $noSearch
* @property string|boolean $requireItem
* @property string $cssClass
* @property string $sitemap
* @property string|boolean $hide
* @property string|boolean $guests
* @property string|integer $tabindex
* @property string $accesskey
* @property string|boolean $published
* @property string|integer $start
* @property string|integer $stop
* @property string|boolean $enforceTwoFactor
* @property string|integer $twoFactorJumpTo
*
* @property array $trail
* @property string $mainAlias
* @property string $mainTitle
* @property string $mainPageTitle
* @property string $parentAlias
* @property string $parentTitle
* @property string $parentPageTitle
* @property string $folderUrl
* @property boolean $isPublic
* @property integer $rootId
* @property string $rootAlias
* @property string $rootTitle
* @property string $rootPageTitle
* @property integer $rootSorting
* @property string $domain
* @property string $rootLanguage
* @property boolean $rootIsPublic
* @property boolean $rootIsFallback
* @property string|boolean $rootUseSSL
* @property string $rootFallbackLanguage
* @property boolean $minifyMarkup
* @property integer $layoutId
* @property boolean $hasJQuery
* @property boolean $hasMooTools
* @property string $template
* @property string $templateGroup
* @property boolean $useAutoItem
*
* @method static PageModel|null findById($id, array $opt=array())
* @method static PageModel|null findByPk($id, array $opt=array())
* @method static PageModel|null findByIdOrAlias($val, array $opt=array())
* @method static PageModel|null findOneBy($col, $val, array $opt=array())
* @method static PageModel|null findOneByPid($val, array $opt=array())
* @method static PageModel|null findOneBySorting($val, array $opt=array())
* @method static PageModel|null findOneByTstamp($val, array $opt=array())
* @method static PageModel|null findOneByTitle($val, array $opt=array())
* @method static PageModel|null findOneByAlias($val, array $opt=array())
* @method static PageModel|null findOneByType($val, array $opt=array())
* @method static PageModel|null findOneByPageTitle($val, array $opt=array())
* @method static PageModel|null findOneByLanguage($val, array $opt=array())
* @method static PageModel|null findOneByRobots($val, array $opt=array())
* @method static PageModel|null findOneByDescription($val, array $opt=array())
* @method static PageModel|null findOneByRedirect($val, array $opt=array())
* @method static PageModel|null findOneByJumpTo($val, array $opt=array())
* @method static PageModel|null findOneByRedirectBack($val, array $opt=array())
* @method static PageModel|null findOneByUrl($val, array $opt=array())
* @method static PageModel|null findOneByTarget($val, array $opt=array())
* @method static PageModel|null findOneByDns($val, array $opt=array())
* @method static PageModel|null findOneByStaticFiles($val, array $opt=array())
* @method static PageModel|null findOneByStaticPlugins($val, array $opt=array())
* @method static PageModel|null findOneByFallback($val, array $opt=array())
* @method static PageModel|null findOneByDisableLanguageRedirect($val, array $opt=array())
* @method static PageModel|null findOneByFavicon($val, array $opt=array())
* @method static PageModel|null findOneByRobotsTxt($val, array $opt=array())
* @method static PageModel|null findOneByMailerTransport($val, array $opt=array())
* @method static PageModel|null findOneByEnableCanonical($val, array $opt=array())
* @method static PageModel|null findOneByCanonicalLink($val, array $opt=array())
* @method static PageModel|null findOneByCanonicalKeepParams($val, array $opt=array())
* @method static PageModel|null findOneByAdminEmail($val, array $opt=array())
* @method static PageModel|null findOneByDateFormat($val, array $opt=array())
* @method static PageModel|null findOneByTimeFormat($val, array $opt=array())
* @method static PageModel|null findOneByDatimFormat($val, array $opt=array())
* @method static PageModel|null findOneByValidAliasCharacters($val, array $opt=array())
* @method static PageModel|null findOneByUseFolderUrl($val, array $opt=array())
* @method static PageModel|null findOneByUrlPrefix($val, array $opt=array())
* @method static PageModel|null findOneByUrlSuffix($val, array $opt=array())
* @method static PageModel|null findOneByUseSSL($val, array $opt=array())
* @method static PageModel|null findOneByAutoforward($val, array $opt=array())
* @method static PageModel|null findOneByProtected($val, array $opt=array())
* @method static PageModel|null findOneByGroups($val, array $opt=array())
* @method static PageModel|null findOneByIncludeLayout($val, array $opt=array())
* @method static PageModel|null findOneByLayout($val, array $opt=array())
* @method static PageModel|null findOneByIncludeCache($val, array $opt=array())
* @method static PageModel|null findOneByCache($val, array $opt=array())
* @method static PageModel|null findOneByIncludeChmod($val, array $opt=array())
* @method static PageModel|null findOneByCuser($val, array $opt=array())
* @method static PageModel|null findOneByCgroup($val, array $opt=array())
* @method static PageModel|null findOneByChmod($val, array $opt=array())
* @method static PageModel|null findOneByNoSearch($val, array $opt=array())
* @method static PageModel|null findOneByCssClass($val, array $opt=array())
* @method static PageModel|null findOneBySitemap($val, array $opt=array())
* @method static PageModel|null findOneByHide($val, array $opt=array())
* @method static PageModel|null findOneByGuests($val, array $opt=array())
* @method static PageModel|null findOneByTabindex($val, array $opt=array())
* @method static PageModel|null findOneByAccesskey($val, array $opt=array())
* @method static PageModel|null findOneByPublished($val, array $opt=array())
* @method static PageModel|null findOneByStart($val, array $opt=array())
* @method static PageModel|null findOneByStop($val, array $opt=array())
* @method static PageModel|null findOneByEnforceTwoFactor($val, array $opt=array())
* @method static PageModel|null findOneByTwoFactorJumpTo($val, array $opt=array())
*
* @method static Collection|PageModel[]|PageModel|null findByPid($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findBySorting($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByTstamp($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByTitle($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByAlias($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByType($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByPageTitle($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByLanguage($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByRobots($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByDescription($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByRedirect($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByJumpTo($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByRedirectBack($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByUrl($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByTarget($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByDns($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByStaticFiles($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByStaticPlugins($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByFallback($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByDisableLanguageRedirect($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByFavicon($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByRobotsTxt($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByMailerTransport($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByEnableCanonical($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByCanonicalLink($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByCanonicalKeepParams($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByAdminEmail($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByDateFormat($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByTimeFormat($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByDatimFormat($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByValidAliasCharacters($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByUseFolderUrl($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByUrlPrefix($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByUrlSuffix($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByUseSSL($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByAutoforward($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByProtected($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByGroups($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByIncludeLayout($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByLayout($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByIncludeCache($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByCache($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByIncludeChmod($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByCuser($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByCgroup($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByChmod($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByNoSearch($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByCssClass($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findBySitemap($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByHide($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByGuests($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByTabindex($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByAccesskey($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByPublished($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByStart($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByStop($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByEnforceTwoFactor($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findByTwoFactorJumpTo($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findMultipleByIds($val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findBy($col, $val, array $opt=array())
* @method static Collection|PageModel[]|PageModel|null findAll(array $opt=array())
*
* @method static integer countById($id, array $opt=array())
* @method static integer countByPid($val, array $opt=array())
* @method static integer countBySorting($val, array $opt=array())
* @method static integer countByTstamp($val, array $opt=array())
* @method static integer countByTitle($val, array $opt=array())
* @method static integer countByAlias($val, array $opt=array())
* @method static integer countByType($val, array $opt=array())
* @method static integer countByPageTitle($val, array $opt=array())
* @method static integer countByLanguage($val, array $opt=array())
* @method static integer countByRobots($val, array $opt=array())
* @method static integer countByDescription($val, array $opt=array())
* @method static integer countByRedirect($val, array $opt=array())
* @method static integer countByJumpTo($val, array $opt=array())
* @method static integer countByRedirectBack($val, array $opt=array())
* @method static integer countByUrl($val, array $opt=array())
* @method static integer countByTarget($val, array $opt=array())
* @method static integer countByDns($val, array $opt=array())
* @method static integer countByStaticFiles($val, array $opt=array())
* @method static integer countByStaticPlugins($val, array $opt=array())
* @method static integer countByFallback($val, array $opt=array())
* @method static integer countByDisableLanguageRedirect($val, array $opt=array())
* @method static integer countByFavicon($val, array $opt=array())
* @method static integer countByRobotsTxt($val, array $opt=array())
* @method static integer countByMailerTransport($val, array $opt=array())
* @method static integer countByEnableCanonical($val, array $opt=array())
* @method static integer countByCanonicalLink($val, array $opt=array())
* @method static integer countByCanonicalKeepParams($val, array $opt=array())
* @method static integer countByAdminEmail($val, array $opt=array())
* @method static integer countByDateFormat($val, array $opt=array())
* @method static integer countByTimeFormat($val, array $opt=array())
* @method static integer countByDatimFormat($val, array $opt=array())
* @method static integer countByValidAliasCharacters($val, array $opt=array())
* @method static integer countByUseFolderUrl($val, array $opt=array())
* @method static integer countByUrlPrefix($val, array $opt=array())
* @method static integer countByUrlSuffix($val, array $opt=array())
* @method static integer countByUseSSL($val, array $opt=array())
* @method static integer countByAutoforward($val, array $opt=array())
* @method static integer countByProtected($val, array $opt=array())
* @method static integer countByGroups($val, array $opt=array())
* @method static integer countByIncludeLayout($val, array $opt=array())
* @method static integer countByLayout($val, array $opt=array())
* @method static integer countByIncludeCache($val, array $opt=array())
* @method static integer countByCache($val, array $opt=array())
* @method static integer countByIncludeChmod($val, array $opt=array())
* @method static integer countByCuser($val, array $opt=array())
* @method static integer countByCgroup($val, array $opt=array())
* @method static integer countByChmod($val, array $opt=array())
* @method static integer countByNoSearch($val, array $opt=array())
* @method static integer countByCssClass($val, array $opt=array())
* @method static integer countBySitemap($val, array $opt=array())
* @method static integer countByHide($val, array $opt=array())
* @method static integer countByGuests($val, array $opt=array())
* @method static integer countByTabindex($val, array $opt=array())
* @method static integer countByAccesskey($val, array $opt=array())
* @method static integer countByPublished($val, array $opt=array())
* @method static integer countByStart($val, array $opt=array())
* @method static integer countByStop($val, array $opt=array())
* @method static integer countByEnforceTwoFactor($val, array $opt=array())
* @method static integer countByTwoFactorJumpTo($val, array $opt=array())
*
* @author Leo Feyer <https://github.com/leofeyer>
*/
class PageModel extends Model
{
/**
* Table name
* @var string
*/
protected static $strTable = 'tl_page';
/**
* Details loaded
* @var boolean
*/
protected $blnDetailsLoaded = false;
public function __set($strKey, $varValue)
{
// Deprecate setting dynamic page attributes if they are set on the global $objPage
if (\in_array($strKey, array('pageTitle', 'description', 'robots', 'noSearch'), true) && ($GLOBALS['objPage'] ?? null) === $this)
{
trigger_deprecation('contao/core-bundle', '4.12', sprintf('Overriding "%s" is deprecated and will not work in Contao 5.0 anymore. Use the ResponseContext instead.', $strKey));
/** @var ResponseContext|null $responseContext */
$responseContext = System::getContainer()->get(ResponseContextAccessor::class)->getResponseContext();
if (!$responseContext)
{
parent::__set($strKey, $varValue);
return;
}
if (\in_array($strKey, array('pageTitle', 'description', 'robots')) && $responseContext->has(HtmlHeadBag::class))
{
/** @var HtmlHeadBag $htmlHeadBag */
$htmlHeadBag = $responseContext->get(HtmlHeadBag::class);
$htmlDecoder = System::getContainer()->get(HtmlDecoder::class);
switch ($strKey)
{
case 'pageTitle':
$htmlHeadBag->setTitle($htmlDecoder->inputEncodedToPlainText($varValue ?? ''));
break;
case 'description':
$htmlHeadBag->setMetaDescription($htmlDecoder->inputEncodedToPlainText($varValue ?? ''));
break;
case 'robots':
$htmlHeadBag->setMetaRobots($varValue);
break;
}
}
if ('noSearch' === $strKey && $responseContext->has(JsonLdManager::class))
{
/** @var JsonLdManager $jsonLdManager */
$jsonLdManager = $responseContext->get(JsonLdManager::class);
if ($jsonLdManager->getGraphForSchema(JsonLdManager::SCHEMA_CONTAO)->has(ContaoPageSchema::class))
{
/** @var ContaoPageSchema $schema */
$schema = $jsonLdManager->getGraphForSchema(JsonLdManager::SCHEMA_CONTAO)->get(ContaoPageSchema::class);
$schema->setNoSearch((bool) $varValue);
}
}
}
parent::__set($strKey, $varValue);
}
/**
* Find a published page by its ID
*
* @param integer $intId The page ID
* @param array $arrOptions An optional options array
*
* @return PageModel|null The model or null if there is no published page
*/
public static function findPublishedById($intId, array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = array("$t.id=?");
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
return static::findOneBy($arrColumns, $intId, $arrOptions);
}
/**
* Find published pages by their PID
*
* @param integer $intPid The parent ID
* @param array $arrOptions An optional options array
*
* @return Collection|PageModel[]|PageModel|null A collection of models or null if there are no pages
*/
public static function findPublishedByPid($intPid, array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = array("$t.pid=?");
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
return static::findBy($arrColumns, $intPid, $arrOptions);
}
/**
* Find the first published root page by its host name and language
*
* @param string $strHost The host name
* @param mixed $varLanguage An ISO language code or an array of ISO language codes
* @param array $arrOptions An optional options array
*
* @return PageModel|null The model or null if there is no matching root page
*
* @deprecated Deprecated since Contao 4.7, to be removed in Contao 5.0.
*/
public static function findFirstPublishedRootByHostAndLanguage($strHost, $varLanguage, array $arrOptions=array())
{
trigger_deprecation('contao/core-bundle', '4.7', 'Using "Contao\PageModel::findFirstPublishedRootByHostAndLanguage()" has been deprecated and will no longer work Contao 5.0.');
$t = static::$strTable;
$objDatabase = Database::getInstance();
if (\is_array($varLanguage))
{
$arrColumns = array("$t.type='root' AND ($t.dns=? OR $t.dns='')");
if (!empty($varLanguage))
{
$arrColumns[] = "($t.language IN('" . implode("','", $varLanguage) . "') OR $t.fallback='1')";
}
else
{
$arrColumns[] = "$t.fallback='1'";
}
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = "$t.dns DESC" . (!empty($varLanguage) ? ", " . $objDatabase->findInSet("$t.language", array_reverse($varLanguage)) . " DESC" : "") . ", $t.sorting";
}
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
return static::findOneBy($arrColumns, $strHost, $arrOptions);
}
$arrColumns = array("$t.type='root' AND ($t.dns=? OR $t.dns='') AND ($t.language=? OR $t.fallback='1')");
$arrValues = array($strHost, $varLanguage);
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = "$t.dns DESC, $t.fallback";
}
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
return static::findOneBy($arrColumns, $arrValues, $arrOptions);
}
/**
* Find the first published page by its parent ID
*
* @param integer $intPid The parent page's ID
* @param array $arrOptions An optional options array
*
* @return PageModel|null The model or null if there is no published page
*/
public static function findFirstPublishedByPid($intPid, array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = array("$t.pid=? AND $t.type!='root' AND $t.type!='error_401' AND $t.type!='error_403' AND $t.type!='error_404'");
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = "$t.sorting";
}
return static::findOneBy($arrColumns, $intPid, $arrOptions);
}
/**
* Find the first published regular page by its parent ID
*
* @param integer $intPid The parent page's ID
* @param array $arrOptions An optional options array
*
* @return PageModel|null The model or null if there is no published regular page
*/
public static function findFirstPublishedRegularByPid($intPid, array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = array("$t.pid=? AND $t.type='regular'");
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = "$t.sorting";
}
return static::findOneBy($arrColumns, $intPid, $arrOptions);
}
/**
* Find an error 401 page by its parent ID
*
* @param integer $intPid The parent page's ID
* @param array $arrOptions An optional options array
*
* @return PageModel|null The model or null if there is no 401 page
*/
public static function find401ByPid($intPid, array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = array("$t.pid=? AND $t.type='error_401'");
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = "$t.sorting";
}
return static::findOneBy($arrColumns, $intPid, $arrOptions);
}
/**
* Find an error 403 page by its parent ID
*
* @param integer $intPid The parent page's ID
* @param array $arrOptions An optional options array
*
* @return PageModel|null The model or null if there is no 403 page
*/
public static function find403ByPid($intPid, array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = array("$t.pid=? AND $t.type='error_403'");
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = "$t.sorting";
}
return static::findOneBy($arrColumns, $intPid, $arrOptions);
}
/**
* Find an error 404 page by its parent ID
*
* @param integer $intPid The parent page's ID
* @param array $arrOptions An optional options array
*
* @return PageModel|null The model or null if there is no 404 page
*/
public static function find404ByPid($intPid, array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = array("$t.pid=? AND $t.type='error_404'");
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = "$t.sorting";
}
return static::findOneBy($arrColumns, $intPid, $arrOptions);
}
/**
* Find pages matching a list of possible alias names
*
* @param array $arrAliases An array of possible alias names
* @param array $arrOptions An optional options array
*
* @return Collection|PageModel[]|PageModel|null A collection of models or null if there are no pages
*/
public static function findByAliases($arrAliases, array $arrOptions=array())
{
if (empty($arrAliases) || !\is_array($arrAliases))
{
return null;
}
// Remove everything that is not an alias
$arrAliases = array_filter(array_map(static function ($v) { return preg_match('/^[\w\/.-]+$/u', $v) ? $v : null; }, $arrAliases));
// Return if nothing is left
if (empty($arrAliases))
{
return null;
}
$t = static::$strTable;
$arrColumns = array("$t.alias IN('" . implode("','", array_filter($arrAliases)) . "')");
// Check the publication status (see #4652)
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = Database::getInstance()->findInSet("$t.alias", $arrAliases);
}
return static::findBy($arrColumns, null, $arrOptions);
}
/**
* Find published pages by their ID or aliases
*
* @param mixed $varId The numeric ID or the alias name
* @param array $arrOptions An optional options array
*
* @return Collection|PageModel[]|PageModel|null A collection of models or null if there are no pages
*/
public static function findPublishedByIdOrAlias($varId, array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = !preg_match('/^[1-9]\d*$/', $varId) ? array("BINARY $t.alias=?") : array("$t.id=?");
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
return static::findBy($arrColumns, $varId, $arrOptions);
}
/**
* Find all published subpages by their parent ID and exclude pages only visible for guests
*
* @param integer $intPid The parent page's ID
* @param boolean $blnShowHidden If true, hidden pages will be included
* @param boolean $blnIsSitemap If true, the sitemap settings apply
*
* @return Collection|PageModel[]|PageModel|null A collection of models or null if there are no pages
*
* @deprecated Deprecated since Contao 4.9, to be removed in Contao 5.0;
* use PageModel::findPublishedByPid() instead and filter the guests pages yourself
*/
public static function findPublishedSubpagesWithoutGuestsByPid($intPid, $blnShowHidden=false, $blnIsSitemap=false)
{
@trigger_error('Using PageModel::findPublishedSubpagesWithoutGuestsByPid() has been deprecated and will no longer work Contao 5.0. Use PageModel::findPublishedByPid() instead and filter the guests pages yourself.', E_USER_DEPRECATED);
$time = Date::floorToMinute();
$tokenChecker = System::getContainer()->get('contao.security.token_checker');
$blnFeUserLoggedIn = $tokenChecker->hasFrontendUser();
$blnBeUserLoggedIn = $tokenChecker->hasBackendUser() && $tokenChecker->isPreviewMode();
$objSubpages = Database::getInstance()->prepare("SELECT p1.*, (SELECT COUNT(*) FROM tl_page p2 WHERE p2.pid=p1.id AND p2.type!='root' AND p2.type!='error_401' AND p2.type!='error_403' AND p2.type!='error_404'" . (!$blnShowHidden ? ($blnIsSitemap ? " AND (p2.hide='' OR sitemap='map_always')" : " AND p2.hide=''") : "") . ($blnFeUserLoggedIn ? " AND p2.guests=''" : "") . (!$blnBeUserLoggedIn ? " AND p2.published='1' AND (p2.start='' OR p2.start<='$time') AND (p2.stop='' OR p2.stop>'$time')" : "") . ") AS subpages FROM tl_page p1 WHERE p1.pid=? AND p1.type!='root' AND p1.type!='error_401' AND p1.type!='error_403' AND p1.type!='error_404'" . (!$blnShowHidden ? ($blnIsSitemap ? " AND (p1.hide='' OR sitemap='map_always')" : " AND p1.hide=''") : "") . ($blnFeUserLoggedIn ? " AND p1.guests=''" : "") . (!$blnBeUserLoggedIn ? " AND p1.published='1' AND (p1.start='' OR p1.start<='$time') AND (p1.stop='' OR p1.stop>'$time')" : "") . " ORDER BY p1.sorting")
->execute($intPid);
if ($objSubpages->numRows < 1)
{
return null;
}
return static::createCollectionFromDbResult($objSubpages, 'tl_page');
}
/**
* Find all published regular pages by their IDs
*
* @param array $arrIds An array of page IDs
* @param array $arrOptions An optional options array
*
* @return Collection|PageModel[]|PageModel|null A collection of models or null if there are no pages
*/
public static function findPublishedRegularByIds($arrIds, array $arrOptions=array())
{
if (empty($arrIds) || !\is_array($arrIds))
{
return null;
}
$t = static::$strTable;
$arrColumns = array("$t.id IN(" . implode(',', array_map('\intval', $arrIds)) . ") AND $t.type!='error_401' AND $t.type!='error_403' AND $t.type!='error_404'");
if (empty($arrOptions['includeRoot']))
{
$arrColumns[] = "$t.type!='root'";
}
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = Database::getInstance()->findInSet("$t.id", $arrIds);
}
return static::findBy($arrColumns, null, $arrOptions);
}
/**
* Find all published regular pages by their IDs and exclude pages only visible for guests
*
* @param array $arrIds An array of page IDs
* @param array $arrOptions An optional options array
*
* @return Collection|PageModel[]|PageModel|null A collection of models or null if there are no pages
*
* @deprecated Deprecated since Contao 4.12, to be removed in Contao 5;
* use PageModel::findPublishedRegularByIds() instead.
*/
public static function findPublishedRegularWithoutGuestsByIds($arrIds, array $arrOptions=array())
{
trigger_deprecation('contao/core-bundle', '4.12', 'Using PageModel::findPublishedRegularWithoutGuestsByIds() has been deprecated and will no longer work in Contao 5.0. Use PageModel::findPublishedRegularByIds() instead.');
if (empty($arrIds) || !\is_array($arrIds))
{
return null;
}
$t = static::$strTable;
$arrColumns = array("$t.id IN(" . implode(',', array_map('\intval', $arrIds)) . ") AND $t.type!='error_401' AND $t.type!='error_403' AND $t.type!='error_404'");
if (empty($arrOptions['includeRoot']))
{
$arrColumns[] = "$t.type!='root'";
}
if (System::getContainer()->get('contao.security.token_checker')->hasFrontendUser())
{
$arrColumns[] = "$t.guests=''";
}
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = Database::getInstance()->findInSet("$t.id", $arrIds);
}
return static::findBy($arrColumns, null, $arrOptions);
}
/**
* Find all published regular pages by their parent IDs
*
* @param integer $intPid The parent page's ID
* @param array $arrOptions An optional options array
*
* @return Collection|PageModel[]|PageModel|null A collection of models or null if there are no pages
*/
public static function findPublishedRegularByPid($intPid, array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = array("$t.pid=? AND $t.type!='root' AND $t.type!='error_401' AND $t.type!='error_403' AND $t.type!='error_404'");
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = "$t.sorting";
}
return static::findBy($arrColumns, $intPid, $arrOptions);
}
/**
* Find all published regular pages by their parent IDs and exclude pages only visible for guests
*
* @param integer $intPid The parent page's ID
* @param array $arrOptions An optional options array
*
* @return Collection|PageModel[]|PageModel|null A collection of models or null if there are no pages
*
* @deprecated Deprecated since Contao 4.12, to be removed in Contao 5;
* use PageModel::findPublishedRegularByPid() instead.
*/
public static function findPublishedRegularWithoutGuestsByPid($intPid, array $arrOptions=array())
{
trigger_deprecation('contao/core-bundle', '4.12', 'Using PageModel::findPublishedRegularWithoutGuestsByPid() has been deprecated and will no longer work in Contao 5.0. Use PageModel::findPublishedRegularByPid() instead.');
$t = static::$strTable;
$arrColumns = array("$t.pid=? AND $t.type!='root' AND $t.type!='error_401' AND $t.type!='error_403' AND $t.type!='error_404'");
if (System::getContainer()->get('contao.security.token_checker')->hasFrontendUser())
{
$arrColumns[] = "$t.guests=''";
}
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
if (!isset($arrOptions['order']))
{
$arrOptions['order'] = "$t.sorting";
}
return static::findBy($arrColumns, $intPid, $arrOptions);
}
/**
* Find the language fallback page by hostname
*
* @param string $strHost The hostname
* @param array $arrOptions An optional options array
*
* @return PageModel|Model|null The model or null if there is not fallback page
*/
public static function findPublishedFallbackByHostname($strHost, array $arrOptions=array())
{
// Try to load from the registry (see #8544)
if (empty($arrOptions))
{
$objModel = Registry::getInstance()->fetch(static::$strTable, $strHost, 'contao.dns-fallback');
if ($objModel !== null)
{
return $objModel;
}
}
$t = static::$strTable;
$arrColumns = array("$t.dns=? AND $t.fallback='1'");
if (isset($arrOptions['fallbackToEmpty']) && $arrOptions['fallbackToEmpty'] === true)
{
$arrColumns = array("($t.dns=? OR $t.dns='') AND $t.fallback='1'");
}
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
return static::findOneBy($arrColumns, $strHost, $arrOptions);
}
/**
* Finds the published root pages
*
* @param array $arrOptions An optional options array
*
* @return Collection|PageModel[]|PageModel|null A collection of models or null if there are no parent pages
*/
public static function findPublishedRootPages(array $arrOptions=array())
{
$t = static::$strTable;
$arrColumns = array("$t.type='root'");
if (isset($arrOptions['dns']))
{
$arrColumns = array("$t.type='root' AND $t.dns=?");
}
if (!static::isPreviewMode($arrOptions))
{
$time = Date::floorToMinute();
$arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')";
}
return static::findBy($arrColumns, $arrOptions['dns'] ?? null, $arrOptions);
}
/**
* Find the parent pages of a page
*
* @param integer $intId The page's ID
*
* @return Collection|PageModel[]|PageModel|null A collection of models or null if there are no parent pages
*/
public static function findParentsById($intId)
{
$arrModels = array();
while ($intId > 0 && ($objPage = static::findByPk($intId)) !== null)
{
$intId = $objPage->pid;
$arrModels[] = $objPage;
}
if (empty($arrModels))
{
return null;
}
return static::createCollection($arrModels, 'tl_page');
}
/**
* Find the first active page by its member groups
*
* @param array $arrIds An array of member group IDs
*
* @return PageModel|null The model or null if there is no matching member group
*/
public static function findFirstActiveByMemberGroups($arrIds)
{
if (empty($arrIds) || !\is_array($arrIds))
{
return null;
}
$time = Date::floorToMinute();
$objDatabase = Database::getInstance();
$arrIds = array_map('\intval', $arrIds);
$objResult = $objDatabase->prepare("SELECT p.* FROM tl_member_group g LEFT JOIN tl_page p ON g.jumpTo=p.id WHERE g.id IN(" . implode(',', $arrIds) . ") AND g.jumpTo>0 AND g.redirect='1' AND g.disable!='1' AND (g.start='' OR g.start<='$time') AND (g.stop='' OR g.stop>'$time') AND p.published='1' AND (p.start='' OR p.start<='$time') AND (p.stop='' OR p.stop>'$time') ORDER BY " . $objDatabase->findInSet('g.id', $arrIds))
->limit(1)
->execute();
if ($objResult->numRows < 1)
{
return null;
}
$objRegistry = Registry::getInstance();
/** @var PageModel|Model $objPage */
if ($objPage = $objRegistry->fetch('tl_page', $objResult->id))
{
return $objPage;
}
return new static($objResult);
}
/**
* Find a page by its ID and return it with the inherited details
*
* @param integer|string $intId The page's ID
*
* @return PageModel|null The model or null if there is no matching page
*/
public static function findWithDetails($intId)
{
$objPage = static::findByPk($intId);
if ($objPage === null)