| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Suppress "error - 0 - No summary was found for this file" on phpdoc generation |
| 5 |
* |
| 6 |
* @package plugin\includes |
| 7 |
*/ |
| 8 |
use WPDataAccess\Connection\WPDADB; |
| 9 |
use WPDataAccess\Cookies\WPDA_Cookies; |
| 10 |
use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists; |
| 11 |
use WPDataAccess\Data_Tables\WPDA_Data_Tables; |
| 12 |
use WPDataAccess\Plugin_Table_Models\WPDA_Table_Settings_Model; |
| 13 |
use WPDataAccess\Utilities\WPDA_Table_Actions; |
| 14 |
use WPDataAccess\Utilities\WPDA_Export; |
| 15 |
use WPDataAccess\Utilities\WPDA_Favourites; |
| 16 |
use WPDataAccess\WPDA; |
| 17 |
use WPDataProjects\Utilities\WPDP_Export_Project; |
| 18 |
use WPDataAccess\Backup\WPDA_Data_Export; |
| 19 |
use WPDataAccess\Plugin_Table_Models\WPDA_CSV_Uploads_Model; |
| 20 |
use WPDataRoles\WPDA_Roles; |
| 21 |
use WPDataAccess\Utilities\WPDA_Autocomplete; |
| 22 |
use WPDataAccess\Premium\WPDAPRO_Geo_Location\WPDAPRO_Geo_Location_WS; |
| 23 |
use WPDataAccess\Premium\WPDAPRO_Geo_Location\WPDAPRO_Geo_Location; |
| 24 |
use WPDataAccess\Query_Builder\WPDA_Query_Builder; |
| 25 |
use WPDataAccess\Dashboard\WPDA_Dashboard; |
| 26 |
use WPDataAccess\Dashboard\WPDA_Widget_Code; |
| 27 |
use WPDataAccess\Dashboard\WPDA_Widget_Publication; |
| 28 |
use WPDataAccess\Dashboard\WPDA_Widget_Dbms; |
| 29 |
use WPDataAccess\Dashboard\WPDA_Widget_Google_Chart; |
| 30 |
use WPDataAccess\Premium\WPDAPRO_Dashboard\WPDAPRO_Widget_Project; |
| 31 |
/** |
| 32 |
* Class WP_Data_Access |
| 33 |
* |
| 34 |
* Core plugin class used to define: |
| 35 |
* + admin specific functionality {@see WP_Data_Access_Admin} |
| 36 |
* + public specific functionality {@see WP_Data_Access_Public} |
| 37 |
* + internationalization {@see WP_Data_Access_I18n} |
| 38 |
* + plugin activation and deactivation {@see WP_Data_Access_Loader} |
| 39 |
* |
| 40 |
* @author Peter Schulz |
| 41 |
* @since 1.0.0 |
| 42 |
* |
| 43 |
* @see WP_Data_Access_Admin |
| 44 |
* @see WP_Data_Access_Public |
| 45 |
* @see WP_Data_Access_I18n |
| 46 |
* @see WP_Data_Access_Loader |
| 47 |
*/ |
| 48 |
class WP_Data_Access { |
| 49 |
/** |
| 50 |
* Reference to plugin loader |
| 51 |
* |
| 52 |
* @var WP_Data_Access_Loader |
| 53 |
* |
| 54 |
* @since 1.0.0 |
| 55 |
* |
| 56 |
* @see WP_Data_Access_Loader |
| 57 |
*/ |
| 58 |
protected $loader; |
| 59 |
|
| 60 |
/** |
| 61 |
* Menu slug or null |
| 62 |
* |
| 63 |
* @var null |
| 64 |
*/ |
| 65 |
protected $page = null; |
| 66 |
|
| 67 |
/** |
| 68 |
* WP_Data_Access constructor |
| 69 |
* |
| 70 |
* Calls method the following methods to setup plugin: |
| 71 |
* + {@see WP_Data_Access::load_dependencies()} |
| 72 |
* + {@see WP_Data_Access::set_locale()} |
| 73 |
* + {@see WP_Data_Access::define_admin_hooks()} |
| 74 |
* + {@see WP_Data_Access::define_public_hooks()} |
| 75 |
* |
| 76 |
* @since 1.0.0 |
| 77 |
* |
| 78 |
* @see WP_Data_Access::load_dependencies() |
| 79 |
* @see WP_Data_Access::set_locale() |
| 80 |
* @see WP_Data_Access::define_admin_hooks() |
| 81 |
* @see WP_Data_Access::define_public_hooks() |
| 82 |
*/ |
| 83 |
public function __construct() { |
| 84 |
if ( isset( $_REQUEST['page'] ) ) { |
| 85 |
// phpcs:ignore WordPress.Security.NonceVerification |
| 86 |
$this->page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); |
| 87 |
// phpcs:ignore WordPress.Security.NonceVerification |
| 88 |
} |
| 89 |
$this->load_dependencies(); |
| 90 |
$this->set_locale(); |
| 91 |
$this->define_admin_hooks(); |
| 92 |
$this->define_public_hooks(); |
| 93 |
// WP Data Access REST API. |
| 94 |
$this->api(); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Add WP Data Access JSON REST API |
| 99 |
* |
| 100 |
* @return void |
| 101 |
*/ |
| 102 |
private function api() { |
| 103 |
$api = new \WPDataAccess\API\WPDA_API(); |
| 104 |
$this->loader->add_action( 'init', $api, 'hide' ); |
| 105 |
$this->loader->add_action( 'rest_api_init', $api, 'init' ); |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Load required dependencies |
| 110 |
* |
| 111 |
* Loads required plugin files and initiates the plugin loader. |
| 112 |
* |
| 113 |
* @since 1.0.0 |
| 114 |
* |
| 115 |
* @see WP_Data_Access_Loader |
| 116 |
*/ |
| 117 |
private function load_dependencies() { |
| 118 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-data-access-loader.php'; |
| 119 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-data-access-i18n.php'; |
| 120 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp-data-access-admin.php'; |
| 121 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wp-data-access-public.php'; |
| 122 |
$this->loader = new WP_Data_Access_Loader(); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Set locale for internationalization |
| 127 |
* |
| 128 |
* @since 1.0.0 |
| 129 |
* |
| 130 |
* @see WP_Data_Access_I18n |
| 131 |
*/ |
| 132 |
private function set_locale() { |
| 133 |
$wpda_i18n = new WP_Data_Access_I18n(); |
| 134 |
$this->loader->add_action( 'init', $wpda_i18n, 'load_plugin_textdomain' ); |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Add admin hooks |
| 139 |
* |
| 140 |
* Initiates {@see WP_Data_Access_Admin} (admin functionality) and {@see WPDA_Export} (export functionality). |
| 141 |
* Adds the appropriate actions to the loader. |
| 142 |
* |
| 143 |
* @since 1.0.0 |
| 144 |
* |
| 145 |
* @see WP_Data_Access_Admin |
| 146 |
* @see WPDA_Export |
| 147 |
*/ |
| 148 |
private function define_admin_hooks() { |
| 149 |
$plugin_admin = new WP_Data_Access_Admin(); |
| 150 |
if ( WPDA::is_plugin_page( $this->page ) ) { |
| 151 |
// Handle plugin cookies. |
| 152 |
$wpda_cookies = new WPDA_Cookies(); |
| 153 |
$this->loader->add_action( 'admin_init', $wpda_cookies, 'handle_plugin_cookies' ); |
| 154 |
} |
| 155 |
// Admin menu. |
| 156 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu_items' ); |
| 157 |
$this->loader->add_action( |
| 158 |
'admin_menu', |
| 159 |
$plugin_admin, |
| 160 |
'add_menu_my_tables', |
| 161 |
11 |
| 162 |
); |
| 163 |
$this->loader->add_filter( 'submenu_file', $plugin_admin, 'wpda_submenu_filter' ); |
| 164 |
// Admin scripts. |
| 165 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
| 166 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| 167 |
$this->loader->add_action( 'in_admin_header', $plugin_admin, 'user_admin_notices' ); |
| 168 |
$this->loader->add_action( 'admin_head', $plugin_admin, 'remove_icons' ); |
| 169 |
// Add settings page. |
| 170 |
$this->loader->add_action( 'admin_menu', $this, 'wpdataaccess_register_settings_page' ); |
| 171 |
// Query Builder. |
| 172 |
$query_builder = new WPDA_Query_Builder(); |
| 173 |
$this->loader->add_action( 'admin_action_wpda_query_builder_execute_sql', $query_builder, 'execute' ); |
| 174 |
$this->loader->add_action( 'admin_action_wpda_query_builder_save_sql', $query_builder, 'save' ); |
| 175 |
$this->loader->add_action( 'admin_action_wpda_query_builder_open_sql', $query_builder, 'open' ); |
| 176 |
$this->loader->add_action( 'admin_action_wpda_query_builder_delete_sql', $query_builder, 'delete' ); |
| 177 |
$this->loader->add_action( 'admin_action_wpda_query_builder_get_db_hints', $query_builder, 'get_db_hints' ); |
| 178 |
$this->loader->add_action( 'admin_action_wpda_query_builder_set_db_hints', $query_builder, 'set_db_hints' ); |
| 179 |
$this->loader->add_action( 'admin_action_wpda_query_builder_get_vqb', $query_builder, 'get_visual_query_ajax' ); |
| 180 |
// Run unattended scheduled export |
| 181 |
$this->loader->add_action( \WPDataAccess\Utilities\WPDA_Export_Scheduler::SCHEDULER_HOOK_NAME, \WPDataAccess\Utilities\WPDA_Export_Scheduler::class, 'run_scheduled_export' ); |
| 182 |
// Mail service. |
| 183 |
$wpda_mail_server = \WPDataAccess\Utilities\WPDA_Mail::get_option(); |
| 184 |
if ( isset( |
| 185 |
$wpda_mail_server['host'], |
| 186 |
$wpda_mail_server['port'], |
| 187 |
$wpda_mail_server['authenticate'], |
| 188 |
$wpda_mail_server['encryption'], |
| 189 |
$wpda_mail_server['skip_verify'], |
| 190 |
$wpda_mail_server['username'], |
| 191 |
$wpda_mail_server['password'] |
| 192 |
) ) { |
| 193 |
add_action( |
| 194 |
'phpmailer_init', |
| 195 |
function ( $phpmailer ) use($wpda_mail_server) { |
| 196 |
// Only run if mail WPDA requests. |
| 197 |
if ( !did_action( 'wpda_sending_mail' ) ) { |
| 198 |
return; |
| 199 |
// Allow other plugins/themes to overwrite. |
| 200 |
} |
| 201 |
$phpmailer->isSMTP(); |
| 202 |
$phpmailer->isHTML( false ); |
| 203 |
$phpmailer->SMTPDebug = $wpda_mail_server['debug'] ?? 0; |
| 204 |
$phpmailer->Host = $wpda_mail_server['host']; |
| 205 |
$phpmailer->Port = $wpda_mail_server['port']; |
| 206 |
$phpmailer->SMTPAuth = 'on' === $wpda_mail_server['authenticate']; |
| 207 |
$phpmailer->SMTPSecure = $wpda_mail_server['encryption']; |
| 208 |
if ( 'on' === $wpda_mail_server['skip_verify'] ) { |
| 209 |
$phpmailer->SMTPOptions = array( |
| 210 |
'ssl' => array( |
| 211 |
'verify_peer' => false, |
| 212 |
'verify_peer_name' => false, |
| 213 |
'allow_self_signed' => true, |
| 214 |
), |
| 215 |
); |
| 216 |
} |
| 217 |
$phpmailer->Username = $wpda_mail_server['username']; |
| 218 |
$phpmailer->Password = $wpda_mail_server['password']; |
| 219 |
$phpmailer->From = $wpda_mail_server['username']; |
| 220 |
}, |
| 221 |
10, |
| 222 |
1 |
| 223 |
); |
| 224 |
} |
| 225 |
// Export action. |
| 226 |
$this->loader->add_action( 'admin_action_wpda_export', WPDA_Export::class, 'export' ); |
| 227 |
// Dashboard and widgets. |
| 228 |
$this->loader->add_action( 'wp_ajax_wpda_save_dashboard', WPDA_Dashboard::class, 'save' ); |
| 229 |
$this->loader->add_action( 'wp_ajax_wpda_dashboard_list', WPDA_Dashboard::class, 'get_list' ); |
| 230 |
$this->loader->add_action( 'wp_ajax_wpda_widget_load_panel', WPDA_Dashboard::class, 'load_widget' ); |
| 231 |
$this->loader->add_action( 'wp_ajax_wpda_widget_delete', WPDA_Dashboard::class, 'delete_widget' ); |
| 232 |
$this->loader->add_action( 'wp_ajax_wpda_widget_code_add', WPDA_Widget_Code::class, 'ajax_widget' ); |
| 233 |
$this->loader->add_action( 'wp_ajax_wpda_widget_dbms_add', WPDA_Widget_Dbms::class, 'ajax_widget' ); |
| 234 |
$this->loader->add_action( 'wp_ajax_wpda_widget_dbms_refresh', WPDA_Widget_Dbms::class, 'ajax_refresh' ); |
| 235 |
$this->loader->add_action( 'wp_ajax_wpda_remove_new_dashboard_message', WPDA_Dashboard::class, 'remove_new_dashboard_message' ); |
| 236 |
$this->loader->add_action( 'wp_ajax_wpda_widget_pub_add', WPDA_Widget_Publication::class, 'ajax_widget' ); |
| 237 |
$this->loader->add_action( 'wp_ajax_wpda_widget_chart_add', WPDA_Widget_Google_Chart::class, 'ajax_widget' ); |
| 238 |
$this->loader->add_action( 'wp_ajax_wpda_widget_chart_refresh', WPDA_Widget_Google_Chart::class, 'ajax_refresh' ); |
| 239 |
// Add/remove favourites. |
| 240 |
$plugin_favourites = new WPDA_Favourites(); |
| 241 |
$this->loader->add_action( 'admin_action_wpda_add_favourite', $plugin_favourites, 'add' ); |
| 242 |
$this->loader->add_action( 'admin_action_wpda_rem_favourite', $plugin_favourites, 'rem' ); |
| 243 |
// Show tables actions. |
| 244 |
$plugin_table_actions = new WPDA_Table_Actions(); |
| 245 |
$this->loader->add_action( 'admin_action_wpda_show_table_actions', $plugin_table_actions, 'show' ); |
| 246 |
$plugin_dictionary_list = new WPDA_Dictionary_Lists(); |
| 247 |
// Get tables for a specific database. |
| 248 |
$this->loader->add_action( 'admin_action_wpda_get_tables', $plugin_dictionary_list, 'get_tables_ajax' ); |
| 249 |
// Get columns for a specific table. |
| 250 |
$this->loader->add_action( 'admin_action_wpda_get_columns', $plugin_dictionary_list, 'get_columns' ); |
| 251 |
// Get row count for a specific table. |
| 252 |
$this->loader->add_action( 'admin_action_wpda_get_table_row_count', $plugin_dictionary_list, 'get_table_row_count_ajax' ); |
| 253 |
// Get table widget info. |
| 254 |
$this->loader->add_action( 'admin_action_wpda_get_table_widget_info', $plugin_dictionary_list, 'get_table_widget_info_ajax' ); |
| 255 |
// Global database search and replace. |
| 256 |
$this->loader->add_action( 'wp_ajax_wpda_global_search', \WPDataAccess\Global_Search\WPDA_Global_Search::class, 'search' ); |
| 257 |
$this->loader->add_action( 'wp_ajax_wpda_global_replace', \WPDataAccess\Global_Search\WPDA_Global_Search::class, 'replace' ); |
| 258 |
// Export project. |
| 259 |
$plugin_export_project = new WPDP_Export_Project(); |
| 260 |
$this->loader->add_action( 'admin_action_wpda_export_project', $plugin_export_project, 'export' ); |
| 261 |
// Data backup. |
| 262 |
$wpda_data_backup = new WPDA_Data_Export(); |
| 263 |
$this->loader->add_action( 'wpda_data_backup', $wpda_data_backup, 'wpda_data_backup' ); |
| 264 |
// Allow to add multiple user roles. |
| 265 |
$wpda_roles = new WPDA_Roles(); |
| 266 |
$this->loader->add_action( 'user_new_form', $wpda_roles, 'multiple_roles_selection' ); |
| 267 |
$this->loader->add_action( 'edit_user_profile', $wpda_roles, 'multiple_roles_selection' ); |
| 268 |
$this->loader->add_action( 'profile_update', $wpda_roles, 'multiple_roles_update' ); |
| 269 |
$this->loader->add_filter( 'manage_users_columns', $wpda_roles, 'multiple_roles_label' ); |
| 270 |
// Check if a remote db connection can be established via ajax. |
| 271 |
$wpdadb = new WPDADB(); |
| 272 |
$this->loader->add_action( 'admin_action_wpda_check_remote_database_connection', $wpdadb, 'check_remote_database_connection' ); |
| 273 |
// Make WordPress user ID available to database connections. |
| 274 |
add_action( |
| 275 |
'wpda_dbinit', |
| 276 |
function ( $wpdadb ) { |
| 277 |
if ( null !== $wpdadb ) { |
| 278 |
$suppress_errors = $wpdadb->suppress_errors( true ); |
| 279 |
$wpdadb->query( 'set @wpda_wp_user_id = ' . get_current_user_id() ); |
| 280 |
$wpdadb->suppress_errors( $suppress_errors ); |
| 281 |
} |
| 282 |
}, |
| 283 |
10, |
| 284 |
1 |
| 285 |
); |
| 286 |
add_action( |
| 287 |
'wp_ajax_wpda_dbinit_admin', |
| 288 |
function () { |
| 289 |
if ( !isset( $_POST['wpnonce'], $_POST['wpdaschema_name'] ) ) { |
| 290 |
WPDA::sent_header( 'application/json' ); |
| 291 |
echo WPDA::sent_msg( 'ERROR', 'Invalid arguments' ); |
| 292 |
// phpcs:ignore WordPress.Security.EscapeOutput |
| 293 |
wp_die(); |
| 294 |
} |
| 295 |
$wpnonce = sanitize_text_field( wp_unslash( $_REQUEST['wpnonce'] ) ); |
| 296 |
// input var okay. |
| 297 |
if ( !WPDA::current_user_is_admin() || !wp_verify_nonce( $wpnonce, 'wpda_dbinit_admin_' . WPDA::get_current_user_login() ) ) { |
| 298 |
WPDA::sent_header( 'application/json' ); |
| 299 |
echo WPDA::sent_msg( 'ERROR', 'Not authorized' ); |
| 300 |
// phpcs:ignore WordPress.Security.EscapeOutput |
| 301 |
wp_die(); |
| 302 |
} |
| 303 |
$wpdaschema_name = sanitize_text_field( wp_unslash( $_REQUEST['wpdaschema_name'] ) ); |
| 304 |
// input var okay. |
| 305 |
$wpdadb = WPDADB::get_db_connection( $wpdaschema_name ); |
| 306 |
if ( null === $wpdadb ) { |
| 307 |
WPDA::sent_header( 'application/json' ); |
| 308 |
echo WPDA::sent_msg( 'ERROR', 'Cannot connect to database' ); |
| 309 |
// phpcs:ignore WordPress.Security.EscapeOutput |
| 310 |
wp_die(); |
| 311 |
} |
| 312 |
$suppress_errors = $wpdadb->suppress_errors( true ); |
| 313 |
$wpdadb->query( 'create function wpda_get_wp_user_id() returns integer deterministic no sql return @wpda_wp_user_id' ); |
| 314 |
$error = $wpdadb->last_error; |
| 315 |
$wpdadb->suppress_errors( $suppress_errors ); |
| 316 |
if ( '' === $error ) { |
| 317 |
//phpcs:ignore - 8.1 proof |
| 318 |
echo WPDA::sent_msg( 'OK', '' ); |
| 319 |
// phpcs:ignore WordPress.Security.EscapeOutput |
| 320 |
} else { |
| 321 |
echo WPDA::sent_msg( 'ERROR', "Function not created [{$error}]" ); |
| 322 |
// phpcs:ignore WordPress.Security.EscapeOutput |
| 323 |
} |
| 324 |
wp_die(); |
| 325 |
}, |
| 326 |
10, |
| 327 |
1 |
| 328 |
); |
| 329 |
// Add id to wpda_datatables.js (for IE). |
| 330 |
$this->loader->add_filter( |
| 331 |
'script_loader_tag', |
| 332 |
$this, |
| 333 |
'add_id_to_script', |
| 334 |
10, |
| 335 |
3 |
| 336 |
); |
| 337 |
// Add CSV mapping calls. |
| 338 |
$wpda_csv_uploads_model = new WPDA_CSV_Uploads_Model(); |
| 339 |
$this->loader->add_action( 'admin_action_wpda_save_csv_mapping', $wpda_csv_uploads_model, 'save_mapping' ); |
| 340 |
$this->loader->add_action( 'admin_action_wpda_csv_preview_mapping', $wpda_csv_uploads_model, 'preview_mapping' ); |
| 341 |
// Data Tables services. |
| 342 |
$this->loader->add_action( 'wp_ajax_wpda_test_publication', \WPDataAccess\Data_Publisher\WPDA_Publisher_Form::class, 'test_publication' ); |
| 343 |
// Add custom CSS to freemius pages. |
| 344 |
add_action( |
| 345 |
'admin_footer', |
| 346 |
function () { |
| 347 |
if ( WP_Data_Access_Admin::MAIN_PAGE_SLUG . '-account' === $this->page || WP_Data_Access_Admin::MAIN_PAGE_SLUG . '-pricing' === $this->page ) { |
| 348 |
?> |
| 349 |
<script type="application/javascript"> |
| 350 |
jQuery(function() { |
| 351 |
jQuery.each(document.styleSheets, function (index, cssFile) { |
| 352 |
if (cssFile.href!==null && cssFile.href.toString().includes("load-styles.php")) { |
| 353 |
var classes = cssFile.rules || cssFile.cssRules; |
| 354 |
for (var x=0; x<classes.length; x++) { |
| 355 |
if ( |
| 356 |
classes[x].selectorText!==undefined && |
| 357 |
classes[x].selectorText!==null && |
| 358 |
classes[x].selectorText.includes("#adminmenu li.current a.menu-top") |
| 359 |
) { |
| 360 |
jQuery("#adminmenu #toplevel_page_wpda a.menu-top").attr("style", classes[x].style.cssText); |
| 361 |
} |
| 362 |
} |
| 363 |
} |
| 364 |
}); |
| 365 |
}); |
| 366 |
</script> |
| 367 |
<?php |
| 368 |
} |
| 369 |
}, |
| 370 |
10, |
| 371 |
1 |
| 372 |
); |
| 373 |
add_action( |
| 374 |
'wpda_set_hard_row_count', |
| 375 |
function ( $dbs, $tbl ) { |
| 376 |
// Only admins and super admins. |
| 377 |
if ( WPDA::current_user_is_admin() ) { |
| 378 |
// Get actual row count. |
| 379 |
$count = \WPDataAccess\API\WPDA_Actions::get_row_count( $dbs, $tbl ); |
| 380 |
// Get table settings. |
| 381 |
$settings_db = WPDA_Table_Settings_Model::query( $tbl, $dbs ); |
| 382 |
if ( isset( $settings_db[0]['wpda_table_settings'] ) ) { |
| 383 |
// Convert string to JSON. |
| 384 |
$settings = json_decode( $settings_db[0]['wpda_table_settings'], true ); |
| 385 |
if ( isset( $settings['table_settings']['row_count_estimate_value_hard'] ) ) { |
| 386 |
// Store actual row count as hard estimate. |
| 387 |
$settings['table_settings']['row_count_estimate_value_hard'] = $count; |
| 388 |
// Save new hard row count. |
| 389 |
WPDA_Table_Settings_Model::update( $tbl, json_encode( $settings ), $dbs ); |
| 390 |
} |
| 391 |
} |
| 392 |
} |
| 393 |
}, |
| 394 |
10, |
| 395 |
2 |
| 396 |
); |
| 397 |
} |
| 398 |
|
| 399 |
/** |
| 400 |
* Needed for JDT to support IE |
| 401 |
* |
| 402 |
* @param string $tag Tag. |
| 403 |
* @param string $handle Handle. |
| 404 |
* @param string $src Source. |
| 405 |
* @return mixed|string |
| 406 |
*/ |
| 407 |
public function add_id_to_script( $tag, $handle, $src ) { |
| 408 |
if ( 'wpda_datatables' === $handle ) { |
| 409 |
$tag = '<script id="wpda_datatables" src="' . $src . '"></script>'; |
| 410 |
// phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
| 411 |
} |
| 412 |
return $tag; |
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* Add public hooks |
| 417 |
* |
| 418 |
* Initiates {@see WP_Data_Access_Public} (public functionality), {@see WPDA_Data_Tables} (ajax call to support |
| 419 |
* server side jQuery DataTables functionality). Adds the appropriate actions to |
| 420 |
* the loader. |
| 421 |
* |
| 422 |
* @since 1.0.0 |
| 423 |
* |
| 424 |
* @see WP_Data_Access_Public |
| 425 |
* @see WPDA_Data_Tables |
| 426 |
* @see WPDA_Dictionary_Lists |
| 427 |
*/ |
| 428 |
private function define_public_hooks() { |
| 429 |
$plugin_public = new WP_Data_Access_Public(); |
| 430 |
// Shortcodes. |
| 431 |
$this->loader->add_action( 'init', $plugin_public, 'register_shortcodes' ); |
| 432 |
// Public scripts. |
| 433 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
| 434 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
| 435 |
$this->loader->add_action( |
| 436 |
'admin_bar_menu', |
| 437 |
$plugin_public, |
| 438 |
'add_apps_to_admin_toolbar', |
| 439 |
9999 |
| 440 |
); |
| 441 |
$this->loader->add_action( |
| 442 |
'admin_bar_menu', |
| 443 |
$plugin_public, |
| 444 |
'add_data_projects_to_admin_toolbar', |
| 445 |
9999 |
| 446 |
); |
| 447 |
// Ajax calls. |
| 448 |
$plugin_datatables = new WPDA_Data_Tables(); |
| 449 |
$this->loader->add_action( 'wp_ajax_wpda_datatables', $plugin_datatables, 'get_data' ); |
| 450 |
$this->loader->add_action( 'wp_ajax_nopriv_wpda_datatables', $plugin_datatables, 'get_data' ); |
| 451 |
// Export action. |
| 452 |
$this->loader->add_action( 'wp_ajax_wpda_export', WPDA_Export::class, 'export_ajax' ); |
| 453 |
$this->loader->add_action( 'wp_ajax_nopriv_wpda_export', WPDA_Export::class, 'export_ajax' ); |
| 454 |
// Add id to wpda_datatables.js (for IE). |
| 455 |
$this->loader->add_filter( |
| 456 |
'script_loader_tag', |
| 457 |
$this, |
| 458 |
'add_id_to_script', |
| 459 |
10, |
| 460 |
3 |
| 461 |
); |
| 462 |
// Autocomplete. |
| 463 |
$autocomplete_service = new WPDA_Autocomplete(); |
| 464 |
$this->loader->add_action( 'wp_ajax_wpda_autocomplete', $autocomplete_service, 'autocomplete' ); |
| 465 |
$this->loader->add_action( 'wp_ajax_nopriv_wpda_autocomplete', $autocomplete_service, 'autocomplete_anonymous' ); |
| 466 |
} |
| 467 |
|
| 468 |
/** |
| 469 |
* Start plugin loader |
| 470 |
* |
| 471 |
* @since 1.0.0 |
| 472 |
*/ |
| 473 |
public function run() { |
| 474 |
$this->loader->run(); |
| 475 |
} |
| 476 |
|
| 477 |
/** |
| 478 |
* Add plugin settings page |
| 479 |
*/ |
| 480 |
public function wpdataaccess_register_settings_page() { |
| 481 |
add_options_page( |
| 482 |
'WP Data Access', |
| 483 |
'WP Data Access', |
| 484 |
'manage_options', |
| 485 |
WP_Data_Access_Admin::PAGE_SETTINGS, |
| 486 |
array($this, 'wpdataaccess_settings_page') |
| 487 |
); |
| 488 |
} |
| 489 |
|
| 490 |
/** |
| 491 |
* Show settings page |
| 492 |
*/ |
| 493 |
public function wpdataaccess_settings_page() { |
| 494 |
WPDA_Dashboard::add_dashboard(); |
| 495 |
$current_tab = ( isset( $_REQUEST['tab'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ) : 'plugin' ); |
| 496 |
// phpcs:ignore WordPress.Security.NonceVerification |
| 497 |
switch ( $current_tab ) { |
| 498 |
case 'apps': |
| 499 |
$wpda_settings_class_name = 'WPDA_Settings_Apps'; |
| 500 |
break; |
| 501 |
case 'backend': |
| 502 |
$wpda_settings_class_name = 'WPDA_Settings_BackEnd'; |
| 503 |
break; |
| 504 |
case 'frontend': |
| 505 |
$wpda_settings_class_name = 'WPDA_Settings_FrontEnd'; |
| 506 |
break; |
| 507 |
case 'pds': |
| 508 |
$wpda_settings_class_name = 'WPDA_Settings_PDS'; |
| 509 |
break; |
| 510 |
case 'uninstall': |
| 511 |
$wpda_settings_class_name = 'WPDA_Settings_Uninstall'; |
| 512 |
break; |
| 513 |
case 'repository': |
| 514 |
$wpda_settings_class_name = 'WPDA_Settings_ManageRepository'; |
| 515 |
break; |
| 516 |
case 'system': |
| 517 |
$wpda_settings_class_name = 'WPDA_Settings_SystemInfo'; |
| 518 |
break; |
| 519 |
case 'mail': |
| 520 |
$wpda_settings_class_name = 'WPDA_Settings_Mail'; |
| 521 |
break; |
| 522 |
case 'drives': |
| 523 |
$wpda_settings_class_name = 'WPDA_Settings_Drives'; |
| 524 |
break; |
| 525 |
case 'legacy': |
| 526 |
$wpda_settings_class_name = 'WPDA_Settings_Legacy'; |
| 527 |
break; |
| 528 |
default: |
| 529 |
$wpda_settings_class_name = 'WPDA_Settings_Plugin'; |
| 530 |
} |
| 531 |
$wpda_settings_class_name = '\\WPDataAccess\\Settings\\' . $wpda_settings_class_name; |
| 532 |
$wpda_settings = new $wpda_settings_class_name($current_tab); |
| 533 |
$wpda_settings->show(); |
| 534 |
} |
| 535 |
|
| 536 |
} |
| 537 |
|