-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethod.install.php
More file actions
96 lines (92 loc) · 3.52 KB
/
method.install.php
File metadata and controls
96 lines (92 loc) · 3.52 KB
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
<?php
/** @var NetDesign $this */
if (!isset($gCms)) exit;
// Create permission(s)
$this->CreatePermission('NetDesign.usage', 'NetDesign CMS: Manage NetDesign CMS settings');
// Copy imagecache.php to the uploads directory
$src = cms_join_path($this->GetModulePath(), 'imagecache.php');
$dst = cms_join_path($this->config['uploads_path'], 'imagecache.php');
chmod($dst, 0664);
copy($src, $dst);
$cfg = array(
'design' => array('name' => 'NetDesign CMS'),
'template' => array('name' => 'NetDesign CMS Template', 'content' => '{NetDesign template="design.tpl"}{capture assign=$content}{content}{/capture}'),
'navigation' => array('name' => 'NetDesign CMS Navigation', 'content' => '{NetDesign action="template" template="navigation.tpl"}')
);
if (NetDesign::GetCMSVersion() == 1) {
// Unset default for all existing templates
$tpls = TemplateOperations::get_instance()->LoadTemplates();
foreach($tpls as $tpl) {
/** @var Template $tpl */
$tpl->default = 0;
$tpl->Save();
}
unset($tpls);
// Create template
$tpl = TemplateOperations::get_instance()->LoadTemplateByContentAlias($cfg['template']['name']);
if (!($tpl instanceof Template)) {
$tpl = new Template();
$tpl->name = $cfg['template']['name'];
$tpl->content = $cfg['template']['content'];
}
$tpl->default = true;
$tpl->active = true;
$tpl->Save();
// Create navigation
/** @var ModuleOperations $mops */
$mops = ModuleOperations::get_instance();
/** @var MenuManager $mod */
$mod = $mops->get_module_instance('MenuManager');
$mod->SetTemplate($cfg['navigation']['name'], $cfg['navigation']['content']);
$mod->SetPreference('default_template', $cfg['navigation']['name']);
// Set the template for every existing page
$pages = ContentOperations::get_instance()->GetAllContent();
foreach($pages as $page) {
/** @var ContentBase $page */
$page->SetTemplateId($tpl->Id());
$page->Save();
}
} else {
// Create design
// 1. Design
try {
$design = new CmsLayoutCollection();
$design->set_name($cfg['design']['name']);
$design->set_default(true);
$design->save();
} catch (Exception $e) {
}
// 2. Template
try {
$tpl = new CmsLayoutTemplate();
$tpl->set_type(CmsLayoutTemplateType::load(sprintf('%s::page', CmsLayoutTemplateType::CORE)));
$tpl->set_name($cfg['template']['name']);
$tpl->set_content($cfg['template']['content']);
$tpl->set_type_dflt(true);
$tpl->set_designs(array($design->get_id()));
$tpl->save();
} catch (Exception $e) {
}
// 3. Navigation
try {
$menu = new CmsLayoutTemplate();
$menu->set_type(CmsLayoutTemplateType::load('Navigator::navigation'));
$tpl->set_name($cfg['navigation']['name']);
$tpl->set_content($cfg['navigation']['content']);
$menu->set_type_dflt(true);
$menu->set_designs(array($design->get_id()));
$menu->save();
} catch (Exception $e) {
}
try {
// 4. Set the design and template for every existing page
$pages = ContentOperations::get_instance()->GetAllContent();
foreach($pages as $page) {
/** @var ContentBase $page */
$page->SetPropertyValue('design_id', $design->get_id());
$page->SetTemplateId($tpl->get_id());
$page->Save();
}
} catch (Exception $e) {
}
}