| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Suppress "error - 0 - No summary was found for this file" on phpdoc generation |
| 5 |
* |
| 6 |
* @package plugin\admin |
| 7 |
*/ |
| 8 |
use WPDataAccess\API\WPDA_API; |
| 9 |
use WPDataAccess\Backup\WPDA_Data_Export; |
| 10 |
use WPDataAccess\CSV_Files\WPDA_CSV_Import; |
| 11 |
use WPDataAccess\Dashboard\WPDA_Dashboard; |
| 12 |
use WPDataAccess\Data_Apps\WPDA_App_Builder; |
| 13 |
use WPDataAccess\Data_Apps\WPDA_Data_Explorer; |
| 14 |
use WPDataAccess\Global_Search\WPDA_Global_Search; |
| 15 |
use WPDataAccess\List_Table\WPDA_List_View; |
| 16 |
use WPDataAccess\Plugin_Table_Models\WPDA_App_Model; |
| 17 |
use WPDataAccess\Plugin_Table_Models\WPDA_Design_Table_Model; |
| 18 |
use WPDataAccess\Plugin_Table_Models\WPDA_Publisher_Model; |
| 19 |
use WPDataAccess\Plugin_Table_Models\WPDA_User_Menus_Model; |
| 20 |
use WPDataAccess\Premium\WPDAPRO_Data_Publisher\WPDAPRO_Data_Publisher_Manage_Styles; |
| 21 |
use WPDataAccess\Settings\WPDA_Settings; |
| 22 |
use WPDataAccess\Utilities\WPDA_Add_App_To_Menu; |
| 23 |
use WPDataAccess\Utilities\WPDA_Repository; |
| 24 |
use WPDataAccess\WPDA; |
| 25 |
use WPDataAccess\WPDA_Navi\WPDA_Navi; |
| 26 |
use WPDataProjects\WPDP; |
| 27 |
/** |
| 28 |
* Class WP_Data_Access_Admin |
| 29 |
* |
| 30 |
* Defines admin specific functionality for plugin WP Data Access. |
| 31 |
* |
| 32 |
* @author Peter Schulz |
| 33 |
* @since 1.0.0 |
| 34 |
*/ |
| 35 |
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- verified on page |
| 36 |
class WP_Data_Access_Admin { |
| 37 |
/** |
| 38 |
* Menu slug for main page |
| 39 |
*/ |
| 40 |
const PAGE_MAIN = 'wpda'; |
| 41 |
|
| 42 |
/** |
| 43 |
* Menu slug for navigator page |
| 44 |
*/ |
| 45 |
const PAGE_NAVI = 'wpda_navi'; |
| 46 |
|
| 47 |
/** |
| 48 |
* Menu slug for apps page |
| 49 |
*/ |
| 50 |
const PAGE_APPS = 'wpda_apps'; |
| 51 |
|
| 52 |
/** |
| 53 |
* Menu slug for dashboard page |
| 54 |
*/ |
| 55 |
const PAGE_DASHBOARD = 'wpda_dashboard'; |
| 56 |
|
| 57 |
/** |
| 58 |
* Menu slug for setting page |
| 59 |
*/ |
| 60 |
const PAGE_SETTINGS = 'wpdataaccess'; |
| 61 |
|
| 62 |
/** |
| 63 |
* Menu slug for explorer page |
| 64 |
*/ |
| 65 |
const PAGE_EXPLORER = 'wpda_explorer'; |
| 66 |
|
| 67 |
/** |
| 68 |
* Menu slug for query builder page |
| 69 |
*/ |
| 70 |
const PAGE_QUERY_BUILDER = 'wpda_query_builder'; |
| 71 |
|
| 72 |
/** |
| 73 |
* Menu slug for Data Tables page |
| 74 |
*/ |
| 75 |
const PAGE_PUBLISHER = 'wpda_publisher'; |
| 76 |
|
| 77 |
/** |
| 78 |
* Menu slug for charts page |
| 79 |
*/ |
| 80 |
const PAGE_CHARTS = 'wpda_charts'; |
| 81 |
|
| 82 |
/** |
| 83 |
* Menu slug for designer page |
| 84 |
*/ |
| 85 |
const PAGE_DESIGNER = 'wpda_designer'; |
| 86 |
|
| 87 |
/** |
| 88 |
* Plugin main page slug |
| 89 |
*/ |
| 90 |
const MAIN_PAGE_SLUG = self::PAGE_NAVI; |
| 91 |
|
| 92 |
/** |
| 93 |
* Menu slug for my tables page |
| 94 |
*/ |
| 95 |
const PAGE_MY_TABLES = 'wpda_my_tables'; |
| 96 |
|
| 97 |
/** |
| 98 |
* Page hook suffix to Data Explorer page or false |
| 99 |
* |
| 100 |
* @var string|false |
| 101 |
*/ |
| 102 |
protected $wpda_data_explorer_menu; |
| 103 |
|
| 104 |
/** |
| 105 |
* Page hook suffix to Data Designer page or false |
| 106 |
* |
| 107 |
* @var string|false |
| 108 |
*/ |
| 109 |
protected $wpda_data_designer_menu; |
| 110 |
|
| 111 |
/** |
| 112 |
* Page hook suffix to Data Tables page or false |
| 113 |
* |
| 114 |
* @var string|false |
| 115 |
*/ |
| 116 |
protected $wpda_data_publisher_menu; |
| 117 |
|
| 118 |
/** |
| 119 |
* Page hook suffix to Charts page or false |
| 120 |
* |
| 121 |
* @var string|false |
| 122 |
*/ |
| 123 |
protected $wpda_charts_menu; |
| 124 |
|
| 125 |
/** |
| 126 |
* Reference to list view for Data Explorer page |
| 127 |
* |
| 128 |
* @var WPDA_List_View |
| 129 |
*/ |
| 130 |
protected $wpda_data_explorer_view; |
| 131 |
|
| 132 |
/** |
| 133 |
* Reference to list view for Data Designer page |
| 134 |
* |
| 135 |
* @var WPDA_List_View |
| 136 |
*/ |
| 137 |
protected $wpda_data_designer_view; |
| 138 |
|
| 139 |
/** |
| 140 |
* Reference to list view for Data Tables page |
| 141 |
* |
| 142 |
* @var WPDA_List_View |
| 143 |
*/ |
| 144 |
protected $wpda_data_publisher_view; |
| 145 |
|
| 146 |
/** |
| 147 |
* Reference to list view for Charts page |
| 148 |
* |
| 149 |
* @var WPDA_List_View |
| 150 |
*/ |
| 151 |
protected $wpda_charts_view; |
| 152 |
|
| 153 |
/** |
| 154 |
* Array of page hook suffixes to user defined sub menus |
| 155 |
* |
| 156 |
* @var array |
| 157 |
*/ |
| 158 |
protected $wpda_my_table_list_menu = array(); |
| 159 |
|
| 160 |
/** |
| 161 |
* Array of list view for user defined sub menus |
| 162 |
* |
| 163 |
* @var array |
| 164 |
*/ |
| 165 |
protected $wpda_my_table_list_view = array(); |
| 166 |
|
| 167 |
/** |
| 168 |
* Page hook suffix help page or false |
| 169 |
* |
| 170 |
* @var string|false |
| 171 |
*/ |
| 172 |
protected $wpda_help; |
| 173 |
|
| 174 |
/** |
| 175 |
* Menu slug or null |
| 176 |
* |
| 177 |
* @var null |
| 178 |
*/ |
| 179 |
protected $page = null; |
| 180 |
|
| 181 |
/** |
| 182 |
* Status loading indicator |
| 183 |
* |
| 184 |
* @var bool |
| 185 |
*/ |
| 186 |
protected $loaded_user_main_menu = false; |
| 187 |
|
| 188 |
/** |
| 189 |
* Main menu page |
| 190 |
* |
| 191 |
* @var null |
| 192 |
*/ |
| 193 |
protected $first_page = null; |
| 194 |
|
| 195 |
/** |
| 196 |
* WP_Data_Access_Admin constructor |
| 197 |
* |
| 198 |
* @since 1.0.0 |
| 199 |
*/ |
| 200 |
public function __construct() { |
| 201 |
if ( isset( $_REQUEST['page'] ) ) { |
| 202 |
$this->page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
private function load_app_css() { |
| 207 |
// WPDataAccess apps CSS. |
| 208 |
wp_register_style( |
| 209 |
'wpda_apps', |
| 210 |
plugins_url( '../assets/css/wpda_apps.css', __FILE__ ), |
| 211 |
array(), |
| 212 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 213 |
); |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* Add stylesheets to back-end |
| 218 |
* |
| 219 |
* The following stylesheets are added: |
| 220 |
* + Plugin stylesheet |
| 221 |
* + Visual editor stylesheet |
| 222 |
* |
| 223 |
* The plugin stylesheet is used to style the setting forms {@see WPDA_Settings}, simple forms |
| 224 |
* {@see \WPDataAccess\Simple_Form\WPDA_Simple_Form}. |
| 225 |
* |
| 226 |
* @since 1.0.0 |
| 227 |
* |
| 228 |
* @see WPDA_Settings |
| 229 |
* @see \WPDataAccess\Simple_Form\WPDA_Simple_Form |
| 230 |
* @see WP_Data_Access_Public |
| 231 |
*/ |
| 232 |
public function enqueue_styles() { |
| 233 |
if ( !WPDA::is_plugin_page( $this->page ) ) { |
| 234 |
// Admin styles are only added to plugin admin pages. |
| 235 |
// App pages still require the apps.css file. |
| 236 |
$apps = WPDA_App_Model::add_to_dashboard_menu(); |
| 237 |
$css_added = false; |
| 238 |
for ($i = 0; $i < count( $apps ) && !$css_added; $i++) { |
| 239 |
$settings = json_decode( $apps[$i]['app_settings'], true ); |
| 240 |
if ( isset( $settings['settings']['app_menu_title'] ) && $this->page === $settings['settings']['app_menu_title'] ) { |
| 241 |
$this->load_app_css(); |
| 242 |
$css_added = true; |
| 243 |
} |
| 244 |
} |
| 245 |
return; |
| 246 |
} |
| 247 |
if ( self::PAGE_NAVI === $this->page ) { |
| 248 |
// WPDataAccess CSS. |
| 249 |
wp_enqueue_style( |
| 250 |
'wpdanavi', |
| 251 |
plugins_url( '../assets/css/wpda_navi.css', __FILE__ ), |
| 252 |
array(), |
| 253 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 254 |
); |
| 255 |
} |
| 256 |
wp_enqueue_style( 'wp-jquery-ui-core' ); |
| 257 |
wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
| 258 |
wp_enqueue_style( 'wp-jquery-ui-sortable' ); |
| 259 |
wp_enqueue_style( 'wp-jquery-ui-tabs' ); |
| 260 |
$this->load_app_css(); |
| 261 |
// WPDataAccess CSS. |
| 262 |
wp_enqueue_style( |
| 263 |
'wpdataaccess', |
| 264 |
plugins_url( '../assets/css/wpda_style.css', __FILE__ ), |
| 265 |
array(), |
| 266 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 267 |
); |
| 268 |
// WPDataAccess dashboard. |
| 269 |
wp_register_style( |
| 270 |
'wpdataaccess_dashboard', |
| 271 |
plugins_url( '../assets/css/wpda_dashboard.css', __FILE__ ), |
| 272 |
array(), |
| 273 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 274 |
); |
| 275 |
// Add WP Data Projects stylesheet. |
| 276 |
wp_enqueue_style( |
| 277 |
'wpdataprojects', |
| 278 |
plugins_url( '../WPDataProjects/assets/css/wpdp_style.css', __FILE__ ), |
| 279 |
array(), |
| 280 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 281 |
); |
| 282 |
// Register datetimepicker external library. |
| 283 |
wp_register_style( |
| 284 |
'datetimepicker', |
| 285 |
plugins_url( '../assets/css/jquery.datetimepicker.min.css', __FILE__ ), |
| 286 |
array(), |
| 287 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 288 |
); |
| 289 |
// Register JQuery DataTables to use data tables in the dashboard. |
| 290 |
wp_register_style( |
| 291 |
'jquery_datatables', |
| 292 |
plugins_url( '../assets/css/jquery.dataTables.min.css', __FILE__ ), |
| 293 |
array(), |
| 294 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 295 |
); |
| 296 |
// Register JQuery DataTables Responsive to use data tables in the dashboard. |
| 297 |
wp_register_style( |
| 298 |
'jquery_datatables_responsive', |
| 299 |
plugins_url( '../assets/css/responsive.dataTables.min.css', __FILE__ ), |
| 300 |
array(), |
| 301 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 302 |
); |
| 303 |
if ( self::PAGE_MAIN === $this->page || self::PAGE_APPS === $this->page || self::PAGE_DASHBOARD === $this->page || self::PAGE_QUERY_BUILDER === $this->page || self::PAGE_PUBLISHER === $this->page || self::PAGE_CHARTS === $this->page ) { |
| 304 |
// Load UI smoothness theme. |
| 305 |
wp_enqueue_style( |
| 306 |
'wpda_ui_smoothness', |
| 307 |
plugins_url( '../assets/css/jquery-ui.smoothness.min.css', __FILE__ ), |
| 308 |
array(), |
| 309 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 310 |
); |
| 311 |
} else { |
| 312 |
// Load UI darkness theme. |
| 313 |
wp_enqueue_style( |
| 314 |
'wpda_ui_darkness', |
| 315 |
plugins_url( '../assets/css/jquery-ui.min.css', __FILE__ ), |
| 316 |
array(), |
| 317 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 318 |
); |
| 319 |
} |
| 320 |
$hide_button_icons = WPDA::get_option( WPDA::OPTION_BE_HIDE_BUTTON_ICONS ); |
| 321 |
if ( false !== $hide_button_icons && 'on' !== $hide_button_icons ) { |
| 322 |
// SAVING SPACE - According to the plugin guidelines it is allowed to include external fonts: |
| 323 |
// https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#8-plugins-may-not-send-executable-code-via-third-party-systems . |
| 324 |
// Load fontawesome icons. |
| 325 |
// phpcs:disable WordPress.WP.EnqueuedResourceParameters.MissingVersion |
| 326 |
wp_enqueue_style( |
| 327 |
'wpda_fontawesome_icons', |
| 328 |
WPDA::CDN_FONTAWESOME . 'all.min.css', |
| 329 |
array(), |
| 330 |
null, |
| 331 |
false |
| 332 |
); |
| 333 |
// phpcs:enable WordPress.WP.EnqueuedResourceParameters.MissingVersion |
| 334 |
} |
| 335 |
if ( self::PAGE_PUBLISHER === $this->page ) { |
| 336 |
wp_register_style( |
| 337 |
'wpda_datatables_default', |
| 338 |
plugins_url( '../assets/css/wpda_datatables_default.css', __FILE__ ), |
| 339 |
array(), |
| 340 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 341 |
); |
| 342 |
// Add jQuery multiselect resources. |
| 343 |
wp_enqueue_style( |
| 344 |
'wpda_jquery_multiselect', |
| 345 |
plugins_url( '../assets/css/jquery.multiselect.sortable.js.css', __FILE__ ), |
| 346 |
array(), |
| 347 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 348 |
false |
| 349 |
); |
| 350 |
} |
| 351 |
if ( self::PAGE_QUERY_BUILDER === $this->page ) { |
| 352 |
// Add Query Builder resources. |
| 353 |
wp_enqueue_style( |
| 354 |
'wpda_query_builder', |
| 355 |
plugins_url( '../assets/css/wpda_query_builder.css', __FILE__ ), |
| 356 |
array(), |
| 357 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 358 |
); |
| 359 |
wp_enqueue_style( |
| 360 |
'wpda_jquery_json_viewer', |
| 361 |
plugins_url( '../assets/css/jquery.json-viewer.css', __FILE__ ), |
| 362 |
array(), |
| 363 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 364 |
); |
| 365 |
} |
| 366 |
if ( !WPDA::current_user_is_admin() ) { |
| 367 |
wp_enqueue_style( |
| 368 |
'wpda_non_admin', |
| 369 |
plugins_url( '../assets/css/wpda_non_admin.css', __FILE__ ), |
| 370 |
array(), |
| 371 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ) |
| 372 |
); |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
/** |
| 377 |
* Remove icons from buttons (if configured) |
| 378 |
* |
| 379 |
* @return void |
| 380 |
*/ |
| 381 |
public function remove_icons() { |
| 382 |
if ( !WPDA::is_plugin_page( $this->page ) ) { |
| 383 |
// Only executed on plugin pages. |
| 384 |
return; |
| 385 |
} |
| 386 |
if ( 'on' === WPDA::get_option( WPDA::OPTION_BE_HIDE_BUTTON_ICONS ) ) { |
| 387 |
echo ' |
| 388 |
<style> |
| 389 |
i.fas.wpda_icon_on_button { |
| 390 |
display: none; |
| 391 |
} |
| 392 |
</style> |
| 393 |
'; |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
/** |
| 398 |
* Add scripts to back-end |
| 399 |
* |
| 400 |
* @since 1.0.0 |
| 401 |
* |
| 402 |
* @see WP_Data_Access_Public |
| 403 |
*/ |
| 404 |
public function enqueue_scripts() { |
| 405 |
if ( !WPDA::is_plugin_page( $this->page ) ) { |
| 406 |
// Admin styles are only added to plugin admin pages. |
| 407 |
return; |
| 408 |
} |
| 409 |
wp_enqueue_script( 'jquery-ui-core' ); |
| 410 |
wp_enqueue_script( 'jquery-ui-dialog' ); |
| 411 |
wp_enqueue_script( 'jquery-ui-tabs' ); |
| 412 |
wp_enqueue_script( 'jquery-ui-sortable' ); |
| 413 |
wp_enqueue_script( 'jquery-ui-tooltip' ); |
| 414 |
wp_enqueue_script( 'jquery-ui-autocomplete' ); |
| 415 |
// Register wpda rest api. |
| 416 |
wp_enqueue_script( |
| 417 |
'wpda_rest_api', |
| 418 |
plugins_url( '../assets/js/wpda_rest_api.js', __FILE__ ), |
| 419 |
array('wp-api'), |
| 420 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 421 |
false |
| 422 |
); |
| 423 |
wp_localize_script( 'wpda_rest_api', 'wpdaApiSettings', array( |
| 424 |
'path' => WPDA_API::WPDA_NAMESPACE, |
| 425 |
) ); |
| 426 |
// Register wpda admin functions. |
| 427 |
wp_enqueue_script( |
| 428 |
'wpda_admin_scripts', |
| 429 |
plugins_url( '../assets/js/wpda_admin.js', __FILE__ ), |
| 430 |
array(), |
| 431 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 432 |
false |
| 433 |
); |
| 434 |
wp_localize_script( 'wpda_admin_scripts', 'wpda_admin_vars', array( |
| 435 |
'wpda_ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 436 |
) ); |
| 437 |
// Register dashboard. |
| 438 |
wp_register_script( |
| 439 |
'wpdataaccess_dashboard', |
| 440 |
plugins_url( '../assets/js/wpda_dashboard.js', __FILE__ ), |
| 441 |
array(), |
| 442 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 443 |
false |
| 444 |
); |
| 445 |
wp_localize_script( 'wpdataaccess_dashboard', 'wpda_dashboard_vars', array( |
| 446 |
'wpda_ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 447 |
) ); |
| 448 |
// Add WP Data Projects JS functions.RESEARCH. |
| 449 |
wp_enqueue_script( |
| 450 |
'wpdataprojects', |
| 451 |
plugins_url( '../WPDataProjects/assets/js/wpdp_admin.js', __FILE__ ), |
| 452 |
array(), |
| 453 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 454 |
false |
| 455 |
); |
| 456 |
// Register jQuery DataTables to use data tables in the dashboard. |
| 457 |
wp_register_script( |
| 458 |
'jquery_datatables', |
| 459 |
plugins_url( '../assets/js/jquery.dataTables.min.js', __FILE__ ), |
| 460 |
array(), |
| 461 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 462 |
false |
| 463 |
); |
| 464 |
// Register jQuery DataTables Responsive to use data tables in the dashboard. |
| 465 |
wp_register_script( |
| 466 |
'jquery_datatables_responsive', |
| 467 |
plugins_url( '../assets/js/dataTables.responsive.min.js', __FILE__ ), |
| 468 |
array(), |
| 469 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 470 |
false |
| 471 |
); |
| 472 |
// Ajax call to WPDA datatables implementation to use data tables in the dashboard. |
| 473 |
wp_register_script( |
| 474 |
'wpda_datatables', |
| 475 |
plugins_url( '../assets/js/wpda_datatables.js', __FILE__ ), |
| 476 |
array(), |
| 477 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 478 |
false |
| 479 |
); |
| 480 |
wp_localize_script( 'wpda_datatables', 'wpda_publication_vars', array( |
| 481 |
'wpda_ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 482 |
) ); |
| 483 |
// Register notify external library. |
| 484 |
wp_enqueue_script( |
| 485 |
'wpda_notify', |
| 486 |
plugins_url( '../assets/js/notify.min.js', __FILE__ ), |
| 487 |
array(), |
| 488 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 489 |
false |
| 490 |
); |
| 491 |
// Register datetimepicker external library. |
| 492 |
wp_register_script( |
| 493 |
'datetimepicker', |
| 494 |
plugins_url( '../assets/js/jquery.datetimepicker.full.min.js', __FILE__ ), |
| 495 |
array(), |
| 496 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 497 |
false |
| 498 |
); |
| 499 |
// Register clipboard.js. |
| 500 |
wp_enqueue_script( 'clipboard' ); |
| 501 |
if ( self::PAGE_PUBLISHER === $this->page ) { |
| 502 |
if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], array('view', 'new', 'edit'), true ) ) { |
| 503 |
$json_editing = WPDA::get_option( WPDA::OPTION_DP_JSON_EDITING ); |
| 504 |
if ( WPDA::OPTION_DP_JSON_EDITING[1] === $json_editing ) { |
| 505 |
// Register codeEditor to support JSON editing in Data Tables (table options advanced). |
| 506 |
$cm_settings['codeEditor'] = wp_enqueue_code_editor( array( |
| 507 |
'type' => 'application/json', |
| 508 |
'codemirror' => array( |
| 509 |
'autoRefresh' => true, |
| 510 |
), |
| 511 |
) ); |
| 512 |
wp_localize_script( 'wp-theme-plugin-editor', 'cm_settings', $cm_settings ); |
| 513 |
wp_enqueue_script( 'wp-theme-plugin-editor' ); |
| 514 |
} |
| 515 |
// Add jQuery multiselect resources. |
| 516 |
wp_enqueue_script( |
| 517 |
'wpda_jquery_multiselect', |
| 518 |
plugins_url( '../assets/js/jquery.multiselect.sortable.js', __FILE__ ), |
| 519 |
array(), |
| 520 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 521 |
false |
| 522 |
); |
| 523 |
} |
| 524 |
} |
| 525 |
if ( self::PAGE_CHARTS === $this->page ) { |
| 526 |
$this->load_google_charts(); |
| 527 |
} |
| 528 |
if ( self::PAGE_QUERY_BUILDER === $this->page ) { |
| 529 |
// Add Query Builder resources. |
| 530 |
wp_enqueue_script( |
| 531 |
'wpda_query_builder', |
| 532 |
plugins_url( '../assets/js/wpda_query_builder.js', __FILE__ ), |
| 533 |
array(), |
| 534 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 535 |
false |
| 536 |
); |
| 537 |
wp_enqueue_script( |
| 538 |
'wpda_jquery_xml2json', |
| 539 |
plugins_url( '../assets/js/jquery.xml2json.js', __FILE__ ), |
| 540 |
array(), |
| 541 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 542 |
false |
| 543 |
); |
| 544 |
wp_enqueue_script( |
| 545 |
'wpda_jquery_json_viewer', |
| 546 |
plugins_url( '../assets/js/jquery.json-viewer.js', __FILE__ ), |
| 547 |
array(), |
| 548 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 549 |
false |
| 550 |
); |
| 551 |
// Add codeEditor to query builder. |
| 552 |
$cm_settings['codeEditor'] = wp_enqueue_code_editor( array( |
| 553 |
'type' => 'text/x-sql', |
| 554 |
'codemirror' => array( |
| 555 |
'mode' => 'sql', |
| 556 |
'lineNumbers' => true, |
| 557 |
'autoRefresh' => true, |
| 558 |
'lineWrapping' => true, |
| 559 |
'styleActiveLine' => true, |
| 560 |
), |
| 561 |
) ); |
| 562 |
wp_enqueue_script( 'wp-theme-plugin-editor' ); |
| 563 |
wp_localize_script( 'wp-theme-plugin-editor', 'cm_settings', $cm_settings ); |
| 564 |
wp_enqueue_style( 'wp-codemirror' ); |
| 565 |
} |
| 566 |
if ( self::PAGE_DASHBOARD === $this->page ) { |
| 567 |
$this->load_google_charts(); |
| 568 |
// Load DBMS panels. |
| 569 |
wp_enqueue_script( |
| 570 |
'wpda_dbms', |
| 571 |
plugins_url( '../assets/js/wpda_dbms.js', __FILE__ ), |
| 572 |
array(), |
| 573 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 574 |
false |
| 575 |
); |
| 576 |
wp_localize_script( 'wpda_dbms', 'wpda_dbms_vars', array( |
| 577 |
'wpda_ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 578 |
) ); |
| 579 |
} |
| 580 |
wp_enqueue_media(); |
| 581 |
} |
| 582 |
|
| 583 |
/** |
| 584 |
* Load Google Charts resources |
| 585 |
* |
| 586 |
* @return void |
| 587 |
*/ |
| 588 |
private function load_google_charts() { |
| 589 |
// Load Google Charts. |
| 590 |
// phpcs:disable WordPress.WP.EnqueuedResourceParameters |
| 591 |
wp_enqueue_script( |
| 592 |
'wpda_google_charts', |
| 593 |
WPDA::GOOGLE_CHARTS, |
| 594 |
array(), |
| 595 |
null, |
| 596 |
false |
| 597 |
); |
| 598 |
// phpcs:enable WordPress.WP.EnqueuedResourceParameters |
| 599 |
wp_enqueue_script( |
| 600 |
'wpda_google_charts_fnc', |
| 601 |
plugins_url( '../assets/js/wpda_google_charts.js', __FILE__ ), |
| 602 |
array(), |
| 603 |
WPDA::get_option( WPDA::OPTION_WPDA_VERSION ), |
| 604 |
false |
| 605 |
); |
| 606 |
wp_localize_script( 'wpda_google_charts_fnc', 'wpda_chart_vars', array( |
| 607 |
'wpda_ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 608 |
'wpda_chartdir' => plugin_dir_url( __FILE__ ) . '../assets/images/google_chart_types/', |
| 609 |
'wpda_premium' => ( wpda_freemius()->can_use_premium_code__premium_only() ? 'true' : 'false' ), |
| 610 |
) ); |
| 611 |
} |
| 612 |
|
| 613 |
/** |
| 614 |
* Hide admin notices |
| 615 |
* |
| 616 |
* @return void |
| 617 |
*/ |
| 618 |
public function user_admin_notices() { |
| 619 |
if ( WPDA::is_plugin_page( $this->page ) && 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_HIDE_NOTICES ) ) { |
| 620 |
remove_all_actions( 'admin_notices' ); |
| 621 |
remove_all_actions( 'all_admin_notices' ); |
| 622 |
} |
| 623 |
} |
| 624 |
|
| 625 |
/** |
| 626 |
* Add plugin menu and sub menus |
| 627 |
* |
| 628 |
* Adds the following menu and sub menus to the back-end menu: |
| 629 |
* + WP Data Access |
| 630 |
* + Data Explorer |
| 631 |
* + Data Designer |
| 632 |
* + Data Projects |
| 633 |
* + Manage Plugin |
| 634 |
* |
| 635 |
* @since 1.0.0 |
| 636 |
*/ |
| 637 |
public function add_menu_items() { |
| 638 |
if ( WPDA::current_user_is_admin() ) { |
| 639 |
if ( 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_HIDE_ADMIN_MENU ) ) { |
| 640 |
// Show Data Projects. |
| 641 |
$this->add_data_projects(); |
| 642 |
// Hide admin menu. |
| 643 |
return; |
| 644 |
} |
| 645 |
if ( self::PAGE_MAIN === $this->page && isset( $_REQUEST['de'] ) ) { |
| 646 |
if ( 'new' === $_REQUEST['de'] ) { |
| 647 |
update_user_meta( WPDA::get_current_user_id(), 'wpda_data_explorer', 'new' ); |
| 648 |
} elseif ( 'old' === $_REQUEST['de'] ) { |
| 649 |
update_user_meta( WPDA::get_current_user_id(), 'wpda_data_explorer', 'old' ); |
| 650 |
} |
| 651 |
} |
| 652 |
if ( self::PAGE_QUERY_BUILDER === $this->page && isset( $_REQUEST['qb'] ) ) { |
| 653 |
if ( 'new' === $_REQUEST['qb'] ) { |
| 654 |
update_user_meta( WPDA::get_current_user_id(), 'wpda_query_builder_version', 'new' ); |
| 655 |
} elseif ( 'old' === $_REQUEST['qb'] ) { |
| 656 |
update_user_meta( WPDA::get_current_user_id(), 'wpda_query_builder_version', 'old' ); |
| 657 |
} |
| 658 |
} |
| 659 |
// Specific list tables (and forms) can be made available for specific capabilities: |
| 660 |
// managed in method add_menu_my_tables. |
| 661 |
// Main menu and items are only available to admin users (set capability to 'manage_options'). |
| 662 |
add_menu_page( |
| 663 |
'WP Data Access', |
| 664 |
'WP Data Access', |
| 665 |
'manage_options', |
| 666 |
self::MAIN_PAGE_SLUG, |
| 667 |
null, |
| 668 |
'dashicons-database', |
| 669 |
999999999 |
| 670 |
); |
| 671 |
// Add navigator page to WPDA menu. |
| 672 |
add_submenu_page( |
| 673 |
self::MAIN_PAGE_SLUG, |
| 674 |
'WP Data Access', |
| 675 |
'Tool Guide', |
| 676 |
'manage_options', |
| 677 |
self::PAGE_NAVI, |
| 678 |
array($this, 'data_navi') |
| 679 |
); |
| 680 |
// Add apps to menu. |
| 681 |
add_submenu_page( |
| 682 |
self::MAIN_PAGE_SLUG, |
| 683 |
'WP Data Access', |
| 684 |
'App Builder', |
| 685 |
'manage_options', |
| 686 |
self::PAGE_APPS, |
| 687 |
array($this, 'data_apps') |
| 688 |
); |
| 689 |
// Add data explorer to WPDA menu. |
| 690 |
$current_data_explorer_version = get_user_meta( WPDA::get_current_user_id(), 'wpda_data_explorer', true ); |
| 691 |
if ( isset( $_POST['explorer'] ) && 'OLD' === $_POST['explorer'] ) { |
| 692 |
$current_data_explorer_version = true; |
| 693 |
} |
| 694 |
$this->wpda_data_explorer_menu = add_submenu_page( |
| 695 |
self::MAIN_PAGE_SLUG, |
| 696 |
'WP Data Access', |
| 697 |
'Data Explorer', |
| 698 |
'manage_options', |
| 699 |
self::PAGE_MAIN, |
| 700 |
array($this, ( 'new' !== $current_data_explorer_version && '' !== $current_data_explorer_version ? 'data_explorer_page' : 'data_explorer_page_new' )) |
| 701 |
); |
| 702 |
if ( self::PAGE_MAIN === $this->page ) { |
| 703 |
if ( 'new' !== $current_data_explorer_version && '' !== $current_data_explorer_version ) { |
| 704 |
$args = array( |
| 705 |
'page_hook_suffix' => $this->wpda_data_explorer_menu, |
| 706 |
); |
| 707 |
$this->wpda_data_explorer_view = new WPDA_List_View($args); |
| 708 |
} |
| 709 |
} |
| 710 |
// Add submenu for Query Builder. |
| 711 |
$current_query_builder_version = get_user_meta( WPDA::get_current_user_id(), 'wpda_query_builder_version', true ); |
| 712 |
$this->wpda_data_publisher_menu = add_submenu_page( |
| 713 |
self::MAIN_PAGE_SLUG, |
| 714 |
'WP Data Access', |
| 715 |
'SQL Query Builder', |
| 716 |
'manage_options', |
| 717 |
self::PAGE_QUERY_BUILDER, |
| 718 |
array($this, ( $current_query_builder_version === 'old' ? 'query_builder_old' : 'query_builder' )) |
| 719 |
); |
| 720 |
// Add submenu for Data Tables. |
| 721 |
$this->wpda_data_publisher_menu = add_submenu_page( |
| 722 |
self::MAIN_PAGE_SLUG, |
| 723 |
'WP Data Access', |
| 724 |
'Table Builder', |
| 725 |
'manage_options', |
| 726 |
self::PAGE_PUBLISHER, |
| 727 |
array($this, 'data_publisher_page') |
| 728 |
); |
| 729 |
if ( self::PAGE_PUBLISHER === $this->page ) { |
| 730 |
$this->wpda_data_publisher_view = new WPDA_List_View(array( |
| 731 |
'page_hook_suffix' => $this->wpda_data_publisher_menu, |
| 732 |
'table_name' => WPDA_Publisher_Model::get_base_table_name(), |
| 733 |
'list_table_class' => 'WPDataAccess\\Data_Publisher\\WPDA_Publisher_List_Table', |
| 734 |
'edit_form_class' => 'WPDataAccess\\Data_Publisher\\WPDA_Publisher_Form', |
| 735 |
)); |
| 736 |
} |
| 737 |
// Add Data Projects menu. |
| 738 |
$wpdp = new WPDP(self::MAIN_PAGE_SLUG); |
| 739 |
$wpdp->add_menu_items(); |
| 740 |
// Add data designer to WPDA menu. |
| 741 |
$this->wpda_data_designer_menu = add_submenu_page( |
| 742 |
self::MAIN_PAGE_SLUG, |
| 743 |
'WP Data Access', |
| 744 |
'Data Designer', |
| 745 |
'manage_options', |
| 746 |
self::PAGE_DESIGNER, |
| 747 |
array($this, 'data_designer_page') |
| 748 |
); |
| 749 |
if ( self::PAGE_DESIGNER === $this->page ) { |
| 750 |
$this->wpda_data_designer_view = new WPDA_List_View(array( |
| 751 |
'page_hook_suffix' => $this->wpda_data_designer_menu, |
| 752 |
'table_name' => WPDA_Design_Table_Model::get_base_table_name(), |
| 753 |
'list_table_class' => 'WPDataAccess\\Design_Table\\WPDA_Design_Table_List_Table', |
| 754 |
'edit_form_class' => 'WPDataAccess\\Design_Table\\WPDA_Design_Table_Form', |
| 755 |
'subtitle' => '', |
| 756 |
)); |
| 757 |
} |
| 758 |
} else { |
| 759 |
$this->grant_access_to_dashboard(); |
| 760 |
$this->grant_access_to_data_publications(); |
| 761 |
} |
| 762 |
$this->add_data_projects(); |
| 763 |
$this->add_apps(); |
| 764 |
} |
| 765 |
|
| 766 |
/** |
| 767 |
* Remove plugin sub menu items (when in dashboard mode) |
| 768 |
* |
| 769 |
* @param mixed $submenu_file Dashboard menu items. |
| 770 |
* @return mixed |
| 771 |
*/ |
| 772 |
public function wpda_submenu_filter( $submenu_file ) { |
| 773 |
if ( WPDA::current_user_is_admin() ) { |
| 774 |
$hidden_submenus = array( |
| 775 |
self::PAGE_DASHBOARD, |
| 776 |
self::PAGE_CHARTS, |
| 777 |
self::PAGE_PUBLISHER, |
| 778 |
WPDP::PAGE_MAIN, |
| 779 |
self::PAGE_DESIGNER, |
| 780 |
WPDP::PAGE_TEMPLATES, |
| 781 |
self::MAIN_PAGE_SLUG . '-account', |
| 782 |
self::MAIN_PAGE_SLUG . '-wp-support-forum' |
| 783 |
); |
| 784 |
foreach ( $hidden_submenus as $submenu ) { |
| 785 |
remove_submenu_page( self::MAIN_PAGE_SLUG, $submenu ); |
| 786 |
} |
| 787 |
} else { |
| 788 |
global $submenu; |
| 789 |
$submenu[self::PAGE_MAIN][0][2] = self::PAGE_DASHBOARD; |
| 790 |
// phpcs:ignore WordPress.WP.GlobalVariablesOverride |
| 791 |
} |
| 792 |
return $submenu_file; |
| 793 |
} |
| 794 |
|
| 795 |
/** |
| 796 |
* Add apps to dashboard menu. |
| 797 |
* |
| 798 |
* @return void |
| 799 |
*/ |
| 800 |
protected function add_apps() { |
| 801 |
// Add apps to dashbaord menu |
| 802 |
$apps = new WPDA_Add_App_To_Menu(); |
| 803 |
$apps->add_apps_to_menu(); |
| 804 |
} |
| 805 |
|
| 806 |
/** |
| 807 |
* Add Data Projects and Project Templates to plugin navigation |
| 808 |
* |
| 809 |
* @return void |
| 810 |
*/ |
| 811 |
protected function add_data_projects() { |
| 812 |
// Add Data Projects. |
| 813 |
$wpdp = new WPDP(); |
| 814 |
$wpdp->add_projects(); |
| 815 |
} |
| 816 |
|
| 817 |
/** |
| 818 |
* Allow authorized users to access WP Data Access dashboard |
| 819 |
* |
| 820 |
* @return void |
| 821 |
*/ |
| 822 |
protected function grant_access_to_dashboard() { |
| 823 |
// Check user role. |
| 824 |
$user_roles = WPDA::get_current_user_roles(); |
| 825 |
if ( false === $user_roles || !is_array( $user_roles ) ) { |
| 826 |
// Cannot determine the user roles (not able to show menus). |
| 827 |
return; |
| 828 |
} |
| 829 |
// Check dashboard role access. |
| 830 |
$dashboard_roles = get_option( \WPDataAccess\Settings\WPDA_Settings_Legacy_Dashboard::DASHBOARD_ROLES ); |
| 831 |
$user_has_role = false; |
| 832 |
foreach ( $user_roles as $user_role ) { |
| 833 |
if ( false !== strpos( $dashboard_roles, $user_role ) ) { |
| 834 |
$user_has_role = true; |
| 835 |
break; |
| 836 |
} |
| 837 |
} |
| 838 |
// Check dashboard user access. |
| 839 |
$dashboard_users = get_option( \WPDataAccess\Settings\WPDA_Settings_Legacy_Dashboard::DASHBOARD_USERS ); |
| 840 |
$user_has_access = false !== strpos( $dashboard_users, WPDA::get_current_user_login() ); |
| 841 |
if ( !$user_has_role && !$user_has_access ) { |
| 842 |
return; |
| 843 |
} |
| 844 |
// User has dashboard access: add menu item. |
| 845 |
$this->create_non_admin_menu( self::PAGE_DASHBOARD ); |
| 846 |
add_submenu_page( |
| 847 |
$this->first_page, |
| 848 |
'Dashboard', |
| 849 |
'Dashboard', |
| 850 |
WPDA::get_current_user_capability(), |
| 851 |
self::PAGE_DASHBOARD, |
| 852 |
array($this, 'data_dashboard_page') |
| 853 |
); |
| 854 |
} |
| 855 |
|
| 856 |
/** |
| 857 |
* Allow authorized users to access Data Tables |
| 858 |
* |
| 859 |
* @return void |
| 860 |
*/ |
| 861 |
protected function grant_access_to_data_publications() { |
| 862 |
// Check user role. |
| 863 |
$user_roles = WPDA::get_current_user_roles(); |
| 864 |
if ( false === $user_roles || !is_array( $user_roles ) ) { |
| 865 |
// Cannot determine the user roles (not able to show menus). |
| 866 |
return; |
| 867 |
} |
| 868 |
$publication_roles = WPDA::get_option( WPDA::OPTION_DP_PUBLICATION_ROLES ); |
| 869 |
if ( '' === $publication_roles || 'administrator' === $publication_roles ) { |
| 870 |
// No access. |
| 871 |
return; |
| 872 |
} |
| 873 |
$user_has_role = false; |
| 874 |
foreach ( $user_roles as $user_role ) { |
| 875 |
if ( false !== stripos( $publication_roles, $user_role ) ) { |
| 876 |
$user_has_role = true; |
| 877 |
} |
| 878 |
} |
| 879 |
if ( !$user_has_role ) { |
| 880 |
// No access. |
| 881 |
return; |
| 882 |
} |
| 883 |
// Grant access to main menu. |
| 884 |
$this->create_non_admin_menu( self::PAGE_PUBLISHER ); |
| 885 |
// Add submenu for Data Tables. |
| 886 |
$this->wpda_data_publisher_menu = add_submenu_page( |
| 887 |
$this->first_page, |
| 888 |
'WP Data Access', |
| 889 |
'Data Tables', |
| 890 |
WPDA::get_current_user_capability(), |
| 891 |
self::PAGE_PUBLISHER, |
| 892 |
array($this, 'data_publisher_page') |
| 893 |
); |
| 894 |
if ( self::PAGE_PUBLISHER === $this->page ) { |
| 895 |
global $wpdb; |
| 896 |
$this->wpda_data_publisher_view = new WPDA_List_View(array( |
| 897 |
'page_hook_suffix' => $this->wpda_data_publisher_menu, |
| 898 |
'table_name' => $wpdb->prefix . 'wpda_publisher', |
| 899 |
'list_table_class' => 'WPDataAccess\\Data_Publisher\\WPDA_Publisher_List_Table', |
| 900 |
'edit_form_class' => 'WPDataAccess\\Data_Publisher\\WPDA_Publisher_Form', |
| 901 |
)); |
| 902 |
} |
| 903 |
} |
| 904 |
|
| 905 |
/** |
| 906 |
* Add dashboard page |
| 907 |
* |
| 908 |
* @return void |
| 909 |
*/ |
| 910 |
public function data_dashboard_page() { |
| 911 |
WPDA_Dashboard::add_dashboard( true ); |
| 912 |
} |
| 913 |
|
| 914 |
/** |
| 915 |
* Show data explorer main page |
| 916 |
* |
| 917 |
* Initialization of $this->wpda_data_explorer_view is done earlier in |
| 918 |
* {@see WP_Data_Access_Admin::add_menu_items()} to support screen options. This method just shows the page |
| 919 |
* containing the list table. |
| 920 |
* |
| 921 |
* @since 1.0.0 |
| 922 |
* |
| 923 |
* @see WP_Data_Access_Admin::add_menu_items() |
| 924 |
*/ |
| 925 |
public function data_explorer_page() { |
| 926 |
WPDA_Dashboard::add_dashboard(); |
| 927 |
if ( isset( $_REQUEST['page_action'] ) && 'wpda_backup' === $_REQUEST['page_action'] ) { |
| 928 |
$this->backup_page(); |
| 929 |
} elseif ( isset( $_REQUEST['page_action'] ) && 'wpda_import_csv' === $_REQUEST['page_action'] ) { |
| 930 |
$this->import_csv(); |
| 931 |
} elseif ( isset( $_REQUEST['page_action'] ) && 'wpda_global_search' === $_REQUEST['page_action'] ) { |
| 932 |
$this->advanced_search(); |
| 933 |
} else { |
| 934 |
$this->wpda_data_explorer_view->show(); |
| 935 |
} |
| 936 |
} |
| 937 |
|
| 938 |
public function data_explorer_page_new() { |
| 939 |
WPDA_Dashboard::add_dashboard(); |
| 940 |
if ( isset( $_REQUEST['page_action'] ) && 'wpda_backup' === $_REQUEST['page_action'] ) { |
| 941 |
$this->backup_page(); |
| 942 |
} elseif ( isset( $_REQUEST['page_action'] ) && 'wpda_import_csv' === $_REQUEST['page_action'] ) { |
| 943 |
$this->import_csv(); |
| 944 |
} elseif ( isset( $_REQUEST['page_action'] ) && 'wpda_global_search' === $_REQUEST['page_action'] ) { |
| 945 |
$this->advanced_search(); |
| 946 |
} else { |
| 947 |
$explorer = new WPDA_Data_Explorer(); |
| 948 |
$explorer->show(); |
| 949 |
} |
| 950 |
} |
| 951 |
|
| 952 |
public function data_navi() { |
| 953 |
if ( isset( $_POST['wpda-legacy-tool-status'] ) ) { |
| 954 |
// Legacy tools update |
| 955 |
$update_status = json_decode( sanitize_text_field( wp_unslash( $_POST['wpda-legacy-tool-status'] ) ), true ); |
| 956 |
if ( null !== $update_status ) { |
| 957 |
if ( isset( |
| 958 |
$update_status['tables'], |
| 959 |
$update_status['forms'], |
| 960 |
$update_status['templates'], |
| 961 |
$update_status['designer'], |
| 962 |
$update_status['dashboards'], |
| 963 |
$update_status['charts'] |
| 964 |
) ) { |
| 965 |
// Get current legacy tool settings |
| 966 |
$option_legacy_tools = \WPDataAccess\Utilities\WPDA_Legacy_Tool_Visibility::get(); |
| 967 |
// Update legacy tool settings |
| 968 |
$option_legacy_tools['tables'][0] = $update_status['tables']; |
| 969 |
$option_legacy_tools['forms'][0] = $update_status['forms']; |
| 970 |
$option_legacy_tools['templates'][0] = $update_status['templates']; |
| 971 |
$option_legacy_tools['designer'][0] = $update_status['designer']; |
| 972 |
$option_legacy_tools['dashboards'][0] = $update_status['dashboards']; |
| 973 |
$option_legacy_tools['charts'][0] = $update_status['charts']; |
| 974 |
// Save legacy tool settings |
| 975 |
WPDA::set_option( WPDA::OPTION_PLUGIN_LEGACY_TOOLS, $option_legacy_tools ); |
| 976 |
} |
| 977 |
} |
| 978 |
} |
| 979 |
WPDA_Dashboard::add_dashboard(); |
| 980 |
$navi = new WPDA_Navi(); |
| 981 |
$navi->show(); |
| 982 |
} |
| 983 |
|
| 984 |
public function data_apps() { |
| 985 |
WPDA_Dashboard::add_dashboard(); |
| 986 |
$wpda_app_builder = new WPDA_App_Builder(); |
| 987 |
$wpda_app_builder->show(); |
| 988 |
} |
| 989 |
|
| 990 |
public function advanced_search() { |
| 991 |
$advanced_search = new WPDA_Global_Search(); |
| 992 |
$advanced_search->show(); |
| 993 |
} |
| 994 |
|
| 995 |
/** |
| 996 |
* Add Query Builder |
| 997 |
* |
| 998 |
* @return void |
| 999 |
*/ |
| 1000 |
public function query_builder() { |
| 1001 |
WPDA_Dashboard::add_dashboard(); |
| 1002 |
$query_builder = new \WPDataAccess\Data_Apps\WPDA_Query_Builder(); |
| 1003 |
$query_builder->show(); |
| 1004 |
} |
| 1005 |
|
| 1006 |
public function query_builder_old() { |
| 1007 |
WPDA_Dashboard::add_dashboard(); |
| 1008 |
$query_builder = new \WPDataAccess\Query_Builder\WPDA_Query_Builder(); |
| 1009 |
$query_builder->show(); |
| 1010 |
} |
| 1011 |
|
| 1012 |
/** |
| 1013 |
* Add CSV page |
| 1014 |
* |
| 1015 |
* @return void |
| 1016 |
*/ |
| 1017 |
public function import_csv() { |
| 1018 |
$csv_import = new WPDA_CSV_Import(); |
| 1019 |
$csv_import->show(); |
| 1020 |
} |
| 1021 |
|
| 1022 |
/** |
| 1023 |
* Show data designer main page |
| 1024 |
* |
| 1025 |
* Initialization of $this->wpda_data_designer_view is done earlier in |
| 1026 |
* {@see WP_Data_Access_Admin::add_menu_items()} to support screen options. This method just shows the page |
| 1027 |
* containing the list table. |
| 1028 |
* |
| 1029 |
* @since 1.0.0 |
| 1030 |
* |
| 1031 |
* @see WP_Data_Access_Admin::add_menu_items() |
| 1032 |
*/ |
| 1033 |
public function data_designer_page() { |
| 1034 |
WPDA_Dashboard::add_dashboard(); |
| 1035 |
$data_designer_table_found = WPDA_Design_Table_Model::table_exists(); |
| 1036 |
if ( $data_designer_table_found ) { |
| 1037 |
$this->wpda_data_designer_view->show(); |
| 1038 |
} else { |
| 1039 |
$this->data_designer_page_not_found(); |
| 1040 |
} |
| 1041 |
} |
| 1042 |
|
| 1043 |
/** |
| 1044 |
* Data Designer repository table not found |
| 1045 |
*/ |
| 1046 |
public function data_designer_page_not_found() { |
| 1047 |
WPDA_Dashboard::add_dashboard(); |
| 1048 |
$wpda_repository = new WPDA_Repository(); |
| 1049 |
$wpda_repository->inform_user(); |
| 1050 |
?> |
| 1051 |
<div class="wrap"> |
| 1052 |
<h1 class="wp-heading-inline"> |
| 1053 |
<span>Data Designer</span> |
| 1054 |
<a href="https://docs.legacy.wpdataaccess.com/docs/data-designer-getting-started/" target="_blank" class="wpda_tooltip" title="Plugin Help - opens in a new tab or window"> |
| 1055 |
<span class="dashicons dashicons-editor-help" style="text-decoration:none;vertical-align:top;font-size:30px;"> |
| 1056 |
</span> |
| 1057 |
</a> |
| 1058 |
</h1> |
| 1059 |
<p> |
| 1060 |
<?php |
| 1061 |
esc_html_e( 'ERROR: Repository table not found!', 'wp-data-access' ); |
| 1062 |
?> |
| 1063 |
</p> |
| 1064 |
</div> |
| 1065 |
<?php |
| 1066 |
} |
| 1067 |
|
| 1068 |
/** |
| 1069 |
* Show Data Tables main page |
| 1070 |
*/ |
| 1071 |
public function data_publisher_page() { |
| 1072 |
if ( WPDA::current_user_is_admin() ) { |
| 1073 |
WPDA_Dashboard::add_dashboard(); |
| 1074 |
} |
| 1075 |
$data_publisher_table_found = WPDA_Publisher_Model::table_exists(); |
| 1076 |
if ( $data_publisher_table_found ) { |
| 1077 |
$this->wpda_data_publisher_view->show(); |
| 1078 |
} else { |
| 1079 |
$this->data_publisher_page_not_found(); |
| 1080 |
} |
| 1081 |
} |
| 1082 |
|
| 1083 |
public function data_publisher_mngstl() { |
| 1084 |
$mngstl = new WPDAPRO_Data_Publisher_Manage_Styles(); |
| 1085 |
$mngstl->show(); |
| 1086 |
} |
| 1087 |
|
| 1088 |
/** |
| 1089 |
* Add Charts page |
| 1090 |
* |
| 1091 |
* @return void |
| 1092 |
*/ |
| 1093 |
public function data_charts_page() { |
| 1094 |
} |
| 1095 |
|
| 1096 |
/** |
| 1097 |
* Data Tables repository table not found |
| 1098 |
*/ |
| 1099 |
public function data_publisher_page_not_found() { |
| 1100 |
if ( WPDA::current_user_is_admin() ) { |
| 1101 |
WPDA_Dashboard::add_dashboard(); |
| 1102 |
} |
| 1103 |
$wpda_repository = new WPDA_Repository(); |
| 1104 |
$wpda_repository->inform_user(); |
| 1105 |
?> |
| 1106 |
<div class="wrap"> |
| 1107 |
<h1 class="wp-heading-inline"> |
| 1108 |
<span>Data Tables</span> |
| 1109 |
<a href="https://docs.legacy.wpdataaccess.com/docs/data-tables-getting-started/" target="_blank" class="wpda_tooltip" title="Plugin Help - opens in a new tab or window"> |
| 1110 |
<span class="dashicons dashicons-editor-help" style="text-decoration:none;vertical-align:top;font-size:30px;"> |
| 1111 |
</span> |
| 1112 |
</a> |
| 1113 |
</h1> |
| 1114 |
<p> |
| 1115 |
<?php |
| 1116 |
esc_html_e( 'ERROR: Repository table not found!', 'wp-data-access' ); |
| 1117 |
?> |
| 1118 |
</p> |
| 1119 |
</div> |
| 1120 |
<?php |
| 1121 |
} |
| 1122 |
|
| 1123 |
/** |
| 1124 |
* Show data backup main page |
| 1125 |
* |
| 1126 |
* Calls a page to create automatic backups (in fact data exports) and offers possibilities to restore (in fact |
| 1127 |
* data imports). |
| 1128 |
* |
| 1129 |
* @since 2.0.6 |
| 1130 |
* |
| 1131 |
* @see WPDA_Data_Export::show_wp_cron() |
| 1132 |
*/ |
| 1133 |
public function backup_page() { |
| 1134 |
$wpda_backup = new WPDA_Data_Export(); |
| 1135 |
$wp_nonce = ( isset( $_REQUEST['wp_nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wp_nonce'] ) ) : '?' ); |
| 1136 |
if ( isset( $_REQUEST['action'] ) && wp_verify_nonce( $wp_nonce, 'wpda-backup-' . WPDA::get_current_user_login() ) ) { |
| 1137 |
$action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ); |
| 1138 |
if ( 'new' === $action ) { |
| 1139 |
$wpda_backup->create_export( 'add' ); |
| 1140 |
} elseif ( 'add' === $action ) { |
| 1141 |
$wpda_backup->wpda_add_cron_job(); |
| 1142 |
} elseif ( 'remove' === $action ) { |
| 1143 |
$wpda_backup->wpda_remove_cron_job(); |
| 1144 |
} elseif ( 'edit' === $action ) { |
| 1145 |
$wpda_backup->create_export( 'update' ); |
| 1146 |
} elseif ( 'update' === $action ) { |
| 1147 |
$wpda_backup->wpda_update_cron_job(); |
| 1148 |
} |
| 1149 |
} else { |
| 1150 |
$wpda_backup->show_wp_cron(); |
| 1151 |
} |
| 1152 |
} |
| 1153 |
|
| 1154 |
/** |
| 1155 |
* Add user defined sub menu |
| 1156 |
* |
| 1157 |
* WPDA allows users to create sub menu for table lists and simple forms. Sub menus can be added to the WPDA |
| 1158 |
* menu or any other (external) menu. A sub menu is added to an external menu via the menu slug. Sub menus are |
| 1159 |
* taken from {@see WPDA_User_Menus_Model}. |
| 1160 |
* |
| 1161 |
* This method is called from the admin_menu action with a lower priority to make sure other menus are available. |
| 1162 |
* User defined menu items are added to available menus in this method. These can be WPDA menus or external menus |
| 1163 |
* as mentioned in the according list table and edit form. WPDA menus are added to menu WP Data Tables. External |
| 1164 |
* menus are added to the menu having the menu slug defined by the user. |
| 1165 |
* |
| 1166 |
* This method does not actually show the list tables! It just creates the menu items. When the user clicks on such |
| 1167 |
* a dynamically defined menu item, method {@see WP_Data_Access_Admin::my_tables_page()} is called, which takes |
| 1168 |
* care of showing the list table. |
| 1169 |
* |
| 1170 |
* @since 1.0.0 |
| 1171 |
* |
| 1172 |
* @see WP_Data_Access_Admin::my_tables_page() |
| 1173 |
* @see WPDA_User_Menus_Model |
| 1174 |
*/ |
| 1175 |
public function add_menu_my_tables() { |
| 1176 |
$menus_shown_to_current_user = array(); |
| 1177 |
// Add list tables to external menus. |
| 1178 |
foreach ( WPDA_User_Menus_Model::list_external_menus() as $menu ) { |
| 1179 |
$user_roles = WPDA::get_current_user_roles(); |
| 1180 |
$user_has_role = false; |
| 1181 |
if ( '' === $menu->menu_role || null === $menu->menu_role ) { |
| 1182 |
$user_has_role = in_array( 'administrator', $user_roles, true ); |
| 1183 |
} else { |
| 1184 |
$user_role_array = explode( ',', (string) $menu->menu_role ); |
| 1185 |
// phpcs:ignore -- 8.1 proof |
| 1186 |
foreach ( $user_role_array as $user_role_array_item ) { |
| 1187 |
$user_has_role = in_array( $user_role_array_item, $user_roles, true ); |
| 1188 |
// phpcs:ignore -- 8.1 proof |
| 1189 |
if ( $user_has_role ) { |
| 1190 |
break; |
| 1191 |
} |
| 1192 |
} |
| 1193 |
} |
| 1194 |
if ( $user_has_role ) { |
| 1195 |
if ( !isset( $menus_shown_to_current_user[$menu->menu_slug . '/' . $menu->menu_name . '/' . $menu->menu_table_name . '/' . $menu->menu_schema_name] ) ) { |
| 1196 |
$menu_slug = self::PAGE_EXPLORER . '_' . $menu->menu_table_name; |
| 1197 |
$menu_index = $menu->menu_table_name; |
| 1198 |
$this->create_non_admin_menu( $menu_slug ); |
| 1199 |
$this->wpda_my_table_list_menu[$menu_index] = add_submenu_page( |
| 1200 |
$this->first_page, |
| 1201 |
'WP Data Access : ' . strtoupper( $menu->menu_table_name ), |
| 1202 |
$menu->menu_name, |
| 1203 |
WPDA::get_current_user_capability(), |
| 1204 |
$menu_slug, |
| 1205 |
array($this, 'my_tables_page') |
| 1206 |
); |
| 1207 |
$this->wpda_my_table_list_view[$menu_index] = new WPDA_List_View(array( |
| 1208 |
'page_hook_suffix' => $this->wpda_my_table_list_menu[$menu_index], |
| 1209 |
'wpdaschema_name' => $menu->menu_schema_name, |
| 1210 |
'table_name' => $menu->menu_table_name, |
| 1211 |
)); |
| 1212 |
$menus_shown_to_current_user[$menu->menu_slug . '/' . $menu->menu_name . '/' . $menu_index . '/' . $menu->menu_schema_name] = true; |
| 1213 |
} |
| 1214 |
} |
| 1215 |
} |
| 1216 |
} |
| 1217 |
|
| 1218 |
/** |
| 1219 |
* Show user defined menus |
| 1220 |
* |
| 1221 |
* A user defined menu that are added to the plugin menu in {@see WP_Data_Access_Admin::add_menu_my_tables()} is |
| 1222 |
* shown here. This method is called when the user clicks on the menu item generated in |
| 1223 |
* {@see WP_Data_Access_Admin::add_menu_my_tables()}. |
| 1224 |
* |
| 1225 |
* @since 1.0.0 |
| 1226 |
* |
| 1227 |
* @see WP_Data_Access_Admin::add_menu_my_tables() |
| 1228 |
*/ |
| 1229 |
public function my_tables_page() { |
| 1230 |
// Grab table name from menu slug. |
| 1231 |
if ( null !== $this->page ) { |
| 1232 |
if ( strpos( $this->page, self::PAGE_EXPLORER ) !== false ) { |
| 1233 |
$table = substr( $this->page, strlen( self::PAGE_EXPLORER . '_' ) ); |
| 1234 |
} else { |
| 1235 |
$table = substr( $this->page, strlen( self::PAGE_MY_TABLES . '_' ) ); |
| 1236 |
} |
| 1237 |
// Show list table. |
| 1238 |
$this->wpda_my_table_list_view[$table]->show(); |
| 1239 |
} |
| 1240 |
} |
| 1241 |
|
| 1242 |
/** |
| 1243 |
* Add main menu for non admin user |
| 1244 |
* |
| 1245 |
* @param string $first_page First plugin page. |
| 1246 |
* @return void |
| 1247 |
*/ |
| 1248 |
protected function create_non_admin_menu( $first_page ) { |
| 1249 |
if ( !$this->loaded_user_main_menu ) { |
| 1250 |
add_menu_page( |
| 1251 |
'WP Data Access', |
| 1252 |
'WP Data Access', |
| 1253 |
WPDA::get_current_user_capability(), |
| 1254 |
$first_page, |
| 1255 |
function () { |
| 1256 |
}, |
| 1257 |
'dashicons-database-view', |
| 1258 |
999999999 |
| 1259 |
); |
| 1260 |
$this->loaded_user_main_menu = true; |
| 1261 |
$this->first_page = $first_page; |
| 1262 |
} |
| 1263 |
} |
| 1264 |
|
| 1265 |
} |
| 1266 |
|
| 1267 |
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |