-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.php
315 lines (277 loc) · 11.7 KB
/
settings.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class AstrometrySettings {
private $astrometry_settings_options;
public function __construct() {
add_action( 'admin_menu', array( $this, 'astrometry_settings_add_plugin_page' ) );
add_action( 'admin_init', array( $this, 'astrometry_settings_page_init' ) );
add_filter( 'plugin_action_links', array($this, 'my_add_action_links'), 10, 5 );
}
public function astrometry_settings_add_plugin_page() {
add_plugins_page(
__('Astrometry Settings','astrometry'),
__('Astrometry Settings','astrometry'),
'manage_options',
'astrometry-settings',
array( $this, 'astrometry_settings_create_admin_page' )
);
}
public function my_add_action_links( $links, $plugin_file ) {
if($plugin_file != ASTROMETRY_PLUGIN_BASE)
return $links;
return array_merge(
array(
'settings' => '<a href="' . admin_url( 'plugins.php?page=astrometry-settings' ) . '">' . __( 'Settings', 'astrometry' ) . '</a>'
),
$links
);
}
public function astrometry_settings_create_admin_page() {
$this->astrometry_settings_options = get_option( 'astrometry_settings' ); ?>
<div class="wrap">
<h2><?= __('Astrometry Settings','astrometry') ?></h2>
<p></p>
<?php settings_errors(); ?>
<script>
jQuery(document).ready(function($){
//Set fields for additional catalogues disabled/enables
jQuery('.additionalCatalogues').prop("disabled", !jQuery('#additionalCatalogues').is(':checked'))
jQuery('#additionalCatalogues').change(function() {
jQuery('.additionalCatalogues').prop("disabled", !jQuery('#additionalCatalogues').is(':checked'))
});
});
</script>
<form method="post" action="options.php">
<?php
settings_fields( 'astrometry_settings_option_group' );
do_settings_sections( 'astrometry-settings-admin' );
submit_button();
?>
</form>
</div>
<?php }
public function astrometry_settings_page_init() {
register_setting(
'astrometry_settings_option_group',
'astrometry_settings',
array( $this, 'astrometry_settings_sanitize' )
);
add_settings_section(
'astrometry_settings_setting_section',
'Settings',
array( $this, 'astrometry_settings_section_info' ),
'astrometry-settings-admin'
);
add_settings_field(
'api_key',
__('API-KEY','astrometry'),
array( $this, 'api_key_callback' ),
'astrometry-settings-admin',
'astrometry_settings_setting_section'
);
add_settings_field(
'image_quality',
__('Image Quality','astrometry'),
array( $this, 'image_quality_callback' ),
'astrometry-settings-admin',
'astrometry_settings_setting_section'
);
add_settings_section(
'astrometry_settings_annotation_section',
__('Annotation','astrometry'),
array( $this, 'astrometry_settings_section_info' ),
'astrometry-settings-admin'
);
add_settings_field(
'color_ngc',
__('NGC catalogue color','astrometry'),
array( $this, 'ngc_color_callback' ),
'astrometry-settings-admin',
'astrometry_settings_annotation_section'
);
add_settings_field(
'color_ic',
__('IC catalogue color','astrometry'),
array( $this, 'ic_color_callback' ),
'astrometry-settings-admin',
'astrometry_settings_annotation_section'
);
add_settings_field(
'color_bright',
__('Bright stars color','astrometry'),
array( $this, 'bright_color_callback' ),
'astrometry-settings-admin',
'astrometry_settings_annotation_section'
);
add_settings_field(
'color_hd',
__('HD catalogue color','astrometry'),
array( $this, 'hd_color_callback' ),
'astrometry-settings-admin',
'astrometry_settings_annotation_section'
);
add_settings_field(
'annotation_css',
__('Additional CSS','astrometry'),
array( $this, 'annotation_css_callback' ),
'astrometry-settings-admin',
'astrometry_settings_annotation_section'
);
add_settings_field(
'additionalCatalogues',
__('Additional Catalogues','astrometry'),
array( $this, 'additionalCatalogues_callback' ),
'astrometry-settings-admin',
'astrometry_settings_annotation_section'
);
add_settings_field(
'color_messier',
__('Messier catalogue color','astrometry'),
array( $this, 'messier_color_callback' ),
'astrometry-settings-admin',
'astrometry_settings_annotation_section'
);
add_settings_field(
'celestialCoordinateGrid',
__('Celestial coordinate grid','astrometry'),
array( $this, 'celestialCoordinateGrid_callback' ),
'astrometry-settings-admin',
'astrometry_settings_annotation_section'
);
add_settings_field(
'color_celestialCoordinateGrid',
__('Celestial coordinate grid color','astrometry'),
array( $this, 'celestialCoordinateGrid_color_callback' ),
'astrometry-settings-admin',
'astrometry_settings_annotation_section'
);
}
public function astrometry_settings_sanitize($input) {
$sanitary_values = array();
if ( isset( $input['api_key'] ) ) {
$sanitary_values['api_key'] = sanitize_text_field( $input['api_key'] );
}
if ( isset( $input['image_quality'] ) ) {
$sanitary_values['image_quality'] = sanitize_text_field( $input['image_quality'] );
}
if ( isset( $input['color_ngc'] ) ) {
$sanitary_values['color_ngc'] = sanitize_text_field( $input['color_ngc'] );
}
if ( isset( $input['color_ic'] ) ) {
$sanitary_values['color_ic'] = sanitize_text_field( $input['color_ic'] );
}
if ( isset( $input['color_bright'] ) ) {
$sanitary_values['color_bright'] = sanitize_text_field( $input['color_bright'] );
}
if ( isset( $input['color_hd'] ) ) {
$sanitary_values['color_hd'] = sanitize_text_field( $input['color_hd'] );
}
if ( isset( $input['annotation_css'] ) ) {
$sanitary_values['annotation_css'] = sanitize_text_field( $input['annotation_css'] );
}
if ( isset( $input['additionalCatalogues'] ) ) {
$sanitary_values['additionalCatalogues'] = $input['additionalCatalogues'];
}
if ( isset( $input['color_messier'] ) ) {
$sanitary_values['color_messier'] = sanitize_text_field( $input['color_messier'] );
}
if ( isset( $input['celestialCoordinateGrid'] ) ) {
$sanitary_values['celestialCoordinateGrid'] = $input['celestialCoordinateGrid'];
}
if ( isset( $input['color_celestialCoordinateGrid'] ) ) {
$sanitary_values['color_celestialCoordinateGrid'] = sanitize_text_field( $input['color_celestialCoordinateGrid'] );
}
return $sanitary_values;
}
public function astrometry_settings_section_info() {
}
public function api_key_callback() {
printf(
'<input class="regular-text" type="text" name="astrometry_settings[api_key]" id="api_key" value="%s">',
isset( $this->astrometry_settings_options['api_key'] ) ? esc_attr( $this->astrometry_settings_options['api_key']) : ''
);
echo "<br><a href='http://nova.astrometry.net' target='_blank'>" . __('Get an API Key','astrometry') . "</a>";
}
public function image_quality_callback() {
printf(
'<input type="number" name="astrometry_settings[image_quality]" id="image_quality" value="%s">',
isset( $this->astrometry_settings_options['image_quality'] ) ? esc_attr( $this->astrometry_settings_options['image_quality']) : '82'
);
echo "<br>" . __('Imagequality 1-100. Overrides the global Wordpress setting (82).','astrometry');
}
public function ngc_color_callback() {
printf(
'<input class="color-picker" type="color" data-default-color="#cc0000" name="astrometry_settings[color_ngc]" id="color_ngc" value="%s">',
isset( $this->astrometry_settings_options['color_ngc'] ) ? esc_attr( $this->astrometry_settings_options['color_ngc']) : '#cc0000'
);
echo "<br>" . __('Color for NGC catalogue annotation','astrometry');
}
public function ic_color_callback() {
printf(
'<input class="color-picker" type="color" data-default-color="#6699ff" name="astrometry_settings[color_ic]" id="color_ic" value="%s">',
isset( $this->astrometry_settings_options['color_ic'] ) ? esc_attr( $this->astrometry_settings_options['color_ic']) : '#6699ff'
);
echo "<br>" . __('Color for IC catalogue annotation','astrometry');
}
public function bright_color_callback() {
printf(
'<input class="color-picker" type="color" data-default-color="#CCC" name="astrometry_settings[color_bright]" id="color_bright" value="%s">',
isset( $this->astrometry_settings_options['color_bright'] ) ? esc_attr( $this->astrometry_settings_options['color_bright']) : '#CCC'
);
echo "<br>" . __('Color for bright stars (named stars) annotation','astrometry');
}
public function hd_color_callback() {
printf(
'<input class="color-picker" type="color" data-default-color="#CCC" name="astrometry_settings[color_hd]" id="color_hd" value="%s">',
isset( $this->astrometry_settings_options['color_hd'] ) ? esc_attr( $this->astrometry_settings_options['color_hd']) : '#CCC'
);
echo "<br>" . __('Color for HD annotation','astrometry');
}
public function annotation_css_callback() {
printf(
'<textarea name="astrometry_settings[annotation_css]" id="annotation_css" class="regular-text">%s</textarea>',
isset( $this->astrometry_settings_options['annotation_css'] ) ? esc_attr( $this->astrometry_settings_options['annotation_css']) : ''
);
echo "<br>" . __('Additional CSS for SVG annotation styling','astrometry');
}
public function additionalCatalogues_callback() {
printf(
'<input type="checkbox" id="additionalCatalogues" name="astrometry_settings[additionalCatalogues]" value="1" %s>',
isset( $this->astrometry_settings_options['additionalCatalogues'] ) ? "checked" : ""
);
echo __('Objects of NGC, IC are shown as objects of additional cataglogues (Messier)','astrometry');
}
public function messier_color_callback() {
printf(
'<input class="color-picker additionalCatalogues" type="color" data-default-color="#CCC" name="astrometry_settings[color_messier]" id="color_messier" value="%s">',
isset( $this->astrometry_settings_options['color_messier'] ) ? esc_attr( $this->astrometry_settings_options['color_messier']) : '#CCC'
);
echo "<br>" . __('Color for Messier annotation','astrometry');
}
public function celestialCoordinateGrid_callback() {
printf(
'<input type="checkbox" id="celestialCoordinateGrid" name="astrometry_settings[celestialCoordinateGrid]" value="1" %s>',
isset( $this->astrometry_settings_options['celestialCoordinateGrid'] ) ? "checked" : ""
);
echo __('Show celestial coordinate grid','astrometry');
}
public function celestialCoordinateGrid_color_callback() {
printf(
'<input class="color-picker" type="color" data-default-color="#CCC" name="astrometry_settings[color_celestialCoordinateGrid]" id="color_celestialCoordinateGrid" value="%s">',
isset( $this->astrometry_settings_options['color_celestialCoordinateGrid'] ) ? esc_attr( $this->astrometry_settings_options['color_celestialCoordinateGrid']) : '#CCC'
);
echo "<br>" . __('Color for celestial coordinate grid','astrometry');
}
}