PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.37
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.37
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
wp-data-access / WPDataAccess / Settings / WPDA_Settings_DataTables.php

WPDA_Settings_DataTables.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.37, at WPDataAccess/Settings/WPDA_Settings_DataTables.php

467 lines 18.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDataAccess\Settings;
4
5 use WPDataAccess\Utilities\WPDA_Message_Box;
6 use WPDataAccess\WPDA;
7 class WPDA_Settings_DataTables extends WPDA_Settings {
8 // jQuery DataTables language settings
9 // DO NOT CHANGE THESE LANGUAGES!!!!
10 // The language text is used in a URL. Changing a language results in a 404 for that language.
11 const FRONTEND_LANG = array(
12 'Afrikaans' => 'af',
13 'Albanian' => 'sq',
14 'Amharic' => 'am',
15 'Arabic' => 'ar',
16 'Armenian' => 'hy',
17 'Azerbaijan' => 'az-AZ',
18 'Bangla' => 'bn',
19 'Basque' => 'eu',
20 'Belarusian' => 'bg',
21 'Bosnian' => 'bs-BA',
22 'Bulgarian' => 'bg',
23 'Catalan' => 'ca',
24 'Chinese' => 'zh',
25 'Chinese-traditional' => 'zh-HANT',
26 'Corsican' => 'co',
27 'Croatian' => 'hr',
28 'Czech' => 'cs',
29 'Danish' => 'da',
30 'Dutch' => 'nl-NL',
31 'English' => 'en-GB',
32 'Esperanto' => 'eo',
33 'Estonian' => 'et',
34 'Filipino' => 'fil',
35 'Finnish' => 'fi',
36 'French' => 'fr-FR',
37 'Galician' => 'gl',
38 'Georgian' => 'ka',
39 'German' => 'de-DE',
40 'Greek' => 'el',
41 'Gujarati' => 'gu',
42 'Hebrew' => 'he',
43 'Hindi' => 'hi',
44 'Hungarian' => 'hu',
45 'Icelandic' => 'is',
46 'Indonesian' => 'id',
47 'Indonesian-Alternative' => 'id-ALT',
48 'Irish' => 'ga',
49 'Italian' => 'it-IT',
50 'Japanese' => 'ja',
51 'Javanese' => 'jv',
52 'Kanada' => 'kn',
53 'Kazakh' => 'kk',
54 'Khmer' => 'km',
55 'Korean' => 'ko',
56 'Kurdish' => 'ku',
57 'Kyrgyz' => 'ky',
58 'Lao' => 'lo',
59 'Latvian' => 'lv',
60 'Lithuanian' => 'lt',
61 'Luganda' => 'ug',
62 'Macedonian' => 'mk',
63 'Malay' => 'ms',
64 'Marathi' => 'mr',
65 'Mongolian' => 'mn',
66 'Nepali' => 'ne',
67 'Norwegian-Bokmal' => 'no-NB',
68 'Norwegian-Nynorsk' => 'no-NO',
69 'Pashto' => 'ps',
70 'Persian' => 'fa',
71 'Polish' => 'pl',
72 'Portuguese' => 'pt-PT',
73 'Portuguese-Brasil' => 'pt=BR',
74 'Punjabi' => 'pa',
75 'Romanian' => 'ro',
76 'Rumantsch' => 'rm',
77 'Russian' => 'ru',
78 'Serbian' => 'sr',
79 'Serbian_latin' => 'sr-SP',
80 'Sinhala' => 'si',
81 'Slovak' => 'sk',
82 'Slovenian' => 'sl',
83 'Spanish' => 'es-ES',
84 'Spanish-Argentina' => 'es-AR',
85 'Spanish-Chile' => 'es-CL',
86 'Spanish-Colombia' => 'es-CO',
87 'Spanish-Mexico' => 'es-MX',
88 'Swahili' => 'sw',
89 'Swedish' => 'sv-SE',
90 'Tajik' => 'tg',
91 'Tamil' => 'ta',
92 'telugu' => 'te',
93 'Thai' => 'th',
94 'Turkish' => 'tr',
95 'Ukrainian' => 'ur',
96 'Urdu' => 'ur',
97 'Uzbek' => 'uz',
98 'Uzbek-Cryllic' => 'uz-CR',
99 'Vietnamese' => 'vi',
100 'Welsh' => 'cy',
101 );
102
103 /**
104 * Add data tables tab content
105 *
106 * See class documentation for flow explanation.
107 *
108 * @since 2.0.15
109 */
110 protected function add_content() {
111 if ( isset( $_REQUEST['action'] ) ) {
112 $action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) );
113 // input var okay.
114 // Security check.
115 $wp_nonce = ( isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '' );
116 // input var okay.
117 if ( !wp_verify_nonce( $wp_nonce, 'wpda-datatables-settings-' . WPDA::get_current_user_login() ) ) {
118 wp_die( __( 'ERROR: Not authorized', 'wp-data-access' ) );
119 }
120 if ( 'save' === $action ) {
121 // Save options.
122 if ( isset( $_REQUEST['publication_roles'] ) ) {
123 $publication_roles_request = ( isset( $_REQUEST['publication_roles'] ) ? $_REQUEST['publication_roles'] : null );
124 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
125 if ( is_array( $publication_roles_request ) ) {
126 $publication_roles = sanitize_text_field( wp_unslash( implode( ',', $publication_roles_request ) ) );
127 } else {
128 $publication_roles = '';
129 }
130 } else {
131 $publication_roles = '';
132 }
133 WPDA::set_option( WPDA::OPTION_DP_PUBLICATION_ROLES, $publication_roles );
134 if ( isset( $_REQUEST['json_editing'] ) ) {
135 WPDA::set_option( WPDA::OPTION_DP_JSON_EDITING, sanitize_text_field( wp_unslash( $_REQUEST['json_editing'] ) ) );
136 }
137 if ( isset( $_REQUEST['publication_style'] ) ) {
138 WPDA::set_option( WPDA::OPTION_DP_STYLE, sanitize_text_field( wp_unslash( $_REQUEST['publication_style'] ) ) );
139 }
140 if ( isset( $_REQUEST['load_datatables'] ) ) {
141 $load_datatables_request = sanitize_text_field( wp_unslash( $_REQUEST['load_datatables'] ) );
142 // input var okay.
143 if ( 'both' === $load_datatables_request || 'be' === $load_datatables_request ) {
144 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES, 'on' );
145 } else {
146 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES, 'off' );
147 }
148 if ( 'both' === $load_datatables_request || 'fe' === $load_datatables_request ) {
149 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES, 'on' );
150 } else {
151 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES, 'off' );
152 }
153 }
154 if ( isset( $_REQUEST['load_datatables_responsive'] ) ) {
155 $load_datatables_responsive_request = sanitize_text_field( wp_unslash( $_REQUEST['load_datatables_responsive'] ) );
156 // input var okay.
157 if ( 'both' === $load_datatables_responsive_request || 'be' === $load_datatables_responsive_request ) {
158 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES_RESPONSE, 'on' );
159 } else {
160 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES_RESPONSE, 'off' );
161 }
162 if ( 'both' === $load_datatables_responsive_request || 'fe' === $load_datatables_responsive_request ) {
163 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES_RESPONSE, 'on' );
164 } else {
165 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES_RESPONSE, 'off' );
166 }
167 }
168 if ( isset( $_REQUEST['language'] ) ) {
169 WPDA::set_option( WPDA::OPTION_DP_LANGUAGE, sanitize_text_field( wp_unslash( $_REQUEST['language'] ) ) );
170 }
171 } elseif ( 'setdefaults' === $action ) {
172 // Set all datatables settings back to default.
173 WPDA::set_option( WPDA::OPTION_DP_PUBLICATION_ROLES );
174 WPDA::set_option( WPDA::OPTION_DP_STYLE );
175 WPDA::set_option( WPDA::OPTION_DP_JSON_EDITING );
176 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES );
177 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES );
178 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES_RESPONSE );
179 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES_RESPONSE );
180 WPDA::set_option( WPDA::OPTION_DP_LANGUAGE );
181 }
182 $msg = new WPDA_Message_Box(array(
183 'message_text' => __( 'Settings saved', 'wp-data-access' ),
184 ));
185 $msg->box();
186 }
187 global $wp_roles;
188 $roles = $wp_roles->roles;
189 unset($roles['administrator']);
190 $lov_roles = array();
191 foreach ( $wp_roles->roles as $role => $val ) {
192 array_push( $lov_roles, $role );
193 //phpcs:ignore - 8.1 proof
194 }
195 $publication_roles = WPDA::get_option( WPDA::OPTION_DP_PUBLICATION_ROLES );
196 $publication_style = WPDA::get_option( WPDA::OPTION_DP_STYLE );
197 $json_editing = WPDA::get_option( WPDA::OPTION_DP_JSON_EDITING );
198 $datatables_version = WPDA::get_option( WPDA::OPTION_WPDA_DATATABLES_VERSION );
199 $be_load_datatables = WPDA::get_option( WPDA::OPTION_BE_LOAD_DATATABLES );
200 $fe_load_datatables = WPDA::get_option( WPDA::OPTION_FE_LOAD_DATATABLES );
201 if ( 'on' === $be_load_datatables && 'on' === $fe_load_datatables ) {
202 $load_datatables = 'both';
203 } elseif ( 'on' === $be_load_datatables ) {
204 $load_datatables = 'be';
205 } elseif ( 'on' === $fe_load_datatables ) {
206 $load_datatables = 'fe';
207 } else {
208 $load_datatables = '';
209 }
210 $datatables_responsive_version = WPDA::get_option( WPDA::OPTION_WPDA_DATATABLES_RESPONSIVE_VERSION );
211 $be_load_datatables_responsive = WPDA::get_option( WPDA::OPTION_BE_LOAD_DATATABLES_RESPONSE );
212 $fe_load_datatables_responsive = WPDA::get_option( WPDA::OPTION_FE_LOAD_DATATABLES_RESPONSE );
213 if ( 'on' === $be_load_datatables_responsive && 'on' === $fe_load_datatables_responsive ) {
214 $load_datatables_responsive = 'both';
215 } elseif ( 'on' === $be_load_datatables_responsive ) {
216 $load_datatables_responsive = 'be';
217 } elseif ( 'on' === $fe_load_datatables_responsive ) {
218 $load_datatables_responsive = 'fe';
219 } else {
220 $load_datatables_responsive = '';
221 }
222 $current_language = WPDA::get_option( WPDA::OPTION_DP_LANGUAGE );
223 ?>
224 <form id="wpda_settings_datatables" method="post"
225 action="?page=<?php
226 echo esc_attr( $this->page );
227 ?>&tab=datatables">
228 <table class="wpda-table-settings">
229 <?php
230 ?>
231 <tr>
232 <th><?php
233 echo __( 'JSON Editing', 'wp-data-access' );
234 ?></th>
235 <td>
236 <label>
237 <input type="radio" name="json_editing" value="validate"
238 <?php
239 echo ( 'validate' === $json_editing ? 'checked' : '' );
240 ?>
241 ><?php
242 echo __( 'Use code editor with JSON validation', 'wp-data-access' );
243 ?>
244 </label>
245 <br/>
246 <label>
247 <input type="radio" name="json_editing" value="text"
248 <?php
249 echo ( 'text' === $json_editing ? 'checked' : '' );
250 ?>
251 ><?php
252 echo __( 'Use textarea without JSON validation', 'wp-data-access' );
253 ?>
254 </label>
255 </td>
256 </tr>
257 <tr>
258 <th>Data Tables Tool Access</th>
259 <td><div style="padding-bottom:10px">
260 <?php
261 echo __( 'Select WordPress roles allowed to access Data Tables', 'wp-data-access' );
262 ?>
263 </div>
264 <select name="publication_roles[]" multiple size="6">
265 <?php
266 foreach ( $roles as $key => $role ) {
267 $selected = ( false !== strpos( $publication_roles, $key ) ? 'selected' : '' );
268 ?>
269 <option value="<?php
270 echo esc_attr( $key );
271 ?>" <?php
272 echo esc_attr( $selected );
273 ?>>
274 <?php
275 echo esc_attr( $role['name'] );
276 ?>
277 </option>
278 <?php
279 }
280 ?>
281 </select>
282 <div style="margin-top:10px">
283 Administrators have access by default
284 </div>
285 </td>
286 </tr>
287 <tr>
288 <th><span class="dashicons dashicons-info" style="float:right;font-size:300%;"></span></th>
289 <td>
290 <span class="dashicons dashicons-yes"></span>
291 <?php
292 echo __( 'Users have readonly access to tables to which you have granted access in Front-end Settings only', 'wp-data-access' );
293 ?>
294 <br/>
295 <span class="dashicons dashicons-yes"></span>
296 <?php
297 echo __( 'Table access is automatically granted to tables used in Data Tables', 'wp-data-access' );
298 ?>
299 </td>
300 </tr>
301 <tr>
302 <th>jQuery DataTables</th>
303 <td>
304 <label>
305 <?php
306 echo sprintf( __( 'Load jQuery DataTables (version %s) scripts and styles', 'wp-data-access' ), esc_attr( $datatables_version ) );
307 ?>
308 </label>
309 <div style="height:10px"></div>
310 <labeL>
311 <input type="radio" name="load_datatables" value="both"
312 <?php
313 echo ( 'both' === $load_datatables ? 'checked' : '' );
314 ?>
315 ><?php
316 echo __( 'In WordPress Back-end and Front-end', 'wp-data-access' );
317 ?>
318 </labeL>
319 <br/>
320 <labeL>
321 <input type="radio" name="load_datatables" value="be"
322 <?php
323 echo ( 'be' === $load_datatables ? 'checked' : '' );
324 ?>
325 ><?php
326 echo __( 'In WordPress Back-end only ', 'wp-data-access' );
327 ?>
328 </labeL>
329 <br/>
330 <labeL>
331 <input type="radio" name="load_datatables" value="fe"
332 <?php
333 echo ( 'fe' === $load_datatables ? 'checked' : '' );
334 ?>
335 ><?php
336 echo __( 'In WordPress Front-end only', 'wp-data-access' );
337 ?>
338 </labeL>
339 <br/>
340 <labeL>
341 <input type="radio" name="load_datatables" value=""
342 <?php
343 echo ( '' === $load_datatables ? 'checked' : '' );
344 ?>
345 ><?php
346 echo __( 'Do not load jQuery DataTables', 'wp-data-access' );
347 ?>
348 </labeL>
349 </td>
350 </tr>
351 <tr>
352 <th>jQuery DataTables Responsive</th>
353 <td>
354 <label>
355 <?php
356 echo sprintf( __( 'Load jQuery DataTables Responsive (version %s) scripts and styles', 'wp-data-access' ), esc_attr( $datatables_responsive_version ) );
357 ?>
358 </label>
359 <div style="height:10px"></div>
360 <label>
361 <input type="radio" name="load_datatables_responsive" value="both"
362 <?php
363 echo ( 'both' === $load_datatables_responsive ? 'checked' : '' );
364 ?>
365 ><?php
366 echo __( 'In WordPress Back-end and Front-end', 'wp-data-access' );
367 ?>
368 </label>
369 <br/>
370 <label>
371 <input type="radio" name="load_datatables_responsive" value="be"
372 <?php
373 echo ( 'be' === $load_datatables_responsive ? 'checked' : '' );
374 ?>
375 ><?php
376 echo __( 'In WordPress Back-end only ', 'wp-data-access' );
377 ?>
378 </label>
379 <br/>
380 <label>
381 <input type="radio" name="load_datatables_responsive" value="fe"
382 <?php
383 echo ( 'fe' === $load_datatables_responsive ? 'checked' : '' );
384 ?>
385 ><?php
386 echo __( 'In WordPress Front-end only', 'wp-data-access' );
387 ?>
388 </label>
389 <br/>
390 <label>
391 <input type="radio" name="load_datatables_responsive" value=""
392 <?php
393 echo ( '' === $load_datatables_responsive ? 'checked' : '' );
394 ?>
395 ><?php
396 echo __( 'Do not load jQuery DataTables Responsive', 'wp-data-access' );
397 ?>
398 </label>
399 </td>
400 </tr>
401 <tr>
402 <th><?php
403 echo __( 'Front-End Language', 'wp-data-access' );
404 ?></th>
405 <td>
406 <select name="language">
407 <?php
408 foreach ( self::FRONTEND_LANG as $language => $code ) {
409 $checked = ( $current_language === $language ? ' selected' : '' );
410 echo "<option value='{$language}'{$checked}>{$language}</option>";
411 // phpcs:ignore WordPress.Security.EscapeOutput
412 }
413 ?>
414 </select>
415 </td>
416 </tr>
417 <tr>
418 <th><span class="dashicons dashicons-info" style="float:right;font-size:300%;"></span></th>
419 <td>
420 <span class="dashicons dashicons-yes"></span>
421 <?php
422 echo __( 'jQuery DataTables (+Responsive) is needed in the Front-end to support data tables on your website', 'wp-data-access' );
423 ?>
424 <br/>
425 <span class="dashicons dashicons-yes"></span>
426 <?php
427 echo __( 'jQuery DataTables (+Responsive) is needed in the Back-end to test data tables in the WordPress dashboard', 'wp-data-access' );
428 ?>
429 <br/>
430 <span class="dashicons dashicons-yes"></span>
431 <?php
432 echo __( 'If you have already loaded jQuery DataTables for other purposes disable loading them to prevent duplication errors', 'wp-data-access' );
433 ?>
434 </td>
435 </tr>
436 </table>
437 <div class="wpda-table-settings-button">
438 <input type="hidden" name="action" value="save"/>
439 <button type="submit" class="button button-primary">
440 <i class="fas fa-check wpda_icon_on_button"></i>
441 <?php
442 echo __( 'Save DataTables Settings', 'wp-data-access' );
443 ?>
444 </button>
445 <a href="javascript:void(0)"
446 onclick="if (confirm('<?php
447 echo __( 'Reset to defaults?', 'wp-data-access' );
448 ?>')) {
449 jQuery('input[name=&quot;action&quot;]').val('setdefaults');
450 jQuery('#wpda_settings_datatables').trigger('submit')
451 }"
452 class="button">
453 <i class="fas fa-times-circle wpda_icon_on_button"></i>
454 <?php
455 echo __( 'Reset DataTables Settings To Defaults', 'wp-data-access' );
456 ?>
457 </a>
458 </div>
459 <?php
460 wp_nonce_field( 'wpda-datatables-settings-' . WPDA::get_current_user_login(), '_wpnonce', false );
461 ?>
462 </form>
463 <?php
464 }
465
466 }
467