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

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

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