-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathboot.php
178 lines (144 loc) · 6.4 KB
/
boot.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
<?php
/**
* @var rex_addon $this
* @psalm-scope-this rex_addon
*/
rex_yform::addTemplatePath(rex_path::addon('yform', 'ytemplates'));
if (rex::isBackend() && rex::getUser()) {
/* @var $this rex_addon */
rex_view::addCssFile($this->getAssetsUrl('yform.css'));
rex_view::addCssFile($this->getAssetsUrl('yform-formbuilder.css'));
rex_extension::register('PACKAGES_INCLUDED', function () {
if ($this->getProperty('compile')) {
$compiler = new rex_scss_compiler();
$compiler->setRootDir($this->getPath('scss/'));
$compiler->setScssFile($this->getPath('scss/yform.scss'));
$compiler->setCssFile($this->getPath('assets/yform.css'));
$compiler->compile();
$compiler->setScssFile($this->getPath('scss/yform-formbuilder.scss'));
$compiler->setCssFile($this->getPath('assets/yform-formbuilder.css'));
$compiler->compile();
rex_dir::copy($this->getPath('assets'), $this->getAssetsPath()); // copy whole assets directory
}
});
rex_extension::register('PAGE_CHECKED', static function (rex_extension_point $ep) {
$page = rex_be_controller::getPageObject('yform');
if (!$page) {
return;
}
$subpages = $page->getSubpages();
if (isset($subpages['manager']) && rex::getUser()->isAdmin()) {
$manager = $subpages['manager'];
unset($subpages['manager']);
$subpages = array_merge(['manager' => $manager], $subpages);
$page->setSubpages($subpages);
}
if (!$subpages || 1 === count($subpages) && isset($subpages['manager'])) {
$page->setHidden(true);
}
});
}
// E-Mail
rex_extension::register('EDITOR_URL', static function (rex_extension_point $ep) {
if (preg_match('@^rex:///yform/email/template/(.*)/(.*)@', $ep->getParam('file'), $match)) {
return rex_url::backendPage(
'yform/email/index',
[
'func' => 'edit',
'template_key' => $match[1],
],
);
}
});
// REST
rex_extension::register('PACKAGES_INCLUDED', static function () {
if (!rex::isBackend()) {
rex_yform_rest::handleRoutes();
}
});
// Tools
if (rex::isBackend() && rex::getUser()) {
rex_view::addJsFile($this->getAssetsUrl('daterangepicker/moment.min.js'));
rex_view::addJsFile($this->getAssetsUrl('daterangepicker/daterangepicker.js'));
rex_view::addCssFile($this->getAssetsUrl('daterangepicker/daterangepicker.css'));
rex_view::addJsFile($this->getAssetsUrl('inputmask/dist/jquery.inputmask.min.js'));
rex_view::addJsFile($this->getAssetsUrl('tools.js'));
}
// Manager
rex_complex_perm::register('yform_manager_table_edit', 'rex_yform_manager_table_perm_edit');
rex_complex_perm::register('yform_manager_table_view', 'rex_yform_manager_table_perm_view');
if (rex::isBackend() && rex::getUser()) {
rex_extension::register('PACKAGES_INCLUDED', function () {
if ($this->getProperty('compile')) {
$compiler = new rex_scss_compiler();
$compiler->setRootDir($this->getPath('scss/'));
$compiler->setScssFile($this->getPath('scss/manager.scss'));
$compiler->setCssFile($this->getPath('assets/manager.css'));
$compiler->compile();
rex_dir::copy($this->getPath('assets'), $this->getAssetsPath()); // copy whole assets directory
}
});
rex_view::addJsFile($this->getAssetsUrl('manager.js'));
rex_view::addJsFile($this->getAssetsUrl('relations.js'));
rex_view::addCssFile($this->getAssetsUrl('manager.css'));
rex_view::addJsFile($this->getAssetsUrl('widget.js'));
if (!rex::getUser()->isAdmin()) {
$page = $this->getProperty('page');
$page['hidden'] = true;
$this->setProperty('page', $page);
}
try {
$tables = rex_yform_manager_table::getAll();
} catch (Exception $e) {
$tables = [];
}
$pages = [];
$prio = 1;
foreach ($tables as $table) {
if ($table->isActive() && $table->isGranted('VIEW', rex::getUser())) {
$be_page = new rex_be_page_main('yform_tables', $table->getTableName(), rex_escape($table->getNameLocalized()));
$be_page->setHref('index.php?page=yform/manager/data_edit&table_name=' . $table->getTableName());
$icon = rex_escape($table->getCustomIcon() ?: 'rex-icon-module');
$be_page->setIcon('rex-icon ' . $icon);
$be_page->setPrio($prio);
if ($table->isHidden()) {
$be_page->setHidden();
}
if ('yform/manager/data_edit' == rex_request('page', 'string') && rex_request('table_name', 'string') == $table->getTableName()) {
$be_page->setIsActive();
$main_page = $this->getAddon()->getProperty('page');
$main_page['isActive'] = false;
$rex_yform_manager_opener = rex_request('rex_yform_manager_opener', 'array');
$rex_yform_manager_popup = rex_request('rex_yform_manager_popup', 'int');
$rex_yform_filter = rex_request('rex_yform_filter', 'array');
if ((isset($rex_yform_manager_opener['id']) && '' != $rex_yform_manager_opener['id']) || 1 == $rex_yform_manager_popup) {
$main_page['popup'] = true;
}
$this->getAddon()->setProperty('page', $main_page);
}
$pages[] = $be_page;
++$prio;
}
}
$this->setProperty('pages', $pages);
}
rex_extension::register('MEDIA_IS_IN_USE', 'rex_yform_value_be_media::isMediaInUse');
rex_extension::register('PACKAGES_INCLUDED', 'rex_yform_value_be_link::isArticleInUse');
rex_extension::register('YFORM_SAVED', static function (rex_extension_point $ep) {
if ($ep->getSubject() instanceof Exception) {
return;
}
$table = rex_yform_manager_table::get($ep->getParam('table'));
if (!$table) {
return;
}
$dataset = $ep->getParam('form')->getParam('manager_dataset');
if (!$dataset) {
$dataset = rex_yform_manager_dataset::getRaw($ep->getParam('id'), $table->getTableName());
}
$dataset->invalidateData();
if ($table->hasHistory() && $dataset->isHistoryEnabled()) {
$action = 'insert' === $ep->getParam('action') ? rex_yform_manager_dataset::ACTION_CREATE : rex_yform_manager_dataset::ACTION_UPDATE;
$dataset->makeSnapshot($action);
}
});