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

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