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

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