' . esc_html__( 'This import has expired. Please upload the file again.', 'nodebook' ) . '

'; } elseif ( $run ) { self::progress( $token ); Nodebook_Admin::footer(); return; } else { self::mapping( $token, $job ); Nodebook_Admin::footer(); return; } } $import = ! Nodebook_Team::restricted(); echo '
'; if ( Nodebook_Team::can_export() ) { self::export_card(); } if ( $import ) { self::import_card(); } if ( $import && Nodebook_Woocommerce::active() ) { self::woo_card(); } if ( $import && current_user_can( 'manage_options' ) ) { self::users_card(); } if ( ! $import && ! Nodebook_Team::can_export() ) { echo '

' . esc_html__( 'Importing and exporting is not switched on for you. Ask an administrator (Settings → Team).', 'nodebook' ) . '

'; } foreach ( $import ? Nodebook_Import::available() : array() as $nodebook_src => $nodebook_class ) { self::crm_card( $nodebook_src, $nodebook_class ); } if ( current_user_can( 'manage_options' ) ) { echo '

' . esc_html__( 'Sample data', 'nodebook' ) . '

' . esc_html( Nodebook_Sample::present() ? __( 'Sample people, deals and tasks are in Nodebook now. Removing them leaves your own data untouched.', 'nodebook' ) : __( 'Try every screen with two dozen sample people, deals, tasks and visits for your kind of business. Nothing is emailed; remove it with one click.', 'nodebook' ) ) . '

'; Nodebook_Sample::button(); echo '
'; } echo '
'; Nodebook_Admin::footer(); } private static function export_card() { ?>

$r ) : ?>

$r->get_error_message() ) ); } wp_send_json_success( array( 'done' => $r['done'], 'progress' => $r['progress'], 'stats' => $r['stats'], 'seen' => (int) $r['seen'], 'total' => (int) $r['total'], ) ); } private static function mapping( $token, array $job ) { $entity = $job['entity']; $targets = 'companies' === $entity ? Nodebook_Fields::company() : Nodebook_Fields::contact(); $guess = Nodebook_Csv::guess_map( $job['headers'], $entity ); $sample = self::sample( $job ); ?>

$h ) : ?>

isset( $_REQUEST['segment'] ) ? absint( $_REQUEST['segment'] ) : 0, 'status' => isset( $_REQUEST['status'] ) ? sanitize_key( wp_unslash( $_REQUEST['status'] ) ) : '', ); // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( 'companies' === $entity ) { Nodebook_Csv::export_companies( array() ); } elseif ( 'activities' === $entity ) { Nodebook_Csv::export_activities( array() ); } elseif ( 'deals' === $entity ) { Nodebook_Csv::export_deals( array() ); } Nodebook_Csv::export_contacts( $args ); } public static function upload() { Nodebook_Admin::require_cap(); check_admin_referer( 'nodebook_import_upload' ); $entity = isset( $_POST['entity'] ) ? sanitize_key( wp_unslash( $_POST['entity'] ) ) : 'contacts'; $file = array(); if ( isset( $_FILES['file'] ) && is_array( $_FILES['file'] ) ) { // tmp_name and size come from PHP itself; the file is checked and stored by wp_handle_upload(). $file = array( 'name' => isset( $_FILES['file']['name'] ) ? sanitize_file_name( wp_unslash( (string) $_FILES['file']['name'] ) ) : '', 'type' => isset( $_FILES['file']['type'] ) ? sanitize_mime_type( wp_unslash( (string) $_FILES['file']['type'] ) ) : '', 'tmp_name' => isset( $_FILES['file']['tmp_name'] ) ? (string) $_FILES['file']['tmp_name'] : '', // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- server path set by PHP, checked with is_uploaded_file() by wp_handle_upload(). 'error' => isset( $_FILES['file']['error'] ) ? absint( $_FILES['file']['error'] ) : UPLOAD_ERR_NO_FILE, 'size' => isset( $_FILES['file']['size'] ) ? absint( $_FILES['file']['size'] ) : 0, ); } $token = Nodebook_Csv::receive( $file, $entity ); if ( is_wp_error( $token ) ) { Nodebook_Admin::redirect( Nodebook_Admin::url( 'nodebook-tools' ), 'upload' ); } Nodebook_Admin::redirect( Nodebook_Admin::url( 'nodebook-tools', array( 'import' => $token ) ) ); } public static function map() { Nodebook_Admin::require_cap(); check_admin_referer( 'nodebook_import_map' ); $token = isset( $_POST['token'] ) ? sanitize_key( wp_unslash( $_POST['token'] ) ) : ''; $job = Nodebook_Csv::get_job( $token ); if ( ! $job ) { Nodebook_Admin::redirect( Nodebook_Admin::url( 'nodebook-tools' ), 'expired' ); } $allowed = array_merge( array( '__skip', '__meta', 'full_name', 'segments', 'custom_fields', 'email_status' ), array_keys( 'companies' === $job['entity'] ? Nodebook_Fields::company() : Nodebook_Fields::contact() ), array_keys( Nodebook_Props::defs( 'companies' === $job['entity'] ? 'company' : 'contact' ) ) ); $map = array(); $raw = isset( $_POST['map'] ) ? array_map( 'sanitize_key', (array) wp_unslash( $_POST['map'] ) ) : array(); foreach ( $job['headers'] as $i => $h ) { $v = isset( $raw[ $i ] ) ? $raw[ $i ] : '__skip'; $v = in_array( $v, array( '__skip', '__meta' ), true ) ? $v : sanitize_key( $v ); $map[ $i ] = in_array( $v, $allowed, true ) ? $v : '__skip'; } $segment = isset( $_POST['segment'] ) ? sanitize_key( wp_unslash( $_POST['segment'] ) ) : '0'; if ( 'new' === $segment ) { $segment = Nodebook_Segments::save( array( /* translators: %s: file name */ 'name' => sprintf( __( 'Import: %s', 'nodebook' ), preg_replace( '/\.csv$/i', '', $job['name'] ) ), 'type' => 'static', ) ); } $job['map'] = $map; $job['options'] = array( 'update' => ! empty( $_POST['update'] ), 'status' => isset( $_POST['status'] ) ? sanitize_key( wp_unslash( $_POST['status'] ) ) : '', 'segment' => absint( $segment ), ); Nodebook_Csv::save_job( $token, $job ); Nodebook_Admin::redirect( Nodebook_Admin::url( 'nodebook-tools', array( 'import' => $token, 'run' => 1, ) ) ); } public static function ajax_batch() { check_ajax_referer( 'nodebook_ajax', 'nonce' ); if ( ! current_user_can( Nodebook_Admin::cap() ) ) { wp_send_json_error( null, 403 ); } $token = isset( $_POST['token'] ) ? sanitize_key( wp_unslash( $_POST['token'] ) ) : ''; $r = Nodebook_Csv::process( $token ); if ( is_wp_error( $r ) ) { wp_send_json_error( array( 'message' => $r->get_error_message() ) ); } wp_send_json_success( $r ); } public static function ajax_backfill() { check_ajax_referer( 'nodebook_ajax', 'nonce' ); if ( ! current_user_can( Nodebook_Admin::cap() ) || ! Nodebook_Woocommerce::active() ) { wp_send_json_error( null, 403 ); } $page = isset( $_POST['page'] ) ? max( 1, absint( $_POST['page'] ) ) : 1; wp_send_json_success( Nodebook_Woocommerce::backfill( $page ) ); } }