PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.80
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.80
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 5.5.41 All 161 releases
wp-data-access / public / class-wp-data-access-public.php

class-wp-data-access-public.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.80, at public/class-wp-data-access-public.php

759 lines 31.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
5 *
6 * @package plugin\public
7 */
8 use WPDataAccess\API\WPDA_API;
9 use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Exist;
10 use WPDataAccess\Data_Tables\WPDA_Data_Tables;
11 use WPDataAccess\List_Table\WPDA_List_View;
12 use WPDataAccess\Premium\WPDAPRO_Data_Publisher\WPDAPRO_Data_Publisher_Init;
13 use WPDataAccess\Utilities\WPDA_Add_App_To_Menu;
14 use WPDataAccess\WPDA;
15 /**
16 * Class WP_Data_Access_Public
17 *
18 * Defines public specific functionality for plugin WP Data Access.
19 *
20 * @author Peter Schulz
21 * @since 1.0.0
22 */
23 // phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- verified on page
24 class WP_Data_Access_Public {
25 /**
26 * Add stylesheets to front-end
27 *
28 * The following stylesheets are registered:
29 * + jQuery DataTables stylesheet (version is set in class WPDA)
30 * + jQuery DataTables responsive stylesheet (version is set in class WPDA)
31 *
32 * Stylesheets are used to style the front-end tables. Whether stylesheets should be loaded or not can be set in
33 * the front-end settings (menu: Manage Plugin). Sites that already have some of these stylesheets loaded, can turn
34 * off loading in the front-end settings to prevent double loading.
35 *
36 * @since 1.0.0
37 *
38 * @see WPDA
39 */
40 public function enqueue_styles() {
41 if ( is_admin() ) {
42 // Public styles are only added to public pages.
43 return;
44 }
45 // WPDataAccess apps CSS.
46 wp_register_style(
47 'wpda_apps',
48 plugins_url( '../assets/css/wpda_apps.css', __FILE__ ),
49 array(),
50 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
51 );
52 // Toolbar icon.
53 wp_enqueue_style(
54 'wpda_wpdp_public',
55 plugins_url( '../assets/css/wpda_public.css', __FILE__ ),
56 array(),
57 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
58 );
59 // Register JQuery DataTables.
60 wp_register_style(
61 'jquery_datatables',
62 plugins_url( '../assets/css/jquery.dataTables.min.css', __FILE__ ),
63 array(),
64 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
65 );
66 // Register JQuery DataTables Responsive.
67 wp_register_style(
68 'jquery_datatables_responsive',
69 plugins_url( '../assets/css/responsive.dataTables.min.css', __FILE__ ),
70 array(),
71 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
72 );
73 // Register styles for WPDADIEHARD shortcode.
74 global $wp_version;
75 wp_register_style(
76 'wpdadiehard',
77 '/wp-admin/load-styles.php?load%5B%5D=list-tables,forms,common,buttons',
78 array(),
79 $wp_version
80 );
81 wp_register_style(
82 'wpdataaccess',
83 plugins_url( '../assets/css/wpda_style.css', __FILE__ ),
84 array(),
85 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
86 );
87 wp_register_style(
88 'wpdataprojects',
89 plugins_url( '../WPDataProjects/assets/css/wpdp_style.css', __FILE__ ),
90 array(),
91 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
92 );
93 // Register datetimepicker external library.
94 wp_register_style(
95 'datetimepicker',
96 plugins_url( '../assets/css/jquery.datetimepicker.min.css', __FILE__ ),
97 array(),
98 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
99 );
100 wp_register_style(
101 'wpda_datatables_default',
102 plugins_url( '../assets/css/wpda_datatables_default.css', __FILE__ ),
103 array(),
104 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
105 );
106 wp_register_style(
107 'wpda_datatables_hide_sort_icons',
108 plugins_url( '../assets/css/wpda_datatables_hide_sort_icons.css', __FILE__ ),
109 array(),
110 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
111 );
112 // SAVING SPACE - According to the plugin guidelines it is allowed to include external fonts:
113 // https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#8-plugins-may-not-send-executable-code-via-third-party-systems .
114 // Load fontawesome icons.
115 // phpcs:disable WordPress.WP.EnqueuedResourceParameters.MissingVersion
116 wp_register_style(
117 'wpda_fontawesome_icons',
118 WPDA::CDN_FONTAWESOME . 'all.min.css',
119 array(),
120 null,
121 false
122 );
123 }
124
125 /**
126 * Add scripts to back-end
127 *
128 * The following script files are registered :
129 * + jQuery DataTables (version is set in class WPDA)
130 * + jQuery DataTables responsive (version is set in class WPDA)
131 * + WP Data Access DataTables server implementation (ajax)
132 *
133 * Scripts are used to build front-end tables and support searching and pagination. Whether the scripts for
134 * jQuery DataTables and/or jQuery DataTables responsive should be loaded or not can be set in the
135 * front-end settings (menu: Manage Plugin). Sites that already have some of these script files loaded, can
136 * turn off loading in the front-end settings to prevent double loading.
137 *
138 * @since 1.0.0
139 *
140 * @see WPDA
141 */
142 public function enqueue_scripts() {
143 if ( is_admin() ) {
144 // Public scripts are only added to public pages.
145 return;
146 }
147 wp_enqueue_script( 'jquery' );
148 // Register wpda rest api.
149 wp_enqueue_script(
150 'wpda_rest_api',
151 plugins_url( '../assets/js/wpda_rest_api.js', __FILE__ ),
152 array('wp-api'),
153 WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
154 false
155 );
156 wp_localize_script( 'wpda_rest_api', 'wpdaApiSettings', array(
157 'path' => WPDA_API::WPDA_NAMESPACE,
158 ) );
159 // Register JQuery DataTables.
160 wp_register_script(
161 'jquery_datatables',
162 plugins_url( '../assets/js/jquery.dataTables.min.js', __FILE__ ),
163 array(),
164 WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
165 false
166 );
167 // Register JQuery DataTables Responsive.
168 wp_register_script(
169 'jquery_datatables_responsive',
170 plugins_url( '../assets/js/dataTables.responsive.min.js', __FILE__ ),
171 array(),
172 WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
173 false
174 );
175 // Add url Ajax call to WPDA datatables.
176 wp_register_script(
177 'wpda_datatables',
178 plugins_url( '../assets/js/wpda_datatables.js', __FILE__ ),
179 array(),
180 WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
181 false
182 );
183 wp_localize_script( 'wpda_datatables', 'wpda_publication_vars', array(
184 'wpda_ajaxurl' => admin_url( 'admin-ajax.php' ),
185 ) );
186 // Register functions for WPDADIEHARD shortcode.
187 global $wp_version;
188 wp_register_script(
189 'wpdadiehard',
190 '/wp-admin/load-scripts.php?load%5B%5D=hoverIntent,hoverintent-js,list-tables,forms,buttons,common',
191 array('wp-i18n'),
192 $wp_version,
193 false
194 );
195 wp_register_script(
196 'wpda_admin_scripts',
197 plugins_url( '../assets/js/wpda_admin.js', __FILE__ ),
198 array(),
199 WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
200 false
201 );
202 // Add WP Data Projects JS functions.
203 wp_register_script(
204 'wpdataprojects',
205 plugins_url( '../WPDataProjects/assets/js/wpdp_admin.js', __FILE__ ),
206 array(),
207 WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
208 false
209 );
210 // Register datetimepicker external library.
211 wp_register_script(
212 'datetimepicker',
213 plugins_url( '../assets/js/jquery.datetimepicker.full.min.js', __FILE__ ),
214 array(),
215 WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
216 false
217 );
218 // Register notify external library.
219 wp_register_script(
220 'wpda_notify',
221 plugins_url( '../assets/js/notify.min.js', __FILE__ ),
222 array(),
223 WPDA::get_option( WPDA::OPTION_WPDA_VERSION ),
224 false
225 );
226 }
227
228 public function add_apps_to_admin_toolbar() {
229 if ( is_admin() ) {
230 // Toolbar only available on public pages.
231 return;
232 }
233 // Add Apps.
234 $apps = new WPDA_Add_App_To_Menu();
235 $apps->add_apps_to_menu();
236 }
237
238 /**
239 * Show projects in admin toolbar
240 *
241 * @return void
242 */
243 public function add_data_projects_to_admin_toolbar() {
244 if ( is_admin() ) {
245 // Toolbar only available on public pages.
246 return;
247 }
248 // Add Data Projects.
249 $wpdp = new \WPDataProjects\WPDP();
250 $wpdp->add_projects();
251 }
252
253 /**
254 * Register shortcode 'wpdataaccess'
255 *
256 * @since 1.0.0
257 */
258 public function register_shortcodes() {
259 add_shortcode( 'wpda_app', array($this, 'wpda_app') );
260 add_shortcode( 'wpda_app_builder', array($this, 'wpda_app_builder') );
261 add_shortcode( 'wpda_data_explorer', array($this, 'wpda_data_explorer') );
262 add_shortcode( 'wpda_query_builder', array($this, 'wpda_query_builder') );
263 add_shortcode( 'wpdataaccess', array($this, 'wpdataaccess') );
264 add_shortcode( 'wpdadiehard', array($this, 'wpdadiehard') );
265 }
266
267 public function wpda_app_builder( $atts ) {
268 $editing = WPDA::is_editing_post();
269 if ( false !== $editing ) {
270 // Prevent errors when user is editing a post.
271 return $editing;
272 }
273 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
274 //phpcs:ignore - 8.1 proof
275 $wp_atts = shortcode_atts( array(
276 'feedback' => false,
277 ), $atts );
278 ob_start();
279 $apps = new WPDataAccess\Data_Apps\WPDA_App_Builder($wp_atts);
280 $apps->show();
281 return ob_get_clean();
282 }
283
284 public function wpda_app( $atts ) {
285 $editing = WPDA::is_editing_post();
286 if ( false !== $editing ) {
287 // Prevent errors when user is editing a post.
288 return $editing;
289 }
290 if ( isset( $_POST['is_fb_preview'], $_GET['et_pb_preview'] ) && 'true' === $_POST['is_fb_preview'] && 'true' === $_GET['et_pb_preview'] ) {
291 // Divi Visual Builder preview not working!
292 // Dynamic resources are not properly loaded into the Divi Visual Builder.
293 ob_start();
294 ?>
295 <div style="width: 100%; border: 1px solid #ccc; padding: 50px; display: grid; gap: 20px; background-color: rgb(249,249,249); border-radius: 5px;">
296 <div>
297 No preview in Visual Builder. App will appear once Visual Builder is closed.
298 </div>
299 </div>
300 <?php
301 return ob_get_clean();
302 }
303 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
304 //phpcs:ignore - 8.1 proof
305 $wp_atts = shortcode_atts( array(
306 'app_id' => null,
307 'feedback' => false,
308 'builders' => true,
309 'hidetitlebar' => false,
310 'fullscreen' => false,
311 'filter_field_name' => null,
312 'filter_field_value' => null,
313 ), $atts );
314 $shortcode_params = array();
315 foreach ( $atts as $key => $value ) {
316 if ( !key_exists( $key, $wp_atts ) ) {
317 $shortcode_params[$key] = $value;
318 }
319 }
320 $shortcode_params['pwa'] = false;
321 // Shortcode not allowed to use parameter pwa
322 ob_start();
323 $app = new WPDataAccess\Data_Apps\WPDA_App_Container($wp_atts, $shortcode_params);
324 $app->show();
325 return ob_get_clean();
326 }
327
328 public function wpda_data_explorer( $atts ) {
329 $editing = WPDA::is_editing_post();
330 if ( false !== $editing ) {
331 // Prevent errors when user is editing a post.
332 return $editing;
333 }
334 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
335 //phpcs:ignore - 8.1 proof
336 $wp_atts = shortcode_atts( array(
337 'feedback' => false,
338 ), $atts );
339 ob_start();
340 $explorer = new WPDataAccess\Data_Apps\WPDA_Data_Explorer($wp_atts);
341 $explorer->show();
342 return ob_get_clean();
343 }
344
345 public function wpda_query_builder( $atts ) {
346 $editing = WPDA::is_editing_post();
347 if ( false !== $editing ) {
348 // Prevent errors when user is editing a post.
349 return $editing;
350 }
351 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
352 //phpcs:ignore - 8.1 proof
353 $wp_atts = shortcode_atts( array(
354 'feedback' => false,
355 ), $atts );
356 ob_start();
357 $qb = new WPDataAccess\Data_Apps\WPDA_Query_Builder($wp_atts);
358 $qb->show();
359 return ob_get_clean();
360 }
361
362 /**
363 * Implementation of shortcode 'wpdataaccess'
364 *
365 * Checks the values entered on validity (as far as possible) and builds the table based on the given table name,
366 * column names and other arguments. Tables is build with class {@see WPDA_Data_Tables}.
367 *
368 * @param array $atts Arguments applied with the shortcode.
369 *
370 * @return string response
371 *
372 * @see WPDA_Data_Tables
373 *
374 * @since 1.0.0
375 */
376 public function wpdataaccess( $atts ) {
377 $editing = WPDA::is_editing_post();
378 if ( false !== $editing ) {
379 // Prevent errors when user is editing a post.
380 return $editing;
381 }
382 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDATAACCESS_POST ) ) {
383 if ( WPDA::is_post() ) {
384 return '<p>' . __( 'Sorry, you cannot use shortcode wpdataaccess in a post!', 'wp-data-access' ) . '</p>';
385 }
386 }
387 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDATAACCESS_PAGE ) ) {
388 if ( WPDA::is_page() ) {
389 return '<p>' . __( 'Sorry, you cannot use shortcode wpdataaccess in a page!', 'wp-data-access' ) . '</p>';
390 }
391 }
392 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
393 //phpcs:ignore - 8.1 proof
394 $wp_atts = shortcode_atts( array(
395 'pub_id' => '',
396 'pub_name' => '',
397 'database' => '',
398 'table' => '',
399 'columns' => '*',
400 'responsive' => 'no',
401 'responsive_cols' => '0',
402 'responsive_type' => 'collapsed',
403 'responsive_icon' => 'yes',
404 'sql_orderby' => '',
405 'filter_field_name' => '',
406 'filter_field_value' => '',
407 'nl2br' => '',
408 ), $atts );
409 $wpda_data_tables = new WPDA_Data_Tables();
410 return $wpda_data_tables->show(
411 $wp_atts['pub_id'],
412 $wp_atts['pub_name'],
413 $wp_atts['database'],
414 $wp_atts['table'],
415 str_replace( ' ', '', $wp_atts['columns'] ),
416 $wp_atts['responsive'],
417 $wp_atts['responsive_cols'],
418 $wp_atts['responsive_type'],
419 $wp_atts['responsive_icon'],
420 $wp_atts['sql_orderby'],
421 $wp_atts['filter_field_name'],
422 $wp_atts['filter_field_value'],
423 $wp_atts['nl2br']
424 );
425 }
426
427 /**
428 * Show data administration page on web page
429 *
430 * Allows to show Data Projects pages on web p0ages as well.
431 *
432 * @param array $atts Shortcode arguments.
433 *
434 * @return false|string
435 */
436 public function wpdadiehard( $atts ) {
437 $editing = WPDA::is_editing_post();
438 if ( false !== $editing ) {
439 // Prevent errors when user is editing a post.
440 return $editing;
441 }
442 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDADIEHARD_POST ) ) {
443 if ( WPDA::is_post() ) {
444 return '<p>' . __( 'Sorry, you cannot use shortcode wpdadiehard in a post!', 'wp-data-access' ) . '</p>';
445 }
446 }
447 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDADIEHARD_PAGE ) ) {
448 if ( WPDA::is_page() ) {
449 return '<p>' . __( 'Sorry, you cannot use shortcode wpdadiehard in a page!', 'wp-data-access' ) . '</p>';
450 }
451 }
452 global $wpdb;
453 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
454 //phpcs:ignore - 8.1 proof
455 $wp_atts = shortcode_atts( array(
456 'project_id' => '',
457 'page_id' => '',
458 'schema_name' => $wpdb->dbname,
459 'table_name' => '',
460 'title' => '',
461 'subtitle' => '',
462 'bulk_actions_enabled' => false,
463 'search_box_enabled' => false,
464 'bulk_export_enabled' => false,
465 'show_view_link' => 'on',
466 'allow_insert' => 'off',
467 'allow_update' => 'off',
468 'allow_delete' => 'off',
469 'allow_import' => 'off',
470 ), $atts );
471 if ( '' === $wp_atts['project_id'] && '' === $wp_atts['page_id'] && '' === $wp_atts['table_name'] ) {
472 // Either a Data Project page (project_id and page_id) or a table name must be provided.
473 return __( 'ERROR: Missing argument(s) [(project_id and page_id) or table_name]', 'wp-data-access' );
474 }
475 // Sanitize database values.
476 $wp_atts['project_id'] = sanitize_text_field( wp_unslash( $wp_atts['project_id'] ) );
477 // input var okay.
478 $wp_atts['page_id'] = sanitize_text_field( wp_unslash( $wp_atts['page_id'] ) );
479 // input var okay.
480 $wp_atts['schema_name'] = sanitize_text_field( wp_unslash( $wp_atts['schema_name'] ) );
481 // input var okay.
482 $wp_atts['table_name'] = sanitize_text_field( wp_unslash( $wp_atts['table_name'] ) );
483 // input var okay.
484 // Set default parameter values.
485 $bulk_actions_enabled = false;
486 $search_box_enabled = false;
487 $bulk_export_enabled = false;
488 $show_view_link = 'on';
489 $allow_insert = 'off';
490 $allow_update = 'off';
491 $allow_delete = 'off';
492 $allow_import = 'off';
493 // Check arguments.
494 if ( 'true' === $wp_atts['bulk_actions_enabled'] ) {
495 $bulk_actions_enabled = true;
496 }
497 if ( 'true' === $wp_atts['search_box_enabled'] ) {
498 $search_box_enabled = true;
499 }
500 if ( 'true' === $wp_atts['bulk_export_enabled'] ) {
501 $bulk_export_enabled = true;
502 }
503 if ( 'false' === $wp_atts['show_view_link'] ) {
504 $show_view_link = 'off';
505 }
506 if ( 'true' === $wp_atts['allow_insert'] ) {
507 $allow_insert = 'on';
508 }
509 if ( 'true' === $wp_atts['allow_update'] ) {
510 $allow_update = 'on';
511 }
512 if ( 'true' === $wp_atts['allow_delete'] ) {
513 $allow_delete = 'on';
514 }
515 if ( 'true' === $wp_atts['allow_import'] ) {
516 $allow_import = 'on';
517 }
518 $default_where = '';
519 if ( isset( $atts['filter_field_name'] ) && isset( $atts['filter_field_value'] ) ) {
520 $filter_field_name = str_replace( '`', '', sanitize_text_field( wp_unslash( $atts['filter_field_name'] ) ) );
521 // input var okay.
522 $filter_field_value = sanitize_text_field( wp_unslash( $atts['filter_field_value'] ) );
523 // input var okay.
524 $filter_field_name_array = array_map( 'trim', explode( ',', $filter_field_name ) );
525 //phpcs:ignore - 8.1 proof
526 $filter_field_value_array = array_map( 'trim', explode( ',', $filter_field_value ) );
527 //phpcs:ignore - 8.1 proof
528 if ( count( $filter_field_name_array ) === count( $filter_field_value_array ) ) {
529 //phpcs:ignore - 8.1 proof
530 // Add filter to where clause.
531 // phpcs:disable Generic.CodeAnalysis.ForLoopWithTestFunctionCall, Squiz.PHP.DisallowSizeFunctionsInLoops, WordPress.DB.PreparedSQLPlaceholders
532 for ($i = 0; $i < count( $filter_field_name_array ); $i++) {
533 $default_where .= (( '' === $default_where ? '' : ' and ' )) . $wpdb->prepare( ' `%1s` like %s ', array(WPDA::remove_backticks( $filter_field_name_array[$i] ), $filter_field_value_array[$i]) );
534 }
535 // phpcs:enable Generic.CodeAnalysis.ForLoopWithTestFunctionCall, Squiz.PHP.DisallowSizeFunctionsInLoops, WordPress.DB.PreparedSQLPlaceholders
536 }
537 }
538 // Is this a Data Projects page or a table administration page?
539 if ( '' !== $wp_atts['project_id'] && '' !== $wp_atts['page_id'] ) {
540 // phpcs:ignore Generic.CodeAnalysis.EmptyStatement
541 // Request for Data Projects page (check is performed in WPDP_List_Page).
542 } else {
543 // Request for table administration page.
544 // Check schema name.
545 if ( 'sys' === $wp_atts['schema_name'] || 'mysql' === $wp_atts['schema_name'] || 'information_schema' === $wp_atts['schema_name'] ) {
546 // No access to MySQL databases (meta data)!
547 return __( 'ERROR: No access to MySQL meta data', 'wp-data-access' );
548 }
549 // Check database table name.
550 if ( '' === $wp_atts['table_name'] ) {
551 // Table name must be provided! No database administration in the public area!
552 return __( 'ERROR: Missing argument [table_name]', 'wp-data-access' );
553 }
554 // Check if table exists (to prevent sql injection) and access is granted.
555 $wpda_dictionary_checks = new WPDA_Dictionary_Exist($wp_atts['schema_name'], $wp_atts['table_name']);
556 if ( !$wpda_dictionary_checks->table_exists( true, false ) ) {
557 // Table not found.
558 return '<p>' . __( 'ERROR: Invalid table name or not authorized', 'wp-data-access' ) . '</p>';
559 }
560 }
561 // Make sure user has access to necessary (fake) classes and functions in the frontend.
562 require_once plugin_dir_path( __DIR__ ) . 'wp-data-access-diehard.php';
563 // Make sure all style and JS is available.
564 wp_enqueue_script( 'wpda_admin_scripts' );
565 wp_enqueue_script( 'wpdataprojects' );
566 wp_enqueue_script( 'wpdadiehard' );
567 wp_enqueue_script( 'jquery-ui-core' );
568 wp_enqueue_script( 'jquery-ui-dialog' );
569 wp_enqueue_script( 'jquery-ui-tabs' );
570 wp_enqueue_script( 'jquery-ui-sortable' );
571 wp_enqueue_script( 'jquery-ui-tooltip' );
572 wp_enqueue_script( 'jquery-ui-autocomplete' );
573 wp_enqueue_style( 'dashicons' );
574 wp_enqueue_style( 'wpdadiehard' );
575 wp_enqueue_style( 'wpdataaccess' );
576 wp_enqueue_style( 'wpdataprojects' );
577 wp_enqueue_style( 'wpda_notify' );
578 wp_enqueue_style(
579 'wpda_ui_darkness',
580 plugins_url( '../assets/css/jquery-ui.min.css', __FILE__ ),
581 array(),
582 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
583 );
584 wp_enqueue_media();
585 do_action( 'wpda_wpdadiehard_prepare' );
586 ob_start();
587 // Set page argument to allow public access.
588 $_REQUEST['page'] = 'diehard';
589 if ( '' !== $wp_atts['project_id'] && '' !== $wp_atts['page_id'] ) {
590 // Show Data Projects page (check is performed in WPDP_List_Page).
591 // Get page values.
592 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table
593 $project_page = $wpdb->get_results( $wpdb->prepare( "\n select * from {$wpdb->prefix}wpda_project_page\n where project_id = %d\n and page_id = %d\n \t", array($wp_atts['project_id'], $wp_atts['page_id']) ), 'ARRAY_A' );
594 // db call ok; no-cache ok.
595 // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
596 if ( 0 === $wpdb->num_rows ) {
597 // This should never happen as it was already tested before.
598 return __( 'ERROR: Data Project page not found [need a valid project_id and page_id]', 'wp-data-access' );
599 }
600 if ( 'off' !== WPDA::get_option( WPDA::OPTION_WPDA_USE_ROLES_IN_SHORTCODE ) ) {
601 // Check if user has role.
602 $user_roles = WPDA::get_current_user_roles();
603 if ( false === $user_roles ) {
604 // Cannot determine the user role(s). Not able to show project menus.
605 return __( 'ERROR: No access [could not determine user role]', 'wp-data-access' );
606 }
607 $user_has_role = false;
608 if ( '' === $project_page[0]['page_role'] || null === $project_page[0]['page_role'] ) {
609 $user_has_role = in_array( 'administrator', $user_roles, true );
610 //phpcs:ignore - 8.1 proof
611 } else {
612 $user_role_array = explode( ',', $project_page[0]['page_role'] );
613 //phpcs:ignore - 8.1 proof
614 foreach ( $user_role_array as $user_role_array_item ) {
615 $user_has_role = in_array( $user_role_array_item, $user_roles, true );
616 //phpcs:ignore - 8.1 proof
617 if ( $user_has_role ) {
618 break;
619 }
620 }
621 }
622 if ( !$user_has_role ) {
623 return __( 'ERROR: No access [missing role]', 'wp-data-access' );
624 }
625 }
626 // Determine plugin classes to be used.
627 if ( 'static' === $project_page[0]['page_type'] ) {
628 return '';
629 } elseif ( 'table' === $project_page[0]['page_type'] ) {
630 $list_view_class = 'WPDataProjects\\List_Table\\WPDP_List_View';
631 $list_table_class = 'WPDataProjects\\List_Table\\WPDP_List_Table';
632 $edit_form_class = 'WPDataProjects\\Simple_Form\\WPDP_Simple_Form';
633 } else {
634 $list_view_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_View';
635 $list_table_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_Table';
636 $edit_form_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_Form';
637 }
638 if ( null !== $project_page[0]['page_where'] && '' !== $project_page[0]['page_where'] ) {
639 if ( 'where' === substr( str_replace( ' ', '', $project_page[0]['page_where'] ), 0, 5 ) ) {
640 $where_clause = " {$project_page[0]['page_where']}";
641 } else {
642 $where_clause = " where {$project_page[0]['page_where']} ";
643 }
644 $where_clause = WPDA::substitute_environment_vars( $where_clause );
645 } else {
646 $where_clause = '';
647 }
648 if ( '' === $default_where ) {
649 $default_where = $where_clause;
650 } else {
651 if ( '' === $where_clause ) {
652 $default_where = " where {$default_where} ";
653 } else {
654 $default_where = " {$where_clause} and {$default_where} ";
655 }
656 }
657 $default_orderby = $project_page[0]['page_orderby'];
658 // Prepare arguments.
659 $args = array(
660 'page_hook_suffix' => 'WPDA_WPDP',
661 'wpdaschema_name' => $project_page[0]['page_schema_name'],
662 'table_name' => $project_page[0]['page_table_name'],
663 'list_table_class' => $list_table_class,
664 'edit_form_class' => $edit_form_class,
665 'project_id' => $wp_atts['project_id'],
666 'page_id' => $wp_atts['page_id'],
667 'default_where' => $default_where,
668 'where_clause' => $default_where,
669 'orderby_clause' => $default_orderby,
670 );
671 if ( 'view' === $project_page[0]['page_mode'] ) {
672 $args['allow_update'] = 'off';
673 $args['allow_import'] = 'off';
674 }
675 if ( 'no' === $project_page[0]['page_allow_insert'] ) {
676 $args['allow_insert'] = 'off';
677 $args['allow_import'] = 'off';
678 }
679 if ( 'no' === $project_page[0]['page_allow_delete'] ) {
680 $args['allow_delete'] = 'off';
681 }
682 if ( 'only' === $project_page[0]['page_allow_insert'] ) {
683 $args['action'] = 'new';
684 $args['allow_insert'] = 'only';
685 $args['allow_update'] = 'off';
686 $args['allow_import'] = 'off';
687 $args['allow_delete'] = 'off';
688 }
689 if ( 'no' === $project_page[0]['page_allow_import'] ) {
690 $args['allow_import'] = 'off';
691 }
692 if ( 'no' === $project_page[0]['page_allow_bulk'] ) {
693 $args['bulk_actions_enabled'] = false;
694 }
695 // Show page.
696 $project_page_view = new $list_view_class($args);
697 $project_page_view->show();
698 } else {
699 // Show table administration page.
700 $media_manager = new WPDA_List_View(array(
701 'wpdaschema_name' => $wp_atts['schema_name'],
702 'table_name' => $wp_atts['table_name'],
703 'title' => $wp_atts['title'],
704 'subtitle' => $wp_atts['subtitle'],
705 'bulk_actions_enabled' => $bulk_actions_enabled,
706 'search_box_enabled' => $search_box_enabled,
707 'bulk_export_enabled' => $bulk_export_enabled,
708 'show_view_link' => $show_view_link,
709 'allow_insert' => $allow_insert,
710 'allow_update' => $allow_update,
711 'allow_delete' => $allow_delete,
712 'allow_import' => $allow_import,
713 'default_where' => $default_where,
714 ));
715 $media_manager->show();
716 }
717 ?>
718 <script type='text/javascript'>
719 // JS variable commonL10n is used in loaded scripts, copied from wp_default_scripts for responsive support
720 /* <![CDATA[ */
721 var commonL10n = {
722 "warnDelete": "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete.",
723 "dismiss": "Dismiss this notice.",
724 "collapseMenu": "Collapse Main menu",
725 "expandMenu": "Expand Main menu"
726 };
727 // Select all rows if checkbox cb-select-all-1 or cb-select-all-2 is clicked
728 jQuery(function () {
729 jQuery('#cb-select-all-1').on('click', function (event) {
730 if (jQuery('#cb-select-all-1').is(':checked')) {
731 jQuery('[name="bulk-selected[]"]').prop('checked', true);
732 jQuery('#cb-select-all-2').prop('checked', true);
733 } else {
734 jQuery('[name="bulk-selected[]"]').prop('checked', false);
735 jQuery('#cb-select-all-2').prop('checked', false);
736 }
737 });
738 jQuery('#cb-select-all-2').on('click', function (event) {
739 if (jQuery('#cb-select-all-2').is(':checked')) {
740 jQuery('[name="bulk-selected[]"]').prop('checked', true);
741 jQuery('#cb-select-all-1').prop('checked', true);
742 } else {
743 jQuery('[name="bulk-selected[]"]').prop('checked', false);
744 jQuery('#cb-select-all-1').prop('checked', false);
745 }
746 });
747 });
748 </script>
749 <style type="text/css">
750 /*@media screen and (max-width: 782px) { .row-actions { position: initial !important; } }*/
751 @media (hover:none) { .row-actions { position: initial !important; } }
752 </style>
753 <?php
754 return ob_get_clean();
755 }
756
757 }
758
759 // phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing