/
Page.php
4178 lines (3732 loc) · 142 KB
/
Page.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 Concrete\Core\Page;
use Concrete\Core\Area\Area;
use Block;
use CacheLocal;
use Concrete\Core\Entity\Page\Summary\CustomPageTemplateCollection;
use Concrete\Core\Localization\Service\Date;
use Concrete\Core\Page\Collection\Collection;
use Concrete\Core\Attribute\Key\CollectionKey;
use Concrete\Core\Attribute\ObjectInterface as AttributeObjectInterface;
use Concrete\Core\Database\Connection\Connection;
use Concrete\Core\Entity\Page\PagePath;
use Concrete\Core\Entity\Page\Template as TemplateEntity;
use Concrete\Core\Entity\Site\Site;
use Concrete\Core\Entity\Site\SiteTree;
use Concrete\Core\Entity\StyleCustomizer\CustomCssRecord;
use Concrete\Core\Export\ExportableInterface;
use Concrete\Core\Localization\Locale\Service as LocaleService;
use Concrete\Core\Logging\Channels;
use Concrete\Core\Multilingual\Page\Section\Section;
use Concrete\Core\Package\PackageList;
use Concrete\Core\Page\Controller\PageController;
use Concrete\Core\Page\Search\ColumnSet\DefaultSet;
use Concrete\Core\Page\Stack\Stack;
use Concrete\Core\Page\Statistics as PageStatistics;
use Concrete\Core\Page\Theme\Theme;
use Concrete\Core\Page\Theme\ThemeRouteCollection;
use Concrete\Core\Page\Type\Composer\Control\BlockControl;
use Concrete\Core\Page\Type\Composer\FormLayoutSetControl;
use Concrete\Core\Page\Type\Type;
use Concrete\Core\Permission\Access\Entity\GroupCombinationEntity as GroupCombinationPermissionAccessEntity;
use Concrete\Core\Permission\Access\Entity\GroupEntity as GroupPermissionAccessEntity;
use Concrete\Core\Permission\Access\Entity\PageOwnerEntity;
use Concrete\Core\Permission\Access\Entity\UserEntity as UserPermissionAccessEntity;
use Concrete\Core\Permission\AssignableObjectInterface;
use Concrete\Core\Permission\AssignableObjectTrait;
use Concrete\Core\Permission\Key\PageKey as PagePermissionKey;
use Concrete\Core\Site\SiteAggregateInterface;
use Concrete\Core\Site\Tree\TreeInterface;
use Concrete\Core\StyleCustomizer\Skin\SkinInterface;
use Concrete\Core\Summary\Category\CategoryMemberInterface;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\Support\Facade\Facade;
use Concrete\Core\User\User;
use Config;
use Core;
use Database;
use Doctrine\ORM\EntityManagerInterface;
use Environment;
use Events;
use Group;
use PageCache;
use PageTemplate;
use PageTheme;
use PageType;
use Queue;
use Request;
use Session;
use Concrete\Core\Events\EventDispatcher;
use UserInfo;
/**
* The page object in Concrete encapsulates all the functionality used by a typical page and their contents including blocks, page metadata, page permissions.
*/
class Page extends Collection implements CategoryMemberInterface,
\Concrete\Core\Permission\ObjectInterface,
AttributeObjectInterface,
AssignableObjectInterface,
TreeInterface,
SiteAggregateInterface,
ExportableInterface
{
use AssignableObjectTrait;
/**
* @deprecated what's deprecated is the public part: use the getSiteTreeObject() method to access this property
*
* @var \Concrete\Core\Entity\Site\Tree|null
*/
public $siteTree;
/**
* The page controller.
*
* @var \Concrete\Core\Page\Controller\PageController|null
*/
protected $controller;
/**
* The list of block IDs that are alias.
*
* @var int[]|null
*/
protected $blocksAliasedFromMasterCollection = null;
/**
* The user id of the user that has checked out the page.
*
* @var int|null
*/
public $cCheckedOutUID = null;
/**
* The original cID of a page (if it's a page alias).
*
* @var int|null
*/
protected $cPointerOriginalID = null;
/**
* The original siteTreeID of a page (if it's a page alias).
*
* @var int|null
*/
protected $cPointerOriginalSiteTreeID = null;
/**
* The link for the aliased page.
*
* @var string|null
*/
protected $cPointerExternalLink = null;
/**
* Should the alias link to be opened in a new window?
*
* @var bool|int|null
*/
protected $cPointerExternalLinkNewWindow = null;
/**
* Is this page a page default?
*
* @var bool|int|null
*/
protected $isMasterCollection = null;
/**
* The ID of the page from which this page inherits permissions from.
*
* @var int|null
*/
protected $cInheritPermissionsFromCID = null;
/**
* Is this a system page?
*
* @var bool
*/
protected $cIsSystemPage = false;
/**
* The site tree ID.
*
* @var int|null
*/
protected $siteTreeID;
/**
* The custom name of the alias page.
*
* @var string|null NULL if the page is not an alias, empty string if we should use the name of the aliased page, the custom alias name otherwise.
*/
private $customAliasName;
/**
* The handle of the alias page
*
* @var string|null NULL if the page is not an alias, the alias handle otherwise.
*/
private $aliasHandle;
/**
* Whether this page has a custom summary template collection assigned to it. If null/false,
* then we just use any that are found to fit the criteria.
*
* @var bool|null
*/
protected $hasCustomSummaryTemplateCollection;
protected $cCacheFullPageContentOverrideLifetime;
protected $cCacheFullPageContentLifetimeCustom;
/**
* Initialize collection until we populate it.
*/
public function __construct()
{
$this->loadError(COLLECTION_INIT); // init collection until we populate.
}
/**
* Get a page given its path.
*
* @param string $path the page path (example: /path/to/page)
* @param string $version the page version ('RECENT' for the most recent version, 'ACTIVE' for the currently published version, 'SCHEDULED' for the currently scheduled version, or an integer to retrieve a specific version ID)
* @param \Concrete\Core\Site\Tree\TreeInterface|null $tree
*
* @return \Concrete\Core\Page\Page
*/
public static function getByPath($path, $version = 'RECENT', TreeInterface $tree = null)
{
$path = rtrim($path, '/'); // if the path ends in a / remove it.
$cache = \Core::make('cache/request');
if ($tree) {
$item = $cache->getItem(sprintf('site/page/path/%s/%s', $tree->getSiteTreeID(), trim($path, '/')));
$cID = $item->get();
if ($item->isMiss()) {
$db = Database::connection();
$cID = $db->fetchColumn('select Pages.cID from PagePaths inner join Pages on Pages.cID = PagePaths.cID where cPath = ? and siteTreeID = ?', [$path, $tree->getSiteTreeID()]);
$cache->save($item->set($cID));
}
} else {
$item = $cache->getItem(sprintf('page/path/%s', trim($path, '/')));
$cID = $item->get();
if ($item->isMiss()) {
$db = Database::connection();
$cID = $db->fetchColumn('select cID from PagePaths where cPath = ?', [$path]);
$cache->save($item->set($cID));
}
}
return self::getByID($cID, $version);
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Attribute\ObjectInterface::getObjectAttributeCategory()
*
* @return \Concrete\Core\Attribute\Category\PageCategory
*/
public function getObjectAttributeCategory()
{
$app = Facade::getFacadeApplication();
return $app->make('\Concrete\Core\Attribute\Category\PageCategory');
}
/**
* * Get a page given its ID.
*
* @param int $cID the ID of the page
* @param string $version the page version ('RECENT' for the most recent version, 'ACTIVE' for the currently published version, 'SCHEDULED' for the currently scheduled version, or an integer to retrieve a specific version ID)
*
* @return \Concrete\Core\Page\Page
*/
public static function getByID($cID, $version = 'RECENT')
{
$class = get_called_class();
if ($cID && $version) {
$c = CacheLocal::getEntry('page', $cID . '/' . $version . '/' . $class);
if ($c instanceof $class) {
return $c;
}
}
$where = 'where Pages.cID = ?';
$c = new $class();
$c->populatePage($cID, $where, $version);
// must use cID instead of c->getCollectionID() because cID may be the pointer to another page
if ($cID && $version) {
CacheLocal::set('page', $cID . '/' . $version . '/' . $class, $c);
}
return $c;
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Export\ExportableInterface::getExporter()
*
* @return \Concrete\Core\Page\Exporter
*/
public function getExporter()
{
return new Exporter();
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Permission\ObjectInterface::getPermissionResponseClassName()
*/
public function getPermissionResponseClassName()
{
return '\\Concrete\\Core\\Permission\\Response\\PageResponse';
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Permission\ObjectInterface::getPermissionAssignmentClassName()
*/
public function getPermissionAssignmentClassName()
{
return '\\Concrete\\Core\\Permission\\Assignment\\PageAssignment';
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Permission\ObjectInterface::getPermissionObjectKeyCategoryHandle()
*/
public function getPermissionObjectKeyCategoryHandle()
{
return 'page';
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Summary\Template\Category\CategoryMemberInterface::getSummaryCategoryHandle()
*/
public function getSummaryCategoryHandle() : string
{
return 'page';
}
/**
* @return int|null
*/
public function getSummaryIdentifier()
{
return $this->getCollectionID();
}
/**
* Return a representation of the Page object as something easily serializable.
*
* @return \stdClass
*/
public function getJSONObject()
{
$r = new \stdClass();
$r->type = $this->getPageTypeName();
$r->name = $this->getCollectionName() !== '' ? $this->getCollectionName() : t('(No Title)');
$r->datePublic = DefaultSet::getCollectionDatePublic($this);
$r->dateModified = DefaultSet::getCollectionDateModified($this);
$r->author = DefaultSet::getCollectionAuthor($this);
if ($this->isAliasPage()) {
$r->cID = $this->getCollectionPointerOriginalID();
} else {
$r->cID = $this->getCollectionID();
}
if ($this->isExternalLink()) {
$r->url = $this->getCollectionPointerExternalLink();
} else {
$r->url = (string) $this->getCollectionLink();
}
return $r;
}
/**
* Get the page controller.
*
* @return \Concrete\Core\Page\Controller\PageController
*/
public function getPageController()
{
if (!isset($this->controller)) {
$env = Environment::get();
if ($this->getPageTypeID() > 0) {
$pt = $this->getPageTypeObject();
// return null if page type doesn't exist anymore
if (!$pt) {
return;
}
$ptHandle = $pt->getPageTypeHandle();
$r = $env->getRecord(DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_TYPES . '/' . $ptHandle . '.php', $pt->getPackageHandle());
$prefix = $r->override ? true : $pt->getPackageHandle();
$class = core_class('Controller\\PageType\\' . camelcase($ptHandle), $prefix);
} elseif ($this->isGeneratedCollection()) {
$file = $this->getCollectionFilename();
if (strpos($file, '/' . FILENAME_COLLECTION_VIEW) !== false) {
$path = substr($file, 0, strpos($file, '/' . FILENAME_COLLECTION_VIEW));
} else {
$path = substr($file, 0, strpos($file, '.php'));
}
$r = $env->getRecord(DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_CONTROLLERS . $path . '.php', $this->getPackageHandle());
$prefix = $r->override ? true : $this->getPackageHandle();
$class = core_class('Controller\\SinglePage\\' . str_replace('/', '\\', camelcase($path, true)), $prefix);
}
if (isset($class) && class_exists($class)) {
$this->controller = Core::make($class, ['c' => $this]);
} else {
$this->controller = Core::make(PageController::class, ['c' => $this]);
}
}
return $this->controller;
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Permission\ObjectInterface::getPermissionObjectIdentifier()
*/
public function getPermissionObjectIdentifier()
{
// this is a hack but it's a really good one for performance
// if the permission access entity for page owner exists in the database, then we return the collection ID. Otherwise, we just return the permission collection id
// this is because page owner is the ONLY thing that makes it so we can't use getPermissionsCollectionID, and for most sites that will DRAMATICALLY reduce the number of queries.
// Drafts are exceptions to this rule because some permission keys of these pages are inherited from "Edit Page Type Draft" permission.
if (\Concrete\Core\Permission\Access\PageAccess::usePermissionCollectionIDForIdentifier() && !$this->isPageDraft()) {
return $this->getPermissionsCollectionID();
}
return $this->getCollectionID();
}
/**
* Is the page in edit mode?
*
* @return bool
*/
public function isEditMode()
{
if ($this->getCollectionPath() == STACKS_LISTING_PAGE_PATH) {
return true;
}
if ($this->getPageTypeHandle() == STACKS_PAGE_TYPE) {
return true;
}
return $this->isCheckedOutByMe();
}
/**
* Get the package ID for a page (page thats added by a package) (returns 0 if its not in a package).
*
* @return int
*/
public function getPackageID()
{
return $this->pkgID;
}
/**
* Get the handle the the package that added this page.
*
* @return string|null
*/
public function getPackageHandle()
{
if (!isset($this->pkgHandle)) {
$this->pkgHandle = PackageList::getHandle($this->pkgID);
}
return $this->pkgHandle;
}
/**
* @deprecated There's no more an "Arrange Mode"
*
* @return false
*/
public function isArrangeMode()
{
return $this->isCheckedOutByMe() && isset($_REQUEST['btask']) && $_REQUEST['btask'] === 'arrange';
}
/**
* Forces the page to be checked in if its checked out.
*/
public function forceCheckIn()
{
$db = Database::connection();
$q = 'update Pages set cIsCheckedOut = 0, cCheckedOutUID = null, cCheckedOutDatetime = null, cCheckedOutDatetimeLastEdit = null where cID = ?';
$db->executeQuery($q, [$this->cID]);
}
/**
* @private
* Forces all pages to be checked in and edit mode to be reset.
* @TODO – move this into a command in version 9.
*/
public static function forceCheckInForAllPages()
{
$db = Database::connection();
$q = 'update Pages set cIsCheckedOut = 0, cCheckedOutUID = null, cCheckedOutDatetime = null, cCheckedOutDatetimeLastEdit = null';
$db->executeQuery($q);
}
/**
* Is this a dashboard page?
*
* @return bool
*/
public function isAdminArea()
{
if ($this->isGeneratedCollection()) {
$pos = strpos($this->getCollectionFilename(), '/' . DIRNAME_DASHBOARD);
return $pos > -1;
}
return false;
}
/**
* Uses a Request object to determine which page to load. Queries by path and then by cID.
*
* @param \Concrete\Core\Http\Request $request
*
* @return \Concrete\Core\Page\Page
*/
public static function getFromRequest(Request $request)
{
// if something has already set a page object, we return it
$c = $request->getCurrentPage();
if (is_object($c)) {
return $c;
}
if ($request->getPath() != '') {
$path = $request->getPath();
$db = Database::connection();
$cID = false;
$ppIsCanonical = false;
$site = \Core::make('site')->getSite();
$treeIDs = [0];
foreach ($site->getLocales() as $locale) {
$tree = $locale->getSiteTree();
if (is_object($tree)) {
$treeIDs[] = $tree->getSiteTreeID();
}
}
$treeIDs = implode(',', $treeIDs);
while ((!$cID) && $path) {
$row = $db->fetchAssoc('select pp.cID, ppIsCanonical from PagePaths pp inner join Pages p on pp.cID = p.cID where cPath = ? and siteTreeID in (' . $treeIDs . ')', [$path]);
if (!empty($row)) {
$cID = $row['cID'];
if ($cID) {
$cPath = $path;
$ppIsCanonical = (bool) $row['ppIsCanonical'];
break;
}
}
$path = substr($path, 0, strrpos($path, '/'));
}
if ($cID && $cPath) {
$c = self::getByID($cID, 'ACTIVE');
$c->cPathFetchIsCanonical = $ppIsCanonical;
} else {
$c = new self();
$c->loadError(COLLECTION_NOT_FOUND);
}
return $c;
}
$cID = $request->query->get('cID');
if (!$cID) {
$cID = $request->request->get('cID');
}
$cID = Core::make('helper/security')->sanitizeInt($cID);
if ($cID) {
$c = self::getByID($cID, 'ACTIVE');
} else {
$site = \Core::make('site')->getSite();
$c = $site->getSiteHomePageObject('ACTIVE');
}
$c->cPathFetchIsCanonical = true;
return $c;
}
/**
* Persist the data associated to a block when it has been moved around in the page.
*
* @param int $area_id The ID of the area where the block resides after the arrangment
* @param int $moved_block_id The ID of the moved block
* @param int[] $block_order The IDs of all the blocks in the area, ordered by their display order
*/
public function processArrangement($area_id, $moved_block_id, $block_order)
{
$area_handle = Area::getAreaHandleFromID($area_id);
$db = Database::connection();
// Remove the moved block from its old area, and all blocks from the destination area.
$db->executeQuery('UPDATE CollectionVersionBlockStyles SET arHandle = ? WHERE cID = ? and cvID = ? and bID = ?',
[$area_handle, $this->getCollectionID(), $this->getVersionID(), $moved_block_id]);
$db->executeQuery('UPDATE CollectionVersionBlocks SET arHandle = ? WHERE cID = ? and cvID = ? and bID = ?',
[$area_handle, $this->getCollectionID(), $this->getVersionID(), $moved_block_id]);
$update_query = 'UPDATE CollectionVersionBlocks SET cbDisplayOrder = CASE bID';
$when_statements = [];
$update_values = [];
foreach ($block_order as $key => $block_id) {
$when_statements[] = 'WHEN ? THEN ?';
$update_values[] = $block_id;
$update_values[] = $key;
}
$update_query .= ' ' . implode(' ', $when_statements) . ' END WHERE bID in (' .
implode(',', array_pad([], count($block_order), '?')) . ') AND cID = ? AND cvID = ?';
$values = array_merge($update_values, $block_order);
$values = array_merge($values, [$this->getCollectionID(), $this->getVersionID()]);
$db->executeQuery($update_query, $values);
}
/**
* Is the page checked out?
*
* @return bool|null returns NULL if the page does not exist, a boolean otherwise
*/
public function isCheckedOut()
{
// function to inform us as to whether the current collection is checked out
/** @var \Concrete\Core\Database\Connection\Connection $db */
$db = Database::connection();
if (isset($this->isCheckedOutCache)) {
return $this->isCheckedOutCache;
}
$q = "select cIsCheckedOut, cCheckedOutDatetimeLastEdit from Pages where cID = '{$this->cID}'";
$r = $db->executeQuery($q);
if ($r) {
$row = $r->fetchAssociative();
// If cCheckedOutDatetimeLastEdit is present, get the time span in seconds since it's last edit.
if (!empty($row['cCheckedOutDatetimeLastEdit'])) {
$dh = Core::make('helper/date');
$timeSinceCheckout = ($dh->getOverridableNow(true) - strtotime($row['cCheckedOutDatetimeLastEdit']));
}
if (isset($row['cIsCheckedOut']) && $row['cIsCheckedOut'] == 0) {
return false;
}
if (isset($timeSinceCheckout) && $timeSinceCheckout > CHECKOUT_TIMEOUT) {
$this->forceCheckIn();
$this->isCheckedOutCache = false;
return false;
}
$this->isCheckedOutCache = true;
return true;
}
}
/**
* Gets the user that is editing the current page.
*
* @return string
*/
public function getCollectionCheckedOutUserName()
{
$db = Database::connection();
$query = 'select cCheckedOutUID from Pages where cID = ?';
$vals = [$this->cID];
$checkedOutId = $db->fetchColumn($query, $vals);
if (is_object(UserInfo::getByID($checkedOutId))) {
$ui = UserInfo::getByID($checkedOutId);
$name = $ui->getUserName();
} else {
$name = t('Unknown User');
}
return $name;
}
/**
* Checks if the page is checked out by the current user.
*
* @return bool
*/
public function isCheckedOutByMe()
{
$app = Application::getFacadeApplication();
$u = $app->make(User::class);
return $this->getCollectionCheckedOutUserID() > 0 && $this->getCollectionCheckedOutUserID() == $u->getUserID();
}
/**
* Checks if the page is a single page.
*
* Generated collections are collections without templates, that have special cFilename attributes
*.
*
* @return bool
*/
public function isGeneratedCollection()
{
return $this->getCollectionFilename() && !$this->getPageTemplateID();
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Permission\AssignableObjectInterface::setPermissionsToOverride()
*/
public function setPermissionsToOverride()
{
if ($this->cInheritPermissionsFrom != 'OVERRIDE') {
$this->setPermissionsToManualOverride();
}
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Permission\AssignableObjectInterface::setChildPermissionsToOverride()
*/
public function setChildPermissionsToOverride()
{
foreach ($this->getCollectionChildren() as $child) {
$child->setPermissionsToManualOverride();
}
}
/**
* Remove specific permission keys for a specific access entity (user, group, group combination).
*
* @param \Concrete\Core\User\Group\Group|\Concrete\Core\User\Group\Group[]|\Concrete\Core\User\User|\Concrete\Core\User\UserInfo|\Concrete\Core\Entity\User\User $userOrGroup A list of groups for a group combination, or a group or a user
* @param string[] $permissions the handles of page permission keys to be removed
*/
public function removePermissions($userOrGroup, $permissions = [])
{
if ($this->cInheritPermissionsFrom != 'OVERRIDE') {
return;
}
if (is_array($userOrGroup)) {
$pe = GroupCombinationPermissionAccessEntity::getOrCreate($userOrGroup);
// group combination
} elseif ($userOrGroup instanceof User || $userOrGroup instanceof \Concrete\Core\User\UserInfo) {
$pe = UserPermissionAccessEntity::getOrCreate($userOrGroup);
} else {
// group;
$pe = GroupPermissionAccessEntity::getOrCreate($userOrGroup);
}
foreach ($permissions as $pkHandle) {
$pk = PagePermissionKey::getByHandle($pkHandle);
$pk->setPermissionObject($this);
$pa = $pk->getPermissionAccessObject();
if (is_object($pa)) {
if ($pa->isPermissionAccessInUse()) {
$pa = $pa->duplicate();
}
$pa->removeListItem($pe);
$pt = $pk->getPermissionAssignmentObject();
$pt->assignPermissionAccess($pa);
}
}
}
/**
* Get the drafts parent page for a specific site.
*
* @param \Concrete\Core\Entity\Site\Site|null $site If not specified, we'll use the default site
*
* @return \Concrete\Core\Page\Page
*/
public static function getDraftsParentPage(Site $site = null)
{
$db = Database::connection();
$site = $site ? $site : \Core::make('site')->getSite();
$cParentID = $db->fetchColumn('select p.cID from PagePaths pp inner join Pages p on pp.cID = p.cID inner join SiteLocales sl on p.siteTreeID = sl.siteTreeID where cPath = ? and sl.siteID = ?', [Config::get('concrete.paths.drafts'), $site->getSiteID()]);
return self::getByID($cParentID);
}
/**
* Get the list of draft pages in a specific site.
*
* @param \Concrete\Core\Entity\Site\Site $site
*
* @return \Concrete\Core\Page\Page[]
*/
public static function getDrafts(Site $site)
{
$db = Database::connection();
$nc = self::getDraftsParentPage($site);
$r = $db->executeQuery('select Pages.cID from Pages inner join Collections c on Pages.cID = c.cID where cParentID = ? order by cDateAdded desc', [$nc->getCollectionID()]);
$pages = [];
while ($row = $r->fetch()) {
$entry = self::getByID($row['cID']);
if (is_object($entry)) {
$pages[] = $entry;
}
}
return $pages;
}
/**
* Is this a draft page?
*
* @return bool
*/
public function isPageDraft()
{
if (isset($this->cIsDraft) && $this->cIsDraft) {
return true;
}
return false;
}
/**
* Set the page controller.
*
* @param \Concrete\Core\Page\Controller\PageController|null $controller
*/
public function setController($controller)
{
$this->controller = $controller;
}
/**
* @deprecated use the getPageController() method
*
* @return \Concrete\Core\Page\Controller\PageController
*/
public function getController()
{
return $this->getPageController();
}
/**
* This is the legacy function that is called just by xml. We pass these values in as though they were the old ones.
*
* @private
*
* @param \SimpleXMLElement $px
*/
public function assignPermissionSet($px)
{
if (isset($px->guests)) {
$pkHandles = self::translatePermissionsXMLToKeys($px->guests);
$this->assignPermissions(Group::getByID(GUEST_GROUP_ID), $pkHandles);
}
if (isset($px->registered)) {
$pkHandles = self::translatePermissionsXMLToKeys($px->registered);
$this->assignPermissions(Group::getByID(REGISTERED_GROUP_ID), $pkHandles);
}
if (isset($px->administrators)) {
$pkHandles = self::translatePermissionsXMLToKeys($px->administrators);
$this->assignPermissions(Group::getByID(ADMIN_GROUP_ID), $pkHandles);
}
if (isset($px->group)) {
foreach ($px->group as $g) {
$pkHandles = self::translatePermissionsXMLToKeys($px->administrators);
$this->assignPermissions(Group::getByID($g['gID']), $pkHandles);
}
}
if (isset($px->user)) {
foreach ($px->user as $u) {
$pkHandles = self::translatePermissionsXMLToKeys($px->administrators);
$this->assignPermissions(UserInfo::getByID($u['uID']), $pkHandles);
}
}
}
public function getSummaryTemplates(): array
{
$app = Application::getFacadeApplication();
$em = $app->make(EntityManagerInterface::class);
return $em->getRepository(\Concrete\Core\Entity\Page\Summary\PageTemplate::class)
->findByCID($this->getCollectionID());
}
/**
* @return CustomPageTemplateCollection
*/
protected function getCustomPageSummaryTemplateCollection()
{
$app = Application::getFacadeApplication();
$em = $app->make(EntityManagerInterface::class);
return $em->getRepository(CustomPageTemplateCollection::class)
->findOneByCID($this->getCollectionID());
}
public function hasCustomSummaryTemplates(): bool
{
if ($this->getCustomPageSummaryTemplateCollection()) {
return true;
}
return false;
}
public function getCustomSelectedSummaryTemplates(): array
{
$collection = $this->getCustomPageSummaryTemplateCollection();
if ($collection) {
$templates = $collection->getTemplates();
if ($templates) {
return $templates->toArray();
}
}
return [];
}
/**
* Make an alias to a page.
*
* @param \Concrete\Core\Page\Page $parentPage The parent page
* @param mixed $c
*
* @return int The ID of the new collection
*/
public function addCollectionAlias($c)
{
$app = Application::getFacadeApplication();
$db = Database::connection();
// the passed collection is the parent collection
$cParentID = $c->getCollectionID();
$u = $app->make(User::class);
$uID = $u->getUserID();
$handle = (string) $this->getCollectionHandle();
if ($handle === '') {
$handle = Core::make('helper/text')->handle($this->getCollectionName());
}
$cDisplayOrder = $c->getNextSubPageDisplayOrder();
$_cParentID = $c->getCollectionID();
$q = 'select PagePaths.cPath from PagePaths where cID = ?';
$v = [$_cParentID];
if ($_cParentID != static::getHomePageID()) {
$q .= ' and ppIsCanonical = ?';
$v[] = 1;
}
$cPath = $db->fetchColumn($q, $v);
$data = [
'handle' => $handle,
'name' => '',
];
$cobj = parent::addCollection($data);
$newCID = $cobj->getCollectionID();
$siteTreeID = $c->getSiteTreeID();
$v = [$newCID, $siteTreeID, $cParentID, $uID, $this->getCollectionID(), $cDisplayOrder];
$q = 'insert into Pages (cID, siteTreeID, cParentID, uID, cPointerID, cDisplayOrder) values (?, ?, ?, ?, ?, ?)';
$r = $db->prepare($q);
$r->execute($v);
PageStatistics::incrementParents($newCID);
$q2 = 'insert into PagePaths (cID, cPath, ppIsCanonical, ppGeneratedFromURLSlugs) values (?, ?, ?, ?)';
$v2 = [$newCID, $cPath . '/' . $handle, 1, 1];
$db->executeQuery($q2, $v2);
$pe = new Event(\Page::getByID($newCID));
Events::dispatch('on_page_alias_add', $pe);
return $newCID;
}
/**
* Update the alias details.
*
* @param array $data Supported keys:
* <ul>
* <li>string <code>customAliasName</code> empty string to use the name of the aliased page</li>
* <li>string <code>aliasHandle</code> the URL slug of the alias</li>
* </ul>
*/
public function updateCollectionAlias(array $data): void
{
if (!$this->isAliasPage()) {
return;
}
$app = Application::getFacadeApplication();
$data += [
'customAliasName' => null,
'aliasHandle' => '',
];
$cSet = [];
$cvSet = [];
if ((string) $data['aliasHandle'] !== '') {
$cSet['cHandle'] = $data['aliasHandle'];
$cvSet['cvHandle'] = $data['aliasHandle'];
}
if ($data['customAliasName'] !== null) {
$cvSet['cvName'] = $data['customAliasName'];
}
$db = $app->make(Connection::class);
if ($cSet !== []) {
$db->update(
'Collections',
$cSet,
['cID' => $this->getCollectionPointerOriginalID()]
);
}
if ($cvSet !== []) {