芝麻web文件管理V1.00
编辑当前文件:/home/seolotod/sthwholesaler.com/wp-content/plugins/woo-alidropship/includes/data.php
default = array( 'enable' => '1', 'secret_key' => '', 'product_status' => 'publish', 'catalog_visibility' => 'visible', 'product_gallery' => '1', 'product_categories' => array(), 'product_tags' => array(), 'product_shipping_class' => '', 'product_description' => 'item_specifics_and_description', 'variation_visible' => '', 'manage_stock' => '1', 'ignore_ship_from' => '', 'price_from' => array( 0 ), 'price_to' => array( '' ), 'plus_value' => array( 200 ), 'plus_sale_value' => array( - 1 ), 'plus_value_type' => array( 'percent' ), 'price_default' => array( 'plus_value' => 2, 'plus_sale_value' => 1, 'plus_value_type' => 'multiply', ), 'import_product_currency' => 'USD', 'import_currency_rate' => '1', 'import_currency_rate_RUB' => '', 'fulfill_default_carrier' => 'EMS_ZX_ZX_US', 'fulfill_default_phone_number' => '', 'fulfill_default_phone_number_override' => '', 'fulfill_default_phone_country' => '', 'fulfill_order_note' => 'I\'m dropshipping. Please DO NOT put any invoices, QR codes, promotions or your brand name logo in the shipments. Please ship as soon as possible for repeat business. Thank you!', 'order_status_for_fulfill' => array( 'wc-completed', 'wc-on-hold', 'wc-processing' ), 'order_status_after_sync' => 'wc-completed', 'string_replace' => array(), 'carrier_name_replaces' => array( 'from_string' => array(), 'to_string' => array(), 'sensitive' => array(), ), 'carrier_url_replaces' => array( 'from_string' => array(), 'to_string' => array(), ), 'disable_background_process' => '', 'simple_if_one_variation' => '', 'download_description_images' => '', 'show_shipping_option' => '1', 'shipping_cost_after_price_rules' => '1', 'use_global_attributes' => '1', 'format_price_rules_enable' => '', 'format_price_rules_test' => 0, 'format_price_rules' => array(), 'override_hide' => 0, 'override_keep_product' => 1, 'override_title' => 0, 'override_images' => 0, 'override_description' => 0, 'override_find_in_orders' => 1, 'delete_woo_product' => 1, 'cpf_custom_meta_key' => '', 'billing_number_meta_key' => '', 'shipping_number_meta_key' => '', 'billing_neighborhood_meta_key' => '', 'shipping_neighborhood_meta_key' => '', 'rut_meta_key' => '', 'rfc_curp_meta_key' => '', 'use_external_image' => '', 'fulfill_billing_fields_in_latin' => '', 'ald_table' => '', ); $this->params = wp_parse_args( $wooaliexpressdropship_settings, $this->default ); } public function get_params( $name = "", $default = false ) { if ( ! $name ) { return apply_filters( 'wooaliexpressdropship_params', $this->params ); } $name_filter = 'wooaliexpressdropship_params_' . $name; if ( ! isset( $result ) ) { $result = $this->params[ $name ] ?? $default; } return $name_filter ? apply_filters( $name_filter, $result ) : $result; } public static function get_instance( $new = false ) { if ( $new || null === self::$instance ) { self::$instance = new self; } return self::$instance; } public static function get_attribute_name_by_slug( $slug ) { return ucwords( str_replace( '-', ' ', $slug ) ); } /** * @param $url * * @return mixed */ public static function get_domain_from_url( $url ) { $url = strtolower( $url ); $url_arr = explode( '//', $url ); if ( count( $url_arr ) > 1 ) { $url = str_replace( 'www.', '', $url_arr[1] ); } else { $url = str_replace( 'www.', '', $url_arr[0] ); } $url_arr = explode( '/', $url ); $url = $url_arr[0]; return $url; } /** * @param array $args * @param bool $return_sku * * @return array */ public static function get_imported_products( $args = array(), $return_sku = false ) { $imported_products = array(); $args = wp_parse_args( $args, array( 'post_type' => 'vi_wad_draft_product', 'posts_per_page' => - 1, 'meta_key' => '_vi_wad_sku',// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key 'post_status' => array( 'publish', 'draft', 'override' ), 'fields' => 'ids' ) ); // $the_query = new WP_Query( $args ); $the_query = VI_WOO_ALIDROPSHIP_DATA::is_ald_table() ? new Ali_Product_Query( $args ) : new WP_Query( $args ); if ( $the_query->have_posts() ) { if ( $return_sku ) { foreach ( $the_query->posts as $product_id ) { $product_sku = Ali_Product_Table::get_post_meta( $product_id, '_vi_wad_sku', true ); if ( $product_sku ) { $imported_products[] = $product_sku; } } } else { $imported_products = $the_query->posts; } } wp_reset_postdata(); return $imported_products; } public static function product_get_woo_id_by_aliexpress_id( $aliexpress_id, $is_variation = false, $count = false, $multiple = false ) { global $wpdb; if ( $aliexpress_id ) { $table_posts = "{$wpdb->prefix}posts"; $table_postmeta = "{$wpdb->prefix}postmeta"; if ( $is_variation ) { $post_type = 'product_variation'; $meta_key = '_vi_wad_aliexpress_variation_id'; } else { $post_type = 'product'; $meta_key = '_vi_wad_aliexpress_product_id'; } if ( $count ) { $query = "SELECT count(*) from {$table_postmeta} join {$table_posts} on {$table_postmeta}.post_id={$table_posts}.ID where {$table_posts}.post_type = '{$post_type}' and {$table_posts}.post_status != 'trash' and {$table_postmeta}.meta_key = '{$meta_key}' and {$table_postmeta}.meta_value = %s"; $results = $wpdb->get_var( $wpdb->prepare( $query, $aliexpress_id ) );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } else { $query = "SELECT {$table_postmeta}.* from {$table_postmeta} join {$table_posts} on {$table_postmeta}.post_id={$table_posts}.ID where {$table_posts}.post_type = '{$post_type}' and {$table_posts}.post_status != 'trash' and {$table_postmeta}.meta_key = '{$meta_key}' and {$table_postmeta}.meta_value = %s"; if ( $multiple ) { $results = $wpdb->get_results( $wpdb->prepare( $query, $aliexpress_id ), ARRAY_A );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } else { $query .= ' LIMIT 1'; $results = $wpdb->get_var( $wpdb->prepare( $query, $aliexpress_id ), 1 );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } } return $results; } else { return false; } } /** * @param $product_id * @param bool $count * @param bool $multiple * @param array $status * * @return array|bool|object|string|null */ public static function product_get_id_by_woo_id( $product_id, $count = false, $multiple = false, $status = array( 'publish', 'draft', 'override' ) ) { global $wpdb; if ( $product_id ) { $table_posts = "{$wpdb->prefix}posts"; $table_postmeta = "{$wpdb->prefix}postmeta"; $post_type = 'vi_wad_draft_product'; $meta_key = '_vi_wad_woo_id'; $post_status = ''; if ( $status ) { if ( is_array( $status ) ) { $status_count = count( $status ); if ( $status_count === 1 ) { $post_status = " AND {$table_posts}.post_status='{$status[0]}' "; } elseif ( $status_count > 1 ) { $post_status = " AND {$table_posts}.post_status IN ('" . implode( "','", $status ) . "') "; } } else { $post_status = " AND {$table_posts}.post_status='{$status}' "; } } if ( $count ) { $query = "SELECT count(*) from {$table_postmeta} join {$table_posts} on {$table_postmeta}.post_id={$table_posts}.ID where {$table_posts}.post_type = '{$post_type}'{$post_status}and {$table_postmeta}.meta_key = '{$meta_key}' and {$table_postmeta}.meta_value = %s"; $results = $wpdb->get_var( $wpdb->prepare( $query, $product_id ) );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } else { $query = "SELECT {$table_postmeta}.* from {$table_postmeta} join {$table_posts} on {$table_postmeta}.post_id={$table_posts}.ID where {$table_posts}.post_type = '{$post_type}'{$post_status}and {$table_postmeta}.meta_key = '{$meta_key}' and {$table_postmeta}.meta_value = %s"; if ( $multiple ) { $results = $wpdb->get_results( $wpdb->prepare( $query, $product_id ), ARRAY_A );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } else { $query .= ' LIMIT 1'; $results = $wpdb->get_var( $wpdb->prepare( $query, $product_id ), 1 );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } } return $results; } else { return false; } } /**Get vi_wad_draft_product ID that will override $product_id * * @param $product_id * * @return bool|string|null */ public static function get_overriding_product( $product_id ) { global $wpdb; if ( $product_id ) { $table_posts = "{$wpdb->prefix}posts"; $query = "SELECT ID from {$table_posts} where {$table_posts}.post_type = 'vi_wad_draft_product' and {$table_posts}.post_status = 'override' and {$table_posts}.post_parent = %s LIMIT 1"; return $wpdb->get_var( $wpdb->prepare( $query, $product_id ), 0 );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } else { return false; } } /** * @param $aliexpress_id * @param array $post_status * @param bool $count * @param bool $multiple * * @return array|string|null */ public static function product_get_id_by_aliexpress_id( $aliexpress_id, $post_status = [ 'publish', 'draft', 'override' ], $count = false, $multiple = false ) { global $wpdb; $table_posts = self::is_ald_table() ? $wpdb->ald_posts : "{$wpdb->prefix}posts"; $table_postmeta = self::is_ald_table() ? $wpdb->ald_postmeta : "{$wpdb->prefix}postmeta"; $post_id_column = self::is_ald_table() ? 'ald_post_id' : 'post_id'; $post_type = 'vi_wad_draft_product'; $meta_key = '_vi_wad_sku'; $args = array(); $where = array(); if ( $post_status ) { if ( is_array( $post_status ) ) { if ( count( $post_status ) === 1 ) { $where[] = "{$table_posts}.post_status=%s"; $args[] = $post_status[0]; } else { $where[] = "{$table_posts}.post_status IN (" . implode( ', ', array_fill( 0, count( $post_status ), '%s' ) ) . ")"; foreach ( $post_status as $v ) { $args[] = $v; } } } else { $where[] = "{$table_posts}.post_status=%s"; $args[] = $post_status; } } if ( $aliexpress_id ) { $where[] = "{$table_postmeta}.meta_key = '{$meta_key}'"; $where[] = "{$table_postmeta}.meta_value = %s"; $args[] = $aliexpress_id; if ( $count ) { $query = "SELECT count(*) from {$table_postmeta} join {$table_posts} on {$table_postmeta}.{$post_id_column}={$table_posts}.ID where {$table_posts}.post_type = '{$post_type}'"; $query .= ' AND ' . implode( ' AND ', $where ); $results = $wpdb->get_var( $wpdb->prepare( $query, $args ) );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } else { $query = "SELECT {$table_postmeta}.* from {$table_postmeta} join {$table_posts} on {$table_postmeta}.{$post_id_column}={$table_posts}.ID where {$table_posts}.post_type = '{$post_type}'"; $query .= ' AND ' . implode( ' AND ', $where ); if ( $multiple ) { $results = $wpdb->get_col( $wpdb->prepare( $query, $args ), 1 );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } else { $query .= ' LIMIT 1'; $results = $wpdb->get_var( $wpdb->prepare( $query, $args ), 1 );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } } } else { $where[] = "{$table_postmeta}.meta_key = '{$meta_key}'"; if ( $count ) { $query = "SELECT count(*) from {$table_postmeta} join {$table_posts} on {$table_postmeta}.{$post_id_column}={$table_posts}.ID where {$table_posts}.post_type = '{$post_type}'"; $query .= ' AND ' . implode( ' AND ', $where ); $results = $wpdb->get_var( count( $args ) ? $wpdb->prepare( $query, $args ) : $query );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } else { $query = "SELECT {$table_postmeta}.* from {$table_postmeta} join {$table_posts} on {$table_postmeta}.{$post_id_column}={$table_posts}.ID where {$table_posts}.post_type = '{$post_type}'"; $query .= ' AND ' . implode( ' AND ', $where ); $results = $wpdb->get_col( count( $args ) ? $wpdb->prepare( $query, $args ) : $query, 1 );// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared , WordPress.DB.DirectDatabaseQuery.DirectQuery , WordPress.DB.DirectDatabaseQuery.NoCaching } } return $results; } /** * @param $url * @param array $args * @param string $html * @param bool $skip_ship_from_check * * @return array */ public static function get_data( $url, $args = array(), $html = '', $skip_ship_from_check = false, $product_args = [] ) { $response = array( 'status' => 'success', 'message' => '', 'code' => '', 'data' => array(), ); $attributes = array( 'sku' => '', ); if ( $html === 'viwad_init_data_before' && ! empty( $product_args['product_id'] ) ) { $product_data = self::ali_request( [], wp_json_encode( $product_args ), [], 'https://aldapi.vinext.net/get_product' ); $html = isset( $product_data['data']['product'] ) ? $product_data['data']['product'] : []; if ( ! empty( $product_data['data']['freight'] ) ) { $response['freight'] = $product_data['data']['freight']['methods'] ?? $product_data['data']['freight']; } } if ( ! $html && $url ) { $args = wp_parse_args( $args, array( 'user-agent' => self::get_user_agent(), 'timeout' => 10, ) ); $request = wp_remote_get( $url, $args ); $response['code'] = wp_remote_retrieve_response_code( $request ); if ( ! is_wp_error( $request ) ) { $html = $request['body']; } else { $response['status'] = 'error'; $response['message'] = $request->get_error_messages(); return $response; } } $prepare = VIALD_CLASS_Parse_Ali_Data::parse_data( $attributes, $html, $skip_ship_from_check ); if ( ! empty( $prepare['error'] ) ) { $response['status'] = 'error'; $response['code'] = $prepare['code'] ?? ''; $response['message'] = $prepare['message'] ?? ''; return $response; } if ( ! empty( $attributes['sku'] ) ) { $response['data'] = $attributes; } else { $response['status'] = 'error'; } return $response; } public static function get_accept_currencies() { return [ 'RUB' ]; } public static function get_user_agent() { $user_agent_list = get_option( 'vi_wad_user_agent_list' ); if ( ! $user_agent_list ) { $user_agent_list = '["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.100 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko\/20100101 Firefox\/67.0","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit\/605.1.15 (KHTML, like Gecko) Version\/12.1.1 Safari\/605.1.15","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.80 Safari\/537.36","Mozilla\/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko\/20100101 Firefox\/67.0","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10.14; rv:67.0) Gecko\/20100101 Firefox\/67.0","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.100 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) HeadlessChrome\/60.0.3112.78 Safari\/537.36","Mozilla\/5.0 (Windows NT 6.1; rv:60.0) Gecko\/20100101 Firefox\/60.0","Mozilla\/5.0 (Windows NT 6.1; Win64; x64; rv:67.0) Gecko\/20100101 Firefox\/67.0","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.90 Safari\/537.36","Mozilla\/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.100 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/64.0.3282.140 Safari\/537.36 Edge\/17.17134","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (X11; Linux x86_64; rv:67.0) Gecko\/20100101 Firefox\/67.0","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.131 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/64.0.3282.140 Safari\/537.36 Edge\/18.17763","Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.80 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit\/605.1.15 (KHTML, like Gecko) Version\/12.1 Safari\/605.1.15","Mozilla\/5.0 (Windows NT 10.0; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit\/605.1.15 (KHTML, like Gecko) Version\/12.1.1 Safari\/605.1.15","Mozilla\/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.100 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; WOW64; Trident\/7.0; rv:11.0) like Gecko","Mozilla\/5.0 (X11; Linux x86_64; rv:60.0) Gecko\/20100101 Firefox\/60.0","Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/73.0.3683.103 Safari\/537.36 OPR\/60.0.3255.151","Mozilla\/5.0 (Windows NT 6.1; WOW64; Trident\/7.0; rv:11.0) like Gecko","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.80 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10.13; rv:67.0) Gecko\/20100101 Firefox\/67.0","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/73.0.3683.103 Safari\/537.36","Mozilla\/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.80 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/62.0.3202.94 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.157 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko\/20100101 Firefox\/66.0","Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko\/20100101 Firefox\/68.0","Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/72.0.3626.109 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.90 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/73.0.3683.103 Safari\/537.36 OPR\/60.0.3255.109","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/73.0.3683.103 Safari\/537.36 OPR\/60.0.3255.170","Mozilla\/5.0 (Windows NT 6.3; Win64; x64; rv:67.0) Gecko\/20100101 Firefox\/67.0","Mozilla\/5.0 (Windows NT 10.0; WOW64; rv:67.0) Gecko\/20100101 Firefox\/67.0","Mozilla\/5.0 (iPad; CPU OS 12_3_1 like Mac OS X) AppleWebKit\/605.1.15 (KHTML, like Gecko) Version\/12.1.1 Mobile\/15E148 Safari\/604.1","Mozilla\/5.0 (Windows NT 6.1; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) HeadlessChrome\/60.0.3112.78 Safari\/537.36","Mozilla\/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.100 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.100 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 YaBrowser\/19.6.1.153 Yowser\/2.5 Safari\/537.36","Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/70.0.3538.77 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/73.0.3683.103 YaBrowser\/19.4.3.370 Yowser\/2.5 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 YaBrowser\/19.6.0.1574 Yowser\/2.5 Safari\/537.36","Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Ubuntu Chromium\/74.0.3729.169 Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (Windows NT 6.1) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.131 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit\/605.1.15 (KHTML, like Gecko) Version\/12.0 Safari\/605.1.15","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/73.0.3683.86 Safari\/537.36","Mozilla\/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build\/JSS15J) AppleWebKit\/534.30 (KHTML, like Gecko) Version\/4.0 Mobile Safari\/534.30","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit\/605.1.15 (KHTML, like Gecko) Version\/12.0.3 Safari\/605.1.15","Mozilla\/5.0 (Windows NT 6.1) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.100 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit\/605.1.15 (KHTML, like Gecko) Version\/11.1.2 Safari\/605.1.15","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.80 Safari\/537.36","Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:67.0) Gecko\/20100101 Firefox\/67.0","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit\/605.1.15 (KHTML, like Gecko) Version\/12.0.2 Safari\/605.1.15","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.100 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko\/20100101 Firefox\/45.0","Mozilla\/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.90 Safari\/537.36","Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.157 Safari\/537.36","Mozilla\/5.0 (X11; Linux x86_64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.90 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.169 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/72.0.3626.121 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/73.0.3683.86 Safari\/537.36","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.100 Safari\/537.36","Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko\/20100101 Firefox\/60.0","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10.12; rv:67.0) Gecko\/20100101 Firefox\/67.0","Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit\/605.1.15 (KHTML, like Gecko) Version\/13.0 Safari\/605.1.15","Mozilla\/5.0 (Windows NT 6.1; rv:67.0) Gecko\/20100101 Firefox\/67.0","Mozilla\/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/73.0.3683.103 Safari\/537.36 OPR\/60.0.3255.151","Mozilla\/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/73.0.3683.103 Safari\/537.36 OPR\/60.0.3255.170","Mozilla\/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/74.0.3729.131 Safari\/537.36","Mozilla\/5.0 (Windows NT 6.1; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/73.0.3683.103 YaBrowser\/19.4.3.370 Yowser\/2.5 Safari\/537.36","Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:56.0) Gecko\/20100101 Firefox\/56.0","Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:56.0) Gecko\/20100101 Firefox\/56.0"]'; update_option( 'vi_wad_user_agent_list', $user_agent_list ); } $user_agent_list_array = vi_wad_json_decode( $user_agent_list ); $return_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'; $last_used = get_option( 'vi_wad_last_used_user_agent', 0 ); if ( $last_used == count( $user_agent_list_array ) - 1 ) { $last_used = 0; shuffle( $user_agent_list_array ); update_option( 'vi_wad_user_agent_list', wp_json_encode( $user_agent_list_array ) ); } else { $last_used ++; } update_option( 'vi_wad_last_used_user_agent', $last_used ); if ( isset( $user_agent_list_array[ $last_used ] ) && $user_agent_list_array[ $last_used ] ) { $return_agent = $user_agent_list_array[ $last_used ]; } return $return_agent; } public static function sku_exists( $sku = '' ) { $sku_exists = false; if ( $sku ) { $id_from_sku = wc_get_product_id_by_sku( $sku ); $product = $id_from_sku ? wc_get_product( $id_from_sku ) : false; $sku_exists = $product && 'importing' !== $product->get_status(); } return $sku_exists; } public static function set( $name, $set_name = false ) { if ( is_array( $name ) ) { return implode( ' ', array_map( array( 'VI_WOO_ALIDROPSHIP_DATA', 'set' ), $name ) ); } else { if ( $set_name ) { return str_replace( '-', '_', self::$prefix . $name ); } else { return self::$prefix . $name; } } } public function get_default( $name = "" ) { if ( ! $name ) { return $this->default; } elseif ( isset( $this->default[ $name ] ) ) { return apply_filters( 'wooaliexpressdropship_params_default_' . $name, $this->default[ $name ] ); } else { return false; } } /** * @param $string_number * * @return float */ public static function string_to_float( $string_number ) { return floatval( str_replace( ',', '', $string_number ) ); } public function process_exchange_price( $price ) { if ( ! $price ) { return $price; } $rate = floatval( $this->get_params( 'import_currency_rate' ) ); if ( $rate ) { $price = $price * $rate; } if ( $this->get_params( 'format_price_rules_enable' ) ) { self::format_price( $price ); } return round( $price, wc_get_price_decimals() ); } protected static function calculate_price_base_on_type( $price, $value, $type ) { $match_value = floatval( $value ); switch ( $type ) { case 'fixed': $price = $price + $match_value; break; case 'percent': $price = $price * ( 1 + $match_value / 100 ); break; case 'multiply': $price = $price * $match_value; break; default: $price = $match_value; } return $price; } /** * @param $price * @param bool $is_sale_price * * @return float|int */ public function process_price( $price, $is_sale_price = false ) { if ( ! $price ) { return $price; } $original_price = $price; $price_default = $this->get_params( 'price_default' ); $price_from = $this->get_params( 'price_from' ); $price_to = $this->get_params( 'price_to' ); $plus_value_type = $this->get_params( 'plus_value_type' ); if ( $is_sale_price ) { $plus_sale_value = $this->get_params( 'plus_sale_value' ); $level_count = count( $price_from ); if ( $level_count > 0 ) { /*adjust price rules since version 1.0.1.1*/ if ( ! is_array( $price_to ) || count( $price_to ) !== $level_count ) { if ( $level_count > 1 ) { $price_to = array_values( array_slice( $price_from, 1 ) ); $price_to[] = ''; } else { $price_to = array( '' ); } } $match = false; for ( $i = 0; $i < $level_count; $i ++ ) { if ( $price >= $price_from[ $i ] && ( $price_to[ $i ] === '' || $price <= $price_to[ $i ] ) ) { $match = $i; break; } } if ( $match !== false ) { if ( $plus_sale_value[ $match ] < 0 ) { $price = 0; } else { $price = self::calculate_price_base_on_type( $price, $plus_sale_value[ $match ], $plus_value_type[ $match ] ); } } else { $plus_sale_value_default = isset( $price_default['plus_sale_value'] ) ? $price_default['plus_sale_value'] : 1; if ( $plus_sale_value_default < 0 ) { $price = 0; } else { $price = self::calculate_price_base_on_type( $price, $plus_sale_value_default, isset( $price_default['plus_value_type'] ) ? $price_default['plus_value_type'] : 'multiply' ); } } } } else { $plus_value = $this->get_params( 'plus_value' ); $level_count = count( $price_from ); if ( $level_count > 0 ) { /*adjust price rules since version 1.0.1.1*/ if ( ! is_array( $price_to ) || count( $price_to ) !== $level_count ) { if ( $level_count > 1 ) { $price_to = array_values( array_slice( $price_from, 1 ) ); $price_to[] = ''; } else { $price_to = array( '' ); } } $match = false; for ( $i = 0; $i < $level_count; $i ++ ) { if ( $price >= $price_from[ $i ] && ( $price_to[ $i ] === '' || $price <= $price_to[ $i ] ) ) { $match = $i; break; } } if ( $match !== false ) { $price = self::calculate_price_base_on_type( $price, $plus_value[ $match ], $plus_value_type[ $match ] ); } else { $price = self::calculate_price_base_on_type( $price, isset( $price_default['plus_value'] ) ? $price_default['plus_value'] : 2, isset( $price_default['plus_value_type'] ) ? $price_default['plus_value_type'] : 'multiply' ); } } } return apply_filters( 'vi_wad_processed_price', $price, $is_sale_price, $original_price ); } public static function format_price( &$price ) { $applied = array(); if ( $price ) { $instance = self::get_instance(); $rules = $instance->get_params( 'format_price_rules' ); if ( is_array( $rules ) && count( $rules ) ) { $decimals = wc_get_price_decimals(); $price = self::string_to_float( $price ); $int_part = intval( $price ); $decimal_part = number_format( $price - $int_part, $decimals ); $int_part_length = strlen( $int_part ); if ( $decimals > 0 ) { foreach ( $rules as $key => $rule ) { if ( $rule['part'] === 'fraction' ) { if ( ( ! $rule['from'] && ! $rule['to'] ) || ( $price >= $rule['from'] && $price <= $rule['to'] ) || ( ! $rule['from'] && $price <= $rule['to'] ) || ( ! $rule['to'] && $price >= $rule['from'] ) ) { $compare_value = $decimal_part; $string = substr( strval( $decimal_part ), 2 ); if ( ( $rule['value_from'] === '' && $rule['value_to'] === '' ) || ( $compare_value >= self::string_to_float( ".{$rule['value_from']}" ) && $compare_value <= self::string_to_float( ".{$rule['value_to']}" ) ) || ( $rule['value_from'] === '' && $compare_value <= self::string_to_float( ".{$rule['value_to']}" ) ) || ( $rule['value_to'] === '' && $compare_value >= self::string_to_float( ".{$rule['value_from']}" ) ) ) { while ( ( $pos = strpos( $rule['value'], 'x' ) ) !== false ) { $replace = 'y'; if ( $pos < strlen( $string ) ) { $replace = substr( $string, $pos, 1 ); } $rule['value'] = substr_replace( $rule['value'], $replace, $pos, 1 ); } $price = $int_part + self::string_to_float( ".{$rule['value']}" ); $decimal_part = $price - $int_part; $applied[] = $key; break; } } } } } foreach ( $rules as $key => $rule ) { if ( $rule['part'] === 'integer' ) { if ( $price >= $rule['from'] && $price <= $rule['to'] ) { if ( $rule['value_from'] === '' && $rule['value_to'] === '' ) { $max = min( $int_part_length - 1, strlen( $rule['value'] ) ); if ( $max > 0 ) { $compare_value = intval( substr( $int_part, $int_part_length - $max ) ); $string = strval( zeroise( $compare_value, $max ) ); $rule['value'] = zeroise( $rule['value'], $max ); while ( ( $pos = strpos( $rule['value'], 'x' ) ) !== false ) { $replace = 'y'; if ( $pos < strlen( $string ) ) { $replace = substr( $string, $pos, 1 ); } $rule['value'] = substr_replace( $rule['value'], $replace, $pos, 1 ); } $price = $int_part - $compare_value + intval( $rule['value'] ) + $decimal_part; $applied[] = $key; break; } } else { $max = min( $int_part_length, max( strlen( $rule['value_from'] ), strlen( $rule['value_to'] ), strlen( $rule['value'] ) ) ); if ( $max > 0 ) { $compare_value = intval( substr( $int_part, $int_part_length - $max ) ); $string = strval( zeroise( $compare_value, $max ) ); $rule['value'] = zeroise( $rule['value'], $max ); if ( ( $compare_value >= intval( $rule['value_from'] ) && $compare_value <= intval( $rule['value_to'] ) ) ) { while ( ( $pos = strpos( $rule['value'], 'x' ) ) !== false ) { $replace = 'y'; if ( $pos < strlen( $string ) ) { $replace = substr( $string, $pos, 1 ); } $rule['value'] = substr_replace( $rule['value'], $replace, $pos, 1 ); } $price = $int_part - $compare_value + intval( $rule['value'] ) + $decimal_part; $applied[] = $key; break; } } } } } } } } return $applied; } public static function process_variation_sku( $sku, $variation_ids ) { $return = ''; if ( is_array( $variation_ids ) && count( $variation_ids ) ) { foreach ( $variation_ids as $key => $value ) { $variation_ids[ $key ] = wc_sanitize_taxonomy_name( $value ); } $return = $sku . '-' . implode( '-', $variation_ids ); } return $return; } public static function download_description( $product_id, $description_url, $description, $product_description ) { if ( $description_url && $product_id ) { $request = wp_remote_get( $description_url, array( 'user-agent' => self::get_user_agent(), 'timeout' => 3, ) ); if ( ! is_wp_error( $request ) && get_post_type( $product_id ) === 'vi_wad_draft_product' ) { if ( isset( $request['body'] ) && $request['body'] ) { $body = preg_replace( '/