This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invitation_manager.admin.inc
205 lines (170 loc) · 7.56 KB
/
invitation_manager.admin.inc
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
/**
* Form that is loaded to create the settings page
*/
function invitation_manager_admin() {
$form = array();
$form['admin'] = array(
'#type' => 'fieldset',
'#title' => t('Invitation Manager Settings'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$enable_options = array(
'on' => t('Enabled'),
'off' => t('Disabled'),
);
$form['admin']['invitation_manager_enabled'] = array(
'#type' => 'radios',
'#title' => t('Invitation Manager'),
'#options' => $enable_options,
'#default_value' => variable_get('invitation_manager_enabled', 'off'),
);
$form['admin']['invitation_manager_aa_enabled'] = array(
'#type' => 'radios',
'#title' => t('Enable Adobe Analytics tracking of popups'),
'#options' => $enable_options,
'#default_value' => variable_get('invitation_manager_aa_enabled', 'off'),
);
// Per-role visibility.
$role_options = array_map('check_plain', user_roles());
$form['admin']['invitation_manager_roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Limit Invitation Manager for specific roles'),
'#default_value' => variable_get('invitation_manager_roles', array()),
'#options' => $role_options,
'#description' => t('Include scripts only for the selected role(s). If you select no roles, the scripts will be included for all users.'),
);
$form['admin']['invitation_manager_token'] = array(
'#type' => 'radios',
'#title' => t('Enable time token on local menu path'),
'#options' => $enable_options,
'#default_value' => variable_get('invitation_manager_token', 'on'),
);
/*
$form['admin']['invitation_manager_filemode'] = array(
'#type' => 'radios',
'#title' => t('On save use module files or pull from github'),
'#options' => array(
'local' => t('Local Files'),
'remote' => t('Download current from <a href="https://github.com/ServiceCanada/invitation-manager">github</a>'),
),
'#default_value' => variable_get('invitation_manager_filemode', 'local'),
'#description' => t('The github files will alaways be the most current. Re-save this page to update the included files.'),
);
*/
/*
$form['admin']['invitation_manager_mode'] = array(
'#type' => 'radios',
'#title' => t('What mode to run for im.json'),
'#options' => array(
'track' => t('Tracked url (logging)'),
'file' => t('Saved File (faster)'),
),
'#default_value' => variable_get('invitation_manager_mode', 'file'),
);
*/
return system_settings_form($form);
}
function invitation_manager_admin_validate($form, $form_state) {
}
/**
* Form that is loaded to create the settings page
*/
function invitation_manager_surveys($form, &$form_state) {
$form = array();
$form['config'] = array(
'#type' => 'fieldset',
'#title' => t('Manage the configuration file'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$enabled = variable_get('invitation_manager_enabled', 'on');
if ($enabled != 'on') {
$form['config']['note'] = array(
'#markup' => '<p><em><strong>'.t('Note: Invitation Manager is disabled.').'</strong></em></p>'
);
}
// ---
$options = array(
BLOCK_VISIBILITY_NOTLISTED => t('All pages except those listed'),
BLOCK_VISIBILITY_LISTED => t('Only the listed pages'),
);
$description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
$form['config']['invitation_manager_visibility'] = array(
'#type' => 'radios',
'#title' => t('Show block on specific pages'),
'#options' => $options,
'#default_value' => variable_get('invitation_manager_visibility', BLOCK_VISIBILITY_NOTLISTED),
);
$form['config']['invitation_manager_pages'] = array(
'#type' => 'textarea',
'#title' => '<span class="element-invisible">' . t('Pages') . '</span>',
'#default_value' => variable_get('invitation_manager_pages', ''),
'#description' => $description,
);
// ---
/*$form['config']['invitation_manager_placeholder_en'] = array(
'#type' => 'textarea',
'#title' => t('Placeholder HTML (English)'),
'#default_value' => variable_get('invitation_manager_placeholder_en', ''),
'#description' => t('L1 menu to embed in the page. Just the <li> entries'),
);*/
$imjson = variable_get('invitation_manager_imjson');
if (empty($imjson) || strlen($imjson) < 24) {
$imjson = invitation_manager_get_default_imjson();
}
$form['config']['note'] = [
'#markup' => '<p>You may want to read the <a href="https://github.com/ServiceCanada/invitation-manager/wiki/Installation-Guide">Installation Guide</a> since it includes details about the configuration file.</p>',
];
$form['config']['invitation_manager_imjson'] = array(
'#type' => 'textarea',
'#title' => t('im.json configuration file'),
'#default_value' => $imjson,
'#rows' => 50,
'#description' => t('If needed, the default file and documentation are in the git repo: https://github.com/ServiceCanada/invitation-manager. You can use the JSONlint page here to validate your configuration file https://jsonlint.com/.'),
);
$form['config']['documentation'] = array(
'#markup' => <<< HTML
<p>To test the site. Go to a page you think it should work on and add testing parameters to the URL like this:<br>
Scope Site: https://www.dev.nrcan.gc.ca/energy-efficiency-homes/20546?logim=1&im_scope=site&im_nocookiecheck=1&im_nodatecheck=1 or<br>
Scope Page: https://www.dev.nrcan.gc.ca/energy-efficiency-homes/20546?logim=1&im_scope=page&im_nocookiecheck=1&im_nodatecheck=1
</p>
HTML
);
$form = system_settings_form($form);
// Save the saved file to disk
$form['#submit'][] = 'invitation_manager_surveys_save_files';
return $form;
}
function invitation_manager_surveys_validate($form, $form_state) {
}
function invitation_manager_surveys_save_files($form, $form_state) {
$file_contents = !empty($form_state['values']['invitation_manager_imjson'])? $form_state['values']['invitation_manager_imjson'] : FALSE;
$date = 'backups/'.date('Y-m-d_G-i-s');
if (!empty($file_contents)) {
$file_destination = 'public://invitation_manager/';
$file_path = 'im.json';
$backups_folder = 'public://invitation_manager/backups';
if (!file_prepare_directory($backups_folder, FILE_CREATE_DIRECTORY)) {
watchdog('invitation_manager', 'Failed to create invitation_manager backups directory: %dirpath', array('%dirpath' => $library_folder_directory), WATCHDOG_ERROR);
return FALSE;
}
//$file_contents = check_markup($file_contents, 'full_html', $lang, FALSE);
// Save both the new file and a timestamped backup
$output_imfile = $file_destination.$file_path;
$result = file_unmanaged_save_data($file_contents, $output_imfile, FILE_EXISTS_REPLACE);
$result = file_unmanaged_save_data($file_contents, $file_destination.$date.'_'.$file_path);
if (function_exists('cloudfront_path_invalidate_invalidate_on_cloudfront')) {
$absolute_imfile = file_create_url($output_imfile);
$imfile_path = parse_url($absolute_imfile);
$output_conffile = $file_destination.'config.JSON';
$absolute_conffile = file_create_url($output_conffile);
$conffile_path = parse_url($absolute_conffile);
$clear_files = [$imfile_path['path'], $conffile_path['path']];
cloudfront_path_invalidate_invalidate_on_cloudfront($clear_files);
}
}
// Save/Update other files.
invitation_manager_prep_library();
}