PluginProbe
WP Data Access – App Builder for Tables, Forms, Dashboards, Charts & Maps / 5.5.87
WP Data Access – App Builder for Tables, Forms, Dashboards, Charts & Maps v5.5.87
5.5.87 5.5.85 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 All 162 releases
wp-data-access / WPDataAccess / Settings / WPDA_Settings_Legacy_DataTables.php

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

473 lines 21.7 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_Legacy_DataTables extends WPDA_Settings_Legacy_Page {
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 public function show() {
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( esc_attr__( 'ERROR: Not authorized', 'wp-data-access' ) );
119 }
120 if ( 'save' === $action ) {
121 // Save options.
122 if ( isset( $_REQUEST['publication_roles'] ) ) {
123 // phpcs:disable WordPress.Security.ValidatedSanitizedInput
124 $publication_roles_request = ( isset( $_REQUEST['publication_roles'] ) ? $_REQUEST['publication_roles'] : null );
125 // phpcs:enable WordPress.Security.ValidatedSanitizedInput
126 if ( is_array( $publication_roles_request ) ) {
127 $publication_roles = sanitize_text_field( wp_unslash( implode( ',', $publication_roles_request ) ) );
128 } else {
129 $publication_roles = '';
130 }
131 } else {
132 $publication_roles = '';
133 }
134 WPDA::set_option( WPDA::OPTION_DP_PUBLICATION_ROLES, $publication_roles );
135 if ( isset( $_REQUEST['json_editing'] ) ) {
136 WPDA::set_option( WPDA::OPTION_DP_JSON_EDITING, sanitize_text_field( wp_unslash( $_REQUEST['json_editing'] ) ) );
137 }
138 if ( isset( $_REQUEST['publication_style'] ) ) {
139 WPDA::set_option( WPDA::OPTION_DP_STYLE, sanitize_text_field( wp_unslash( $_REQUEST['publication_style'] ) ) );
140 }
141 if ( isset( $_REQUEST['load_datatables'] ) ) {
142 $load_datatables_request = sanitize_text_field( wp_unslash( $_REQUEST['load_datatables'] ) );
143 // input var okay.
144 if ( 'both' === $load_datatables_request || 'be' === $load_datatables_request ) {
145 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES, 'on' );
146 } else {
147 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES, 'off' );
148 }
149 if ( 'both' === $load_datatables_request || 'fe' === $load_datatables_request ) {
150 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES, 'on' );
151 } else {
152 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES, 'off' );
153 }
154 }
155 if ( isset( $_REQUEST['load_datatables_responsive'] ) ) {
156 $load_datatables_responsive_request = sanitize_text_field( wp_unslash( $_REQUEST['load_datatables_responsive'] ) );
157 // input var okay.
158 if ( 'both' === $load_datatables_responsive_request || 'be' === $load_datatables_responsive_request ) {
159 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES_RESPONSE, 'on' );
160 } else {
161 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES_RESPONSE, 'off' );
162 }
163 if ( 'both' === $load_datatables_responsive_request || 'fe' === $load_datatables_responsive_request ) {
164 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES_RESPONSE, 'on' );
165 } else {
166 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES_RESPONSE, 'off' );
167 }
168 }
169 if ( isset( $_REQUEST['language'] ) ) {
170 WPDA::set_option( WPDA::OPTION_DP_LANGUAGE, sanitize_text_field( wp_unslash( $_REQUEST['language'] ) ) );
171 }
172 } elseif ( 'setdefaults' === $action ) {
173 // Set all datatables settings back to default.
174 WPDA::set_option( WPDA::OPTION_DP_PUBLICATION_ROLES );
175 WPDA::set_option( WPDA::OPTION_DP_STYLE );
176 WPDA::set_option( WPDA::OPTION_DP_JSON_EDITING );
177 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES );
178 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES );
179 WPDA::set_option( WPDA::OPTION_BE_LOAD_DATATABLES_RESPONSE );
180 WPDA::set_option( WPDA::OPTION_FE_LOAD_DATATABLES_RESPONSE );
181 WPDA::set_option( WPDA::OPTION_DP_LANGUAGE );
182 }
183 $msg = new WPDA_Message_Box(array(
184 'message_text' => __( 'Settings saved', 'wp-data-access' ),
185 ));
186 $msg->box();
187 }
188 global $wp_roles;
189 $roles = $wp_roles->roles;
190 unset($roles['administrator']);
191 $lov_roles = array();
192 foreach ( $wp_roles->roles as $role => $val ) {
193 array_push( $lov_roles, $role );
194 // phpcs:ignore -- 8.1 proof
195 }
196 $publication_roles = WPDA::get_option( WPDA::OPTION_DP_PUBLICATION_ROLES );
197 $publication_style = WPDA::get_option( WPDA::OPTION_DP_STYLE );
198 $json_editing = WPDA::get_option( WPDA::OPTION_DP_JSON_EDITING );
199 $datatables_version = WPDA::get_option( WPDA::OPTION_WPDA_DATATABLES_VERSION );
200 $be_load_datatables = WPDA::get_option( WPDA::OPTION_BE_LOAD_DATATABLES );
201 $fe_load_datatables = WPDA::get_option( WPDA::OPTION_FE_LOAD_DATATABLES );
202 if ( 'on' === $be_load_datatables && 'on' === $fe_load_datatables ) {
203 $load_datatables = 'both';
204 } elseif ( 'on' === $be_load_datatables ) {
205 $load_datatables = 'be';
206 } elseif ( 'on' === $fe_load_datatables ) {
207 $load_datatables = 'fe';
208 } else {
209 $load_datatables = '';
210 }
211 $datatables_responsive_version = WPDA::get_option( WPDA::OPTION_WPDA_DATATABLES_RESPONSIVE_VERSION );
212 $be_load_datatables_responsive = WPDA::get_option( WPDA::OPTION_BE_LOAD_DATATABLES_RESPONSE );
213 $fe_load_datatables_responsive = WPDA::get_option( WPDA::OPTION_FE_LOAD_DATATABLES_RESPONSE );
214 if ( 'on' === $be_load_datatables_responsive && 'on' === $fe_load_datatables_responsive ) {
215 $load_datatables_responsive = 'both';
216 } elseif ( 'on' === $be_load_datatables_responsive ) {
217 $load_datatables_responsive = 'be';
218 } elseif ( 'on' === $fe_load_datatables_responsive ) {
219 $load_datatables_responsive = 'fe';
220 } else {
221 $load_datatables_responsive = '';
222 }
223 $current_language = WPDA::get_option( WPDA::OPTION_DP_LANGUAGE );
224 ?>
225
226 <form id="wpda_settings_datatables" method="post"
227 action="?page=<?php
228 echo esc_attr( $this->page );
229 ?>&tab=legacy&vtab=datatables">
230 <table class="wpda-table-settings">
231 <tr style="border-top: 1px solid #ccc">
232 <th><?php
233 esc_html_e( '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 esc_html_e( '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 esc_html_e( 'Use textarea without JSON validation', 'wp-data-access' );
253 ?>
254 </label>
255 </td>
256 </tr>
257 <?php
258 ?>
259 <tr>
260 <th>Data Tables Tool Access</th>
261 <td><div style="padding-bottom:10px">
262 <?php
263 esc_html_e( 'Select WordPress roles allowed to access Data Tables', 'wp-data-access' );
264 ?>
265 </div>
266 <select name="publication_roles[]" multiple size="6">
267 <?php
268 foreach ( $roles as $key => $role ) {
269 $selected = ( false !== strpos( $publication_roles, $key ) ? 'selected' : '' );
270 ?>
271 <option value="<?php
272 echo esc_attr( $key );
273 ?>" <?php
274 echo esc_attr( $selected );
275 ?>>
276 <?php
277 echo esc_attr( $role['name'] );
278 ?>
279 </option>
280 <?php
281 }
282 ?>
283 </select>
284 <div style="margin-top:10px">
285 Administrators have access by default
286 </div>
287 </td>
288 </tr>
289 <tr>
290 <th><span class="dashicons dashicons-info" style="float:right;font-size:300%;"></span></th>
291 <td>
292 <span class="dashicons dashicons-yes"></span>
293 <?php
294 esc_html_e( 'Users have readonly access to tables to which you have granted access in Front-end Settings only', 'wp-data-access' );
295 ?>
296 <br/>
297 <span class="dashicons dashicons-yes"></span>
298 <?php
299 esc_html_e( 'Table access is automatically granted to tables used in Data Tables', 'wp-data-access' );
300 ?>
301 </td>
302 </tr>
303 <tr>
304 <th>jQuery DataTables</th>
305 <td>
306 <label>
307 <?php
308 /* translators: %s = data tables version number */
309 echo sprintf( esc_attr__( 'Load jQuery DataTables (version %s) scripts and styles', 'wp-data-access' ), esc_attr( $datatables_version ) );
310 ?>
311 </label>
312 <div style="height:10px"></div>
313 <labeL>
314 <input type="radio" name="load_datatables" value="both"
315 <?php
316 echo ( 'both' === $load_datatables ? 'checked' : '' );
317 ?>
318 ><?php
319 esc_html_e( 'In WordPress Back-end and Front-end', 'wp-data-access' );
320 ?>
321 </labeL>
322 <br/>
323 <labeL>
324 <input type="radio" name="load_datatables" value="be"
325 <?php
326 echo ( 'be' === $load_datatables ? 'checked' : '' );
327 ?>
328 ><?php
329 esc_html_e( 'In WordPress Back-end only ', 'wp-data-access' );
330 ?>
331 </labeL>
332 <br/>
333 <labeL>
334 <input type="radio" name="load_datatables" value="fe"
335 <?php
336 echo ( 'fe' === $load_datatables ? 'checked' : '' );
337 ?>
338 ><?php
339 esc_html_e( 'In WordPress Front-end only', 'wp-data-access' );
340 ?>
341 </labeL>
342 <br/>
343 <labeL>
344 <input type="radio" name="load_datatables" value=""
345 <?php
346 echo ( '' === $load_datatables ? 'checked' : '' );
347 ?>
348 ><?php
349 esc_html_e( 'Do not load jQuery DataTables', 'wp-data-access' );
350 ?>
351 </labeL>
352 </td>
353 </tr>
354 <tr>
355 <th>jQuery DataTables Responsive</th>
356 <td>
357 <label>
358 <?php
359 /* translators: %s = data tables responsive version number */
360 echo sprintf( esc_attr__( 'Load jQuery DataTables Responsive (version %s) scripts and styles', 'wp-data-access' ), esc_attr( $datatables_responsive_version ) );
361 ?>
362 </label>
363 <div style="height:10px"></div>
364 <label>
365 <input type="radio" name="load_datatables_responsive" value="both"
366 <?php
367 echo ( 'both' === $load_datatables_responsive ? 'checked' : '' );
368 ?>
369 ><?php
370 esc_html_e( 'In WordPress Back-end and Front-end', 'wp-data-access' );
371 ?>
372 </label>
373 <br/>
374 <label>
375 <input type="radio" name="load_datatables_responsive" value="be"
376 <?php
377 echo ( 'be' === $load_datatables_responsive ? 'checked' : '' );
378 ?>
379 ><?php
380 esc_html_e( 'In WordPress Back-end only ', 'wp-data-access' );
381 ?>
382 </label>
383 <br/>
384 <label>
385 <input type="radio" name="load_datatables_responsive" value="fe"
386 <?php
387 echo ( 'fe' === $load_datatables_responsive ? 'checked' : '' );
388 ?>
389 ><?php
390 esc_html_e( 'In WordPress Front-end only', 'wp-data-access' );
391 ?>
392 </label>
393 <br/>
394 <label>
395 <input type="radio" name="load_datatables_responsive" value=""
396 <?php
397 echo ( '' === $load_datatables_responsive ? 'checked' : '' );
398 ?>
399 ><?php
400 esc_html_e( 'Do not load jQuery DataTables Responsive', 'wp-data-access' );
401 ?>
402 </label>
403 </td>
404 </tr>
405 <tr>
406 <th><?php
407 esc_html_e( 'Front-End Language', 'wp-data-access' );
408 ?></th>
409 <td>
410 <select name="language">
411 <?php
412 foreach ( self::FRONTEND_LANG as $language => $code ) {
413 $checked = ( $current_language === $language ? ' selected' : '' );
414 // phpcs:disable WordPress.Security.EscapeOutput
415 echo "<option value='{$language}'{$checked}>{$language}</option>";
416 // phpcs:enable WordPress.Security.EscapeOutput
417 }
418 ?>
419 </select>
420 </td>
421 </tr>
422 <tr>
423 <th><span class="dashicons dashicons-info" style="float:right;font-size:300%;"></span></th>
424 <td>
425 <span class="dashicons dashicons-yes"></span>
426 <?php
427 esc_html_e( 'jQuery DataTables (+Responsive) is needed in the Front-end to support data tables on your website', 'wp-data-access' );
428 ?>
429 <br/>
430 <span class="dashicons dashicons-yes"></span>
431 <?php
432 esc_html_e( 'jQuery DataTables (+Responsive) is needed in the Back-end to test data tables in the WordPress dashboard', 'wp-data-access' );
433 ?>
434 <br/>
435 <span class="dashicons dashicons-yes"></span>
436 <?php
437 esc_html_e( 'If you have already loaded jQuery DataTables for other purposes disable loading them to prevent duplication errors', 'wp-data-access' );
438 ?>
439 </td>
440 </tr>
441 </table>
442 <div class="wpda-table-settings-button">
443 <input type="hidden" name="action" value="save"/>
444 <button type="submit" class="button button-primary">
445 <i class="fas fa-check wpda_icon_on_button"></i>
446 <?php
447 esc_html_e( 'Save DataTables Settings', 'wp-data-access' );
448 ?>
449 </button>
450 <a href="javascript:void(0)"
451 onclick="if (confirm('<?php
452 esc_html_e( 'Reset to defaults?', 'wp-data-access' );
453 ?>')) {
454 jQuery('input[name=&quot;action&quot;]').val('setdefaults');
455 jQuery('#wpda_settings_datatables').trigger('submit')
456 }"
457 class="button">
458 <i class="fas fa-times-circle wpda_icon_on_button"></i>
459 <?php
460 esc_html_e( 'Reset DataTables Settings To Defaults', 'wp-data-access' );
461 ?>
462 </a>
463 </div>
464 <?php
465 wp_nonce_field( 'wpda-datatables-settings-' . WPDA::get_current_user_login(), '_wpnonce', false );
466 ?>
467 </form>
468
469 <?php
470 }
471
472 }
473