-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
284 lines (265 loc) · 8.28 KB
/
Copy pathadmin.php
File metadata and controls
284 lines (265 loc) · 8.28 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
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
<?php
/**
* Admin DSGVO snippet for Leaflet Map and its Extensions
*
* @package DSGVO snippet for Leaflet Map and its Extensions
**/
// Direktzugriff auf diese Datei verhindern.
defined( 'ABSPATH' ) || die();
// Add menu page
function leafext_dsgvo_add_page() {
// Add Submenu
$leafext_admin_page = add_submenu_page(
'leaflet-map',
'Leaflet Map ' . __( 'Options GDPR', 'dsgvo-leaflet-map' ),
'Leaflet Map ' . __( 'GDPR', 'dsgvo-leaflet-map' ),
'manage_options',
LEAFEXT_DSGVO_PLUGIN_NAME,
'leafext_dsgvo_do_page'
);
}
add_action( 'admin_menu', 'leafext_dsgvo_add_page', 90 );
function leafext_dsgvo_init() {
add_settings_section( 'leafext_dsgvo', '', '__return_empty_string', 'leafext_settings_dsgvo' );
$fields = leafext_dsgvo_params();
foreach ( $fields as $field ) {
add_settings_field(
'leafext_dsgvo[' . $field['param'] . ']',
$field['desc'],
'leafext_dsgvo_form',
'leafext_settings_dsgvo',
'leafext_dsgvo',
$field['param'],
);
}
$leafext_dsgvo = get_option( 'leafext_dsgvo' );
if ( $leafext_dsgvo === false ) {
add_option( 'leafext_dsgvo', array() );
}
register_setting(
'leafext_settings_dsgvo',
'leafext_dsgvo',
array(
'type' => 'array',
'sanitize_callback' => 'leafext_validate_dsgvo',
'default' => array(),
)
);
}
add_action( 'admin_init', 'leafext_dsgvo_init' );
function leafext_dsgvo_form( $field ) {
$options = leafext_dsgvo_params();
$option = leafext_array_find3( $field, $options );
$settings = leafext_dsgvo_settings();
$setting = $settings[ $field ];
if ( leafext_plugin_active( 'polylang-theme-translation' ) ) {
$ttfp = ' readonly ';
} else {
$ttfp = '';
}
switch ( $field ) {
case 'text':
echo '<textarea ' . esc_attr( $ttfp ) . ' name="leafext_dsgvo[text]" type="textarea" cols="80" rows="5">';
echo wp_kses_post( $setting );
echo '</textarea>';
break;
case 'mapurl':
echo '<input type="url" size="80" name="leafext_dsgvo[mapurl]" value="' . esc_url( $setting ) . '" />';
break;
case 'color':
leafext_dsgvo_colors( $option['default'], $setting );
break;
case 'cookie':
echo '<input type="number" size="5" min="1" max="365" name="leafext_dsgvo[cookie]" value="' . absint( $setting ) . '"> ';
esc_html_e( 'days', 'dsgvo-leaflet-map' );
break;
case 'count':
echo '<input type="radio" name="leafext_dsgvo[count]" value="1" ';
echo boolval( $setting ) ? 'checked' : '';
echo '> ';
esc_html_e( 'each map', 'dsgvo-leaflet-map' );
echo ' ';
echo '<input type="radio" name="leafext_dsgvo[count]" value="0" ';
echo ! boolval( $setting ) ? 'checked' : '';
echo '> ';
esc_html_e( 'only first', 'dsgvo-leaflet-map' );
echo ' ';
break;
case 'okay':
echo '<input type="text" ' . esc_attr( $ttfp ) . ' size="80" name="leafext_dsgvo[okay]" value="' . esc_attr( $setting ) . '" />';
break;
default:
wp_die( 'error' );
}
}
// Sanitize and validate input. Accepts an array, return a sanitized array.
function leafext_validate_dsgvo( $options ) {
check_admin_referer( 'leafext_dsgvo', 'leafext_dsgvo_nonce' );
if ( isset( $_POST['submit'] ) ) {
$defaults = array();
$params = leafext_dsgvo_params();
foreach ( $params as $param ) {
$defaults[ $param['param'] ] = $param['default'];
}
if ( isset( $options['cookie'] ) && ( $options['cookie'] === '0' || $options['cookie'] === '' ) ) {
$options['cookie'] = absint( $defaults['cookie'] );
}
if ( isset( $options['text'] ) ) {
$options['text'] = wp_kses_post( $options['text'] );
}
if ( isset( $options['mapurl'] ) ) {
$options['mapurl'] = sanitize_url( $options['mapurl'] );
}
if ( isset( $options['color'] ) ) {
$options['color'] = sanitize_text_field( $options['color'] );
}
if ( isset( $options['count'] ) ) {
$options['count'] = absint( $options['count'] );
}
if ( isset( $options['okay'] ) ) {
$options['okay'] = sanitize_text_field( $options['okay'] );
}
$change = array();
foreach ( $options as $key => $value ) {
if ( $value !== $defaults[ $key ] ) {
$change[ $key ] = $value;
}
}
return $change;
}
if ( isset( $_POST['delete'] ) ) {
delete_option( 'leafext_dsgvo' );
}
return false;
}
// Draw the menu page itself
function leafext_dsgvo_do_page() {
$tab = filter_input(
INPUT_GET,
'tab',
FILTER_CALLBACK,
array( 'options' => 'esc_html' )
);
$active_tab = $tab ? $tab : 'help';
echo '<div style="max-width: 1000px;">';
if ( ! leafext_plugin_active( 'leaflet-map' ) ) {
echo '<div class="wrap nothickbox">';
leafext_dsgvo_help();
echo '</div>' . "\n";
} else {
leafext_admin_dsgvo_tabs();
if ( strpos( $active_tab, 'shortcode' ) !== false ) {
include_once __DIR__ . '/admin/help-shortcode.php';
leafext_dsgvo_short_code_help();
} elseif ( strpos( $active_tab, 'time-delete' ) !== false ) {
include_once __DIR__ . '/admin/help-time-delete.php';
leafext_dsgvo_time_delete_help();
} elseif ( strpos( $active_tab, 'css' ) !== false ) {
include_once __DIR__ . '/admin/help-style.php';
echo wp_kses_post( leafext_dsgvo_css_help() );
} else {
if ( function_exists( 'leafext_dsgvo_updates_from_github' ) ) {
leafext_dsgvo_updates_from_github();
}
leafext_dsgvo_main_help();
}
}
echo '</div>';
}
// Suche bestimmten Wert in array im admin interface
function leafext_array_find3( $needle, $haystack ) {
foreach ( $haystack as $item ) {
if ( $item['param'] === $needle ) {
return $item;
}
}
}
// Baue Abfrage Farben
function leafext_dsgvo_colors( $defcolor, $value ) {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script(
'wp-color-picker-alpha',
plugins_url( '/js/wp-color-picker-alpha.min.js', __FILE__ ),
array( 'wp-color-picker' ),
LEAFEXT_DSGVO_PLUGIN_VERSION,
true
);
wp_enqueue_script(
'leafext-picker',
plugins_url( '/js/colorpicker.js', __FILE__ ),
array( 'wp-color-picker-alpha', 'wp-color-picker' ),
LEAFEXT_DSGVO_PLUGIN_VERSION,
true
);
echo '<input type="text" class="color-picker" id="leafext_dsgvo_color" name="leafext_dsgvo[color]" data-alpha-enabled="true" data-default-color="'
. esc_attr( $defcolor ) . '" value="' . esc_attr( $value ) . '">';
}
function leafext_admin_dsgvo_tabs() {
echo '<div class="wrap nothickbox">';
leafext_dsgvo_help();
echo '</div>' . "\n";
$tab = filter_input(
INPUT_GET,
'tab',
FILTER_CALLBACK,
array( 'options' => 'esc_html' )
);
$active_tab = $tab ? $tab : 'help';
echo '<h3 class="nav-tab-wrapper">';
echo '<a href="' . esc_url( '?page=' . LEAFEXT_DSGVO_PLUGIN_NAME . '&tab=help' ) . '" class="nav-tab';
echo $active_tab === 'help' ? ' nav-tab-active' : '';
echo '">' . esc_html__( 'Help', 'dsgvo-leaflet-map' ) . '</a>' . "\n";
$tabs = array(
array(
'tab' => 'shortcode',
'title' => 'leafext-cookie',
),
array(
'tab' => 'time-delete',
'title' => __( 'cookie-time & delete-cookie', 'dsgvo-leaflet-map' ),
),
array(
'tab' => 'css',
'title' => __( 'Styling', 'dsgvo-leaflet-map' ),
),
);
foreach ( $tabs as $tab ) {
echo '<a href="' . esc_url( '?page=' . LEAFEXT_DSGVO_PLUGIN_NAME . '&tab=' . $tab['tab'] ) . '" class="nav-tab';
$active = ( $active_tab === $tab['tab'] ) ? ' nav-tab-active' : '';
echo esc_attr( $active );
echo '">' . esc_html( $tab['title'] ) . '</a>' . "\n";
}
echo '</h3>';
}
function leafext_enqueue_dsgvo_admin() {
wp_enqueue_style(
'prism-css',
plugins_url( 'pkg/prism/prism.css', __FILE__ ),
array(),
LEAFEXT_DSGVO_PLUGIN_VERSION
);
wp_enqueue_script(
'prism-js',
plugins_url( 'pkg/prism/prism.js', __FILE__ ),
array(),
LEAFEXT_DSGVO_PLUGIN_VERSION,
true
);
}
function leafext_dsgvo_leaflet_map_needed() {
if ( ! leafext_plugin_active( 'leaflet-map' ) ) {
$uri = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ) );
if ( strpos( $uri, 'plugins.php' ) !== false || strpos( $uri, 'admin.php' ) !== false ) {
$message = '<div class="error"><p>' . sprintf(
/* translators: %s is a link. */
__( 'Please install and activate %1$sLeaflet Map%2$s before using %3$s.', 'dsgvo-leaflet-map' ),
'<a href="https://wordpress.org/plugins/leaflet-map/">',
'</a>',
__( 'DSGVO snippet for Leaflet Map and its Extensions', 'dsgvo-leaflet-map' )
) . '</p></div>';
echo wp_kses_post( $message );
}
}
}
add_action( 'admin_notices', 'leafext_dsgvo_leaflet_map_needed' );