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

756 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 // Styles 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 'filter_field_name' => null,
311 'filter_field_value' => null,
312 ), $atts );
313 $shortcode_params = array();
314 foreach ( $atts as $key => $value ) {
315 if ( !key_exists( $key, $wp_atts ) ) {
316 $shortcode_params[$key] = $value;
317 }
318 }
319 ob_start();
320 $app = new WPDataAccess\Data_Apps\WPDA_App_Container($wp_atts, $shortcode_params);
321 $app->show();
322 return ob_get_clean();
323 }
324
325 public function wpda_data_explorer( $atts ) {
326 $editing = WPDA::is_editing_post();
327 if ( false !== $editing ) {
328 // Prevent errors when user is editing a post.
329 return $editing;
330 }
331 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
332 //phpcs:ignore - 8.1 proof
333 $wp_atts = shortcode_atts( array(
334 'feedback' => false,
335 ), $atts );
336 ob_start();
337 $explorer = new WPDataAccess\Data_Apps\WPDA_Data_Explorer($wp_atts);
338 $explorer->show();
339 return ob_get_clean();
340 }
341
342 public function wpda_query_builder( $atts ) {
343 $editing = WPDA::is_editing_post();
344 if ( false !== $editing ) {
345 // Prevent errors when user is editing a post.
346 return $editing;
347 }
348 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
349 //phpcs:ignore - 8.1 proof
350 $wp_atts = shortcode_atts( array(
351 'feedback' => false,
352 ), $atts );
353 ob_start();
354 $qb = new WPDataAccess\Data_Apps\WPDA_Query_Builder($wp_atts);
355 $qb->show();
356 return ob_get_clean();
357 }
358
359 /**
360 * Implementation of shortcode 'wpdataaccess'
361 *
362 * Checks the values entered on validity (as far as possible) and builds the table based on the given table name,
363 * column names and other arguments. Tables is build with class {@see WPDA_Data_Tables}.
364 *
365 * @param array $atts Arguments applied with the shortcode.
366 *
367 * @return string response
368 *
369 * @see WPDA_Data_Tables
370 *
371 * @since 1.0.0
372 */
373 public function wpdataaccess( $atts ) {
374 $editing = WPDA::is_editing_post();
375 if ( false !== $editing ) {
376 // Prevent errors when user is editing a post.
377 return $editing;
378 }
379 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDATAACCESS_POST ) ) {
380 if ( WPDA::is_post() ) {
381 return '<p>' . __( 'Sorry, you cannot use shortcode wpdataaccess in a post!', 'wp-data-access' ) . '</p>';
382 }
383 }
384 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDATAACCESS_PAGE ) ) {
385 if ( WPDA::is_page() ) {
386 return '<p>' . __( 'Sorry, you cannot use shortcode wpdataaccess in a page!', 'wp-data-access' ) . '</p>';
387 }
388 }
389 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
390 //phpcs:ignore - 8.1 proof
391 $wp_atts = shortcode_atts( array(
392 'pub_id' => '',
393 'pub_name' => '',
394 'database' => '',
395 'table' => '',
396 'columns' => '*',
397 'responsive' => 'no',
398 'responsive_cols' => '0',
399 'responsive_type' => 'collapsed',
400 'responsive_icon' => 'yes',
401 'sql_orderby' => '',
402 'filter_field_name' => '',
403 'filter_field_value' => '',
404 'nl2br' => '',
405 ), $atts );
406 $wpda_data_tables = new WPDA_Data_Tables();
407 return $wpda_data_tables->show(
408 $wp_atts['pub_id'],
409 $wp_atts['pub_name'],
410 $wp_atts['database'],
411 $wp_atts['table'],
412 str_replace( ' ', '', $wp_atts['columns'] ),
413 $wp_atts['responsive'],
414 $wp_atts['responsive_cols'],
415 $wp_atts['responsive_type'],
416 $wp_atts['responsive_icon'],
417 $wp_atts['sql_orderby'],
418 $wp_atts['filter_field_name'],
419 $wp_atts['filter_field_value'],
420 $wp_atts['nl2br']
421 );
422 }
423
424 /**
425 * Show data administration page on web page
426 *
427 * Allows to show Data Projects pages on web p0ages as well.
428 *
429 * @param array $atts Shortcode arguments.
430 *
431 * @return false|string
432 */
433 public function wpdadiehard( $atts ) {
434 $editing = WPDA::is_editing_post();
435 if ( false !== $editing ) {
436 // Prevent errors when user is editing a post.
437 return $editing;
438 }
439 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDADIEHARD_POST ) ) {
440 if ( WPDA::is_post() ) {
441 return '<p>' . __( 'Sorry, you cannot use shortcode wpdadiehard in a post!', 'wp-data-access' ) . '</p>';
442 }
443 }
444 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDADIEHARD_PAGE ) ) {
445 if ( WPDA::is_page() ) {
446 return '<p>' . __( 'Sorry, you cannot use shortcode wpdadiehard in a page!', 'wp-data-access' ) . '</p>';
447 }
448 }
449 global $wpdb;
450 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
451 //phpcs:ignore - 8.1 proof
452 $wp_atts = shortcode_atts( array(
453 'project_id' => '',
454 'page_id' => '',
455 'schema_name' => $wpdb->dbname,
456 'table_name' => '',
457 'title' => '',
458 'subtitle' => '',
459 'bulk_actions_enabled' => false,
460 'search_box_enabled' => false,
461 'bulk_export_enabled' => false,
462 'show_view_link' => 'on',
463 'allow_insert' => 'off',
464 'allow_update' => 'off',
465 'allow_delete' => 'off',
466 'allow_import' => 'off',
467 ), $atts );
468 if ( '' === $wp_atts['project_id'] && '' === $wp_atts['page_id'] && '' === $wp_atts['table_name'] ) {
469 // Either a Data Project page (project_id and page_id) or a table name must be provided.
470 return __( 'ERROR: Missing argument(s) [(project_id and page_id) or table_name]', 'wp-data-access' );
471 }
472 // Sanitize database values.
473 $wp_atts['project_id'] = sanitize_text_field( wp_unslash( $wp_atts['project_id'] ) );
474 // input var okay.
475 $wp_atts['page_id'] = sanitize_text_field( wp_unslash( $wp_atts['page_id'] ) );
476 // input var okay.
477 $wp_atts['schema_name'] = sanitize_text_field( wp_unslash( $wp_atts['schema_name'] ) );
478 // input var okay.
479 $wp_atts['table_name'] = sanitize_text_field( wp_unslash( $wp_atts['table_name'] ) );
480 // input var okay.
481 // Set default parameter values.
482 $bulk_actions_enabled = false;
483 $search_box_enabled = false;
484 $bulk_export_enabled = false;
485 $show_view_link = 'on';
486 $allow_insert = 'off';
487 $allow_update = 'off';
488 $allow_delete = 'off';
489 $allow_import = 'off';
490 // Check arguments.
491 if ( 'true' === $wp_atts['bulk_actions_enabled'] ) {
492 $bulk_actions_enabled = true;
493 }
494 if ( 'true' === $wp_atts['search_box_enabled'] ) {
495 $search_box_enabled = true;
496 }
497 if ( 'true' === $wp_atts['bulk_export_enabled'] ) {
498 $bulk_export_enabled = true;
499 }
500 if ( 'false' === $wp_atts['show_view_link'] ) {
501 $show_view_link = 'off';
502 }
503 if ( 'true' === $wp_atts['allow_insert'] ) {
504 $allow_insert = 'on';
505 }
506 if ( 'true' === $wp_atts['allow_update'] ) {
507 $allow_update = 'on';
508 }
509 if ( 'true' === $wp_atts['allow_delete'] ) {
510 $allow_delete = 'on';
511 }
512 if ( 'true' === $wp_atts['allow_import'] ) {
513 $allow_import = 'on';
514 }
515 $default_where = '';
516 if ( isset( $atts['filter_field_name'] ) && isset( $atts['filter_field_value'] ) ) {
517 $filter_field_name = str_replace( '`', '', sanitize_text_field( wp_unslash( $atts['filter_field_name'] ) ) );
518 // input var okay.
519 $filter_field_value = sanitize_text_field( wp_unslash( $atts['filter_field_value'] ) );
520 // input var okay.
521 $filter_field_name_array = array_map( 'trim', explode( ',', $filter_field_name ) );
522 //phpcs:ignore - 8.1 proof
523 $filter_field_value_array = array_map( 'trim', explode( ',', $filter_field_value ) );
524 //phpcs:ignore - 8.1 proof
525 if ( count( $filter_field_name_array ) === count( $filter_field_value_array ) ) {
526 //phpcs:ignore - 8.1 proof
527 // Add filter to where clause.
528 for ($i = 0; $i < count( $filter_field_name_array ); $i++) {
529 // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall, Squiz.PHP.DisallowSizeFunctionsInLoops
530 $default_where .= (( '' === $default_where ? '' : ' and ' )) . $wpdb->prepare(
531 ' `%1s` like %s ',
532 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
533 array(WPDA::remove_backticks( $filter_field_name_array[$i] ), $filter_field_value_array[$i])
534 );
535 }
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 $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' );
593 // db call ok; no-cache ok.
594 if ( 0 === $wpdb->num_rows ) {
595 // This should never happen as it was already tested before.
596 return __( 'ERROR: Data Project page not found [need a valid project_id and page_id]', 'wp-data-access' );
597 }
598 if ( 'off' !== WPDA::get_option( WPDA::OPTION_WPDA_USE_ROLES_IN_SHORTCODE ) ) {
599 // Check if user has role.
600 $user_roles = WPDA::get_current_user_roles();
601 if ( false === $user_roles ) {
602 // Cannot determine the user role(s). Not able to show project menus.
603 return __( 'ERROR: No access [could not determine user role]', 'wp-data-access' );
604 }
605 $user_has_role = false;
606 if ( '' === $project_page[0]['page_role'] || null === $project_page[0]['page_role'] ) {
607 $user_has_role = in_array( 'administrator', $user_roles, true );
608 //phpcs:ignore - 8.1 proof
609 } else {
610 $user_role_array = explode( ',', $project_page[0]['page_role'] );
611 //phpcs:ignore - 8.1 proof
612 foreach ( $user_role_array as $user_role_array_item ) {
613 $user_has_role = in_array( $user_role_array_item, $user_roles, true );
614 //phpcs:ignore - 8.1 proof
615 if ( $user_has_role ) {
616 break;
617 }
618 }
619 }
620 if ( !$user_has_role ) {
621 return __( 'ERROR: No access [missing role]', 'wp-data-access' );
622 }
623 }
624 // Determine plugin classes to be used.
625 if ( 'static' === $project_page[0]['page_type'] ) {
626 return '';
627 } elseif ( 'table' === $project_page[0]['page_type'] ) {
628 $list_view_class = 'WPDataProjects\\List_Table\\WPDP_List_View';
629 $list_table_class = 'WPDataProjects\\List_Table\\WPDP_List_Table';
630 $edit_form_class = 'WPDataProjects\\Simple_Form\\WPDP_Simple_Form';
631 } else {
632 $list_view_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_View';
633 $list_table_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_Table';
634 $edit_form_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_Form';
635 }
636 if ( null !== $project_page[0]['page_where'] && '' !== $project_page[0]['page_where'] ) {
637 if ( 'where' === substr( str_replace( ' ', '', $project_page[0]['page_where'] ), 0, 5 ) ) {
638 $where_clause = " {$project_page[0]['page_where']}";
639 } else {
640 $where_clause = " where {$project_page[0]['page_where']} ";
641 }
642 $where_clause = WPDA::substitute_environment_vars( $where_clause );
643 } else {
644 $where_clause = '';
645 }
646 if ( '' === $default_where ) {
647 $default_where = $where_clause;
648 } else {
649 if ( '' === $where_clause ) {
650 $default_where = " where {$default_where} ";
651 } else {
652 $default_where = " {$where_clause} and {$default_where} ";
653 }
654 }
655 $default_orderby = $project_page[0]['page_orderby'];
656 // Prepare arguments.
657 $args = array(
658 'page_hook_suffix' => 'WPDA_WPDP',
659 'wpdaschema_name' => $project_page[0]['page_schema_name'],
660 'table_name' => $project_page[0]['page_table_name'],
661 'list_table_class' => $list_table_class,
662 'edit_form_class' => $edit_form_class,
663 'project_id' => $wp_atts['project_id'],
664 'page_id' => $wp_atts['page_id'],
665 'default_where' => $default_where,
666 'where_clause' => $default_where,
667 'orderby_clause' => $default_orderby,
668 );
669 if ( 'view' === $project_page[0]['page_mode'] ) {
670 $args['allow_update'] = 'off';
671 $args['allow_import'] = 'off';
672 }
673 if ( 'no' === $project_page[0]['page_allow_insert'] ) {
674 $args['allow_insert'] = 'off';
675 $args['allow_import'] = 'off';
676 }
677 if ( 'no' === $project_page[0]['page_allow_delete'] ) {
678 $args['allow_delete'] = 'off';
679 }
680 if ( 'only' === $project_page[0]['page_allow_insert'] ) {
681 $args['action'] = 'new';
682 $args['allow_insert'] = 'only';
683 $args['allow_update'] = 'off';
684 $args['allow_import'] = 'off';
685 $args['allow_delete'] = 'off';
686 }
687 if ( 'no' === $project_page[0]['page_allow_import'] ) {
688 $args['allow_import'] = 'off';
689 }
690 if ( 'no' === $project_page[0]['page_allow_bulk'] ) {
691 $args['bulk_actions_enabled'] = false;
692 }
693 // Show page.
694 $project_page_view = new $list_view_class($args);
695 $project_page_view->show();
696 } else {
697 // Show table administration page.
698 $media_manager = new WPDA_List_View(array(
699 'wpdaschema_name' => $wp_atts['schema_name'],
700 'table_name' => $wp_atts['table_name'],
701 'title' => $wp_atts['title'],
702 'subtitle' => $wp_atts['subtitle'],
703 'bulk_actions_enabled' => $bulk_actions_enabled,
704 'search_box_enabled' => $search_box_enabled,
705 'bulk_export_enabled' => $bulk_export_enabled,
706 'show_view_link' => $show_view_link,
707 'allow_insert' => $allow_insert,
708 'allow_update' => $allow_update,
709 'allow_delete' => $allow_delete,
710 'allow_import' => $allow_import,
711 'default_where' => $default_where,
712 ));
713 $media_manager->show();
714 }
715 ?>
716 <script type='text/javascript'>
717 // JS variable commonL10n is used in loaded scripts, copied from wp_default_scripts for responsive support
718 /* <![CDATA[ */
719 var commonL10n = {
720 "warnDelete": "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete.",
721 "dismiss": "Dismiss this notice.",
722 "collapseMenu": "Collapse Main menu",
723 "expandMenu": "Expand Main menu"
724 };
725 // Select all rows if checkbox cb-select-all-1 or cb-select-all-2 is clicked
726 jQuery(function () {
727 jQuery('#cb-select-all-1').on('click', function (event) {
728 if (jQuery('#cb-select-all-1').is(':checked')) {
729 jQuery('[name="bulk-selected[]"]').prop('checked', true);
730 jQuery('#cb-select-all-2').prop('checked', true);
731 } else {
732 jQuery('[name="bulk-selected[]"]').prop('checked', false);
733 jQuery('#cb-select-all-2').prop('checked', false);
734 }
735 });
736 jQuery('#cb-select-all-2').on('click', function (event) {
737 if (jQuery('#cb-select-all-2').is(':checked')) {
738 jQuery('[name="bulk-selected[]"]').prop('checked', true);
739 jQuery('#cb-select-all-1').prop('checked', true);
740 } else {
741 jQuery('[name="bulk-selected[]"]').prop('checked', false);
742 jQuery('#cb-select-all-1').prop('checked', false);
743 }
744 });
745 });
746 </script>
747 <style type="text/css">
748 /*@media screen and (max-width: 782px) { .row-actions { position: initial !important; } }*/
749 @media (hover:none) { .row-actions { position: initial !important; } }
750 </style>
751 <?php
752 return ob_get_clean();
753 }
754
755 }
756