| 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 |
'title' => '', |
| 459 |
'subtitle' => '', |
| 460 |
'bulk_actions_enabled' => false, |
| 461 |
'search_box_enabled' => false, |
| 462 |
'bulk_export_enabled' => false, |
| 463 |
'show_view_link' => 'on', |
| 464 |
'allow_insert' => 'off', |
| 465 |
'allow_update' => 'off', |
| 466 |
'allow_delete' => 'off', |
| 467 |
'allow_import' => 'off', |
| 468 |
), $atts ); |
| 469 |
if ( '' === $wp_atts['project_id'] && '' === $wp_atts['page_id'] ) { |
| 470 |
// Dashboard menu feature was removed. Parameter table_name no longer valid. |
| 471 |
return __( 'ERROR: Missing argument(s) [project_id and page_id]', 'wp-data-access' ); |
| 472 |
} |
| 473 |
// Sanitize database values. |
| 474 |
$wp_atts['project_id'] = sanitize_text_field( wp_unslash( $wp_atts['project_id'] ) ); |
| 475 |
// input var okay. |
| 476 |
$wp_atts['page_id'] = sanitize_text_field( wp_unslash( $wp_atts['page_id'] ) ); |
| 477 |
// input var okay. |
| 478 |
// Set default parameter values. |
| 479 |
$bulk_actions_enabled = false; |
| 480 |
$search_box_enabled = false; |
| 481 |
$bulk_export_enabled = false; |
| 482 |
$show_view_link = 'on'; |
| 483 |
$allow_insert = 'off'; |
| 484 |
$allow_update = 'off'; |
| 485 |
$allow_delete = 'off'; |
| 486 |
$allow_import = 'off'; |
| 487 |
// Check arguments. |
| 488 |
if ( 'true' === $wp_atts['bulk_actions_enabled'] ) { |
| 489 |
$bulk_actions_enabled = true; |
| 490 |
} |
| 491 |
if ( 'true' === $wp_atts['search_box_enabled'] ) { |
| 492 |
$search_box_enabled = true; |
| 493 |
} |
| 494 |
if ( 'true' === $wp_atts['bulk_export_enabled'] ) { |
| 495 |
$bulk_export_enabled = true; |
| 496 |
} |
| 497 |
if ( 'false' === $wp_atts['show_view_link'] ) { |
| 498 |
$show_view_link = 'off'; |
| 499 |
} |
| 500 |
if ( 'true' === $wp_atts['allow_insert'] ) { |
| 501 |
$allow_insert = 'on'; |
| 502 |
} |
| 503 |
if ( 'true' === $wp_atts['allow_update'] ) { |
| 504 |
$allow_update = 'on'; |
| 505 |
} |
| 506 |
if ( 'true' === $wp_atts['allow_delete'] ) { |
| 507 |
$allow_delete = 'on'; |
| 508 |
} |
| 509 |
if ( 'true' === $wp_atts['allow_import'] ) { |
| 510 |
$allow_import = 'on'; |
| 511 |
} |
| 512 |
$default_where = ''; |
| 513 |
if ( isset( $atts['filter_field_name'] ) && isset( $atts['filter_field_value'] ) ) { |
| 514 |
$filter_field_name = str_replace( '`', '', sanitize_text_field( wp_unslash( $atts['filter_field_name'] ) ) ); |
| 515 |
// input var okay. |
| 516 |
$filter_field_value = sanitize_text_field( wp_unslash( $atts['filter_field_value'] ) ); |
| 517 |
// input var okay. |
| 518 |
$filter_field_name_array = array_map( 'trim', explode( ',', $filter_field_name ) ); |
| 519 |
//phpcs:ignore - 8.1 proof |
| 520 |
$filter_field_value_array = array_map( 'trim', explode( ',', $filter_field_value ) ); |
| 521 |
//phpcs:ignore - 8.1 proof |
| 522 |
if ( count( $filter_field_name_array ) === count( $filter_field_value_array ) ) { |
| 523 |
//phpcs:ignore - 8.1 proof |
| 524 |
// Add filter to where clause. |
| 525 |
// phpcs:disable Generic.CodeAnalysis.ForLoopWithTestFunctionCall, Squiz.PHP.DisallowSizeFunctionsInLoops, WordPress.DB.PreparedSQLPlaceholders |
| 526 |
for ($i = 0; $i < count( $filter_field_name_array ); $i++) { |
| 527 |
$default_where .= (( '' === $default_where ? '' : ' and ' )) . $wpdb->prepare( ' `%1s` like %s ', array(WPDA::remove_backticks( $filter_field_name_array[$i] ), $filter_field_value_array[$i]) ); |
| 528 |
} |
| 529 |
// phpcs:enable Generic.CodeAnalysis.ForLoopWithTestFunctionCall, Squiz.PHP.DisallowSizeFunctionsInLoops, WordPress.DB.PreparedSQLPlaceholders |
| 530 |
} |
| 531 |
} |
| 532 |
// Make sure user has access to necessary (fake) classes and functions in the frontend. |
| 533 |
require_once plugin_dir_path( __DIR__ ) . 'wp-data-access-diehard.php'; |
| 534 |
// Make sure all style and JS is available. |
| 535 |
wp_enqueue_script( 'wpda_admin_scripts' ); |
| 536 |
wp_enqueue_script( 'wpdataprojects' ); |
| 537 |
wp_enqueue_script( 'wpdadiehard' ); |
| 538 |
wp_enqueue_script( 'jquery-ui-core' ); |
| 539 |
wp_enqueue_script( 'jquery-ui-dialog' ); |
| 540 |
wp_enqueue_script( 'jquery-ui-tabs' ); |
| 541 |
wp_enqueue_script( 'jquery-ui-sortable' ); |
| 542 |
wp_enqueue_script( 'jquery-ui-tooltip' ); |
| 543 |
wp_enqueue_script( 'jquery-ui-autocomplete' ); |
| 544 |
wp_enqueue_style( 'dashicons' ); |
| 545 |
wp_enqueue_style( 'wpdadiehard' ); |
| 546 |
wp_enqueue_style( 'wpdataaccess' ); |
| 547 |
wp_enqueue_style( 'wpdataprojects' ); |
| 548 |
wp_enqueue_style( 'wpda_notify' ); |
| 549 |
wp_enqueue_style( |
| 550 |
'wpda_ui_darkness', |
| 551 |
plugins_url( '../assets/css/jquery-ui.min.css', __FILE__ ), |
| 552 |
array(), |
| 553 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 554 |
); |
| 555 |
wp_enqueue_media(); |
| 556 |
do_action( 'wpda_wpdadiehard_prepare' ); |
| 557 |
ob_start(); |
| 558 |
// Set page argument to allow public access. |
| 559 |
$_REQUEST['page'] = 'diehard'; |
| 560 |
// Show Data Projects page (check is performed in WPDP_List_Page). |
| 561 |
// Get page values. |
| 562 |
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- plugin table |
| 563 |
$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' ); |
| 564 |
// db call ok; no-cache ok. |
| 565 |
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching |
| 566 |
if ( 0 === $wpdb->num_rows ) { |
| 567 |
// This should never happen as it was already tested before. |
| 568 |
return __( 'ERROR: Data Project page not found [need a valid project_id and page_id]', 'wp-data-access' ); |
| 569 |
} |
| 570 |
// Check if user has role. |
| 571 |
$user_roles = WPDA::get_current_user_roles(); |
| 572 |
if ( false === $user_roles ) { |
| 573 |
// Cannot determine the user role(s). Not able to show project menus. |
| 574 |
return __( 'ERROR: No access [could not determine user role]', 'wp-data-access' ); |
| 575 |
} |
| 576 |
$user_has_role = in_array( 'administrator', $user_roles, true ); |
| 577 |
if ( !$user_has_role && '' !== $project_page[0]['page_role'] && null !== $project_page[0]['page_role'] ) { |
| 578 |
$user_role_array = explode( ',', $project_page[0]['page_role'] ); |
| 579 |
foreach ( $user_role_array as $user_role_array_item ) { |
| 580 |
$user_has_role = in_array( $user_role_array_item, $user_roles, true ); |
| 581 |
if ( $user_has_role ) { |
| 582 |
break; |
| 583 |
} |
| 584 |
} |
| 585 |
} |
| 586 |
if ( !$user_has_role ) { |
| 587 |
return __( 'ERROR: No access [missing role]', 'wp-data-access' ); |
| 588 |
} |
| 589 |
// Determine plugin classes to be used. |
| 590 |
if ( 'static' === $project_page[0]['page_type'] ) { |
| 591 |
return ''; |
| 592 |
} elseif ( 'table' === $project_page[0]['page_type'] ) { |
| 593 |
$list_view_class = 'WPDataProjects\\List_Table\\WPDP_List_View'; |
| 594 |
$list_table_class = 'WPDataProjects\\List_Table\\WPDP_List_Table'; |
| 595 |
$edit_form_class = 'WPDataProjects\\Simple_Form\\WPDP_Simple_Form'; |
| 596 |
} else { |
| 597 |
$list_view_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_View'; |
| 598 |
$list_table_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_List_Table'; |
| 599 |
$edit_form_class = 'WPDataProjects\\Parent_Child\\WPDP_Parent_Form'; |
| 600 |
} |
| 601 |
if ( null !== $project_page[0]['page_where'] && '' !== $project_page[0]['page_where'] ) { |
| 602 |
if ( 'where' === substr( str_replace( ' ', '', $project_page[0]['page_where'] ), 0, 5 ) ) { |
| 603 |
$where_clause = " {$project_page[0]['page_where']}"; |
| 604 |
} else { |
| 605 |
$where_clause = " where {$project_page[0]['page_where']} "; |
| 606 |
} |
| 607 |
$where_clause = WPDA::substitute_environment_vars( $where_clause ); |
| 608 |
} else { |
| 609 |
$where_clause = ''; |
| 610 |
} |
| 611 |
if ( '' === $default_where ) { |
| 612 |
$default_where = $where_clause; |
| 613 |
} else { |
| 614 |
if ( '' === $where_clause ) { |
| 615 |
$default_where = " where {$default_where} "; |
| 616 |
} else { |
| 617 |
$default_where = " {$where_clause} and {$default_where} "; |
| 618 |
} |
| 619 |
} |
| 620 |
$default_orderby = $project_page[0]['page_orderby']; |
| 621 |
// Prepare arguments. |
| 622 |
$args = array( |
| 623 |
'page_hook_suffix' => 'WPDA_WPDP', |
| 624 |
'wpdaschema_name' => $project_page[0]['page_schema_name'], |
| 625 |
'table_name' => $project_page[0]['page_table_name'], |
| 626 |
'list_table_class' => $list_table_class, |
| 627 |
'edit_form_class' => $edit_form_class, |
| 628 |
'project_id' => $wp_atts['project_id'], |
| 629 |
'page_id' => $wp_atts['page_id'], |
| 630 |
'default_where' => $default_where, |
| 631 |
'where_clause' => $default_where, |
| 632 |
'orderby_clause' => $default_orderby, |
| 633 |
); |
| 634 |
if ( 'view' === $project_page[0]['page_mode'] ) { |
| 635 |
$args['allow_update'] = 'off'; |
| 636 |
$args['allow_import'] = 'off'; |
| 637 |
} |
| 638 |
if ( 'no' === $project_page[0]['page_allow_insert'] ) { |
| 639 |
$args['allow_insert'] = 'off'; |
| 640 |
$args['allow_import'] = 'off'; |
| 641 |
} |
| 642 |
if ( 'no' === $project_page[0]['page_allow_delete'] ) { |
| 643 |
$args['allow_delete'] = 'off'; |
| 644 |
} |
| 645 |
if ( 'only' === $project_page[0]['page_allow_insert'] ) { |
| 646 |
$args['action'] = 'new'; |
| 647 |
$args['allow_insert'] = 'only'; |
| 648 |
$args['allow_update'] = 'off'; |
| 649 |
$args['allow_import'] = 'off'; |
| 650 |
$args['allow_delete'] = 'off'; |
| 651 |
} |
| 652 |
if ( 'no' === $project_page[0]['page_allow_import'] ) { |
| 653 |
$args['allow_import'] = 'off'; |
| 654 |
} |
| 655 |
if ( 'no' === $project_page[0]['page_allow_bulk'] ) { |
| 656 |
$args['bulk_actions_enabled'] = false; |
| 657 |
} |
| 658 |
// Show page. |
| 659 |
$project_page_view = new $list_view_class($args); |
| 660 |
$project_page_view->show(); |
| 661 |
?> |
| 662 |
<script type='text/javascript'> |
| 663 |
// JS variable commonL10n is used in loaded scripts, copied from wp_default_scripts for responsive support |
| 664 |
/* <![CDATA[ */ |
| 665 |
var commonL10n = { |
| 666 |
"warnDelete": "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete.", |
| 667 |
"dismiss": "Dismiss this notice.", |
| 668 |
"collapseMenu": "Collapse Main menu", |
| 669 |
"expandMenu": "Expand Main menu" |
| 670 |
}; |
| 671 |
// Select all rows if checkbox cb-select-all-1 or cb-select-all-2 is clicked |
| 672 |
jQuery(function () { |
| 673 |
jQuery('#cb-select-all-1').on('click', function (event) { |
| 674 |
if (jQuery('#cb-select-all-1').is(':checked')) { |
| 675 |
jQuery('[name="bulk-selected[]"]').prop('checked', true); |
| 676 |
jQuery('#cb-select-all-2').prop('checked', true); |
| 677 |
} else { |
| 678 |
jQuery('[name="bulk-selected[]"]').prop('checked', false); |
| 679 |
jQuery('#cb-select-all-2').prop('checked', false); |
| 680 |
} |
| 681 |
}); |
| 682 |
jQuery('#cb-select-all-2').on('click', function (event) { |
| 683 |
if (jQuery('#cb-select-all-2').is(':checked')) { |
| 684 |
jQuery('[name="bulk-selected[]"]').prop('checked', true); |
| 685 |
jQuery('#cb-select-all-1').prop('checked', true); |
| 686 |
} else { |
| 687 |
jQuery('[name="bulk-selected[]"]').prop('checked', false); |
| 688 |
jQuery('#cb-select-all-1').prop('checked', false); |
| 689 |
} |
| 690 |
}); |
| 691 |
}); |
| 692 |
</script> |
| 693 |
<style type="text/css"> |
| 694 |
/*@media screen and (max-width: 782px) { .row-actions { position: initial !important; } }*/ |
| 695 |
@media (hover:none) { .row-actions { position: initial !important; } } |
| 696 |
</style> |
| 697 |
<?php |
| 698 |
return ob_get_clean(); |
| 699 |
} |
| 700 |
|
| 701 |
} |
| 702 |
|
| 703 |
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |