/
AbstractPageContentRoutine.php
64 lines (56 loc) · 2.88 KB
/
AbstractPageContentRoutine.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
<?php
namespace Concrete\Core\Backup\ContentImporter\Importer\Routine;
use Concrete\Core\Backup\ContentImporter;
use Concrete\Core\Block\Block;
use Concrete\Core\Block\BlockType\BlockType;
use Concrete\Core\Page\Page;
use Concrete\Core\StyleCustomizer\Inline\StyleSet;
abstract class AbstractPageContentRoutine extends AbstractRoutine
{
public function importPageAreas(Page $page, \SimpleXMLElement $px)
{
foreach ($px->area as $ax) {
if (isset($ax->blocks)) {
foreach ($ax->blocks->block as $bx) {
if ($bx['type'] != '') {
// we check this because you might just get a block node with only an mc-block-id, if it's an alias
$bt = BlockType::getByHandle((string) $bx['type']);
if (!is_object($bt)) {
throw new \Exception(t('Invalid block type handle: %s', strval($bx['type'])));
}
$btc = $bt->getController();
$btc->import($page, (string) $ax['name'], $bx);
} else {
if ($bx['mc-block-id'] != '') {
// we find that block in the master collection block pool and alias it out
$bID = array_search((string) $bx['mc-block-id'], ContentImporter::getMasterCollectionTemporaryBlockIDs());
if ($bID) {
$mc = Page::getByID($page->getMasterCollectionID(), 'RECENT');
$block = Block::getByID($bID, $mc, (string) $ax['name']);
$block->alias($page);
if ($block->getBlockTypeHandle() == BLOCK_HANDLE_LAYOUT_PROXY) {
// we have to go get the blocks on that page in this layout.
$btc = $block->getController();
$arLayout = $btc->getAreaLayoutObject();
$columns = $arLayout->getAreaLayoutColumns();
foreach ($columns as $column) {
$area = $column->getAreaObject();
$blocks = $area->getAreaBlocksArray($mc);
foreach ($blocks as $_b) {
$_b->alias($page);
}
}
}
}
}
}
}
}
if (isset($ax->style)) {
$area = \Area::get($page, (string) $ax['name']);
$set = StyleSet::import($ax->style);
$page->setCustomStyleSet($area, $set);
}
}
}
}