is_view() ) { // Prevent import object being created: exception must be handled in calling method. throw new \Exception( __( 'ERROR: Import not possible on views', 'wp-data-access' ) ); } } $this->url = $page; $this->schema_name = $schema_name; $this->table_name = $table_name; } /** * Checks if request is valid and allowed * * If the requested import is valid and allowed, the import file is loaded and its content imported. * * @since 1.0.0 */ public function check_post() { // Check if import was requested. // Import is not possible for WPDA_List_Table::LIST_BASE_TABLE (view in mysql information_schema). if ( WPDA_List_Table::LIST_BASE_TABLE !== $this->table_name && isset( $_REQUEST['action'] ) && 'import' === sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) // input var okay. ) { // Security check. $wp_nonce = isset( $_REQUEST['_wpnonceimport'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonceimport'] ) ) : '?'; // input var okay. if ( ! wp_verify_nonce( $wp_nonce, "wpda-import-{$this->table_name}" ) ) { wp_die( __( 'ERROR: Not authorized', 'wp-data-access' ) ); } if ( isset( $_FILES['filename'] ) ) { // phpcs:disable $temp_file_name = sanitize_text_field( $_FILES['filename']['tmp_name'] ); // For Windows: do NOT unslash! // phpcs:enable if ( UPLOAD_ERR_OK === $_FILES['filename']['error'] && is_uploaded_file( $temp_file_name ) ) { // Get file content. $wpda_import = new WPDA_Import_File( $temp_file_name ); // Check if errors should be shown. $hide_errors = isset( $_REQUEST['hide_errors'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['hide_errors'] ) ) : 'off'; // input var okay. // Process file content. $wpda_import->import( $this->schema_name, $this->table_name, $hide_errors ); } } else { // File upload failed: inform user. $msg = new WPDA_Message_Box( array( 'message_text' => __( 'File upload failed', 'wp-data-access' ), 'message_type' => 'error', 'message_is_dismissible' => false, ) ); $msg->box(); } } } /** * Adds an import button * * @param string $label Button label. * @param string $class Button CSS class. * * @since 1.0.0 */ public function add_button( $label = '', $class = 'page-title-action' ) { $storage_type = WPDA::is_wpda_table( $this->table_name ) ? __( 'current respository table', 'wp-data-access' ) : __( 'table', 'wp-data-access' ) . " {$this->table_name}"; $title = sprintf( __( 'Allows only imports into %s', 'wp-data-access' ), $storage_type ); ?>