PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.23
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.23
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
wp-data-access / 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.23, at public/class-wp-data-access-public.php

731 lines 30.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_Apps\WPDA_Apps;
10 use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Exist;
11 use WPDataAccess\Data_Tables\WPDA_Data_Tables;
12 use WPDataAccess\List_Table\WPDA_List_View;
13 use WPDataAccess\WPDA;
14 use WPDataAccess\Premium\WPDAPRO_Data_Publisher\WPDAPRO_Data_Publisher_Init;
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_Apps();
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_apps', array($this, 'wpda_apps') );
259 add_shortcode( 'wpda_app', array($this, 'wpda_app') );
260 add_shortcode( 'wpda_data_explorer', array($this, 'wpda_data_explorer') );
261 add_shortcode( 'wpdataaccess', array($this, 'wpdataaccess') );
262 add_shortcode( 'wpdadiehard', array($this, 'wpdadiehard') );
263 }
264
265 public function wpda_apps( $atts ) {
266 $editing = WPDA::is_editing_post();
267 if ( false !== $editing ) {
268 // Prevent errors when user is editing a post.
269 return $editing;
270 }
271 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
272 //phpcs:ignore - 8.1 proof
273 $wp_atts = shortcode_atts( array(
274 'feedback' => false,
275 ), $atts );
276 ob_start();
277 $apps = new WPDataAccess\Data_Apps\WPDA_Apps_List($wp_atts);
278 $apps->show();
279 return ob_get_clean();
280 }
281
282 public function wpda_app( $atts ) {
283 $editing = WPDA::is_editing_post();
284 if ( false !== $editing ) {
285 // Prevent errors when user is editing a post.
286 return $editing;
287 }
288 if ( isset( $_POST['is_fb_preview'], $_GET['et_pb_preview'] ) && 'true' === $_POST['is_fb_preview'] && 'true' === $_GET['et_pb_preview'] ) {
289 // Divi Visual Builder preview not working!
290 // Styles are not properly loaded into the Divi Visual Builder.
291 ob_start();
292 ?>
293 <div style="width: 100%; border: 1px solid #ccc; padding: 50px; display: grid; gap: 20px; background-color: rgb(249,249,249); border-radius: 5px;">
294 <div>
295 No preview in Visual Builder. App will appear once Visual Builder is closed.
296 </div>
297 </div>
298 <?php
299 return ob_get_clean();
300 }
301 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
302 //phpcs:ignore - 8.1 proof
303 $wp_atts = shortcode_atts( array(
304 'app_id' => null,
305 'feedback' => false,
306 'builders' => true,
307 'filter_field_name' => null,
308 'filter_field_value' => null,
309 ), $atts );
310 $shortcode_args = array_diff( $atts, $wp_atts );
311 ob_start();
312 $app = new WPDataAccess\Data_Apps\WPDA_App_Container($wp_atts, $shortcode_args);
313 $app->show();
314 return ob_get_clean();
315 }
316
317 public function wpda_data_explorer( $atts ) {
318 $editing = WPDA::is_editing_post();
319 if ( false !== $editing ) {
320 // Prevent errors when user is editing a post.
321 return $editing;
322 }
323 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
324 //phpcs:ignore - 8.1 proof
325 $wp_atts = shortcode_atts( array(
326 'feedback' => false,
327 ), $atts );
328 ob_start();
329 $explorer = new WPDataAccess\Data_Apps\WPDA_Explorer_Container($wp_atts);
330 $explorer->show();
331 return ob_get_clean();
332 }
333
334 /**
335 * Implementation of shortcode 'wpdataaccess'
336 *
337 * Checks the values entered on validity (as far as possible) and builds the table based on the given table name,
338 * column names and other arguments. Tables is build with class {@see WPDA_Data_Tables}.
339 *
340 * @param array $atts Arguments applied with the shortcode.
341 *
342 * @return string response
343 *
344 * @see WPDA_Data_Tables
345 *
346 * @since 1.0.0
347 */
348 public function wpdataaccess( $atts ) {
349 $editing = WPDA::is_editing_post();
350 if ( false !== $editing ) {
351 // Prevent errors when user is editing a post.
352 return $editing;
353 }
354 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDATAACCESS_POST ) ) {
355 if ( WPDA::is_post() ) {
356 return '<p>' . __( 'Sorry, you cannot use shortcode wpdataaccess in a post!', 'wp-data-access' ) . '</p>';
357 }
358 }
359 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDATAACCESS_PAGE ) ) {
360 if ( WPDA::is_page() ) {
361 return '<p>' . __( 'Sorry, you cannot use shortcode wpdataaccess in a page!', 'wp-data-access' ) . '</p>';
362 }
363 }
364 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
365 //phpcs:ignore - 8.1 proof
366 $wp_atts = shortcode_atts( array(
367 'pub_id' => '',
368 'pub_name' => '',
369 'database' => '',
370 'table' => '',
371 'columns' => '*',
372 'responsive' => 'no',
373 'responsive_cols' => '0',
374 'responsive_type' => 'collapsed',
375 'responsive_icon' => 'yes',
376 'sql_orderby' => '',
377 'filter_field_name' => '',
378 'filter_field_value' => '',
379 'nl2br' => '',
380 ), $atts );
381 $wpda_data_tables = new WPDA_Data_Tables();
382 return $wpda_data_tables->show(
383 $wp_atts['pub_id'],
384 $wp_atts['pub_name'],
385 $wp_atts['database'],
386 $wp_atts['table'],
387 str_replace( ' ', '', $wp_atts['columns'] ),
388 $wp_atts['responsive'],
389 $wp_atts['responsive_cols'],
390 $wp_atts['responsive_type'],
391 $wp_atts['responsive_icon'],
392 $wp_atts['sql_orderby'],
393 $wp_atts['filter_field_name'],
394 $wp_atts['filter_field_value'],
395 $wp_atts['nl2br']
396 );
397 }
398
399 /**
400 * Show data administration page on web page
401 *
402 * Allows to show Data Projects pages on web p0ages as well.
403 *
404 * @param array $atts Shortcode arguments.
405 *
406 * @return false|string
407 */
408 public function wpdadiehard( $atts ) {
409 $editing = WPDA::is_editing_post();
410 if ( false !== $editing ) {
411 // Prevent errors when user is editing a post.
412 return $editing;
413 }
414 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDADIEHARD_POST ) ) {
415 if ( WPDA::is_post() ) {
416 return '<p>' . __( 'Sorry, you cannot use shortcode wpdadiehard in a post!', 'wp-data-access' ) . '</p>';
417 }
418 }
419 if ( 'on' !== WPDA::get_option( WPDA::OPTION_PLUGIN_WPDADIEHARD_PAGE ) ) {
420 if ( WPDA::is_page() ) {
421 return '<p>' . __( 'Sorry, you cannot use shortcode wpdadiehard in a page!', 'wp-data-access' ) . '</p>';
422 }
423 }
424 global $wpdb;
425 $atts = array_change_key_case( (array) $atts, CASE_LOWER );
426 //phpcs:ignore - 8.1 proof
427 $wp_atts = shortcode_atts( array(
428 'project_id' => '',
429 'page_id' => '',
430 'schema_name' => $wpdb->dbname,
431 'table_name' => '',
432 'title' => '',
433 'subtitle' => '',
434 'bulk_actions_enabled' => false,
435 'search_box_enabled' => false,
436 'bulk_export_enabled' => false,
437 'show_view_link' => 'on',
438 'allow_insert' => 'off',
439 'allow_update' => 'off',
440 'allow_delete' => 'off',
441 'allow_import' => 'off',
442 ), $atts );
443 if ( '' === $wp_atts['project_id'] && '' === $wp_atts['page_id'] && '' === $wp_atts['table_name'] ) {
444 // Either a Data Project page (project_id and page_id) or a table name must be provided.
445 return __( 'ERROR: Missing argument(s) [(project_id and page_id) or table_name]', 'wp-data-access' );
446 }
447 // Sanitize database values.
448 $wp_atts['project_id'] = sanitize_text_field( wp_unslash( $wp_atts['project_id'] ) );
449 // input var okay.
450 $wp_atts['page_id'] = sanitize_text_field( wp_unslash( $wp_atts['page_id'] ) );
451 // input var okay.
452 $wp_atts['schema_name'] = sanitize_text_field( wp_unslash( $wp_atts['schema_name'] ) );
453 // input var okay.
454 $wp_atts['table_name'] = sanitize_text_field( wp_unslash( $wp_atts['table_name'] ) );
455 // input var okay.
456 // Set default parameter values.
457 $bulk_actions_enabled = false;
458 $search_box_enabled = false;
459 $bulk_export_enabled = false;
460 $show_view_link = 'on';
461 $allow_insert = 'off';
462 $allow_update = 'off';
463 $allow_delete = 'off';
464 $allow_import = 'off';
465 // Check arguments.
466 if ( 'true' === $wp_atts['bulk_actions_enabled'] ) {
467 $bulk_actions_enabled = true;
468 }
469 if ( 'true' === $wp_atts['search_box_enabled'] ) {
470 $search_box_enabled = true;
471 }
472 if ( 'true' === $wp_atts['bulk_export_enabled'] ) {
473 $bulk_export_enabled = true;
474 }
475 if ( 'false' === $wp_atts['show_view_link'] ) {
476 $show_view_link = 'off';
477 }
478 if ( 'true' === $wp_atts['allow_insert'] ) {
479 $allow_insert = 'on';
480 }
481 if ( 'true' === $wp_atts['allow_update'] ) {
482 $allow_update = 'on';
483 }
484 if ( 'true' === $wp_atts['allow_delete'] ) {
485 $allow_delete = 'on';
486 }
487 if ( 'true' === $wp_atts['allow_import'] ) {
488 $allow_import = 'on';
489 }
490 $default_where = '';
491 if ( isset( $atts['filter_field_name'] ) && isset( $atts['filter_field_value'] ) ) {
492 $filter_field_name = str_replace( '`', '', sanitize_text_field( wp_unslash( $atts['filter_field_name'] ) ) );
493 // input var okay.
494 $filter_field_value = sanitize_text_field( wp_unslash( $atts['filter_field_value'] ) );
495 // input var okay.
496 $filter_field_name_array = array_map( 'trim', explode( ',', $filter_field_name ) );
497 //phpcs:ignore - 8.1 proof
498 $filter_field_value_array = array_map( 'trim', explode( ',', $filter_field_value ) );
499 //phpcs:ignore - 8.1 proof
500 if ( count( $filter_field_name_array ) === count( $filter_field_value_array ) ) {
501 //phpcs:ignore - 8.1 proof
502 // Add filter to where clause.
503 for ($i = 0; $i < count( $filter_field_name_array ); $i++) {
504 // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall, Squiz.PHP.DisallowSizeFunctionsInLoops
505 $default_where .= (( '' === $default_where ? '' : ' and ' )) . $wpdb->prepare(
506 ' `%1s` like %s ',
507 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders
508 array(WPDA::remove_backticks( $filter_field_name_array[$i] ), $filter_field_value_array[$i])
509 );
510 }
511 }
512 }
513 // Is this a Data Projects page or a table administration page?
514 if ( '' !== $wp_atts['project_id'] && '' !== $wp_atts['page_id'] ) {
515 // phpcs:ignore Generic.CodeAnalysis.EmptyStatement
516 // Request for Data Projects page (check is performed in WPDP_List_Page).
517 } else {
518 // Request for table administration page.
519 // Check schema name.
520 if ( 'sys' === $wp_atts['schema_name'] || 'mysql' === $wp_atts['schema_name'] || 'information_schema' === $wp_atts['schema_name'] ) {
521 // No access to MySQL databases (meta data)!
522 return __( 'ERROR: No access to MySQL meta data', 'wp-data-access' );
523 }
524 // Check database table name.
525 if ( '' === $wp_atts['table_name'] ) {
526 // Table name must be provided! No database administration in the public area!
527 return __( 'ERROR: Missing argument [table_name]', 'wp-data-access' );
528 }
529 // Check if table exists (to prevent sql injection) and access is granted.
530 $wpda_dictionary_checks = new WPDA_Dictionary_Exist($wp_atts['schema_name'], $wp_atts['table_name']);
531 if ( !$wpda_dictionary_checks->table_exists( true, false ) ) {
532 // Table not found.
533 return '<p>' . __( 'ERROR: Invalid table name or not authorized', 'wp-data-access' ) . '</p>';
534 }
535 }
536 // Make sure user has access to necessary (fake) classes and functions in the frontend.
537 require_once plugin_dir_path( __DIR__ ) . 'wp-data-access-diehard.php';
538 // Make sure all style and JS is available.
539 wp_enqueue_script( 'wpda_admin_scripts' );
540 wp_enqueue_script( 'wpdataprojects' );
541 wp_enqueue_script( 'wpdadiehard' );
542 wp_enqueue_script( 'jquery-ui-core' );
543 wp_enqueue_script( 'jquery-ui-dialog' );
544 wp_enqueue_script( 'jquery-ui-tabs' );
545 wp_enqueue_script( 'jquery-ui-sortable' );
546 wp_enqueue_script( 'jquery-ui-tooltip' );
547 wp_enqueue_script( 'jquery-ui-autocomplete' );
548 wp_enqueue_style( 'dashicons' );
549 wp_enqueue_style( 'wpdadiehard' );
550 wp_enqueue_style( 'wpdataaccess' );
551 wp_enqueue_style( 'wpdataprojects' );
552 wp_enqueue_style( 'wpda_notify' );
553 wp_enqueue_style(
554 'wpda_ui_darkness',
555 plugins_url( '../assets/css/jquery-ui.min.css', __FILE__ ),
556 array(),
557 WPDA::get_option( WPDA::OPTION_WPDA_VERSION )
558 );
559 wp_enqueue_media();
560 do_action( 'wpda_wpdadiehard_prepare' );
561 ob_start();
562 // Set page argument to allow public access.
563 $_REQUEST['page'] = 'diehard';
564 if ( '' !== $wp_atts['project_id'] && '' !== $wp_atts['page_id'] ) {
565 // Show Data Projects page (check is performed in WPDP_List_Page).
566 // Get page values.
567 $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' );
568 // db call ok; no-cache ok.
569 if ( 0 === $wpdb->num_rows ) {
570 // This should never happen as it was already tested before.
571 return __( 'ERROR: Data Project page not found [need a valid project_id and page_id]', 'wp-data-access' );
572 }
573 if ( 'off' !== WPDA::get_option( WPDA::OPTION_WPDA_USE_ROLES_IN_SHORTCODE ) ) {
574 // Check if user has role.
575 $user_roles = WPDA::get_current_user_roles();
576 if ( false === $user_roles ) {
577 // Cannot determine the user role(s). Not able to show project menus.
578 return __( 'ERROR: No access [could not determine user role]', 'wp-data-access' );
579 }
580 $user_has_role = false;
581 if ( '' === $project_page[0]['page_role'] || null === $project_page[0]['page_role'] ) {
582 $user_has_role = in_array( 'administrator', $user_roles, true );
583 //phpcs:ignore - 8.1 proof
584 } else {
585 $user_role_array = explode( ',', $project_page[0]['page_role'] );
586 //phpcs:ignore - 8.1 proof
587 foreach ( $user_role_array as $user_role_array_item ) {
588 $user_has_role = in_array( $user_role_array_item, $user_roles, true );
589 //phpcs:ignore - 8.1 proof
590 if ( $user_has_role ) {
591 break;
592 }
593 }
594 }
595 if ( !$user_has_role ) {
596 return __( 'ERROR: No access [missing role]', 'wp-data-access' );
597 }
598 }
599 // Determine plugin classes to be used.
600 if ( 'static' === $project_page[0]['page_type'] ) {
601 return '';
602 } elseif ( 'table' === $project_page[0]['page_type'] ) {
603 $list_view_class = 'WPDataProjects\\List_Table\\WPDP_List_View';
604 $list_table_class = 'WPDataProjects\\List_Table\\WPDP_List_Table';
605 $edit_form_class = 'WPDataProjects\\Simple_Form\\WPDP_Simple_Form';
606 } else {
607 $list_view_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_View';
608 $list_table_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_Table';
609 $edit_form_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_Form';
610 }
611 if ( null !== $project_page[0]['page_where'] && '' !== $project_page[0]['page_where'] ) {
612 if ( 'where' === substr( str_replace( ' ', '', $project_page[0]['page_where'] ), 0, 5 ) ) {
613 $where_clause = " {$project_page[0]['page_where']}";
614 } else {
615 $where_clause = " where {$project_page[0]['page_where']} ";
616 }
617 $where_clause = WPDA::substitute_environment_vars( $where_clause );
618 } else {
619 $where_clause = '';
620 }
621 if ( '' === $default_where ) {
622 $default_where = $where_clause;
623 } else {
624 if ( '' === $where_clause ) {
625 $default_where = " where {$default_where} ";
626 } else {
627 $default_where = " {$where_clause} and {$default_where} ";
628 }
629 }
630 $default_orderby = $project_page[0]['page_orderby'];
631 // Prepare arguments.
632 $args = array(
633 'page_hook_suffix' => 'WPDA_WPDP',
634 'wpdaschema_name' => $project_page[0]['page_schema_name'],
635 'table_name' => $project_page[0]['page_table_name'],
636 'list_table_class' => $list_table_class,
637 'edit_form_class' => $edit_form_class,
638 'project_id' => $wp_atts['project_id'],
639 'page_id' => $wp_atts['page_id'],
640 'default_where' => $default_where,
641 'where_clause' => $default_where,
642 'orderby_clause' => $default_orderby,
643 );
644 if ( 'view' === $project_page[0]['page_mode'] ) {
645 $args['allow_update'] = 'off';
646 $args['allow_import'] = 'off';
647 }
648 if ( 'no' === $project_page[0]['page_allow_insert'] ) {
649 $args['allow_insert'] = 'off';
650 $args['allow_import'] = 'off';
651 }
652 if ( 'no' === $project_page[0]['page_allow_delete'] ) {
653 $args['allow_delete'] = 'off';
654 }
655 if ( 'only' === $project_page[0]['page_allow_insert'] ) {
656 $args['action'] = 'new';
657 $args['allow_insert'] = 'only';
658 $args['allow_update'] = 'off';
659 $args['allow_import'] = 'off';
660 $args['allow_delete'] = 'off';
661 }
662 if ( 'no' === $project_page[0]['page_allow_import'] ) {
663 $args['allow_import'] = 'off';
664 }
665 if ( 'no' === $project_page[0]['page_allow_bulk'] ) {
666 $args['bulk_actions_enabled'] = false;
667 }
668 // Show page.
669 $project_page_view = new $list_view_class($args);
670 $project_page_view->show();
671 } else {
672 // Show table administration page.
673 $media_manager = new WPDA_List_View(array(
674 'wpdaschema_name' => $wp_atts['schema_name'],
675 'table_name' => $wp_atts['table_name'],
676 'title' => $wp_atts['title'],
677 'subtitle' => $wp_atts['subtitle'],
678 'bulk_actions_enabled' => $bulk_actions_enabled,
679 'search_box_enabled' => $search_box_enabled,
680 'bulk_export_enabled' => $bulk_export_enabled,
681 'show_view_link' => $show_view_link,
682 'allow_insert' => $allow_insert,
683 'allow_update' => $allow_update,
684 'allow_delete' => $allow_delete,
685 'allow_import' => $allow_import,
686 'default_where' => $default_where,
687 ));
688 $media_manager->show();
689 }
690 ?>
691 <script type='text/javascript'>
692 // JS variable commonL10n is used in loaded scripts, copied from wp_default_scripts for responsive support
693 /* <![CDATA[ */
694 var commonL10n = {
695 "warnDelete": "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete.",
696 "dismiss": "Dismiss this notice.",
697 "collapseMenu": "Collapse Main menu",
698 "expandMenu": "Expand Main menu"
699 };
700 // Select all rows if checkbox cb-select-all-1 or cb-select-all-2 is clicked
701 jQuery(function () {
702 jQuery('#cb-select-all-1').on('click', function (event) {
703 if (jQuery('#cb-select-all-1').is(':checked')) {
704 jQuery('[name="bulk-selected[]"]').prop('checked', true);
705 jQuery('#cb-select-all-2').prop('checked', true);
706 } else {
707 jQuery('[name="bulk-selected[]"]').prop('checked', false);
708 jQuery('#cb-select-all-2').prop('checked', false);
709 }
710 });
711 jQuery('#cb-select-all-2').on('click', function (event) {
712 if (jQuery('#cb-select-all-2').is(':checked')) {
713 jQuery('[name="bulk-selected[]"]').prop('checked', true);
714 jQuery('#cb-select-all-1').prop('checked', true);
715 } else {
716 jQuery('[name="bulk-selected[]"]').prop('checked', false);
717 jQuery('#cb-select-all-1').prop('checked', false);
718 }
719 });
720 });
721 </script>
722 <style type="text/css">
723 /*@media screen and (max-width: 782px) { .row-actions { position: initial !important; } }*/
724 @media (hover:none) { .row-actions { position: initial !important; } }
725 </style>
726 <?php
727 return ob_get_clean();
728 }
729
730 }
731