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

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