-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathhome.class.php
More file actions
executable file
·114 lines (100 loc) · 4.54 KB
/
home.class.php
File metadata and controls
executable file
·114 lines (100 loc) · 4.54 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
require_once dirname(__DIR__) . '/index.class.php';
/**
* The name of the controller is based on the path (home) and the
* namespace (clientconfig). This home controller is the main client view.
*/
class ClientConfigHomeManagerController extends ClientConfigManagerController {
public $tabs = [];
/**
* Any specific processing we need on the Home controller.
* In this case, we get all groups and all settings in the group.
* @param array $scriptProperties
*/
public function process(array $scriptProperties = []) {
$tabs = [];
/**
* Get all the Groups
* @var cgGroup $group
* @var cgSetting $setting
*/
$c = $this->modx->newQuery('cgGroup');
$c->sortby('sortorder','ASC');
$c->sortby('label','ASC');
$groups = $this->modx->getCollection('cgGroup', $c);
foreach ($groups as $group) {
$grp = $group->toArray();
$grp['items'] = [];
$c = $this->modx->newQuery('cgSetting');
$c->sortby('sortorder','ASC');
$c->sortby('label','ASC');
foreach ($group->getMany('Settings', $c) as $setting) {
$sa = $setting->toArray();
if (in_array($sa['xtype'], ['checkbox','xcheckbox'], true)) {
$sa['value'] = (bool)$sa['value'];
}
if ($sa['xtype'] === 'googlefontlist') {
$googleFontsApiKey = $this->modx->getOption('clientconfig.google_fonts_api_key', null, '');
$sa['xtype'] = empty($googleFontsApiKey) ? 'textfield' : $sa['xtype'];
}
elseif ($setting->get('process_options') && in_array($sa['xtype'], ['modx-combo', 'radiogroup', 'xradiogroup'], true)) {
$inputOpts = $setting->get('options');
$this->modx->getParser();
$this->modx->parser->processElementTags('', $inputOpts, true, true);
$sa['options'] = $inputOpts;
}
$grp['items'][] = $sa;
}
$tabs[] = $grp;
}
$this->loadRichTextEditor();
$this->tabs = $tabs;
if (array_key_exists('context', $scriptProperties) && $this->modx->getOption('clientconfig.context_aware')) {
$key = $scriptProperties['context'];
$context = $this->modx->getObject('modContext', ['key' => $key]);
if ($context instanceof \modContext || $context instanceof \MODX\Revolution\modContext) {
$this->addHtml('<script type="text/javascript">
Ext.onReady(function() {
ClientConfig.initialContext = ' . $context->toJSON() . ';
});
</script>');
}
}
}
/**
* The pagetitle to put in the <title> attribute.
* @return null|string
*/
public function getPageTitle() {
return $this->modx->lexicon('clientconfig');
}
/**
* Register all the needed javascript files. Using this method, it will automagically
* combine and compress them if enabled in system settings.
*/
public function loadCustomCssJs() {
$this->addCss($this->clientconfig->config['jsUrl'] . 'mgr/extras/colorpicker/colorpicker.css');
$mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
$this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.panel.tv.renders.js');
$this->addJavascript($this->clientconfig->config['jsUrl'].'mgr/extras/colorpicker/colorpicker.js');
$this->addJavascript($this->clientconfig->config['jsUrl'].'mgr/extras/colorpicker/colorpickerfield.js');
$this->addJavascript($this->clientconfig->config['jsUrl'].'mgr/widgets/combos.js');
$this->addLastJavascript($this->clientconfig->config['jsUrl'].'mgr/sections/home.js');
$contextAware = $this->modx->getOption('clientconfig.context_aware') ? 'true' : 'false';
$this->addHtml('<script type="text/javascript">
Ext.onReady(function() {
ClientConfig.data = '.$this->modx->toJSON($this->tabs).';
ClientConfig.contextAware = ' . $contextAware . ';
ClientConfig.isAdmin = ' . (($this->clientconfig->hasAdminPermission()) ? '1' : '0') .';
MODx.load({ xtype: "clientconfig-page-home" });
});
</script>');
}
/**
* The name for the template file to load.
* @return string
*/
public function getTemplateFile() {
return $this->clientconfig->config['templatesPath'].'home.tpl';
}
}