/
inspect.php
92 lines (81 loc) · 3.1 KB
/
inspect.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
<?php
namespace Concrete\Controller\SinglePage\Dashboard\Pages\Themes;
use Concrete\Core\Package\PackageService;
use Concrete\Core\Page\Controller\DashboardPageController;
use Concrete\Core\Page\Template as PageTemplate;
use Concrete\Core\Page\Theme\Theme as PageTheme;
use Exception;
class Inspect extends DashboardPageController
{
public function on_before_render()
{
parent::on_before_render();
$this->set('pageTitle', t('Page Templates in Theme'));
}
// grab all the page types from within a theme
public function view($pThemeID = null, $message = false)
{
if (!$pThemeID) {
return $this->buildRedirect('/dashboard/pages/themes/');
}
$v = $this->app->make('helper/validation/error');
$pt = PageTheme::getByID($pThemeID);
if (is_object($pt)) {
$files = $pt->getFilesInTheme();
$this->set('files', $files);
$this->set('pThemeID', $pThemeID);
$this->set('pageTheme', $pt);
} else {
$v->add('Invalid Theme');
}
switch ($message) {
case 'install':
$this->set(
'message',
t(
'Theme installed. You may automatically create page templates from template files contained in your theme using the form below.'
)
);
break;
case 'activate':
$this->set(
'message',
t(
'Theme activated. You may automatically create page templates from template files contained in your theme using the form below.'
)
);
break;
}
if ($v->has()) {
$this->set('error', $v);
}
$this->set('disableThirdLevelNav', true);
}
public function activate_files($pThemeID)
{
try {
$pt = PageTheme::getByID($pThemeID);
if (!is_array($this->request->request->get('pageTemplates'))) {
throw new Exception(t('You must specify at least one template to create.'));
}
$pkg = false;
$pkgHandle = $pt->getPackageHandle();
if ($pkgHandle) {
$pkg = $this->app->make(PackageService::class)->getByHandle($pkgHandle);
}
$txt = $this->app->make('helper/text');
foreach ($this->post('pageTemplates') as $pTemplateHandle) {
$pTemplateName = $txt->unhandle($pTemplateHandle);
$pTemplateIcon = $pTemplateHandle . '.png';
if (!file_exists(DIR_FILES_PAGE_TEMPLATE_ICONS . '/' . $pTemplateIcon)) {
$pTemplateIcon = FILENAME_PAGE_TEMPLATE_DEFAULT_ICON;
}
$ct = PageTemplate::add($pTemplateHandle, $pTemplateName, $pTemplateIcon, $pkg);
}
$this->set('success', t('Files in the theme were activated successfully.'));
} catch (Exception $e) {
$this->set('error', $e);
}
$this->view($pThemeID);
}
}